blob: 7a22ab0b047b865e1b259ed2065084a6b2ce3c71 [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);
3624 if (snd_hda_get_num_conns(codec, nid) > 1) {
3625 type = ALC_CTL_BIND_MUTE;
3626 val |= 2 << 19; /* FIXME: fixed two widgets, so far */
3627 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003628 }
3629 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003630}
3631
Takashi Iwaie29d3772011-11-14 17:13:23 +01003632static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003633 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003634{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003635 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3636 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003637}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003638
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003639static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003640 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003641{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003642 int i;
3643
3644 for (i = path->depth - 1; i >= 0; i--) {
3645 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3646 return path->path[i];
3647 if (i != path->depth - 1 && i != 0 &&
3648 nid_has_mute(codec, path->path[i], HDA_INPUT))
3649 return path->path[i];
3650 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003651 return 0;
3652}
3653
3654static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003655 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003656{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003657 int i;
3658
3659 for (i = path->depth - 1; i >= 0; i--) {
3660 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3661 return path->path[i];
3662 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003663 return 0;
3664}
3665
Takashi Iwai7085ec12009-10-02 09:03:58 +02003666/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003667static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003668 const struct auto_pin_cfg *cfg)
3669{
3670 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003671 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003672
Takashi Iwaice764ab2011-04-27 16:35:23 +02003673 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003674 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003675 noutputs += spec->multi_ios;
3676
3677 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003678 const char *name;
3679 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003680 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003681 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003682
3683 dac = spec->multiout.dac_nids[i];
3684 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003685 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003686 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003687 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003688 index = 0;
3689 name = channel_name[i];
3690 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003691 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003692 name = alc_get_line_out_pfx(spec, i, true, &index);
3693 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003694
Takashi Iwaiba8111272012-12-06 18:06:23 +01003695 path = get_out_path(codec, pin, dac);
3696 if (!path)
3697 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003698 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003699 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003700 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003701 if (err < 0)
3702 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003703 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003704 if (err < 0)
3705 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003706 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003707 if (err < 0)
3708 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003709 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003710 if (err < 0)
3711 return err;
3712 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003713 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003714 if (err < 0)
3715 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003716 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003717 if (err < 0)
3718 return err;
3719 }
3720 }
3721 return 0;
3722}
3723
Takashi Iwai343a04b2011-07-06 14:28:39 +02003724static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003725 hda_nid_t dac, const char *pfx,
3726 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003727{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003728 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003729 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003730
Takashi Iwaiba8111272012-12-06 18:06:23 +01003731 path = get_out_path(codec, pin, dac);
3732 if (!path)
3733 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003734 /* bind volume control will be created in the case of dac = 0 */
3735 if (dac) {
3736 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3737 if (err < 0)
3738 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003739 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003740 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003741 if (err < 0)
3742 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003743 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003744}
3745
Takashi Iwai23c09b02011-08-19 09:05:35 +02003746static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3747 unsigned int nums,
3748 struct hda_ctl_ops *ops)
3749{
3750 struct alc_spec *spec = codec->spec;
3751 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003752 ctlp = snd_array_new(&spec->bind_ctls);
3753 if (!ctlp)
3754 return NULL;
3755 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3756 *ctlp = ctl;
3757 if (ctl)
3758 ctl->ops = ops;
3759 return ctl;
3760}
3761
3762/* add playback controls for speaker and HP outputs */
3763static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3764 const hda_nid_t *pins,
3765 const hda_nid_t *dacs,
3766 const char *pfx)
3767{
3768 struct alc_spec *spec = codec->spec;
3769 struct hda_bind_ctls *ctl;
3770 char name[32];
3771 int i, n, err;
3772
3773 if (!num_pins || !pins[0])
3774 return 0;
3775
Takashi Iwai527e4d72011-10-27 16:33:27 +02003776 if (num_pins == 1) {
3777 hda_nid_t dac = *dacs;
3778 if (!dac)
3779 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003780 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003781 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003782
Takashi Iwai23c09b02011-08-19 09:05:35 +02003783 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003784 hda_nid_t dac;
3785 if (dacs[num_pins - 1])
3786 dac = dacs[i]; /* with individual volumes */
3787 else
3788 dac = 0;
3789 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3790 err = alc_auto_create_extra_out(codec, pins[i], dac,
3791 "Bass Speaker", 0);
3792 } else if (num_pins >= 3) {
3793 snprintf(name, sizeof(name), "%s %s",
3794 pfx, channel_name[i]);
3795 err = alc_auto_create_extra_out(codec, pins[i], dac,
3796 name, 0);
3797 } else {
3798 err = alc_auto_create_extra_out(codec, pins[i], dac,
3799 pfx, i);
3800 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003801 if (err < 0)
3802 return err;
3803 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003804 if (dacs[num_pins - 1])
3805 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003806
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003807 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003808 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3809 if (!ctl)
3810 return -ENOMEM;
3811 n = 0;
3812 for (i = 0; i < num_pins; i++) {
3813 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003814 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003815 if (!pins[i] || !dacs[i])
3816 continue;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003817 path = get_out_path(codec, pins[i], dacs[i]);
3818 if (!path)
3819 continue;
3820 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003821 if (vol)
3822 ctl->values[n++] =
3823 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3824 }
3825 if (n) {
3826 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3827 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3828 if (err < 0)
3829 return err;
3830 }
3831 return 0;
3832}
3833
Takashi Iwai343a04b2011-07-06 14:28:39 +02003834static int alc_auto_create_hp_out(struct hda_codec *codec)
3835{
3836 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003837 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3838 spec->autocfg.hp_pins,
3839 spec->multiout.hp_out_nid,
3840 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003841}
3842
3843static int alc_auto_create_speaker_out(struct hda_codec *codec)
3844{
3845 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003846 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3847 spec->autocfg.speaker_pins,
3848 spec->multiout.extra_out_nid,
3849 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003850}
3851
Takashi Iwai78e635c2012-12-10 17:07:16 +01003852/* is a volume or mute control already present? */
3853static bool __is_out_ctl_present(struct hda_codec *codec,
3854 struct nid_path *exclude_path,
3855 hda_nid_t nid, int dir, int types)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003856{
Takashi Iwai78e635c2012-12-10 17:07:16 +01003857 struct alc_spec *spec = codec->spec;
3858 int i, type;
3859
3860 for (i = 0; i < spec->out_path.used; i++) {
3861 struct nid_path *p = snd_array_elem(&spec->out_path, i);
3862 if (p == exclude_path || p->depth <= 0)
3863 continue;
3864 for (type = 0; type < 2; type++) {
3865 if (types & (1 << type)) {
3866 unsigned int val = p->ctls[type];
3867 if (get_amp_nid_(val) == nid &&
3868 get_amp_direction_(val) == dir)
3869 return true;
3870 }
3871 }
3872 }
3873 return false;
3874}
3875
3876#define is_out_ctl_present(codec, path, nid, dir) \
3877 __is_out_ctl_present(codec, path, nid, dir, 3) /* check both types */
3878#define is_out_vol_ctl_present(codec, nid, dir) \
3879 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_VOL_CTL)
3880#define is_out_mute_ctl_present(codec, nid, dir) \
3881 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_MUTE_CTL)
3882
3883static int get_default_amp_val(struct hda_codec *codec, hda_nid_t nid, int dir)
3884{
3885 unsigned int caps, offset;
3886 unsigned int val = 0;
3887
3888 caps = query_amp_caps(codec, nid, dir);
3889 if (caps & AC_AMPCAP_NUM_STEPS) {
3890 offset = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
3891 /* if a volume control is assigned, set the lowest level
3892 * as default; otherwise set to 0dB
3893 */
3894 if (is_out_vol_ctl_present(codec, nid, dir))
3895 val = 0;
3896 else
3897 val = offset;
3898 }
3899 if (caps & AC_AMPCAP_MUTE) {
3900 /* if a mute control is assigned, mute as default */
3901 if (is_out_mute_ctl_present(codec, nid, dir))
3902 val |= HDA_AMP_MUTE;
3903 }
3904 return val;
3905}
3906
3907/* configure the path from the given dac to the pin as the proper output */
3908static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3909 hda_nid_t pin, int pin_type,
3910 hda_nid_t dac, bool force)
3911{
3912 int i, val;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003913 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003914
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003915 alc_set_pin_output(codec, pin, pin_type);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003916 path = get_out_path(codec, pin, dac);
3917 if (!path)
3918 return;
Takashi Iwai43dea222011-11-06 11:25:34 +01003919
Takashi Iwai78e635c2012-12-10 17:07:16 +01003920 for (i = path->depth - 1; i >= 0; i--) {
3921 hda_nid_t nid = path->path[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01003922 if (path->multi[i])
Takashi Iwai78e635c2012-12-10 17:07:16 +01003923 snd_hda_codec_write(codec, nid, 0,
3924 AC_VERB_SET_CONNECT_SEL,
Takashi Iwai95e960c2012-12-10 17:27:57 +01003925 path->idx[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003926
3927 if (i != 0 && i != path->depth - 1 &&
3928 (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) &&
3929 (force || !is_out_ctl_present(codec, path, nid,
3930 HDA_INPUT))) {
3931 val = get_default_amp_val(codec, nid, HDA_INPUT);
3932 snd_hda_codec_write(codec, nid, 0,
3933 AC_VERB_SET_AMP_GAIN_MUTE,
3934 AMP_IN_UNMUTE(0) | val);
3935 snd_hda_codec_write(codec, nid, 0,
3936 AC_VERB_SET_AMP_GAIN_MUTE,
3937 AMP_IN_UNMUTE(1) | val);
3938 }
3939 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
3940 (force || !is_out_ctl_present(codec, path, nid,
3941 HDA_OUTPUT))) {
3942 val = get_default_amp_val(codec, nid, HDA_OUTPUT);
3943 snd_hda_codec_write(codec, nid, 0,
3944 AC_VERB_SET_AMP_GAIN_MUTE,
3945 AMP_OUT_UNMUTE | val);
3946 }
3947 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003948}
3949
Takashi Iwai343a04b2011-07-06 14:28:39 +02003950static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003951{
3952 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003953 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003954 int i;
3955
3956 for (i = 0; i <= HDA_SIDE; i++) {
3957 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3958 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003959 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai78e635c2012-12-10 17:07:16 +01003960 spec->multiout.dac_nids[i], true);
3961
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003962 }
3963}
3964
Takashi Iwai343a04b2011-07-06 14:28:39 +02003965static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003966{
3967 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003968 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003969 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003970
David Henningsson636030e2011-10-12 19:26:03 +02003971 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003972 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3973 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003974 pin = spec->autocfg.hp_pins[i];
3975 if (!pin)
3976 break;
3977 dac = spec->multiout.hp_out_nid[i];
3978 if (!dac) {
3979 if (i > 0 && spec->multiout.hp_out_nid[0])
3980 dac = spec->multiout.hp_out_nid[0];
3981 else
3982 dac = spec->multiout.dac_nids[0];
3983 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003984 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003985 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003986 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003987 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3988 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003989 pin = spec->autocfg.speaker_pins[i];
3990 if (!pin)
3991 break;
3992 dac = spec->multiout.extra_out_nid[i];
3993 if (!dac) {
3994 if (i > 0 && spec->multiout.extra_out_nid[0])
3995 dac = spec->multiout.extra_out_nid[0];
3996 else
3997 dac = spec->multiout.dac_nids[0];
3998 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003999 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004000 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004001}
4002
Takashi Iwai276dd702012-02-17 16:17:03 +01004003/* check whether the given pin can be a multi-io pin */
4004static bool can_be_multiio_pin(struct hda_codec *codec,
4005 unsigned int location, hda_nid_t nid)
4006{
4007 unsigned int defcfg, caps;
4008
4009 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4010 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4011 return false;
4012 if (location && get_defcfg_location(defcfg) != location)
4013 return false;
4014 caps = snd_hda_query_pin_caps(codec, nid);
4015 if (!(caps & AC_PINCAP_OUT))
4016 return false;
4017 return true;
4018}
4019
Takashi Iwaice764ab2011-04-27 16:35:23 +02004020/*
4021 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004022 *
4023 * When hardwired is set, try to fill ony hardwired pins, and returns
4024 * zero if any pins are filled, non-zero if nothing found.
4025 * When hardwired is off, try to fill possible input pins, and returns
4026 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004027 */
4028static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004029 hda_nid_t reference_pin,
4030 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004031{
4032 struct alc_spec *spec = codec->spec;
4033 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004034 int type, i, j, dacs, num_pins, old_pins;
4035 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4036 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004037 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004038
Takashi Iwai276dd702012-02-17 16:17:03 +01004039 old_pins = spec->multi_ios;
4040 if (old_pins >= 2)
4041 goto end_fill;
4042
4043 num_pins = 0;
4044 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4045 for (i = 0; i < cfg->num_inputs; i++) {
4046 if (cfg->inputs[i].type != type)
4047 continue;
4048 if (can_be_multiio_pin(codec, location,
4049 cfg->inputs[i].pin))
4050 num_pins++;
4051 }
4052 }
4053 if (num_pins < 2)
4054 goto end_fill;
4055
Takashi Iwai07b18f62011-11-10 15:42:54 +01004056 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004057 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4058 for (i = 0; i < cfg->num_inputs; i++) {
4059 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004060 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004061
Takashi Iwaice764ab2011-04-27 16:35:23 +02004062 if (cfg->inputs[i].type != type)
4063 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004064 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004065 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004066 for (j = 0; j < spec->multi_ios; j++) {
4067 if (nid == spec->multi_io[j].pin)
4068 break;
4069 }
4070 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004071 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004072
4073 if (offset && offset + spec->multi_ios < dacs) {
4074 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01004075 if (!alc_auto_is_dac_reachable(codec, nid, dac))
4076 dac = 0;
4077 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004078 if (hardwired)
4079 dac = get_dac_if_single(codec, nid);
4080 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01004081 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004082 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004083 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004084 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004085 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004086 if (!add_new_out_path(codec, nid, dac)) {
4087 badness++;
4088 continue;
4089 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004090 spec->multi_io[spec->multi_ios].pin = nid;
4091 spec->multi_io[spec->multi_ios].dac = dac;
4092 spec->multi_ios++;
4093 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004094 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004095 }
4096 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004097 end_fill:
4098 if (badness)
4099 badness = BAD_MULTI_IO;
4100 if (old_pins == spec->multi_ios) {
4101 if (hardwired)
4102 return 1; /* nothing found */
4103 else
4104 return badness; /* no badness if nothing found */
4105 }
4106 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004107 /* cancel newly assigned paths */
4108 spec->out_path.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004109 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004110 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004111 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004112
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004113 /* assign volume and mute controls */
4114 for (i = old_pins; i < spec->multi_ios; i++)
4115 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4116 spec->multi_io[i].dac);
4117
4118 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004119}
4120
4121static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4122 struct snd_ctl_elem_info *uinfo)
4123{
4124 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4125 struct alc_spec *spec = codec->spec;
4126
4127 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4128 uinfo->count = 1;
4129 uinfo->value.enumerated.items = spec->multi_ios + 1;
4130 if (uinfo->value.enumerated.item > spec->multi_ios)
4131 uinfo->value.enumerated.item = spec->multi_ios;
4132 sprintf(uinfo->value.enumerated.name, "%dch",
4133 (uinfo->value.enumerated.item + 1) * 2);
4134 return 0;
4135}
4136
4137static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4138 struct snd_ctl_elem_value *ucontrol)
4139{
4140 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4141 struct alc_spec *spec = codec->spec;
4142 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4143 return 0;
4144}
4145
4146static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4147{
4148 struct alc_spec *spec = codec->spec;
4149 hda_nid_t nid = spec->multi_io[idx].pin;
4150
4151 if (!spec->multi_io[idx].ctl_in)
4152 spec->multi_io[idx].ctl_in =
4153 snd_hda_codec_read(codec, nid, 0,
4154 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4155 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004156 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004157 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4158 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4159 HDA_AMP_MUTE, 0);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004160 alc_auto_set_output_and_unmute(codec, nid, PIN_OUT,
4161 spec->multi_io[idx].dac, false);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004162 } else {
4163 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4164 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4165 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004166 snd_hda_set_pin_ctl_cache(codec, nid,
4167 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004168 }
4169 return 0;
4170}
4171
4172static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4173 struct snd_ctl_elem_value *ucontrol)
4174{
4175 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4176 struct alc_spec *spec = codec->spec;
4177 int i, ch;
4178
4179 ch = ucontrol->value.enumerated.item[0];
4180 if (ch < 0 || ch > spec->multi_ios)
4181 return -EINVAL;
4182 if (ch == (spec->ext_channel_count - 1) / 2)
4183 return 0;
4184 spec->ext_channel_count = (ch + 1) * 2;
4185 for (i = 0; i < spec->multi_ios; i++)
4186 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004187 spec->multiout.max_channels = max(spec->ext_channel_count,
4188 spec->const_channel_count);
4189 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004190 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004191 return 1;
4192}
4193
Takashi Iwaia9111322011-05-02 11:30:18 +02004194static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004195 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4196 .name = "Channel Mode",
4197 .info = alc_auto_ch_mode_info,
4198 .get = alc_auto_ch_mode_get,
4199 .put = alc_auto_ch_mode_put,
4200};
4201
Takashi Iwai23c09b02011-08-19 09:05:35 +02004202static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004203{
4204 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004205
Takashi Iwaic2674682011-08-24 17:57:44 +02004206 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004207 if (!alc_kcontrol_new(spec, "Channel Mode",
4208 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004209 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004210 }
4211 return 0;
4212}
4213
Takashi Iwai1d045db2011-07-07 18:23:21 +02004214/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4215 * active input pins
4216 */
4217static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4218{
4219 struct alc_spec *spec = codec->spec;
4220 const struct hda_input_mux *imux;
4221 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4222 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4223 int i, n, nums;
4224
4225 imux = spec->input_mux;
4226 if (!imux)
4227 return;
4228 if (spec->dyn_adc_switch)
4229 return;
4230
Takashi Iwai26acaf02012-03-22 14:36:50 +01004231 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004232 nums = 0;
4233 for (n = 0; n < spec->num_adc_nids; n++) {
4234 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004235 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004236 for (i = 0; i < imux->num_items; i++) {
4237 hda_nid_t pin = spec->imux_pins[i];
4238 if (pin) {
4239 if (get_connection_index(codec, cap, pin) < 0)
4240 break;
4241 } else if (num_conns <= imux->items[i].index)
4242 break;
4243 }
4244 if (i >= imux->num_items) {
4245 adc_nids[nums] = spec->private_adc_nids[n];
4246 capsrc_nids[nums++] = cap;
4247 }
4248 }
4249 if (!nums) {
4250 /* check whether ADC-switch is possible */
4251 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004252 if (spec->shared_mic_hp) {
4253 spec->shared_mic_hp = 0;
4254 spec->private_imux[0].num_items = 1;
4255 goto again;
4256 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004257 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4258 " using fallback 0x%x\n",
4259 codec->chip_name, spec->private_adc_nids[0]);
4260 spec->num_adc_nids = 1;
4261 spec->auto_mic = 0;
4262 return;
4263 }
4264 } else if (nums != spec->num_adc_nids) {
4265 memcpy(spec->private_adc_nids, adc_nids,
4266 nums * sizeof(hda_nid_t));
4267 memcpy(spec->private_capsrc_nids, capsrc_nids,
4268 nums * sizeof(hda_nid_t));
4269 spec->num_adc_nids = nums;
4270 }
4271
4272 if (spec->auto_mic)
4273 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004274 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004275 spec->num_adc_nids = 1; /* reduce to a single ADC */
4276}
4277
4278/*
4279 * initialize ADC paths
4280 */
4281static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4282{
4283 struct alc_spec *spec = codec->spec;
4284 hda_nid_t nid;
4285
4286 nid = spec->adc_nids[adc_idx];
4287 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004288 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004289 snd_hda_codec_write(codec, nid, 0,
4290 AC_VERB_SET_AMP_GAIN_MUTE,
4291 AMP_IN_MUTE(0));
4292 return;
4293 }
4294 if (!spec->capsrc_nids)
4295 return;
4296 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004297 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004298 snd_hda_codec_write(codec, nid, 0,
4299 AC_VERB_SET_AMP_GAIN_MUTE,
4300 AMP_OUT_MUTE);
4301}
4302
4303static void alc_auto_init_input_src(struct hda_codec *codec)
4304{
4305 struct alc_spec *spec = codec->spec;
4306 int c, nums;
4307
4308 for (c = 0; c < spec->num_adc_nids; c++)
4309 alc_auto_init_adc(codec, c);
4310 if (spec->dyn_adc_switch)
4311 nums = 1;
4312 else
4313 nums = spec->num_adc_nids;
4314 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004315 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004316}
4317
4318/* add mic boosts if needed */
4319static int alc_auto_add_mic_boost(struct hda_codec *codec)
4320{
4321 struct alc_spec *spec = codec->spec;
4322 struct auto_pin_cfg *cfg = &spec->autocfg;
4323 int i, err;
4324 int type_idx = 0;
4325 hda_nid_t nid;
4326 const char *prev_label = NULL;
4327
4328 for (i = 0; i < cfg->num_inputs; i++) {
4329 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4330 break;
4331 nid = cfg->inputs[i].pin;
4332 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4333 const char *label;
4334 char boost_label[32];
4335
4336 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004337 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4338 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004339 if (prev_label && !strcmp(label, prev_label))
4340 type_idx++;
4341 else
4342 type_idx = 0;
4343 prev_label = label;
4344
4345 snprintf(boost_label, sizeof(boost_label),
4346 "%s Boost Volume", label);
4347 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4348 boost_label, type_idx,
4349 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4350 if (err < 0)
4351 return err;
4352 }
4353 }
4354 return 0;
4355}
4356
4357/* select or unmute the given capsrc route */
4358static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4359 int idx)
4360{
4361 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4362 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4363 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004364 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004365 snd_hda_codec_write_cache(codec, cap, 0,
4366 AC_VERB_SET_CONNECT_SEL, idx);
4367 }
4368}
4369
4370/* set the default connection to that pin */
4371static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4372{
4373 struct alc_spec *spec = codec->spec;
4374 int i;
4375
4376 if (!pin)
4377 return 0;
4378 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004379 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004380 int idx;
4381
4382 idx = get_connection_index(codec, cap, pin);
4383 if (idx < 0)
4384 continue;
4385 select_or_unmute_capsrc(codec, cap, idx);
4386 return i; /* return the found index */
4387 }
4388 return -1; /* not found */
4389}
4390
4391/* initialize some special cases for input sources */
4392static void alc_init_special_input_src(struct hda_codec *codec)
4393{
4394 struct alc_spec *spec = codec->spec;
4395 int i;
4396
4397 for (i = 0; i < spec->autocfg.num_inputs; i++)
4398 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4399}
4400
4401/* assign appropriate capture mixers */
4402static void set_capture_mixer(struct hda_codec *codec)
4403{
4404 struct alc_spec *spec = codec->spec;
4405 static const struct snd_kcontrol_new *caps[2][3] = {
4406 { alc_capture_mixer_nosrc1,
4407 alc_capture_mixer_nosrc2,
4408 alc_capture_mixer_nosrc3 },
4409 { alc_capture_mixer1,
4410 alc_capture_mixer2,
4411 alc_capture_mixer3 },
4412 };
4413
4414 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004415 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004416 if (!spec->capsrc_nids)
4417 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004418 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004419 return; /* no volume in capsrc, too */
4420 spec->vol_in_capsrc = 1;
4421 }
4422
4423 if (spec->num_adc_nids > 0) {
4424 int mux = 0;
4425 int num_adcs = 0;
4426
4427 if (spec->input_mux && spec->input_mux->num_items > 1)
4428 mux = 1;
4429 if (spec->auto_mic) {
4430 num_adcs = 1;
4431 mux = 0;
4432 } else if (spec->dyn_adc_switch)
4433 num_adcs = 1;
4434 if (!num_adcs) {
4435 if (spec->num_adc_nids > 3)
4436 spec->num_adc_nids = 3;
4437 else if (!spec->num_adc_nids)
4438 return;
4439 num_adcs = spec->num_adc_nids;
4440 }
4441 spec->cap_mixer = caps[mux][num_adcs - 1];
4442 }
4443}
4444
4445/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004446 * standard auto-parser initializations
4447 */
4448static void alc_auto_init_std(struct hda_codec *codec)
4449{
Takashi Iwaie4770622011-07-08 11:11:35 +02004450 alc_auto_init_multi_out(codec);
4451 alc_auto_init_extra_out(codec);
4452 alc_auto_init_analog_input(codec);
4453 alc_auto_init_input_src(codec);
4454 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004455 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004456}
4457
4458/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004459 * Digital-beep handlers
4460 */
4461#ifdef CONFIG_SND_HDA_INPUT_BEEP
4462#define set_beep_amp(spec, nid, idx, dir) \
4463 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4464
4465static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004466 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004467 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4468 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4469 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4470 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004471 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004472 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4473 {}
4474};
4475
4476static inline int has_cdefine_beep(struct hda_codec *codec)
4477{
4478 struct alc_spec *spec = codec->spec;
4479 const struct snd_pci_quirk *q;
4480 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4481 if (q)
4482 return q->value;
4483 return spec->cdefine.enable_pcbeep;
4484}
4485#else
4486#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4487#define has_cdefine_beep(codec) 0
4488#endif
4489
4490/* parse the BIOS configuration and set up the alc_spec */
4491/* return 1 if successful, 0 if the proper config is not found,
4492 * or a negative error code
4493 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004494static int alc_parse_auto_config(struct hda_codec *codec,
4495 const hda_nid_t *ignore_nids,
4496 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004497{
4498 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004499 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004500 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004501
Takashi Iwai53c334a2011-08-23 18:27:14 +02004502 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4503 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004504 if (err < 0)
4505 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004506 if (!cfg->line_outs) {
4507 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004508 spec->multiout.max_channels = 2;
4509 spec->no_analog = 1;
4510 goto dig_only;
4511 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004512 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004513 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004514
Takashi Iwaie427c232012-07-29 10:04:08 +02004515 if (!spec->no_primary_hp &&
4516 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004517 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004518 /* use HP as primary out */
4519 cfg->speaker_outs = cfg->line_outs;
4520 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4521 sizeof(cfg->speaker_pins));
4522 cfg->line_outs = cfg->hp_outs;
4523 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4524 cfg->hp_outs = 0;
4525 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4526 cfg->line_out_type = AUTO_PIN_HP_OUT;
4527 }
4528
Takashi Iwai1d045db2011-07-07 18:23:21 +02004529 err = alc_auto_fill_dac_nids(codec);
4530 if (err < 0)
4531 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004532 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004533 if (err < 0)
4534 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004535 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004536 if (err < 0)
4537 return err;
4538 err = alc_auto_create_hp_out(codec);
4539 if (err < 0)
4540 return err;
4541 err = alc_auto_create_speaker_out(codec);
4542 if (err < 0)
4543 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004544 err = alc_auto_create_shared_input(codec);
4545 if (err < 0)
4546 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004547 err = alc_auto_create_input_ctls(codec);
4548 if (err < 0)
4549 return err;
4550
Takashi Iwaib6adb572012-12-03 10:30:58 +01004551 /* check the multiple speaker pins */
4552 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4553 spec->const_channel_count = cfg->line_outs * 2;
4554 else
4555 spec->const_channel_count = cfg->speaker_outs * 2;
4556
4557 if (spec->multi_ios > 0)
4558 spec->multiout.max_channels = max(spec->ext_channel_count,
4559 spec->const_channel_count);
4560 else
4561 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004562
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004563 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004564 alc_auto_parse_digital(codec);
4565
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004566 if (!spec->no_analog)
4567 alc_remove_invalid_adc_nids(codec);
4568
4569 if (ssid_nids)
4570 alc_ssid_check(codec, ssid_nids);
4571
4572 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004573 err = alc_auto_check_switches(codec);
4574 if (err < 0)
4575 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004576 err = alc_auto_add_mic_boost(codec);
4577 if (err < 0)
4578 return err;
4579 }
4580
Takashi Iwai1d045db2011-07-07 18:23:21 +02004581 if (spec->kctls.list)
4582 add_mixer(spec, spec->kctls.list);
4583
Takashi Iwai070cff42012-02-21 12:54:17 +01004584 if (!spec->no_analog && !spec->cap_mixer)
4585 set_capture_mixer(codec);
4586
Takashi Iwai1d045db2011-07-07 18:23:21 +02004587 return 1;
4588}
4589
Takashi Iwai3de95172012-05-07 18:03:15 +02004590/* common preparation job for alc_spec */
4591static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4592{
4593 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4594 int err;
4595
4596 if (!spec)
4597 return -ENOMEM;
4598 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004599 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004600 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004601 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004602 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4603 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004604 snd_array_init(&spec->out_path, sizeof(struct nid_path), 8);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01004605 snd_array_init(&spec->in_path, sizeof(struct nid_path), 8);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01004606 snd_array_init(&spec->loopback_path, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004607
4608 err = alc_codec_rename_from_preset(codec);
4609 if (err < 0) {
4610 kfree(spec);
4611 return err;
4612 }
4613 return 0;
4614}
4615
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004616static int alc880_parse_auto_config(struct hda_codec *codec)
4617{
4618 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004619 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004620 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4621}
4622
Takashi Iwai1d045db2011-07-07 18:23:21 +02004623/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004624 * ALC880 fix-ups
4625 */
4626enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004627 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004628 ALC880_FIXUP_GPIO2,
4629 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004630 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004631 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004632 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004633 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004634 ALC880_FIXUP_VOL_KNOB,
4635 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004636 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004637 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004638 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004639 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004640 ALC880_FIXUP_3ST_BASE,
4641 ALC880_FIXUP_3ST,
4642 ALC880_FIXUP_3ST_DIG,
4643 ALC880_FIXUP_5ST_BASE,
4644 ALC880_FIXUP_5ST,
4645 ALC880_FIXUP_5ST_DIG,
4646 ALC880_FIXUP_6ST_BASE,
4647 ALC880_FIXUP_6ST,
4648 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004649};
4650
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004651/* enable the volume-knob widget support on NID 0x21 */
4652static void alc880_fixup_vol_knob(struct hda_codec *codec,
4653 const struct alc_fixup *fix, int action)
4654{
4655 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004656 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004657}
4658
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004659static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004660 [ALC880_FIXUP_GPIO1] = {
4661 .type = ALC_FIXUP_VERBS,
4662 .v.verbs = alc_gpio1_init_verbs,
4663 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004664 [ALC880_FIXUP_GPIO2] = {
4665 .type = ALC_FIXUP_VERBS,
4666 .v.verbs = alc_gpio2_init_verbs,
4667 },
4668 [ALC880_FIXUP_MEDION_RIM] = {
4669 .type = ALC_FIXUP_VERBS,
4670 .v.verbs = (const struct hda_verb[]) {
4671 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4672 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4673 { }
4674 },
4675 .chained = true,
4676 .chain_id = ALC880_FIXUP_GPIO2,
4677 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004678 [ALC880_FIXUP_LG] = {
4679 .type = ALC_FIXUP_PINS,
4680 .v.pins = (const struct alc_pincfg[]) {
4681 /* disable bogus unused pins */
4682 { 0x16, 0x411111f0 },
4683 { 0x18, 0x411111f0 },
4684 { 0x1a, 0x411111f0 },
4685 { }
4686 }
4687 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004688 [ALC880_FIXUP_W810] = {
4689 .type = ALC_FIXUP_PINS,
4690 .v.pins = (const struct alc_pincfg[]) {
4691 /* disable bogus unused pins */
4692 { 0x17, 0x411111f0 },
4693 { }
4694 },
4695 .chained = true,
4696 .chain_id = ALC880_FIXUP_GPIO2,
4697 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004698 [ALC880_FIXUP_EAPD_COEF] = {
4699 .type = ALC_FIXUP_VERBS,
4700 .v.verbs = (const struct hda_verb[]) {
4701 /* change to EAPD mode */
4702 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4703 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4704 {}
4705 },
4706 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004707 [ALC880_FIXUP_TCL_S700] = {
4708 .type = ALC_FIXUP_VERBS,
4709 .v.verbs = (const struct hda_verb[]) {
4710 /* change to EAPD mode */
4711 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4712 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4713 {}
4714 },
4715 .chained = true,
4716 .chain_id = ALC880_FIXUP_GPIO2,
4717 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004718 [ALC880_FIXUP_VOL_KNOB] = {
4719 .type = ALC_FIXUP_FUNC,
4720 .v.func = alc880_fixup_vol_knob,
4721 },
4722 [ALC880_FIXUP_FUJITSU] = {
4723 /* override all pins as BIOS on old Amilo is broken */
4724 .type = ALC_FIXUP_PINS,
4725 .v.pins = (const struct alc_pincfg[]) {
4726 { 0x14, 0x0121411f }, /* HP */
4727 { 0x15, 0x99030120 }, /* speaker */
4728 { 0x16, 0x99030130 }, /* bass speaker */
4729 { 0x17, 0x411111f0 }, /* N/A */
4730 { 0x18, 0x411111f0 }, /* N/A */
4731 { 0x19, 0x01a19950 }, /* mic-in */
4732 { 0x1a, 0x411111f0 }, /* N/A */
4733 { 0x1b, 0x411111f0 }, /* N/A */
4734 { 0x1c, 0x411111f0 }, /* N/A */
4735 { 0x1d, 0x411111f0 }, /* N/A */
4736 { 0x1e, 0x01454140 }, /* SPDIF out */
4737 { }
4738 },
4739 .chained = true,
4740 .chain_id = ALC880_FIXUP_VOL_KNOB,
4741 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004742 [ALC880_FIXUP_F1734] = {
4743 /* almost compatible with FUJITSU, but no bass and SPDIF */
4744 .type = ALC_FIXUP_PINS,
4745 .v.pins = (const struct alc_pincfg[]) {
4746 { 0x14, 0x0121411f }, /* HP */
4747 { 0x15, 0x99030120 }, /* speaker */
4748 { 0x16, 0x411111f0 }, /* N/A */
4749 { 0x17, 0x411111f0 }, /* N/A */
4750 { 0x18, 0x411111f0 }, /* N/A */
4751 { 0x19, 0x01a19950 }, /* mic-in */
4752 { 0x1a, 0x411111f0 }, /* N/A */
4753 { 0x1b, 0x411111f0 }, /* N/A */
4754 { 0x1c, 0x411111f0 }, /* N/A */
4755 { 0x1d, 0x411111f0 }, /* N/A */
4756 { 0x1e, 0x411111f0 }, /* N/A */
4757 { }
4758 },
4759 .chained = true,
4760 .chain_id = ALC880_FIXUP_VOL_KNOB,
4761 },
Takashi Iwai817de922012-02-20 17:20:48 +01004762 [ALC880_FIXUP_UNIWILL] = {
4763 /* need to fix HP and speaker pins to be parsed correctly */
4764 .type = ALC_FIXUP_PINS,
4765 .v.pins = (const struct alc_pincfg[]) {
4766 { 0x14, 0x0121411f }, /* HP */
4767 { 0x15, 0x99030120 }, /* speaker */
4768 { 0x16, 0x99030130 }, /* bass speaker */
4769 { }
4770 },
4771 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004772 [ALC880_FIXUP_UNIWILL_DIG] = {
4773 .type = ALC_FIXUP_PINS,
4774 .v.pins = (const struct alc_pincfg[]) {
4775 /* disable bogus unused pins */
4776 { 0x17, 0x411111f0 },
4777 { 0x19, 0x411111f0 },
4778 { 0x1b, 0x411111f0 },
4779 { 0x1f, 0x411111f0 },
4780 { }
4781 }
4782 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004783 [ALC880_FIXUP_Z71V] = {
4784 .type = ALC_FIXUP_PINS,
4785 .v.pins = (const struct alc_pincfg[]) {
4786 /* set up the whole pins as BIOS is utterly broken */
4787 { 0x14, 0x99030120 }, /* speaker */
4788 { 0x15, 0x0121411f }, /* HP */
4789 { 0x16, 0x411111f0 }, /* N/A */
4790 { 0x17, 0x411111f0 }, /* N/A */
4791 { 0x18, 0x01a19950 }, /* mic-in */
4792 { 0x19, 0x411111f0 }, /* N/A */
4793 { 0x1a, 0x01813031 }, /* line-in */
4794 { 0x1b, 0x411111f0 }, /* N/A */
4795 { 0x1c, 0x411111f0 }, /* N/A */
4796 { 0x1d, 0x411111f0 }, /* N/A */
4797 { 0x1e, 0x0144111e }, /* SPDIF */
4798 { }
4799 }
4800 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004801 [ALC880_FIXUP_3ST_BASE] = {
4802 .type = ALC_FIXUP_PINS,
4803 .v.pins = (const struct alc_pincfg[]) {
4804 { 0x14, 0x01014010 }, /* line-out */
4805 { 0x15, 0x411111f0 }, /* N/A */
4806 { 0x16, 0x411111f0 }, /* N/A */
4807 { 0x17, 0x411111f0 }, /* N/A */
4808 { 0x18, 0x01a19c30 }, /* mic-in */
4809 { 0x19, 0x0121411f }, /* HP */
4810 { 0x1a, 0x01813031 }, /* line-in */
4811 { 0x1b, 0x02a19c40 }, /* front-mic */
4812 { 0x1c, 0x411111f0 }, /* N/A */
4813 { 0x1d, 0x411111f0 }, /* N/A */
4814 /* 0x1e is filled in below */
4815 { 0x1f, 0x411111f0 }, /* N/A */
4816 { }
4817 }
4818 },
4819 [ALC880_FIXUP_3ST] = {
4820 .type = ALC_FIXUP_PINS,
4821 .v.pins = (const struct alc_pincfg[]) {
4822 { 0x1e, 0x411111f0 }, /* N/A */
4823 { }
4824 },
4825 .chained = true,
4826 .chain_id = ALC880_FIXUP_3ST_BASE,
4827 },
4828 [ALC880_FIXUP_3ST_DIG] = {
4829 .type = ALC_FIXUP_PINS,
4830 .v.pins = (const struct alc_pincfg[]) {
4831 { 0x1e, 0x0144111e }, /* SPDIF */
4832 { }
4833 },
4834 .chained = true,
4835 .chain_id = ALC880_FIXUP_3ST_BASE,
4836 },
4837 [ALC880_FIXUP_5ST_BASE] = {
4838 .type = ALC_FIXUP_PINS,
4839 .v.pins = (const struct alc_pincfg[]) {
4840 { 0x14, 0x01014010 }, /* front */
4841 { 0x15, 0x411111f0 }, /* N/A */
4842 { 0x16, 0x01011411 }, /* CLFE */
4843 { 0x17, 0x01016412 }, /* surr */
4844 { 0x18, 0x01a19c30 }, /* mic-in */
4845 { 0x19, 0x0121411f }, /* HP */
4846 { 0x1a, 0x01813031 }, /* line-in */
4847 { 0x1b, 0x02a19c40 }, /* front-mic */
4848 { 0x1c, 0x411111f0 }, /* N/A */
4849 { 0x1d, 0x411111f0 }, /* N/A */
4850 /* 0x1e is filled in below */
4851 { 0x1f, 0x411111f0 }, /* N/A */
4852 { }
4853 }
4854 },
4855 [ALC880_FIXUP_5ST] = {
4856 .type = ALC_FIXUP_PINS,
4857 .v.pins = (const struct alc_pincfg[]) {
4858 { 0x1e, 0x411111f0 }, /* N/A */
4859 { }
4860 },
4861 .chained = true,
4862 .chain_id = ALC880_FIXUP_5ST_BASE,
4863 },
4864 [ALC880_FIXUP_5ST_DIG] = {
4865 .type = ALC_FIXUP_PINS,
4866 .v.pins = (const struct alc_pincfg[]) {
4867 { 0x1e, 0x0144111e }, /* SPDIF */
4868 { }
4869 },
4870 .chained = true,
4871 .chain_id = ALC880_FIXUP_5ST_BASE,
4872 },
4873 [ALC880_FIXUP_6ST_BASE] = {
4874 .type = ALC_FIXUP_PINS,
4875 .v.pins = (const struct alc_pincfg[]) {
4876 { 0x14, 0x01014010 }, /* front */
4877 { 0x15, 0x01016412 }, /* surr */
4878 { 0x16, 0x01011411 }, /* CLFE */
4879 { 0x17, 0x01012414 }, /* side */
4880 { 0x18, 0x01a19c30 }, /* mic-in */
4881 { 0x19, 0x02a19c40 }, /* front-mic */
4882 { 0x1a, 0x01813031 }, /* line-in */
4883 { 0x1b, 0x0121411f }, /* HP */
4884 { 0x1c, 0x411111f0 }, /* N/A */
4885 { 0x1d, 0x411111f0 }, /* N/A */
4886 /* 0x1e is filled in below */
4887 { 0x1f, 0x411111f0 }, /* N/A */
4888 { }
4889 }
4890 },
4891 [ALC880_FIXUP_6ST] = {
4892 .type = ALC_FIXUP_PINS,
4893 .v.pins = (const struct alc_pincfg[]) {
4894 { 0x1e, 0x411111f0 }, /* N/A */
4895 { }
4896 },
4897 .chained = true,
4898 .chain_id = ALC880_FIXUP_6ST_BASE,
4899 },
4900 [ALC880_FIXUP_6ST_DIG] = {
4901 .type = ALC_FIXUP_PINS,
4902 .v.pins = (const struct alc_pincfg[]) {
4903 { 0x1e, 0x0144111e }, /* SPDIF */
4904 { }
4905 },
4906 .chained = true,
4907 .chain_id = ALC880_FIXUP_6ST_BASE,
4908 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004909};
4910
4911static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004912 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004913 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004914 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4915 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004916 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004917 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004918 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004919 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004920 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004921 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004922 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004923 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004924 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004925 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004926 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004927 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4928 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4929 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004930 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004931
4932 /* Below is the copied entries from alc880_quirks.c.
4933 * It's not quite sure whether BIOS sets the correct pin-config table
4934 * on these machines, thus they are kept to be compatible with
4935 * the old static quirks. Once when it's confirmed to work without
4936 * these overrides, it'd be better to remove.
4937 */
4938 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4939 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4940 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4941 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4942 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4943 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4944 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4945 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4946 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4947 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4948 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4949 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4950 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4951 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4952 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4953 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4954 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4955 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4956 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4957 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4958 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4959 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4960 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4961 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4962 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4963 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4964 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4965 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4966 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4967 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4968 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4969 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4970 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4971 /* default Intel */
4972 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4973 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4974 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4975 {}
4976};
4977
4978static const struct alc_model_fixup alc880_fixup_models[] = {
4979 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4980 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4981 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4982 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4983 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4984 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004985 {}
4986};
4987
4988
4989/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004990 * OK, here we have finally the patch for ALC880
4991 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004992static int patch_alc880(struct hda_codec *codec)
4993{
4994 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995 int err;
4996
Takashi Iwai3de95172012-05-07 18:03:15 +02004997 err = alc_alloc_spec(codec, 0x0b);
4998 if (err < 0)
4999 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000
Takashi Iwai3de95172012-05-07 18:03:15 +02005001 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02005002 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005003
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005004 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
5005 alc880_fixups);
5006 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005007
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005008 /* automatic parse from the BIOS config */
5009 err = alc880_parse_auto_config(codec);
5010 if (err < 0)
5011 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005012
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005013 if (!spec->no_analog) {
5014 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005015 if (err < 0)
5016 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005017 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5018 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005019
Takashi Iwai1d045db2011-07-07 18:23:21 +02005020 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02005021 codec->patch_ops.unsol_event = alc880_unsol_event;
5022
Takashi Iwai1d045db2011-07-07 18:23:21 +02005023
Takashi Iwai589876e2012-02-20 15:47:55 +01005024 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5025
Takashi Iwai1d045db2011-07-07 18:23:21 +02005026 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005027
5028 error:
5029 alc_free(codec);
5030 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005031}
5032
5033
5034/*
5035 * ALC260 support
5036 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005037static int alc260_parse_auto_config(struct hda_codec *codec)
5038{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005039 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005040 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5041 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005042}
5043
Takashi Iwai1d045db2011-07-07 18:23:21 +02005044/*
5045 * Pin config fixes
5046 */
5047enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005048 ALC260_FIXUP_HP_DC5750,
5049 ALC260_FIXUP_HP_PIN_0F,
5050 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005051 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005052 ALC260_FIXUP_GPIO1_TOGGLE,
5053 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005054 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005055 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005056};
5057
Takashi Iwai20f7d922012-02-16 12:35:16 +01005058static void alc260_gpio1_automute(struct hda_codec *codec)
5059{
5060 struct alc_spec *spec = codec->spec;
5061 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5062 spec->hp_jack_present);
5063}
5064
5065static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5066 const struct alc_fixup *fix, int action)
5067{
5068 struct alc_spec *spec = codec->spec;
5069 if (action == ALC_FIXUP_ACT_PROBE) {
5070 /* although the machine has only one output pin, we need to
5071 * toggle GPIO1 according to the jack state
5072 */
5073 spec->automute_hook = alc260_gpio1_automute;
5074 spec->detect_hp = 1;
5075 spec->automute_speaker = 1;
5076 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005077 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5078 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005079 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005080 }
5081}
5082
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005083static void alc260_fixup_kn1(struct hda_codec *codec,
5084 const struct alc_fixup *fix, int action)
5085{
5086 struct alc_spec *spec = codec->spec;
5087 static const struct alc_pincfg pincfgs[] = {
5088 { 0x0f, 0x02214000 }, /* HP/speaker */
5089 { 0x12, 0x90a60160 }, /* int mic */
5090 { 0x13, 0x02a19000 }, /* ext mic */
5091 { 0x18, 0x01446000 }, /* SPDIF out */
5092 /* disable bogus I/O pins */
5093 { 0x10, 0x411111f0 },
5094 { 0x11, 0x411111f0 },
5095 { 0x14, 0x411111f0 },
5096 { 0x15, 0x411111f0 },
5097 { 0x16, 0x411111f0 },
5098 { 0x17, 0x411111f0 },
5099 { 0x19, 0x411111f0 },
5100 { }
5101 };
5102
5103 switch (action) {
5104 case ALC_FIXUP_ACT_PRE_PROBE:
5105 alc_apply_pincfgs(codec, pincfgs);
5106 break;
5107 case ALC_FIXUP_ACT_PROBE:
5108 spec->init_amp = ALC_INIT_NONE;
5109 break;
5110 }
5111}
5112
Takashi Iwai1d045db2011-07-07 18:23:21 +02005113static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005114 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005115 .type = ALC_FIXUP_PINS,
5116 .v.pins = (const struct alc_pincfg[]) {
5117 { 0x11, 0x90130110 }, /* speaker */
5118 { }
5119 }
5120 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005121 [ALC260_FIXUP_HP_PIN_0F] = {
5122 .type = ALC_FIXUP_PINS,
5123 .v.pins = (const struct alc_pincfg[]) {
5124 { 0x0f, 0x01214000 }, /* HP */
5125 { }
5126 }
5127 },
5128 [ALC260_FIXUP_COEF] = {
5129 .type = ALC_FIXUP_VERBS,
5130 .v.verbs = (const struct hda_verb[]) {
5131 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5132 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5133 { }
5134 },
5135 .chained = true,
5136 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5137 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005138 [ALC260_FIXUP_GPIO1] = {
5139 .type = ALC_FIXUP_VERBS,
5140 .v.verbs = alc_gpio1_init_verbs,
5141 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005142 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5143 .type = ALC_FIXUP_FUNC,
5144 .v.func = alc260_fixup_gpio1_toggle,
5145 .chained = true,
5146 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5147 },
5148 [ALC260_FIXUP_REPLACER] = {
5149 .type = ALC_FIXUP_VERBS,
5150 .v.verbs = (const struct hda_verb[]) {
5151 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5152 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5153 { }
5154 },
5155 .chained = true,
5156 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5157 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005158 [ALC260_FIXUP_HP_B1900] = {
5159 .type = ALC_FIXUP_FUNC,
5160 .v.func = alc260_fixup_gpio1_toggle,
5161 .chained = true,
5162 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005163 },
5164 [ALC260_FIXUP_KN1] = {
5165 .type = ALC_FIXUP_FUNC,
5166 .v.func = alc260_fixup_kn1,
5167 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005168};
5169
5170static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005171 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005172 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005173 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005174 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005175 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005176 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005177 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005178 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005179 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005180 {}
5181};
5182
5183/*
5184 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005185static int patch_alc260(struct hda_codec *codec)
5186{
5187 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005188 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005189
Takashi Iwai3de95172012-05-07 18:03:15 +02005190 err = alc_alloc_spec(codec, 0x07);
5191 if (err < 0)
5192 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005193
Takashi Iwai3de95172012-05-07 18:03:15 +02005194 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005195
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005196 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5197 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005198
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005199 /* automatic parse from the BIOS config */
5200 err = alc260_parse_auto_config(codec);
5201 if (err < 0)
5202 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005203
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005204 if (!spec->no_analog) {
5205 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005206 if (err < 0)
5207 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005208 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5209 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005210
Takashi Iwai1d045db2011-07-07 18:23:21 +02005211 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005212 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005213
Takashi Iwai589876e2012-02-20 15:47:55 +01005214 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5215
Takashi Iwai1d045db2011-07-07 18:23:21 +02005216 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005217
5218 error:
5219 alc_free(codec);
5220 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005221}
5222
5223
5224/*
5225 * ALC882/883/885/888/889 support
5226 *
5227 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5228 * configuration. Each pin widget can choose any input DACs and a mixer.
5229 * Each ADC is connected from a mixer of all inputs. This makes possible
5230 * 6-channel independent captures.
5231 *
5232 * In addition, an independent DAC for the multi-playback (not used in this
5233 * driver yet).
5234 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005235
5236/*
5237 * Pin config fixes
5238 */
5239enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005240 ALC882_FIXUP_ABIT_AW9D_MAX,
5241 ALC882_FIXUP_LENOVO_Y530,
5242 ALC882_FIXUP_PB_M5210,
5243 ALC882_FIXUP_ACER_ASPIRE_7736,
5244 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005245 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005246 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005247 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005248 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005249 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005250 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005251 ALC882_FIXUP_GPIO1,
5252 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005253 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005254 ALC889_FIXUP_COEF,
5255 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005256 ALC882_FIXUP_ACER_ASPIRE_4930G,
5257 ALC882_FIXUP_ACER_ASPIRE_8930G,
5258 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005259 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005260 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005261 ALC889_FIXUP_MBP_VREF,
5262 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005263 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005264 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005265};
5266
Takashi Iwai68ef0562011-11-09 18:24:44 +01005267static void alc889_fixup_coef(struct hda_codec *codec,
5268 const struct alc_fixup *fix, int action)
5269{
5270 if (action != ALC_FIXUP_ACT_INIT)
5271 return;
5272 alc889_coef_init(codec);
5273}
5274
Takashi Iwai56710872011-11-14 17:42:11 +01005275/* toggle speaker-output according to the hp-jack state */
5276static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5277{
5278 unsigned int gpiostate, gpiomask, gpiodir;
5279
5280 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5281 AC_VERB_GET_GPIO_DATA, 0);
5282
5283 if (!muted)
5284 gpiostate |= (1 << pin);
5285 else
5286 gpiostate &= ~(1 << pin);
5287
5288 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5289 AC_VERB_GET_GPIO_MASK, 0);
5290 gpiomask |= (1 << pin);
5291
5292 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5293 AC_VERB_GET_GPIO_DIRECTION, 0);
5294 gpiodir |= (1 << pin);
5295
5296
5297 snd_hda_codec_write(codec, codec->afg, 0,
5298 AC_VERB_SET_GPIO_MASK, gpiomask);
5299 snd_hda_codec_write(codec, codec->afg, 0,
5300 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5301
5302 msleep(1);
5303
5304 snd_hda_codec_write(codec, codec->afg, 0,
5305 AC_VERB_SET_GPIO_DATA, gpiostate);
5306}
5307
5308/* set up GPIO at initialization */
5309static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5310 const struct alc_fixup *fix, int action)
5311{
5312 if (action != ALC_FIXUP_ACT_INIT)
5313 return;
5314 alc882_gpio_mute(codec, 0, 0);
5315 alc882_gpio_mute(codec, 1, 0);
5316}
5317
Takashi Iwai02a237b2012-02-13 15:25:07 +01005318/* Fix the connection of some pins for ALC889:
5319 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5320 * work correctly (bko#42740)
5321 */
5322static void alc889_fixup_dac_route(struct hda_codec *codec,
5323 const struct alc_fixup *fix, int action)
5324{
5325 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005326 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005327 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5328 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5329 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5330 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5331 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5332 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005333 } else if (action == ALC_FIXUP_ACT_PROBE) {
5334 /* restore the connections */
5335 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5336 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5337 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5338 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5339 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005340 }
5341}
5342
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005343/* Set VREF on HP pin */
5344static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5345 const struct alc_fixup *fix, int action)
5346{
5347 struct alc_spec *spec = codec->spec;
5348 static hda_nid_t nids[2] = { 0x14, 0x15 };
5349 int i;
5350
5351 if (action != ALC_FIXUP_ACT_INIT)
5352 return;
5353 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5354 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5355 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5356 continue;
5357 val = snd_hda_codec_read(codec, nids[i], 0,
5358 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5359 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005360 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005361 spec->keep_vref_in_automute = 1;
5362 break;
5363 }
5364}
5365
5366/* Set VREF on speaker pins on imac91 */
5367static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5368 const struct alc_fixup *fix, int action)
5369{
5370 struct alc_spec *spec = codec->spec;
5371 static hda_nid_t nids[2] = { 0x18, 0x1a };
5372 int i;
5373
5374 if (action != ALC_FIXUP_ACT_INIT)
5375 return;
5376 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5377 unsigned int val;
5378 val = snd_hda_codec_read(codec, nids[i], 0,
5379 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5380 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005381 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005382 }
5383 spec->keep_vref_in_automute = 1;
5384}
5385
Takashi Iwaie427c232012-07-29 10:04:08 +02005386/* Don't take HP output as primary
5387 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5388 */
5389static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5390 const struct alc_fixup *fix, int action)
5391{
5392 struct alc_spec *spec = codec->spec;
5393 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5394 spec->no_primary_hp = 1;
5395}
5396
Takashi Iwai1d045db2011-07-07 18:23:21 +02005397static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005398 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005399 .type = ALC_FIXUP_PINS,
5400 .v.pins = (const struct alc_pincfg[]) {
5401 { 0x15, 0x01080104 }, /* side */
5402 { 0x16, 0x01011012 }, /* rear */
5403 { 0x17, 0x01016011 }, /* clfe */
5404 { }
5405 }
5406 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005407 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005408 .type = ALC_FIXUP_PINS,
5409 .v.pins = (const struct alc_pincfg[]) {
5410 { 0x15, 0x99130112 }, /* rear int speakers */
5411 { 0x16, 0x99130111 }, /* subwoofer */
5412 { }
5413 }
5414 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005415 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005416 .type = ALC_FIXUP_VERBS,
5417 .v.verbs = (const struct hda_verb[]) {
5418 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5419 {}
5420 }
5421 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005422 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005423 .type = ALC_FIXUP_FUNC,
5424 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005425 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005426 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005427 .type = ALC_FIXUP_PINS,
5428 .v.pins = (const struct alc_pincfg[]) {
5429 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5430 { }
5431 }
5432 },
Marton Balint8f239212012-03-05 21:33:23 +01005433 [ALC889_FIXUP_CD] = {
5434 .type = ALC_FIXUP_PINS,
5435 .v.pins = (const struct alc_pincfg[]) {
5436 { 0x1c, 0x993301f0 }, /* CD */
5437 { }
5438 }
5439 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005440 [ALC889_FIXUP_VAIO_TT] = {
5441 .type = ALC_FIXUP_PINS,
5442 .v.pins = (const struct alc_pincfg[]) {
5443 { 0x17, 0x90170111 }, /* hidden surround speaker */
5444 { }
5445 }
5446 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005447 [ALC888_FIXUP_EEE1601] = {
5448 .type = ALC_FIXUP_VERBS,
5449 .v.verbs = (const struct hda_verb[]) {
5450 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5451 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5452 { }
5453 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005454 },
5455 [ALC882_FIXUP_EAPD] = {
5456 .type = ALC_FIXUP_VERBS,
5457 .v.verbs = (const struct hda_verb[]) {
5458 /* change to EAPD mode */
5459 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5460 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5461 { }
5462 }
5463 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005464 [ALC883_FIXUP_EAPD] = {
5465 .type = ALC_FIXUP_VERBS,
5466 .v.verbs = (const struct hda_verb[]) {
5467 /* change to EAPD mode */
5468 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5469 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5470 { }
5471 }
5472 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005473 [ALC883_FIXUP_ACER_EAPD] = {
5474 .type = ALC_FIXUP_VERBS,
5475 .v.verbs = (const struct hda_verb[]) {
5476 /* eanable EAPD on Acer laptops */
5477 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5478 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5479 { }
5480 }
5481 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005482 [ALC882_FIXUP_GPIO1] = {
5483 .type = ALC_FIXUP_VERBS,
5484 .v.verbs = alc_gpio1_init_verbs,
5485 },
5486 [ALC882_FIXUP_GPIO2] = {
5487 .type = ALC_FIXUP_VERBS,
5488 .v.verbs = alc_gpio2_init_verbs,
5489 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005490 [ALC882_FIXUP_GPIO3] = {
5491 .type = ALC_FIXUP_VERBS,
5492 .v.verbs = alc_gpio3_init_verbs,
5493 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005494 [ALC882_FIXUP_ASUS_W2JC] = {
5495 .type = ALC_FIXUP_VERBS,
5496 .v.verbs = alc_gpio1_init_verbs,
5497 .chained = true,
5498 .chain_id = ALC882_FIXUP_EAPD,
5499 },
5500 [ALC889_FIXUP_COEF] = {
5501 .type = ALC_FIXUP_FUNC,
5502 .v.func = alc889_fixup_coef,
5503 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005504 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5505 .type = ALC_FIXUP_PINS,
5506 .v.pins = (const struct alc_pincfg[]) {
5507 { 0x16, 0x99130111 }, /* CLFE speaker */
5508 { 0x17, 0x99130112 }, /* surround speaker */
5509 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005510 },
5511 .chained = true,
5512 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005513 },
5514 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5515 .type = ALC_FIXUP_PINS,
5516 .v.pins = (const struct alc_pincfg[]) {
5517 { 0x16, 0x99130111 }, /* CLFE speaker */
5518 { 0x1b, 0x99130112 }, /* surround speaker */
5519 { }
5520 },
5521 .chained = true,
5522 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5523 },
5524 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5525 /* additional init verbs for Acer Aspire 8930G */
5526 .type = ALC_FIXUP_VERBS,
5527 .v.verbs = (const struct hda_verb[]) {
5528 /* Enable all DACs */
5529 /* DAC DISABLE/MUTE 1? */
5530 /* setting bits 1-5 disables DAC nids 0x02-0x06
5531 * apparently. Init=0x38 */
5532 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5533 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5534 /* DAC DISABLE/MUTE 2? */
5535 /* some bit here disables the other DACs.
5536 * Init=0x4900 */
5537 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5538 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5539 /* DMIC fix
5540 * This laptop has a stereo digital microphone.
5541 * The mics are only 1cm apart which makes the stereo
5542 * useless. However, either the mic or the ALC889
5543 * makes the signal become a difference/sum signal
5544 * instead of standard stereo, which is annoying.
5545 * So instead we flip this bit which makes the
5546 * codec replicate the sum signal to both channels,
5547 * turning it into a normal mono mic.
5548 */
5549 /* DMIC_CONTROL? Init value = 0x0001 */
5550 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5551 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5552 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5553 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5554 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005555 },
5556 .chained = true,
5557 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005558 },
Takashi Iwai56710872011-11-14 17:42:11 +01005559 [ALC885_FIXUP_MACPRO_GPIO] = {
5560 .type = ALC_FIXUP_FUNC,
5561 .v.func = alc885_fixup_macpro_gpio,
5562 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005563 [ALC889_FIXUP_DAC_ROUTE] = {
5564 .type = ALC_FIXUP_FUNC,
5565 .v.func = alc889_fixup_dac_route,
5566 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005567 [ALC889_FIXUP_MBP_VREF] = {
5568 .type = ALC_FIXUP_FUNC,
5569 .v.func = alc889_fixup_mbp_vref,
5570 .chained = true,
5571 .chain_id = ALC882_FIXUP_GPIO1,
5572 },
5573 [ALC889_FIXUP_IMAC91_VREF] = {
5574 .type = ALC_FIXUP_FUNC,
5575 .v.func = alc889_fixup_imac91_vref,
5576 .chained = true,
5577 .chain_id = ALC882_FIXUP_GPIO1,
5578 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005579 [ALC882_FIXUP_INV_DMIC] = {
5580 .type = ALC_FIXUP_FUNC,
5581 .v.func = alc_fixup_inv_dmic_0x12,
5582 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005583 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5584 .type = ALC_FIXUP_FUNC,
5585 .v.func = alc882_fixup_no_primary_hp,
5586 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005587};
5588
5589static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005590 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5591 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5592 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5593 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5594 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5595 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005596 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5597 ALC882_FIXUP_ACER_ASPIRE_4930G),
5598 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5599 ALC882_FIXUP_ACER_ASPIRE_4930G),
5600 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5601 ALC882_FIXUP_ACER_ASPIRE_8930G),
5602 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5603 ALC882_FIXUP_ACER_ASPIRE_8930G),
5604 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5605 ALC882_FIXUP_ACER_ASPIRE_4930G),
5606 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5607 ALC882_FIXUP_ACER_ASPIRE_4930G),
5608 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5609 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005610 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005611 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5612 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005613 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005614 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005615 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005616 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005617 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005618 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005619 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005620 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005621 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005622
5623 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005624 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5625 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5626 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005627 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5628 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5629 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005630 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5631 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005632 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005633 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5634 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5635 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5636 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005637 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005638 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5639 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5640 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005641 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005642 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005643 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5644 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5645 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005646
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005647 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005648 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005649 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005650 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005651 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005652 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5653 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005654 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005655 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656 {}
5657};
5658
Takashi Iwai912093b2012-04-11 14:03:41 +02005659static const struct alc_model_fixup alc882_fixup_models[] = {
5660 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5661 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5662 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005663 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005664 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005665 {}
5666};
5667
Takashi Iwai1d045db2011-07-07 18:23:21 +02005668/*
5669 * BIOS auto configuration
5670 */
5671/* almost identical with ALC880 parser... */
5672static int alc882_parse_auto_config(struct hda_codec *codec)
5673{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005674 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005675 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5676 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005677}
5678
Takashi Iwai1d045db2011-07-07 18:23:21 +02005679/*
5680 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005681static int patch_alc882(struct hda_codec *codec)
5682{
5683 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005684 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005685
Takashi Iwai3de95172012-05-07 18:03:15 +02005686 err = alc_alloc_spec(codec, 0x0b);
5687 if (err < 0)
5688 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005689
Takashi Iwai3de95172012-05-07 18:03:15 +02005690 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691
5692 switch (codec->vendor_id) {
5693 case 0x10ec0882:
5694 case 0x10ec0885:
5695 break;
5696 default:
5697 /* ALC883 and variants */
5698 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5699 break;
5700 }
5701
Takashi Iwai912093b2012-04-11 14:03:41 +02005702 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5703 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005704 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005705
5706 alc_auto_parse_customize_define(codec);
5707
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005708 /* automatic parse from the BIOS config */
5709 err = alc882_parse_auto_config(codec);
5710 if (err < 0)
5711 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005713 if (!spec->no_analog && has_cdefine_beep(codec)) {
5714 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005715 if (err < 0)
5716 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005717 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005718 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005719
Takashi Iwai1d045db2011-07-07 18:23:21 +02005720 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721
Takashi Iwai589876e2012-02-20 15:47:55 +01005722 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5723
Takashi Iwai1d045db2011-07-07 18:23:21 +02005724 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005725
5726 error:
5727 alc_free(codec);
5728 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005729}
5730
5731
5732/*
5733 * ALC262 support
5734 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005735static int alc262_parse_auto_config(struct hda_codec *codec)
5736{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005737 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005738 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5739 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005740}
5741
5742/*
5743 * Pin config fixes
5744 */
5745enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005746 ALC262_FIXUP_FSC_H270,
5747 ALC262_FIXUP_HP_Z200,
5748 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005749 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005750 ALC262_FIXUP_BENQ,
5751 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005752 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753};
5754
5755static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005756 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757 .type = ALC_FIXUP_PINS,
5758 .v.pins = (const struct alc_pincfg[]) {
5759 { 0x14, 0x99130110 }, /* speaker */
5760 { 0x15, 0x0221142f }, /* front HP */
5761 { 0x1b, 0x0121141f }, /* rear HP */
5762 { }
5763 }
5764 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005765 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005766 .type = ALC_FIXUP_PINS,
5767 .v.pins = (const struct alc_pincfg[]) {
5768 { 0x16, 0x99130120 }, /* internal speaker */
5769 { }
5770 }
5771 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005772 [ALC262_FIXUP_TYAN] = {
5773 .type = ALC_FIXUP_PINS,
5774 .v.pins = (const struct alc_pincfg[]) {
5775 { 0x14, 0x1993e1f0 }, /* int AUX */
5776 { }
5777 }
5778 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005779 [ALC262_FIXUP_LENOVO_3000] = {
5780 .type = ALC_FIXUP_VERBS,
5781 .v.verbs = (const struct hda_verb[]) {
5782 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005783 {}
5784 },
5785 .chained = true,
5786 .chain_id = ALC262_FIXUP_BENQ,
5787 },
5788 [ALC262_FIXUP_BENQ] = {
5789 .type = ALC_FIXUP_VERBS,
5790 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005791 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5792 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5793 {}
5794 }
5795 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005796 [ALC262_FIXUP_BENQ_T31] = {
5797 .type = ALC_FIXUP_VERBS,
5798 .v.verbs = (const struct hda_verb[]) {
5799 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5800 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5801 {}
5802 }
5803 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005804 [ALC262_FIXUP_INV_DMIC] = {
5805 .type = ALC_FIXUP_FUNC,
5806 .v.func = alc_fixup_inv_dmic_0x12,
5807 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005808};
5809
5810static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005811 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005812 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5813 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005814 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5815 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005816 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005817 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5818 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005819 {}
5820};
5821
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005822static const struct alc_model_fixup alc262_fixup_models[] = {
5823 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5824 {}
5825};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005826
Takashi Iwai1d045db2011-07-07 18:23:21 +02005827/*
5828 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005829static int patch_alc262(struct hda_codec *codec)
5830{
5831 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005832 int err;
5833
Takashi Iwai3de95172012-05-07 18:03:15 +02005834 err = alc_alloc_spec(codec, 0x0b);
5835 if (err < 0)
5836 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005837
Takashi Iwai3de95172012-05-07 18:03:15 +02005838 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005839
5840#if 0
5841 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5842 * under-run
5843 */
5844 {
5845 int tmp;
5846 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5847 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5848 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5849 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5850 }
5851#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005852 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5853
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005854 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5855 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005856 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005857
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005858 alc_auto_parse_customize_define(codec);
5859
Takashi Iwai42399f72011-11-07 17:18:44 +01005860 /* automatic parse from the BIOS config */
5861 err = alc262_parse_auto_config(codec);
5862 if (err < 0)
5863 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005864
Takashi Iwai1d045db2011-07-07 18:23:21 +02005865 if (!spec->no_analog && has_cdefine_beep(codec)) {
5866 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005867 if (err < 0)
5868 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005869 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005870 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005871
Takashi Iwai1d045db2011-07-07 18:23:21 +02005872 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005873 spec->shutup = alc_eapd_shutup;
5874
Takashi Iwai589876e2012-02-20 15:47:55 +01005875 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5876
Takashi Iwai1d045db2011-07-07 18:23:21 +02005877 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005878
5879 error:
5880 alc_free(codec);
5881 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005882}
5883
5884/*
5885 * ALC268
5886 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887/* bind Beep switches of both NID 0x0f and 0x10 */
5888static const struct hda_bind_ctls alc268_bind_beep_sw = {
5889 .ops = &snd_hda_bind_sw,
5890 .values = {
5891 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5892 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5893 0
5894 },
5895};
5896
5897static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5898 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5899 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5900 { }
5901};
5902
5903/* set PCBEEP vol = 0, mute connections */
5904static const struct hda_verb alc268_beep_init_verbs[] = {
5905 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5906 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5907 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5908 { }
5909};
5910
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005911enum {
5912 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005913 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005914};
5915
5916static const struct alc_fixup alc268_fixups[] = {
5917 [ALC268_FIXUP_INV_DMIC] = {
5918 .type = ALC_FIXUP_FUNC,
5919 .v.func = alc_fixup_inv_dmic_0x12,
5920 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005921 [ALC268_FIXUP_HP_EAPD] = {
5922 .type = ALC_FIXUP_VERBS,
5923 .v.verbs = (const struct hda_verb[]) {
5924 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5925 {}
5926 }
5927 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005928};
5929
5930static const struct alc_model_fixup alc268_fixup_models[] = {
5931 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005932 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5933 {}
5934};
5935
5936static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5937 /* below is codec SSID since multiple Toshiba laptops have the
5938 * same PCI SSID 1179:ff00
5939 */
5940 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005941 {}
5942};
5943
Takashi Iwai1d045db2011-07-07 18:23:21 +02005944/*
5945 * BIOS auto configuration
5946 */
5947static int alc268_parse_auto_config(struct hda_codec *codec)
5948{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005949 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005950 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005951 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5952 if (err > 0) {
5953 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5954 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005955 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005956 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005957 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005958 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005959}
5960
Takashi Iwai1d045db2011-07-07 18:23:21 +02005961/*
5962 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005963static int patch_alc268(struct hda_codec *codec)
5964{
5965 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005966 int i, has_beep, err;
5967
Takashi Iwai1d045db2011-07-07 18:23:21 +02005968 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005969 err = alc_alloc_spec(codec, 0);
5970 if (err < 0)
5971 return err;
5972
5973 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005974
Takashi Iwaicb766402012-10-20 10:55:21 +02005975 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005976 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5977
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005978 /* automatic parse from the BIOS config */
5979 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005980 if (err < 0)
5981 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005982
Takashi Iwai1d045db2011-07-07 18:23:21 +02005983 has_beep = 0;
5984 for (i = 0; i < spec->num_mixers; i++) {
5985 if (spec->mixers[i] == alc268_beep_mixer) {
5986 has_beep = 1;
5987 break;
5988 }
5989 }
5990
5991 if (has_beep) {
5992 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005993 if (err < 0)
5994 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005995 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5996 /* override the amp caps for beep generator */
5997 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5998 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5999 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
6000 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6001 (0 << AC_AMPCAP_MUTE_SHIFT));
6002 }
6003
Takashi Iwai1d045db2011-07-07 18:23:21 +02006004 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006005 spec->shutup = alc_eapd_shutup;
6006
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006007 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6008
Takashi Iwai1d045db2011-07-07 18:23:21 +02006009 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006010
6011 error:
6012 alc_free(codec);
6013 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006014}
6015
6016/*
6017 * ALC269
6018 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006019static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6020 .substreams = 1,
6021 .channels_min = 2,
6022 .channels_max = 8,
6023 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6024 /* NID is set in alc_build_pcms */
6025 .ops = {
6026 .open = alc_playback_pcm_open,
6027 .prepare = alc_playback_pcm_prepare,
6028 .cleanup = alc_playback_pcm_cleanup
6029 },
6030};
6031
6032static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6033 .substreams = 1,
6034 .channels_min = 2,
6035 .channels_max = 2,
6036 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6037 /* NID is set in alc_build_pcms */
6038};
6039
Takashi Iwai1d045db2011-07-07 18:23:21 +02006040/* different alc269-variants */
6041enum {
6042 ALC269_TYPE_ALC269VA,
6043 ALC269_TYPE_ALC269VB,
6044 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006045 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006046 ALC269_TYPE_ALC280,
6047 ALC269_TYPE_ALC282,
6048 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006049};
6050
6051/*
6052 * BIOS auto configuration
6053 */
6054static int alc269_parse_auto_config(struct hda_codec *codec)
6055{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006056 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006057 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6058 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6059 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006060 const hda_nid_t *ssids;
6061
6062 switch (spec->codec_variant) {
6063 case ALC269_TYPE_ALC269VA:
6064 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006065 case ALC269_TYPE_ALC280:
6066 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006067 ssids = alc269va_ssids;
6068 break;
6069 case ALC269_TYPE_ALC269VB:
6070 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006071 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006072 ssids = alc269_ssids;
6073 break;
6074 default:
6075 ssids = alc269_ssids;
6076 break;
6077 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006078
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006079 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006080}
6081
Kailang Yang1387e2d2012-11-08 10:23:18 +01006082static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006083{
6084 int val = alc_read_coef_idx(codec, 0x04);
6085 if (power_up)
6086 val |= 1 << 11;
6087 else
6088 val &= ~(1 << 11);
6089 alc_write_coef_idx(codec, 0x04, val);
6090}
6091
6092static void alc269_shutup(struct hda_codec *codec)
6093{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006094 struct alc_spec *spec = codec->spec;
6095
6096 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6097 return;
6098
Kailang Yang1387e2d2012-11-08 10:23:18 +01006099 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6100 alc269vb_toggle_power_output(codec, 0);
6101 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6102 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006103 msleep(150);
6104 }
6105}
6106
Takashi Iwai2a439522011-07-26 09:52:50 +02006107#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006108static int alc269_resume(struct hda_codec *codec)
6109{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006110 struct alc_spec *spec = codec->spec;
6111
Kailang Yang1387e2d2012-11-08 10:23:18 +01006112 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6113 alc269vb_toggle_power_output(codec, 0);
6114 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006115 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006116 msleep(150);
6117 }
6118
6119 codec->patch_ops.init(codec);
6120
Kailang Yang1387e2d2012-11-08 10:23:18 +01006121 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6122 alc269vb_toggle_power_output(codec, 1);
6123 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006124 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006125 msleep(200);
6126 }
6127
Takashi Iwai1d045db2011-07-07 18:23:21 +02006128 snd_hda_codec_resume_amp(codec);
6129 snd_hda_codec_resume_cache(codec);
6130 hda_call_check_power_status(codec, 0x01);
6131 return 0;
6132}
Takashi Iwai2a439522011-07-26 09:52:50 +02006133#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006134
David Henningsson108cc102012-07-20 10:37:25 +02006135static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6136 const struct alc_fixup *fix, int action)
6137{
6138 struct alc_spec *spec = codec->spec;
6139
6140 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6141 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6142}
6143
Takashi Iwai1d045db2011-07-07 18:23:21 +02006144static void alc269_fixup_hweq(struct hda_codec *codec,
6145 const struct alc_fixup *fix, int action)
6146{
6147 int coef;
6148
6149 if (action != ALC_FIXUP_ACT_INIT)
6150 return;
6151 coef = alc_read_coef_idx(codec, 0x1e);
6152 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6153}
6154
6155static void alc271_fixup_dmic(struct hda_codec *codec,
6156 const struct alc_fixup *fix, int action)
6157{
6158 static const struct hda_verb verbs[] = {
6159 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6160 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6161 {}
6162 };
6163 unsigned int cfg;
6164
6165 if (strcmp(codec->chip_name, "ALC271X"))
6166 return;
6167 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6168 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6169 snd_hda_sequence_write(codec, verbs);
6170}
6171
Takashi Iwai017f2a12011-07-09 14:42:25 +02006172static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6173 const struct alc_fixup *fix, int action)
6174{
6175 struct alc_spec *spec = codec->spec;
6176
6177 if (action != ALC_FIXUP_ACT_PROBE)
6178 return;
6179
6180 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6181 * fix the sample rate of analog I/O to 44.1kHz
6182 */
6183 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6184 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6185}
6186
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006187static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6188 const struct alc_fixup *fix, int action)
6189{
6190 int coef;
6191
6192 if (action != ALC_FIXUP_ACT_INIT)
6193 return;
6194 /* The digital-mic unit sends PDM (differential signal) instead of
6195 * the standard PCM, thus you can't record a valid mono stream as is.
6196 * Below is a workaround specific to ALC269 to control the dmic
6197 * signal source as mono.
6198 */
6199 coef = alc_read_coef_idx(codec, 0x07);
6200 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6201}
6202
Takashi Iwai24519912011-08-16 15:08:49 +02006203static void alc269_quanta_automute(struct hda_codec *codec)
6204{
David Henningsson42cf0d02011-09-20 12:04:56 +02006205 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006206
6207 snd_hda_codec_write(codec, 0x20, 0,
6208 AC_VERB_SET_COEF_INDEX, 0x0c);
6209 snd_hda_codec_write(codec, 0x20, 0,
6210 AC_VERB_SET_PROC_COEF, 0x680);
6211
6212 snd_hda_codec_write(codec, 0x20, 0,
6213 AC_VERB_SET_COEF_INDEX, 0x0c);
6214 snd_hda_codec_write(codec, 0x20, 0,
6215 AC_VERB_SET_PROC_COEF, 0x480);
6216}
6217
6218static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6219 const struct alc_fixup *fix, int action)
6220{
6221 struct alc_spec *spec = codec->spec;
6222 if (action != ALC_FIXUP_ACT_PROBE)
6223 return;
6224 spec->automute_hook = alc269_quanta_automute;
6225}
6226
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006227/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6228static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6229{
6230 struct hda_codec *codec = private_data;
6231 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6232 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6233 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6234}
6235
6236static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6237 const struct alc_fixup *fix, int action)
6238{
6239 struct alc_spec *spec = codec->spec;
6240 switch (action) {
6241 case ALC_FIXUP_ACT_BUILD:
6242 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6243 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6244 /* fallthru */
6245 case ALC_FIXUP_ACT_INIT:
6246 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6247 break;
6248 }
6249}
6250
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006251/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6252static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6253{
6254 struct hda_codec *codec = private_data;
6255 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006256 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006257}
6258
6259static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6260 const struct alc_fixup *fix, int action)
6261{
6262 struct alc_spec *spec = codec->spec;
6263 switch (action) {
6264 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006265 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006266 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006267 /* fallthru */
6268 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006269 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006270 break;
6271 }
6272}
6273
Dylan Reid08a978d2012-11-18 22:56:40 -08006274static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6275 const struct alc_fixup *fix,
6276 int action)
6277{
6278 struct alc_spec *spec = codec->spec;
6279
6280 if (action == ALC_FIXUP_ACT_PROBE)
6281 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6282 spec->autocfg.hp_pins[0]);
6283}
David Henningsson693b6132012-06-22 19:12:10 +02006284
Takashi Iwai1d045db2011-07-07 18:23:21 +02006285enum {
6286 ALC269_FIXUP_SONY_VAIO,
6287 ALC275_FIXUP_SONY_VAIO_GPIO2,
6288 ALC269_FIXUP_DELL_M101Z,
6289 ALC269_FIXUP_SKU_IGNORE,
6290 ALC269_FIXUP_ASUS_G73JW,
6291 ALC269_FIXUP_LENOVO_EAPD,
6292 ALC275_FIXUP_SONY_HWEQ,
6293 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006294 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006295 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006296 ALC269_FIXUP_QUANTA_MUTE,
6297 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006298 ALC269_FIXUP_AMIC,
6299 ALC269_FIXUP_DMIC,
6300 ALC269VB_FIXUP_AMIC,
6301 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006302 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006303 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006304 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006305 ALC269_FIXUP_LENOVO_DOCK,
6306 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006307 ALC271_FIXUP_AMIC_MIC2,
6308 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006309};
6310
6311static const struct alc_fixup alc269_fixups[] = {
6312 [ALC269_FIXUP_SONY_VAIO] = {
6313 .type = ALC_FIXUP_VERBS,
6314 .v.verbs = (const struct hda_verb[]) {
6315 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6316 {}
6317 }
6318 },
6319 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6320 .type = ALC_FIXUP_VERBS,
6321 .v.verbs = (const struct hda_verb[]) {
6322 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6323 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6324 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6325 { }
6326 },
6327 .chained = true,
6328 .chain_id = ALC269_FIXUP_SONY_VAIO
6329 },
6330 [ALC269_FIXUP_DELL_M101Z] = {
6331 .type = ALC_FIXUP_VERBS,
6332 .v.verbs = (const struct hda_verb[]) {
6333 /* Enables internal speaker */
6334 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6335 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6336 {}
6337 }
6338 },
6339 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006340 .type = ALC_FIXUP_FUNC,
6341 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006342 },
6343 [ALC269_FIXUP_ASUS_G73JW] = {
6344 .type = ALC_FIXUP_PINS,
6345 .v.pins = (const struct alc_pincfg[]) {
6346 { 0x17, 0x99130111 }, /* subwoofer */
6347 { }
6348 }
6349 },
6350 [ALC269_FIXUP_LENOVO_EAPD] = {
6351 .type = ALC_FIXUP_VERBS,
6352 .v.verbs = (const struct hda_verb[]) {
6353 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6354 {}
6355 }
6356 },
6357 [ALC275_FIXUP_SONY_HWEQ] = {
6358 .type = ALC_FIXUP_FUNC,
6359 .v.func = alc269_fixup_hweq,
6360 .chained = true,
6361 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6362 },
6363 [ALC271_FIXUP_DMIC] = {
6364 .type = ALC_FIXUP_FUNC,
6365 .v.func = alc271_fixup_dmic,
6366 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006367 [ALC269_FIXUP_PCM_44K] = {
6368 .type = ALC_FIXUP_FUNC,
6369 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006370 .chained = true,
6371 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006372 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006373 [ALC269_FIXUP_STEREO_DMIC] = {
6374 .type = ALC_FIXUP_FUNC,
6375 .v.func = alc269_fixup_stereo_dmic,
6376 },
Takashi Iwai24519912011-08-16 15:08:49 +02006377 [ALC269_FIXUP_QUANTA_MUTE] = {
6378 .type = ALC_FIXUP_FUNC,
6379 .v.func = alc269_fixup_quanta_mute,
6380 },
6381 [ALC269_FIXUP_LIFEBOOK] = {
6382 .type = ALC_FIXUP_PINS,
6383 .v.pins = (const struct alc_pincfg[]) {
6384 { 0x1a, 0x2101103f }, /* dock line-out */
6385 { 0x1b, 0x23a11040 }, /* dock mic-in */
6386 { }
6387 },
6388 .chained = true,
6389 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6390 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006391 [ALC269_FIXUP_AMIC] = {
6392 .type = ALC_FIXUP_PINS,
6393 .v.pins = (const struct alc_pincfg[]) {
6394 { 0x14, 0x99130110 }, /* speaker */
6395 { 0x15, 0x0121401f }, /* HP out */
6396 { 0x18, 0x01a19c20 }, /* mic */
6397 { 0x19, 0x99a3092f }, /* int-mic */
6398 { }
6399 },
6400 },
6401 [ALC269_FIXUP_DMIC] = {
6402 .type = ALC_FIXUP_PINS,
6403 .v.pins = (const struct alc_pincfg[]) {
6404 { 0x12, 0x99a3092f }, /* int-mic */
6405 { 0x14, 0x99130110 }, /* speaker */
6406 { 0x15, 0x0121401f }, /* HP out */
6407 { 0x18, 0x01a19c20 }, /* mic */
6408 { }
6409 },
6410 },
6411 [ALC269VB_FIXUP_AMIC] = {
6412 .type = ALC_FIXUP_PINS,
6413 .v.pins = (const struct alc_pincfg[]) {
6414 { 0x14, 0x99130110 }, /* speaker */
6415 { 0x18, 0x01a19c20 }, /* mic */
6416 { 0x19, 0x99a3092f }, /* int-mic */
6417 { 0x21, 0x0121401f }, /* HP out */
6418 { }
6419 },
6420 },
David Henningsson2267ea92012-01-03 08:45:56 +01006421 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006422 .type = ALC_FIXUP_PINS,
6423 .v.pins = (const struct alc_pincfg[]) {
6424 { 0x12, 0x99a3092f }, /* int-mic */
6425 { 0x14, 0x99130110 }, /* speaker */
6426 { 0x18, 0x01a19c20 }, /* mic */
6427 { 0x21, 0x0121401f }, /* HP out */
6428 { }
6429 },
6430 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006431 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6432 .type = ALC_FIXUP_FUNC,
6433 .v.func = alc269_fixup_mic1_mute,
6434 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006435 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6436 .type = ALC_FIXUP_FUNC,
6437 .v.func = alc269_fixup_mic2_mute,
6438 },
David Henningsson693b6132012-06-22 19:12:10 +02006439 [ALC269_FIXUP_INV_DMIC] = {
6440 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006441 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006442 },
David Henningsson108cc102012-07-20 10:37:25 +02006443 [ALC269_FIXUP_LENOVO_DOCK] = {
6444 .type = ALC_FIXUP_PINS,
6445 .v.pins = (const struct alc_pincfg[]) {
6446 { 0x19, 0x23a11040 }, /* dock mic */
6447 { 0x1b, 0x2121103f }, /* dock headphone */
6448 { }
6449 },
6450 .chained = true,
6451 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6452 },
6453 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6454 .type = ALC_FIXUP_FUNC,
6455 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6456 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006457 [ALC271_FIXUP_AMIC_MIC2] = {
6458 .type = ALC_FIXUP_PINS,
6459 .v.pins = (const struct alc_pincfg[]) {
6460 { 0x14, 0x99130110 }, /* speaker */
6461 { 0x19, 0x01a19c20 }, /* mic */
6462 { 0x1b, 0x99a7012f }, /* int-mic */
6463 { 0x21, 0x0121401f }, /* HP out */
6464 { }
6465 },
6466 },
6467 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6468 .type = ALC_FIXUP_FUNC,
6469 .v.func = alc271_hp_gate_mic_jack,
6470 .chained = true,
6471 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6472 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006473};
6474
6475static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006476 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6477 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006478 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006479 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006480 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006481 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006482 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006483 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006484 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6485 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6486 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6487 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6488 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006489 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6490 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6491 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6492 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6493 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006494 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006495 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006496 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006497 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6498 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6499 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6500 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6501 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006502 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006503 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006504 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006505 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006506 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006507 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006508 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006509
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006510#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006511 /* Below is a quirk table taken from the old code.
6512 * Basically the device should work as is without the fixup table.
6513 * If BIOS doesn't give a proper info, enable the corresponding
6514 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006515 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006516 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6517 ALC269_FIXUP_AMIC),
6518 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006519 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6520 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6521 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6522 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6523 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6524 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6525 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6526 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6527 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6528 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6529 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6530 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6531 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6532 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6533 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6534 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6535 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6536 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6537 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6538 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6539 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6540 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6541 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6542 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6543 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6544 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6545 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6546 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6547 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6548 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6549 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6550 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6551 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6552 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6553 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6554 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6555 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6556 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6557#endif
6558 {}
6559};
6560
6561static const struct alc_model_fixup alc269_fixup_models[] = {
6562 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6563 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006564 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6565 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6566 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006567 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006568 {}
6569};
6570
6571
Takashi Iwai546bb672012-03-07 08:37:19 +01006572static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006573{
Kailang Yang526af6e2012-03-07 08:25:20 +01006574 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006575 int val;
6576
Kailang Yang526af6e2012-03-07 08:25:20 +01006577 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006578 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006579
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006580 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006581 alc_write_coef_idx(codec, 0xf, 0x960b);
6582 alc_write_coef_idx(codec, 0xe, 0x8817);
6583 }
6584
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006585 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006586 alc_write_coef_idx(codec, 0xf, 0x960b);
6587 alc_write_coef_idx(codec, 0xe, 0x8814);
6588 }
6589
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006590 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006591 val = alc_read_coef_idx(codec, 0x04);
6592 /* Power up output pin */
6593 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6594 }
6595
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006596 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006597 val = alc_read_coef_idx(codec, 0xd);
6598 if ((val & 0x0c00) >> 10 != 0x1) {
6599 /* Capless ramp up clock control */
6600 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6601 }
6602 val = alc_read_coef_idx(codec, 0x17);
6603 if ((val & 0x01c0) >> 6 != 0x4) {
6604 /* Class D power on reset */
6605 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6606 }
6607 }
6608
6609 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6610 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6611
6612 val = alc_read_coef_idx(codec, 0x4); /* HP */
6613 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006614}
6615
6616/*
6617 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006618static int patch_alc269(struct hda_codec *codec)
6619{
6620 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006621 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006622
Takashi Iwai3de95172012-05-07 18:03:15 +02006623 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006624 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006625 return err;
6626
6627 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006628
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006629 alc_pick_fixup(codec, alc269_fixup_models,
6630 alc269_fixup_tbl, alc269_fixups);
6631 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6632
6633 alc_auto_parse_customize_define(codec);
6634
Kailang Yang065380f2013-01-10 10:25:48 +01006635 switch (codec->vendor_id) {
6636 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006637 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006638 switch (alc_get_coef0(codec) & 0x00f0) {
6639 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006640 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006641 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006642 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006643 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006644 break;
6645 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006646 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6647 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006648 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006649 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006650 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006651 case 0x0030:
6652 spec->codec_variant = ALC269_TYPE_ALC269VD;
6653 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006654 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006655 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006656 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006657 if (err < 0)
6658 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006659 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006660 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006661 break;
6662
6663 case 0x10ec0280:
6664 case 0x10ec0290:
6665 spec->codec_variant = ALC269_TYPE_ALC280;
6666 break;
6667 case 0x10ec0282:
6668 case 0x10ec0283:
6669 spec->codec_variant = ALC269_TYPE_ALC282;
6670 break;
6671 case 0x10ec0284:
6672 case 0x10ec0292:
6673 spec->codec_variant = ALC269_TYPE_ALC284;
6674 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006675 }
6676
Takashi Iwaia4297b52011-08-23 18:40:12 +02006677 /* automatic parse from the BIOS config */
6678 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006679 if (err < 0)
6680 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006681
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006682 if (!spec->no_analog && has_cdefine_beep(codec)) {
6683 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006684 if (err < 0)
6685 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006686 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006687 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006688
Takashi Iwai1d045db2011-07-07 18:23:21 +02006689 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006690#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006691 codec->patch_ops.resume = alc269_resume;
6692#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006693 spec->shutup = alc269_shutup;
6694
Takashi Iwai589876e2012-02-20 15:47:55 +01006695 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6696
Takashi Iwai1d045db2011-07-07 18:23:21 +02006697 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006698
6699 error:
6700 alc_free(codec);
6701 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006702}
6703
6704/*
6705 * ALC861
6706 */
6707
Takashi Iwai1d045db2011-07-07 18:23:21 +02006708static int alc861_parse_auto_config(struct hda_codec *codec)
6709{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006710 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006711 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6712 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006713}
6714
Takashi Iwai1d045db2011-07-07 18:23:21 +02006715/* Pin config fixes */
6716enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006717 ALC861_FIXUP_FSC_AMILO_PI1505,
6718 ALC861_FIXUP_AMP_VREF_0F,
6719 ALC861_FIXUP_NO_JACK_DETECT,
6720 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006721};
6722
Takashi Iwai31150f22012-01-30 10:54:08 +01006723/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6724static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6725 const struct alc_fixup *fix, int action)
6726{
6727 struct alc_spec *spec = codec->spec;
6728 unsigned int val;
6729
6730 if (action != ALC_FIXUP_ACT_INIT)
6731 return;
6732 val = snd_hda_codec_read(codec, 0x0f, 0,
6733 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6734 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6735 val |= AC_PINCTL_IN_EN;
6736 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006737 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006738 spec->keep_vref_in_automute = 1;
6739}
6740
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006741/* suppress the jack-detection */
6742static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6743 const struct alc_fixup *fix, int action)
6744{
6745 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6746 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006747}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006748
Takashi Iwai1d045db2011-07-07 18:23:21 +02006749static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006750 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006751 .type = ALC_FIXUP_PINS,
6752 .v.pins = (const struct alc_pincfg[]) {
6753 { 0x0b, 0x0221101f }, /* HP */
6754 { 0x0f, 0x90170310 }, /* speaker */
6755 { }
6756 }
6757 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006758 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006759 .type = ALC_FIXUP_FUNC,
6760 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006761 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006762 [ALC861_FIXUP_NO_JACK_DETECT] = {
6763 .type = ALC_FIXUP_FUNC,
6764 .v.func = alc_fixup_no_jack_detect,
6765 },
6766 [ALC861_FIXUP_ASUS_A6RP] = {
6767 .type = ALC_FIXUP_FUNC,
6768 .v.func = alc861_fixup_asus_amp_vref_0f,
6769 .chained = true,
6770 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6771 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006772};
6773
6774static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006775 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6776 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6777 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6778 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6779 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6780 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006781 {}
6782};
6783
6784/*
6785 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006786static int patch_alc861(struct hda_codec *codec)
6787{
6788 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006789 int err;
6790
Takashi Iwai3de95172012-05-07 18:03:15 +02006791 err = alc_alloc_spec(codec, 0x15);
6792 if (err < 0)
6793 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006794
Takashi Iwai3de95172012-05-07 18:03:15 +02006795 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006796
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006797 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6798 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006799
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006800 /* automatic parse from the BIOS config */
6801 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006802 if (err < 0)
6803 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006804
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006805 if (!spec->no_analog) {
6806 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006807 if (err < 0)
6808 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006809 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6810 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006811
Takashi Iwai1d045db2011-07-07 18:23:21 +02006812 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006813#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006814 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006815#endif
6816
Takashi Iwai589876e2012-02-20 15:47:55 +01006817 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6818
Takashi Iwai1d045db2011-07-07 18:23:21 +02006819 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006820
6821 error:
6822 alc_free(codec);
6823 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006824}
6825
6826/*
6827 * ALC861-VD support
6828 *
6829 * Based on ALC882
6830 *
6831 * In addition, an independent DAC
6832 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006833static int alc861vd_parse_auto_config(struct hda_codec *codec)
6834{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006835 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006836 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6837 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006838}
6839
Takashi Iwai1d045db2011-07-07 18:23:21 +02006840enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006841 ALC660VD_FIX_ASUS_GPIO1,
6842 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006843};
6844
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006845/* exclude VREF80 */
6846static void alc861vd_fixup_dallas(struct hda_codec *codec,
6847 const struct alc_fixup *fix, int action)
6848{
6849 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006850 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6851 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006852 }
6853}
6854
Takashi Iwai1d045db2011-07-07 18:23:21 +02006855static const struct alc_fixup alc861vd_fixups[] = {
6856 [ALC660VD_FIX_ASUS_GPIO1] = {
6857 .type = ALC_FIXUP_VERBS,
6858 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006859 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006860 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6861 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6862 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6863 { }
6864 }
6865 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006866 [ALC861VD_FIX_DALLAS] = {
6867 .type = ALC_FIXUP_FUNC,
6868 .v.func = alc861vd_fixup_dallas,
6869 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006870};
6871
6872static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006873 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006874 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006875 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006876 {}
6877};
6878
Takashi Iwai1d045db2011-07-07 18:23:21 +02006879/*
6880 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006881static int patch_alc861vd(struct hda_codec *codec)
6882{
6883 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006884 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006885
Takashi Iwai3de95172012-05-07 18:03:15 +02006886 err = alc_alloc_spec(codec, 0x0b);
6887 if (err < 0)
6888 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006889
Takashi Iwai3de95172012-05-07 18:03:15 +02006890 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006891
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006892 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6893 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006894
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006895 /* automatic parse from the BIOS config */
6896 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006897 if (err < 0)
6898 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006899
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006900 if (!spec->no_analog) {
6901 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006902 if (err < 0)
6903 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006904 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6905 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006906
Takashi Iwai1d045db2011-07-07 18:23:21 +02006907 codec->patch_ops = alc_patch_ops;
6908
Takashi Iwai1d045db2011-07-07 18:23:21 +02006909 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006910
Takashi Iwai589876e2012-02-20 15:47:55 +01006911 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6912
Takashi Iwai1d045db2011-07-07 18:23:21 +02006913 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006914
6915 error:
6916 alc_free(codec);
6917 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006918}
6919
6920/*
6921 * ALC662 support
6922 *
6923 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6924 * configuration. Each pin widget can choose any input DACs and a mixer.
6925 * Each ADC is connected from a mixer of all inputs. This makes possible
6926 * 6-channel independent captures.
6927 *
6928 * In addition, an independent DAC for the multi-playback (not used in this
6929 * driver yet).
6930 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006931
6932/*
6933 * BIOS auto configuration
6934 */
6935
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006936static int alc662_parse_auto_config(struct hda_codec *codec)
6937{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006938 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006939 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6940 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6941 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006942
Kailang Yang6227cdc2010-02-25 08:36:52 +01006943 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6944 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006945 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006946 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006947 ssids = alc662_ssids;
6948 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006949}
6950
Todd Broch6be79482010-12-07 16:51:05 -08006951static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006952 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006953{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006954 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006955 return;
Todd Broch6be79482010-12-07 16:51:05 -08006956 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6957 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6958 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6959 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6960 (0 << AC_AMPCAP_MUTE_SHIFT)))
6961 printk(KERN_WARNING
6962 "hda_codec: failed to override amp caps for NID 0x2\n");
6963}
6964
David Henningsson6cb3b702010-09-09 08:51:44 +02006965enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006966 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006967 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006968 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006969 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006970 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006971 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006972 ALC662_FIXUP_ASUS_MODE1,
6973 ALC662_FIXUP_ASUS_MODE2,
6974 ALC662_FIXUP_ASUS_MODE3,
6975 ALC662_FIXUP_ASUS_MODE4,
6976 ALC662_FIXUP_ASUS_MODE5,
6977 ALC662_FIXUP_ASUS_MODE6,
6978 ALC662_FIXUP_ASUS_MODE7,
6979 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006980 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006981 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006982 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006983};
6984
6985static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006986 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006987 .type = ALC_FIXUP_PINS,
6988 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006989 { 0x15, 0x99130112 }, /* subwoofer */
6990 { }
6991 }
6992 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006993 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006994 .type = ALC_FIXUP_PINS,
6995 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006996 { 0x17, 0x99130112 }, /* subwoofer */
6997 { }
6998 }
6999 },
Todd Broch6be79482010-12-07 16:51:05 -08007000 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007001 .type = ALC_FIXUP_FUNC,
7002 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007003 },
7004 [ALC662_FIXUP_CZC_P10T] = {
7005 .type = ALC_FIXUP_VERBS,
7006 .v.verbs = (const struct hda_verb[]) {
7007 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7008 {}
7009 }
7010 },
David Henningsson94024cd2011-04-29 14:10:55 +02007011 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02007012 .type = ALC_FIXUP_FUNC,
7013 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02007014 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007015 [ALC662_FIXUP_HP_RP5800] = {
7016 .type = ALC_FIXUP_PINS,
7017 .v.pins = (const struct alc_pincfg[]) {
7018 { 0x14, 0x0221201f }, /* HP out */
7019 { }
7020 },
7021 .chained = true,
7022 .chain_id = ALC662_FIXUP_SKU_IGNORE
7023 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007024 [ALC662_FIXUP_ASUS_MODE1] = {
7025 .type = ALC_FIXUP_PINS,
7026 .v.pins = (const struct alc_pincfg[]) {
7027 { 0x14, 0x99130110 }, /* speaker */
7028 { 0x18, 0x01a19c20 }, /* mic */
7029 { 0x19, 0x99a3092f }, /* int-mic */
7030 { 0x21, 0x0121401f }, /* HP out */
7031 { }
7032 },
7033 .chained = true,
7034 .chain_id = ALC662_FIXUP_SKU_IGNORE
7035 },
7036 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007037 .type = ALC_FIXUP_PINS,
7038 .v.pins = (const struct alc_pincfg[]) {
7039 { 0x14, 0x99130110 }, /* speaker */
7040 { 0x18, 0x01a19820 }, /* mic */
7041 { 0x19, 0x99a3092f }, /* int-mic */
7042 { 0x1b, 0x0121401f }, /* HP out */
7043 { }
7044 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007045 .chained = true,
7046 .chain_id = ALC662_FIXUP_SKU_IGNORE
7047 },
7048 [ALC662_FIXUP_ASUS_MODE3] = {
7049 .type = ALC_FIXUP_PINS,
7050 .v.pins = (const struct alc_pincfg[]) {
7051 { 0x14, 0x99130110 }, /* speaker */
7052 { 0x15, 0x0121441f }, /* HP */
7053 { 0x18, 0x01a19840 }, /* mic */
7054 { 0x19, 0x99a3094f }, /* int-mic */
7055 { 0x21, 0x01211420 }, /* HP2 */
7056 { }
7057 },
7058 .chained = true,
7059 .chain_id = ALC662_FIXUP_SKU_IGNORE
7060 },
7061 [ALC662_FIXUP_ASUS_MODE4] = {
7062 .type = ALC_FIXUP_PINS,
7063 .v.pins = (const struct alc_pincfg[]) {
7064 { 0x14, 0x99130110 }, /* speaker */
7065 { 0x16, 0x99130111 }, /* speaker */
7066 { 0x18, 0x01a19840 }, /* mic */
7067 { 0x19, 0x99a3094f }, /* int-mic */
7068 { 0x21, 0x0121441f }, /* HP */
7069 { }
7070 },
7071 .chained = true,
7072 .chain_id = ALC662_FIXUP_SKU_IGNORE
7073 },
7074 [ALC662_FIXUP_ASUS_MODE5] = {
7075 .type = ALC_FIXUP_PINS,
7076 .v.pins = (const struct alc_pincfg[]) {
7077 { 0x14, 0x99130110 }, /* speaker */
7078 { 0x15, 0x0121441f }, /* HP */
7079 { 0x16, 0x99130111 }, /* speaker */
7080 { 0x18, 0x01a19840 }, /* mic */
7081 { 0x19, 0x99a3094f }, /* int-mic */
7082 { }
7083 },
7084 .chained = true,
7085 .chain_id = ALC662_FIXUP_SKU_IGNORE
7086 },
7087 [ALC662_FIXUP_ASUS_MODE6] = {
7088 .type = ALC_FIXUP_PINS,
7089 .v.pins = (const struct alc_pincfg[]) {
7090 { 0x14, 0x99130110 }, /* speaker */
7091 { 0x15, 0x01211420 }, /* HP2 */
7092 { 0x18, 0x01a19840 }, /* mic */
7093 { 0x19, 0x99a3094f }, /* int-mic */
7094 { 0x1b, 0x0121441f }, /* HP */
7095 { }
7096 },
7097 .chained = true,
7098 .chain_id = ALC662_FIXUP_SKU_IGNORE
7099 },
7100 [ALC662_FIXUP_ASUS_MODE7] = {
7101 .type = ALC_FIXUP_PINS,
7102 .v.pins = (const struct alc_pincfg[]) {
7103 { 0x14, 0x99130110 }, /* speaker */
7104 { 0x17, 0x99130111 }, /* speaker */
7105 { 0x18, 0x01a19840 }, /* mic */
7106 { 0x19, 0x99a3094f }, /* int-mic */
7107 { 0x1b, 0x01214020 }, /* HP */
7108 { 0x21, 0x0121401f }, /* HP */
7109 { }
7110 },
7111 .chained = true,
7112 .chain_id = ALC662_FIXUP_SKU_IGNORE
7113 },
7114 [ALC662_FIXUP_ASUS_MODE8] = {
7115 .type = ALC_FIXUP_PINS,
7116 .v.pins = (const struct alc_pincfg[]) {
7117 { 0x14, 0x99130110 }, /* speaker */
7118 { 0x12, 0x99a30970 }, /* int-mic */
7119 { 0x15, 0x01214020 }, /* HP */
7120 { 0x17, 0x99130111 }, /* speaker */
7121 { 0x18, 0x01a19840 }, /* mic */
7122 { 0x21, 0x0121401f }, /* HP */
7123 { }
7124 },
7125 .chained = true,
7126 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007127 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007128 [ALC662_FIXUP_NO_JACK_DETECT] = {
7129 .type = ALC_FIXUP_FUNC,
7130 .v.func = alc_fixup_no_jack_detect,
7131 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007132 [ALC662_FIXUP_ZOTAC_Z68] = {
7133 .type = ALC_FIXUP_PINS,
7134 .v.pins = (const struct alc_pincfg[]) {
7135 { 0x1b, 0x02214020 }, /* Front HP */
7136 { }
7137 }
7138 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007139 [ALC662_FIXUP_INV_DMIC] = {
7140 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007141 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007142 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007143};
7144
Takashi Iwaia9111322011-05-02 11:30:18 +02007145static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007146 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007147 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007148 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007149 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007150 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007151 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007152 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007153 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007154 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007155 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007156 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007157 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007158 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007159
7160#if 0
7161 /* Below is a quirk table taken from the old code.
7162 * Basically the device should work as is without the fixup table.
7163 * If BIOS doesn't give a proper info, enable the corresponding
7164 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007165 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007166 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7167 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7168 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7169 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7170 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7171 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7172 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7173 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7174 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7175 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7176 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7177 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7178 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7179 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7180 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7181 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7182 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7183 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7184 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7185 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7186 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7187 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7188 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7189 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7190 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7191 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7192 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7193 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7194 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7195 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7196 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7197 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7198 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7199 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7200 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7201 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7202 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7203 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7204 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7205 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7206 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7207 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7208 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7209 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7210 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7211 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7212 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7213 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7214 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7215 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7216#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007217 {}
7218};
7219
Todd Broch6be79482010-12-07 16:51:05 -08007220static const struct alc_model_fixup alc662_fixup_models[] = {
7221 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007222 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7223 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7224 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7225 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7226 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7227 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7228 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7229 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007230 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007231 {}
7232};
David Henningsson6cb3b702010-09-09 08:51:44 +02007233
Kailang Yang8663ff72012-06-29 09:35:52 +02007234static void alc662_fill_coef(struct hda_codec *codec)
7235{
7236 int val, coef;
7237
7238 coef = alc_get_coef0(codec);
7239
7240 switch (codec->vendor_id) {
7241 case 0x10ec0662:
7242 if ((coef & 0x00f0) == 0x0030) {
7243 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7244 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7245 }
7246 break;
7247 case 0x10ec0272:
7248 case 0x10ec0273:
7249 case 0x10ec0663:
7250 case 0x10ec0665:
7251 case 0x10ec0670:
7252 case 0x10ec0671:
7253 case 0x10ec0672:
7254 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7255 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7256 break;
7257 }
7258}
David Henningsson6cb3b702010-09-09 08:51:44 +02007259
Takashi Iwai1d045db2011-07-07 18:23:21 +02007260/*
7261 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007262static int patch_alc662(struct hda_codec *codec)
7263{
7264 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007265 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007266
Takashi Iwai3de95172012-05-07 18:03:15 +02007267 err = alc_alloc_spec(codec, 0x0b);
7268 if (err < 0)
7269 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007270
Takashi Iwai3de95172012-05-07 18:03:15 +02007271 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007272
Takashi Iwai53c334a2011-08-23 18:27:14 +02007273 /* handle multiple HPs as is */
7274 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7275
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007276 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7277
Kailang Yang8663ff72012-06-29 09:35:52 +02007278 spec->init_hook = alc662_fill_coef;
7279 alc662_fill_coef(codec);
7280
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007281 alc_pick_fixup(codec, alc662_fixup_models,
7282 alc662_fixup_tbl, alc662_fixups);
7283 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7284
7285 alc_auto_parse_customize_define(codec);
7286
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007287 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007288 codec->bus->pci->subsystem_vendor == 0x1025 &&
7289 spec->cdefine.platform_type == 1) {
7290 if (alc_codec_rename(codec, "ALC272X") < 0)
7291 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007292 }
Kailang Yang274693f2009-12-03 10:07:50 +01007293
Takashi Iwaib9c51062011-08-24 18:08:07 +02007294 /* automatic parse from the BIOS config */
7295 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007296 if (err < 0)
7297 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007298
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007299 if (!spec->no_analog && has_cdefine_beep(codec)) {
7300 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007301 if (err < 0)
7302 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007303 switch (codec->vendor_id) {
7304 case 0x10ec0662:
7305 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7306 break;
7307 case 0x10ec0272:
7308 case 0x10ec0663:
7309 case 0x10ec0665:
7310 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7311 break;
7312 case 0x10ec0273:
7313 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7314 break;
7315 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007316 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007317
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007318 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007319 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007320
Takashi Iwai589876e2012-02-20 15:47:55 +01007321 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7322
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007323 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007324
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007325 error:
7326 alc_free(codec);
7327 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007328}
7329
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007330/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007331 * ALC680 support
7332 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007333
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007334static int alc680_parse_auto_config(struct hda_codec *codec)
7335{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007336 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007337}
7338
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007339/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007340 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007341static int patch_alc680(struct hda_codec *codec)
7342{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007343 int err;
7344
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007345 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007346 err = alc_alloc_spec(codec, 0);
7347 if (err < 0)
7348 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007349
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007350 /* automatic parse from the BIOS config */
7351 err = alc680_parse_auto_config(codec);
7352 if (err < 0) {
7353 alc_free(codec);
7354 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007355 }
7356
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007357 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007358
7359 return 0;
7360}
7361
7362/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007363 * patch entries
7364 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007365static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007366 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007367 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007368 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007369 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007370 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007371 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007372 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007373 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007374 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007375 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007376 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007377 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007378 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007379 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007380 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007381 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007382 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007383 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007384 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7385 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7386 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007387 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007388 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007389 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7390 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007391 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7392 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007393 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007394 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007395 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007396 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007397 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007398 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007399 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007400 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007401 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007402 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007403 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007404 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007405 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007406 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007407 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007408 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007409 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007410 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007411 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007412 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007413 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007414 {} /* terminator */
7415};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007416
7417MODULE_ALIAS("snd-hda-codec-id:10ec*");
7418
7419MODULE_LICENSE("GPL");
7420MODULE_DESCRIPTION("Realtek HD-audio codec");
7421
7422static struct hda_codec_preset_list realtek_list = {
7423 .preset = snd_hda_preset_realtek,
7424 .owner = THIS_MODULE,
7425};
7426
7427static int __init patch_realtek_init(void)
7428{
7429 return snd_hda_add_codec_preset(&realtek_list);
7430}
7431
7432static void __exit patch_realtek_exit(void)
7433{
7434 snd_hda_delete_codec_preset(&realtek_list);
7435}
7436
7437module_init(patch_realtek_init)
7438module_exit(patch_realtek_exit)