blob: 18c4a78efbc77ff80b11ed9e8b0176062a1b6fc4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe409a3e92012-03-27 13:01:01 +10309 * Jonathan Woithe <jwoithe@just42.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Takashi Iwai23d30f22012-05-07 17:17:32 +020035#include "hda_auto_parser.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090036#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020037#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Takashi Iwai1d045db2011-07-07 18:23:21 +020039/* unsol event tags */
40#define ALC_FRONT_EVENT 0x01
41#define ALC_DCVOL_EVENT 0x02
42#define ALC_HP_EVENT 0x04
43#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020044
Kailang Yangdf694da2005-12-05 19:42:22 +010045/* for GPIO Poll */
46#define GPIO_MASK 0x03
47
Takashi Iwai4a79ba32009-04-22 16:31:35 +020048/* extra amp-initialization sequence types */
49enum {
50 ALC_INIT_NONE,
51 ALC_INIT_DEFAULT,
52 ALC_INIT_GPIO1,
53 ALC_INIT_GPIO2,
54 ALC_INIT_GPIO3,
55};
56
Kailang Yangda00c242010-03-19 11:23:45 +010057struct alc_customize_define {
58 unsigned int sku_cfg;
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
65 unsigned int swap:1;
66 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020067 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010068};
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwaid922b512011-04-28 12:18:53 +020076enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020077 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020080};
81
Takashi Iwaic14c95f2012-02-16 16:38:07 +010082#define MAX_VOL_NIDS 0x40
83
Takashi Iwai23d30f22012-05-07 17:17:32 +020084/* make compatible with old code */
85#define alc_apply_pincfgs snd_hda_apply_pincfgs
86#define alc_apply_fixup snd_hda_apply_fixup
87#define alc_pick_fixup snd_hda_pick_fixup
88#define alc_fixup hda_fixup
89#define alc_pincfg hda_pintbl
90#define alc_model_fixup hda_model_fixup
91
92#define ALC_FIXUP_PINS HDA_FIXUP_PINS
93#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
95
96#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
100
101
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100102#define MAX_NID_PATH_DEPTH 5
103
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100104/* Widget connection path
105 *
106 * For output, stored in the order of DAC -> ... -> pin,
107 * for input, pin -> ... -> ADC.
108 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100109 * idx[i] contains the source index number to select on of the widget path[i];
110 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100111 * multi[] indicates whether it's a selector widget with multi-connectors
112 * (i.e. the connection selection is mandatory)
113 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
114 */
115struct nid_path {
116 int depth;
117 hda_nid_t path[MAX_NID_PATH_DEPTH];
118 unsigned char idx[MAX_NID_PATH_DEPTH];
119 unsigned char multi[MAX_NID_PATH_DEPTH];
120 unsigned int ctls[2]; /* 0 = volume, 1 = mute */
121};
122
Takashi Iwaiba8111272012-12-06 18:06:23 +0100123enum { NID_PATH_VOL_CTL = 0, NID_PATH_MUTE_CTL = 1 };
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200126 struct hda_gen_spec gen;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200129 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +0200131 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100132 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200134 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200135 const struct hda_pcm_stream *stream_analog_playback;
136 const struct hda_pcm_stream *stream_analog_capture;
137 const struct hda_pcm_stream *stream_analog_alt_playback;
138 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200140 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200141 const struct hda_pcm_stream *stream_digital_playback;
142 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200145 struct hda_multi_out multiout; /* playback set-up
146 * max_channels, dacs must be set
147 * dig_out_nid and hp_nid are optional
148 */
Takashi Iwai63300792008-01-24 15:31:36 +0100149 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100150 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100151 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* capture */
154 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200155 const hda_nid_t *adc_nids;
156 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200157 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200158 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Takashi Iwai840b64c2010-07-13 22:49:01 +0200160 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200161 hda_nid_t cur_adc;
162 unsigned int cur_adc_stream_tag;
163 unsigned int cur_adc_format;
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200166 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 const struct hda_input_mux *input_mux;
168 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200169 hda_nid_t ext_mic_pin;
170 hda_nid_t dock_mic_pin;
171 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100174 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200176 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100177 int const_channel_count; /* min. channel count (for speakers) */
178 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100181 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200182
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200183 /* dynamic controls, init_verbs and input_mux */
184 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100185 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200186 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200187 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200188 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200189 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
190 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200191 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
192 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
193 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200194 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100195
Takashi Iwai463419d2012-12-05 14:17:37 +0100196 /* DAC list */
197 int num_all_dacs;
198 hda_nid_t all_dacs[16];
199
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100200 /* output paths */
201 struct snd_array out_path;
202
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100203 /* input paths */
204 struct snd_array in_path;
205
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100206 /* analog loopback paths */
207 struct snd_array loopback_path;
208
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100209 /* hooks */
210 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200211#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500212 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100213#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200214 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200215 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100216
Takashi Iwai834be882006-03-01 14:16:17 +0100217 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200218 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200219 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200220 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200221 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200222 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200223 unsigned int automute_speaker:1; /* automute speaker outputs */
224 unsigned int automute_lo:1; /* automute LO outputs */
225 unsigned int detect_hp:1; /* Headphone detection enabled */
226 unsigned int detect_lo:1; /* Line-out detection enabled */
227 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
228 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100229 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200230
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100231 /* other flags */
232 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200233 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100234 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200235 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200236 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100237 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200238 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
239 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200240 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200241
242 /* auto-mute control */
243 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200244 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200245
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200246 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200247 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100248
Takashi Iwai2134ea42008-01-10 16:53:55 +0100249 /* for virtual master */
250 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100251 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200252#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200253 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100254 int num_loopbacks;
255 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200256#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200257
258 /* for PLL fix */
259 hda_nid_t pll_nid;
260 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200261 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100262
Takashi Iwaice764ab2011-04-27 16:35:23 +0200263 /* multi-io */
264 int multi_ios;
265 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200266
267 /* bind volumes */
268 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100269};
270
Takashi Iwai44c02402011-07-08 15:14:19 +0200271static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
272 int dir, unsigned int bits)
273{
274 if (!nid)
275 return false;
276 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
277 if (query_amp_caps(codec, nid, dir) & bits)
278 return true;
279 return false;
280}
281
282#define nid_has_mute(codec, nid, dir) \
283 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
284#define nid_has_volume(codec, nid, dir) \
285 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287/*
288 * input MUX handling
289 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200290static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
291 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
293 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
294 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200295 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
296 if (mux_idx >= spec->num_mux_defs)
297 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100298 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
299 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200300 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200303static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
304 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
307 struct alc_spec *spec = codec->spec;
308 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
309
310 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
311 return 0;
312}
313
Takashi Iwai21268962011-07-07 15:01:13 +0200314static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Takashi Iwai21268962011-07-07 15:01:13 +0200316 struct alc_spec *spec = codec->spec;
317 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
318
319 if (spec->cur_adc && spec->cur_adc != new_adc) {
320 /* stream is running, let's swap the current ADC */
321 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
322 spec->cur_adc = new_adc;
323 snd_hda_codec_setup_stream(codec, new_adc,
324 spec->cur_adc_stream_tag, 0,
325 spec->cur_adc_format);
326 return true;
327 }
328 return false;
329}
330
Takashi Iwai61071592011-11-23 07:52:15 +0100331static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
332{
333 return spec->capsrc_nids ?
334 spec->capsrc_nids[idx] : spec->adc_nids[idx];
335}
336
Takashi Iwai24de1832011-11-07 17:13:39 +0100337static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200338static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100339
David Henningsson00227f12012-06-27 18:45:44 +0200340/* for shared I/O, change the pin-control accordingly */
341static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
342{
343 struct alc_spec *spec = codec->spec;
344 unsigned int val;
345 hda_nid_t pin = spec->autocfg.inputs[1].pin;
346 /* NOTE: this assumes that there are only two inputs, the
347 * first is the real internal mic and the second is HP/mic jack.
348 */
349
350 val = snd_hda_get_default_vref(codec, pin);
351
352 /* This pin does not have vref caps - let's enable vref on pin 0x18
353 instead, as suggested by Realtek */
354 if (val == AC_PINCTL_VREF_HIZ) {
355 const hda_nid_t vref_pin = 0x18;
356 /* Sanity check pin 0x18 */
357 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
358 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
359 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
360 if (vref_val != AC_PINCTL_VREF_HIZ)
361 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
362 }
363 }
364
365 val = set_as_mic ? val | PIN_IN : PIN_HP;
366 snd_hda_set_pin_ctl(codec, pin, val);
367
368 spec->automute_speaker = !set_as_mic;
369 call_update_outputs(codec);
370}
Takashi Iwai21268962011-07-07 15:01:13 +0200371
372/* select the given imux item; either unmute exclusively or select the route */
373static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
374 unsigned int idx, bool force)
375{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100377 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100378 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100379 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200380 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Takashi Iwai5803a322012-02-21 11:59:45 +0100382 if (!spec->input_mux)
383 return 0;
384
Takashi Iwaicd896c32008-11-18 12:36:33 +0100385 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
386 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100387 if (!imux->num_items && mux_idx > 0)
388 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100389 if (!imux->num_items)
390 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100391
Takashi Iwai21268962011-07-07 15:01:13 +0200392 if (idx >= imux->num_items)
393 idx = imux->num_items - 1;
394 if (spec->cur_mux[adc_idx] == idx && !force)
395 return 0;
396 spec->cur_mux[adc_idx] = idx;
397
David Henningsson00227f12012-06-27 18:45:44 +0200398 if (spec->shared_mic_hp)
399 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100400
Takashi Iwai21268962011-07-07 15:01:13 +0200401 if (spec->dyn_adc_switch) {
402 alc_dyn_adc_pcm_resetup(codec, idx);
403 adc_idx = spec->dyn_adc_idx[idx];
404 }
405
Takashi Iwai61071592011-11-23 07:52:15 +0100406 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200407
408 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200409 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100410 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200411 return 1;
412
Takashi Iwaia22d5432009-07-27 12:54:26 +0200413 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200414 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100415 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100416 int active = imux->items[idx].index;
417 for (i = 0; i < num_conns; i++) {
418 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
419 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100420 HDA_AMP_MUTE, v);
421 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100422 } else {
423 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200424 snd_hda_codec_write_cache(codec, nid, 0,
425 AC_VERB_SET_CONNECT_SEL,
426 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100427 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200428 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200429 return 1;
430}
431
432static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
433 struct snd_ctl_elem_value *ucontrol)
434{
435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
436 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
437 return alc_mux_select(codec, adc_idx,
438 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100439}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100442 * set up the input pin config (depending on the given auto-pin type)
443 */
444static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
445 int auto_pin_type)
446{
447 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200448 if (auto_pin_type == AUTO_PIN_MIC)
449 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200450 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100451}
452
453/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200454 * Append the given mixer and verb elements for the later use
455 * The mixer array is referred in build_controls(), and init_verbs are
456 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100457 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200458static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100459{
460 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
461 return;
462 spec->mixers[spec->num_mixers++] = mix;
463}
464
Takashi Iwaid88897e2008-10-31 15:01:37 +0100465/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200466 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100467 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200468/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200469static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200470 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
471 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
472 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
473 { }
474};
475
Takashi Iwaia9111322011-05-02 11:30:18 +0200476static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200477 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
478 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
479 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
480 { }
481};
482
Takashi Iwaia9111322011-05-02 11:30:18 +0200483static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200484 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
485 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
486 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
487 { }
488};
489
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200490/*
491 * Fix hardware PLL issue
492 * On some codecs, the analog PLL gating control must be off while
493 * the default value is 1.
494 */
495static void alc_fix_pll(struct hda_codec *codec)
496{
497 struct alc_spec *spec = codec->spec;
498 unsigned int val;
499
500 if (!spec->pll_nid)
501 return;
502 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
503 spec->pll_coef_idx);
504 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
505 AC_VERB_GET_PROC_COEF, 0);
506 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
507 spec->pll_coef_idx);
508 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
509 val & ~(1 << spec->pll_coef_bit));
510}
511
512static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
513 unsigned int coef_idx, unsigned int coef_bit)
514{
515 struct alc_spec *spec = codec->spec;
516 spec->pll_nid = nid;
517 spec->pll_coef_idx = coef_idx;
518 spec->pll_coef_bit = coef_bit;
519 alc_fix_pll(codec);
520}
521
Takashi Iwai1d045db2011-07-07 18:23:21 +0200522/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200523 * Jack detections for HP auto-mute and mic-switch
524 */
525
526/* check each pin in the given array; returns true if any of them is plugged */
527static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200528{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200530
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200531 for (i = 0; i < num_pins; i++) {
532 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200533 if (!nid)
534 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200535 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200536 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537 return present;
538}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200539
Takashi Iwai1d045db2011-07-07 18:23:21 +0200540/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200541static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200542 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543{
544 struct alc_spec *spec = codec->spec;
545 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200546 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200547 int i;
548
549 for (i = 0; i < num_pins; i++) {
550 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100551 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200552 if (!nid)
553 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200554 switch (spec->automute_mode) {
555 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100556 /* don't reset VREF value in case it's controlling
557 * the amp (see alc861_fixup_asus_amp_vref_0f())
558 */
559 if (spec->keep_vref_in_automute) {
560 val = snd_hda_codec_read(codec, nid, 0,
561 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
562 val &= ~PIN_HP;
563 } else
564 val = 0;
565 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200566 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200567 break;
568 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200569 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200570 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200571 break;
572 case ALC_AUTOMUTE_MIXER:
573 nid = spec->automute_mixer_nid[i];
574 if (!nid)
575 break;
576 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200578 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200579 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200580 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200581 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200582 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200583}
584
David Henningsson42cf0d02011-09-20 12:04:56 +0200585/* Toggle outputs muting */
586static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200587{
588 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200589 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590
Takashi Iwaic0a20262011-06-10 15:28:15 +0200591 /* Control HP pins/amps depending on master_mute state;
592 * in general, HP pins/amps control should be enabled in all cases,
593 * but currently set only for master_mute, just to be safe
594 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100595 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
596 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200597 spec->autocfg.hp_pins, spec->master_mute, true);
598
David Henningsson42cf0d02011-09-20 12:04:56 +0200599 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200600 on = 0;
601 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200602 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200603 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200604 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200605 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200606
607 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200608 /* if LO is a copy of either HP or Speaker, don't need to handle it */
609 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
610 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200611 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200612 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200613 on = 0;
614 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200615 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200616 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200617 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200618 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200619}
620
David Henningsson42cf0d02011-09-20 12:04:56 +0200621static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200622{
623 struct alc_spec *spec = codec->spec;
624 if (spec->automute_hook)
625 spec->automute_hook(codec);
626 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200627 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200628}
629
Takashi Iwai1d045db2011-07-07 18:23:21 +0200630/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200631static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200632{
633 struct alc_spec *spec = codec->spec;
634
David Henningsson42cf0d02011-09-20 12:04:56 +0200635 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200636 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
637 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200638 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200639 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200640 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200641}
642
Takashi Iwai1d045db2011-07-07 18:23:21 +0200643/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200644static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200645{
646 struct alc_spec *spec = codec->spec;
647
David Henningssonf7f4b2322012-10-10 16:32:09 +0200648 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
649 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200650 /* check LO jack only when it's different from HP */
651 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
652 return;
653
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200654 spec->line_jack_present =
655 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
656 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200657 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200658 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200659 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200660}
661
Takashi Iwai8d087c72011-06-28 12:45:47 +0200662#define get_connection_index(codec, mux, nid) \
663 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200664
Takashi Iwai1d045db2011-07-07 18:23:21 +0200665/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200666static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200667{
668 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200669 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200670
Takashi Iwai21268962011-07-07 15:01:13 +0200671 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200672 return;
673 if (snd_BUG_ON(!spec->adc_nids))
674 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200675 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200676 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200677
Takashi Iwai21268962011-07-07 15:01:13 +0200678 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
679 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
680 else if (spec->dock_mic_idx >= 0 &&
681 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
682 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
683 else
684 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200685}
686
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100687/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200688static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100689{
690 unsigned int val;
691 struct snd_kcontrol *kctl;
692 struct snd_ctl_elem_value *uctl;
693
694 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
695 if (!kctl)
696 return;
697 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
698 if (!uctl)
699 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200700 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100701 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
702 val &= HDA_AMP_VOLMASK;
703 uctl->value.integer.value[0] = val;
704 uctl->value.integer.value[1] = val;
705 kctl->put(kctl, uctl);
706 kfree(uctl);
707}
708
David Henningsson29adc4b2012-09-25 11:31:00 +0200709static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100710{
David Henningsson29adc4b2012-09-25 11:31:00 +0200711 /* For some reason, the res given from ALC880 is broken.
712 Here we adjust it properly. */
713 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100714}
715
Takashi Iwai1d045db2011-07-07 18:23:21 +0200716/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200717static void alc_inithook(struct hda_codec *codec)
718{
David Henningsson29adc4b2012-09-25 11:31:00 +0200719 alc_hp_automute(codec, NULL);
720 alc_line_automute(codec, NULL);
721 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200722}
723
Kailang Yangf9423e72008-05-27 12:32:25 +0200724/* additional initialization for ALC888 variants */
725static void alc888_coef_init(struct hda_codec *codec)
726{
727 unsigned int tmp;
728
729 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
730 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
731 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100732 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200733 /* alc888S-VC */
734 snd_hda_codec_read(codec, 0x20, 0,
735 AC_VERB_SET_PROC_COEF, 0x830);
736 else
737 /* alc888-VB */
738 snd_hda_codec_read(codec, 0x20, 0,
739 AC_VERB_SET_PROC_COEF, 0x3030);
740}
741
Takashi Iwai1d045db2011-07-07 18:23:21 +0200742/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200743static void alc889_coef_init(struct hda_codec *codec)
744{
745 unsigned int tmp;
746
747 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
748 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
749 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
750 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
751}
752
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100753/* turn on/off EAPD control (only if available) */
754static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
755{
756 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
757 return;
758 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
759 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
760 on ? 2 : 0);
761}
762
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200763/* turn on/off EAPD controls of the codec */
764static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
765{
766 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200767 static hda_nid_t pins[] = {
768 0x0f, 0x10, 0x14, 0x15, 0
769 };
770 hda_nid_t *p;
771 for (p = pins; *p; p++)
772 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200773}
774
Takashi Iwai1c716152011-04-07 10:37:16 +0200775/* generic shutup callback;
776 * just turning off EPAD and a little pause for avoiding pop-noise
777 */
778static void alc_eapd_shutup(struct hda_codec *codec)
779{
780 alc_auto_setup_eapd(codec, false);
781 msleep(200);
782}
783
Takashi Iwai1d045db2011-07-07 18:23:21 +0200784/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200785static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200786{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200787 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200788
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200789 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200790 switch (type) {
791 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200792 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
793 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200794 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200795 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
796 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200797 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200798 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
799 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200800 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200801 switch (codec->vendor_id) {
802 case 0x10ec0260:
803 snd_hda_codec_write(codec, 0x1a, 0,
804 AC_VERB_SET_COEF_INDEX, 7);
805 tmp = snd_hda_codec_read(codec, 0x1a, 0,
806 AC_VERB_GET_PROC_COEF, 0);
807 snd_hda_codec_write(codec, 0x1a, 0,
808 AC_VERB_SET_COEF_INDEX, 7);
809 snd_hda_codec_write(codec, 0x1a, 0,
810 AC_VERB_SET_PROC_COEF,
811 tmp | 0x2010);
812 break;
813 case 0x10ec0262:
814 case 0x10ec0880:
815 case 0x10ec0882:
816 case 0x10ec0883:
817 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100818 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100819 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200820 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200821 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200822 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200823 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200824 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100825#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200826 case 0x10ec0267:
827 case 0x10ec0268:
828 snd_hda_codec_write(codec, 0x20, 0,
829 AC_VERB_SET_COEF_INDEX, 7);
830 tmp = snd_hda_codec_read(codec, 0x20, 0,
831 AC_VERB_GET_PROC_COEF, 0);
832 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200833 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200834 snd_hda_codec_write(codec, 0x20, 0,
835 AC_VERB_SET_PROC_COEF,
836 tmp | 0x3000);
837 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100838#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200839 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200840 break;
841 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200842}
Kailang Yangea1fb292008-08-26 12:58:38 +0200843
Takashi Iwai1d045db2011-07-07 18:23:21 +0200844/*
845 * Auto-Mute mode mixer enum support
846 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200847static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
848 struct snd_ctl_elem_info *uinfo)
849{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
851 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200852 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100853 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200854 };
855
Takashi Iwaidda415d2012-11-30 18:34:38 +0100856 if (spec->automute_speaker_possible && spec->automute_lo_possible)
857 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
858 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200859}
860
861static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
862 struct snd_ctl_elem_value *ucontrol)
863{
864 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
865 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200866 unsigned int val = 0;
867 if (spec->automute_speaker)
868 val++;
869 if (spec->automute_lo)
870 val++;
871
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200872 ucontrol->value.enumerated.item[0] = val;
873 return 0;
874}
875
876static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
877 struct snd_ctl_elem_value *ucontrol)
878{
879 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
880 struct alc_spec *spec = codec->spec;
881
882 switch (ucontrol->value.enumerated.item[0]) {
883 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200886 spec->automute_speaker = 0;
887 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200888 break;
889 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200890 if (spec->automute_speaker_possible) {
891 if (!spec->automute_lo && spec->automute_speaker)
892 return 0;
893 spec->automute_speaker = 1;
894 spec->automute_lo = 0;
895 } else if (spec->automute_lo_possible) {
896 if (spec->automute_lo)
897 return 0;
898 spec->automute_lo = 1;
899 } else
900 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200901 break;
902 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200903 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200904 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200905 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200906 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200907 spec->automute_speaker = 1;
908 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909 break;
910 default:
911 return -EINVAL;
912 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200913 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200914 return 1;
915}
916
Takashi Iwaia9111322011-05-02 11:30:18 +0200917static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
919 .name = "Auto-Mute Mode",
920 .info = alc_automute_mode_info,
921 .get = alc_automute_mode_get,
922 .put = alc_automute_mode_put,
923};
924
Takashi Iwai668d1e92012-11-29 14:10:17 +0100925static struct snd_kcontrol_new *
926alc_kcontrol_new(struct alc_spec *spec, const char *name,
927 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200928{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100929 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
930 if (!knew)
931 return NULL;
932 *knew = *temp;
933 knew->name = kstrdup(name, GFP_KERNEL);
934 if (!knew->name)
935 return NULL;
936 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200937}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200938
939static int alc_add_automute_mode_enum(struct hda_codec *codec)
940{
941 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200942
Takashi Iwai668d1e92012-11-29 14:10:17 +0100943 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200944 return -ENOMEM;
945 return 0;
946}
947
Takashi Iwai1d045db2011-07-07 18:23:21 +0200948/*
949 * Check the availability of HP/line-out auto-mute;
950 * Set up appropriately if really supported
951 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100952static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200953{
954 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200955 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200956 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100957 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200958
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200959 if (cfg->hp_pins[0])
960 present++;
961 if (cfg->line_out_pins[0])
962 present++;
963 if (cfg->speaker_pins[0])
964 present++;
965 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100966 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200967
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200968 if (!cfg->speaker_pins[0] &&
969 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200970 memcpy(cfg->speaker_pins, cfg->line_out_pins,
971 sizeof(cfg->speaker_pins));
972 cfg->speaker_outs = cfg->line_outs;
973 }
974
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200975 if (!cfg->hp_pins[0] &&
976 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200977 memcpy(cfg->hp_pins, cfg->line_out_pins,
978 sizeof(cfg->hp_pins));
979 cfg->hp_outs = cfg->line_outs;
980 }
981
David Henningsson42cf0d02011-09-20 12:04:56 +0200982 spec->automute_mode = ALC_AUTOMUTE_PIN;
983
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200984 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200985 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200986 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200987 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200988 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200989 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200990 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
991 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200992 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200993 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200994
David Henningsson42cf0d02011-09-20 12:04:56 +0200995 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
996 if (cfg->speaker_outs)
997 for (i = 0; i < cfg->line_outs; i++) {
998 hda_nid_t nid = cfg->line_out_pins[i];
999 if (!is_jack_detectable(codec, nid))
1000 continue;
1001 snd_printdd("realtek: Enable Line-Out "
1002 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +02001003 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
1004 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +02001005 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +02001006 }
David Henningsson42cf0d02011-09-20 12:04:56 +02001007 spec->automute_lo_possible = spec->detect_hp;
1008 }
1009
1010 spec->automute_speaker_possible = cfg->speaker_outs &&
1011 (spec->detect_hp || spec->detect_lo);
1012
1013 spec->automute_lo = spec->automute_lo_possible;
1014 spec->automute_speaker = spec->automute_speaker_possible;
1015
Takashi Iwai475c3d22012-11-30 08:31:30 +01001016 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001017 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001018 err = alc_add_automute_mode_enum(codec);
1019 if (err < 0)
1020 return err;
1021 }
1022 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001023}
1024
Takashi Iwai1d045db2011-07-07 18:23:21 +02001025/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001026static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1027{
1028 int i;
1029 for (i = 0; i < nums; i++)
1030 if (list[i] == nid)
1031 return i;
1032 return -1;
1033}
1034
Takashi Iwai1d045db2011-07-07 18:23:21 +02001035/* check whether dynamic ADC-switching is available */
1036static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1037{
1038 struct alc_spec *spec = codec->spec;
1039 struct hda_input_mux *imux = &spec->private_imux[0];
1040 int i, n, idx;
1041 hda_nid_t cap, pin;
1042
1043 if (imux != spec->input_mux) /* no dynamic imux? */
1044 return false;
1045
1046 for (n = 0; n < spec->num_adc_nids; n++) {
1047 cap = spec->private_capsrc_nids[n];
1048 for (i = 0; i < imux->num_items; i++) {
1049 pin = spec->imux_pins[i];
1050 if (!pin)
1051 return false;
1052 if (get_connection_index(codec, cap, pin) < 0)
1053 break;
1054 }
1055 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001056 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001057 }
1058
1059 for (i = 0; i < imux->num_items; i++) {
1060 pin = spec->imux_pins[i];
1061 for (n = 0; n < spec->num_adc_nids; n++) {
1062 cap = spec->private_capsrc_nids[n];
1063 idx = get_connection_index(codec, cap, pin);
1064 if (idx >= 0) {
1065 imux->items[i].index = idx;
1066 spec->dyn_adc_idx[i] = n;
1067 break;
1068 }
1069 }
1070 }
1071
1072 snd_printdd("realtek: enabling ADC switching\n");
1073 spec->dyn_adc_switch = 1;
1074 return true;
1075}
Takashi Iwai21268962011-07-07 15:01:13 +02001076
Takashi Iwai21268962011-07-07 15:01:13 +02001077/* check whether all auto-mic pins are valid; setup indices if OK */
1078static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1079{
1080 struct alc_spec *spec = codec->spec;
1081 const struct hda_input_mux *imux;
1082
1083 if (!spec->auto_mic)
1084 return false;
1085 if (spec->auto_mic_valid_imux)
1086 return true; /* already checked */
1087
1088 /* fill up imux indices */
1089 if (!alc_check_dyn_adc_switch(codec)) {
1090 spec->auto_mic = 0;
1091 return false;
1092 }
1093
1094 imux = spec->input_mux;
1095 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1098 spec->imux_pins, imux->num_items);
1099 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1100 spec->imux_pins, imux->num_items);
1101 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1102 spec->auto_mic = 0;
1103 return false; /* no corresponding imux */
1104 }
1105
David Henningsson29adc4b2012-09-25 11:31:00 +02001106 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1107 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001108 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001109 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1110 ALC_MIC_EVENT,
1111 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001112
1113 spec->auto_mic_valid_imux = 1;
1114 spec->auto_mic = 1;
1115 return true;
1116}
1117
Takashi Iwai1d045db2011-07-07 18:23:21 +02001118/*
1119 * Check the availability of auto-mic switch;
1120 * Set up if really supported
1121 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001122static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001123{
1124 struct alc_spec *spec = codec->spec;
1125 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001126 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001127 int i;
1128
Takashi Iwai24de1832011-11-07 17:13:39 +01001129 if (spec->shared_mic_hp)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001130 return 0; /* no auto-mic for the shared I/O */
Takashi Iwai24de1832011-11-07 17:13:39 +01001131
Takashi Iwai21268962011-07-07 15:01:13 +02001132 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1133
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001134 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001135 for (i = 0; i < cfg->num_inputs; i++) {
1136 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001137 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001138 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001139 switch (snd_hda_get_input_pin_attr(defcfg)) {
1140 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001141 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001142 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001143 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001144 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 fixed = nid;
1146 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001147 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001148 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001149 case INPUT_PIN_ATTR_DOCK:
1150 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001151 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001152 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001153 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001154 dock = nid;
1155 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001156 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001157 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001158 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001159 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001160 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001161 ext = nid;
1162 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001163 }
1164 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001165 if (!ext && dock) {
1166 ext = dock;
1167 dock = 0;
1168 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001169 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001170 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001171 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001172 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001173 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001174 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001175
1176 /* check imux indices */
1177 spec->ext_mic_pin = ext;
1178 spec->int_mic_pin = fixed;
1179 spec->dock_mic_pin = dock;
1180
1181 spec->auto_mic = 1;
1182 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001183 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001184
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001185 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1186 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001187
1188 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001189}
1190
Takashi Iwai1d045db2011-07-07 18:23:21 +02001191/* check the availabilities of auto-mute and auto-mic switches */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001192static int alc_auto_check_switches(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02001193{
Takashi Iwai475c3d22012-11-30 08:31:30 +01001194 int err;
1195
1196 err = alc_init_automute(codec);
1197 if (err < 0)
1198 return err;
1199 err = alc_init_auto_mic(codec);
1200 if (err < 0)
1201 return err;
1202 return 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02001203}
1204
1205/*
1206 * Realtek SSID verification
1207 */
1208
David Henningsson90622912010-10-14 14:50:18 +02001209/* Could be any non-zero and even value. When used as fixup, tells
1210 * the driver to ignore any present sku defines.
1211 */
1212#define ALC_FIXUP_SKU_IGNORE (2)
1213
Takashi Iwai23d30f22012-05-07 17:17:32 +02001214static void alc_fixup_sku_ignore(struct hda_codec *codec,
1215 const struct hda_fixup *fix, int action)
1216{
1217 struct alc_spec *spec = codec->spec;
1218 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1219 spec->cdefine.fixup = 1;
1220 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1221 }
1222}
1223
Kailang Yangda00c242010-03-19 11:23:45 +01001224static int alc_auto_parse_customize_define(struct hda_codec *codec)
1225{
1226 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001227 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001228 struct alc_spec *spec = codec->spec;
1229
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001230 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1231
David Henningsson90622912010-10-14 14:50:18 +02001232 if (spec->cdefine.fixup) {
1233 ass = spec->cdefine.sku_cfg;
1234 if (ass == ALC_FIXUP_SKU_IGNORE)
1235 return -1;
1236 goto do_sku;
1237 }
1238
Kailang Yangda00c242010-03-19 11:23:45 +01001239 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001240 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001241 goto do_sku;
1242
1243 nid = 0x1d;
1244 if (codec->vendor_id == 0x10ec0260)
1245 nid = 0x17;
1246 ass = snd_hda_codec_get_pincfg(codec, nid);
1247
1248 if (!(ass & 1)) {
1249 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1250 codec->chip_name, ass);
1251 return -1;
1252 }
1253
1254 /* check sum */
1255 tmp = 0;
1256 for (i = 1; i < 16; i++) {
1257 if ((ass >> i) & 1)
1258 tmp++;
1259 }
1260 if (((ass >> 16) & 0xf) != tmp)
1261 return -1;
1262
1263 spec->cdefine.port_connectivity = ass >> 30;
1264 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1265 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1266 spec->cdefine.customization = ass >> 8;
1267do_sku:
1268 spec->cdefine.sku_cfg = ass;
1269 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1270 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1271 spec->cdefine.swap = (ass & 0x2) >> 1;
1272 spec->cdefine.override = ass & 0x1;
1273
1274 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1275 nid, spec->cdefine.sku_cfg);
1276 snd_printd("SKU: port_connectivity=0x%x\n",
1277 spec->cdefine.port_connectivity);
1278 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1279 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1280 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1281 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1282 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1283 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1284 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1285
1286 return 0;
1287}
1288
Takashi Iwai1d045db2011-07-07 18:23:21 +02001289/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001290static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1291{
Takashi Iwai21268962011-07-07 15:01:13 +02001292 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001293}
1294
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001295/* check subsystem ID and set up device-specific initialization;
1296 * return 1 if initialized, 0 if invalid SSID
1297 */
1298/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1299 * 31 ~ 16 : Manufacture ID
1300 * 15 ~ 8 : SKU ID
1301 * 7 ~ 0 : Assembly ID
1302 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1303 */
1304static int alc_subsystem_id(struct hda_codec *codec,
1305 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001306 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001307{
1308 unsigned int ass, tmp, i;
1309 unsigned nid;
1310 struct alc_spec *spec = codec->spec;
1311
David Henningsson90622912010-10-14 14:50:18 +02001312 if (spec->cdefine.fixup) {
1313 ass = spec->cdefine.sku_cfg;
1314 if (ass == ALC_FIXUP_SKU_IGNORE)
1315 return 0;
1316 goto do_sku;
1317 }
1318
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001319 ass = codec->subsystem_id & 0xffff;
1320 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1321 goto do_sku;
1322
1323 /* invalid SSID, check the special NID pin defcfg instead */
1324 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001325 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001326 * 29~21 : reserve
1327 * 20 : PCBEEP input
1328 * 19~16 : Check sum (15:1)
1329 * 15~1 : Custom
1330 * 0 : override
1331 */
1332 nid = 0x1d;
1333 if (codec->vendor_id == 0x10ec0260)
1334 nid = 0x17;
1335 ass = snd_hda_codec_get_pincfg(codec, nid);
1336 snd_printd("realtek: No valid SSID, "
1337 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001338 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001339 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001340 return 0;
1341 if ((ass >> 30) != 1) /* no physical connection */
1342 return 0;
1343
1344 /* check sum */
1345 tmp = 0;
1346 for (i = 1; i < 16; i++) {
1347 if ((ass >> i) & 1)
1348 tmp++;
1349 }
1350 if (((ass >> 16) & 0xf) != tmp)
1351 return 0;
1352do_sku:
1353 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1354 ass & 0xffff, codec->vendor_id);
1355 /*
1356 * 0 : override
1357 * 1 : Swap Jack
1358 * 2 : 0 --> Desktop, 1 --> Laptop
1359 * 3~5 : External Amplifier control
1360 * 7~6 : Reserved
1361 */
1362 tmp = (ass & 0x38) >> 3; /* external Amp control */
1363 switch (tmp) {
1364 case 1:
1365 spec->init_amp = ALC_INIT_GPIO1;
1366 break;
1367 case 3:
1368 spec->init_amp = ALC_INIT_GPIO2;
1369 break;
1370 case 7:
1371 spec->init_amp = ALC_INIT_GPIO3;
1372 break;
1373 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001374 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001375 spec->init_amp = ALC_INIT_DEFAULT;
1376 break;
1377 }
1378
1379 /* is laptop or Desktop and enable the function "Mute internal speaker
1380 * when the external headphone out jack is plugged"
1381 */
1382 if (!(ass & 0x8000))
1383 return 1;
1384 /*
1385 * 10~8 : Jack location
1386 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1387 * 14~13: Resvered
1388 * 15 : 1 --> enable the function "Mute internal speaker
1389 * when the external headphone out jack is plugged"
1390 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001391 if (!spec->autocfg.hp_pins[0] &&
1392 !(spec->autocfg.line_out_pins[0] &&
1393 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001394 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001395 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1396 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001397 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001398 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001399 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001400 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001401 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001402 else if (tmp == 3)
1403 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001404 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001405 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001406 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1407 spec->autocfg.line_outs))
1408 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001409 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001410 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001411 return 1;
1412}
Kailang Yangea1fb292008-08-26 12:58:38 +02001413
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001414/* Check the validity of ALC subsystem-id
1415 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1416static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001417{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001418 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001419 struct alc_spec *spec = codec->spec;
1420 snd_printd("realtek: "
1421 "Enable default setup for auto mode as fallback\n");
1422 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001423 }
Takashi Iwai21268962011-07-07 15:01:13 +02001424}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001425
Takashi Iwai41e41f12005-06-08 14:48:49 +02001426/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001427 * COEF access helper functions
1428 */
Kailang Yang274693f2009-12-03 10:07:50 +01001429static int alc_read_coef_idx(struct hda_codec *codec,
1430 unsigned int coef_idx)
1431{
1432 unsigned int val;
1433 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1434 coef_idx);
1435 val = snd_hda_codec_read(codec, 0x20, 0,
1436 AC_VERB_GET_PROC_COEF, 0);
1437 return val;
1438}
1439
Kailang Yang977ddd62010-09-15 10:02:29 +02001440static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1441 unsigned int coef_val)
1442{
1443 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1444 coef_idx);
1445 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1446 coef_val);
1447}
1448
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001449/* a special bypass for COEF 0; read the cached value at the second time */
1450static unsigned int alc_get_coef0(struct hda_codec *codec)
1451{
1452 struct alc_spec *spec = codec->spec;
1453 if (!spec->coef0)
1454 spec->coef0 = alc_read_coef_idx(codec, 0);
1455 return spec->coef0;
1456}
1457
Takashi Iwai1d045db2011-07-07 18:23:21 +02001458/*
1459 * Digital I/O handling
1460 */
1461
Takashi Iwai757899a2010-07-30 10:48:14 +02001462/* set right pin controls for digital I/O */
1463static void alc_auto_init_digital(struct hda_codec *codec)
1464{
1465 struct alc_spec *spec = codec->spec;
1466 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001467 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001468
1469 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1470 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001471 if (!pin)
1472 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001473 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001474 if (!i)
1475 dac = spec->multiout.dig_out_nid;
1476 else
1477 dac = spec->slave_dig_outs[i - 1];
1478 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1479 continue;
1480 snd_hda_codec_write(codec, dac, 0,
1481 AC_VERB_SET_AMP_GAIN_MUTE,
1482 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001483 }
1484 pin = spec->autocfg.dig_in_pin;
1485 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001486 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001487}
1488
1489/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1490static void alc_auto_parse_digital(struct hda_codec *codec)
1491{
1492 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001493 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001494 hda_nid_t dig_nid;
1495
1496 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001497 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001498 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001499 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001500 err = snd_hda_get_connections(codec,
1501 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001502 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001503 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001504 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001505 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001506 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001507 spec->multiout.dig_out_nid = dig_nid;
1508 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1509 } else {
1510 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001511 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001512 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001513 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001514 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001515 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001516 }
1517
1518 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001519 dig_nid = codec->start_nid;
1520 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1521 unsigned int wcaps = get_wcaps(codec, dig_nid);
1522 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1523 continue;
1524 if (!(wcaps & AC_WCAP_DIGITAL))
1525 continue;
1526 if (!(wcaps & AC_WCAP_CONN_LIST))
1527 continue;
1528 err = get_connection_index(codec, dig_nid,
1529 spec->autocfg.dig_in_pin);
1530 if (err >= 0) {
1531 spec->dig_in_nid = dig_nid;
1532 break;
1533 }
1534 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001535 }
1536}
1537
Takashi Iwaif95474e2007-07-10 00:47:43 +02001538/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001539 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001540 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001541static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1542 struct snd_ctl_elem_info *uinfo)
1543{
1544 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1545 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001546 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001547 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001548
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001549 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001550 if (spec->vol_in_capsrc)
1551 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1552 else
1553 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1554 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001555 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001556 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001557 return err;
1558}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001560static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1561 unsigned int size, unsigned int __user *tlv)
1562{
1563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1564 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001565 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001566 int err;
1567
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001568 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001569 if (spec->vol_in_capsrc)
1570 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1571 else
1572 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1573 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001574 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001575 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001576 return err;
1577}
1578
1579typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1580 struct snd_ctl_elem_value *ucontrol);
1581
1582static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1583 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001584 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001585{
1586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1587 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001588 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001589
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001590 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001591 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001592 for (i = 0; i < spec->num_adc_nids; i++) {
1593 kcontrol->private_value =
1594 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1595 3, 0, HDA_INPUT);
1596 err = func(kcontrol, ucontrol);
1597 if (err < 0)
1598 goto error;
1599 }
1600 } else {
1601 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001602 if (spec->vol_in_capsrc)
1603 kcontrol->private_value =
1604 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1605 3, 0, HDA_OUTPUT);
1606 else
1607 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001608 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1609 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001610 err = func(kcontrol, ucontrol);
1611 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001612 if (err >= 0 && is_put)
1613 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001614 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001615 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001616 return err;
1617}
1618
1619static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1621{
1622 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001623 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001624}
1625
1626static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1627 struct snd_ctl_elem_value *ucontrol)
1628{
1629 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001630 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001631}
1632
1633/* capture mixer elements */
1634#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1635
1636static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1637 struct snd_ctl_elem_value *ucontrol)
1638{
1639 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001640 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001641}
1642
1643static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1644 struct snd_ctl_elem_value *ucontrol)
1645{
1646 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001647 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001648}
1649
Takashi Iwaia23b6882009-03-23 15:21:36 +01001650#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001651 { \
1652 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1653 .name = "Capture Switch", \
1654 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1655 .count = num, \
1656 .info = alc_cap_sw_info, \
1657 .get = alc_cap_sw_get, \
1658 .put = alc_cap_sw_put, \
1659 }, \
1660 { \
1661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1662 .name = "Capture Volume", \
1663 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1664 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1665 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1666 .count = num, \
1667 .info = alc_cap_vol_info, \
1668 .get = alc_cap_vol_get, \
1669 .put = alc_cap_vol_put, \
1670 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001671 }
1672
1673#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001674 { \
1675 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1676 /* .name = "Capture Source", */ \
1677 .name = "Input Source", \
1678 .count = num, \
1679 .info = alc_mux_enum_info, \
1680 .get = alc_mux_enum_get, \
1681 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001682 }
1683
1684#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001685static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001686 _DEFINE_CAPMIX(num), \
1687 _DEFINE_CAPSRC(num), \
1688 { } /* end */ \
1689}
1690
1691#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001692static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001693 _DEFINE_CAPMIX(num), \
1694 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001695}
1696
1697/* up to three ADCs */
1698DEFINE_CAPMIX(1);
1699DEFINE_CAPMIX(2);
1700DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001701DEFINE_CAPMIX_NOSRC(1);
1702DEFINE_CAPMIX_NOSRC(2);
1703DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001704
1705/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001706 * Inverted digital-mic handling
1707 *
1708 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1709 * gives the additional mute only to the right channel of the digital mic
1710 * capture stream. This is a workaround for avoiding the almost silence
1711 * by summing the stereo stream from some (known to be ForteMedia)
1712 * digital mic unit.
1713 *
1714 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1715 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1716 * without caching so that the cache can still keep the original value.
1717 * The cached value is then restored when the flag is set off or any other
1718 * than d-mic is used as the current input source.
1719 */
1720static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1721{
1722 struct alc_spec *spec = codec->spec;
1723 int i;
1724
1725 if (!spec->inv_dmic_fixup)
1726 return;
1727 if (!spec->inv_dmic_muted && !force)
1728 return;
1729 for (i = 0; i < spec->num_adc_nids; i++) {
1730 int src = spec->dyn_adc_switch ? 0 : i;
1731 bool dmic_fixup = false;
1732 hda_nid_t nid;
1733 int parm, dir, v;
1734
1735 if (spec->inv_dmic_muted &&
1736 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1737 dmic_fixup = true;
1738 if (!dmic_fixup && !force)
1739 continue;
1740 if (spec->vol_in_capsrc) {
1741 nid = spec->capsrc_nids[i];
1742 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1743 dir = HDA_OUTPUT;
1744 } else {
1745 nid = spec->adc_nids[i];
1746 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1747 dir = HDA_INPUT;
1748 }
1749 /* we care only right channel */
1750 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1751 if (v & 0x80) /* if already muted, we don't need to touch */
1752 continue;
1753 if (dmic_fixup) /* add mute for d-mic */
1754 v |= 0x80;
1755 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1756 parm | v);
1757 }
1758}
1759
1760static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1761 struct snd_ctl_elem_value *ucontrol)
1762{
1763 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1764 struct alc_spec *spec = codec->spec;
1765
1766 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1767 return 0;
1768}
1769
1770static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1771 struct snd_ctl_elem_value *ucontrol)
1772{
1773 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1774 struct alc_spec *spec = codec->spec;
1775 unsigned int val = !ucontrol->value.integer.value[0];
1776
1777 if (val == spec->inv_dmic_muted)
1778 return 0;
1779 spec->inv_dmic_muted = val;
1780 alc_inv_dmic_sync(codec, true);
1781 return 0;
1782}
1783
1784static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1786 .info = snd_ctl_boolean_mono_info,
1787 .get = alc_inv_dmic_sw_get,
1788 .put = alc_inv_dmic_sw_put,
1789};
1790
1791static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1792{
1793 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001794
1795 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1796 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001797 return -ENOMEM;
1798 spec->inv_dmic_fixup = 1;
1799 spec->inv_dmic_muted = 0;
1800 spec->inv_dmic_pin = nid;
1801 return 0;
1802}
1803
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001804/* typically the digital mic is put at node 0x12 */
1805static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1806 const struct alc_fixup *fix, int action)
1807{
1808 if (action == ALC_FIXUP_ACT_PROBE)
1809 alc_add_inv_dmic_mixer(codec, 0x12);
1810}
1811
Takashi Iwai125821a2012-06-22 14:30:29 +02001812/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001813 * virtual master controls
1814 */
1815
1816/*
1817 * slave controls for virtual master
1818 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001819static const char * const alc_slave_pfxs[] = {
1820 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001821 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001822 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001823 NULL,
1824};
1825
1826/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001827 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001829
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001830#define NID_MAPPING (-1)
1831
1832#define SUBDEV_SPEAKER_ (0 << 6)
1833#define SUBDEV_HP_ (1 << 6)
1834#define SUBDEV_LINE_ (2 << 6)
1835#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1836#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1837#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1838
Takashi Iwai603c4012008-07-30 15:01:44 +02001839static void alc_free_kctls(struct hda_codec *codec);
1840
Takashi Iwai67d634c2009-11-16 15:35:59 +01001841#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001842/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001843static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001844 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001845 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001846 { } /* end */
1847};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001848#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001849
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001850static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851{
1852 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001853 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001854 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001855 int i, j, err;
1856 unsigned int u;
1857 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
1859 for (i = 0; i < spec->num_mixers; i++) {
1860 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1861 if (err < 0)
1862 return err;
1863 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001864 if (spec->cap_mixer) {
1865 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1866 if (err < 0)
1867 return err;
1868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001870 err = snd_hda_create_dig_out_ctls(codec,
1871 spec->multiout.dig_out_nid,
1872 spec->multiout.dig_out_nid,
1873 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 if (err < 0)
1875 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001876 if (!spec->no_analog) {
1877 err = snd_hda_create_spdif_share_sw(codec,
1878 &spec->multiout);
1879 if (err < 0)
1880 return err;
1881 spec->multiout.share_spdif = 1;
1882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 }
1884 if (spec->dig_in_nid) {
1885 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1886 if (err < 0)
1887 return err;
1888 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001889
Takashi Iwai67d634c2009-11-16 15:35:59 +01001890#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001891 /* create beep controls if needed */
1892 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001893 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001894 for (knew = alc_beep_mixer; knew->name; knew++) {
1895 struct snd_kcontrol *kctl;
1896 kctl = snd_ctl_new1(knew, codec);
1897 if (!kctl)
1898 return -ENOMEM;
1899 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001900 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001901 if (err < 0)
1902 return err;
1903 }
1904 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001905#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001906
Takashi Iwai2134ea42008-01-10 16:53:55 +01001907 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001908 if (!spec->no_analog &&
1909 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001910 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001911 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001912 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001913 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001914 vmaster_tlv, alc_slave_pfxs,
1915 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001916 if (err < 0)
1917 return err;
1918 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001919 if (!spec->no_analog &&
1920 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001921 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1922 NULL, alc_slave_pfxs,
1923 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001924 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001925 if (err < 0)
1926 return err;
1927 }
1928
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001929 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001930 if (spec->capsrc_nids || spec->adc_nids) {
1931 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1932 if (!kctl)
1933 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1934 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001935 err = snd_hda_add_nid(codec, kctl, i,
1936 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001937 if (err < 0)
1938 return err;
1939 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001940 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001941 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001942 const char *kname = kctl ? kctl->id.name : NULL;
1943 for (knew = spec->cap_mixer; knew->name; knew++) {
1944 if (kname && strcmp(knew->name, kname) == 0)
1945 continue;
1946 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1947 for (i = 0; kctl && i < kctl->count; i++) {
1948 err = snd_hda_add_nid(codec, kctl, i,
1949 spec->adc_nids[i]);
1950 if (err < 0)
1951 return err;
1952 }
1953 }
1954 }
1955
1956 /* other nid->control mapping */
1957 for (i = 0; i < spec->num_mixers; i++) {
1958 for (knew = spec->mixers[i]; knew->name; knew++) {
1959 if (knew->iface != NID_MAPPING)
1960 continue;
1961 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1962 if (kctl == NULL)
1963 continue;
1964 u = knew->subdevice;
1965 for (j = 0; j < 4; j++, u >>= 8) {
1966 nid = u & 0x3f;
1967 if (nid == 0)
1968 continue;
1969 switch (u & 0xc0) {
1970 case SUBDEV_SPEAKER_:
1971 nid = spec->autocfg.speaker_pins[nid];
1972 break;
1973 case SUBDEV_LINE_:
1974 nid = spec->autocfg.line_out_pins[nid];
1975 break;
1976 case SUBDEV_HP_:
1977 nid = spec->autocfg.hp_pins[nid];
1978 break;
1979 default:
1980 continue;
1981 }
1982 err = snd_hda_add_nid(codec, kctl, 0, nid);
1983 if (err < 0)
1984 return err;
1985 }
1986 u = knew->private_value;
1987 for (j = 0; j < 4; j++, u >>= 8) {
1988 nid = u & 0xff;
1989 if (nid == 0)
1990 continue;
1991 err = snd_hda_add_nid(codec, kctl, 0, nid);
1992 if (err < 0)
1993 return err;
1994 }
1995 }
1996 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001997
1998 alc_free_kctls(codec); /* no longer needed */
1999
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002000 return 0;
2001}
2002
David Henningsson5780b622012-06-27 18:45:45 +02002003static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002004{
2005 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02002006
2007 if (spec->shared_mic_hp) {
2008 int err;
2009 int nid = spec->autocfg.inputs[1].pin;
2010 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
2011 if (err < 0)
2012 return err;
2013 err = snd_hda_jack_detect_enable(codec, nid, 0);
2014 if (err < 0)
2015 return err;
2016 }
2017
2018 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2019}
2020
2021static int alc_build_controls(struct hda_codec *codec)
2022{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002023 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002024 if (err < 0)
2025 return err;
David Henningsson5780b622012-06-27 18:45:45 +02002026
2027 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002028 if (err < 0)
2029 return err;
2030 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2031 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032}
2033
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002034
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002036 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002037 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002038
Takashi Iwai584c0c42011-03-10 12:51:11 +01002039static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002040static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042static int alc_init(struct hda_codec *codec)
2043{
2044 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002045
Takashi Iwai546bb672012-03-07 08:37:19 +01002046 if (spec->init_hook)
2047 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002048
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002049 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002050 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002051
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002052 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002053 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002054 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002055
Takashi Iwai58701122011-01-13 15:41:45 +01002056 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2057
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002058 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 return 0;
2060}
2061
Takashi Iwai83012a72012-08-24 18:38:08 +02002062#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002063static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2064{
2065 struct alc_spec *spec = codec->spec;
2066 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2067}
2068#endif
2069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070/*
2071 * Analog playback callbacks
2072 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002073static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002075 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
2077 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002078 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2079 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080}
2081
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002082static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 struct hda_codec *codec,
2084 unsigned int stream_tag,
2085 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002086 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
2088 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002089 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2090 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002093static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002095 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
2097 struct alc_spec *spec = codec->spec;
2098 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2099}
2100
2101/*
2102 * Digital out
2103 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002104static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002106 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 struct alc_spec *spec = codec->spec;
2109 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2110}
2111
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002112static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002113 struct hda_codec *codec,
2114 unsigned int stream_tag,
2115 unsigned int format,
2116 struct snd_pcm_substream *substream)
2117{
2118 struct alc_spec *spec = codec->spec;
2119 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2120 stream_tag, format, substream);
2121}
2122
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002123static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002124 struct hda_codec *codec,
2125 struct snd_pcm_substream *substream)
2126{
2127 struct alc_spec *spec = codec->spec;
2128 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2129}
2130
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002131static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002133 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
2135 struct alc_spec *spec = codec->spec;
2136 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2137}
2138
2139/*
2140 * Analog capture
2141 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002142static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct hda_codec *codec,
2144 unsigned int stream_tag,
2145 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002146 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147{
2148 struct alc_spec *spec = codec->spec;
2149
Takashi Iwai63300792008-01-24 15:31:36 +01002150 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 stream_tag, 0, format);
2152 return 0;
2153}
2154
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002155static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002157 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
2159 struct alc_spec *spec = codec->spec;
2160
Takashi Iwai888afa12008-03-18 09:57:50 +01002161 snd_hda_codec_cleanup_stream(codec,
2162 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 return 0;
2164}
2165
Takashi Iwai840b64c2010-07-13 22:49:01 +02002166/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002167static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002168 struct hda_codec *codec,
2169 unsigned int stream_tag,
2170 unsigned int format,
2171 struct snd_pcm_substream *substream)
2172{
2173 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002174 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002175 spec->cur_adc_stream_tag = stream_tag;
2176 spec->cur_adc_format = format;
2177 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2178 return 0;
2179}
2180
Takashi Iwai21268962011-07-07 15:01:13 +02002181static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002182 struct hda_codec *codec,
2183 struct snd_pcm_substream *substream)
2184{
2185 struct alc_spec *spec = codec->spec;
2186 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2187 spec->cur_adc = 0;
2188 return 0;
2189}
2190
Takashi Iwai21268962011-07-07 15:01:13 +02002191static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002192 .substreams = 1,
2193 .channels_min = 2,
2194 .channels_max = 2,
2195 .nid = 0, /* fill later */
2196 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002197 .prepare = dyn_adc_capture_pcm_prepare,
2198 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002199 },
2200};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
2202/*
2203 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002204static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 .substreams = 1,
2206 .channels_min = 2,
2207 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002208 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002210 .open = alc_playback_pcm_open,
2211 .prepare = alc_playback_pcm_prepare,
2212 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 },
2214};
2215
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002216static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002217 .substreams = 1,
2218 .channels_min = 2,
2219 .channels_max = 2,
2220 /* NID is set in alc_build_pcms */
2221};
2222
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002223static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002224 .substreams = 1,
2225 .channels_min = 2,
2226 .channels_max = 2,
2227 /* NID is set in alc_build_pcms */
2228};
2229
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002230static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002231 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 .channels_min = 2,
2233 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002234 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002236 .prepare = alc_alt_capture_pcm_prepare,
2237 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 },
2239};
2240
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002241static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 .substreams = 1,
2243 .channels_min = 2,
2244 .channels_max = 2,
2245 /* NID is set in alc_build_pcms */
2246 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002247 .open = alc_dig_playback_pcm_open,
2248 .close = alc_dig_playback_pcm_close,
2249 .prepare = alc_dig_playback_pcm_prepare,
2250 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 },
2252};
2253
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002254static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 .substreams = 1,
2256 .channels_min = 2,
2257 .channels_max = 2,
2258 /* NID is set in alc_build_pcms */
2259};
2260
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002261/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002262static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002263 .substreams = 0,
2264 .channels_min = 0,
2265 .channels_max = 0,
2266};
2267
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268static int alc_build_pcms(struct hda_codec *codec)
2269{
2270 struct alc_spec *spec = codec->spec;
2271 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002272 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002273 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 int i;
2275
2276 codec->num_pcms = 1;
2277 codec->pcm_info = info;
2278
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002279 if (spec->no_analog)
2280 goto skip_analog;
2281
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002282 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2283 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002285
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002286 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002287 p = spec->stream_analog_playback;
2288 if (!p)
2289 p = &alc_pcm_analog_playback;
2290 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002291 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002292 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2293 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002294 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2295 spec->autocfg.line_outs == 2)
2296 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2297 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002298 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002299 if (spec->adc_nids) {
2300 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002301 if (!p) {
2302 if (spec->dyn_adc_switch)
2303 p = &dyn_adc_pcm_analog_capture;
2304 else
2305 p = &alc_pcm_analog_capture;
2306 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002307 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002308 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Takashi Iwai4a471b72005-12-07 13:56:29 +01002311 if (spec->channel_mode) {
2312 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2313 for (i = 0; i < spec->num_channel_mode; i++) {
2314 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2315 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 }
2318 }
2319
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002320 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002321 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002323 snprintf(spec->stream_name_digital,
2324 sizeof(spec->stream_name_digital),
2325 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002326 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002327 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002328 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002330 if (spec->dig_out_type)
2331 info->pcm_type = spec->dig_out_type;
2332 else
2333 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002334 if (spec->multiout.dig_out_nid) {
2335 p = spec->stream_digital_playback;
2336 if (!p)
2337 p = &alc_pcm_digital_playback;
2338 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2340 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002341 if (spec->dig_in_nid) {
2342 p = spec->stream_digital_capture;
2343 if (!p)
2344 p = &alc_pcm_digital_capture;
2345 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2347 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002348 /* FIXME: do we need this for all Realtek codec models? */
2349 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 }
2351
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002352 if (spec->no_analog)
2353 return 0;
2354
Takashi Iwaie08a0072006-09-07 17:52:14 +02002355 /* If the use of more than one ADC is requested for the current
2356 * model, configure a second analog capture-only PCM.
2357 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002358 have_multi_adcs = (spec->num_adc_nids > 1) &&
2359 !spec->dyn_adc_switch && !spec->auto_mic &&
2360 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002361 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002362 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002363 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002364 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002365 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002366 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002367 p = spec->stream_analog_alt_playback;
2368 if (!p)
2369 p = &alc_pcm_analog_alt_playback;
2370 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002371 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2372 spec->alt_dac_nid;
2373 } else {
2374 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2375 alc_pcm_null_stream;
2376 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2377 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002378 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002379 p = spec->stream_analog_alt_capture;
2380 if (!p)
2381 p = &alc_pcm_analog_alt_capture;
2382 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002383 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2384 spec->adc_nids[1];
2385 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2386 spec->num_adc_nids - 1;
2387 } else {
2388 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2389 alc_pcm_null_stream;
2390 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002391 }
2392 }
2393
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 return 0;
2395}
2396
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002397static inline void alc_shutup(struct hda_codec *codec)
2398{
Takashi Iwai1c716152011-04-07 10:37:16 +02002399 struct alc_spec *spec = codec->spec;
2400
2401 if (spec && spec->shutup)
2402 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002403 snd_hda_shutup_pins(codec);
2404}
2405
Takashi Iwai603c4012008-07-30 15:01:44 +02002406static void alc_free_kctls(struct hda_codec *codec)
2407{
2408 struct alc_spec *spec = codec->spec;
2409
2410 if (spec->kctls.list) {
2411 struct snd_kcontrol_new *kctl = spec->kctls.list;
2412 int i;
2413 for (i = 0; i < spec->kctls.used; i++)
2414 kfree(kctl[i].name);
2415 }
2416 snd_array_free(&spec->kctls);
2417}
2418
Takashi Iwai23c09b02011-08-19 09:05:35 +02002419static void alc_free_bind_ctls(struct hda_codec *codec)
2420{
2421 struct alc_spec *spec = codec->spec;
2422 if (spec->bind_ctls.list) {
2423 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2424 int i;
2425 for (i = 0; i < spec->bind_ctls.used; i++)
2426 kfree(ctl[i]);
2427 }
2428 snd_array_free(&spec->bind_ctls);
2429}
2430
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431static void alc_free(struct hda_codec *codec)
2432{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002433 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002434
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002435 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002436 return;
2437
Takashi Iwai603c4012008-07-30 15:01:44 +02002438 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002439 alc_free_bind_ctls(codec);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002440 snd_array_free(&spec->out_path);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002441 snd_array_free(&spec->in_path);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002442 snd_array_free(&spec->loopback_path);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002443 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002444 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002445 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446}
2447
Takashi Iwai83012a72012-08-24 18:38:08 +02002448#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002449static void alc_power_eapd(struct hda_codec *codec)
2450{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002451 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002452}
2453
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002454static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002455{
2456 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002457 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002458 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002459 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002460 return 0;
2461}
2462#endif
2463
Takashi Iwai2a439522011-07-26 09:52:50 +02002464#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002465static int alc_resume(struct hda_codec *codec)
2466{
Takashi Iwai1c716152011-04-07 10:37:16 +02002467 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002468 codec->patch_ops.init(codec);
2469 snd_hda_codec_resume_amp(codec);
2470 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002471 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002472 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002473 return 0;
2474}
Takashi Iwaie044c392008-10-27 16:56:24 +01002475#endif
2476
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477/*
2478 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002479static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 .build_controls = alc_build_controls,
2481 .build_pcms = alc_build_pcms,
2482 .init = alc_init,
2483 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002484 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002485#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002486 .resume = alc_resume,
2487#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002488#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002489 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002490 .check_power_status = alc_check_power_status,
2491#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002492 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493};
2494
David Henningsson29adc4b2012-09-25 11:31:00 +02002495
Kailang Yangc027ddc2010-03-19 11:33:06 +01002496/* replace the codec chip_name with the given string */
2497static int alc_codec_rename(struct hda_codec *codec, const char *name)
2498{
2499 kfree(codec->chip_name);
2500 codec->chip_name = kstrdup(name, GFP_KERNEL);
2501 if (!codec->chip_name) {
2502 alc_free(codec);
2503 return -ENOMEM;
2504 }
2505 return 0;
2506}
2507
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002508/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002509 * Rename codecs appropriately from COEF value
2510 */
2511struct alc_codec_rename_table {
2512 unsigned int vendor_id;
2513 unsigned short coef_mask;
2514 unsigned short coef_bits;
2515 const char *name;
2516};
2517
2518static struct alc_codec_rename_table rename_tbl[] = {
2519 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2520 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2521 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2522 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2523 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2524 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2525 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002526 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002527 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2528 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2529 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2530 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2531 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2532 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2533 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2534 { } /* terminator */
2535};
2536
2537static int alc_codec_rename_from_preset(struct hda_codec *codec)
2538{
2539 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002540
2541 for (p = rename_tbl; p->vendor_id; p++) {
2542 if (p->vendor_id != codec->vendor_id)
2543 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002544 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002545 return alc_codec_rename(codec, p->name);
2546 }
2547 return 0;
2548}
2549
2550/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002551 * Automatic parse of I/O pins from the BIOS configuration
2552 */
2553
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002554enum {
2555 ALC_CTL_WIDGET_VOL,
2556 ALC_CTL_WIDGET_MUTE,
2557 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002558 ALC_CTL_BIND_VOL,
2559 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002560};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002561static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002562 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2563 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002564 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002565 HDA_BIND_VOL(NULL, 0),
2566 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002567};
2568
2569/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002570static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002571 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002572{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002573 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002574
Takashi Iwai668d1e92012-11-29 14:10:17 +01002575 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002576 if (!knew)
2577 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002578 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002579 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002580 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002581 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002582 return 0;
2583}
2584
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002585static int add_control_with_pfx(struct alc_spec *spec, int type,
2586 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002587 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002588{
2589 char name[32];
2590 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002591 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002592}
2593
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002594#define add_pb_vol_ctrl(spec, type, pfx, val) \
2595 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2596#define add_pb_sw_ctrl(spec, type, pfx, val) \
2597 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2598#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2599 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2600#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2601 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002602
Takashi Iwai23c09b02011-08-19 09:05:35 +02002603static const char * const channel_name[4] = {
2604 "Front", "Surround", "CLFE", "Side"
2605};
2606
Takashi Iwai6843ca12011-06-24 11:03:58 +02002607static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2608 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002609{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002610 struct auto_pin_cfg *cfg = &spec->autocfg;
2611
Takashi Iwai6843ca12011-06-24 11:03:58 +02002612 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002613 if (cfg->line_outs == 1 && !spec->multi_ios &&
2614 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002615 return "Master";
2616
2617 switch (cfg->line_out_type) {
2618 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002619 if (cfg->line_outs == 1)
2620 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002621 if (cfg->line_outs == 2)
2622 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002623 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002624 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002625 /* for multi-io case, only the primary out */
2626 if (ch && spec->multi_ios)
2627 break;
2628 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002629 return "Headphone";
2630 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002631 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002632 return "PCM";
2633 break;
2634 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002635 if (ch >= ARRAY_SIZE(channel_name)) {
2636 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002637 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002638 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002639
2640 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002641}
2642
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002643static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2644 hda_nid_t to_nid, int with_aa_mix,
2645 struct nid_path *path);
2646
Takashi Iwai83012a72012-08-24 18:38:08 +02002647#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002648/* add the powersave loopback-list entry */
2649static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2650{
2651 struct hda_amp_list *list;
2652
2653 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2654 return;
2655 list = spec->loopback_list + spec->num_loopbacks;
2656 list->nid = mix;
2657 list->dir = HDA_INPUT;
2658 list->idx = idx;
2659 spec->num_loopbacks++;
2660 spec->loopback.amplist = spec->loopback_list;
2661}
2662#else
2663#define add_loopback_list(spec, mix, idx) /* NOP */
2664#endif
2665
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002666/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002667static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002668 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002669 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002670{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002671 struct alc_spec *spec = codec->spec;
2672 struct nid_path *path;
2673 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002674
Takashi Iwaibd32f782012-12-12 18:08:52 +01002675 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2676 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2677 return 0; /* no need for analog loopback */
2678
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002679 path = snd_array_new(&spec->loopback_path);
2680 if (!path)
2681 return -ENOMEM;
2682 memset(path, 0, sizeof(*path));
2683 if (!parse_nid_path(codec, pin, mix_nid, 2, path))
2684 return -EINVAL;
2685
2686 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002687 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
2688 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002689 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002690 if (err < 0)
2691 return err;
2692 }
2693
2694 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
2695 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002696 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002697 if (err < 0)
2698 return err;
2699 }
2700
Takashi Iwai164f73e2012-02-21 11:27:09 +01002701 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002702 return 0;
2703}
2704
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002705static int new_capture_source(struct hda_codec *codec, int adc_idx,
2706 hda_nid_t pin, int idx, const char *label)
2707{
2708 struct alc_spec *spec = codec->spec;
2709 struct hda_input_mux *imux = &spec->private_imux[0];
2710 struct nid_path *path;
2711
2712 path = snd_array_new(&spec->in_path);
2713 if (!path)
2714 return -ENOMEM;
2715 memset(path, 0, sizeof(*path));
2716 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2717 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2718 pin, spec->adc_nids[adc_idx]);
2719 return -EINVAL;
2720 }
2721
2722 spec->imux_pins[imux->num_items] = pin;
2723 snd_hda_add_imux_item(imux, label, idx, NULL);
2724 return 0;
2725}
2726
Takashi Iwai05f5f472009-08-25 13:10:18 +02002727static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002728{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002729 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2730 return (pincap & AC_PINCAP_IN) != 0;
2731}
2732
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002733/* check whether the given two widgets can be connected */
2734static bool is_reachable_path(struct hda_codec *codec,
2735 hda_nid_t from_nid, hda_nid_t to_nid)
2736{
2737 if (!from_nid || !to_nid)
2738 return false;
2739 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2740}
2741
Takashi Iwai1d045db2011-07-07 18:23:21 +02002742/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002743static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002744{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002745 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002746 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002747 hda_nid_t *adc_nids = spec->private_adc_nids;
2748 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2749 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002750 int i, nums = 0;
2751
2752 nid = codec->start_nid;
2753 for (i = 0; i < codec->num_nodes; i++, nid++) {
2754 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002755 unsigned int caps = get_wcaps(codec, nid);
2756 int type = get_wcaps_type(caps);
2757
2758 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2759 continue;
2760 adc_nids[nums] = nid;
2761 cap_nids[nums] = nid;
2762 src = nid;
2763 for (;;) {
2764 int n;
2765 type = get_wcaps_type(get_wcaps(codec, src));
2766 if (type == AC_WID_PIN)
2767 break;
2768 if (type == AC_WID_AUD_SEL) {
2769 cap_nids[nums] = src;
2770 break;
2771 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002772 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002773 if (n > 1) {
2774 cap_nids[nums] = src;
2775 break;
2776 } else if (n != 1)
2777 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002778 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2779 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002780 }
2781 if (++nums >= max_nums)
2782 break;
2783 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002784 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002785 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002786 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002787 return nums;
2788}
2789
Takashi Iwai05f5f472009-08-25 13:10:18 +02002790/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002791static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002792{
2793 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002794 const struct auto_pin_cfg *cfg = &spec->autocfg;
2795 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002796 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002797 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002798 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002799 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002800
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002801 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002802 if (num_adcs < 0)
2803 return 0;
2804
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002805 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002806 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002807 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002808
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002809 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002810 if (!alc_is_input_pin(codec, pin))
2811 continue;
2812
David Henningsson5322bf22011-01-05 11:03:56 +01002813 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002814 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2815 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002816 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002817 type_idx++;
2818 else
2819 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002820 prev_label = label;
2821
Takashi Iwai05f5f472009-08-25 13:10:18 +02002822 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002823 if (is_reachable_path(codec, pin, mixer)) {
2824 err = new_analog_input(codec, pin,
2825 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002826 if (err < 0)
2827 return err;
2828 }
2829 }
2830
Takashi Iwaib7821702011-07-06 15:12:46 +02002831 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002832 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002833 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002834 if (idx >= 0) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002835 err = new_capture_source(codec, c, pin, idx, label);
2836 if (err < 0)
2837 return err;
Takashi Iwaib7821702011-07-06 15:12:46 +02002838 break;
2839 }
2840 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002841 }
Takashi Iwai21268962011-07-07 15:01:13 +02002842
2843 spec->num_mux_defs = 1;
2844 spec->input_mux = imux;
2845
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002846 return 0;
2847}
2848
Takashi Iwai24de1832011-11-07 17:13:39 +01002849/* create a shared input with the headphone out */
2850static int alc_auto_create_shared_input(struct hda_codec *codec)
2851{
2852 struct alc_spec *spec = codec->spec;
2853 struct auto_pin_cfg *cfg = &spec->autocfg;
2854 unsigned int defcfg;
2855 hda_nid_t nid;
2856
2857 /* only one internal input pin? */
2858 if (cfg->num_inputs != 1)
2859 return 0;
2860 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2861 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2862 return 0;
2863
2864 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2865 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2866 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2867 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2868 else
2869 return 0; /* both not available */
2870
2871 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2872 return 0; /* no input */
2873
2874 cfg->inputs[1].pin = nid;
2875 cfg->inputs[1].type = AUTO_PIN_MIC;
2876 cfg->num_inputs = 2;
2877 spec->shared_mic_hp = 1;
2878 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2879 return 0;
2880}
2881
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002882static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2883 unsigned int pin_type)
2884{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002885 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002886 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002887 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2888 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002889 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002890}
2891
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002892static int get_pin_type(int line_out_type)
2893{
2894 if (line_out_type == AUTO_PIN_HP_OUT)
2895 return PIN_HP;
2896 else
2897 return PIN_OUT;
2898}
2899
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002900static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002901{
2902 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002903 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002904 int i;
2905
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002906 for (i = 0; i < cfg->num_inputs; i++) {
2907 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002908 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002909 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002910 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002911 snd_hda_codec_write(codec, nid, 0,
2912 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002913 AMP_OUT_MUTE);
2914 }
2915 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002916
2917 /* mute all loopback inputs */
2918 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002919 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002920 for (i = 0; i < nums; i++)
2921 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2922 AC_VERB_SET_AMP_GAIN_MUTE,
2923 AMP_IN_MUTE(i));
2924 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002925}
2926
Takashi Iwai185d99f2012-02-16 18:39:45 +01002927static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2928{
2929 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002930 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002931
2932 for (i = 0; i < spec->out_path.used; i++) {
2933 struct nid_path *path = snd_array_elem(&spec->out_path, i);
2934 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002935 return true;
2936 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002937 return false;
2938}
2939
Takashi Iwai07b18f62011-11-10 15:42:54 +01002940/* check whether the DAC is reachable from the pin */
2941static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2942 hda_nid_t pin, hda_nid_t dac)
2943{
Takashi Iwaidc31b582012-02-17 17:27:53 +01002944 if (!pin || !dac)
2945 return false;
Takashi Iwai6a84c302012-12-05 14:08:45 +01002946 return snd_hda_get_conn_index(codec, pin, dac, true) >= 0;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002947}
2948
Takashi Iwai463419d2012-12-05 14:17:37 +01002949/* look for an empty DAC slot */
2950static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2951{
2952 struct alc_spec *spec = codec->spec;
2953 int i;
2954
2955 for (i = 0; i < spec->num_all_dacs; i++) {
2956 hda_nid_t nid = spec->all_dacs[i];
2957 if (!nid || alc_is_dac_already_used(codec, nid))
2958 continue;
2959 if (alc_auto_is_dac_reachable(codec, pin, nid))
2960 return nid;
2961 }
2962 return 0;
2963}
2964
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002965/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002966static bool __parse_nid_path(struct hda_codec *codec,
2967 hda_nid_t from_nid, hda_nid_t to_nid,
2968 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002969{
2970 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002971 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002972 int i, nums;
2973
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002974 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002975 if (!with_aa_mix)
2976 return false;
2977 with_aa_mix = 2; /* mark aa-mix is included */
2978 }
2979
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002980 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002981 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002982 if (conn[i] != from_nid) {
2983 /* special case: when from_nid is 0,
2984 * try to find an empty DAC
2985 */
2986 if (from_nid ||
2987 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2988 alc_is_dac_already_used(codec, conn[i]))
2989 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002990 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002991 /* aa-mix is requested but not included? */
2992 if (!(spec->mixer_nid && with_aa_mix == 1))
2993 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002994 }
2995 if (depth >= MAX_NID_PATH_DEPTH)
2996 return false;
2997 for (i = 0; i < nums; i++) {
2998 unsigned int type;
2999 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003000 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
3001 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003002 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003003 if (__parse_nid_path(codec, from_nid, conn[i],
3004 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003005 goto found;
3006 }
3007 return false;
3008
3009 found:
3010 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01003011 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003012 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01003013 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003014 path->depth++;
3015 return true;
3016}
3017
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003018/* parse the widget path from the given nid to the target nid;
3019 * when @from_nid is 0, try to find an empty DAC;
3020 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
3021 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
3022 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003023 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003024static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
3025 hda_nid_t to_nid, int with_aa_mix,
3026 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003027{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003028 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
3029 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003030 path->depth++;
3031#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003032 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003033 path->depth, path->path[0], path->path[1],
3034 path->path[2], path->path[3], path->path[4]);
3035#endif
3036 return true;
3037 }
3038 return false;
3039}
3040
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003041static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3042{
Takashi Iwai140547e2012-02-16 17:23:46 +01003043 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01003044 int i;
3045 hda_nid_t nid_found = 0;
3046
3047 for (i = 0; i < spec->num_all_dacs; i++) {
3048 hda_nid_t nid = spec->all_dacs[i];
3049 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003050 continue;
Takashi Iwai463419d2012-12-05 14:17:37 +01003051 if (alc_auto_is_dac_reachable(codec, pin, nid)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003052 if (nid_found)
3053 return 0;
3054 nid_found = nid;
3055 }
3056 }
3057 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003058}
3059
Takashi Iwaiba8111272012-12-06 18:06:23 +01003060static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003061{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003062 struct alc_spec *spec = codec->spec;
3063 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003064
Takashi Iwaiba8111272012-12-06 18:06:23 +01003065 for (i = 0; i < spec->out_path.used; i++) {
3066 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3067 if (path->ctls[type] == val)
3068 return true;
3069 }
3070 return false;
3071}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003072
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003073/* badness definition */
3074enum {
3075 /* No primary DAC is found for the main output */
3076 BAD_NO_PRIMARY_DAC = 0x10000,
3077 /* No DAC is found for the extra output */
3078 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003079 /* No possible multi-ios */
3080 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003081 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003082 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003083 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003084 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003085 /* Primary DAC shared with main surrounds */
3086 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003087 /* Primary DAC shared with main CLFE */
3088 BAD_SHARED_CLFE = 0x10,
3089 /* Primary DAC shared with extra surrounds */
3090 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003091 /* Volume widget is shared */
3092 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003093};
3094
3095static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003096 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003097static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003098 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003099
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003100static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3101 hda_nid_t dac)
3102{
3103 struct alc_spec *spec = codec->spec;
3104 struct nid_path *path;
3105
3106 path = snd_array_new(&spec->out_path);
3107 if (!path)
3108 return false;
3109 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003110 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003111 return true;
3112 /* push back */
3113 spec->out_path.used--;
3114 return false;
3115}
3116
Takashi Iwaiba8111272012-12-06 18:06:23 +01003117/* get the path pointing from the given dac to pin;
3118 * passing 0 to either @pin or @dac behaves as a wildcard
3119 */
3120static struct nid_path *get_out_path(struct hda_codec *codec, hda_nid_t pin,
3121 hda_nid_t dac)
3122{
3123 struct alc_spec *spec = codec->spec;
3124 int i;
3125
3126 for (i = 0; i < spec->out_path.used; i++) {
3127 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3128 if (path->depth <= 0)
3129 continue;
3130 if ((!dac || path->path[0] == dac) &&
3131 (!pin || path->path[path->depth - 1] == pin))
3132 return path;
3133 }
3134 return NULL;
3135}
3136
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003137/* look for widgets in the path between the given NIDs appropriate for
3138 * volume and mute controls, and assign the values to ctls[].
3139 *
3140 * When no appropriate widget is found in the path, the badness value
3141 * is incremented depending on the situation. The function returns the
3142 * total badness for both volume and mute controls.
3143 */
3144static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3145 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003146{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003147 struct nid_path *path = get_out_path(codec, pin, dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003148 hda_nid_t nid;
3149 unsigned int val;
3150 int badness = 0;
3151
Takashi Iwaiba8111272012-12-06 18:06:23 +01003152 if (!path)
3153 return BAD_SHARED_VOL * 2;
3154 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003155 if (nid) {
3156 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003157 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003158 badness += BAD_SHARED_VOL;
3159 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003160 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003161 } else
3162 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003163 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003164 if (nid) {
3165 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003166 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3167 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003168 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3169 else
3170 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003171 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003172 badness += BAD_SHARED_VOL;
3173 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003174 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003175 } else
3176 badness += BAD_SHARED_VOL;
3177 return badness;
3178}
3179
Takashi Iwaidc31b582012-02-17 17:27:53 +01003180struct badness_table {
3181 int no_primary_dac; /* no primary DAC */
3182 int no_dac; /* no secondary DACs */
3183 int shared_primary; /* primary DAC is shared with main output */
3184 int shared_surr; /* secondary DAC shared with main or primary */
3185 int shared_clfe; /* third DAC shared with main or primary */
3186 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3187};
3188
3189static struct badness_table main_out_badness = {
3190 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3191 .no_dac = BAD_NO_DAC,
3192 .shared_primary = BAD_NO_PRIMARY_DAC,
3193 .shared_surr = BAD_SHARED_SURROUND,
3194 .shared_clfe = BAD_SHARED_CLFE,
3195 .shared_surr_main = BAD_SHARED_SURROUND,
3196};
3197
3198static struct badness_table extra_out_badness = {
3199 .no_primary_dac = BAD_NO_DAC,
3200 .no_dac = BAD_NO_DAC,
3201 .shared_primary = BAD_NO_EXTRA_DAC,
3202 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3203 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3204 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3205};
3206
3207/* try to assign DACs to pins and return the resultant badness */
3208static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3209 const hda_nid_t *pins, hda_nid_t *dacs,
3210 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003211{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003212 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003213 struct auto_pin_cfg *cfg = &spec->autocfg;
3214 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003215 int badness = 0;
3216 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003217
Takashi Iwai185d99f2012-02-16 18:39:45 +01003218 if (!num_outs)
3219 return 0;
3220
Takashi Iwaidc31b582012-02-17 17:27:53 +01003221 for (i = 0; i < num_outs; i++) {
3222 hda_nid_t pin = pins[i];
3223 if (!dacs[i])
3224 dacs[i] = alc_auto_look_for_dac(codec, pin);
3225 if (!dacs[i] && !i) {
3226 for (j = 1; j < num_outs; j++) {
3227 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3228 dacs[0] = dacs[j];
3229 dacs[j] = 0;
3230 break;
3231 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003232 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003233 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003234 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003235 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003236 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003237 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003238 else if (cfg->line_outs > i &&
3239 alc_auto_is_dac_reachable(codec, pin,
3240 spec->private_dac_nids[i]))
3241 dac = spec->private_dac_nids[i];
3242 if (dac) {
3243 if (!i)
3244 badness += bad->shared_primary;
3245 else if (i == 1)
3246 badness += bad->shared_surr;
3247 else
3248 badness += bad->shared_clfe;
3249 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003250 spec->private_dac_nids[0])) {
3251 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003252 badness += bad->shared_surr_main;
3253 } else if (!i)
3254 badness += bad->no_primary_dac;
3255 else
3256 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003257 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003258 if (!add_new_out_path(codec, pin, dac))
3259 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003260 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003261 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003262 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003263
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003264 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003265}
3266
3267static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003268 hda_nid_t reference_pin,
3269 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003270
Takashi Iwai185d99f2012-02-16 18:39:45 +01003271static bool alc_map_singles(struct hda_codec *codec, int outs,
3272 const hda_nid_t *pins, hda_nid_t *dacs)
3273{
3274 int i;
3275 bool found = false;
3276 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003277 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003278 if (dacs[i])
3279 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003280 dac = get_dac_if_single(codec, pins[i]);
3281 if (!dac)
3282 continue;
3283 if (add_new_out_path(codec, pins[i], dac)) {
3284 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003285 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003286 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003287 }
3288 return found;
3289}
3290
Takashi Iwai7085ec12009-10-02 09:03:58 +02003291/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003292static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003293 bool fill_hardwired,
3294 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003295{
3296 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003297 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003298 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003299
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003300 /* set num_dacs once to full for alc_auto_look_for_dac() */
3301 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003302 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003303 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3304 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3305 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003306 spec->multi_ios = 0;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003307 snd_array_free(&spec->out_path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003308 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003309
3310 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003311 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003312 bool mapped;
3313 do {
3314 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003315 cfg->line_out_pins,
3316 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003317 mapped |= alc_map_singles(codec, cfg->hp_outs,
3318 cfg->hp_pins,
3319 spec->multiout.hp_out_nid);
3320 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3321 cfg->speaker_pins,
3322 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003323 if (fill_mio_first && cfg->line_outs == 1 &&
3324 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3325 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3326 if (!err)
3327 mapped = true;
3328 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003329 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003330 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003331
Takashi Iwaidc31b582012-02-17 17:27:53 +01003332 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3333 spec->private_dac_nids,
3334 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003335
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003336 /* re-count num_dacs and squash invalid entries */
3337 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003338 for (i = 0; i < cfg->line_outs; i++) {
3339 if (spec->private_dac_nids[i])
3340 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003341 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003342 memmove(spec->private_dac_nids + i,
3343 spec->private_dac_nids + i + 1,
3344 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003345 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3346 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003347 }
3348
Takashi Iwai276dd702012-02-17 16:17:03 +01003349 if (fill_mio_first &&
3350 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003351 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003352 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003353 if (err < 0)
3354 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003355 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003356 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003357
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003358 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003359 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3360 spec->multiout.hp_out_nid,
3361 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003362 if (err < 0)
3363 return err;
3364 badness += err;
3365 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003366 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003367 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3368 cfg->speaker_pins,
3369 spec->multiout.extra_out_nid,
3370 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003371 if (err < 0)
3372 return err;
3373 badness += err;
3374 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003375 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3376 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003377 if (err < 0)
3378 return err;
3379 badness += err;
3380 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003381 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3382 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003383 int offset = 0;
3384 if (cfg->line_outs >= 3)
3385 offset = 1;
3386 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3387 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003388 if (err < 0)
3389 return err;
3390 badness += err;
3391 }
3392
3393 if (spec->multi_ios == 2) {
3394 for (i = 0; i < 2; i++)
3395 spec->private_dac_nids[spec->multiout.num_dacs++] =
3396 spec->multi_io[i].dac;
3397 spec->ext_channel_count = 2;
3398 } else if (spec->multi_ios) {
3399 spec->multi_ios = 0;
3400 badness += BAD_MULTI_IO;
3401 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003402
3403 return badness;
3404}
3405
3406#define DEBUG_BADNESS
3407
3408#ifdef DEBUG_BADNESS
3409#define debug_badness snd_printdd
3410#else
3411#define debug_badness(...)
3412#endif
3413
3414static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3415{
3416 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3417 cfg->line_out_pins[0], cfg->line_out_pins[1],
3418 cfg->line_out_pins[2], cfg->line_out_pins[2],
3419 spec->multiout.dac_nids[0],
3420 spec->multiout.dac_nids[1],
3421 spec->multiout.dac_nids[2],
3422 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003423 if (spec->multi_ios > 0)
3424 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3425 spec->multi_ios,
3426 spec->multi_io[0].pin, spec->multi_io[1].pin,
3427 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003428 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3429 cfg->hp_pins[0], cfg->hp_pins[1],
3430 cfg->hp_pins[2], cfg->hp_pins[2],
3431 spec->multiout.hp_out_nid[0],
3432 spec->multiout.hp_out_nid[1],
3433 spec->multiout.hp_out_nid[2],
3434 spec->multiout.hp_out_nid[3]);
3435 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3436 cfg->speaker_pins[0], cfg->speaker_pins[1],
3437 cfg->speaker_pins[2], cfg->speaker_pins[3],
3438 spec->multiout.extra_out_nid[0],
3439 spec->multiout.extra_out_nid[1],
3440 spec->multiout.extra_out_nid[2],
3441 spec->multiout.extra_out_nid[3]);
3442}
3443
Takashi Iwai463419d2012-12-05 14:17:37 +01003444/* find all available DACs of the codec */
3445static void alc_fill_all_nids(struct hda_codec *codec)
3446{
3447 struct alc_spec *spec = codec->spec;
3448 int i;
3449 hda_nid_t nid = codec->start_nid;
3450
3451 spec->num_all_dacs = 0;
3452 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3453 for (i = 0; i < codec->num_nodes; i++, nid++) {
3454 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3455 continue;
3456 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3457 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3458 break;
3459 }
3460 spec->all_dacs[spec->num_all_dacs++] = nid;
3461 }
3462}
3463
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003464static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3465{
3466 struct alc_spec *spec = codec->spec;
3467 struct auto_pin_cfg *cfg = &spec->autocfg;
3468 struct auto_pin_cfg *best_cfg;
3469 int best_badness = INT_MAX;
3470 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003471 bool fill_hardwired = true, fill_mio_first = true;
3472 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003473 bool hp_spk_swapped = false;
3474
Takashi Iwai463419d2012-12-05 14:17:37 +01003475 alc_fill_all_nids(codec);
3476
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003477 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3478 if (!best_cfg)
3479 return -ENOMEM;
3480 *best_cfg = *cfg;
3481
3482 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003483 badness = fill_and_eval_dacs(codec, fill_hardwired,
3484 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003485 if (badness < 0) {
3486 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003487 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003488 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003489 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3490 cfg->line_out_type, fill_hardwired, fill_mio_first,
3491 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003492 debug_show_configs(spec, cfg);
3493 if (badness < best_badness) {
3494 best_badness = badness;
3495 *best_cfg = *cfg;
3496 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003497 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003498 }
3499 if (!badness)
3500 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003501 fill_mio_first = !fill_mio_first;
3502 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003503 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003504 fill_hardwired = !fill_hardwired;
3505 if (!fill_hardwired)
3506 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003507 if (hp_spk_swapped)
3508 break;
3509 hp_spk_swapped = true;
3510 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003511 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3512 cfg->hp_outs = cfg->line_outs;
3513 memcpy(cfg->hp_pins, cfg->line_out_pins,
3514 sizeof(cfg->hp_pins));
3515 cfg->line_outs = cfg->speaker_outs;
3516 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3517 sizeof(cfg->speaker_pins));
3518 cfg->speaker_outs = 0;
3519 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3520 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003521 fill_hardwired = true;
3522 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003523 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003524 if (cfg->hp_outs > 0 &&
3525 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3526 cfg->speaker_outs = cfg->line_outs;
3527 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3528 sizeof(cfg->speaker_pins));
3529 cfg->line_outs = cfg->hp_outs;
3530 memcpy(cfg->line_out_pins, cfg->hp_pins,
3531 sizeof(cfg->hp_pins));
3532 cfg->hp_outs = 0;
3533 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3534 cfg->line_out_type = AUTO_PIN_HP_OUT;
3535 fill_hardwired = true;
3536 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003537 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003538 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003539 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003540
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003541 if (badness) {
3542 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003543 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003544 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003545 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3546 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003547 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003548
Takashi Iwaiba8111272012-12-06 18:06:23 +01003549 if (cfg->line_out_pins[0]) {
3550 struct nid_path *path = get_out_path(codec,
3551 cfg->line_out_pins[0],
3552 spec->multiout.dac_nids[0]);
3553 if (path)
3554 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3555 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003556
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003557 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003558 return 0;
3559}
3560
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003561/* replace the channels in the composed amp value with the given number */
3562static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3563{
3564 val &= ~(0x3U << 16);
3565 val |= chs << 16;
3566 return val;
3567}
3568
Takashi Iwai343a04b2011-07-06 14:28:39 +02003569static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003570 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003571 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003572 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003573{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003574 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003575 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003576 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003577 val = path->ctls[NID_PATH_VOL_CTL];
3578 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003579 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003580 val = amp_val_replace_channels(val, chs);
3581 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3582}
3583
3584/* return the channel bits suitable for the given path->ctls[] */
3585static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3586 int type)
3587{
3588 int chs = 1; /* mono (left only) */
3589 if (path) {
3590 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3591 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3592 chs = 3; /* stereo */
3593 }
3594 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003595}
3596
Takashi Iwaie29d3772011-11-14 17:13:23 +01003597static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3598 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003599 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003600{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003601 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3602 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003603}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003604
3605/* create a mute-switch for the given mixer widget;
3606 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3607 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003608static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003609 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003610 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003611 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003612{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003613 unsigned int val;
3614 int type = ALC_CTL_WIDGET_MUTE;
3615
3616 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003617 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003618 val = path->ctls[NID_PATH_MUTE_CTL];
3619 if (!val)
3620 return 0;
3621 val = amp_val_replace_channels(val, chs);
3622 if (get_amp_direction_(val) == HDA_INPUT) {
3623 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003624 int nums = snd_hda_get_num_conns(codec, nid);
3625 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003626 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003627 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003628 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003629 }
3630 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003631}
3632
Takashi Iwaie29d3772011-11-14 17:13:23 +01003633static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003634 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003635{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003636 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3637 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003638}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003639
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003640static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003641 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003642{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003643 int i;
3644
3645 for (i = path->depth - 1; i >= 0; i--) {
3646 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3647 return path->path[i];
3648 if (i != path->depth - 1 && i != 0 &&
3649 nid_has_mute(codec, path->path[i], HDA_INPUT))
3650 return path->path[i];
3651 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003652 return 0;
3653}
3654
3655static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003656 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003657{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003658 int i;
3659
3660 for (i = path->depth - 1; i >= 0; i--) {
3661 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3662 return path->path[i];
3663 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003664 return 0;
3665}
3666
Takashi Iwai7085ec12009-10-02 09:03:58 +02003667/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003668static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003669 const struct auto_pin_cfg *cfg)
3670{
3671 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003672 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003673
Takashi Iwaice764ab2011-04-27 16:35:23 +02003674 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003675 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003676 noutputs += spec->multi_ios;
3677
3678 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003679 const char *name;
3680 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003681 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003682 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003683
3684 dac = spec->multiout.dac_nids[i];
3685 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003686 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003687 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003688 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003689 index = 0;
3690 name = channel_name[i];
3691 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003692 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003693 name = alc_get_line_out_pfx(spec, i, true, &index);
3694 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003695
Takashi Iwaiba8111272012-12-06 18:06:23 +01003696 path = get_out_path(codec, pin, dac);
3697 if (!path)
3698 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003699 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003700 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003701 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003702 if (err < 0)
3703 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003704 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003705 if (err < 0)
3706 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003707 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003708 if (err < 0)
3709 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003710 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003711 if (err < 0)
3712 return err;
3713 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003714 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003715 if (err < 0)
3716 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003717 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003718 if (err < 0)
3719 return err;
3720 }
3721 }
3722 return 0;
3723}
3724
Takashi Iwai343a04b2011-07-06 14:28:39 +02003725static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003726 hda_nid_t dac, const char *pfx,
3727 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003728{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003729 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003730 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003731
Takashi Iwaiba8111272012-12-06 18:06:23 +01003732 path = get_out_path(codec, pin, dac);
3733 if (!path)
3734 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003735 /* bind volume control will be created in the case of dac = 0 */
3736 if (dac) {
3737 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3738 if (err < 0)
3739 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003740 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003741 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003742 if (err < 0)
3743 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003744 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003745}
3746
Takashi Iwai23c09b02011-08-19 09:05:35 +02003747static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3748 unsigned int nums,
3749 struct hda_ctl_ops *ops)
3750{
3751 struct alc_spec *spec = codec->spec;
3752 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003753 ctlp = snd_array_new(&spec->bind_ctls);
3754 if (!ctlp)
3755 return NULL;
3756 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3757 *ctlp = ctl;
3758 if (ctl)
3759 ctl->ops = ops;
3760 return ctl;
3761}
3762
3763/* add playback controls for speaker and HP outputs */
3764static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3765 const hda_nid_t *pins,
3766 const hda_nid_t *dacs,
3767 const char *pfx)
3768{
3769 struct alc_spec *spec = codec->spec;
3770 struct hda_bind_ctls *ctl;
3771 char name[32];
3772 int i, n, err;
3773
3774 if (!num_pins || !pins[0])
3775 return 0;
3776
Takashi Iwai527e4d72011-10-27 16:33:27 +02003777 if (num_pins == 1) {
3778 hda_nid_t dac = *dacs;
3779 if (!dac)
3780 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003781 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003782 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003783
Takashi Iwai23c09b02011-08-19 09:05:35 +02003784 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003785 hda_nid_t dac;
3786 if (dacs[num_pins - 1])
3787 dac = dacs[i]; /* with individual volumes */
3788 else
3789 dac = 0;
3790 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3791 err = alc_auto_create_extra_out(codec, pins[i], dac,
3792 "Bass Speaker", 0);
3793 } else if (num_pins >= 3) {
3794 snprintf(name, sizeof(name), "%s %s",
3795 pfx, channel_name[i]);
3796 err = alc_auto_create_extra_out(codec, pins[i], dac,
3797 name, 0);
3798 } else {
3799 err = alc_auto_create_extra_out(codec, pins[i], dac,
3800 pfx, i);
3801 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003802 if (err < 0)
3803 return err;
3804 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003805 if (dacs[num_pins - 1])
3806 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003807
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003808 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003809 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3810 if (!ctl)
3811 return -ENOMEM;
3812 n = 0;
3813 for (i = 0; i < num_pins; i++) {
3814 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003815 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003816 if (!pins[i] || !dacs[i])
3817 continue;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003818 path = get_out_path(codec, pins[i], dacs[i]);
3819 if (!path)
3820 continue;
3821 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003822 if (vol)
3823 ctl->values[n++] =
3824 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3825 }
3826 if (n) {
3827 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3828 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3829 if (err < 0)
3830 return err;
3831 }
3832 return 0;
3833}
3834
Takashi Iwai343a04b2011-07-06 14:28:39 +02003835static int alc_auto_create_hp_out(struct hda_codec *codec)
3836{
3837 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003838 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3839 spec->autocfg.hp_pins,
3840 spec->multiout.hp_out_nid,
3841 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003842}
3843
3844static int alc_auto_create_speaker_out(struct hda_codec *codec)
3845{
3846 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003847 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3848 spec->autocfg.speaker_pins,
3849 spec->multiout.extra_out_nid,
3850 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003851}
3852
Takashi Iwai78e635c2012-12-10 17:07:16 +01003853/* is a volume or mute control already present? */
3854static bool __is_out_ctl_present(struct hda_codec *codec,
3855 struct nid_path *exclude_path,
3856 hda_nid_t nid, int dir, int types)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003857{
Takashi Iwai78e635c2012-12-10 17:07:16 +01003858 struct alc_spec *spec = codec->spec;
3859 int i, type;
3860
3861 for (i = 0; i < spec->out_path.used; i++) {
3862 struct nid_path *p = snd_array_elem(&spec->out_path, i);
3863 if (p == exclude_path || p->depth <= 0)
3864 continue;
3865 for (type = 0; type < 2; type++) {
3866 if (types & (1 << type)) {
3867 unsigned int val = p->ctls[type];
3868 if (get_amp_nid_(val) == nid &&
3869 get_amp_direction_(val) == dir)
3870 return true;
3871 }
3872 }
3873 }
3874 return false;
3875}
3876
3877#define is_out_ctl_present(codec, path, nid, dir) \
3878 __is_out_ctl_present(codec, path, nid, dir, 3) /* check both types */
3879#define is_out_vol_ctl_present(codec, nid, dir) \
3880 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_VOL_CTL)
3881#define is_out_mute_ctl_present(codec, nid, dir) \
3882 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_MUTE_CTL)
3883
3884static int get_default_amp_val(struct hda_codec *codec, hda_nid_t nid, int dir)
3885{
3886 unsigned int caps, offset;
3887 unsigned int val = 0;
3888
3889 caps = query_amp_caps(codec, nid, dir);
3890 if (caps & AC_AMPCAP_NUM_STEPS) {
3891 offset = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
3892 /* if a volume control is assigned, set the lowest level
3893 * as default; otherwise set to 0dB
3894 */
3895 if (is_out_vol_ctl_present(codec, nid, dir))
3896 val = 0;
3897 else
3898 val = offset;
3899 }
3900 if (caps & AC_AMPCAP_MUTE) {
3901 /* if a mute control is assigned, mute as default */
3902 if (is_out_mute_ctl_present(codec, nid, dir))
3903 val |= HDA_AMP_MUTE;
3904 }
3905 return val;
3906}
3907
3908/* configure the path from the given dac to the pin as the proper output */
3909static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3910 hda_nid_t pin, int pin_type,
3911 hda_nid_t dac, bool force)
3912{
Takashi Iwai9366ede2012-12-13 16:43:52 +01003913 struct alc_spec *spec = codec->spec;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003914 int i, val;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003915 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003916
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003917 alc_set_pin_output(codec, pin, pin_type);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003918 path = get_out_path(codec, pin, dac);
3919 if (!path)
3920 return;
Takashi Iwai43dea222011-11-06 11:25:34 +01003921
Takashi Iwai78e635c2012-12-10 17:07:16 +01003922 for (i = path->depth - 1; i >= 0; i--) {
3923 hda_nid_t nid = path->path[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01003924 if (path->multi[i])
Takashi Iwai78e635c2012-12-10 17:07:16 +01003925 snd_hda_codec_write(codec, nid, 0,
3926 AC_VERB_SET_CONNECT_SEL,
Takashi Iwai95e960c2012-12-10 17:27:57 +01003927 path->idx[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003928
3929 if (i != 0 && i != path->depth - 1 &&
3930 (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) &&
3931 (force || !is_out_ctl_present(codec, path, nid,
3932 HDA_INPUT))) {
Takashi Iwai9366ede2012-12-13 16:43:52 +01003933 hda_nid_t conn[16];
3934 int n, nums;
3935 nums = snd_hda_get_connections(codec, nid, conn,
3936 ARRAY_SIZE(conn));
Takashi Iwai78e635c2012-12-10 17:07:16 +01003937 val = get_default_amp_val(codec, nid, HDA_INPUT);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003938 for (n = 0; n < nums; n++) {
3939 if (n != path->idx[i] &&
3940 conn[n] != spec->mixer_nid)
3941 continue;
3942 snd_hda_codec_write(codec, nid, 0,
Takashi Iwai78e635c2012-12-10 17:07:16 +01003943 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwai9366ede2012-12-13 16:43:52 +01003944 AMP_IN_UNMUTE(n) | val);
3945 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003946 }
3947 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
3948 (force || !is_out_ctl_present(codec, path, nid,
3949 HDA_OUTPUT))) {
3950 val = get_default_amp_val(codec, nid, HDA_OUTPUT);
3951 snd_hda_codec_write(codec, nid, 0,
3952 AC_VERB_SET_AMP_GAIN_MUTE,
3953 AMP_OUT_UNMUTE | val);
3954 }
3955 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003956}
3957
Takashi Iwai343a04b2011-07-06 14:28:39 +02003958static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003959{
3960 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003961 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003962 int i;
3963
3964 for (i = 0; i <= HDA_SIDE; i++) {
3965 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3966 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003967 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai78e635c2012-12-10 17:07:16 +01003968 spec->multiout.dac_nids[i], true);
3969
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003970 }
3971}
3972
Takashi Iwai343a04b2011-07-06 14:28:39 +02003973static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003974{
3975 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003976 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003977 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003978
David Henningsson636030e2011-10-12 19:26:03 +02003979 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003980 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3981 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003982 pin = spec->autocfg.hp_pins[i];
3983 if (!pin)
3984 break;
3985 dac = spec->multiout.hp_out_nid[i];
3986 if (!dac) {
3987 if (i > 0 && spec->multiout.hp_out_nid[0])
3988 dac = spec->multiout.hp_out_nid[0];
3989 else
3990 dac = spec->multiout.dac_nids[0];
3991 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003992 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003993 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003994 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003995 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3996 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003997 pin = spec->autocfg.speaker_pins[i];
3998 if (!pin)
3999 break;
4000 dac = spec->multiout.extra_out_nid[i];
4001 if (!dac) {
4002 if (i > 0 && spec->multiout.extra_out_nid[0])
4003 dac = spec->multiout.extra_out_nid[0];
4004 else
4005 dac = spec->multiout.dac_nids[0];
4006 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01004007 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004008 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004009}
4010
Takashi Iwai276dd702012-02-17 16:17:03 +01004011/* check whether the given pin can be a multi-io pin */
4012static bool can_be_multiio_pin(struct hda_codec *codec,
4013 unsigned int location, hda_nid_t nid)
4014{
4015 unsigned int defcfg, caps;
4016
4017 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4018 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4019 return false;
4020 if (location && get_defcfg_location(defcfg) != location)
4021 return false;
4022 caps = snd_hda_query_pin_caps(codec, nid);
4023 if (!(caps & AC_PINCAP_OUT))
4024 return false;
4025 return true;
4026}
4027
Takashi Iwaice764ab2011-04-27 16:35:23 +02004028/*
4029 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004030 *
4031 * When hardwired is set, try to fill ony hardwired pins, and returns
4032 * zero if any pins are filled, non-zero if nothing found.
4033 * When hardwired is off, try to fill possible input pins, and returns
4034 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004035 */
4036static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004037 hda_nid_t reference_pin,
4038 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004039{
4040 struct alc_spec *spec = codec->spec;
4041 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004042 int type, i, j, dacs, num_pins, old_pins;
4043 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4044 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004045 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004046
Takashi Iwai276dd702012-02-17 16:17:03 +01004047 old_pins = spec->multi_ios;
4048 if (old_pins >= 2)
4049 goto end_fill;
4050
4051 num_pins = 0;
4052 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4053 for (i = 0; i < cfg->num_inputs; i++) {
4054 if (cfg->inputs[i].type != type)
4055 continue;
4056 if (can_be_multiio_pin(codec, location,
4057 cfg->inputs[i].pin))
4058 num_pins++;
4059 }
4060 }
4061 if (num_pins < 2)
4062 goto end_fill;
4063
Takashi Iwai07b18f62011-11-10 15:42:54 +01004064 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004065 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4066 for (i = 0; i < cfg->num_inputs; i++) {
4067 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004068 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004069
Takashi Iwaice764ab2011-04-27 16:35:23 +02004070 if (cfg->inputs[i].type != type)
4071 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004072 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004073 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004074 for (j = 0; j < spec->multi_ios; j++) {
4075 if (nid == spec->multi_io[j].pin)
4076 break;
4077 }
4078 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004079 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004080
4081 if (offset && offset + spec->multi_ios < dacs) {
4082 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01004083 if (!alc_auto_is_dac_reachable(codec, nid, dac))
4084 dac = 0;
4085 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004086 if (hardwired)
4087 dac = get_dac_if_single(codec, nid);
4088 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01004089 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004090 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004091 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004092 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004093 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004094 if (!add_new_out_path(codec, nid, dac)) {
4095 badness++;
4096 continue;
4097 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004098 spec->multi_io[spec->multi_ios].pin = nid;
4099 spec->multi_io[spec->multi_ios].dac = dac;
4100 spec->multi_ios++;
4101 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004102 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004103 }
4104 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004105 end_fill:
4106 if (badness)
4107 badness = BAD_MULTI_IO;
4108 if (old_pins == spec->multi_ios) {
4109 if (hardwired)
4110 return 1; /* nothing found */
4111 else
4112 return badness; /* no badness if nothing found */
4113 }
4114 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004115 /* cancel newly assigned paths */
4116 spec->out_path.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004117 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004118 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004119 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004120
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004121 /* assign volume and mute controls */
4122 for (i = old_pins; i < spec->multi_ios; i++)
4123 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4124 spec->multi_io[i].dac);
4125
4126 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004127}
4128
4129static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4130 struct snd_ctl_elem_info *uinfo)
4131{
4132 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4133 struct alc_spec *spec = codec->spec;
4134
4135 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4136 uinfo->count = 1;
4137 uinfo->value.enumerated.items = spec->multi_ios + 1;
4138 if (uinfo->value.enumerated.item > spec->multi_ios)
4139 uinfo->value.enumerated.item = spec->multi_ios;
4140 sprintf(uinfo->value.enumerated.name, "%dch",
4141 (uinfo->value.enumerated.item + 1) * 2);
4142 return 0;
4143}
4144
4145static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4146 struct snd_ctl_elem_value *ucontrol)
4147{
4148 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4149 struct alc_spec *spec = codec->spec;
4150 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4151 return 0;
4152}
4153
4154static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4155{
4156 struct alc_spec *spec = codec->spec;
4157 hda_nid_t nid = spec->multi_io[idx].pin;
4158
4159 if (!spec->multi_io[idx].ctl_in)
4160 spec->multi_io[idx].ctl_in =
4161 snd_hda_codec_read(codec, nid, 0,
4162 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4163 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004164 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004165 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4166 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4167 HDA_AMP_MUTE, 0);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004168 alc_auto_set_output_and_unmute(codec, nid, PIN_OUT,
4169 spec->multi_io[idx].dac, false);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004170 } else {
4171 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4172 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4173 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004174 snd_hda_set_pin_ctl_cache(codec, nid,
4175 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004176 }
4177 return 0;
4178}
4179
4180static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4181 struct snd_ctl_elem_value *ucontrol)
4182{
4183 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4184 struct alc_spec *spec = codec->spec;
4185 int i, ch;
4186
4187 ch = ucontrol->value.enumerated.item[0];
4188 if (ch < 0 || ch > spec->multi_ios)
4189 return -EINVAL;
4190 if (ch == (spec->ext_channel_count - 1) / 2)
4191 return 0;
4192 spec->ext_channel_count = (ch + 1) * 2;
4193 for (i = 0; i < spec->multi_ios; i++)
4194 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004195 spec->multiout.max_channels = max(spec->ext_channel_count,
4196 spec->const_channel_count);
4197 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004198 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004199 return 1;
4200}
4201
Takashi Iwaia9111322011-05-02 11:30:18 +02004202static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004203 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4204 .name = "Channel Mode",
4205 .info = alc_auto_ch_mode_info,
4206 .get = alc_auto_ch_mode_get,
4207 .put = alc_auto_ch_mode_put,
4208};
4209
Takashi Iwai23c09b02011-08-19 09:05:35 +02004210static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004211{
4212 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004213
Takashi Iwaic2674682011-08-24 17:57:44 +02004214 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004215 if (!alc_kcontrol_new(spec, "Channel Mode",
4216 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004217 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004218 }
4219 return 0;
4220}
4221
Takashi Iwai1d045db2011-07-07 18:23:21 +02004222/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4223 * active input pins
4224 */
4225static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4226{
4227 struct alc_spec *spec = codec->spec;
4228 const struct hda_input_mux *imux;
4229 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4230 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4231 int i, n, nums;
4232
4233 imux = spec->input_mux;
4234 if (!imux)
4235 return;
4236 if (spec->dyn_adc_switch)
4237 return;
4238
Takashi Iwai26acaf02012-03-22 14:36:50 +01004239 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004240 nums = 0;
4241 for (n = 0; n < spec->num_adc_nids; n++) {
4242 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004243 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004244 for (i = 0; i < imux->num_items; i++) {
4245 hda_nid_t pin = spec->imux_pins[i];
4246 if (pin) {
4247 if (get_connection_index(codec, cap, pin) < 0)
4248 break;
4249 } else if (num_conns <= imux->items[i].index)
4250 break;
4251 }
4252 if (i >= imux->num_items) {
4253 adc_nids[nums] = spec->private_adc_nids[n];
4254 capsrc_nids[nums++] = cap;
4255 }
4256 }
4257 if (!nums) {
4258 /* check whether ADC-switch is possible */
4259 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004260 if (spec->shared_mic_hp) {
4261 spec->shared_mic_hp = 0;
4262 spec->private_imux[0].num_items = 1;
4263 goto again;
4264 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004265 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4266 " using fallback 0x%x\n",
4267 codec->chip_name, spec->private_adc_nids[0]);
4268 spec->num_adc_nids = 1;
4269 spec->auto_mic = 0;
4270 return;
4271 }
4272 } else if (nums != spec->num_adc_nids) {
4273 memcpy(spec->private_adc_nids, adc_nids,
4274 nums * sizeof(hda_nid_t));
4275 memcpy(spec->private_capsrc_nids, capsrc_nids,
4276 nums * sizeof(hda_nid_t));
4277 spec->num_adc_nids = nums;
4278 }
4279
4280 if (spec->auto_mic)
4281 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004282 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004283 spec->num_adc_nids = 1; /* reduce to a single ADC */
4284}
4285
4286/*
4287 * initialize ADC paths
4288 */
4289static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4290{
4291 struct alc_spec *spec = codec->spec;
4292 hda_nid_t nid;
4293
4294 nid = spec->adc_nids[adc_idx];
4295 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004296 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004297 snd_hda_codec_write(codec, nid, 0,
4298 AC_VERB_SET_AMP_GAIN_MUTE,
4299 AMP_IN_MUTE(0));
4300 return;
4301 }
4302 if (!spec->capsrc_nids)
4303 return;
4304 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004305 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004306 snd_hda_codec_write(codec, nid, 0,
4307 AC_VERB_SET_AMP_GAIN_MUTE,
4308 AMP_OUT_MUTE);
4309}
4310
4311static void alc_auto_init_input_src(struct hda_codec *codec)
4312{
4313 struct alc_spec *spec = codec->spec;
4314 int c, nums;
4315
4316 for (c = 0; c < spec->num_adc_nids; c++)
4317 alc_auto_init_adc(codec, c);
4318 if (spec->dyn_adc_switch)
4319 nums = 1;
4320 else
4321 nums = spec->num_adc_nids;
4322 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004323 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004324}
4325
4326/* add mic boosts if needed */
4327static int alc_auto_add_mic_boost(struct hda_codec *codec)
4328{
4329 struct alc_spec *spec = codec->spec;
4330 struct auto_pin_cfg *cfg = &spec->autocfg;
4331 int i, err;
4332 int type_idx = 0;
4333 hda_nid_t nid;
4334 const char *prev_label = NULL;
4335
4336 for (i = 0; i < cfg->num_inputs; i++) {
4337 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4338 break;
4339 nid = cfg->inputs[i].pin;
4340 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4341 const char *label;
4342 char boost_label[32];
4343
4344 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004345 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4346 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004347 if (prev_label && !strcmp(label, prev_label))
4348 type_idx++;
4349 else
4350 type_idx = 0;
4351 prev_label = label;
4352
4353 snprintf(boost_label, sizeof(boost_label),
4354 "%s Boost Volume", label);
4355 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4356 boost_label, type_idx,
4357 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4358 if (err < 0)
4359 return err;
4360 }
4361 }
4362 return 0;
4363}
4364
4365/* select or unmute the given capsrc route */
4366static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4367 int idx)
4368{
4369 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4370 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4371 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004372 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004373 snd_hda_codec_write_cache(codec, cap, 0,
4374 AC_VERB_SET_CONNECT_SEL, idx);
4375 }
4376}
4377
4378/* set the default connection to that pin */
4379static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4380{
4381 struct alc_spec *spec = codec->spec;
4382 int i;
4383
4384 if (!pin)
4385 return 0;
4386 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004387 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004388 int idx;
4389
4390 idx = get_connection_index(codec, cap, pin);
4391 if (idx < 0)
4392 continue;
4393 select_or_unmute_capsrc(codec, cap, idx);
4394 return i; /* return the found index */
4395 }
4396 return -1; /* not found */
4397}
4398
4399/* initialize some special cases for input sources */
4400static void alc_init_special_input_src(struct hda_codec *codec)
4401{
4402 struct alc_spec *spec = codec->spec;
4403 int i;
4404
4405 for (i = 0; i < spec->autocfg.num_inputs; i++)
4406 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4407}
4408
4409/* assign appropriate capture mixers */
4410static void set_capture_mixer(struct hda_codec *codec)
4411{
4412 struct alc_spec *spec = codec->spec;
4413 static const struct snd_kcontrol_new *caps[2][3] = {
4414 { alc_capture_mixer_nosrc1,
4415 alc_capture_mixer_nosrc2,
4416 alc_capture_mixer_nosrc3 },
4417 { alc_capture_mixer1,
4418 alc_capture_mixer2,
4419 alc_capture_mixer3 },
4420 };
4421
4422 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004423 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004424 if (!spec->capsrc_nids)
4425 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004426 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004427 return; /* no volume in capsrc, too */
4428 spec->vol_in_capsrc = 1;
4429 }
4430
4431 if (spec->num_adc_nids > 0) {
4432 int mux = 0;
4433 int num_adcs = 0;
4434
4435 if (spec->input_mux && spec->input_mux->num_items > 1)
4436 mux = 1;
4437 if (spec->auto_mic) {
4438 num_adcs = 1;
4439 mux = 0;
4440 } else if (spec->dyn_adc_switch)
4441 num_adcs = 1;
4442 if (!num_adcs) {
4443 if (spec->num_adc_nids > 3)
4444 spec->num_adc_nids = 3;
4445 else if (!spec->num_adc_nids)
4446 return;
4447 num_adcs = spec->num_adc_nids;
4448 }
4449 spec->cap_mixer = caps[mux][num_adcs - 1];
4450 }
4451}
4452
4453/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004454 * standard auto-parser initializations
4455 */
4456static void alc_auto_init_std(struct hda_codec *codec)
4457{
Takashi Iwaie4770622011-07-08 11:11:35 +02004458 alc_auto_init_multi_out(codec);
4459 alc_auto_init_extra_out(codec);
4460 alc_auto_init_analog_input(codec);
4461 alc_auto_init_input_src(codec);
4462 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004463 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004464}
4465
4466/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004467 * Digital-beep handlers
4468 */
4469#ifdef CONFIG_SND_HDA_INPUT_BEEP
4470#define set_beep_amp(spec, nid, idx, dir) \
4471 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4472
4473static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004474 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004475 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4476 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4477 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4478 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004479 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004480 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4481 {}
4482};
4483
4484static inline int has_cdefine_beep(struct hda_codec *codec)
4485{
4486 struct alc_spec *spec = codec->spec;
4487 const struct snd_pci_quirk *q;
4488 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4489 if (q)
4490 return q->value;
4491 return spec->cdefine.enable_pcbeep;
4492}
4493#else
4494#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4495#define has_cdefine_beep(codec) 0
4496#endif
4497
4498/* parse the BIOS configuration and set up the alc_spec */
4499/* return 1 if successful, 0 if the proper config is not found,
4500 * or a negative error code
4501 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004502static int alc_parse_auto_config(struct hda_codec *codec,
4503 const hda_nid_t *ignore_nids,
4504 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004505{
4506 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004507 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004508 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004509
Takashi Iwai53c334a2011-08-23 18:27:14 +02004510 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4511 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004512 if (err < 0)
4513 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004514 if (!cfg->line_outs) {
4515 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004516 spec->multiout.max_channels = 2;
4517 spec->no_analog = 1;
4518 goto dig_only;
4519 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004520 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004521 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004522
Takashi Iwaie427c232012-07-29 10:04:08 +02004523 if (!spec->no_primary_hp &&
4524 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004525 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004526 /* use HP as primary out */
4527 cfg->speaker_outs = cfg->line_outs;
4528 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4529 sizeof(cfg->speaker_pins));
4530 cfg->line_outs = cfg->hp_outs;
4531 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4532 cfg->hp_outs = 0;
4533 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4534 cfg->line_out_type = AUTO_PIN_HP_OUT;
4535 }
4536
Takashi Iwai1d045db2011-07-07 18:23:21 +02004537 err = alc_auto_fill_dac_nids(codec);
4538 if (err < 0)
4539 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004540 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004541 if (err < 0)
4542 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004543 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004544 if (err < 0)
4545 return err;
4546 err = alc_auto_create_hp_out(codec);
4547 if (err < 0)
4548 return err;
4549 err = alc_auto_create_speaker_out(codec);
4550 if (err < 0)
4551 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004552 err = alc_auto_create_shared_input(codec);
4553 if (err < 0)
4554 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004555 err = alc_auto_create_input_ctls(codec);
4556 if (err < 0)
4557 return err;
4558
Takashi Iwaib6adb572012-12-03 10:30:58 +01004559 /* check the multiple speaker pins */
4560 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4561 spec->const_channel_count = cfg->line_outs * 2;
4562 else
4563 spec->const_channel_count = cfg->speaker_outs * 2;
4564
4565 if (spec->multi_ios > 0)
4566 spec->multiout.max_channels = max(spec->ext_channel_count,
4567 spec->const_channel_count);
4568 else
4569 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004570
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004571 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004572 alc_auto_parse_digital(codec);
4573
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004574 if (!spec->no_analog)
4575 alc_remove_invalid_adc_nids(codec);
4576
4577 if (ssid_nids)
4578 alc_ssid_check(codec, ssid_nids);
4579
4580 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004581 err = alc_auto_check_switches(codec);
4582 if (err < 0)
4583 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004584 err = alc_auto_add_mic_boost(codec);
4585 if (err < 0)
4586 return err;
4587 }
4588
Takashi Iwai1d045db2011-07-07 18:23:21 +02004589 if (spec->kctls.list)
4590 add_mixer(spec, spec->kctls.list);
4591
Takashi Iwai070cff42012-02-21 12:54:17 +01004592 if (!spec->no_analog && !spec->cap_mixer)
4593 set_capture_mixer(codec);
4594
Takashi Iwai1d045db2011-07-07 18:23:21 +02004595 return 1;
4596}
4597
Takashi Iwai3de95172012-05-07 18:03:15 +02004598/* common preparation job for alc_spec */
4599static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4600{
4601 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4602 int err;
4603
4604 if (!spec)
4605 return -ENOMEM;
4606 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004607 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004608 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004609 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004610 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4611 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004612 snd_array_init(&spec->out_path, sizeof(struct nid_path), 8);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01004613 snd_array_init(&spec->in_path, sizeof(struct nid_path), 8);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01004614 snd_array_init(&spec->loopback_path, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004615
4616 err = alc_codec_rename_from_preset(codec);
4617 if (err < 0) {
4618 kfree(spec);
4619 return err;
4620 }
4621 return 0;
4622}
4623
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004624static int alc880_parse_auto_config(struct hda_codec *codec)
4625{
4626 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004627 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004628 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4629}
4630
Takashi Iwai1d045db2011-07-07 18:23:21 +02004631/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004632 * ALC880 fix-ups
4633 */
4634enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004635 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004636 ALC880_FIXUP_GPIO2,
4637 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004638 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004639 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004640 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004641 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004642 ALC880_FIXUP_VOL_KNOB,
4643 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004644 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004645 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004646 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004647 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004648 ALC880_FIXUP_3ST_BASE,
4649 ALC880_FIXUP_3ST,
4650 ALC880_FIXUP_3ST_DIG,
4651 ALC880_FIXUP_5ST_BASE,
4652 ALC880_FIXUP_5ST,
4653 ALC880_FIXUP_5ST_DIG,
4654 ALC880_FIXUP_6ST_BASE,
4655 ALC880_FIXUP_6ST,
4656 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004657};
4658
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004659/* enable the volume-knob widget support on NID 0x21 */
4660static void alc880_fixup_vol_knob(struct hda_codec *codec,
4661 const struct alc_fixup *fix, int action)
4662{
4663 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004664 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004665}
4666
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004667static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004668 [ALC880_FIXUP_GPIO1] = {
4669 .type = ALC_FIXUP_VERBS,
4670 .v.verbs = alc_gpio1_init_verbs,
4671 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004672 [ALC880_FIXUP_GPIO2] = {
4673 .type = ALC_FIXUP_VERBS,
4674 .v.verbs = alc_gpio2_init_verbs,
4675 },
4676 [ALC880_FIXUP_MEDION_RIM] = {
4677 .type = ALC_FIXUP_VERBS,
4678 .v.verbs = (const struct hda_verb[]) {
4679 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4680 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4681 { }
4682 },
4683 .chained = true,
4684 .chain_id = ALC880_FIXUP_GPIO2,
4685 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004686 [ALC880_FIXUP_LG] = {
4687 .type = ALC_FIXUP_PINS,
4688 .v.pins = (const struct alc_pincfg[]) {
4689 /* disable bogus unused pins */
4690 { 0x16, 0x411111f0 },
4691 { 0x18, 0x411111f0 },
4692 { 0x1a, 0x411111f0 },
4693 { }
4694 }
4695 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004696 [ALC880_FIXUP_W810] = {
4697 .type = ALC_FIXUP_PINS,
4698 .v.pins = (const struct alc_pincfg[]) {
4699 /* disable bogus unused pins */
4700 { 0x17, 0x411111f0 },
4701 { }
4702 },
4703 .chained = true,
4704 .chain_id = ALC880_FIXUP_GPIO2,
4705 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004706 [ALC880_FIXUP_EAPD_COEF] = {
4707 .type = ALC_FIXUP_VERBS,
4708 .v.verbs = (const struct hda_verb[]) {
4709 /* change to EAPD mode */
4710 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4711 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4712 {}
4713 },
4714 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004715 [ALC880_FIXUP_TCL_S700] = {
4716 .type = ALC_FIXUP_VERBS,
4717 .v.verbs = (const struct hda_verb[]) {
4718 /* change to EAPD mode */
4719 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4720 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4721 {}
4722 },
4723 .chained = true,
4724 .chain_id = ALC880_FIXUP_GPIO2,
4725 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004726 [ALC880_FIXUP_VOL_KNOB] = {
4727 .type = ALC_FIXUP_FUNC,
4728 .v.func = alc880_fixup_vol_knob,
4729 },
4730 [ALC880_FIXUP_FUJITSU] = {
4731 /* override all pins as BIOS on old Amilo is broken */
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 { 0x17, 0x411111f0 }, /* N/A */
4738 { 0x18, 0x411111f0 }, /* N/A */
4739 { 0x19, 0x01a19950 }, /* mic-in */
4740 { 0x1a, 0x411111f0 }, /* N/A */
4741 { 0x1b, 0x411111f0 }, /* N/A */
4742 { 0x1c, 0x411111f0 }, /* N/A */
4743 { 0x1d, 0x411111f0 }, /* N/A */
4744 { 0x1e, 0x01454140 }, /* SPDIF out */
4745 { }
4746 },
4747 .chained = true,
4748 .chain_id = ALC880_FIXUP_VOL_KNOB,
4749 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004750 [ALC880_FIXUP_F1734] = {
4751 /* almost compatible with FUJITSU, but no bass and SPDIF */
4752 .type = ALC_FIXUP_PINS,
4753 .v.pins = (const struct alc_pincfg[]) {
4754 { 0x14, 0x0121411f }, /* HP */
4755 { 0x15, 0x99030120 }, /* speaker */
4756 { 0x16, 0x411111f0 }, /* N/A */
4757 { 0x17, 0x411111f0 }, /* N/A */
4758 { 0x18, 0x411111f0 }, /* N/A */
4759 { 0x19, 0x01a19950 }, /* mic-in */
4760 { 0x1a, 0x411111f0 }, /* N/A */
4761 { 0x1b, 0x411111f0 }, /* N/A */
4762 { 0x1c, 0x411111f0 }, /* N/A */
4763 { 0x1d, 0x411111f0 }, /* N/A */
4764 { 0x1e, 0x411111f0 }, /* N/A */
4765 { }
4766 },
4767 .chained = true,
4768 .chain_id = ALC880_FIXUP_VOL_KNOB,
4769 },
Takashi Iwai817de922012-02-20 17:20:48 +01004770 [ALC880_FIXUP_UNIWILL] = {
4771 /* need to fix HP and speaker pins to be parsed correctly */
4772 .type = ALC_FIXUP_PINS,
4773 .v.pins = (const struct alc_pincfg[]) {
4774 { 0x14, 0x0121411f }, /* HP */
4775 { 0x15, 0x99030120 }, /* speaker */
4776 { 0x16, 0x99030130 }, /* bass speaker */
4777 { }
4778 },
4779 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004780 [ALC880_FIXUP_UNIWILL_DIG] = {
4781 .type = ALC_FIXUP_PINS,
4782 .v.pins = (const struct alc_pincfg[]) {
4783 /* disable bogus unused pins */
4784 { 0x17, 0x411111f0 },
4785 { 0x19, 0x411111f0 },
4786 { 0x1b, 0x411111f0 },
4787 { 0x1f, 0x411111f0 },
4788 { }
4789 }
4790 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004791 [ALC880_FIXUP_Z71V] = {
4792 .type = ALC_FIXUP_PINS,
4793 .v.pins = (const struct alc_pincfg[]) {
4794 /* set up the whole pins as BIOS is utterly broken */
4795 { 0x14, 0x99030120 }, /* speaker */
4796 { 0x15, 0x0121411f }, /* HP */
4797 { 0x16, 0x411111f0 }, /* N/A */
4798 { 0x17, 0x411111f0 }, /* N/A */
4799 { 0x18, 0x01a19950 }, /* mic-in */
4800 { 0x19, 0x411111f0 }, /* N/A */
4801 { 0x1a, 0x01813031 }, /* line-in */
4802 { 0x1b, 0x411111f0 }, /* N/A */
4803 { 0x1c, 0x411111f0 }, /* N/A */
4804 { 0x1d, 0x411111f0 }, /* N/A */
4805 { 0x1e, 0x0144111e }, /* SPDIF */
4806 { }
4807 }
4808 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004809 [ALC880_FIXUP_3ST_BASE] = {
4810 .type = ALC_FIXUP_PINS,
4811 .v.pins = (const struct alc_pincfg[]) {
4812 { 0x14, 0x01014010 }, /* line-out */
4813 { 0x15, 0x411111f0 }, /* N/A */
4814 { 0x16, 0x411111f0 }, /* N/A */
4815 { 0x17, 0x411111f0 }, /* N/A */
4816 { 0x18, 0x01a19c30 }, /* mic-in */
4817 { 0x19, 0x0121411f }, /* HP */
4818 { 0x1a, 0x01813031 }, /* line-in */
4819 { 0x1b, 0x02a19c40 }, /* front-mic */
4820 { 0x1c, 0x411111f0 }, /* N/A */
4821 { 0x1d, 0x411111f0 }, /* N/A */
4822 /* 0x1e is filled in below */
4823 { 0x1f, 0x411111f0 }, /* N/A */
4824 { }
4825 }
4826 },
4827 [ALC880_FIXUP_3ST] = {
4828 .type = ALC_FIXUP_PINS,
4829 .v.pins = (const struct alc_pincfg[]) {
4830 { 0x1e, 0x411111f0 }, /* N/A */
4831 { }
4832 },
4833 .chained = true,
4834 .chain_id = ALC880_FIXUP_3ST_BASE,
4835 },
4836 [ALC880_FIXUP_3ST_DIG] = {
4837 .type = ALC_FIXUP_PINS,
4838 .v.pins = (const struct alc_pincfg[]) {
4839 { 0x1e, 0x0144111e }, /* SPDIF */
4840 { }
4841 },
4842 .chained = true,
4843 .chain_id = ALC880_FIXUP_3ST_BASE,
4844 },
4845 [ALC880_FIXUP_5ST_BASE] = {
4846 .type = ALC_FIXUP_PINS,
4847 .v.pins = (const struct alc_pincfg[]) {
4848 { 0x14, 0x01014010 }, /* front */
4849 { 0x15, 0x411111f0 }, /* N/A */
4850 { 0x16, 0x01011411 }, /* CLFE */
4851 { 0x17, 0x01016412 }, /* surr */
4852 { 0x18, 0x01a19c30 }, /* mic-in */
4853 { 0x19, 0x0121411f }, /* HP */
4854 { 0x1a, 0x01813031 }, /* line-in */
4855 { 0x1b, 0x02a19c40 }, /* front-mic */
4856 { 0x1c, 0x411111f0 }, /* N/A */
4857 { 0x1d, 0x411111f0 }, /* N/A */
4858 /* 0x1e is filled in below */
4859 { 0x1f, 0x411111f0 }, /* N/A */
4860 { }
4861 }
4862 },
4863 [ALC880_FIXUP_5ST] = {
4864 .type = ALC_FIXUP_PINS,
4865 .v.pins = (const struct alc_pincfg[]) {
4866 { 0x1e, 0x411111f0 }, /* N/A */
4867 { }
4868 },
4869 .chained = true,
4870 .chain_id = ALC880_FIXUP_5ST_BASE,
4871 },
4872 [ALC880_FIXUP_5ST_DIG] = {
4873 .type = ALC_FIXUP_PINS,
4874 .v.pins = (const struct alc_pincfg[]) {
4875 { 0x1e, 0x0144111e }, /* SPDIF */
4876 { }
4877 },
4878 .chained = true,
4879 .chain_id = ALC880_FIXUP_5ST_BASE,
4880 },
4881 [ALC880_FIXUP_6ST_BASE] = {
4882 .type = ALC_FIXUP_PINS,
4883 .v.pins = (const struct alc_pincfg[]) {
4884 { 0x14, 0x01014010 }, /* front */
4885 { 0x15, 0x01016412 }, /* surr */
4886 { 0x16, 0x01011411 }, /* CLFE */
4887 { 0x17, 0x01012414 }, /* side */
4888 { 0x18, 0x01a19c30 }, /* mic-in */
4889 { 0x19, 0x02a19c40 }, /* front-mic */
4890 { 0x1a, 0x01813031 }, /* line-in */
4891 { 0x1b, 0x0121411f }, /* HP */
4892 { 0x1c, 0x411111f0 }, /* N/A */
4893 { 0x1d, 0x411111f0 }, /* N/A */
4894 /* 0x1e is filled in below */
4895 { 0x1f, 0x411111f0 }, /* N/A */
4896 { }
4897 }
4898 },
4899 [ALC880_FIXUP_6ST] = {
4900 .type = ALC_FIXUP_PINS,
4901 .v.pins = (const struct alc_pincfg[]) {
4902 { 0x1e, 0x411111f0 }, /* N/A */
4903 { }
4904 },
4905 .chained = true,
4906 .chain_id = ALC880_FIXUP_6ST_BASE,
4907 },
4908 [ALC880_FIXUP_6ST_DIG] = {
4909 .type = ALC_FIXUP_PINS,
4910 .v.pins = (const struct alc_pincfg[]) {
4911 { 0x1e, 0x0144111e }, /* SPDIF */
4912 { }
4913 },
4914 .chained = true,
4915 .chain_id = ALC880_FIXUP_6ST_BASE,
4916 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004917};
4918
4919static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004920 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004921 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004922 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4923 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004924 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004925 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004926 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004927 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004928 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004929 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004930 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004931 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004932 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004933 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004934 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004935 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4936 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4937 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004938 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004939
4940 /* Below is the copied entries from alc880_quirks.c.
4941 * It's not quite sure whether BIOS sets the correct pin-config table
4942 * on these machines, thus they are kept to be compatible with
4943 * the old static quirks. Once when it's confirmed to work without
4944 * these overrides, it'd be better to remove.
4945 */
4946 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4947 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4948 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4949 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4950 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4951 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4952 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4953 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4954 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4955 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4956 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4957 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4958 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4959 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4960 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4961 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4962 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4963 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4964 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4965 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4966 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4967 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4968 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4969 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4970 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4971 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4972 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4973 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4974 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4975 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4976 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4977 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4978 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4979 /* default Intel */
4980 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4981 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4982 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4983 {}
4984};
4985
4986static const struct alc_model_fixup alc880_fixup_models[] = {
4987 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4988 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4989 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4990 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4991 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4992 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004993 {}
4994};
4995
4996
4997/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004998 * OK, here we have finally the patch for ALC880
4999 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000static int patch_alc880(struct hda_codec *codec)
5001{
5002 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005003 int err;
5004
Takashi Iwai3de95172012-05-07 18:03:15 +02005005 err = alc_alloc_spec(codec, 0x0b);
5006 if (err < 0)
5007 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005008
Takashi Iwai3de95172012-05-07 18:03:15 +02005009 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02005010 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005011
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005012 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
5013 alc880_fixups);
5014 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005015
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005016 /* automatic parse from the BIOS config */
5017 err = alc880_parse_auto_config(codec);
5018 if (err < 0)
5019 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005020
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005021 if (!spec->no_analog) {
5022 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005023 if (err < 0)
5024 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005025 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5026 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005027
Takashi Iwai1d045db2011-07-07 18:23:21 +02005028 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02005029 codec->patch_ops.unsol_event = alc880_unsol_event;
5030
Takashi Iwai1d045db2011-07-07 18:23:21 +02005031
Takashi Iwai589876e2012-02-20 15:47:55 +01005032 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5033
Takashi Iwai1d045db2011-07-07 18:23:21 +02005034 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005035
5036 error:
5037 alc_free(codec);
5038 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005039}
5040
5041
5042/*
5043 * ALC260 support
5044 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005045static int alc260_parse_auto_config(struct hda_codec *codec)
5046{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005047 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005048 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5049 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005050}
5051
Takashi Iwai1d045db2011-07-07 18:23:21 +02005052/*
5053 * Pin config fixes
5054 */
5055enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005056 ALC260_FIXUP_HP_DC5750,
5057 ALC260_FIXUP_HP_PIN_0F,
5058 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005059 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005060 ALC260_FIXUP_GPIO1_TOGGLE,
5061 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005062 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005063 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005064};
5065
Takashi Iwai20f7d922012-02-16 12:35:16 +01005066static void alc260_gpio1_automute(struct hda_codec *codec)
5067{
5068 struct alc_spec *spec = codec->spec;
5069 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5070 spec->hp_jack_present);
5071}
5072
5073static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5074 const struct alc_fixup *fix, int action)
5075{
5076 struct alc_spec *spec = codec->spec;
5077 if (action == ALC_FIXUP_ACT_PROBE) {
5078 /* although the machine has only one output pin, we need to
5079 * toggle GPIO1 according to the jack state
5080 */
5081 spec->automute_hook = alc260_gpio1_automute;
5082 spec->detect_hp = 1;
5083 spec->automute_speaker = 1;
5084 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005085 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5086 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005087 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005088 }
5089}
5090
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005091static void alc260_fixup_kn1(struct hda_codec *codec,
5092 const struct alc_fixup *fix, int action)
5093{
5094 struct alc_spec *spec = codec->spec;
5095 static const struct alc_pincfg pincfgs[] = {
5096 { 0x0f, 0x02214000 }, /* HP/speaker */
5097 { 0x12, 0x90a60160 }, /* int mic */
5098 { 0x13, 0x02a19000 }, /* ext mic */
5099 { 0x18, 0x01446000 }, /* SPDIF out */
5100 /* disable bogus I/O pins */
5101 { 0x10, 0x411111f0 },
5102 { 0x11, 0x411111f0 },
5103 { 0x14, 0x411111f0 },
5104 { 0x15, 0x411111f0 },
5105 { 0x16, 0x411111f0 },
5106 { 0x17, 0x411111f0 },
5107 { 0x19, 0x411111f0 },
5108 { }
5109 };
5110
5111 switch (action) {
5112 case ALC_FIXUP_ACT_PRE_PROBE:
5113 alc_apply_pincfgs(codec, pincfgs);
5114 break;
5115 case ALC_FIXUP_ACT_PROBE:
5116 spec->init_amp = ALC_INIT_NONE;
5117 break;
5118 }
5119}
5120
Takashi Iwai1d045db2011-07-07 18:23:21 +02005121static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005122 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005123 .type = ALC_FIXUP_PINS,
5124 .v.pins = (const struct alc_pincfg[]) {
5125 { 0x11, 0x90130110 }, /* speaker */
5126 { }
5127 }
5128 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005129 [ALC260_FIXUP_HP_PIN_0F] = {
5130 .type = ALC_FIXUP_PINS,
5131 .v.pins = (const struct alc_pincfg[]) {
5132 { 0x0f, 0x01214000 }, /* HP */
5133 { }
5134 }
5135 },
5136 [ALC260_FIXUP_COEF] = {
5137 .type = ALC_FIXUP_VERBS,
5138 .v.verbs = (const struct hda_verb[]) {
5139 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5140 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5141 { }
5142 },
5143 .chained = true,
5144 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5145 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005146 [ALC260_FIXUP_GPIO1] = {
5147 .type = ALC_FIXUP_VERBS,
5148 .v.verbs = alc_gpio1_init_verbs,
5149 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005150 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5151 .type = ALC_FIXUP_FUNC,
5152 .v.func = alc260_fixup_gpio1_toggle,
5153 .chained = true,
5154 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5155 },
5156 [ALC260_FIXUP_REPLACER] = {
5157 .type = ALC_FIXUP_VERBS,
5158 .v.verbs = (const struct hda_verb[]) {
5159 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5160 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5161 { }
5162 },
5163 .chained = true,
5164 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5165 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005166 [ALC260_FIXUP_HP_B1900] = {
5167 .type = ALC_FIXUP_FUNC,
5168 .v.func = alc260_fixup_gpio1_toggle,
5169 .chained = true,
5170 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005171 },
5172 [ALC260_FIXUP_KN1] = {
5173 .type = ALC_FIXUP_FUNC,
5174 .v.func = alc260_fixup_kn1,
5175 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005176};
5177
5178static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005179 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005180 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005181 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005182 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005183 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005184 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005185 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005186 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005187 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005188 {}
5189};
5190
5191/*
5192 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005193static int patch_alc260(struct hda_codec *codec)
5194{
5195 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005196 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005197
Takashi Iwai3de95172012-05-07 18:03:15 +02005198 err = alc_alloc_spec(codec, 0x07);
5199 if (err < 0)
5200 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005201
Takashi Iwai3de95172012-05-07 18:03:15 +02005202 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005203
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005204 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5205 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005206
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005207 /* automatic parse from the BIOS config */
5208 err = alc260_parse_auto_config(codec);
5209 if (err < 0)
5210 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005211
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005212 if (!spec->no_analog) {
5213 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005214 if (err < 0)
5215 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005216 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5217 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005218
Takashi Iwai1d045db2011-07-07 18:23:21 +02005219 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005220 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005221
Takashi Iwai589876e2012-02-20 15:47:55 +01005222 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5223
Takashi Iwai1d045db2011-07-07 18:23:21 +02005224 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005225
5226 error:
5227 alc_free(codec);
5228 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005229}
5230
5231
5232/*
5233 * ALC882/883/885/888/889 support
5234 *
5235 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5236 * configuration. Each pin widget can choose any input DACs and a mixer.
5237 * Each ADC is connected from a mixer of all inputs. This makes possible
5238 * 6-channel independent captures.
5239 *
5240 * In addition, an independent DAC for the multi-playback (not used in this
5241 * driver yet).
5242 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005243
5244/*
5245 * Pin config fixes
5246 */
5247enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005248 ALC882_FIXUP_ABIT_AW9D_MAX,
5249 ALC882_FIXUP_LENOVO_Y530,
5250 ALC882_FIXUP_PB_M5210,
5251 ALC882_FIXUP_ACER_ASPIRE_7736,
5252 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005253 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005254 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005255 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005256 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005257 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005258 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005259 ALC882_FIXUP_GPIO1,
5260 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005261 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005262 ALC889_FIXUP_COEF,
5263 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005264 ALC882_FIXUP_ACER_ASPIRE_4930G,
5265 ALC882_FIXUP_ACER_ASPIRE_8930G,
5266 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005267 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005268 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005269 ALC889_FIXUP_MBP_VREF,
5270 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005271 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005272 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005273};
5274
Takashi Iwai68ef0562011-11-09 18:24:44 +01005275static void alc889_fixup_coef(struct hda_codec *codec,
5276 const struct alc_fixup *fix, int action)
5277{
5278 if (action != ALC_FIXUP_ACT_INIT)
5279 return;
5280 alc889_coef_init(codec);
5281}
5282
Takashi Iwai56710872011-11-14 17:42:11 +01005283/* toggle speaker-output according to the hp-jack state */
5284static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5285{
5286 unsigned int gpiostate, gpiomask, gpiodir;
5287
5288 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5289 AC_VERB_GET_GPIO_DATA, 0);
5290
5291 if (!muted)
5292 gpiostate |= (1 << pin);
5293 else
5294 gpiostate &= ~(1 << pin);
5295
5296 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5297 AC_VERB_GET_GPIO_MASK, 0);
5298 gpiomask |= (1 << pin);
5299
5300 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5301 AC_VERB_GET_GPIO_DIRECTION, 0);
5302 gpiodir |= (1 << pin);
5303
5304
5305 snd_hda_codec_write(codec, codec->afg, 0,
5306 AC_VERB_SET_GPIO_MASK, gpiomask);
5307 snd_hda_codec_write(codec, codec->afg, 0,
5308 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5309
5310 msleep(1);
5311
5312 snd_hda_codec_write(codec, codec->afg, 0,
5313 AC_VERB_SET_GPIO_DATA, gpiostate);
5314}
5315
5316/* set up GPIO at initialization */
5317static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5318 const struct alc_fixup *fix, int action)
5319{
5320 if (action != ALC_FIXUP_ACT_INIT)
5321 return;
5322 alc882_gpio_mute(codec, 0, 0);
5323 alc882_gpio_mute(codec, 1, 0);
5324}
5325
Takashi Iwai02a237b2012-02-13 15:25:07 +01005326/* Fix the connection of some pins for ALC889:
5327 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5328 * work correctly (bko#42740)
5329 */
5330static void alc889_fixup_dac_route(struct hda_codec *codec,
5331 const struct alc_fixup *fix, int action)
5332{
5333 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005334 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005335 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5336 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5337 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5338 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5339 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5340 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005341 } else if (action == ALC_FIXUP_ACT_PROBE) {
5342 /* restore the connections */
5343 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5344 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5345 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5346 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5347 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005348 }
5349}
5350
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005351/* Set VREF on HP pin */
5352static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5353 const struct alc_fixup *fix, int action)
5354{
5355 struct alc_spec *spec = codec->spec;
5356 static hda_nid_t nids[2] = { 0x14, 0x15 };
5357 int i;
5358
5359 if (action != ALC_FIXUP_ACT_INIT)
5360 return;
5361 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5362 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5363 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5364 continue;
5365 val = snd_hda_codec_read(codec, nids[i], 0,
5366 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5367 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005368 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005369 spec->keep_vref_in_automute = 1;
5370 break;
5371 }
5372}
5373
5374/* Set VREF on speaker pins on imac91 */
5375static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5376 const struct alc_fixup *fix, int action)
5377{
5378 struct alc_spec *spec = codec->spec;
5379 static hda_nid_t nids[2] = { 0x18, 0x1a };
5380 int i;
5381
5382 if (action != ALC_FIXUP_ACT_INIT)
5383 return;
5384 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5385 unsigned int val;
5386 val = snd_hda_codec_read(codec, nids[i], 0,
5387 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5388 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005389 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005390 }
5391 spec->keep_vref_in_automute = 1;
5392}
5393
Takashi Iwaie427c232012-07-29 10:04:08 +02005394/* Don't take HP output as primary
5395 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5396 */
5397static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5398 const struct alc_fixup *fix, int action)
5399{
5400 struct alc_spec *spec = codec->spec;
5401 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5402 spec->no_primary_hp = 1;
5403}
5404
Takashi Iwai1d045db2011-07-07 18:23:21 +02005405static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005406 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005407 .type = ALC_FIXUP_PINS,
5408 .v.pins = (const struct alc_pincfg[]) {
5409 { 0x15, 0x01080104 }, /* side */
5410 { 0x16, 0x01011012 }, /* rear */
5411 { 0x17, 0x01016011 }, /* clfe */
5412 { }
5413 }
5414 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005415 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005416 .type = ALC_FIXUP_PINS,
5417 .v.pins = (const struct alc_pincfg[]) {
5418 { 0x15, 0x99130112 }, /* rear int speakers */
5419 { 0x16, 0x99130111 }, /* subwoofer */
5420 { }
5421 }
5422 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005423 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005424 .type = ALC_FIXUP_VERBS,
5425 .v.verbs = (const struct hda_verb[]) {
5426 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5427 {}
5428 }
5429 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005430 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005431 .type = ALC_FIXUP_FUNC,
5432 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005433 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005434 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005435 .type = ALC_FIXUP_PINS,
5436 .v.pins = (const struct alc_pincfg[]) {
5437 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5438 { }
5439 }
5440 },
Marton Balint8f239212012-03-05 21:33:23 +01005441 [ALC889_FIXUP_CD] = {
5442 .type = ALC_FIXUP_PINS,
5443 .v.pins = (const struct alc_pincfg[]) {
5444 { 0x1c, 0x993301f0 }, /* CD */
5445 { }
5446 }
5447 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005448 [ALC889_FIXUP_VAIO_TT] = {
5449 .type = ALC_FIXUP_PINS,
5450 .v.pins = (const struct alc_pincfg[]) {
5451 { 0x17, 0x90170111 }, /* hidden surround speaker */
5452 { }
5453 }
5454 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005455 [ALC888_FIXUP_EEE1601] = {
5456 .type = ALC_FIXUP_VERBS,
5457 .v.verbs = (const struct hda_verb[]) {
5458 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5459 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5460 { }
5461 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005462 },
5463 [ALC882_FIXUP_EAPD] = {
5464 .type = ALC_FIXUP_VERBS,
5465 .v.verbs = (const struct hda_verb[]) {
5466 /* change to EAPD mode */
5467 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5468 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5469 { }
5470 }
5471 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005472 [ALC883_FIXUP_EAPD] = {
5473 .type = ALC_FIXUP_VERBS,
5474 .v.verbs = (const struct hda_verb[]) {
5475 /* change to EAPD mode */
5476 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5477 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5478 { }
5479 }
5480 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005481 [ALC883_FIXUP_ACER_EAPD] = {
5482 .type = ALC_FIXUP_VERBS,
5483 .v.verbs = (const struct hda_verb[]) {
5484 /* eanable EAPD on Acer laptops */
5485 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5486 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5487 { }
5488 }
5489 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005490 [ALC882_FIXUP_GPIO1] = {
5491 .type = ALC_FIXUP_VERBS,
5492 .v.verbs = alc_gpio1_init_verbs,
5493 },
5494 [ALC882_FIXUP_GPIO2] = {
5495 .type = ALC_FIXUP_VERBS,
5496 .v.verbs = alc_gpio2_init_verbs,
5497 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005498 [ALC882_FIXUP_GPIO3] = {
5499 .type = ALC_FIXUP_VERBS,
5500 .v.verbs = alc_gpio3_init_verbs,
5501 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005502 [ALC882_FIXUP_ASUS_W2JC] = {
5503 .type = ALC_FIXUP_VERBS,
5504 .v.verbs = alc_gpio1_init_verbs,
5505 .chained = true,
5506 .chain_id = ALC882_FIXUP_EAPD,
5507 },
5508 [ALC889_FIXUP_COEF] = {
5509 .type = ALC_FIXUP_FUNC,
5510 .v.func = alc889_fixup_coef,
5511 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005512 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5513 .type = ALC_FIXUP_PINS,
5514 .v.pins = (const struct alc_pincfg[]) {
5515 { 0x16, 0x99130111 }, /* CLFE speaker */
5516 { 0x17, 0x99130112 }, /* surround speaker */
5517 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005518 },
5519 .chained = true,
5520 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005521 },
5522 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5523 .type = ALC_FIXUP_PINS,
5524 .v.pins = (const struct alc_pincfg[]) {
5525 { 0x16, 0x99130111 }, /* CLFE speaker */
5526 { 0x1b, 0x99130112 }, /* surround speaker */
5527 { }
5528 },
5529 .chained = true,
5530 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5531 },
5532 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5533 /* additional init verbs for Acer Aspire 8930G */
5534 .type = ALC_FIXUP_VERBS,
5535 .v.verbs = (const struct hda_verb[]) {
5536 /* Enable all DACs */
5537 /* DAC DISABLE/MUTE 1? */
5538 /* setting bits 1-5 disables DAC nids 0x02-0x06
5539 * apparently. Init=0x38 */
5540 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5541 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5542 /* DAC DISABLE/MUTE 2? */
5543 /* some bit here disables the other DACs.
5544 * Init=0x4900 */
5545 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5546 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5547 /* DMIC fix
5548 * This laptop has a stereo digital microphone.
5549 * The mics are only 1cm apart which makes the stereo
5550 * useless. However, either the mic or the ALC889
5551 * makes the signal become a difference/sum signal
5552 * instead of standard stereo, which is annoying.
5553 * So instead we flip this bit which makes the
5554 * codec replicate the sum signal to both channels,
5555 * turning it into a normal mono mic.
5556 */
5557 /* DMIC_CONTROL? Init value = 0x0001 */
5558 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5559 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5560 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5561 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5562 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005563 },
5564 .chained = true,
5565 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005566 },
Takashi Iwai56710872011-11-14 17:42:11 +01005567 [ALC885_FIXUP_MACPRO_GPIO] = {
5568 .type = ALC_FIXUP_FUNC,
5569 .v.func = alc885_fixup_macpro_gpio,
5570 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005571 [ALC889_FIXUP_DAC_ROUTE] = {
5572 .type = ALC_FIXUP_FUNC,
5573 .v.func = alc889_fixup_dac_route,
5574 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005575 [ALC889_FIXUP_MBP_VREF] = {
5576 .type = ALC_FIXUP_FUNC,
5577 .v.func = alc889_fixup_mbp_vref,
5578 .chained = true,
5579 .chain_id = ALC882_FIXUP_GPIO1,
5580 },
5581 [ALC889_FIXUP_IMAC91_VREF] = {
5582 .type = ALC_FIXUP_FUNC,
5583 .v.func = alc889_fixup_imac91_vref,
5584 .chained = true,
5585 .chain_id = ALC882_FIXUP_GPIO1,
5586 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005587 [ALC882_FIXUP_INV_DMIC] = {
5588 .type = ALC_FIXUP_FUNC,
5589 .v.func = alc_fixup_inv_dmic_0x12,
5590 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005591 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5592 .type = ALC_FIXUP_FUNC,
5593 .v.func = alc882_fixup_no_primary_hp,
5594 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005595};
5596
5597static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005598 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5599 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5600 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5601 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5602 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5603 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005604 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5605 ALC882_FIXUP_ACER_ASPIRE_4930G),
5606 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5607 ALC882_FIXUP_ACER_ASPIRE_4930G),
5608 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5609 ALC882_FIXUP_ACER_ASPIRE_8930G),
5610 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5611 ALC882_FIXUP_ACER_ASPIRE_8930G),
5612 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5613 ALC882_FIXUP_ACER_ASPIRE_4930G),
5614 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5615 ALC882_FIXUP_ACER_ASPIRE_4930G),
5616 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5617 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005618 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005619 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5620 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005621 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005622 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005623 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005624 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005625 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005626 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005627 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005628 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005629 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005630
5631 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005632 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5633 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5634 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005635 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5636 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5637 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005638 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5639 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005640 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005641 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5642 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5643 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5644 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005645 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005646 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5647 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5648 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005649 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005650 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005651 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5652 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5653 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005654
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005655 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005656 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005657 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005658 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005659 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005660 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5661 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005662 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005663 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005664 {}
5665};
5666
Takashi Iwai912093b2012-04-11 14:03:41 +02005667static const struct alc_model_fixup alc882_fixup_models[] = {
5668 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5669 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5670 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005671 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005672 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005673 {}
5674};
5675
Takashi Iwai1d045db2011-07-07 18:23:21 +02005676/*
5677 * BIOS auto configuration
5678 */
5679/* almost identical with ALC880 parser... */
5680static int alc882_parse_auto_config(struct hda_codec *codec)
5681{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005682 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005683 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5684 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005685}
5686
Takashi Iwai1d045db2011-07-07 18:23:21 +02005687/*
5688 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005689static int patch_alc882(struct hda_codec *codec)
5690{
5691 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005692 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005693
Takashi Iwai3de95172012-05-07 18:03:15 +02005694 err = alc_alloc_spec(codec, 0x0b);
5695 if (err < 0)
5696 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005697
Takashi Iwai3de95172012-05-07 18:03:15 +02005698 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005699
5700 switch (codec->vendor_id) {
5701 case 0x10ec0882:
5702 case 0x10ec0885:
5703 break;
5704 default:
5705 /* ALC883 and variants */
5706 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5707 break;
5708 }
5709
Takashi Iwai912093b2012-04-11 14:03:41 +02005710 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5711 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005712 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005713
5714 alc_auto_parse_customize_define(codec);
5715
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005716 /* automatic parse from the BIOS config */
5717 err = alc882_parse_auto_config(codec);
5718 if (err < 0)
5719 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005720
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005721 if (!spec->no_analog && has_cdefine_beep(codec)) {
5722 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005723 if (err < 0)
5724 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005725 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005726 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727
Takashi Iwai1d045db2011-07-07 18:23:21 +02005728 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005729
Takashi Iwai589876e2012-02-20 15:47:55 +01005730 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5731
Takashi Iwai1d045db2011-07-07 18:23:21 +02005732 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005733
5734 error:
5735 alc_free(codec);
5736 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005737}
5738
5739
5740/*
5741 * ALC262 support
5742 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743static int alc262_parse_auto_config(struct hda_codec *codec)
5744{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005746 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5747 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748}
5749
5750/*
5751 * Pin config fixes
5752 */
5753enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005754 ALC262_FIXUP_FSC_H270,
5755 ALC262_FIXUP_HP_Z200,
5756 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005757 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005758 ALC262_FIXUP_BENQ,
5759 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005760 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005761};
5762
5763static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005764 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765 .type = ALC_FIXUP_PINS,
5766 .v.pins = (const struct alc_pincfg[]) {
5767 { 0x14, 0x99130110 }, /* speaker */
5768 { 0x15, 0x0221142f }, /* front HP */
5769 { 0x1b, 0x0121141f }, /* rear HP */
5770 { }
5771 }
5772 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005773 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005774 .type = ALC_FIXUP_PINS,
5775 .v.pins = (const struct alc_pincfg[]) {
5776 { 0x16, 0x99130120 }, /* internal speaker */
5777 { }
5778 }
5779 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005780 [ALC262_FIXUP_TYAN] = {
5781 .type = ALC_FIXUP_PINS,
5782 .v.pins = (const struct alc_pincfg[]) {
5783 { 0x14, 0x1993e1f0 }, /* int AUX */
5784 { }
5785 }
5786 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005787 [ALC262_FIXUP_LENOVO_3000] = {
5788 .type = ALC_FIXUP_VERBS,
5789 .v.verbs = (const struct hda_verb[]) {
5790 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005791 {}
5792 },
5793 .chained = true,
5794 .chain_id = ALC262_FIXUP_BENQ,
5795 },
5796 [ALC262_FIXUP_BENQ] = {
5797 .type = ALC_FIXUP_VERBS,
5798 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005799 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5800 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5801 {}
5802 }
5803 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005804 [ALC262_FIXUP_BENQ_T31] = {
5805 .type = ALC_FIXUP_VERBS,
5806 .v.verbs = (const struct hda_verb[]) {
5807 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5808 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5809 {}
5810 }
5811 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005812 [ALC262_FIXUP_INV_DMIC] = {
5813 .type = ALC_FIXUP_FUNC,
5814 .v.func = alc_fixup_inv_dmic_0x12,
5815 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005816};
5817
5818static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005819 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005820 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5821 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005822 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5823 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005824 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005825 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5826 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005827 {}
5828};
5829
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005830static const struct alc_model_fixup alc262_fixup_models[] = {
5831 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5832 {}
5833};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005834
Takashi Iwai1d045db2011-07-07 18:23:21 +02005835/*
5836 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005837static int patch_alc262(struct hda_codec *codec)
5838{
5839 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005840 int err;
5841
Takashi Iwai3de95172012-05-07 18:03:15 +02005842 err = alc_alloc_spec(codec, 0x0b);
5843 if (err < 0)
5844 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005845
Takashi Iwai3de95172012-05-07 18:03:15 +02005846 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005847
5848#if 0
5849 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5850 * under-run
5851 */
5852 {
5853 int tmp;
5854 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5855 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5856 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5857 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5858 }
5859#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005860 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5861
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005862 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5863 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005864 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005865
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005866 alc_auto_parse_customize_define(codec);
5867
Takashi Iwai42399f72011-11-07 17:18:44 +01005868 /* automatic parse from the BIOS config */
5869 err = alc262_parse_auto_config(codec);
5870 if (err < 0)
5871 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005872
Takashi Iwai1d045db2011-07-07 18:23:21 +02005873 if (!spec->no_analog && has_cdefine_beep(codec)) {
5874 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005875 if (err < 0)
5876 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005877 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005878 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005879
Takashi Iwai1d045db2011-07-07 18:23:21 +02005880 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005881 spec->shutup = alc_eapd_shutup;
5882
Takashi Iwai589876e2012-02-20 15:47:55 +01005883 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5884
Takashi Iwai1d045db2011-07-07 18:23:21 +02005885 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005886
5887 error:
5888 alc_free(codec);
5889 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005890}
5891
5892/*
5893 * ALC268
5894 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005895/* bind Beep switches of both NID 0x0f and 0x10 */
5896static const struct hda_bind_ctls alc268_bind_beep_sw = {
5897 .ops = &snd_hda_bind_sw,
5898 .values = {
5899 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5900 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5901 0
5902 },
5903};
5904
5905static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5906 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5907 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5908 { }
5909};
5910
5911/* set PCBEEP vol = 0, mute connections */
5912static const struct hda_verb alc268_beep_init_verbs[] = {
5913 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5914 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5915 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5916 { }
5917};
5918
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005919enum {
5920 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005921 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005922};
5923
5924static const struct alc_fixup alc268_fixups[] = {
5925 [ALC268_FIXUP_INV_DMIC] = {
5926 .type = ALC_FIXUP_FUNC,
5927 .v.func = alc_fixup_inv_dmic_0x12,
5928 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005929 [ALC268_FIXUP_HP_EAPD] = {
5930 .type = ALC_FIXUP_VERBS,
5931 .v.verbs = (const struct hda_verb[]) {
5932 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5933 {}
5934 }
5935 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005936};
5937
5938static const struct alc_model_fixup alc268_fixup_models[] = {
5939 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005940 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5941 {}
5942};
5943
5944static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5945 /* below is codec SSID since multiple Toshiba laptops have the
5946 * same PCI SSID 1179:ff00
5947 */
5948 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005949 {}
5950};
5951
Takashi Iwai1d045db2011-07-07 18:23:21 +02005952/*
5953 * BIOS auto configuration
5954 */
5955static int alc268_parse_auto_config(struct hda_codec *codec)
5956{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005957 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005958 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005959 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5960 if (err > 0) {
5961 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5962 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005963 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005964 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005965 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005966 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005967}
5968
Takashi Iwai1d045db2011-07-07 18:23:21 +02005969/*
5970 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005971static int patch_alc268(struct hda_codec *codec)
5972{
5973 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005974 int i, has_beep, err;
5975
Takashi Iwai1d045db2011-07-07 18:23:21 +02005976 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005977 err = alc_alloc_spec(codec, 0);
5978 if (err < 0)
5979 return err;
5980
5981 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005982
Takashi Iwaicb766402012-10-20 10:55:21 +02005983 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005984 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5985
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005986 /* automatic parse from the BIOS config */
5987 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005988 if (err < 0)
5989 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005990
Takashi Iwai1d045db2011-07-07 18:23:21 +02005991 has_beep = 0;
5992 for (i = 0; i < spec->num_mixers; i++) {
5993 if (spec->mixers[i] == alc268_beep_mixer) {
5994 has_beep = 1;
5995 break;
5996 }
5997 }
5998
5999 if (has_beep) {
6000 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006001 if (err < 0)
6002 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006003 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
6004 /* override the amp caps for beep generator */
6005 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
6006 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
6007 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
6008 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6009 (0 << AC_AMPCAP_MUTE_SHIFT));
6010 }
6011
Takashi Iwai1d045db2011-07-07 18:23:21 +02006012 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006013 spec->shutup = alc_eapd_shutup;
6014
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006015 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6016
Takashi Iwai1d045db2011-07-07 18:23:21 +02006017 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006018
6019 error:
6020 alc_free(codec);
6021 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006022}
6023
6024/*
6025 * ALC269
6026 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006027static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6028 .substreams = 1,
6029 .channels_min = 2,
6030 .channels_max = 8,
6031 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6032 /* NID is set in alc_build_pcms */
6033 .ops = {
6034 .open = alc_playback_pcm_open,
6035 .prepare = alc_playback_pcm_prepare,
6036 .cleanup = alc_playback_pcm_cleanup
6037 },
6038};
6039
6040static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6041 .substreams = 1,
6042 .channels_min = 2,
6043 .channels_max = 2,
6044 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6045 /* NID is set in alc_build_pcms */
6046};
6047
Takashi Iwai1d045db2011-07-07 18:23:21 +02006048/* different alc269-variants */
6049enum {
6050 ALC269_TYPE_ALC269VA,
6051 ALC269_TYPE_ALC269VB,
6052 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006053 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006054 ALC269_TYPE_ALC280,
6055 ALC269_TYPE_ALC282,
6056 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006057};
6058
6059/*
6060 * BIOS auto configuration
6061 */
6062static int alc269_parse_auto_config(struct hda_codec *codec)
6063{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006064 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006065 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6066 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6067 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006068 const hda_nid_t *ssids;
6069
6070 switch (spec->codec_variant) {
6071 case ALC269_TYPE_ALC269VA:
6072 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006073 case ALC269_TYPE_ALC280:
6074 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006075 ssids = alc269va_ssids;
6076 break;
6077 case ALC269_TYPE_ALC269VB:
6078 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006079 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006080 ssids = alc269_ssids;
6081 break;
6082 default:
6083 ssids = alc269_ssids;
6084 break;
6085 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006086
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006087 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006088}
6089
Kailang Yang1387e2d2012-11-08 10:23:18 +01006090static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006091{
6092 int val = alc_read_coef_idx(codec, 0x04);
6093 if (power_up)
6094 val |= 1 << 11;
6095 else
6096 val &= ~(1 << 11);
6097 alc_write_coef_idx(codec, 0x04, val);
6098}
6099
6100static void alc269_shutup(struct hda_codec *codec)
6101{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006102 struct alc_spec *spec = codec->spec;
6103
6104 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6105 return;
6106
Kailang Yang1387e2d2012-11-08 10:23:18 +01006107 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6108 alc269vb_toggle_power_output(codec, 0);
6109 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6110 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006111 msleep(150);
6112 }
6113}
6114
Takashi Iwai2a439522011-07-26 09:52:50 +02006115#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006116static int alc269_resume(struct hda_codec *codec)
6117{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006118 struct alc_spec *spec = codec->spec;
6119
Kailang Yang1387e2d2012-11-08 10:23:18 +01006120 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6121 alc269vb_toggle_power_output(codec, 0);
6122 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006123 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006124 msleep(150);
6125 }
6126
6127 codec->patch_ops.init(codec);
6128
Kailang Yang1387e2d2012-11-08 10:23:18 +01006129 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6130 alc269vb_toggle_power_output(codec, 1);
6131 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006132 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006133 msleep(200);
6134 }
6135
Takashi Iwai1d045db2011-07-07 18:23:21 +02006136 snd_hda_codec_resume_amp(codec);
6137 snd_hda_codec_resume_cache(codec);
6138 hda_call_check_power_status(codec, 0x01);
6139 return 0;
6140}
Takashi Iwai2a439522011-07-26 09:52:50 +02006141#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006142
David Henningsson108cc102012-07-20 10:37:25 +02006143static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6144 const struct alc_fixup *fix, int action)
6145{
6146 struct alc_spec *spec = codec->spec;
6147
6148 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6149 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6150}
6151
Takashi Iwai1d045db2011-07-07 18:23:21 +02006152static void alc269_fixup_hweq(struct hda_codec *codec,
6153 const struct alc_fixup *fix, int action)
6154{
6155 int coef;
6156
6157 if (action != ALC_FIXUP_ACT_INIT)
6158 return;
6159 coef = alc_read_coef_idx(codec, 0x1e);
6160 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6161}
6162
6163static void alc271_fixup_dmic(struct hda_codec *codec,
6164 const struct alc_fixup *fix, int action)
6165{
6166 static const struct hda_verb verbs[] = {
6167 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6168 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6169 {}
6170 };
6171 unsigned int cfg;
6172
6173 if (strcmp(codec->chip_name, "ALC271X"))
6174 return;
6175 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6176 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6177 snd_hda_sequence_write(codec, verbs);
6178}
6179
Takashi Iwai017f2a12011-07-09 14:42:25 +02006180static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6181 const struct alc_fixup *fix, int action)
6182{
6183 struct alc_spec *spec = codec->spec;
6184
6185 if (action != ALC_FIXUP_ACT_PROBE)
6186 return;
6187
6188 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6189 * fix the sample rate of analog I/O to 44.1kHz
6190 */
6191 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6192 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6193}
6194
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006195static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6196 const struct alc_fixup *fix, int action)
6197{
6198 int coef;
6199
6200 if (action != ALC_FIXUP_ACT_INIT)
6201 return;
6202 /* The digital-mic unit sends PDM (differential signal) instead of
6203 * the standard PCM, thus you can't record a valid mono stream as is.
6204 * Below is a workaround specific to ALC269 to control the dmic
6205 * signal source as mono.
6206 */
6207 coef = alc_read_coef_idx(codec, 0x07);
6208 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6209}
6210
Takashi Iwai24519912011-08-16 15:08:49 +02006211static void alc269_quanta_automute(struct hda_codec *codec)
6212{
David Henningsson42cf0d02011-09-20 12:04:56 +02006213 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006214
6215 snd_hda_codec_write(codec, 0x20, 0,
6216 AC_VERB_SET_COEF_INDEX, 0x0c);
6217 snd_hda_codec_write(codec, 0x20, 0,
6218 AC_VERB_SET_PROC_COEF, 0x680);
6219
6220 snd_hda_codec_write(codec, 0x20, 0,
6221 AC_VERB_SET_COEF_INDEX, 0x0c);
6222 snd_hda_codec_write(codec, 0x20, 0,
6223 AC_VERB_SET_PROC_COEF, 0x480);
6224}
6225
6226static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6227 const struct alc_fixup *fix, int action)
6228{
6229 struct alc_spec *spec = codec->spec;
6230 if (action != ALC_FIXUP_ACT_PROBE)
6231 return;
6232 spec->automute_hook = alc269_quanta_automute;
6233}
6234
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006235/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6236static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6237{
6238 struct hda_codec *codec = private_data;
6239 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6240 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6241 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6242}
6243
6244static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6245 const struct alc_fixup *fix, int action)
6246{
6247 struct alc_spec *spec = codec->spec;
6248 switch (action) {
6249 case ALC_FIXUP_ACT_BUILD:
6250 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6251 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6252 /* fallthru */
6253 case ALC_FIXUP_ACT_INIT:
6254 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6255 break;
6256 }
6257}
6258
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006259/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6260static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6261{
6262 struct hda_codec *codec = private_data;
6263 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006264 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006265}
6266
6267static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6268 const struct alc_fixup *fix, int action)
6269{
6270 struct alc_spec *spec = codec->spec;
6271 switch (action) {
6272 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006273 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006274 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006275 /* fallthru */
6276 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006277 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006278 break;
6279 }
6280}
6281
Dylan Reid08a978d2012-11-18 22:56:40 -08006282static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6283 const struct alc_fixup *fix,
6284 int action)
6285{
6286 struct alc_spec *spec = codec->spec;
6287
6288 if (action == ALC_FIXUP_ACT_PROBE)
6289 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6290 spec->autocfg.hp_pins[0]);
6291}
David Henningsson693b6132012-06-22 19:12:10 +02006292
Takashi Iwai1d045db2011-07-07 18:23:21 +02006293enum {
6294 ALC269_FIXUP_SONY_VAIO,
6295 ALC275_FIXUP_SONY_VAIO_GPIO2,
6296 ALC269_FIXUP_DELL_M101Z,
6297 ALC269_FIXUP_SKU_IGNORE,
6298 ALC269_FIXUP_ASUS_G73JW,
6299 ALC269_FIXUP_LENOVO_EAPD,
6300 ALC275_FIXUP_SONY_HWEQ,
6301 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006302 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006303 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006304 ALC269_FIXUP_QUANTA_MUTE,
6305 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006306 ALC269_FIXUP_AMIC,
6307 ALC269_FIXUP_DMIC,
6308 ALC269VB_FIXUP_AMIC,
6309 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006310 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006311 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006312 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006313 ALC269_FIXUP_LENOVO_DOCK,
6314 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006315 ALC271_FIXUP_AMIC_MIC2,
6316 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006317};
6318
6319static const struct alc_fixup alc269_fixups[] = {
6320 [ALC269_FIXUP_SONY_VAIO] = {
6321 .type = ALC_FIXUP_VERBS,
6322 .v.verbs = (const struct hda_verb[]) {
6323 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6324 {}
6325 }
6326 },
6327 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6328 .type = ALC_FIXUP_VERBS,
6329 .v.verbs = (const struct hda_verb[]) {
6330 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6331 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6332 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6333 { }
6334 },
6335 .chained = true,
6336 .chain_id = ALC269_FIXUP_SONY_VAIO
6337 },
6338 [ALC269_FIXUP_DELL_M101Z] = {
6339 .type = ALC_FIXUP_VERBS,
6340 .v.verbs = (const struct hda_verb[]) {
6341 /* Enables internal speaker */
6342 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6343 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6344 {}
6345 }
6346 },
6347 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006348 .type = ALC_FIXUP_FUNC,
6349 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006350 },
6351 [ALC269_FIXUP_ASUS_G73JW] = {
6352 .type = ALC_FIXUP_PINS,
6353 .v.pins = (const struct alc_pincfg[]) {
6354 { 0x17, 0x99130111 }, /* subwoofer */
6355 { }
6356 }
6357 },
6358 [ALC269_FIXUP_LENOVO_EAPD] = {
6359 .type = ALC_FIXUP_VERBS,
6360 .v.verbs = (const struct hda_verb[]) {
6361 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6362 {}
6363 }
6364 },
6365 [ALC275_FIXUP_SONY_HWEQ] = {
6366 .type = ALC_FIXUP_FUNC,
6367 .v.func = alc269_fixup_hweq,
6368 .chained = true,
6369 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6370 },
6371 [ALC271_FIXUP_DMIC] = {
6372 .type = ALC_FIXUP_FUNC,
6373 .v.func = alc271_fixup_dmic,
6374 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006375 [ALC269_FIXUP_PCM_44K] = {
6376 .type = ALC_FIXUP_FUNC,
6377 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006378 .chained = true,
6379 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006380 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006381 [ALC269_FIXUP_STEREO_DMIC] = {
6382 .type = ALC_FIXUP_FUNC,
6383 .v.func = alc269_fixup_stereo_dmic,
6384 },
Takashi Iwai24519912011-08-16 15:08:49 +02006385 [ALC269_FIXUP_QUANTA_MUTE] = {
6386 .type = ALC_FIXUP_FUNC,
6387 .v.func = alc269_fixup_quanta_mute,
6388 },
6389 [ALC269_FIXUP_LIFEBOOK] = {
6390 .type = ALC_FIXUP_PINS,
6391 .v.pins = (const struct alc_pincfg[]) {
6392 { 0x1a, 0x2101103f }, /* dock line-out */
6393 { 0x1b, 0x23a11040 }, /* dock mic-in */
6394 { }
6395 },
6396 .chained = true,
6397 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6398 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006399 [ALC269_FIXUP_AMIC] = {
6400 .type = ALC_FIXUP_PINS,
6401 .v.pins = (const struct alc_pincfg[]) {
6402 { 0x14, 0x99130110 }, /* speaker */
6403 { 0x15, 0x0121401f }, /* HP out */
6404 { 0x18, 0x01a19c20 }, /* mic */
6405 { 0x19, 0x99a3092f }, /* int-mic */
6406 { }
6407 },
6408 },
6409 [ALC269_FIXUP_DMIC] = {
6410 .type = ALC_FIXUP_PINS,
6411 .v.pins = (const struct alc_pincfg[]) {
6412 { 0x12, 0x99a3092f }, /* int-mic */
6413 { 0x14, 0x99130110 }, /* speaker */
6414 { 0x15, 0x0121401f }, /* HP out */
6415 { 0x18, 0x01a19c20 }, /* mic */
6416 { }
6417 },
6418 },
6419 [ALC269VB_FIXUP_AMIC] = {
6420 .type = ALC_FIXUP_PINS,
6421 .v.pins = (const struct alc_pincfg[]) {
6422 { 0x14, 0x99130110 }, /* speaker */
6423 { 0x18, 0x01a19c20 }, /* mic */
6424 { 0x19, 0x99a3092f }, /* int-mic */
6425 { 0x21, 0x0121401f }, /* HP out */
6426 { }
6427 },
6428 },
David Henningsson2267ea92012-01-03 08:45:56 +01006429 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006430 .type = ALC_FIXUP_PINS,
6431 .v.pins = (const struct alc_pincfg[]) {
6432 { 0x12, 0x99a3092f }, /* int-mic */
6433 { 0x14, 0x99130110 }, /* speaker */
6434 { 0x18, 0x01a19c20 }, /* mic */
6435 { 0x21, 0x0121401f }, /* HP out */
6436 { }
6437 },
6438 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006439 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6440 .type = ALC_FIXUP_FUNC,
6441 .v.func = alc269_fixup_mic1_mute,
6442 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006443 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6444 .type = ALC_FIXUP_FUNC,
6445 .v.func = alc269_fixup_mic2_mute,
6446 },
David Henningsson693b6132012-06-22 19:12:10 +02006447 [ALC269_FIXUP_INV_DMIC] = {
6448 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006449 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006450 },
David Henningsson108cc102012-07-20 10:37:25 +02006451 [ALC269_FIXUP_LENOVO_DOCK] = {
6452 .type = ALC_FIXUP_PINS,
6453 .v.pins = (const struct alc_pincfg[]) {
6454 { 0x19, 0x23a11040 }, /* dock mic */
6455 { 0x1b, 0x2121103f }, /* dock headphone */
6456 { }
6457 },
6458 .chained = true,
6459 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6460 },
6461 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6462 .type = ALC_FIXUP_FUNC,
6463 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6464 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006465 [ALC271_FIXUP_AMIC_MIC2] = {
6466 .type = ALC_FIXUP_PINS,
6467 .v.pins = (const struct alc_pincfg[]) {
6468 { 0x14, 0x99130110 }, /* speaker */
6469 { 0x19, 0x01a19c20 }, /* mic */
6470 { 0x1b, 0x99a7012f }, /* int-mic */
6471 { 0x21, 0x0121401f }, /* HP out */
6472 { }
6473 },
6474 },
6475 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6476 .type = ALC_FIXUP_FUNC,
6477 .v.func = alc271_hp_gate_mic_jack,
6478 .chained = true,
6479 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6480 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006481};
6482
6483static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006484 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6485 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006486 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006487 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006488 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006489 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006490 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006491 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006492 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6493 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6494 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6495 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6496 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006497 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6498 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6499 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6500 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6501 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006502 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006503 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006504 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006505 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6506 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6507 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6508 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6509 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006510 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006511 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006512 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006513 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006514 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006515 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006516 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006517
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006518#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006519 /* Below is a quirk table taken from the old code.
6520 * Basically the device should work as is without the fixup table.
6521 * If BIOS doesn't give a proper info, enable the corresponding
6522 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006523 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006524 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6525 ALC269_FIXUP_AMIC),
6526 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006527 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6528 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6529 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6530 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6531 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6532 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6533 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6534 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6535 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6536 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6537 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6538 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6539 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6540 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6541 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6542 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6543 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6544 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6545 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6546 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6547 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6548 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6549 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6550 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6551 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6552 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6553 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6554 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6555 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6556 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6557 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6558 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6559 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6560 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6561 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6562 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6563 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6564 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6565#endif
6566 {}
6567};
6568
6569static const struct alc_model_fixup alc269_fixup_models[] = {
6570 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6571 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006572 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6573 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6574 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006575 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006576 {}
6577};
6578
6579
Takashi Iwai546bb672012-03-07 08:37:19 +01006580static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006581{
Kailang Yang526af6e2012-03-07 08:25:20 +01006582 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006583 int val;
6584
Kailang Yang526af6e2012-03-07 08:25:20 +01006585 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006586 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006587
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006588 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006589 alc_write_coef_idx(codec, 0xf, 0x960b);
6590 alc_write_coef_idx(codec, 0xe, 0x8817);
6591 }
6592
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006593 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006594 alc_write_coef_idx(codec, 0xf, 0x960b);
6595 alc_write_coef_idx(codec, 0xe, 0x8814);
6596 }
6597
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006598 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006599 val = alc_read_coef_idx(codec, 0x04);
6600 /* Power up output pin */
6601 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6602 }
6603
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006604 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006605 val = alc_read_coef_idx(codec, 0xd);
6606 if ((val & 0x0c00) >> 10 != 0x1) {
6607 /* Capless ramp up clock control */
6608 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6609 }
6610 val = alc_read_coef_idx(codec, 0x17);
6611 if ((val & 0x01c0) >> 6 != 0x4) {
6612 /* Class D power on reset */
6613 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6614 }
6615 }
6616
6617 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6618 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6619
6620 val = alc_read_coef_idx(codec, 0x4); /* HP */
6621 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006622}
6623
6624/*
6625 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006626static int patch_alc269(struct hda_codec *codec)
6627{
6628 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006629 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006630
Takashi Iwai3de95172012-05-07 18:03:15 +02006631 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006632 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006633 return err;
6634
6635 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006636
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006637 alc_pick_fixup(codec, alc269_fixup_models,
6638 alc269_fixup_tbl, alc269_fixups);
6639 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6640
6641 alc_auto_parse_customize_define(codec);
6642
Kailang Yang065380f2013-01-10 10:25:48 +01006643 switch (codec->vendor_id) {
6644 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006645 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006646 switch (alc_get_coef0(codec) & 0x00f0) {
6647 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006648 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006649 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006650 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006651 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006652 break;
6653 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006654 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6655 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006656 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006657 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006658 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006659 case 0x0030:
6660 spec->codec_variant = ALC269_TYPE_ALC269VD;
6661 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006662 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006663 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006664 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006665 if (err < 0)
6666 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006667 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006668 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006669 break;
6670
6671 case 0x10ec0280:
6672 case 0x10ec0290:
6673 spec->codec_variant = ALC269_TYPE_ALC280;
6674 break;
6675 case 0x10ec0282:
6676 case 0x10ec0283:
6677 spec->codec_variant = ALC269_TYPE_ALC282;
6678 break;
6679 case 0x10ec0284:
6680 case 0x10ec0292:
6681 spec->codec_variant = ALC269_TYPE_ALC284;
6682 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006683 }
6684
Takashi Iwaia4297b52011-08-23 18:40:12 +02006685 /* automatic parse from the BIOS config */
6686 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006687 if (err < 0)
6688 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006689
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006690 if (!spec->no_analog && has_cdefine_beep(codec)) {
6691 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006692 if (err < 0)
6693 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006694 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006695 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006696
Takashi Iwai1d045db2011-07-07 18:23:21 +02006697 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006698#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006699 codec->patch_ops.resume = alc269_resume;
6700#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006701 spec->shutup = alc269_shutup;
6702
Takashi Iwai589876e2012-02-20 15:47:55 +01006703 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6704
Takashi Iwai1d045db2011-07-07 18:23:21 +02006705 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006706
6707 error:
6708 alc_free(codec);
6709 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006710}
6711
6712/*
6713 * ALC861
6714 */
6715
Takashi Iwai1d045db2011-07-07 18:23:21 +02006716static int alc861_parse_auto_config(struct hda_codec *codec)
6717{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006718 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006719 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6720 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006721}
6722
Takashi Iwai1d045db2011-07-07 18:23:21 +02006723/* Pin config fixes */
6724enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006725 ALC861_FIXUP_FSC_AMILO_PI1505,
6726 ALC861_FIXUP_AMP_VREF_0F,
6727 ALC861_FIXUP_NO_JACK_DETECT,
6728 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006729};
6730
Takashi Iwai31150f22012-01-30 10:54:08 +01006731/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6732static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6733 const struct alc_fixup *fix, int action)
6734{
6735 struct alc_spec *spec = codec->spec;
6736 unsigned int val;
6737
6738 if (action != ALC_FIXUP_ACT_INIT)
6739 return;
6740 val = snd_hda_codec_read(codec, 0x0f, 0,
6741 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6742 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6743 val |= AC_PINCTL_IN_EN;
6744 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006745 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006746 spec->keep_vref_in_automute = 1;
6747}
6748
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006749/* suppress the jack-detection */
6750static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6751 const struct alc_fixup *fix, int action)
6752{
6753 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6754 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006755}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006756
Takashi Iwai1d045db2011-07-07 18:23:21 +02006757static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006758 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006759 .type = ALC_FIXUP_PINS,
6760 .v.pins = (const struct alc_pincfg[]) {
6761 { 0x0b, 0x0221101f }, /* HP */
6762 { 0x0f, 0x90170310 }, /* speaker */
6763 { }
6764 }
6765 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006766 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006767 .type = ALC_FIXUP_FUNC,
6768 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006769 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006770 [ALC861_FIXUP_NO_JACK_DETECT] = {
6771 .type = ALC_FIXUP_FUNC,
6772 .v.func = alc_fixup_no_jack_detect,
6773 },
6774 [ALC861_FIXUP_ASUS_A6RP] = {
6775 .type = ALC_FIXUP_FUNC,
6776 .v.func = alc861_fixup_asus_amp_vref_0f,
6777 .chained = true,
6778 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6779 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006780};
6781
6782static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006783 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6784 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6785 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6786 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6787 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6788 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006789 {}
6790};
6791
6792/*
6793 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006794static int patch_alc861(struct hda_codec *codec)
6795{
6796 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006797 int err;
6798
Takashi Iwai3de95172012-05-07 18:03:15 +02006799 err = alc_alloc_spec(codec, 0x15);
6800 if (err < 0)
6801 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006802
Takashi Iwai3de95172012-05-07 18:03:15 +02006803 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006804
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006805 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6806 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006807
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006808 /* automatic parse from the BIOS config */
6809 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006810 if (err < 0)
6811 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006812
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006813 if (!spec->no_analog) {
6814 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006815 if (err < 0)
6816 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006817 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6818 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006819
Takashi Iwai1d045db2011-07-07 18:23:21 +02006820 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006821#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006822 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006823#endif
6824
Takashi Iwai589876e2012-02-20 15:47:55 +01006825 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6826
Takashi Iwai1d045db2011-07-07 18:23:21 +02006827 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006828
6829 error:
6830 alc_free(codec);
6831 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006832}
6833
6834/*
6835 * ALC861-VD support
6836 *
6837 * Based on ALC882
6838 *
6839 * In addition, an independent DAC
6840 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006841static int alc861vd_parse_auto_config(struct hda_codec *codec)
6842{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006843 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006844 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6845 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006846}
6847
Takashi Iwai1d045db2011-07-07 18:23:21 +02006848enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006849 ALC660VD_FIX_ASUS_GPIO1,
6850 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006851};
6852
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006853/* exclude VREF80 */
6854static void alc861vd_fixup_dallas(struct hda_codec *codec,
6855 const struct alc_fixup *fix, int action)
6856{
6857 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006858 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6859 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006860 }
6861}
6862
Takashi Iwai1d045db2011-07-07 18:23:21 +02006863static const struct alc_fixup alc861vd_fixups[] = {
6864 [ALC660VD_FIX_ASUS_GPIO1] = {
6865 .type = ALC_FIXUP_VERBS,
6866 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006867 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006868 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6869 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6870 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6871 { }
6872 }
6873 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006874 [ALC861VD_FIX_DALLAS] = {
6875 .type = ALC_FIXUP_FUNC,
6876 .v.func = alc861vd_fixup_dallas,
6877 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006878};
6879
6880static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006881 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006882 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006883 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006884 {}
6885};
6886
Takashi Iwai1d045db2011-07-07 18:23:21 +02006887/*
6888 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006889static int patch_alc861vd(struct hda_codec *codec)
6890{
6891 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006892 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006893
Takashi Iwai3de95172012-05-07 18:03:15 +02006894 err = alc_alloc_spec(codec, 0x0b);
6895 if (err < 0)
6896 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006897
Takashi Iwai3de95172012-05-07 18:03:15 +02006898 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006899
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006900 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6901 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006902
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006903 /* automatic parse from the BIOS config */
6904 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006905 if (err < 0)
6906 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006907
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006908 if (!spec->no_analog) {
6909 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006910 if (err < 0)
6911 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006912 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6913 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006914
Takashi Iwai1d045db2011-07-07 18:23:21 +02006915 codec->patch_ops = alc_patch_ops;
6916
Takashi Iwai1d045db2011-07-07 18:23:21 +02006917 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006918
Takashi Iwai589876e2012-02-20 15:47:55 +01006919 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6920
Takashi Iwai1d045db2011-07-07 18:23:21 +02006921 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006922
6923 error:
6924 alc_free(codec);
6925 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006926}
6927
6928/*
6929 * ALC662 support
6930 *
6931 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6932 * configuration. Each pin widget can choose any input DACs and a mixer.
6933 * Each ADC is connected from a mixer of all inputs. This makes possible
6934 * 6-channel independent captures.
6935 *
6936 * In addition, an independent DAC for the multi-playback (not used in this
6937 * driver yet).
6938 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006939
6940/*
6941 * BIOS auto configuration
6942 */
6943
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006944static int alc662_parse_auto_config(struct hda_codec *codec)
6945{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006946 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006947 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6948 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6949 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006950
Kailang Yang6227cdc2010-02-25 08:36:52 +01006951 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6952 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006953 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006954 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006955 ssids = alc662_ssids;
6956 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006957}
6958
Todd Broch6be79482010-12-07 16:51:05 -08006959static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006960 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006961{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006962 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006963 return;
Todd Broch6be79482010-12-07 16:51:05 -08006964 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6965 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6966 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6967 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6968 (0 << AC_AMPCAP_MUTE_SHIFT)))
6969 printk(KERN_WARNING
6970 "hda_codec: failed to override amp caps for NID 0x2\n");
6971}
6972
David Henningsson6cb3b702010-09-09 08:51:44 +02006973enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006974 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006975 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006976 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006977 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006978 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006979 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006980 ALC662_FIXUP_ASUS_MODE1,
6981 ALC662_FIXUP_ASUS_MODE2,
6982 ALC662_FIXUP_ASUS_MODE3,
6983 ALC662_FIXUP_ASUS_MODE4,
6984 ALC662_FIXUP_ASUS_MODE5,
6985 ALC662_FIXUP_ASUS_MODE6,
6986 ALC662_FIXUP_ASUS_MODE7,
6987 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006988 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006989 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006990 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006991};
6992
6993static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006994 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006995 .type = ALC_FIXUP_PINS,
6996 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006997 { 0x15, 0x99130112 }, /* subwoofer */
6998 { }
6999 }
7000 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007001 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007002 .type = ALC_FIXUP_PINS,
7003 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02007004 { 0x17, 0x99130112 }, /* subwoofer */
7005 { }
7006 }
7007 },
Todd Broch6be79482010-12-07 16:51:05 -08007008 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007009 .type = ALC_FIXUP_FUNC,
7010 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007011 },
7012 [ALC662_FIXUP_CZC_P10T] = {
7013 .type = ALC_FIXUP_VERBS,
7014 .v.verbs = (const struct hda_verb[]) {
7015 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7016 {}
7017 }
7018 },
David Henningsson94024cd2011-04-29 14:10:55 +02007019 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02007020 .type = ALC_FIXUP_FUNC,
7021 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02007022 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007023 [ALC662_FIXUP_HP_RP5800] = {
7024 .type = ALC_FIXUP_PINS,
7025 .v.pins = (const struct alc_pincfg[]) {
7026 { 0x14, 0x0221201f }, /* HP out */
7027 { }
7028 },
7029 .chained = true,
7030 .chain_id = ALC662_FIXUP_SKU_IGNORE
7031 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007032 [ALC662_FIXUP_ASUS_MODE1] = {
7033 .type = ALC_FIXUP_PINS,
7034 .v.pins = (const struct alc_pincfg[]) {
7035 { 0x14, 0x99130110 }, /* speaker */
7036 { 0x18, 0x01a19c20 }, /* mic */
7037 { 0x19, 0x99a3092f }, /* int-mic */
7038 { 0x21, 0x0121401f }, /* HP out */
7039 { }
7040 },
7041 .chained = true,
7042 .chain_id = ALC662_FIXUP_SKU_IGNORE
7043 },
7044 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007045 .type = ALC_FIXUP_PINS,
7046 .v.pins = (const struct alc_pincfg[]) {
7047 { 0x14, 0x99130110 }, /* speaker */
7048 { 0x18, 0x01a19820 }, /* mic */
7049 { 0x19, 0x99a3092f }, /* int-mic */
7050 { 0x1b, 0x0121401f }, /* HP out */
7051 { }
7052 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007053 .chained = true,
7054 .chain_id = ALC662_FIXUP_SKU_IGNORE
7055 },
7056 [ALC662_FIXUP_ASUS_MODE3] = {
7057 .type = ALC_FIXUP_PINS,
7058 .v.pins = (const struct alc_pincfg[]) {
7059 { 0x14, 0x99130110 }, /* speaker */
7060 { 0x15, 0x0121441f }, /* HP */
7061 { 0x18, 0x01a19840 }, /* mic */
7062 { 0x19, 0x99a3094f }, /* int-mic */
7063 { 0x21, 0x01211420 }, /* HP2 */
7064 { }
7065 },
7066 .chained = true,
7067 .chain_id = ALC662_FIXUP_SKU_IGNORE
7068 },
7069 [ALC662_FIXUP_ASUS_MODE4] = {
7070 .type = ALC_FIXUP_PINS,
7071 .v.pins = (const struct alc_pincfg[]) {
7072 { 0x14, 0x99130110 }, /* speaker */
7073 { 0x16, 0x99130111 }, /* speaker */
7074 { 0x18, 0x01a19840 }, /* mic */
7075 { 0x19, 0x99a3094f }, /* int-mic */
7076 { 0x21, 0x0121441f }, /* HP */
7077 { }
7078 },
7079 .chained = true,
7080 .chain_id = ALC662_FIXUP_SKU_IGNORE
7081 },
7082 [ALC662_FIXUP_ASUS_MODE5] = {
7083 .type = ALC_FIXUP_PINS,
7084 .v.pins = (const struct alc_pincfg[]) {
7085 { 0x14, 0x99130110 }, /* speaker */
7086 { 0x15, 0x0121441f }, /* HP */
7087 { 0x16, 0x99130111 }, /* speaker */
7088 { 0x18, 0x01a19840 }, /* mic */
7089 { 0x19, 0x99a3094f }, /* int-mic */
7090 { }
7091 },
7092 .chained = true,
7093 .chain_id = ALC662_FIXUP_SKU_IGNORE
7094 },
7095 [ALC662_FIXUP_ASUS_MODE6] = {
7096 .type = ALC_FIXUP_PINS,
7097 .v.pins = (const struct alc_pincfg[]) {
7098 { 0x14, 0x99130110 }, /* speaker */
7099 { 0x15, 0x01211420 }, /* HP2 */
7100 { 0x18, 0x01a19840 }, /* mic */
7101 { 0x19, 0x99a3094f }, /* int-mic */
7102 { 0x1b, 0x0121441f }, /* HP */
7103 { }
7104 },
7105 .chained = true,
7106 .chain_id = ALC662_FIXUP_SKU_IGNORE
7107 },
7108 [ALC662_FIXUP_ASUS_MODE7] = {
7109 .type = ALC_FIXUP_PINS,
7110 .v.pins = (const struct alc_pincfg[]) {
7111 { 0x14, 0x99130110 }, /* speaker */
7112 { 0x17, 0x99130111 }, /* speaker */
7113 { 0x18, 0x01a19840 }, /* mic */
7114 { 0x19, 0x99a3094f }, /* int-mic */
7115 { 0x1b, 0x01214020 }, /* HP */
7116 { 0x21, 0x0121401f }, /* HP */
7117 { }
7118 },
7119 .chained = true,
7120 .chain_id = ALC662_FIXUP_SKU_IGNORE
7121 },
7122 [ALC662_FIXUP_ASUS_MODE8] = {
7123 .type = ALC_FIXUP_PINS,
7124 .v.pins = (const struct alc_pincfg[]) {
7125 { 0x14, 0x99130110 }, /* speaker */
7126 { 0x12, 0x99a30970 }, /* int-mic */
7127 { 0x15, 0x01214020 }, /* HP */
7128 { 0x17, 0x99130111 }, /* speaker */
7129 { 0x18, 0x01a19840 }, /* mic */
7130 { 0x21, 0x0121401f }, /* HP */
7131 { }
7132 },
7133 .chained = true,
7134 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007135 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007136 [ALC662_FIXUP_NO_JACK_DETECT] = {
7137 .type = ALC_FIXUP_FUNC,
7138 .v.func = alc_fixup_no_jack_detect,
7139 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007140 [ALC662_FIXUP_ZOTAC_Z68] = {
7141 .type = ALC_FIXUP_PINS,
7142 .v.pins = (const struct alc_pincfg[]) {
7143 { 0x1b, 0x02214020 }, /* Front HP */
7144 { }
7145 }
7146 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007147 [ALC662_FIXUP_INV_DMIC] = {
7148 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007149 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007150 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007151};
7152
Takashi Iwaia9111322011-05-02 11:30:18 +02007153static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007154 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007155 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007156 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007157 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007158 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007159 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007160 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007161 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007162 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007163 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007164 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007165 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007166 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007167
7168#if 0
7169 /* Below is a quirk table taken from the old code.
7170 * Basically the device should work as is without the fixup table.
7171 * If BIOS doesn't give a proper info, enable the corresponding
7172 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007173 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007174 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7175 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7176 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7177 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7178 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7179 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7180 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7181 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7182 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7183 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7184 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7185 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7186 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7187 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7188 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7189 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7190 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7191 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7192 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7193 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7194 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7195 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7196 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7197 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7198 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7199 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7200 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7201 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7202 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7203 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7204 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7205 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7206 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7207 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7208 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7209 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7210 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7211 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7212 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7213 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7214 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7215 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7216 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7217 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7218 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7219 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7220 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7221 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7222 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7223 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7224#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007225 {}
7226};
7227
Todd Broch6be79482010-12-07 16:51:05 -08007228static const struct alc_model_fixup alc662_fixup_models[] = {
7229 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007230 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7231 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7232 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7233 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7234 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7235 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7236 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7237 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007238 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007239 {}
7240};
David Henningsson6cb3b702010-09-09 08:51:44 +02007241
Kailang Yang8663ff72012-06-29 09:35:52 +02007242static void alc662_fill_coef(struct hda_codec *codec)
7243{
7244 int val, coef;
7245
7246 coef = alc_get_coef0(codec);
7247
7248 switch (codec->vendor_id) {
7249 case 0x10ec0662:
7250 if ((coef & 0x00f0) == 0x0030) {
7251 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7252 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7253 }
7254 break;
7255 case 0x10ec0272:
7256 case 0x10ec0273:
7257 case 0x10ec0663:
7258 case 0x10ec0665:
7259 case 0x10ec0670:
7260 case 0x10ec0671:
7261 case 0x10ec0672:
7262 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7263 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7264 break;
7265 }
7266}
David Henningsson6cb3b702010-09-09 08:51:44 +02007267
Takashi Iwai1d045db2011-07-07 18:23:21 +02007268/*
7269 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007270static int patch_alc662(struct hda_codec *codec)
7271{
7272 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007273 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007274
Takashi Iwai3de95172012-05-07 18:03:15 +02007275 err = alc_alloc_spec(codec, 0x0b);
7276 if (err < 0)
7277 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007278
Takashi Iwai3de95172012-05-07 18:03:15 +02007279 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007280
Takashi Iwai53c334a2011-08-23 18:27:14 +02007281 /* handle multiple HPs as is */
7282 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7283
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007284 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7285
Kailang Yang8663ff72012-06-29 09:35:52 +02007286 spec->init_hook = alc662_fill_coef;
7287 alc662_fill_coef(codec);
7288
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007289 alc_pick_fixup(codec, alc662_fixup_models,
7290 alc662_fixup_tbl, alc662_fixups);
7291 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7292
7293 alc_auto_parse_customize_define(codec);
7294
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007295 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007296 codec->bus->pci->subsystem_vendor == 0x1025 &&
7297 spec->cdefine.platform_type == 1) {
7298 if (alc_codec_rename(codec, "ALC272X") < 0)
7299 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007300 }
Kailang Yang274693f2009-12-03 10:07:50 +01007301
Takashi Iwaib9c51062011-08-24 18:08:07 +02007302 /* automatic parse from the BIOS config */
7303 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007304 if (err < 0)
7305 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007306
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007307 if (!spec->no_analog && has_cdefine_beep(codec)) {
7308 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007309 if (err < 0)
7310 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007311 switch (codec->vendor_id) {
7312 case 0x10ec0662:
7313 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7314 break;
7315 case 0x10ec0272:
7316 case 0x10ec0663:
7317 case 0x10ec0665:
7318 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7319 break;
7320 case 0x10ec0273:
7321 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7322 break;
7323 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007324 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007325
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007326 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007327 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007328
Takashi Iwai589876e2012-02-20 15:47:55 +01007329 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7330
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007331 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007332
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007333 error:
7334 alc_free(codec);
7335 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007336}
7337
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007338/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007339 * ALC680 support
7340 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007341
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007342static int alc680_parse_auto_config(struct hda_codec *codec)
7343{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007344 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007345}
7346
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007347/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007348 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007349static int patch_alc680(struct hda_codec *codec)
7350{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007351 int err;
7352
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007353 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007354 err = alc_alloc_spec(codec, 0);
7355 if (err < 0)
7356 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007357
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007358 /* automatic parse from the BIOS config */
7359 err = alc680_parse_auto_config(codec);
7360 if (err < 0) {
7361 alc_free(codec);
7362 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007363 }
7364
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007365 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007366
7367 return 0;
7368}
7369
7370/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007371 * patch entries
7372 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007373static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007374 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007375 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007376 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007377 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007378 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007379 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007380 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007381 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007382 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007383 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007384 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007385 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007386 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007387 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007388 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007389 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007390 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007391 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007392 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7393 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7394 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007395 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007396 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007397 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7398 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007399 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7400 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007401 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007402 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007403 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007404 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007405 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007406 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007407 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007408 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007409 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007410 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007411 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007412 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007413 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007414 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007415 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007416 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007417 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007418 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007419 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007420 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007421 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007422 {} /* terminator */
7423};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007424
7425MODULE_ALIAS("snd-hda-codec-id:10ec*");
7426
7427MODULE_LICENSE("GPL");
7428MODULE_DESCRIPTION("Realtek HD-audio codec");
7429
7430static struct hda_codec_preset_list realtek_list = {
7431 .preset = snd_hda_preset_realtek,
7432 .owner = THIS_MODULE,
7433};
7434
7435static int __init patch_realtek_init(void)
7436{
7437 return snd_hda_add_codec_preset(&realtek_list);
7438}
7439
7440static void __exit patch_realtek_exit(void)
7441{
7442 snd_hda_delete_codec_preset(&realtek_list);
7443}
7444
7445module_init(patch_realtek_init)
7446module_exit(patch_realtek_exit)