blob: 567d93f6c69837b488dd2a542c93ae8d94bc1387 [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 Iwai23d30f22012-05-07 17:17:32 +020076/* make compatible with old code */
77#define alc_apply_pincfgs snd_hda_apply_pincfgs
78#define alc_apply_fixup snd_hda_apply_fixup
79#define alc_pick_fixup snd_hda_pick_fixup
80#define alc_fixup hda_fixup
81#define alc_pincfg hda_pintbl
82#define alc_model_fixup hda_model_fixup
83
84#define ALC_FIXUP_PINS HDA_FIXUP_PINS
85#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
86#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
87
88#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
89#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
90#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
91#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
92
93
Takashi Iwai30dcd3b2012-12-06 15:45:38 +010094#define MAX_NID_PATH_DEPTH 5
95
Takashi Iwai8dd48672012-12-14 18:19:04 +010096enum {
97 NID_PATH_VOL_CTL,
98 NID_PATH_MUTE_CTL,
99 NID_PATH_BOOST_CTL,
100 NID_PATH_NUM_CTLS
101};
102
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100103/* Widget connection path
104 *
105 * For output, stored in the order of DAC -> ... -> pin,
106 * for input, pin -> ... -> ADC.
107 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100108 * idx[i] contains the source index number to select on of the widget path[i];
109 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100110 * multi[] indicates whether it's a selector widget with multi-connectors
111 * (i.e. the connection selection is mandatory)
112 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
113 */
114struct nid_path {
115 int depth;
116 hda_nid_t path[MAX_NID_PATH_DEPTH];
117 unsigned char idx[MAX_NID_PATH_DEPTH];
118 unsigned char multi[MAX_NID_PATH_DEPTH];
Takashi Iwai8dd48672012-12-14 18:19:04 +0100119 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
Takashi Iwai130e5f02012-12-14 16:09:29 +0100120 bool active;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100121};
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123struct alc_spec {
124 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200125 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 unsigned int num_mixers;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100127 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200129 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200130 const struct hda_pcm_stream *stream_analog_playback;
131 const struct hda_pcm_stream *stream_analog_capture;
132 const struct hda_pcm_stream *stream_analog_alt_playback;
133 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200135 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200136 const struct hda_pcm_stream *stream_digital_playback;
137 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200140 struct hda_multi_out multiout; /* playback set-up
141 * max_channels, dacs must be set
142 * dig_out_nid and hp_nid are optional
143 */
Takashi Iwai63300792008-01-24 15:31:36 +0100144 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100145 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100146 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* capture */
149 unsigned int num_adc_nids;
Takashi Iwai27d31532012-12-18 08:57:05 +0100150 hda_nid_t adc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai16ded522005-06-10 19:58:24 +0200151 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200152 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Takashi Iwai840b64c2010-07-13 22:49:01 +0200154 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200155 hda_nid_t cur_adc;
156 unsigned int cur_adc_stream_tag;
157 unsigned int cur_adc_format;
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 /* capture source */
Takashi Iwai27d31532012-12-18 08:57:05 +0100160 struct hda_input_mux input_mux;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200162 hda_nid_t ext_mic_pin;
163 hda_nid_t dock_mic_pin;
164 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100167 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 int num_channel_mode;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100169 int const_channel_count; /* min. channel count (for speakers) */
170 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100173 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200174
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200175 /* dynamic controls, init_verbs and input_mux */
176 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100177 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200178 struct snd_array kctls;
Takashi Iwai41923e42007-10-22 17:20:10 +0200179 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200180 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
181 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
182 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200183 hda_nid_t inv_dmic_pin;
Takashi Iwai37c04202012-12-18 14:22:45 +0100184 hda_nid_t shared_mic_vref_pin;
Takashi Iwai81fede892012-12-18 17:24:25 +0100185 int inv_dmic_split_idx; /* used internally for inv_dmic_split */
Takashi Iwai834be882006-03-01 14:16:17 +0100186
Takashi Iwai463419d2012-12-05 14:17:37 +0100187 /* DAC list */
188 int num_all_dacs;
189 hda_nid_t all_dacs[16];
190
Takashi Iwaic9967f12012-12-14 16:39:22 +0100191 /* path list */
192 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100193
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100194 /* hooks */
195 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200196#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500197 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100198#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200199 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200200 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100201
Takashi Iwai834be882006-03-01 14:16:17 +0100202 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200203 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200204 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200205 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200206 unsigned int auto_mic:1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200207 unsigned int automute_speaker:1; /* automute speaker outputs */
208 unsigned int automute_lo:1; /* automute LO outputs */
209 unsigned int detect_hp:1; /* Headphone detection enabled */
210 unsigned int detect_lo:1; /* Line-out detection enabled */
211 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
212 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100213 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200214
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100215 /* other flags */
Takashi Iwai20c18f52012-12-18 14:33:21 +0100216 unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100217 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200218 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai24de1832011-11-07 17:13:39 +0100219 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200220 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
221 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200222 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwai9bf387b2012-12-18 17:18:21 +0100223 unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */
Takashi Iwai81fede892012-12-18 17:24:25 +0100224 unsigned int inv_dmic_split:1; /* inverted dmic w/a for conexant */
Takashi Iwaid922b512011-04-28 12:18:53 +0200225
Takashi Iwai20c18f52012-12-18 14:33:21 +0100226 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwaid922b512011-04-28 12:18:53 +0200227
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200228 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200229 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100230
Takashi Iwai2134ea42008-01-10 16:53:55 +0100231 /* for virtual master */
232 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100233 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200234#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200235 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100236 int num_loopbacks;
237 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200238#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200239
240 /* for PLL fix */
241 hda_nid_t pll_nid;
242 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200243 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100244
Takashi Iwaice764ab2011-04-27 16:35:23 +0200245 /* multi-io */
246 int multi_ios;
247 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200248
249 /* bind volumes */
250 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100251};
252
Takashi Iwai44c02402011-07-08 15:14:19 +0200253static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
254 int dir, unsigned int bits)
255{
256 if (!nid)
257 return false;
258 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
259 if (query_amp_caps(codec, nid, dir) & bits)
260 return true;
261 return false;
262}
263
264#define nid_has_mute(codec, nid, dir) \
265 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
266#define nid_has_volume(codec, nid, dir) \
267 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
268
Takashi Iwai666a70d2012-12-17 20:29:29 +0100269static struct nid_path *
270get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid);
271static void activate_path(struct hda_codec *codec, struct nid_path *path,
272 bool enable, bool add_aamix);
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274/*
275 * input MUX handling
276 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200277static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
278 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
280 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
281 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +0100282 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200285static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
289 struct alc_spec *spec = codec->spec;
290 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
291
292 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
293 return 0;
294}
295
Takashi Iwai666a70d2012-12-17 20:29:29 +0100296static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
297{
298 struct alc_spec *spec = codec->spec;
299 if (spec->dyn_adc_switch)
300 adc_idx = spec->dyn_adc_idx[imux_idx];
301 return spec->adc_nids[adc_idx];
302}
303
Takashi Iwai21268962011-07-07 15:01:13 +0200304static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Takashi Iwai21268962011-07-07 15:01:13 +0200306 struct alc_spec *spec = codec->spec;
307 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
308
309 if (spec->cur_adc && spec->cur_adc != new_adc) {
310 /* stream is running, let's swap the current ADC */
311 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
312 spec->cur_adc = new_adc;
313 snd_hda_codec_setup_stream(codec, new_adc,
314 spec->cur_adc_stream_tag, 0,
315 spec->cur_adc_format);
316 return true;
317 }
318 return false;
319}
320
Takashi Iwai24de1832011-11-07 17:13:39 +0100321static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200322static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100323static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx);
Takashi Iwai24de1832011-11-07 17:13:39 +0100324
David Henningsson00227f12012-06-27 18:45:44 +0200325/* for shared I/O, change the pin-control accordingly */
326static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
327{
328 struct alc_spec *spec = codec->spec;
329 unsigned int val;
330 hda_nid_t pin = spec->autocfg.inputs[1].pin;
331 /* NOTE: this assumes that there are only two inputs, the
332 * first is the real internal mic and the second is HP/mic jack.
333 */
334
335 val = snd_hda_get_default_vref(codec, pin);
336
337 /* This pin does not have vref caps - let's enable vref on pin 0x18
338 instead, as suggested by Realtek */
Takashi Iwai37c04202012-12-18 14:22:45 +0100339 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
340 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
341 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
342 if (vref_val != AC_PINCTL_VREF_HIZ)
343 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
David Henningsson00227f12012-06-27 18:45:44 +0200344 }
345
346 val = set_as_mic ? val | PIN_IN : PIN_HP;
347 snd_hda_set_pin_ctl(codec, pin, val);
348
349 spec->automute_speaker = !set_as_mic;
350 call_update_outputs(codec);
351}
Takashi Iwai21268962011-07-07 15:01:13 +0200352
353/* select the given imux item; either unmute exclusively or select the route */
354static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
355 unsigned int idx, bool force)
356{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100358 const struct hda_input_mux *imux;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100359 struct nid_path *path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Takashi Iwai27d31532012-12-18 08:57:05 +0100361 imux = &spec->input_mux;
362 if (!imux->num_items)
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100363 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100364
Takashi Iwai21268962011-07-07 15:01:13 +0200365 if (idx >= imux->num_items)
366 idx = imux->num_items - 1;
367 if (spec->cur_mux[adc_idx] == idx && !force)
368 return 0;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100369
370 path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]],
371 spec->adc_nids[adc_idx]);
372 if (!path)
373 return 0;
374 if (path->active)
375 activate_path(codec, path, false, false);
376
Takashi Iwai21268962011-07-07 15:01:13 +0200377 spec->cur_mux[adc_idx] = idx;
378
David Henningsson00227f12012-06-27 18:45:44 +0200379 if (spec->shared_mic_hp)
380 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100381
Takashi Iwai666a70d2012-12-17 20:29:29 +0100382 if (spec->dyn_adc_switch)
Takashi Iwai21268962011-07-07 15:01:13 +0200383 alc_dyn_adc_pcm_resetup(codec, idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200384
Takashi Iwai666a70d2012-12-17 20:29:29 +0100385 path = get_nid_path(codec, spec->imux_pins[idx],
386 get_adc_nid(codec, adc_idx, idx));
387 if (!path)
388 return 0;
389 if (path->active)
390 return 0;
391 activate_path(codec, path, true, false);
Takashi Iwai125821a2012-06-22 14:30:29 +0200392 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200393 return 1;
394}
395
396static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
397 struct snd_ctl_elem_value *ucontrol)
398{
399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
400 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
401 return alc_mux_select(codec, adc_idx,
402 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100403}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100406 * set up the input pin config (depending on the given auto-pin type)
407 */
408static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
409 int auto_pin_type)
410{
411 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200412 if (auto_pin_type == AUTO_PIN_MIC)
413 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200414 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100415}
416
417/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200418 * Append the given mixer and verb elements for the later use
419 * The mixer array is referred in build_controls(), and init_verbs are
420 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100421 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200422static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100423{
424 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
425 return;
426 spec->mixers[spec->num_mixers++] = mix;
427}
428
Takashi Iwaid88897e2008-10-31 15:01:37 +0100429/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200430 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100431 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200432/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200433static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200434 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
435 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
436 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
437 { }
438};
439
Takashi Iwaia9111322011-05-02 11:30:18 +0200440static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200441 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
442 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
443 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
444 { }
445};
446
Takashi Iwaia9111322011-05-02 11:30:18 +0200447static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200448 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
449 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
450 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
451 { }
452};
453
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200454/*
455 * Fix hardware PLL issue
456 * On some codecs, the analog PLL gating control must be off while
457 * the default value is 1.
458 */
459static void alc_fix_pll(struct hda_codec *codec)
460{
461 struct alc_spec *spec = codec->spec;
462 unsigned int val;
463
464 if (!spec->pll_nid)
465 return;
466 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
467 spec->pll_coef_idx);
468 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
469 AC_VERB_GET_PROC_COEF, 0);
470 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
471 spec->pll_coef_idx);
472 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
473 val & ~(1 << spec->pll_coef_bit));
474}
475
476static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
477 unsigned int coef_idx, unsigned int coef_bit)
478{
479 struct alc_spec *spec = codec->spec;
480 spec->pll_nid = nid;
481 spec->pll_coef_idx = coef_idx;
482 spec->pll_coef_bit = coef_bit;
483 alc_fix_pll(codec);
484}
485
Takashi Iwai1d045db2011-07-07 18:23:21 +0200486/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200487 * Jack detections for HP auto-mute and mic-switch
488 */
489
490/* check each pin in the given array; returns true if any of them is plugged */
491static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200492{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200493 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200494
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495 for (i = 0; i < num_pins; i++) {
496 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200497 if (!nid)
498 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200499 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200500 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 return present;
502}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200503
Takashi Iwai1d045db2011-07-07 18:23:21 +0200504/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200505static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200506 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507{
508 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200509 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200510 int i;
511
512 for (i = 0; i < num_pins; i++) {
513 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100514 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200515 if (!nid)
516 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100517 /* don't reset VREF value in case it's controlling
518 * the amp (see alc861_fixup_asus_amp_vref_0f())
519 */
520 if (spec->keep_vref_in_automute) {
521 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100522 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100523 val &= ~PIN_HP;
524 } else
525 val = 0;
526 val |= pin_bits;
527 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200528 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200529}
530
David Henningsson42cf0d02011-09-20 12:04:56 +0200531/* Toggle outputs muting */
532static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200533{
534 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200535 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200536
Takashi Iwaic0a20262011-06-10 15:28:15 +0200537 /* Control HP pins/amps depending on master_mute state;
538 * in general, HP pins/amps control should be enabled in all cases,
539 * but currently set only for master_mute, just to be safe
540 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100541 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
542 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200543 spec->autocfg.hp_pins, spec->master_mute, true);
544
David Henningsson42cf0d02011-09-20 12:04:56 +0200545 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200546 on = 0;
547 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200548 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200549 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200550 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200551 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200552
553 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200554 /* if LO is a copy of either HP or Speaker, don't need to handle it */
555 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
556 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200557 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200558 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200559 on = 0;
560 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200561 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200562 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200563 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200564 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200565}
566
David Henningsson42cf0d02011-09-20 12:04:56 +0200567static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200568{
569 struct alc_spec *spec = codec->spec;
570 if (spec->automute_hook)
571 spec->automute_hook(codec);
572 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200573 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200574}
575
Takashi Iwai1d045db2011-07-07 18:23:21 +0200576/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200577static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200578{
579 struct alc_spec *spec = codec->spec;
580
David Henningsson42cf0d02011-09-20 12:04:56 +0200581 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
583 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200584 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200585 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200586 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200587}
588
Takashi Iwai1d045db2011-07-07 18:23:21 +0200589/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200590static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591{
592 struct alc_spec *spec = codec->spec;
593
David Henningssonf7f4b2322012-10-10 16:32:09 +0200594 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
595 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200596 /* check LO jack only when it's different from HP */
597 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
598 return;
599
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200600 spec->line_jack_present =
601 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
602 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200603 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200604 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200605 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200606}
607
Takashi Iwai1d045db2011-07-07 18:23:21 +0200608/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200609static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200610{
611 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200612 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200613
Takashi Iwai480967d2012-12-18 14:29:52 +0100614 if (!spec->auto_mic)
Takashi Iwai6c819492009-08-10 18:47:44 +0200615 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200616 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200617 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200618
Takashi Iwai21268962011-07-07 15:01:13 +0200619 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
620 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
621 else if (spec->dock_mic_idx >= 0 &&
622 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
623 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
624 else
625 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200626}
627
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100628/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200629static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100630{
631 unsigned int val;
632 struct snd_kcontrol *kctl;
633 struct snd_ctl_elem_value *uctl;
634
635 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
636 if (!kctl)
637 return;
638 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
639 if (!uctl)
640 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200641 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100642 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
643 val &= HDA_AMP_VOLMASK;
644 uctl->value.integer.value[0] = val;
645 uctl->value.integer.value[1] = val;
646 kctl->put(kctl, uctl);
647 kfree(uctl);
648}
649
David Henningsson29adc4b2012-09-25 11:31:00 +0200650static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100651{
David Henningsson29adc4b2012-09-25 11:31:00 +0200652 /* For some reason, the res given from ALC880 is broken.
653 Here we adjust it properly. */
654 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100655}
656
Kailang Yangf9423e72008-05-27 12:32:25 +0200657/* additional initialization for ALC888 variants */
658static void alc888_coef_init(struct hda_codec *codec)
659{
660 unsigned int tmp;
661
662 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
663 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
664 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100665 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200666 /* alc888S-VC */
667 snd_hda_codec_read(codec, 0x20, 0,
668 AC_VERB_SET_PROC_COEF, 0x830);
669 else
670 /* alc888-VB */
671 snd_hda_codec_read(codec, 0x20, 0,
672 AC_VERB_SET_PROC_COEF, 0x3030);
673}
674
Takashi Iwai1d045db2011-07-07 18:23:21 +0200675/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200676static void alc889_coef_init(struct hda_codec *codec)
677{
678 unsigned int tmp;
679
680 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
681 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
682 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
683 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
684}
685
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100686/* turn on/off EAPD control (only if available) */
687static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
688{
689 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
690 return;
691 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
692 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
693 on ? 2 : 0);
694}
695
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200696/* turn on/off EAPD controls of the codec */
697static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
698{
699 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200700 static hda_nid_t pins[] = {
701 0x0f, 0x10, 0x14, 0x15, 0
702 };
703 hda_nid_t *p;
704 for (p = pins; *p; p++)
705 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200706}
707
Takashi Iwai1c7161532011-04-07 10:37:16 +0200708/* generic shutup callback;
709 * just turning off EPAD and a little pause for avoiding pop-noise
710 */
711static void alc_eapd_shutup(struct hda_codec *codec)
712{
713 alc_auto_setup_eapd(codec, false);
714 msleep(200);
715}
716
Takashi Iwai1d045db2011-07-07 18:23:21 +0200717/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200718static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200719{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200720 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200721
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200722 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200723 switch (type) {
724 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200725 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
726 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200727 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200728 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
729 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200730 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200731 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
732 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200733 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200734 switch (codec->vendor_id) {
735 case 0x10ec0260:
736 snd_hda_codec_write(codec, 0x1a, 0,
737 AC_VERB_SET_COEF_INDEX, 7);
738 tmp = snd_hda_codec_read(codec, 0x1a, 0,
739 AC_VERB_GET_PROC_COEF, 0);
740 snd_hda_codec_write(codec, 0x1a, 0,
741 AC_VERB_SET_COEF_INDEX, 7);
742 snd_hda_codec_write(codec, 0x1a, 0,
743 AC_VERB_SET_PROC_COEF,
744 tmp | 0x2010);
745 break;
746 case 0x10ec0262:
747 case 0x10ec0880:
748 case 0x10ec0882:
749 case 0x10ec0883:
750 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100751 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100752 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200753 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200754 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200755 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200756 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200757 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100758#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200759 case 0x10ec0267:
760 case 0x10ec0268:
761 snd_hda_codec_write(codec, 0x20, 0,
762 AC_VERB_SET_COEF_INDEX, 7);
763 tmp = snd_hda_codec_read(codec, 0x20, 0,
764 AC_VERB_GET_PROC_COEF, 0);
765 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200766 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200767 snd_hda_codec_write(codec, 0x20, 0,
768 AC_VERB_SET_PROC_COEF,
769 tmp | 0x3000);
770 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100771#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200772 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200773 break;
774 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200775}
Kailang Yangea1fb292008-08-26 12:58:38 +0200776
Takashi Iwai1d045db2011-07-07 18:23:21 +0200777/*
778 * Auto-Mute mode mixer enum support
779 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200780static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
781 struct snd_ctl_elem_info *uinfo)
782{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200783 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
784 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200785 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100786 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200787 };
788
Takashi Iwaidda415d2012-11-30 18:34:38 +0100789 if (spec->automute_speaker_possible && spec->automute_lo_possible)
790 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
791 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200792}
793
794static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_value *ucontrol)
796{
797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200799 unsigned int val = 0;
800 if (spec->automute_speaker)
801 val++;
802 if (spec->automute_lo)
803 val++;
804
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200805 ucontrol->value.enumerated.item[0] = val;
806 return 0;
807}
808
809static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
810 struct snd_ctl_elem_value *ucontrol)
811{
812 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
813 struct alc_spec *spec = codec->spec;
814
815 switch (ucontrol->value.enumerated.item[0]) {
816 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200817 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200818 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200819 spec->automute_speaker = 0;
820 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200821 break;
822 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200823 if (spec->automute_speaker_possible) {
824 if (!spec->automute_lo && spec->automute_speaker)
825 return 0;
826 spec->automute_speaker = 1;
827 spec->automute_lo = 0;
828 } else if (spec->automute_lo_possible) {
829 if (spec->automute_lo)
830 return 0;
831 spec->automute_lo = 1;
832 } else
833 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200834 break;
835 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200836 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200837 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200838 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200839 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200840 spec->automute_speaker = 1;
841 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200842 break;
843 default:
844 return -EINVAL;
845 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200846 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200847 return 1;
848}
849
Takashi Iwaia9111322011-05-02 11:30:18 +0200850static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200851 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
852 .name = "Auto-Mute Mode",
853 .info = alc_automute_mode_info,
854 .get = alc_automute_mode_get,
855 .put = alc_automute_mode_put,
856};
857
Takashi Iwai668d1e92012-11-29 14:10:17 +0100858static struct snd_kcontrol_new *
859alc_kcontrol_new(struct alc_spec *spec, const char *name,
860 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200861{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100862 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
863 if (!knew)
864 return NULL;
865 *knew = *temp;
Takashi Iwaibc549762012-12-18 15:35:11 +0100866 if (name)
867 knew->name = kstrdup(name, GFP_KERNEL);
868 else if (knew->name)
869 knew->name = kstrdup(knew->name, GFP_KERNEL);
Takashi Iwai668d1e92012-11-29 14:10:17 +0100870 if (!knew->name)
871 return NULL;
872 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200873}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200874
875static int alc_add_automute_mode_enum(struct hda_codec *codec)
876{
877 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200878
Takashi Iwaibc549762012-12-18 15:35:11 +0100879 if (!alc_kcontrol_new(spec, NULL, &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 return -ENOMEM;
881 return 0;
882}
883
Takashi Iwai1d045db2011-07-07 18:23:21 +0200884/*
885 * Check the availability of HP/line-out auto-mute;
886 * Set up appropriately if really supported
887 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100888static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200889{
890 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200891 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200892 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100893 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200894
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200895 if (cfg->hp_pins[0])
896 present++;
897 if (cfg->line_out_pins[0])
898 present++;
899 if (cfg->speaker_pins[0])
900 present++;
901 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100902 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200903
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200904 if (!cfg->speaker_pins[0] &&
905 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200906 memcpy(cfg->speaker_pins, cfg->line_out_pins,
907 sizeof(cfg->speaker_pins));
908 cfg->speaker_outs = cfg->line_outs;
909 }
910
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200911 if (!cfg->hp_pins[0] &&
912 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200913 memcpy(cfg->hp_pins, cfg->line_out_pins,
914 sizeof(cfg->hp_pins));
915 cfg->hp_outs = cfg->line_outs;
916 }
917
918 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200919 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200920 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200921 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200922 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200923 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200924 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
925 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200926 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200927 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200928
David Henningsson42cf0d02011-09-20 12:04:56 +0200929 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
930 if (cfg->speaker_outs)
931 for (i = 0; i < cfg->line_outs; i++) {
932 hda_nid_t nid = cfg->line_out_pins[i];
933 if (!is_jack_detectable(codec, nid))
934 continue;
935 snd_printdd("realtek: Enable Line-Out "
936 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200937 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
938 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200939 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200940 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200941 spec->automute_lo_possible = spec->detect_hp;
942 }
943
944 spec->automute_speaker_possible = cfg->speaker_outs &&
945 (spec->detect_hp || spec->detect_lo);
946
947 spec->automute_lo = spec->automute_lo_possible;
948 spec->automute_speaker = spec->automute_speaker_possible;
949
Takashi Iwai475c3d22012-11-30 08:31:30 +0100950 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200951 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100952 err = alc_add_automute_mode_enum(codec);
953 if (err < 0)
954 return err;
955 }
956 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200957}
958
Takashi Iwai1d045db2011-07-07 18:23:21 +0200959/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200960static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
961{
962 int i;
963 for (i = 0; i < nums; i++)
964 if (list[i] == nid)
965 return i;
966 return -1;
967}
968
Takashi Iwai21268962011-07-07 15:01:13 +0200969/* check whether all auto-mic pins are valid; setup indices if OK */
970static bool alc_auto_mic_check_imux(struct hda_codec *codec)
971{
972 struct alc_spec *spec = codec->spec;
973 const struct hda_input_mux *imux;
974
Takashi Iwai27d31532012-12-18 08:57:05 +0100975 imux = &spec->input_mux;
Takashi Iwai21268962011-07-07 15:01:13 +0200976 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
977 spec->imux_pins, imux->num_items);
978 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
979 spec->imux_pins, imux->num_items);
980 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
981 spec->imux_pins, imux->num_items);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100982 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0)
Takashi Iwai21268962011-07-07 15:01:13 +0200983 return false; /* no corresponding imux */
Takashi Iwai21268962011-07-07 15:01:13 +0200984
David Henningsson29adc4b2012-09-25 11:31:00 +0200985 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
986 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200987 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +0200988 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
989 ALC_MIC_EVENT,
990 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200991 return true;
992}
993
Takashi Iwai1d045db2011-07-07 18:23:21 +0200994/*
995 * Check the availability of auto-mic switch;
996 * Set up if really supported
997 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100998static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +0200999{
1000 struct alc_spec *spec = codec->spec;
1001 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001002 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001003 int i;
1004
Takashi Iwai21268962011-07-07 15:01:13 +02001005 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1006
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001007 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001008 for (i = 0; i < cfg->num_inputs; i++) {
1009 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001010 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001011 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001012 switch (snd_hda_get_input_pin_attr(defcfg)) {
1013 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001014 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001015 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001016 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001017 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001018 fixed = nid;
1019 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001020 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001021 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001022 case INPUT_PIN_ATTR_DOCK:
1023 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001024 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001025 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001026 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001027 dock = nid;
1028 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001029 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001030 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001031 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001032 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001033 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001034 ext = nid;
1035 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001036 }
1037 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001038 if (!ext && dock) {
1039 ext = dock;
1040 dock = 0;
1041 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001042 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001043 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001044 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001045 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001046 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001047 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001048
1049 /* check imux indices */
1050 spec->ext_mic_pin = ext;
1051 spec->int_mic_pin = fixed;
1052 spec->dock_mic_pin = dock;
1053
Takashi Iwai21268962011-07-07 15:01:13 +02001054 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001055 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001056
Takashi Iwai666a70d2012-12-17 20:29:29 +01001057 spec->auto_mic = 1;
1058 spec->num_adc_nids = 1;
1059 spec->cur_mux[0] = spec->int_mic_idx;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001060 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1061 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001062
1063 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001064}
1065
Takashi Iwai1d045db2011-07-07 18:23:21 +02001066/*
1067 * Realtek SSID verification
1068 */
1069
David Henningsson90622912010-10-14 14:50:18 +02001070/* Could be any non-zero and even value. When used as fixup, tells
1071 * the driver to ignore any present sku defines.
1072 */
1073#define ALC_FIXUP_SKU_IGNORE (2)
1074
Takashi Iwai23d30f22012-05-07 17:17:32 +02001075static void alc_fixup_sku_ignore(struct hda_codec *codec,
1076 const struct hda_fixup *fix, int action)
1077{
1078 struct alc_spec *spec = codec->spec;
1079 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1080 spec->cdefine.fixup = 1;
1081 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1082 }
1083}
1084
Kailang Yangda00c242010-03-19 11:23:45 +01001085static int alc_auto_parse_customize_define(struct hda_codec *codec)
1086{
1087 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001088 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001089 struct alc_spec *spec = codec->spec;
1090
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001091 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1092
David Henningsson90622912010-10-14 14:50:18 +02001093 if (spec->cdefine.fixup) {
1094 ass = spec->cdefine.sku_cfg;
1095 if (ass == ALC_FIXUP_SKU_IGNORE)
1096 return -1;
1097 goto do_sku;
1098 }
1099
Kailang Yangda00c242010-03-19 11:23:45 +01001100 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001101 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001102 goto do_sku;
1103
1104 nid = 0x1d;
1105 if (codec->vendor_id == 0x10ec0260)
1106 nid = 0x17;
1107 ass = snd_hda_codec_get_pincfg(codec, nid);
1108
1109 if (!(ass & 1)) {
1110 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1111 codec->chip_name, ass);
1112 return -1;
1113 }
1114
1115 /* check sum */
1116 tmp = 0;
1117 for (i = 1; i < 16; i++) {
1118 if ((ass >> i) & 1)
1119 tmp++;
1120 }
1121 if (((ass >> 16) & 0xf) != tmp)
1122 return -1;
1123
1124 spec->cdefine.port_connectivity = ass >> 30;
1125 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1126 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1127 spec->cdefine.customization = ass >> 8;
1128do_sku:
1129 spec->cdefine.sku_cfg = ass;
1130 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1131 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1132 spec->cdefine.swap = (ass & 0x2) >> 1;
1133 spec->cdefine.override = ass & 0x1;
1134
1135 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1136 nid, spec->cdefine.sku_cfg);
1137 snd_printd("SKU: port_connectivity=0x%x\n",
1138 spec->cdefine.port_connectivity);
1139 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1140 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1141 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1142 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1143 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1144 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1145 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1146
1147 return 0;
1148}
1149
Takashi Iwai1d045db2011-07-07 18:23:21 +02001150/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001151static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1152{
Takashi Iwai21268962011-07-07 15:01:13 +02001153 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001154}
1155
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001156/* check subsystem ID and set up device-specific initialization;
1157 * return 1 if initialized, 0 if invalid SSID
1158 */
1159/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1160 * 31 ~ 16 : Manufacture ID
1161 * 15 ~ 8 : SKU ID
1162 * 7 ~ 0 : Assembly ID
1163 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1164 */
1165static int alc_subsystem_id(struct hda_codec *codec,
1166 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001167 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001168{
1169 unsigned int ass, tmp, i;
1170 unsigned nid;
1171 struct alc_spec *spec = codec->spec;
1172
David Henningsson90622912010-10-14 14:50:18 +02001173 if (spec->cdefine.fixup) {
1174 ass = spec->cdefine.sku_cfg;
1175 if (ass == ALC_FIXUP_SKU_IGNORE)
1176 return 0;
1177 goto do_sku;
1178 }
1179
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001180 ass = codec->subsystem_id & 0xffff;
1181 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1182 goto do_sku;
1183
1184 /* invalid SSID, check the special NID pin defcfg instead */
1185 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001186 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001187 * 29~21 : reserve
1188 * 20 : PCBEEP input
1189 * 19~16 : Check sum (15:1)
1190 * 15~1 : Custom
1191 * 0 : override
1192 */
1193 nid = 0x1d;
1194 if (codec->vendor_id == 0x10ec0260)
1195 nid = 0x17;
1196 ass = snd_hda_codec_get_pincfg(codec, nid);
1197 snd_printd("realtek: No valid SSID, "
1198 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001199 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001200 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001201 return 0;
1202 if ((ass >> 30) != 1) /* no physical connection */
1203 return 0;
1204
1205 /* check sum */
1206 tmp = 0;
1207 for (i = 1; i < 16; i++) {
1208 if ((ass >> i) & 1)
1209 tmp++;
1210 }
1211 if (((ass >> 16) & 0xf) != tmp)
1212 return 0;
1213do_sku:
1214 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1215 ass & 0xffff, codec->vendor_id);
1216 /*
1217 * 0 : override
1218 * 1 : Swap Jack
1219 * 2 : 0 --> Desktop, 1 --> Laptop
1220 * 3~5 : External Amplifier control
1221 * 7~6 : Reserved
1222 */
1223 tmp = (ass & 0x38) >> 3; /* external Amp control */
1224 switch (tmp) {
1225 case 1:
1226 spec->init_amp = ALC_INIT_GPIO1;
1227 break;
1228 case 3:
1229 spec->init_amp = ALC_INIT_GPIO2;
1230 break;
1231 case 7:
1232 spec->init_amp = ALC_INIT_GPIO3;
1233 break;
1234 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001235 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001236 spec->init_amp = ALC_INIT_DEFAULT;
1237 break;
1238 }
1239
1240 /* is laptop or Desktop and enable the function "Mute internal speaker
1241 * when the external headphone out jack is plugged"
1242 */
1243 if (!(ass & 0x8000))
1244 return 1;
1245 /*
1246 * 10~8 : Jack location
1247 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1248 * 14~13: Resvered
1249 * 15 : 1 --> enable the function "Mute internal speaker
1250 * when the external headphone out jack is plugged"
1251 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001252 if (!spec->autocfg.hp_pins[0] &&
1253 !(spec->autocfg.line_out_pins[0] &&
1254 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001255 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001256 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1257 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001258 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001259 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001260 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001261 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001262 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001263 else if (tmp == 3)
1264 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001265 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001266 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001267 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1268 spec->autocfg.line_outs))
1269 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001270 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001271 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001272 return 1;
1273}
Kailang Yangea1fb292008-08-26 12:58:38 +02001274
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001275/* Check the validity of ALC subsystem-id
1276 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1277static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001278{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001279 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001280 struct alc_spec *spec = codec->spec;
1281 snd_printd("realtek: "
1282 "Enable default setup for auto mode as fallback\n");
1283 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001284 }
Takashi Iwai21268962011-07-07 15:01:13 +02001285}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001286
Takashi Iwai41e41f12005-06-08 14:48:49 +02001287/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001288 * COEF access helper functions
1289 */
Kailang Yang274693f2009-12-03 10:07:50 +01001290static int alc_read_coef_idx(struct hda_codec *codec,
1291 unsigned int coef_idx)
1292{
1293 unsigned int val;
1294 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1295 coef_idx);
1296 val = snd_hda_codec_read(codec, 0x20, 0,
1297 AC_VERB_GET_PROC_COEF, 0);
1298 return val;
1299}
1300
Kailang Yang977ddd62010-09-15 10:02:29 +02001301static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1302 unsigned int coef_val)
1303{
1304 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1305 coef_idx);
1306 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1307 coef_val);
1308}
1309
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001310/* a special bypass for COEF 0; read the cached value at the second time */
1311static unsigned int alc_get_coef0(struct hda_codec *codec)
1312{
1313 struct alc_spec *spec = codec->spec;
1314 if (!spec->coef0)
1315 spec->coef0 = alc_read_coef_idx(codec, 0);
1316 return spec->coef0;
1317}
1318
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001319static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1320 hda_nid_t pin, int pin_type,
1321 hda_nid_t dac);
1322static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1323 bool is_digital);
Takashi Iwai965cceb2012-12-18 11:46:37 +01001324static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
1325 hda_nid_t to_nid, int with_aa_mix,
1326 struct nid_path *path);
1327static struct nid_path *add_new_nid_path(struct hda_codec *codec,
1328 hda_nid_t from_nid, hda_nid_t to_nid,
1329 int with_aa_mix);
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001330
Takashi Iwai1d045db2011-07-07 18:23:21 +02001331/*
1332 * Digital I/O handling
1333 */
1334
Takashi Iwai757899a2010-07-30 10:48:14 +02001335/* set right pin controls for digital I/O */
1336static void alc_auto_init_digital(struct hda_codec *codec)
1337{
1338 struct alc_spec *spec = codec->spec;
1339 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001340 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001341
1342 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1343 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001344 if (!pin)
1345 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001346 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001347 }
1348 pin = spec->autocfg.dig_in_pin;
1349 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001350 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001351}
1352
1353/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1354static void alc_auto_parse_digital(struct hda_codec *codec)
1355{
1356 struct alc_spec *spec = codec->spec;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001357 int i, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001358 hda_nid_t dig_nid;
1359
1360 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001361 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001362 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001363 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1364 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1365 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001366 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001367 if (!add_new_nid_path(codec, dig_nid, pin, 2))
1368 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001369 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001370 spec->multiout.dig_out_nid = dig_nid;
1371 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1372 } else {
1373 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001374 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001375 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001376 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001377 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001378 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001379 }
1380
1381 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001382 dig_nid = codec->start_nid;
1383 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001384 struct nid_path *path;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001385 unsigned int wcaps = get_wcaps(codec, dig_nid);
1386 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1387 continue;
1388 if (!(wcaps & AC_WCAP_DIGITAL))
1389 continue;
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001390 path = add_new_nid_path(codec, spec->autocfg.dig_in_pin,
1391 dig_nid, 2);
1392 if (path) {
1393 path->active = true;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001394 spec->dig_in_nid = dig_nid;
1395 break;
1396 }
1397 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001398 }
1399}
1400
Takashi Iwaif95474e2007-07-10 00:47:43 +02001401/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001402 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001403 */
Takashi Iwai666a70d2012-12-17 20:29:29 +01001404#define alc_cap_vol_info snd_hda_mixer_amp_volume_info
1405#define alc_cap_vol_get snd_hda_mixer_amp_volume_get
1406#define alc_cap_vol_tlv snd_hda_mixer_amp_tlv
1407
1408typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
1409 struct snd_ctl_elem_value *ucontrol);
1410
1411static int alc_cap_put_caller(struct snd_kcontrol *kcontrol,
1412 struct snd_ctl_elem_value *ucontrol,
1413 put_call_t func, int type)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001414{
1415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1416 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001417 const struct hda_input_mux *imux;
1418 struct nid_path *path;
1419 int i, adc_idx, err = 0;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001420
Takashi Iwai27d31532012-12-18 08:57:05 +01001421 imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001422 adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001423 mutex_lock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001424 codec->cached_write = 1;
1425 for (i = 0; i < imux->num_items; i++) {
1426 path = get_nid_path(codec, spec->imux_pins[i],
1427 get_adc_nid(codec, adc_idx, i));
1428 if (!path->ctls[type])
1429 continue;
1430 kcontrol->private_value = path->ctls[type];
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001431 err = func(kcontrol, ucontrol);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001432 if (err < 0)
1433 goto error;
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001434 }
1435 error:
Takashi Iwai666a70d2012-12-17 20:29:29 +01001436 codec->cached_write = 0;
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001437 mutex_unlock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001438 snd_hda_codec_resume_amp(codec);
1439 if (err >= 0 && type == NID_PATH_MUTE_CTL &&
1440 spec->inv_dmic_fixup && spec->inv_dmic_muted)
1441 alc_inv_dmic_sync_adc(codec, adc_idx);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001442 return err;
1443}
1444
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001445static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1446 struct snd_ctl_elem_value *ucontrol)
1447{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001448 return alc_cap_put_caller(kcontrol, ucontrol,
1449 snd_hda_mixer_amp_volume_put,
1450 NID_PATH_VOL_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001451}
1452
1453/* capture mixer elements */
1454#define alc_cap_sw_info snd_ctl_boolean_stereo_info
Takashi Iwai666a70d2012-12-17 20:29:29 +01001455#define alc_cap_sw_get snd_hda_mixer_amp_switch_get
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001456
1457static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1458 struct snd_ctl_elem_value *ucontrol)
1459{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001460 return alc_cap_put_caller(kcontrol, ucontrol,
1461 snd_hda_mixer_amp_switch_put,
1462 NID_PATH_MUTE_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001463}
1464
Takashi Iwai666a70d2012-12-17 20:29:29 +01001465static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1466{
1467 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01001468 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001469 struct nid_path *path;
1470 hda_nid_t nid;
1471 int i, dir, parm;
1472 unsigned int val;
1473
1474 for (i = 0; i < imux->num_items; i++) {
1475 if (spec->imux_pins[i] == spec->inv_dmic_pin)
1476 break;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001477 }
Takashi Iwai666a70d2012-12-17 20:29:29 +01001478 if (i >= imux->num_items)
1479 return;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001480
Takashi Iwai666a70d2012-12-17 20:29:29 +01001481 path = get_nid_path(codec, spec->inv_dmic_pin,
1482 get_adc_nid(codec, adc_idx, i));
1483 val = path->ctls[NID_PATH_MUTE_CTL];
1484 if (!val)
1485 return;
1486 nid = get_amp_nid_(val);
1487 dir = get_amp_direction_(val);
1488 parm = AC_AMP_SET_RIGHT |
1489 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001490
Takashi Iwai666a70d2012-12-17 20:29:29 +01001491 /* we care only right channel */
1492 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1493 if (val & 0x80) /* if already muted, we don't need to touch */
1494 return;
1495 val |= 0x80;
1496 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1497 parm | val);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001498}
1499
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001500/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001501 * Inverted digital-mic handling
1502 *
1503 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1504 * gives the additional mute only to the right channel of the digital mic
1505 * capture stream. This is a workaround for avoiding the almost silence
1506 * by summing the stereo stream from some (known to be ForteMedia)
1507 * digital mic unit.
1508 *
1509 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1510 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1511 * without caching so that the cache can still keep the original value.
1512 * The cached value is then restored when the flag is set off or any other
1513 * than d-mic is used as the current input source.
1514 */
1515static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1516{
1517 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001518 int src, nums;
Takashi Iwai125821a2012-06-22 14:30:29 +02001519
1520 if (!spec->inv_dmic_fixup)
1521 return;
1522 if (!spec->inv_dmic_muted && !force)
1523 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001524 nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids;
1525 for (src = 0; src < nums; src++) {
Takashi Iwai125821a2012-06-22 14:30:29 +02001526 bool dmic_fixup = false;
Takashi Iwai125821a2012-06-22 14:30:29 +02001527
1528 if (spec->inv_dmic_muted &&
1529 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1530 dmic_fixup = true;
1531 if (!dmic_fixup && !force)
1532 continue;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001533 alc_inv_dmic_sync_adc(codec, src);
Takashi Iwai125821a2012-06-22 14:30:29 +02001534 }
1535}
1536
1537static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1538 struct snd_ctl_elem_value *ucontrol)
1539{
1540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1541 struct alc_spec *spec = codec->spec;
1542
1543 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1544 return 0;
1545}
1546
1547static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1548 struct snd_ctl_elem_value *ucontrol)
1549{
1550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1551 struct alc_spec *spec = codec->spec;
1552 unsigned int val = !ucontrol->value.integer.value[0];
1553
1554 if (val == spec->inv_dmic_muted)
1555 return 0;
1556 spec->inv_dmic_muted = val;
1557 alc_inv_dmic_sync(codec, true);
1558 return 0;
1559}
1560
1561static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1562 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwaibc549762012-12-18 15:35:11 +01001563 .name = "Inverted Internal Mic Capture Switch",
Takashi Iwai125821a2012-06-22 14:30:29 +02001564 .info = snd_ctl_boolean_mono_info,
1565 .get = alc_inv_dmic_sw_get,
1566 .put = alc_inv_dmic_sw_put,
1567};
1568
1569static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1570{
1571 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001572
Takashi Iwaibc549762012-12-18 15:35:11 +01001573 if (!alc_kcontrol_new(spec, NULL, &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001574 return -ENOMEM;
1575 spec->inv_dmic_fixup = 1;
1576 spec->inv_dmic_muted = 0;
1577 spec->inv_dmic_pin = nid;
1578 return 0;
1579}
1580
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001581/* typically the digital mic is put at node 0x12 */
1582static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1583 const struct alc_fixup *fix, int action)
1584{
1585 if (action == ALC_FIXUP_ACT_PROBE)
1586 alc_add_inv_dmic_mixer(codec, 0x12);
1587}
1588
Takashi Iwai125821a2012-06-22 14:30:29 +02001589/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001590 * virtual master controls
1591 */
1592
1593/*
1594 * slave controls for virtual master
1595 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001596static const char * const alc_slave_pfxs[] = {
1597 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001598 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001599 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001600 NULL,
1601};
1602
1603/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001604 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001606
1607static void alc_free_kctls(struct hda_codec *codec);
1608
Takashi Iwai67d634c2009-11-16 15:35:59 +01001609#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001610/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001611static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001612 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001613 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001614 { } /* end */
1615};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001616#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001617
Takashi Iwai2eab6942012-12-18 15:30:41 +01001618static int alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
1620 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001621 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623 for (i = 0; i < spec->num_mixers; i++) {
1624 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1625 if (err < 0)
1626 return err;
1627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001629 err = snd_hda_create_dig_out_ctls(codec,
1630 spec->multiout.dig_out_nid,
1631 spec->multiout.dig_out_nid,
1632 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 if (err < 0)
1634 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001635 if (!spec->no_analog) {
1636 err = snd_hda_create_spdif_share_sw(codec,
1637 &spec->multiout);
1638 if (err < 0)
1639 return err;
1640 spec->multiout.share_spdif = 1;
1641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 }
1643 if (spec->dig_in_nid) {
1644 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1645 if (err < 0)
1646 return err;
1647 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001648
Takashi Iwai67d634c2009-11-16 15:35:59 +01001649#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001650 /* create beep controls if needed */
1651 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001652 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001653 for (knew = alc_beep_mixer; knew->name; knew++) {
1654 struct snd_kcontrol *kctl;
1655 kctl = snd_ctl_new1(knew, codec);
1656 if (!kctl)
1657 return -ENOMEM;
1658 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001659 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001660 if (err < 0)
1661 return err;
1662 }
1663 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001664#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001665
Takashi Iwai2134ea42008-01-10 16:53:55 +01001666 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001667 if (!spec->no_analog &&
1668 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001669 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001670 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001671 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001672 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001673 vmaster_tlv, alc_slave_pfxs,
1674 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001675 if (err < 0)
1676 return err;
1677 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001678 if (!spec->no_analog &&
1679 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001680 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1681 NULL, alc_slave_pfxs,
1682 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001683 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001684 if (err < 0)
1685 return err;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001686 if (spec->vmaster_mute.hook)
1687 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001688 }
1689
Takashi Iwaibae84e72010-03-22 08:30:20 +01001690 alc_free_kctls(codec); /* no longer needed */
1691
David Henningsson5780b622012-06-27 18:45:45 +02001692 if (spec->shared_mic_hp) {
1693 int err;
1694 int nid = spec->autocfg.inputs[1].pin;
1695 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1696 if (err < 0)
1697 return err;
1698 err = snd_hda_jack_detect_enable(codec, nid, 0);
1699 if (err < 0)
1700 return err;
1701 }
1702
Takashi Iwai2eab6942012-12-18 15:30:41 +01001703 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001704 if (err < 0)
1705 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001706
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001707 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1708 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709}
1710
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001713 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001714 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001715
Takashi Iwai070cff42012-02-21 12:54:17 +01001716static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718static int alc_init(struct hda_codec *codec)
1719{
1720 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001721
Takashi Iwai546bb672012-03-07 08:37:19 +01001722 if (spec->init_hook)
1723 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001724
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001725 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001726 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001727
Takashi Iwaic9ce6b22012-12-18 18:12:44 +01001728 snd_hda_apply_verbs(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001729 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001730
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001731 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
1732 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
1733
Takashi Iwai58701122011-01-13 15:41:45 +01001734 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1735
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001736 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 return 0;
1738}
1739
Takashi Iwai83012a72012-08-24 18:38:08 +02001740#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001741static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1742{
1743 struct alc_spec *spec = codec->spec;
1744 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1745}
1746#endif
1747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748/*
1749 * Analog playback callbacks
1750 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001751static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001753 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{
1755 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001756 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1757 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758}
1759
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001760static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 struct hda_codec *codec,
1762 unsigned int stream_tag,
1763 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001764 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765{
1766 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001767 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1768 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769}
1770
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001771static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001773 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 struct alc_spec *spec = codec->spec;
1776 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1777}
1778
1779/*
1780 * Digital out
1781 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001782static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001784 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785{
1786 struct alc_spec *spec = codec->spec;
1787 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1788}
1789
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001790static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001791 struct hda_codec *codec,
1792 unsigned int stream_tag,
1793 unsigned int format,
1794 struct snd_pcm_substream *substream)
1795{
1796 struct alc_spec *spec = codec->spec;
1797 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1798 stream_tag, format, substream);
1799}
1800
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001801static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001802 struct hda_codec *codec,
1803 struct snd_pcm_substream *substream)
1804{
1805 struct alc_spec *spec = codec->spec;
1806 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1807}
1808
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001809static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001811 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812{
1813 struct alc_spec *spec = codec->spec;
1814 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1815}
1816
1817/*
1818 * Analog capture
1819 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001820static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 struct hda_codec *codec,
1822 unsigned int stream_tag,
1823 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001824 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
1826 struct alc_spec *spec = codec->spec;
1827
Takashi Iwai63300792008-01-24 15:31:36 +01001828 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 stream_tag, 0, format);
1830 return 0;
1831}
1832
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001833static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001835 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836{
1837 struct alc_spec *spec = codec->spec;
1838
Takashi Iwai888afa12008-03-18 09:57:50 +01001839 snd_hda_codec_cleanup_stream(codec,
1840 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 return 0;
1842}
1843
Takashi Iwai840b64c2010-07-13 22:49:01 +02001844/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02001845static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001846 struct hda_codec *codec,
1847 unsigned int stream_tag,
1848 unsigned int format,
1849 struct snd_pcm_substream *substream)
1850{
1851 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001852 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02001853 spec->cur_adc_stream_tag = stream_tag;
1854 spec->cur_adc_format = format;
1855 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1856 return 0;
1857}
1858
Takashi Iwai21268962011-07-07 15:01:13 +02001859static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001860 struct hda_codec *codec,
1861 struct snd_pcm_substream *substream)
1862{
1863 struct alc_spec *spec = codec->spec;
1864 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1865 spec->cur_adc = 0;
1866 return 0;
1867}
1868
Takashi Iwai21268962011-07-07 15:01:13 +02001869static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02001870 .substreams = 1,
1871 .channels_min = 2,
1872 .channels_max = 2,
1873 .nid = 0, /* fill later */
1874 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02001875 .prepare = dyn_adc_capture_pcm_prepare,
1876 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02001877 },
1878};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
1880/*
1881 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001882static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 .substreams = 1,
1884 .channels_min = 2,
1885 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001886 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001888 .open = alc_playback_pcm_open,
1889 .prepare = alc_playback_pcm_prepare,
1890 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 },
1892};
1893
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001894static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001895 .substreams = 1,
1896 .channels_min = 2,
1897 .channels_max = 2,
1898 /* NID is set in alc_build_pcms */
1899};
1900
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001901static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01001902 .substreams = 1,
1903 .channels_min = 2,
1904 .channels_max = 2,
1905 /* NID is set in alc_build_pcms */
1906};
1907
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001908static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001909 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 .channels_min = 2,
1911 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001912 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001914 .prepare = alc_alt_capture_pcm_prepare,
1915 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 },
1917};
1918
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001919static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 .substreams = 1,
1921 .channels_min = 2,
1922 .channels_max = 2,
1923 /* NID is set in alc_build_pcms */
1924 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001925 .open = alc_dig_playback_pcm_open,
1926 .close = alc_dig_playback_pcm_close,
1927 .prepare = alc_dig_playback_pcm_prepare,
1928 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 },
1930};
1931
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001932static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 .substreams = 1,
1934 .channels_min = 2,
1935 .channels_max = 2,
1936 /* NID is set in alc_build_pcms */
1937};
1938
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001939/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02001940static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001941 .substreams = 0,
1942 .channels_min = 0,
1943 .channels_max = 0,
1944};
1945
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946static int alc_build_pcms(struct hda_codec *codec)
1947{
1948 struct alc_spec *spec = codec->spec;
1949 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001950 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01001951 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 int i;
1953
1954 codec->num_pcms = 1;
1955 codec->pcm_info = info;
1956
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001957 if (spec->no_analog)
1958 goto skip_analog;
1959
Takashi Iwai812a2cc2009-05-16 10:00:49 +02001960 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1961 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01001963
Takashi Iwaieedec3d2012-02-06 10:24:04 +01001964 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001965 p = spec->stream_analog_playback;
1966 if (!p)
1967 p = &alc_pcm_analog_playback;
1968 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001969 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02001970 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1971 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01001972 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
1973 spec->autocfg.line_outs == 2)
1974 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1975 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001976 }
Takashi Iwai27d31532012-12-18 08:57:05 +01001977 if (spec->num_adc_nids) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001978 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02001979 if (!p) {
1980 if (spec->dyn_adc_switch)
1981 p = &dyn_adc_pcm_analog_capture;
1982 else
1983 p = &alc_pcm_analog_capture;
1984 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001985 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001986 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Takashi Iwai4a471b72005-12-07 13:56:29 +01001989 if (spec->channel_mode) {
1990 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
1991 for (i = 0; i < spec->num_channel_mode; i++) {
1992 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
1993 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
1994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 }
1996 }
1997
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001998 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02001999 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002001 snprintf(spec->stream_name_digital,
2002 sizeof(spec->stream_name_digital),
2003 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002004 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002005 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002006 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002008 if (spec->dig_out_type)
2009 info->pcm_type = spec->dig_out_type;
2010 else
2011 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002012 if (spec->multiout.dig_out_nid) {
2013 p = spec->stream_digital_playback;
2014 if (!p)
2015 p = &alc_pcm_digital_playback;
2016 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2018 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002019 if (spec->dig_in_nid) {
2020 p = spec->stream_digital_capture;
2021 if (!p)
2022 p = &alc_pcm_digital_capture;
2023 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2025 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002026 /* FIXME: do we need this for all Realtek codec models? */
2027 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 }
2029
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002030 if (spec->no_analog)
2031 return 0;
2032
Takashi Iwaie08a0072006-09-07 17:52:14 +02002033 /* If the use of more than one ADC is requested for the current
2034 * model, configure a second analog capture-only PCM.
2035 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002036 have_multi_adcs = (spec->num_adc_nids > 1) &&
Takashi Iwai27d31532012-12-18 08:57:05 +01002037 !spec->dyn_adc_switch && !spec->auto_mic;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002038 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002039 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002040 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002041 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002042 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002043 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002044 p = spec->stream_analog_alt_playback;
2045 if (!p)
2046 p = &alc_pcm_analog_alt_playback;
2047 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002048 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2049 spec->alt_dac_nid;
2050 } else {
2051 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2052 alc_pcm_null_stream;
2053 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2054 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002055 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002056 p = spec->stream_analog_alt_capture;
2057 if (!p)
2058 p = &alc_pcm_analog_alt_capture;
2059 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002060 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2061 spec->adc_nids[1];
2062 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2063 spec->num_adc_nids - 1;
2064 } else {
2065 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2066 alc_pcm_null_stream;
2067 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002068 }
2069 }
2070
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 return 0;
2072}
2073
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002074static inline void alc_shutup(struct hda_codec *codec)
2075{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002076 struct alc_spec *spec = codec->spec;
2077
2078 if (spec && spec->shutup)
2079 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002080 snd_hda_shutup_pins(codec);
2081}
2082
Takashi Iwai603c4012008-07-30 15:01:44 +02002083static void alc_free_kctls(struct hda_codec *codec)
2084{
2085 struct alc_spec *spec = codec->spec;
2086
2087 if (spec->kctls.list) {
2088 struct snd_kcontrol_new *kctl = spec->kctls.list;
2089 int i;
2090 for (i = 0; i < spec->kctls.used; i++)
2091 kfree(kctl[i].name);
2092 }
2093 snd_array_free(&spec->kctls);
2094}
2095
Takashi Iwai23c09b02011-08-19 09:05:35 +02002096static void alc_free_bind_ctls(struct hda_codec *codec)
2097{
2098 struct alc_spec *spec = codec->spec;
2099 if (spec->bind_ctls.list) {
2100 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2101 int i;
2102 for (i = 0; i < spec->bind_ctls.used; i++)
2103 kfree(ctl[i]);
2104 }
2105 snd_array_free(&spec->bind_ctls);
2106}
2107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108static void alc_free(struct hda_codec *codec)
2109{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002110 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002111
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002112 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002113 return;
2114
Takashi Iwai603c4012008-07-30 15:01:44 +02002115 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002116 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002117 snd_array_free(&spec->paths);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002118 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002119 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120}
2121
Takashi Iwai83012a72012-08-24 18:38:08 +02002122#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002123static void alc_power_eapd(struct hda_codec *codec)
2124{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002125 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002126}
2127
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002128static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002129{
2130 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002131 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002132 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002133 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002134 return 0;
2135}
2136#endif
2137
Takashi Iwai2a439522011-07-26 09:52:50 +02002138#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002139static int alc_resume(struct hda_codec *codec)
2140{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002141 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002142 codec->patch_ops.init(codec);
2143 snd_hda_codec_resume_amp(codec);
2144 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002145 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002146 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002147 return 0;
2148}
Takashi Iwaie044c392008-10-27 16:56:24 +01002149#endif
2150
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151/*
2152 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002153static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 .build_controls = alc_build_controls,
2155 .build_pcms = alc_build_pcms,
2156 .init = alc_init,
2157 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002158 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002159#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002160 .resume = alc_resume,
2161#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002162#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002163 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002164 .check_power_status = alc_check_power_status,
2165#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002166 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167};
2168
David Henningsson29adc4b2012-09-25 11:31:00 +02002169
Kailang Yangc027ddc2010-03-19 11:33:06 +01002170/* replace the codec chip_name with the given string */
2171static int alc_codec_rename(struct hda_codec *codec, const char *name)
2172{
2173 kfree(codec->chip_name);
2174 codec->chip_name = kstrdup(name, GFP_KERNEL);
2175 if (!codec->chip_name) {
2176 alc_free(codec);
2177 return -ENOMEM;
2178 }
2179 return 0;
2180}
2181
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002182/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002183 * Rename codecs appropriately from COEF value
2184 */
2185struct alc_codec_rename_table {
2186 unsigned int vendor_id;
2187 unsigned short coef_mask;
2188 unsigned short coef_bits;
2189 const char *name;
2190};
2191
2192static struct alc_codec_rename_table rename_tbl[] = {
2193 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2194 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2195 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2196 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2197 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2198 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2199 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002200 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002201 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2202 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2203 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2204 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2205 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2206 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2207 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2208 { } /* terminator */
2209};
2210
2211static int alc_codec_rename_from_preset(struct hda_codec *codec)
2212{
2213 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002214
2215 for (p = rename_tbl; p->vendor_id; p++) {
2216 if (p->vendor_id != codec->vendor_id)
2217 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002218 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002219 return alc_codec_rename(codec, p->name);
2220 }
2221 return 0;
2222}
2223
2224/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002225 * Automatic parse of I/O pins from the BIOS configuration
2226 */
2227
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002228enum {
2229 ALC_CTL_WIDGET_VOL,
2230 ALC_CTL_WIDGET_MUTE,
2231 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002232 ALC_CTL_BIND_VOL,
2233 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002234};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002235static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002236 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2237 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002238 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002239 HDA_BIND_VOL(NULL, 0),
2240 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002241};
2242
2243/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002244static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002245 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002246{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002247 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002248
Takashi Iwai668d1e92012-11-29 14:10:17 +01002249 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002250 if (!knew)
2251 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002252 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002253 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002254 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002255 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002256 return 0;
2257}
2258
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002259static int add_control_with_pfx(struct alc_spec *spec, int type,
2260 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002261 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002262{
2263 char name[32];
2264 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002265 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002266}
2267
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002268#define add_pb_vol_ctrl(spec, type, pfx, val) \
2269 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2270#define add_pb_sw_ctrl(spec, type, pfx, val) \
2271 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2272#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2273 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2274#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2275 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002276
Takashi Iwai23c09b02011-08-19 09:05:35 +02002277static const char * const channel_name[4] = {
2278 "Front", "Surround", "CLFE", "Side"
2279};
2280
Takashi Iwai6843ca12011-06-24 11:03:58 +02002281static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2282 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002283{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002284 struct auto_pin_cfg *cfg = &spec->autocfg;
2285
Takashi Iwai6843ca12011-06-24 11:03:58 +02002286 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002287 if (cfg->line_outs == 1 && !spec->multi_ios &&
2288 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwai52a8efa2012-12-18 17:33:04 +01002289 return spec->vmaster_mute.hook ? "PCM" : "Master";
2290
2291 /* if there is really a single DAC used in the whole output paths,
2292 * use it master (or "PCM" if a vmaster hook is present)
2293 */
2294 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
2295 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
2296 return spec->vmaster_mute.hook ? "PCM" : "Master";
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002297
2298 switch (cfg->line_out_type) {
2299 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002300 if (cfg->line_outs == 1)
2301 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002302 if (cfg->line_outs == 2)
2303 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002304 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002305 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002306 /* for multi-io case, only the primary out */
2307 if (ch && spec->multi_ios)
2308 break;
2309 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002310 return "Headphone";
2311 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002312 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002313 return "PCM";
2314 break;
2315 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002316 if (ch >= ARRAY_SIZE(channel_name)) {
2317 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002318 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002319 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002320
2321 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002322}
2323
Takashi Iwai83012a72012-08-24 18:38:08 +02002324#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002325/* add the powersave loopback-list entry */
2326static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2327{
2328 struct hda_amp_list *list;
2329
2330 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2331 return;
2332 list = spec->loopback_list + spec->num_loopbacks;
2333 list->nid = mix;
2334 list->dir = HDA_INPUT;
2335 list->idx = idx;
2336 spec->num_loopbacks++;
2337 spec->loopback.amplist = spec->loopback_list;
2338}
2339#else
2340#define add_loopback_list(spec, mix, idx) /* NOP */
2341#endif
2342
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002343/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002344static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002345 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002346 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002347{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002348 struct alc_spec *spec = codec->spec;
2349 struct nid_path *path;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002350 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002351 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002352
Takashi Iwaibd32f782012-12-12 18:08:52 +01002353 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2354 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2355 return 0; /* no need for analog loopback */
2356
Takashi Iwai965cceb2012-12-18 11:46:37 +01002357 path = add_new_nid_path(codec, pin, mix_nid, 2);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002358 if (!path)
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002359 return -EINVAL;
2360
2361 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002362 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002363 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2364 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002365 if (err < 0)
2366 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002367 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002368 }
2369
2370 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002371 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2372 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002373 if (err < 0)
2374 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002375 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002376 }
2377
Takashi Iwai829f69e2012-12-14 18:26:02 +01002378 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002379 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002380 return 0;
2381}
2382
Takashi Iwai05f5f472009-08-25 13:10:18 +02002383static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002384{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002385 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2386 return (pincap & AC_PINCAP_IN) != 0;
2387}
2388
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002389/* check whether the given two widgets can be connected */
2390static bool is_reachable_path(struct hda_codec *codec,
2391 hda_nid_t from_nid, hda_nid_t to_nid)
2392{
2393 if (!from_nid || !to_nid)
2394 return false;
2395 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2396}
2397
Takashi Iwai666a70d2012-12-17 20:29:29 +01002398/* Parse the codec tree and retrieve ADCs */
2399static int alc_auto_fill_adc_nids(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002400{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002401 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002402 hda_nid_t nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002403 hda_nid_t *adc_nids = spec->adc_nids;
2404 int max_nums = ARRAY_SIZE(spec->adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002405 int i, nums = 0;
2406
2407 nid = codec->start_nid;
2408 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwaib7821702011-07-06 15:12:46 +02002409 unsigned int caps = get_wcaps(codec, nid);
2410 int type = get_wcaps_type(caps);
2411
2412 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2413 continue;
2414 adc_nids[nums] = nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002415 if (++nums >= max_nums)
2416 break;
2417 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002418 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002419 return nums;
2420}
2421
Takashi Iwai666a70d2012-12-17 20:29:29 +01002422/* filter out invalid adc_nids that don't give all active input pins;
2423 * if needed, check whether dynamic ADC-switching is available
2424 */
2425static int check_dyn_adc_switch(struct hda_codec *codec)
2426{
2427 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002428 struct hda_input_mux *imux = &spec->input_mux;
2429 hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)];
Takashi Iwai666a70d2012-12-17 20:29:29 +01002430 int i, n, nums;
2431 hda_nid_t pin, adc;
2432
2433 again:
2434 nums = 0;
2435 for (n = 0; n < spec->num_adc_nids; n++) {
2436 adc = spec->adc_nids[n];
2437 for (i = 0; i < imux->num_items; i++) {
2438 pin = spec->imux_pins[i];
2439 if (!is_reachable_path(codec, pin, adc))
2440 break;
2441 }
2442 if (i >= imux->num_items)
2443 adc_nids[nums++] = adc;
2444 }
2445
2446 if (!nums) {
2447 if (spec->shared_mic_hp) {
2448 spec->shared_mic_hp = 0;
Takashi Iwai27d31532012-12-18 08:57:05 +01002449 imux->num_items = 1;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002450 goto again;
2451 }
2452
2453 /* check whether ADC-switch is possible */
2454 for (i = 0; i < imux->num_items; i++) {
2455 pin = spec->imux_pins[i];
2456 for (n = 0; n < spec->num_adc_nids; n++) {
2457 adc = spec->adc_nids[n];
2458 if (is_reachable_path(codec, pin, adc)) {
2459 spec->dyn_adc_idx[i] = n;
2460 break;
2461 }
2462 }
2463 }
2464
2465 snd_printdd("realtek: enabling ADC switching\n");
2466 spec->dyn_adc_switch = 1;
2467 } else if (nums != spec->num_adc_nids) {
Takashi Iwai27d31532012-12-18 08:57:05 +01002468 memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t));
Takashi Iwai666a70d2012-12-17 20:29:29 +01002469 spec->num_adc_nids = nums;
2470 }
2471
Takashi Iwai27d31532012-12-18 08:57:05 +01002472 if (imux->num_items == 1 || spec->shared_mic_hp) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002473 snd_printdd("realtek: reducing to a single ADC\n");
2474 spec->num_adc_nids = 1; /* reduce to a single ADC */
2475 }
2476
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002477 /* single index for individual volumes ctls */
2478 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
2479 spec->num_adc_nids = 1;
2480
Takashi Iwai666a70d2012-12-17 20:29:29 +01002481 return 0;
2482}
2483
2484/* templates for capture controls */
2485static const struct snd_kcontrol_new cap_src_temp = {
2486 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2487 .name = "Input Source",
2488 .info = alc_mux_enum_info,
2489 .get = alc_mux_enum_get,
2490 .put = alc_mux_enum_put,
2491};
2492
2493static const struct snd_kcontrol_new cap_vol_temp = {
2494 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2495 .name = "Capture Volume",
2496 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2497 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2498 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2499 .info = alc_cap_vol_info,
2500 .get = alc_cap_vol_get,
2501 .put = alc_cap_vol_put,
2502 .tlv = { .c = alc_cap_vol_tlv },
2503};
2504
2505static const struct snd_kcontrol_new cap_sw_temp = {
2506 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2507 .name = "Capture Switch",
2508 .info = alc_cap_sw_info,
2509 .get = alc_cap_sw_get,
2510 .put = alc_cap_sw_put,
2511};
2512
2513static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2514{
2515 hda_nid_t nid;
2516 int i, depth;
2517
2518 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2519 for (depth = 0; depth < 3; depth++) {
2520 if (depth >= path->depth)
2521 return -EINVAL;
2522 i = path->depth - depth - 1;
2523 nid = path->path[i];
2524 if (!path->ctls[NID_PATH_VOL_CTL]) {
2525 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2526 path->ctls[NID_PATH_VOL_CTL] =
2527 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2528 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2529 int idx = path->idx[i];
2530 if (!depth && codec->single_adc_amp)
2531 idx = 0;
2532 path->ctls[NID_PATH_VOL_CTL] =
2533 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2534 }
2535 }
2536 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2537 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2538 path->ctls[NID_PATH_MUTE_CTL] =
2539 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2540 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2541 int idx = path->idx[i];
2542 if (!depth && codec->single_adc_amp)
2543 idx = 0;
2544 path->ctls[NID_PATH_MUTE_CTL] =
2545 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2546 }
2547 }
2548 }
2549 return 0;
2550}
2551
Takashi Iwai81fede892012-12-18 17:24:25 +01002552static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs);
2553
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002554static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
2555 int idx, bool is_switch, unsigned int ctl)
2556{
2557 struct alc_spec *spec = codec->spec;
2558 char tmpname[44];
2559 int type = is_switch ? ALC_CTL_WIDGET_MUTE : ALC_CTL_WIDGET_VOL;
2560 const char *sfx = is_switch ? "Switch" : "Volume";
Takashi Iwai81fede892012-12-18 17:24:25 +01002561 unsigned int chs;
2562 int err;
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002563
2564 if (!ctl)
2565 return 0;
2566
Takashi Iwai81fede892012-12-18 17:24:25 +01002567 if (idx == spec->inv_dmic_split_idx)
2568 chs = 1;
2569 else
2570 chs = 3;
2571
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002572 if (label)
2573 snprintf(tmpname, sizeof(tmpname),
2574 "%s Capture %s", label, sfx);
2575 else
2576 snprintf(tmpname, sizeof(tmpname),
2577 "Capture %s", sfx);
Takashi Iwai81fede892012-12-18 17:24:25 +01002578 err = add_control(spec, type, tmpname, idx,
2579 amp_val_replace_channels(ctl, chs));
2580 if (err < 0 || chs == 3)
2581 return err;
2582
2583 /* Make independent right kcontrol */
2584 if (label)
2585 snprintf(tmpname, sizeof(tmpname),
2586 "Inverted %s Capture %s", label, sfx);
2587 else
2588 snprintf(tmpname, sizeof(tmpname),
2589 "Inverted Capture %s", sfx);
2590 return add_control(spec, type, tmpname, idx,
2591 amp_val_replace_channels(ctl, 2));
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002592}
2593
2594/* create single (and simple) capture volume and switch controls */
2595static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
2596 unsigned int vol_ctl, unsigned int sw_ctl)
2597{
2598 int err;
2599 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl);
2600 if (err < 0)
2601 return err;
2602 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl);
2603 if (err < 0)
2604 return err;
2605 return 0;
2606}
2607
2608/* create bound capture volume and switch controls */
2609static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
2610 unsigned int vol_ctl, unsigned int sw_ctl)
2611{
2612 struct alc_spec *spec = codec->spec;
2613 struct snd_kcontrol_new *knew;
2614
2615 if (vol_ctl) {
2616 knew = alc_kcontrol_new(spec, NULL, &cap_vol_temp);
2617 if (!knew)
2618 return -ENOMEM;
2619 knew->index = idx;
2620 knew->private_value = vol_ctl;
2621 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2622 }
2623 if (sw_ctl) {
2624 knew = alc_kcontrol_new(spec, NULL, &cap_sw_temp);
2625 if (!knew)
2626 return -ENOMEM;
2627 knew->index = idx;
2628 knew->private_value = sw_ctl;
2629 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2630 }
2631 return 0;
2632}
2633
2634/* return the vol ctl when used first in the imux list */
2635static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
2636{
2637 struct alc_spec *spec = codec->spec;
2638 struct nid_path *path;
2639 unsigned int ctl;
2640 int i;
2641
2642 path = get_nid_path(codec, spec->imux_pins[idx],
2643 get_adc_nid(codec, 0, idx));
2644 if (!path)
2645 return 0;
2646 ctl = path->ctls[type];
2647 if (!ctl)
2648 return 0;
2649 for (i = 0; i < idx - 1; i++) {
2650 path = get_nid_path(codec, spec->imux_pins[i],
2651 get_adc_nid(codec, 0, i));
2652 if (path && path->ctls[type] == ctl)
2653 return 0;
2654 }
2655 return ctl;
2656}
2657
2658/* create individual capture volume and switch controls per input */
2659static int create_multi_cap_vol_ctl(struct hda_codec *codec)
2660{
2661 struct alc_spec *spec = codec->spec;
2662 struct hda_input_mux *imux = &spec->input_mux;
2663 int i, err, type, type_idx = 0;
2664 const char *prev_label = NULL;
2665
2666 for (i = 0; i < imux->num_items; i++) {
2667 const char *label;
2668 label = hda_get_autocfg_input_label(codec, &spec->autocfg, i);
2669 if (prev_label && !strcmp(label, prev_label))
2670 type_idx++;
2671 else
2672 type_idx = 0;
2673 prev_label = label;
2674
2675 for (type = 0; type < 2; type++) {
2676 err = add_single_cap_ctl(codec, label, type_idx, type,
2677 get_first_cap_ctl(codec, i, type));
2678 if (err < 0)
2679 return err;
2680 }
2681 }
2682 return 0;
2683}
2684
Takashi Iwai666a70d2012-12-17 20:29:29 +01002685static int create_capture_mixers(struct hda_codec *codec)
2686{
2687 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002688 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002689 int i, n, nums, err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002690
2691 if (spec->dyn_adc_switch)
2692 nums = 1;
2693 else
2694 nums = spec->num_adc_nids;
2695
2696 if (!spec->auto_mic && imux->num_items > 1) {
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002697 struct snd_kcontrol_new *knew;
Takashi Iwaibc549762012-12-18 15:35:11 +01002698 knew = alc_kcontrol_new(spec, NULL, &cap_src_temp);
Takashi Iwai666a70d2012-12-17 20:29:29 +01002699 if (!knew)
2700 return -ENOMEM;
2701 knew->count = nums;
2702 }
2703
2704 for (n = 0; n < nums; n++) {
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002705 bool multi = false;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002706 int vol, sw;
2707
2708 vol = sw = 0;
2709 for (i = 0; i < imux->num_items; i++) {
2710 struct nid_path *path;
2711 path = get_nid_path(codec, spec->imux_pins[i],
2712 get_adc_nid(codec, n, i));
2713 if (!path)
2714 continue;
2715 parse_capvol_in_path(codec, path);
2716 if (!vol)
2717 vol = path->ctls[NID_PATH_VOL_CTL];
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002718 else if (vol != path->ctls[NID_PATH_VOL_CTL])
2719 multi = true;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002720 if (!sw)
2721 sw = path->ctls[NID_PATH_MUTE_CTL];
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002722 else if (sw != path->ctls[NID_PATH_MUTE_CTL])
2723 multi = true;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002724 }
2725
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002726 if (!multi)
2727 err = create_single_cap_vol_ctl(codec, n, vol, sw);
2728 else if (!spec->multi_cap_vol)
2729 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
2730 else
2731 err = create_multi_cap_vol_ctl(codec);
2732 if (err < 0)
2733 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002734 }
2735
2736 return 0;
2737}
2738
Takashi Iwai05f5f472009-08-25 13:10:18 +02002739/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002740static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002741{
2742 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002743 const struct auto_pin_cfg *cfg = &spec->autocfg;
2744 hda_nid_t mixer = spec->mixer_nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002745 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwaib7821702011-07-06 15:12:46 +02002746 int num_adcs;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002747 int i, c, err, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002748 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002749
Takashi Iwai666a70d2012-12-17 20:29:29 +01002750 num_adcs = alc_auto_fill_adc_nids(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002751 if (num_adcs < 0)
2752 return 0;
2753
Takashi Iwai81fede892012-12-18 17:24:25 +01002754 spec->inv_dmic_split_idx = -1;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002755 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002756 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002757 const char *label;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002758 bool imux_added;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002759
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002760 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002761 if (!alc_is_input_pin(codec, pin))
2762 continue;
2763
David Henningsson5322bf22011-01-05 11:03:56 +01002764 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002765 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2766 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002767 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002768 type_idx++;
2769 else
2770 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002771 prev_label = label;
2772
Takashi Iwai05f5f472009-08-25 13:10:18 +02002773 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002774 if (is_reachable_path(codec, pin, mixer)) {
2775 err = new_analog_input(codec, pin,
2776 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002777 if (err < 0)
2778 return err;
2779 }
2780 }
2781
Takashi Iwai666a70d2012-12-17 20:29:29 +01002782 imux_added = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002783 for (c = 0; c < num_adcs; c++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002784 struct nid_path *path;
2785 hda_nid_t adc = spec->adc_nids[c];
2786
2787 if (!is_reachable_path(codec, pin, adc))
2788 continue;
2789 path = snd_array_new(&spec->paths);
2790 if (!path)
2791 return -ENOMEM;
2792 memset(path, 0, sizeof(*path));
2793 if (!parse_nid_path(codec, pin, adc, 2, path)) {
2794 snd_printd(KERN_ERR
2795 "invalid input path 0x%x -> 0x%x\n",
2796 pin, adc);
2797 spec->paths.used--;
2798 continue;
2799 }
2800
2801 if (!imux_added) {
2802 spec->imux_pins[imux->num_items] = pin;
2803 snd_hda_add_imux_item(imux, label,
2804 imux->num_items, NULL);
2805 imux_added = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002806 }
2807 }
Takashi Iwai81fede892012-12-18 17:24:25 +01002808
2809 if (spec->inv_dmic_split) {
2810 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
2811 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
2812 if (snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT)
2813 spec->inv_dmic_split_idx = i;
2814 }
2815 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002816 }
Takashi Iwai21268962011-07-07 15:01:13 +02002817
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002818 return 0;
2819}
2820
Takashi Iwai24de1832011-11-07 17:13:39 +01002821/* create a shared input with the headphone out */
2822static int alc_auto_create_shared_input(struct hda_codec *codec)
2823{
2824 struct alc_spec *spec = codec->spec;
2825 struct auto_pin_cfg *cfg = &spec->autocfg;
2826 unsigned int defcfg;
2827 hda_nid_t nid;
2828
2829 /* only one internal input pin? */
2830 if (cfg->num_inputs != 1)
2831 return 0;
2832 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2833 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2834 return 0;
2835
2836 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2837 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2838 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2839 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2840 else
2841 return 0; /* both not available */
2842
2843 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2844 return 0; /* no input */
2845
2846 cfg->inputs[1].pin = nid;
2847 cfg->inputs[1].type = AUTO_PIN_MIC;
2848 cfg->num_inputs = 2;
2849 spec->shared_mic_hp = 1;
2850 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2851 return 0;
2852}
2853
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002854static int get_pin_type(int line_out_type)
2855{
2856 if (line_out_type == AUTO_PIN_HP_OUT)
2857 return PIN_HP;
2858 else
2859 return PIN_OUT;
2860}
2861
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002862static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002863{
2864 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002865 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002866 int i;
2867
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002868 for (i = 0; i < cfg->num_inputs; i++) {
2869 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai62343992012-12-18 09:06:01 +01002870 if (alc_is_input_pin(codec, nid))
Takashi Iwai30ea0982010-09-16 18:47:56 +02002871 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002872
Takashi Iwai829f69e2012-12-14 18:26:02 +01002873 /* mute loopback inputs */
2874 if (spec->mixer_nid) {
2875 struct nid_path *path;
2876 path = get_nid_path(codec, nid, spec->mixer_nid);
2877 if (path)
Takashi Iwai666a70d2012-12-17 20:29:29 +01002878 activate_path(codec, path, path->active, false);
Takashi Iwai829f69e2012-12-14 18:26:02 +01002879 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002880 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002881}
2882
Takashi Iwai185d99f2012-02-16 18:39:45 +01002883static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2884{
2885 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002886 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002887
Takashi Iwaic9967f12012-12-14 16:39:22 +01002888 for (i = 0; i < spec->paths.used; i++) {
2889 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002890 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002891 return true;
2892 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002893 return false;
2894}
2895
Takashi Iwai463419d2012-12-05 14:17:37 +01002896/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002897static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2898 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002899{
2900 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002901 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002902 int i;
2903
2904 for (i = 0; i < spec->num_all_dacs; i++) {
2905 hda_nid_t nid = spec->all_dacs[i];
2906 if (!nid || alc_is_dac_already_used(codec, nid))
2907 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002908 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2909 if (is_digital != cap_digital)
2910 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002911 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002912 return nid;
2913 }
2914 return 0;
2915}
2916
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002917/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002918static bool __parse_nid_path(struct hda_codec *codec,
2919 hda_nid_t from_nid, hda_nid_t to_nid,
2920 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002921{
2922 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002923 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002924 int i, nums;
2925
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002926 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002927 if (!with_aa_mix)
2928 return false;
2929 with_aa_mix = 2; /* mark aa-mix is included */
2930 }
2931
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002932 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002933 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002934 if (conn[i] != from_nid) {
2935 /* special case: when from_nid is 0,
2936 * try to find an empty DAC
2937 */
2938 if (from_nid ||
2939 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2940 alc_is_dac_already_used(codec, conn[i]))
2941 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002942 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002943 /* aa-mix is requested but not included? */
2944 if (!(spec->mixer_nid && with_aa_mix == 1))
2945 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002946 }
2947 if (depth >= MAX_NID_PATH_DEPTH)
2948 return false;
2949 for (i = 0; i < nums; i++) {
2950 unsigned int type;
2951 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002952 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2953 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002954 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002955 if (__parse_nid_path(codec, from_nid, conn[i],
2956 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002957 goto found;
2958 }
2959 return false;
2960
2961 found:
2962 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002963 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002964 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002965 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002966 path->depth++;
2967 return true;
2968}
2969
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002970/* parse the widget path from the given nid to the target nid;
2971 * when @from_nid is 0, try to find an empty DAC;
2972 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2973 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2974 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002975 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002976static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2977 hda_nid_t to_nid, int with_aa_mix,
2978 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002979{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002980 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2981 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002982 path->depth++;
2983#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002984 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002985 path->depth, path->path[0], path->path[1],
2986 path->path[2], path->path[3], path->path[4]);
2987#endif
2988 return true;
2989 }
2990 return false;
2991}
2992
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002993static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2994{
Takashi Iwai140547e2012-02-16 17:23:46 +01002995 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002996 int i;
2997 hda_nid_t nid_found = 0;
2998
2999 for (i = 0; i < spec->num_all_dacs; i++) {
3000 hda_nid_t nid = spec->all_dacs[i];
3001 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003002 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01003003 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003004 if (nid_found)
3005 return 0;
3006 nid_found = nid;
3007 }
3008 }
3009 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003010}
3011
Takashi Iwaiba8111272012-12-06 18:06:23 +01003012static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003013{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003014 struct alc_spec *spec = codec->spec;
3015 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003016
Takashi Iwaic9967f12012-12-14 16:39:22 +01003017 for (i = 0; i < spec->paths.used; i++) {
3018 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003019 if (path->ctls[type] == val)
3020 return true;
3021 }
3022 return false;
3023}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003024
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003025/* badness definition */
3026enum {
3027 /* No primary DAC is found for the main output */
3028 BAD_NO_PRIMARY_DAC = 0x10000,
3029 /* No DAC is found for the extra output */
3030 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003031 /* No possible multi-ios */
3032 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003033 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003034 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003035 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003036 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003037 /* Primary DAC shared with main surrounds */
3038 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003039 /* Primary DAC shared with main CLFE */
3040 BAD_SHARED_CLFE = 0x10,
3041 /* Primary DAC shared with extra surrounds */
3042 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003043 /* Volume widget is shared */
3044 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003045};
3046
3047static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003048 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003049static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003050 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003051
Takashi Iwai965cceb2012-12-18 11:46:37 +01003052static struct nid_path *add_new_nid_path(struct hda_codec *codec,
3053 hda_nid_t from_nid, hda_nid_t to_nid,
3054 int with_aa_mix)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003055{
3056 struct alc_spec *spec = codec->spec;
3057 struct nid_path *path;
3058
Takashi Iwai965cceb2012-12-18 11:46:37 +01003059 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
3060 return NULL;
3061
Takashi Iwaic9967f12012-12-14 16:39:22 +01003062 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003063 if (!path)
Takashi Iwai965cceb2012-12-18 11:46:37 +01003064 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003065 memset(path, 0, sizeof(*path));
Takashi Iwai965cceb2012-12-18 11:46:37 +01003066 if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path))
3067 return path;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003068 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01003069 spec->paths.used--;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003070 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003071}
3072
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003073/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003074 * passing 0 to either @pin or @dac behaves as a wildcard
3075 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003076static struct nid_path *
3077get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01003078{
3079 struct alc_spec *spec = codec->spec;
3080 int i;
3081
Takashi Iwaic9967f12012-12-14 16:39:22 +01003082 for (i = 0; i < spec->paths.used; i++) {
3083 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003084 if (path->depth <= 0)
3085 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003086 if ((!from_nid || path->path[0] == from_nid) &&
3087 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01003088 return path;
3089 }
3090 return NULL;
3091}
3092
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003093/* look for widgets in the path between the given NIDs appropriate for
3094 * volume and mute controls, and assign the values to ctls[].
3095 *
3096 * When no appropriate widget is found in the path, the badness value
3097 * is incremented depending on the situation. The function returns the
3098 * total badness for both volume and mute controls.
3099 */
3100static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3101 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003102{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003103 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003104 hda_nid_t nid;
3105 unsigned int val;
3106 int badness = 0;
3107
Takashi Iwaiba8111272012-12-06 18:06:23 +01003108 if (!path)
3109 return BAD_SHARED_VOL * 2;
3110 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003111 if (nid) {
3112 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003113 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003114 badness += BAD_SHARED_VOL;
3115 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003116 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003117 } else
3118 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003119 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003120 if (nid) {
3121 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003122 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3123 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003124 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3125 else
3126 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003127 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003128 badness += BAD_SHARED_VOL;
3129 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003130 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003131 } else
3132 badness += BAD_SHARED_VOL;
3133 return badness;
3134}
3135
Takashi Iwaidc31b582012-02-17 17:27:53 +01003136struct badness_table {
3137 int no_primary_dac; /* no primary DAC */
3138 int no_dac; /* no secondary DACs */
3139 int shared_primary; /* primary DAC is shared with main output */
3140 int shared_surr; /* secondary DAC shared with main or primary */
3141 int shared_clfe; /* third DAC shared with main or primary */
3142 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3143};
3144
3145static struct badness_table main_out_badness = {
3146 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3147 .no_dac = BAD_NO_DAC,
3148 .shared_primary = BAD_NO_PRIMARY_DAC,
3149 .shared_surr = BAD_SHARED_SURROUND,
3150 .shared_clfe = BAD_SHARED_CLFE,
3151 .shared_surr_main = BAD_SHARED_SURROUND,
3152};
3153
3154static struct badness_table extra_out_badness = {
3155 .no_primary_dac = BAD_NO_DAC,
3156 .no_dac = BAD_NO_DAC,
3157 .shared_primary = BAD_NO_EXTRA_DAC,
3158 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3159 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3160 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3161};
3162
3163/* try to assign DACs to pins and return the resultant badness */
3164static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3165 const hda_nid_t *pins, hda_nid_t *dacs,
3166 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003167{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003168 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003169 struct auto_pin_cfg *cfg = &spec->autocfg;
3170 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003171 int badness = 0;
3172 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003173
Takashi Iwai185d99f2012-02-16 18:39:45 +01003174 if (!num_outs)
3175 return 0;
3176
Takashi Iwaidc31b582012-02-17 17:27:53 +01003177 for (i = 0; i < num_outs; i++) {
3178 hda_nid_t pin = pins[i];
3179 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003180 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003181 if (!dacs[i] && !i) {
3182 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003183 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003184 dacs[0] = dacs[j];
3185 dacs[j] = 0;
3186 break;
3187 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003188 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003189 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003190 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003191 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003192 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003193 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003194 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003195 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003196 dac = spec->private_dac_nids[i];
3197 if (dac) {
3198 if (!i)
3199 badness += bad->shared_primary;
3200 else if (i == 1)
3201 badness += bad->shared_surr;
3202 else
3203 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003204 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003205 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003206 badness += bad->shared_surr_main;
3207 } else if (!i)
3208 badness += bad->no_primary_dac;
3209 else
3210 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003211 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003212 if (!add_new_nid_path(codec, dac, pin, 0))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003213 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003214 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003215 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003216 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003217
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003218 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003219}
3220
3221static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003222 hda_nid_t reference_pin,
3223 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003224
Takashi Iwai185d99f2012-02-16 18:39:45 +01003225static bool alc_map_singles(struct hda_codec *codec, int outs,
3226 const hda_nid_t *pins, hda_nid_t *dacs)
3227{
3228 int i;
3229 bool found = false;
3230 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003231 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003232 if (dacs[i])
3233 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003234 dac = get_dac_if_single(codec, pins[i]);
3235 if (!dac)
3236 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003237 if (add_new_nid_path(codec, dac, pins[i], 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003238 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003239 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003240 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003241 }
3242 return found;
3243}
3244
Takashi Iwai7085ec12009-10-02 09:03:58 +02003245/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003246static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003247 bool fill_hardwired,
3248 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003249{
3250 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003251 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003252 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003253
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003254 /* set num_dacs once to full for alc_auto_look_for_dac() */
3255 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003256 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003257 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3258 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3259 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003260 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003261 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003262 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003263
3264 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003265 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003266 bool mapped;
3267 do {
3268 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003269 cfg->line_out_pins,
3270 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003271 mapped |= alc_map_singles(codec, cfg->hp_outs,
3272 cfg->hp_pins,
3273 spec->multiout.hp_out_nid);
3274 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3275 cfg->speaker_pins,
3276 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003277 if (fill_mio_first && cfg->line_outs == 1 &&
3278 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3279 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3280 if (!err)
3281 mapped = true;
3282 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003283 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003284 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003285
Takashi Iwaidc31b582012-02-17 17:27:53 +01003286 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3287 spec->private_dac_nids,
3288 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003289
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003290 /* re-count num_dacs and squash invalid entries */
3291 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003292 for (i = 0; i < cfg->line_outs; i++) {
3293 if (spec->private_dac_nids[i])
3294 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003295 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003296 memmove(spec->private_dac_nids + i,
3297 spec->private_dac_nids + i + 1,
3298 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003299 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3300 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003301 }
3302
Takashi Iwai276dd702012-02-17 16:17:03 +01003303 if (fill_mio_first &&
3304 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003305 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003306 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003307 if (err < 0)
3308 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003309 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003310 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003311
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003312 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003313 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3314 spec->multiout.hp_out_nid,
3315 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003316 if (err < 0)
3317 return err;
3318 badness += err;
3319 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003320 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003321 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3322 cfg->speaker_pins,
3323 spec->multiout.extra_out_nid,
3324 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003325 if (err < 0)
3326 return err;
3327 badness += err;
3328 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003329 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3330 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003331 if (err < 0)
3332 return err;
3333 badness += err;
3334 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003335 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3336 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003337 int offset = 0;
3338 if (cfg->line_outs >= 3)
3339 offset = 1;
3340 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3341 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003342 if (err < 0)
3343 return err;
3344 badness += err;
3345 }
3346
3347 if (spec->multi_ios == 2) {
3348 for (i = 0; i < 2; i++)
3349 spec->private_dac_nids[spec->multiout.num_dacs++] =
3350 spec->multi_io[i].dac;
3351 spec->ext_channel_count = 2;
3352 } else if (spec->multi_ios) {
3353 spec->multi_ios = 0;
3354 badness += BAD_MULTI_IO;
3355 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003356
3357 return badness;
3358}
3359
3360#define DEBUG_BADNESS
3361
3362#ifdef DEBUG_BADNESS
3363#define debug_badness snd_printdd
3364#else
3365#define debug_badness(...)
3366#endif
3367
3368static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3369{
3370 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3371 cfg->line_out_pins[0], cfg->line_out_pins[1],
3372 cfg->line_out_pins[2], cfg->line_out_pins[2],
3373 spec->multiout.dac_nids[0],
3374 spec->multiout.dac_nids[1],
3375 spec->multiout.dac_nids[2],
3376 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003377 if (spec->multi_ios > 0)
3378 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3379 spec->multi_ios,
3380 spec->multi_io[0].pin, spec->multi_io[1].pin,
3381 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003382 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3383 cfg->hp_pins[0], cfg->hp_pins[1],
3384 cfg->hp_pins[2], cfg->hp_pins[2],
3385 spec->multiout.hp_out_nid[0],
3386 spec->multiout.hp_out_nid[1],
3387 spec->multiout.hp_out_nid[2],
3388 spec->multiout.hp_out_nid[3]);
3389 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3390 cfg->speaker_pins[0], cfg->speaker_pins[1],
3391 cfg->speaker_pins[2], cfg->speaker_pins[3],
3392 spec->multiout.extra_out_nid[0],
3393 spec->multiout.extra_out_nid[1],
3394 spec->multiout.extra_out_nid[2],
3395 spec->multiout.extra_out_nid[3]);
3396}
3397
Takashi Iwai463419d2012-12-05 14:17:37 +01003398/* find all available DACs of the codec */
3399static void alc_fill_all_nids(struct hda_codec *codec)
3400{
3401 struct alc_spec *spec = codec->spec;
3402 int i;
3403 hda_nid_t nid = codec->start_nid;
3404
3405 spec->num_all_dacs = 0;
3406 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3407 for (i = 0; i < codec->num_nodes; i++, nid++) {
3408 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3409 continue;
3410 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3411 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3412 break;
3413 }
3414 spec->all_dacs[spec->num_all_dacs++] = nid;
3415 }
3416}
3417
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003418static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3419{
3420 struct alc_spec *spec = codec->spec;
3421 struct auto_pin_cfg *cfg = &spec->autocfg;
3422 struct auto_pin_cfg *best_cfg;
3423 int best_badness = INT_MAX;
3424 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003425 bool fill_hardwired = true, fill_mio_first = true;
3426 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003427 bool hp_spk_swapped = false;
3428
Takashi Iwai463419d2012-12-05 14:17:37 +01003429 alc_fill_all_nids(codec);
3430
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003431 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3432 if (!best_cfg)
3433 return -ENOMEM;
3434 *best_cfg = *cfg;
3435
3436 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003437 badness = fill_and_eval_dacs(codec, fill_hardwired,
3438 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003439 if (badness < 0) {
3440 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003441 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003442 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003443 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3444 cfg->line_out_type, fill_hardwired, fill_mio_first,
3445 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003446 debug_show_configs(spec, cfg);
3447 if (badness < best_badness) {
3448 best_badness = badness;
3449 *best_cfg = *cfg;
3450 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003451 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003452 }
3453 if (!badness)
3454 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003455 fill_mio_first = !fill_mio_first;
3456 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003457 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003458 fill_hardwired = !fill_hardwired;
3459 if (!fill_hardwired)
3460 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003461 if (hp_spk_swapped)
3462 break;
3463 hp_spk_swapped = true;
3464 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003465 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3466 cfg->hp_outs = cfg->line_outs;
3467 memcpy(cfg->hp_pins, cfg->line_out_pins,
3468 sizeof(cfg->hp_pins));
3469 cfg->line_outs = cfg->speaker_outs;
3470 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3471 sizeof(cfg->speaker_pins));
3472 cfg->speaker_outs = 0;
3473 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3474 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003475 fill_hardwired = true;
3476 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003477 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003478 if (cfg->hp_outs > 0 &&
3479 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3480 cfg->speaker_outs = cfg->line_outs;
3481 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3482 sizeof(cfg->speaker_pins));
3483 cfg->line_outs = cfg->hp_outs;
3484 memcpy(cfg->line_out_pins, cfg->hp_pins,
3485 sizeof(cfg->hp_pins));
3486 cfg->hp_outs = 0;
3487 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3488 cfg->line_out_type = AUTO_PIN_HP_OUT;
3489 fill_hardwired = true;
3490 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003491 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003492 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003493 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003494
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003495 if (badness) {
3496 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003497 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003498 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003499 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3500 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003501 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003502
Takashi Iwaiba8111272012-12-06 18:06:23 +01003503 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003504 struct nid_path *path = get_nid_path(codec,
3505 spec->multiout.dac_nids[0],
3506 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003507 if (path)
3508 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3509 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003510
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003511 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003512 return 0;
3513}
3514
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003515/* replace the channels in the composed amp value with the given number */
3516static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3517{
3518 val &= ~(0x3U << 16);
3519 val |= chs << 16;
3520 return val;
3521}
3522
Takashi Iwai343a04b2011-07-06 14:28:39 +02003523static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003524 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003525 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003526 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003527{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003528 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003529 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003530 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003531 val = path->ctls[NID_PATH_VOL_CTL];
3532 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003533 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003534 val = amp_val_replace_channels(val, chs);
3535 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3536}
3537
3538/* return the channel bits suitable for the given path->ctls[] */
3539static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3540 int type)
3541{
3542 int chs = 1; /* mono (left only) */
3543 if (path) {
3544 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3545 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3546 chs = 3; /* stereo */
3547 }
3548 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003549}
3550
Takashi Iwaie29d3772011-11-14 17:13:23 +01003551static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3552 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003553 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003554{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003555 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3556 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003557}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003558
3559/* create a mute-switch for the given mixer widget;
3560 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3561 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003562static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003563 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003564 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003565 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003566{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003567 unsigned int val;
3568 int type = ALC_CTL_WIDGET_MUTE;
3569
3570 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003571 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003572 val = path->ctls[NID_PATH_MUTE_CTL];
3573 if (!val)
3574 return 0;
3575 val = amp_val_replace_channels(val, chs);
3576 if (get_amp_direction_(val) == HDA_INPUT) {
3577 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003578 int nums = snd_hda_get_num_conns(codec, nid);
3579 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003580 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003581 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003582 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003583 }
3584 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003585}
3586
Takashi Iwaie29d3772011-11-14 17:13:23 +01003587static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003588 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003589{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003590 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3591 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003592}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003593
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003594static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003595 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003596{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003597 int i;
3598
3599 for (i = path->depth - 1; i >= 0; i--) {
3600 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3601 return path->path[i];
3602 if (i != path->depth - 1 && i != 0 &&
3603 nid_has_mute(codec, path->path[i], HDA_INPUT))
3604 return path->path[i];
3605 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003606 return 0;
3607}
3608
3609static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003610 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003611{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003612 int i;
3613
3614 for (i = path->depth - 1; i >= 0; i--) {
3615 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3616 return path->path[i];
3617 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003618 return 0;
3619}
3620
Takashi Iwai7085ec12009-10-02 09:03:58 +02003621/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003622static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003623 const struct auto_pin_cfg *cfg)
3624{
3625 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003626 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003627
Takashi Iwaice764ab2011-04-27 16:35:23 +02003628 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003629 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003630 noutputs += spec->multi_ios;
3631
3632 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003633 const char *name;
3634 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003635 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003636 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003637
3638 dac = spec->multiout.dac_nids[i];
3639 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003640 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003641 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003642 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003643 index = 0;
3644 name = channel_name[i];
3645 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003646 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003647 name = alc_get_line_out_pfx(spec, i, true, &index);
3648 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003649
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003650 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003651 if (!path)
3652 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003653 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003654 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003655 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003656 if (err < 0)
3657 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003658 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003659 if (err < 0)
3660 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003661 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003662 if (err < 0)
3663 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003664 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003665 if (err < 0)
3666 return err;
3667 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003668 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003669 if (err < 0)
3670 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003671 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003672 if (err < 0)
3673 return err;
3674 }
3675 }
3676 return 0;
3677}
3678
Takashi Iwai343a04b2011-07-06 14:28:39 +02003679static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003680 hda_nid_t dac, const char *pfx,
3681 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003682{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003683 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003684 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003685
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003686 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003687 if (!path)
3688 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003689 /* bind volume control will be created in the case of dac = 0 */
3690 if (dac) {
3691 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3692 if (err < 0)
3693 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003694 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003695 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003696 if (err < 0)
3697 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003698 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003699}
3700
Takashi Iwai23c09b02011-08-19 09:05:35 +02003701static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3702 unsigned int nums,
3703 struct hda_ctl_ops *ops)
3704{
3705 struct alc_spec *spec = codec->spec;
3706 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003707 ctlp = snd_array_new(&spec->bind_ctls);
3708 if (!ctlp)
3709 return NULL;
3710 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3711 *ctlp = ctl;
3712 if (ctl)
3713 ctl->ops = ops;
3714 return ctl;
3715}
3716
3717/* add playback controls for speaker and HP outputs */
3718static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3719 const hda_nid_t *pins,
3720 const hda_nid_t *dacs,
3721 const char *pfx)
3722{
3723 struct alc_spec *spec = codec->spec;
3724 struct hda_bind_ctls *ctl;
3725 char name[32];
3726 int i, n, err;
3727
3728 if (!num_pins || !pins[0])
3729 return 0;
3730
Takashi Iwai527e4d72011-10-27 16:33:27 +02003731 if (num_pins == 1) {
3732 hda_nid_t dac = *dacs;
3733 if (!dac)
3734 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003735 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003736 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003737
Takashi Iwai23c09b02011-08-19 09:05:35 +02003738 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003739 hda_nid_t dac;
3740 if (dacs[num_pins - 1])
3741 dac = dacs[i]; /* with individual volumes */
3742 else
3743 dac = 0;
3744 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3745 err = alc_auto_create_extra_out(codec, pins[i], dac,
3746 "Bass Speaker", 0);
3747 } else if (num_pins >= 3) {
3748 snprintf(name, sizeof(name), "%s %s",
3749 pfx, channel_name[i]);
3750 err = alc_auto_create_extra_out(codec, pins[i], dac,
3751 name, 0);
3752 } else {
3753 err = alc_auto_create_extra_out(codec, pins[i], dac,
3754 pfx, i);
3755 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003756 if (err < 0)
3757 return err;
3758 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003759 if (dacs[num_pins - 1])
3760 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003761
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003762 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003763 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3764 if (!ctl)
3765 return -ENOMEM;
3766 n = 0;
3767 for (i = 0; i < num_pins; i++) {
3768 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003769 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003770 if (!pins[i] || !dacs[i])
3771 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003772 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003773 if (!path)
3774 continue;
3775 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003776 if (vol)
3777 ctl->values[n++] =
3778 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3779 }
3780 if (n) {
3781 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3782 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3783 if (err < 0)
3784 return err;
3785 }
3786 return 0;
3787}
3788
Takashi Iwai343a04b2011-07-06 14:28:39 +02003789static int alc_auto_create_hp_out(struct hda_codec *codec)
3790{
3791 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003792 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3793 spec->autocfg.hp_pins,
3794 spec->multiout.hp_out_nid,
3795 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003796}
3797
3798static int alc_auto_create_speaker_out(struct hda_codec *codec)
3799{
3800 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003801 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3802 spec->autocfg.speaker_pins,
3803 spec->multiout.extra_out_nid,
3804 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003805}
3806
Takashi Iwai130e5f02012-12-14 16:09:29 +01003807/* check whether a control with the given (nid, dir, idx) was assigned */
3808static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3809 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003810{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003811 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003812 int i, type;
3813
3814 for (i = 0; i < spec->paths.used; i++) {
3815 struct nid_path *p = snd_array_elem(&spec->paths, i);
3816 if (p->depth <= 0)
3817 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003818 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003819 unsigned int val = p->ctls[type];
3820 if (get_amp_nid_(val) == nid &&
3821 get_amp_direction_(val) == dir &&
3822 get_amp_index_(val) == idx)
3823 return true;
3824 }
3825 }
3826 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003827}
3828
3829/* can have the amp-in capability? */
3830static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3831{
3832 hda_nid_t nid = path->path[idx];
3833 unsigned int caps = get_wcaps(codec, nid);
3834 unsigned int type = get_wcaps_type(caps);
3835
3836 if (!(caps & AC_WCAP_IN_AMP))
3837 return false;
3838 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3839 return false;
3840 return true;
3841}
3842
3843/* can have the amp-out capability? */
3844static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3845{
3846 hda_nid_t nid = path->path[idx];
3847 unsigned int caps = get_wcaps(codec, nid);
3848 unsigned int type = get_wcaps_type(caps);
3849
3850 if (!(caps & AC_WCAP_OUT_AMP))
3851 return false;
3852 if (type == AC_WID_PIN && !idx) /* only for output pins */
3853 return false;
3854 return true;
3855}
3856
Takashi Iwaic9967f12012-12-14 16:39:22 +01003857/* check whether the given (nid,dir,idx) is active */
3858static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3859 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003860{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003861 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003862 int i, n;
3863
Takashi Iwaic9967f12012-12-14 16:39:22 +01003864 for (n = 0; n < spec->paths.used; n++) {
3865 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003866 if (!path->active)
3867 continue;
3868 for (i = 0; i < path->depth; i++) {
3869 if (path->path[i] == nid) {
3870 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3871 return true;
3872 break;
3873 }
3874 }
3875 }
3876 return false;
3877}
3878
Takashi Iwai130e5f02012-12-14 16:09:29 +01003879/* get the default amp value for the target state */
3880static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3881 int dir, bool enable)
3882{
3883 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003884 unsigned int val = 0;
3885
3886 caps = query_amp_caps(codec, nid, dir);
3887 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003888 /* set to 0dB */
3889 if (enable)
3890 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003891 }
3892 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003893 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003894 val |= HDA_AMP_MUTE;
3895 }
3896 return val;
3897}
3898
Takashi Iwai130e5f02012-12-14 16:09:29 +01003899/* initialize the amp value (only at the first time) */
3900static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3901{
3902 int val = get_amp_val_to_activate(codec, nid, dir, false);
3903 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3904}
3905
3906static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3907 int idx, bool enable)
3908{
3909 int val;
3910 if (is_ctl_associated(codec, nid, dir, idx) ||
3911 is_active_nid(codec, nid, dir, idx))
3912 return;
3913 val = get_amp_val_to_activate(codec, nid, dir, enable);
3914 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3915}
3916
3917static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3918 int i, bool enable)
3919{
3920 hda_nid_t nid = path->path[i];
3921 init_amp(codec, nid, HDA_OUTPUT, 0);
3922 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3923}
3924
3925static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003926 int i, bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003927{
3928 struct alc_spec *spec = codec->spec;
3929 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003930 int n, nums, idx;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003931 int type;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003932 hda_nid_t nid = path->path[i];
3933
3934 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai666a70d2012-12-17 20:29:29 +01003935 type = get_wcaps_type(get_wcaps(codec, nid));
3936 if (type == AC_WID_PIN ||
3937 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003938 nums = 1;
3939 idx = 0;
3940 } else
3941 idx = path->idx[i];
3942
Takashi Iwai130e5f02012-12-14 16:09:29 +01003943 for (n = 0; n < nums; n++)
3944 init_amp(codec, nid, HDA_INPUT, n);
3945
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003946 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003947 return;
3948
3949 /* here is a little bit tricky in comparison with activate_amp_out();
3950 * when aa-mixer is available, we need to enable the path as well
3951 */
3952 for (n = 0; n < nums; n++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01003953 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003954 continue;
3955 activate_amp(codec, nid, HDA_INPUT, n, enable);
3956 }
3957}
3958
3959static void activate_path(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003960 bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003961{
3962 int i;
3963
Takashi Iwai130e5f02012-12-14 16:09:29 +01003964 if (!enable)
3965 path->active = false;
3966
3967 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003968 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003969 snd_hda_codec_write_cache(codec, path->path[i], 0,
3970 AC_VERB_SET_CONNECT_SEL,
3971 path->idx[i]);
3972 if (has_amp_in(codec, path, i))
Takashi Iwai666a70d2012-12-17 20:29:29 +01003973 activate_amp_in(codec, path, i, enable, add_aamix);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003974 if (has_amp_out(codec, path, i))
3975 activate_amp_out(codec, path, i, enable);
3976 }
3977
3978 if (enable)
3979 path->active = true;
3980}
3981
Takashi Iwai78e635c2012-12-10 17:07:16 +01003982/* configure the path from the given dac to the pin as the proper output */
3983static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3984 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003985 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003986{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003987 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003988
Takashi Iwai130e5f02012-12-14 16:09:29 +01003989 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003990 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003991 if (!path)
3992 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003993 if (path->active)
3994 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003995 activate_path(codec, path, true, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003996}
3997
Takashi Iwai343a04b2011-07-06 14:28:39 +02003998static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003999{
4000 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02004001 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004002 int i;
4003
4004 for (i = 0; i <= HDA_SIDE; i++) {
4005 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4006 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02004007 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01004008 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004009
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004010 }
4011}
4012
Takashi Iwai343a04b2011-07-06 14:28:39 +02004013static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004014{
4015 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004016 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004017 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004018
David Henningsson636030e2011-10-12 19:26:03 +02004019 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004020 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4021 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02004022 pin = spec->autocfg.hp_pins[i];
4023 if (!pin)
4024 break;
4025 dac = spec->multiout.hp_out_nid[i];
4026 if (!dac) {
4027 if (i > 0 && spec->multiout.hp_out_nid[0])
4028 dac = spec->multiout.hp_out_nid[0];
4029 else
4030 dac = spec->multiout.dac_nids[0];
4031 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004032 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004033 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02004034 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004035 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4036 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004037 pin = spec->autocfg.speaker_pins[i];
4038 if (!pin)
4039 break;
4040 dac = spec->multiout.extra_out_nid[i];
4041 if (!dac) {
4042 if (i > 0 && spec->multiout.extra_out_nid[0])
4043 dac = spec->multiout.extra_out_nid[0];
4044 else
4045 dac = spec->multiout.dac_nids[0];
4046 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004047 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004048 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004049}
4050
Takashi Iwai276dd702012-02-17 16:17:03 +01004051/* check whether the given pin can be a multi-io pin */
4052static bool can_be_multiio_pin(struct hda_codec *codec,
4053 unsigned int location, hda_nid_t nid)
4054{
4055 unsigned int defcfg, caps;
4056
4057 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4058 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4059 return false;
4060 if (location && get_defcfg_location(defcfg) != location)
4061 return false;
4062 caps = snd_hda_query_pin_caps(codec, nid);
4063 if (!(caps & AC_PINCAP_OUT))
4064 return false;
4065 return true;
4066}
4067
Takashi Iwaice764ab2011-04-27 16:35:23 +02004068/*
4069 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004070 *
4071 * When hardwired is set, try to fill ony hardwired pins, and returns
4072 * zero if any pins are filled, non-zero if nothing found.
4073 * When hardwired is off, try to fill possible input pins, and returns
4074 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004075 */
4076static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004077 hda_nid_t reference_pin,
4078 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004079{
4080 struct alc_spec *spec = codec->spec;
4081 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004082 int type, i, j, dacs, num_pins, old_pins;
4083 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4084 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004085 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004086
Takashi Iwai276dd702012-02-17 16:17:03 +01004087 old_pins = spec->multi_ios;
4088 if (old_pins >= 2)
4089 goto end_fill;
4090
4091 num_pins = 0;
4092 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4093 for (i = 0; i < cfg->num_inputs; i++) {
4094 if (cfg->inputs[i].type != type)
4095 continue;
4096 if (can_be_multiio_pin(codec, location,
4097 cfg->inputs[i].pin))
4098 num_pins++;
4099 }
4100 }
4101 if (num_pins < 2)
4102 goto end_fill;
4103
Takashi Iwai07b18f62011-11-10 15:42:54 +01004104 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004105 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4106 for (i = 0; i < cfg->num_inputs; i++) {
4107 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004108 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004109
Takashi Iwaice764ab2011-04-27 16:35:23 +02004110 if (cfg->inputs[i].type != type)
4111 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004112 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004113 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004114 for (j = 0; j < spec->multi_ios; j++) {
4115 if (nid == spec->multi_io[j].pin)
4116 break;
4117 }
4118 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004119 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004120
4121 if (offset && offset + spec->multi_ios < dacs) {
4122 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004123 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004124 dac = 0;
4125 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004126 if (hardwired)
4127 dac = get_dac_if_single(codec, nid);
4128 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004129 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004130 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004131 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004132 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004133 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01004134 if (!add_new_nid_path(codec, dac, nid, 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004135 badness++;
4136 continue;
4137 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004138 spec->multi_io[spec->multi_ios].pin = nid;
4139 spec->multi_io[spec->multi_ios].dac = dac;
4140 spec->multi_ios++;
4141 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004142 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004143 }
4144 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004145 end_fill:
4146 if (badness)
4147 badness = BAD_MULTI_IO;
4148 if (old_pins == spec->multi_ios) {
4149 if (hardwired)
4150 return 1; /* nothing found */
4151 else
4152 return badness; /* no badness if nothing found */
4153 }
4154 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004155 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004156 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004157 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004158 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004159 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004160
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004161 /* assign volume and mute controls */
4162 for (i = old_pins; i < spec->multi_ios; i++)
4163 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4164 spec->multi_io[i].dac);
4165
4166 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004167}
4168
4169static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4170 struct snd_ctl_elem_info *uinfo)
4171{
4172 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4173 struct alc_spec *spec = codec->spec;
4174
4175 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4176 uinfo->count = 1;
4177 uinfo->value.enumerated.items = spec->multi_ios + 1;
4178 if (uinfo->value.enumerated.item > spec->multi_ios)
4179 uinfo->value.enumerated.item = spec->multi_ios;
4180 sprintf(uinfo->value.enumerated.name, "%dch",
4181 (uinfo->value.enumerated.item + 1) * 2);
4182 return 0;
4183}
4184
4185static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4186 struct snd_ctl_elem_value *ucontrol)
4187{
4188 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4189 struct alc_spec *spec = codec->spec;
4190 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4191 return 0;
4192}
4193
4194static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4195{
4196 struct alc_spec *spec = codec->spec;
4197 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004198 struct nid_path *path;
4199
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004200 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004201 if (!path)
4202 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004203
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004204 if (path->active == output)
4205 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004206
Takashi Iwaice764ab2011-04-27 16:35:23 +02004207 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004208 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004209 activate_path(codec, path, true, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004210 } else {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004211 activate_path(codec, path, false, true);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004212 snd_hda_set_pin_ctl_cache(codec, nid,
4213 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004214 }
4215 return 0;
4216}
4217
4218static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4219 struct snd_ctl_elem_value *ucontrol)
4220{
4221 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4222 struct alc_spec *spec = codec->spec;
4223 int i, ch;
4224
4225 ch = ucontrol->value.enumerated.item[0];
4226 if (ch < 0 || ch > spec->multi_ios)
4227 return -EINVAL;
4228 if (ch == (spec->ext_channel_count - 1) / 2)
4229 return 0;
4230 spec->ext_channel_count = (ch + 1) * 2;
4231 for (i = 0; i < spec->multi_ios; i++)
4232 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004233 spec->multiout.max_channels = max(spec->ext_channel_count,
4234 spec->const_channel_count);
4235 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004236 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004237 return 1;
4238}
4239
Takashi Iwaia9111322011-05-02 11:30:18 +02004240static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004241 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4242 .name = "Channel Mode",
4243 .info = alc_auto_ch_mode_info,
4244 .get = alc_auto_ch_mode_get,
4245 .put = alc_auto_ch_mode_put,
4246};
4247
Takashi Iwai23c09b02011-08-19 09:05:35 +02004248static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004249{
4250 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004251
Takashi Iwaic2674682011-08-24 17:57:44 +02004252 if (spec->multi_ios > 0) {
Takashi Iwaibc549762012-12-18 15:35:11 +01004253 if (!alc_kcontrol_new(spec, NULL, &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004254 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004255 }
4256 return 0;
4257}
4258
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004259static void alc_auto_init_multi_io(struct hda_codec *codec)
4260{
4261 struct alc_spec *spec = codec->spec;
4262 int i;
4263
4264 for (i = 0; i < spec->multi_ios; i++) {
4265 hda_nid_t pin = spec->multi_io[i].pin;
4266 struct nid_path *path;
4267 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4268 if (!path)
4269 continue;
4270 if (!spec->multi_io[i].ctl_in)
4271 spec->multi_io[i].ctl_in =
4272 snd_hda_codec_update_cache(codec, pin, 0,
4273 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004274 activate_path(codec, path, path->active, true);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004275 }
4276}
4277
Takashi Iwai1d045db2011-07-07 18:23:21 +02004278/*
4279 * initialize ADC paths
4280 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004281static void alc_auto_init_input_src(struct hda_codec *codec)
4282{
4283 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01004284 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004285 struct nid_path *path;
4286 int i, c, nums;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004287
Takashi Iwai1d045db2011-07-07 18:23:21 +02004288 if (spec->dyn_adc_switch)
4289 nums = 1;
4290 else
4291 nums = spec->num_adc_nids;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004292
4293 for (c = 0; c < nums; c++) {
4294 for (i = 0; i < imux->num_items; i++) {
4295 path = get_nid_path(codec, spec->imux_pins[i],
4296 get_adc_nid(codec, c, i));
4297 if (path) {
4298 bool active = path->active;
4299 if (i == spec->cur_mux[c])
4300 active = true;
4301 activate_path(codec, path, active, false);
4302 }
4303 }
4304 }
4305
4306 alc_inv_dmic_sync(codec, true);
4307 if (spec->shared_mic_hp)
4308 update_shared_mic_hp(codec, spec->cur_mux[0]);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004309}
4310
4311/* add mic boosts if needed */
4312static int alc_auto_add_mic_boost(struct hda_codec *codec)
4313{
4314 struct alc_spec *spec = codec->spec;
4315 struct auto_pin_cfg *cfg = &spec->autocfg;
4316 int i, err;
4317 int type_idx = 0;
4318 hda_nid_t nid;
4319 const char *prev_label = NULL;
4320
4321 for (i = 0; i < cfg->num_inputs; i++) {
4322 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4323 break;
4324 nid = cfg->inputs[i].pin;
4325 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4326 const char *label;
4327 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004328 struct nid_path *path;
4329 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004330
4331 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004332 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4333 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004334 if (prev_label && !strcmp(label, prev_label))
4335 type_idx++;
4336 else
4337 type_idx = 0;
4338 prev_label = label;
4339
4340 snprintf(boost_label, sizeof(boost_label),
4341 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004342 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004343 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004344 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004345 if (err < 0)
4346 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004347
4348 path = get_nid_path(codec, nid, 0);
4349 if (path)
4350 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004351 }
4352 }
4353 return 0;
4354}
4355
Takashi Iwai1d045db2011-07-07 18:23:21 +02004356/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004357 * standard auto-parser initializations
4358 */
4359static void alc_auto_init_std(struct hda_codec *codec)
4360{
Takashi Iwaie4770622011-07-08 11:11:35 +02004361 alc_auto_init_multi_out(codec);
4362 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004363 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004364 alc_auto_init_analog_input(codec);
4365 alc_auto_init_input_src(codec);
4366 alc_auto_init_digital(codec);
Takashi Iwai2eab6942012-12-18 15:30:41 +01004367 /* call init functions of standard auto-mute helpers */
4368 alc_hp_automute(codec, NULL);
4369 alc_line_automute(codec, NULL);
4370 alc_mic_automute(codec, NULL);
Takashi Iwaie4770622011-07-08 11:11:35 +02004371}
4372
4373/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004374 * Digital-beep handlers
4375 */
4376#ifdef CONFIG_SND_HDA_INPUT_BEEP
4377#define set_beep_amp(spec, nid, idx, dir) \
4378 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4379
4380static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004381 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004382 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4383 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4384 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4385 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004386 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004387 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4388 {}
4389};
4390
4391static inline int has_cdefine_beep(struct hda_codec *codec)
4392{
4393 struct alc_spec *spec = codec->spec;
4394 const struct snd_pci_quirk *q;
4395 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4396 if (q)
4397 return q->value;
4398 return spec->cdefine.enable_pcbeep;
4399}
4400#else
4401#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4402#define has_cdefine_beep(codec) 0
4403#endif
4404
4405/* parse the BIOS configuration and set up the alc_spec */
4406/* return 1 if successful, 0 if the proper config is not found,
4407 * or a negative error code
4408 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004409static int alc_parse_auto_config(struct hda_codec *codec,
4410 const hda_nid_t *ignore_nids,
4411 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004412{
4413 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004414 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004415 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004416
Takashi Iwai53c334a2011-08-23 18:27:14 +02004417 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4418 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004419 if (err < 0)
4420 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004421 if (!cfg->line_outs) {
4422 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004423 spec->multiout.max_channels = 2;
4424 spec->no_analog = 1;
4425 goto dig_only;
4426 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004427 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004428 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004429
Takashi Iwaie427c232012-07-29 10:04:08 +02004430 if (!spec->no_primary_hp &&
4431 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004432 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004433 /* use HP as primary out */
4434 cfg->speaker_outs = cfg->line_outs;
4435 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4436 sizeof(cfg->speaker_pins));
4437 cfg->line_outs = cfg->hp_outs;
4438 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4439 cfg->hp_outs = 0;
4440 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4441 cfg->line_out_type = AUTO_PIN_HP_OUT;
4442 }
4443
Takashi Iwai1d045db2011-07-07 18:23:21 +02004444 err = alc_auto_fill_dac_nids(codec);
4445 if (err < 0)
4446 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004447 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004448 if (err < 0)
4449 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004450 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004451 if (err < 0)
4452 return err;
4453 err = alc_auto_create_hp_out(codec);
4454 if (err < 0)
4455 return err;
4456 err = alc_auto_create_speaker_out(codec);
4457 if (err < 0)
4458 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004459 err = alc_auto_create_shared_input(codec);
4460 if (err < 0)
4461 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004462 err = alc_auto_create_input_ctls(codec);
4463 if (err < 0)
4464 return err;
4465
Takashi Iwaib6adb572012-12-03 10:30:58 +01004466 /* check the multiple speaker pins */
4467 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4468 spec->const_channel_count = cfg->line_outs * 2;
4469 else
4470 spec->const_channel_count = cfg->speaker_outs * 2;
4471
4472 if (spec->multi_ios > 0)
4473 spec->multiout.max_channels = max(spec->ext_channel_count,
4474 spec->const_channel_count);
4475 else
4476 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004477
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004478 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004479 alc_auto_parse_digital(codec);
4480
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004481 if (ssid_nids)
4482 alc_ssid_check(codec, ssid_nids);
4483
4484 if (!spec->no_analog) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004485 err = alc_init_automute(codec);
Takashi Iwai475c3d22012-11-30 08:31:30 +01004486 if (err < 0)
4487 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004488
4489 err = check_dyn_adc_switch(codec);
4490 if (err < 0)
4491 return err;
4492
4493 if (!spec->shared_mic_hp) {
4494 err = alc_init_auto_mic(codec);
4495 if (err < 0)
4496 return err;
4497 }
4498
4499 err = create_capture_mixers(codec);
4500 if (err < 0)
4501 return err;
4502
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004503 err = alc_auto_add_mic_boost(codec);
4504 if (err < 0)
4505 return err;
4506 }
4507
Takashi Iwai1d045db2011-07-07 18:23:21 +02004508 if (spec->kctls.list)
4509 add_mixer(spec, spec->kctls.list);
4510
Takashi Iwai1d045db2011-07-07 18:23:21 +02004511 return 1;
4512}
4513
Takashi Iwai3de95172012-05-07 18:03:15 +02004514/* common preparation job for alc_spec */
4515static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4516{
4517 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4518 int err;
4519
4520 if (!spec)
4521 return -ENOMEM;
4522 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004523 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004524 spec->mixer_nid = mixer_nid;
Takashi Iwai361dab32012-05-09 14:35:27 +02004525 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4526 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004527 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004528
4529 err = alc_codec_rename_from_preset(codec);
4530 if (err < 0) {
4531 kfree(spec);
4532 return err;
4533 }
4534 return 0;
4535}
4536
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004537static int alc880_parse_auto_config(struct hda_codec *codec)
4538{
4539 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004540 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004541 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4542}
4543
Takashi Iwai1d045db2011-07-07 18:23:21 +02004544/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004545 * ALC880 fix-ups
4546 */
4547enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004548 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004549 ALC880_FIXUP_GPIO2,
4550 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004551 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004552 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004553 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004554 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004555 ALC880_FIXUP_VOL_KNOB,
4556 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004557 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004558 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004559 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004560 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004561 ALC880_FIXUP_3ST_BASE,
4562 ALC880_FIXUP_3ST,
4563 ALC880_FIXUP_3ST_DIG,
4564 ALC880_FIXUP_5ST_BASE,
4565 ALC880_FIXUP_5ST,
4566 ALC880_FIXUP_5ST_DIG,
4567 ALC880_FIXUP_6ST_BASE,
4568 ALC880_FIXUP_6ST,
4569 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004570};
4571
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004572/* enable the volume-knob widget support on NID 0x21 */
4573static void alc880_fixup_vol_knob(struct hda_codec *codec,
4574 const struct alc_fixup *fix, int action)
4575{
4576 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004577 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004578}
4579
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004580static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004581 [ALC880_FIXUP_GPIO1] = {
4582 .type = ALC_FIXUP_VERBS,
4583 .v.verbs = alc_gpio1_init_verbs,
4584 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004585 [ALC880_FIXUP_GPIO2] = {
4586 .type = ALC_FIXUP_VERBS,
4587 .v.verbs = alc_gpio2_init_verbs,
4588 },
4589 [ALC880_FIXUP_MEDION_RIM] = {
4590 .type = ALC_FIXUP_VERBS,
4591 .v.verbs = (const struct hda_verb[]) {
4592 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4593 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4594 { }
4595 },
4596 .chained = true,
4597 .chain_id = ALC880_FIXUP_GPIO2,
4598 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004599 [ALC880_FIXUP_LG] = {
4600 .type = ALC_FIXUP_PINS,
4601 .v.pins = (const struct alc_pincfg[]) {
4602 /* disable bogus unused pins */
4603 { 0x16, 0x411111f0 },
4604 { 0x18, 0x411111f0 },
4605 { 0x1a, 0x411111f0 },
4606 { }
4607 }
4608 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004609 [ALC880_FIXUP_W810] = {
4610 .type = ALC_FIXUP_PINS,
4611 .v.pins = (const struct alc_pincfg[]) {
4612 /* disable bogus unused pins */
4613 { 0x17, 0x411111f0 },
4614 { }
4615 },
4616 .chained = true,
4617 .chain_id = ALC880_FIXUP_GPIO2,
4618 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004619 [ALC880_FIXUP_EAPD_COEF] = {
4620 .type = ALC_FIXUP_VERBS,
4621 .v.verbs = (const struct hda_verb[]) {
4622 /* change to EAPD mode */
4623 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4624 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4625 {}
4626 },
4627 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004628 [ALC880_FIXUP_TCL_S700] = {
4629 .type = ALC_FIXUP_VERBS,
4630 .v.verbs = (const struct hda_verb[]) {
4631 /* change to EAPD mode */
4632 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4633 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4634 {}
4635 },
4636 .chained = true,
4637 .chain_id = ALC880_FIXUP_GPIO2,
4638 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004639 [ALC880_FIXUP_VOL_KNOB] = {
4640 .type = ALC_FIXUP_FUNC,
4641 .v.func = alc880_fixup_vol_knob,
4642 },
4643 [ALC880_FIXUP_FUJITSU] = {
4644 /* override all pins as BIOS on old Amilo is broken */
4645 .type = ALC_FIXUP_PINS,
4646 .v.pins = (const struct alc_pincfg[]) {
4647 { 0x14, 0x0121411f }, /* HP */
4648 { 0x15, 0x99030120 }, /* speaker */
4649 { 0x16, 0x99030130 }, /* bass speaker */
4650 { 0x17, 0x411111f0 }, /* N/A */
4651 { 0x18, 0x411111f0 }, /* N/A */
4652 { 0x19, 0x01a19950 }, /* mic-in */
4653 { 0x1a, 0x411111f0 }, /* N/A */
4654 { 0x1b, 0x411111f0 }, /* N/A */
4655 { 0x1c, 0x411111f0 }, /* N/A */
4656 { 0x1d, 0x411111f0 }, /* N/A */
4657 { 0x1e, 0x01454140 }, /* SPDIF out */
4658 { }
4659 },
4660 .chained = true,
4661 .chain_id = ALC880_FIXUP_VOL_KNOB,
4662 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004663 [ALC880_FIXUP_F1734] = {
4664 /* almost compatible with FUJITSU, but no bass and SPDIF */
4665 .type = ALC_FIXUP_PINS,
4666 .v.pins = (const struct alc_pincfg[]) {
4667 { 0x14, 0x0121411f }, /* HP */
4668 { 0x15, 0x99030120 }, /* speaker */
4669 { 0x16, 0x411111f0 }, /* N/A */
4670 { 0x17, 0x411111f0 }, /* N/A */
4671 { 0x18, 0x411111f0 }, /* N/A */
4672 { 0x19, 0x01a19950 }, /* mic-in */
4673 { 0x1a, 0x411111f0 }, /* N/A */
4674 { 0x1b, 0x411111f0 }, /* N/A */
4675 { 0x1c, 0x411111f0 }, /* N/A */
4676 { 0x1d, 0x411111f0 }, /* N/A */
4677 { 0x1e, 0x411111f0 }, /* N/A */
4678 { }
4679 },
4680 .chained = true,
4681 .chain_id = ALC880_FIXUP_VOL_KNOB,
4682 },
Takashi Iwai817de922012-02-20 17:20:48 +01004683 [ALC880_FIXUP_UNIWILL] = {
4684 /* need to fix HP and speaker pins to be parsed correctly */
4685 .type = ALC_FIXUP_PINS,
4686 .v.pins = (const struct alc_pincfg[]) {
4687 { 0x14, 0x0121411f }, /* HP */
4688 { 0x15, 0x99030120 }, /* speaker */
4689 { 0x16, 0x99030130 }, /* bass speaker */
4690 { }
4691 },
4692 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004693 [ALC880_FIXUP_UNIWILL_DIG] = {
4694 .type = ALC_FIXUP_PINS,
4695 .v.pins = (const struct alc_pincfg[]) {
4696 /* disable bogus unused pins */
4697 { 0x17, 0x411111f0 },
4698 { 0x19, 0x411111f0 },
4699 { 0x1b, 0x411111f0 },
4700 { 0x1f, 0x411111f0 },
4701 { }
4702 }
4703 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004704 [ALC880_FIXUP_Z71V] = {
4705 .type = ALC_FIXUP_PINS,
4706 .v.pins = (const struct alc_pincfg[]) {
4707 /* set up the whole pins as BIOS is utterly broken */
4708 { 0x14, 0x99030120 }, /* speaker */
4709 { 0x15, 0x0121411f }, /* HP */
4710 { 0x16, 0x411111f0 }, /* N/A */
4711 { 0x17, 0x411111f0 }, /* N/A */
4712 { 0x18, 0x01a19950 }, /* mic-in */
4713 { 0x19, 0x411111f0 }, /* N/A */
4714 { 0x1a, 0x01813031 }, /* line-in */
4715 { 0x1b, 0x411111f0 }, /* N/A */
4716 { 0x1c, 0x411111f0 }, /* N/A */
4717 { 0x1d, 0x411111f0 }, /* N/A */
4718 { 0x1e, 0x0144111e }, /* SPDIF */
4719 { }
4720 }
4721 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004722 [ALC880_FIXUP_3ST_BASE] = {
4723 .type = ALC_FIXUP_PINS,
4724 .v.pins = (const struct alc_pincfg[]) {
4725 { 0x14, 0x01014010 }, /* line-out */
4726 { 0x15, 0x411111f0 }, /* N/A */
4727 { 0x16, 0x411111f0 }, /* N/A */
4728 { 0x17, 0x411111f0 }, /* N/A */
4729 { 0x18, 0x01a19c30 }, /* mic-in */
4730 { 0x19, 0x0121411f }, /* HP */
4731 { 0x1a, 0x01813031 }, /* line-in */
4732 { 0x1b, 0x02a19c40 }, /* front-mic */
4733 { 0x1c, 0x411111f0 }, /* N/A */
4734 { 0x1d, 0x411111f0 }, /* N/A */
4735 /* 0x1e is filled in below */
4736 { 0x1f, 0x411111f0 }, /* N/A */
4737 { }
4738 }
4739 },
4740 [ALC880_FIXUP_3ST] = {
4741 .type = ALC_FIXUP_PINS,
4742 .v.pins = (const struct alc_pincfg[]) {
4743 { 0x1e, 0x411111f0 }, /* N/A */
4744 { }
4745 },
4746 .chained = true,
4747 .chain_id = ALC880_FIXUP_3ST_BASE,
4748 },
4749 [ALC880_FIXUP_3ST_DIG] = {
4750 .type = ALC_FIXUP_PINS,
4751 .v.pins = (const struct alc_pincfg[]) {
4752 { 0x1e, 0x0144111e }, /* SPDIF */
4753 { }
4754 },
4755 .chained = true,
4756 .chain_id = ALC880_FIXUP_3ST_BASE,
4757 },
4758 [ALC880_FIXUP_5ST_BASE] = {
4759 .type = ALC_FIXUP_PINS,
4760 .v.pins = (const struct alc_pincfg[]) {
4761 { 0x14, 0x01014010 }, /* front */
4762 { 0x15, 0x411111f0 }, /* N/A */
4763 { 0x16, 0x01011411 }, /* CLFE */
4764 { 0x17, 0x01016412 }, /* surr */
4765 { 0x18, 0x01a19c30 }, /* mic-in */
4766 { 0x19, 0x0121411f }, /* HP */
4767 { 0x1a, 0x01813031 }, /* line-in */
4768 { 0x1b, 0x02a19c40 }, /* front-mic */
4769 { 0x1c, 0x411111f0 }, /* N/A */
4770 { 0x1d, 0x411111f0 }, /* N/A */
4771 /* 0x1e is filled in below */
4772 { 0x1f, 0x411111f0 }, /* N/A */
4773 { }
4774 }
4775 },
4776 [ALC880_FIXUP_5ST] = {
4777 .type = ALC_FIXUP_PINS,
4778 .v.pins = (const struct alc_pincfg[]) {
4779 { 0x1e, 0x411111f0 }, /* N/A */
4780 { }
4781 },
4782 .chained = true,
4783 .chain_id = ALC880_FIXUP_5ST_BASE,
4784 },
4785 [ALC880_FIXUP_5ST_DIG] = {
4786 .type = ALC_FIXUP_PINS,
4787 .v.pins = (const struct alc_pincfg[]) {
4788 { 0x1e, 0x0144111e }, /* SPDIF */
4789 { }
4790 },
4791 .chained = true,
4792 .chain_id = ALC880_FIXUP_5ST_BASE,
4793 },
4794 [ALC880_FIXUP_6ST_BASE] = {
4795 .type = ALC_FIXUP_PINS,
4796 .v.pins = (const struct alc_pincfg[]) {
4797 { 0x14, 0x01014010 }, /* front */
4798 { 0x15, 0x01016412 }, /* surr */
4799 { 0x16, 0x01011411 }, /* CLFE */
4800 { 0x17, 0x01012414 }, /* side */
4801 { 0x18, 0x01a19c30 }, /* mic-in */
4802 { 0x19, 0x02a19c40 }, /* front-mic */
4803 { 0x1a, 0x01813031 }, /* line-in */
4804 { 0x1b, 0x0121411f }, /* HP */
4805 { 0x1c, 0x411111f0 }, /* N/A */
4806 { 0x1d, 0x411111f0 }, /* N/A */
4807 /* 0x1e is filled in below */
4808 { 0x1f, 0x411111f0 }, /* N/A */
4809 { }
4810 }
4811 },
4812 [ALC880_FIXUP_6ST] = {
4813 .type = ALC_FIXUP_PINS,
4814 .v.pins = (const struct alc_pincfg[]) {
4815 { 0x1e, 0x411111f0 }, /* N/A */
4816 { }
4817 },
4818 .chained = true,
4819 .chain_id = ALC880_FIXUP_6ST_BASE,
4820 },
4821 [ALC880_FIXUP_6ST_DIG] = {
4822 .type = ALC_FIXUP_PINS,
4823 .v.pins = (const struct alc_pincfg[]) {
4824 { 0x1e, 0x0144111e }, /* SPDIF */
4825 { }
4826 },
4827 .chained = true,
4828 .chain_id = ALC880_FIXUP_6ST_BASE,
4829 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004830};
4831
4832static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004833 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004834 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004835 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4836 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004837 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004838 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004839 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004840 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004841 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004842 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004843 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004844 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004845 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004846 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004847 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004848 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4849 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4850 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004851 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004852
4853 /* Below is the copied entries from alc880_quirks.c.
4854 * It's not quite sure whether BIOS sets the correct pin-config table
4855 * on these machines, thus they are kept to be compatible with
4856 * the old static quirks. Once when it's confirmed to work without
4857 * these overrides, it'd be better to remove.
4858 */
4859 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4860 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4861 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4862 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4863 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4864 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4865 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4866 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4867 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4868 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4869 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4870 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4871 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4872 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4873 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4874 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4875 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4876 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4877 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4878 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4879 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4880 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4881 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4882 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4883 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4884 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4885 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4886 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4887 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4888 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4889 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4890 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4891 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4892 /* default Intel */
4893 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4894 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4895 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4896 {}
4897};
4898
4899static const struct alc_model_fixup alc880_fixup_models[] = {
4900 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4901 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4902 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4903 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4904 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4905 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004906 {}
4907};
4908
4909
4910/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004911 * OK, here we have finally the patch for ALC880
4912 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004913static int patch_alc880(struct hda_codec *codec)
4914{
4915 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004916 int err;
4917
Takashi Iwai3de95172012-05-07 18:03:15 +02004918 err = alc_alloc_spec(codec, 0x0b);
4919 if (err < 0)
4920 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004921
Takashi Iwai3de95172012-05-07 18:03:15 +02004922 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004923 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004924
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004925 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4926 alc880_fixups);
4927 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004928
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004929 /* automatic parse from the BIOS config */
4930 err = alc880_parse_auto_config(codec);
4931 if (err < 0)
4932 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004933
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004934 if (!spec->no_analog) {
4935 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004936 if (err < 0)
4937 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004938 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4939 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004940
Takashi Iwai1d045db2011-07-07 18:23:21 +02004941 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004942 codec->patch_ops.unsol_event = alc880_unsol_event;
4943
Takashi Iwai1d045db2011-07-07 18:23:21 +02004944
Takashi Iwai589876e2012-02-20 15:47:55 +01004945 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4946
Takashi Iwai1d045db2011-07-07 18:23:21 +02004947 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004948
4949 error:
4950 alc_free(codec);
4951 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004952}
4953
4954
4955/*
4956 * ALC260 support
4957 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004958static int alc260_parse_auto_config(struct hda_codec *codec)
4959{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004960 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004961 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4962 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004963}
4964
Takashi Iwai1d045db2011-07-07 18:23:21 +02004965/*
4966 * Pin config fixes
4967 */
4968enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004969 ALC260_FIXUP_HP_DC5750,
4970 ALC260_FIXUP_HP_PIN_0F,
4971 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004972 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004973 ALC260_FIXUP_GPIO1_TOGGLE,
4974 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004975 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004976 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004977};
4978
Takashi Iwai20f7d922012-02-16 12:35:16 +01004979static void alc260_gpio1_automute(struct hda_codec *codec)
4980{
4981 struct alc_spec *spec = codec->spec;
4982 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4983 spec->hp_jack_present);
4984}
4985
4986static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4987 const struct alc_fixup *fix, int action)
4988{
4989 struct alc_spec *spec = codec->spec;
4990 if (action == ALC_FIXUP_ACT_PROBE) {
4991 /* although the machine has only one output pin, we need to
4992 * toggle GPIO1 according to the jack state
4993 */
4994 spec->automute_hook = alc260_gpio1_automute;
4995 spec->detect_hp = 1;
4996 spec->automute_speaker = 1;
4997 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004998 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4999 alc_hp_automute);
Takashi Iwaic9ce6b22012-12-18 18:12:44 +01005000 snd_hda_add_verbs(codec, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005001 }
5002}
5003
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005004static void alc260_fixup_kn1(struct hda_codec *codec,
5005 const struct alc_fixup *fix, int action)
5006{
5007 struct alc_spec *spec = codec->spec;
5008 static const struct alc_pincfg pincfgs[] = {
5009 { 0x0f, 0x02214000 }, /* HP/speaker */
5010 { 0x12, 0x90a60160 }, /* int mic */
5011 { 0x13, 0x02a19000 }, /* ext mic */
5012 { 0x18, 0x01446000 }, /* SPDIF out */
5013 /* disable bogus I/O pins */
5014 { 0x10, 0x411111f0 },
5015 { 0x11, 0x411111f0 },
5016 { 0x14, 0x411111f0 },
5017 { 0x15, 0x411111f0 },
5018 { 0x16, 0x411111f0 },
5019 { 0x17, 0x411111f0 },
5020 { 0x19, 0x411111f0 },
5021 { }
5022 };
5023
5024 switch (action) {
5025 case ALC_FIXUP_ACT_PRE_PROBE:
5026 alc_apply_pincfgs(codec, pincfgs);
5027 break;
5028 case ALC_FIXUP_ACT_PROBE:
5029 spec->init_amp = ALC_INIT_NONE;
5030 break;
5031 }
5032}
5033
Takashi Iwai1d045db2011-07-07 18:23:21 +02005034static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005035 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005036 .type = ALC_FIXUP_PINS,
5037 .v.pins = (const struct alc_pincfg[]) {
5038 { 0x11, 0x90130110 }, /* speaker */
5039 { }
5040 }
5041 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005042 [ALC260_FIXUP_HP_PIN_0F] = {
5043 .type = ALC_FIXUP_PINS,
5044 .v.pins = (const struct alc_pincfg[]) {
5045 { 0x0f, 0x01214000 }, /* HP */
5046 { }
5047 }
5048 },
5049 [ALC260_FIXUP_COEF] = {
5050 .type = ALC_FIXUP_VERBS,
5051 .v.verbs = (const struct hda_verb[]) {
5052 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5053 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5054 { }
5055 },
5056 .chained = true,
5057 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5058 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005059 [ALC260_FIXUP_GPIO1] = {
5060 .type = ALC_FIXUP_VERBS,
5061 .v.verbs = alc_gpio1_init_verbs,
5062 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005063 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5064 .type = ALC_FIXUP_FUNC,
5065 .v.func = alc260_fixup_gpio1_toggle,
5066 .chained = true,
5067 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5068 },
5069 [ALC260_FIXUP_REPLACER] = {
5070 .type = ALC_FIXUP_VERBS,
5071 .v.verbs = (const struct hda_verb[]) {
5072 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5073 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5074 { }
5075 },
5076 .chained = true,
5077 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5078 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005079 [ALC260_FIXUP_HP_B1900] = {
5080 .type = ALC_FIXUP_FUNC,
5081 .v.func = alc260_fixup_gpio1_toggle,
5082 .chained = true,
5083 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005084 },
5085 [ALC260_FIXUP_KN1] = {
5086 .type = ALC_FIXUP_FUNC,
5087 .v.func = alc260_fixup_kn1,
5088 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005089};
5090
5091static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005092 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005093 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005094 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005095 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005096 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005097 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005098 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005099 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005100 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005101 {}
5102};
5103
5104/*
5105 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005106static int patch_alc260(struct hda_codec *codec)
5107{
5108 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005109 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005110
Takashi Iwai3de95172012-05-07 18:03:15 +02005111 err = alc_alloc_spec(codec, 0x07);
5112 if (err < 0)
5113 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005114
Takashi Iwai3de95172012-05-07 18:03:15 +02005115 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005116
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005117 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5118 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005119
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005120 /* automatic parse from the BIOS config */
5121 err = alc260_parse_auto_config(codec);
5122 if (err < 0)
5123 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005124
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005125 if (!spec->no_analog) {
5126 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005127 if (err < 0)
5128 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005129 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5130 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005131
Takashi Iwai1d045db2011-07-07 18:23:21 +02005132 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005133 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005134
Takashi Iwai589876e2012-02-20 15:47:55 +01005135 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5136
Takashi Iwai1d045db2011-07-07 18:23:21 +02005137 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005138
5139 error:
5140 alc_free(codec);
5141 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005142}
5143
5144
5145/*
5146 * ALC882/883/885/888/889 support
5147 *
5148 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5149 * configuration. Each pin widget can choose any input DACs and a mixer.
5150 * Each ADC is connected from a mixer of all inputs. This makes possible
5151 * 6-channel independent captures.
5152 *
5153 * In addition, an independent DAC for the multi-playback (not used in this
5154 * driver yet).
5155 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005156
5157/*
5158 * Pin config fixes
5159 */
5160enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005161 ALC882_FIXUP_ABIT_AW9D_MAX,
5162 ALC882_FIXUP_LENOVO_Y530,
5163 ALC882_FIXUP_PB_M5210,
5164 ALC882_FIXUP_ACER_ASPIRE_7736,
5165 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005166 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005167 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005168 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005169 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005170 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005171 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005172 ALC882_FIXUP_GPIO1,
5173 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005174 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005175 ALC889_FIXUP_COEF,
5176 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005177 ALC882_FIXUP_ACER_ASPIRE_4930G,
5178 ALC882_FIXUP_ACER_ASPIRE_8930G,
5179 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005180 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005181 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005182 ALC889_FIXUP_MBP_VREF,
5183 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005184 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005185 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005186};
5187
Takashi Iwai68ef0562011-11-09 18:24:44 +01005188static void alc889_fixup_coef(struct hda_codec *codec,
5189 const struct alc_fixup *fix, int action)
5190{
5191 if (action != ALC_FIXUP_ACT_INIT)
5192 return;
5193 alc889_coef_init(codec);
5194}
5195
Takashi Iwai56710872011-11-14 17:42:11 +01005196/* toggle speaker-output according to the hp-jack state */
5197static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5198{
5199 unsigned int gpiostate, gpiomask, gpiodir;
5200
5201 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5202 AC_VERB_GET_GPIO_DATA, 0);
5203
5204 if (!muted)
5205 gpiostate |= (1 << pin);
5206 else
5207 gpiostate &= ~(1 << pin);
5208
5209 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5210 AC_VERB_GET_GPIO_MASK, 0);
5211 gpiomask |= (1 << pin);
5212
5213 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5214 AC_VERB_GET_GPIO_DIRECTION, 0);
5215 gpiodir |= (1 << pin);
5216
5217
5218 snd_hda_codec_write(codec, codec->afg, 0,
5219 AC_VERB_SET_GPIO_MASK, gpiomask);
5220 snd_hda_codec_write(codec, codec->afg, 0,
5221 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5222
5223 msleep(1);
5224
5225 snd_hda_codec_write(codec, codec->afg, 0,
5226 AC_VERB_SET_GPIO_DATA, gpiostate);
5227}
5228
5229/* set up GPIO at initialization */
5230static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5231 const struct alc_fixup *fix, int action)
5232{
5233 if (action != ALC_FIXUP_ACT_INIT)
5234 return;
5235 alc882_gpio_mute(codec, 0, 0);
5236 alc882_gpio_mute(codec, 1, 0);
5237}
5238
Takashi Iwai02a237b2012-02-13 15:25:07 +01005239/* Fix the connection of some pins for ALC889:
5240 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5241 * work correctly (bko#42740)
5242 */
5243static void alc889_fixup_dac_route(struct hda_codec *codec,
5244 const struct alc_fixup *fix, int action)
5245{
5246 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005247 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005248 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5249 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5250 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5251 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5252 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5253 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005254 } else if (action == ALC_FIXUP_ACT_PROBE) {
5255 /* restore the connections */
5256 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5257 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5258 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5259 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5260 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005261 }
5262}
5263
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005264/* Set VREF on HP pin */
5265static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5266 const struct alc_fixup *fix, int action)
5267{
5268 struct alc_spec *spec = codec->spec;
5269 static hda_nid_t nids[2] = { 0x14, 0x15 };
5270 int i;
5271
5272 if (action != ALC_FIXUP_ACT_INIT)
5273 return;
5274 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5275 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5276 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5277 continue;
5278 val = snd_hda_codec_read(codec, nids[i], 0,
5279 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5280 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005281 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005282 spec->keep_vref_in_automute = 1;
5283 break;
5284 }
5285}
5286
5287/* Set VREF on speaker pins on imac91 */
5288static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5289 const struct alc_fixup *fix, int action)
5290{
5291 struct alc_spec *spec = codec->spec;
5292 static hda_nid_t nids[2] = { 0x18, 0x1a };
5293 int i;
5294
5295 if (action != ALC_FIXUP_ACT_INIT)
5296 return;
5297 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5298 unsigned int val;
5299 val = snd_hda_codec_read(codec, nids[i], 0,
5300 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5301 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005302 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005303 }
5304 spec->keep_vref_in_automute = 1;
5305}
5306
Takashi Iwaie427c232012-07-29 10:04:08 +02005307/* Don't take HP output as primary
5308 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5309 */
5310static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5311 const struct alc_fixup *fix, int action)
5312{
5313 struct alc_spec *spec = codec->spec;
5314 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5315 spec->no_primary_hp = 1;
5316}
5317
Takashi Iwai1d045db2011-07-07 18:23:21 +02005318static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005319 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005320 .type = ALC_FIXUP_PINS,
5321 .v.pins = (const struct alc_pincfg[]) {
5322 { 0x15, 0x01080104 }, /* side */
5323 { 0x16, 0x01011012 }, /* rear */
5324 { 0x17, 0x01016011 }, /* clfe */
5325 { }
5326 }
5327 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005328 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005329 .type = ALC_FIXUP_PINS,
5330 .v.pins = (const struct alc_pincfg[]) {
5331 { 0x15, 0x99130112 }, /* rear int speakers */
5332 { 0x16, 0x99130111 }, /* subwoofer */
5333 { }
5334 }
5335 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005336 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005337 .type = ALC_FIXUP_VERBS,
5338 .v.verbs = (const struct hda_verb[]) {
5339 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5340 {}
5341 }
5342 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005343 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005344 .type = ALC_FIXUP_FUNC,
5345 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005346 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005347 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005348 .type = ALC_FIXUP_PINS,
5349 .v.pins = (const struct alc_pincfg[]) {
5350 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5351 { }
5352 }
5353 },
Marton Balint8f239212012-03-05 21:33:23 +01005354 [ALC889_FIXUP_CD] = {
5355 .type = ALC_FIXUP_PINS,
5356 .v.pins = (const struct alc_pincfg[]) {
5357 { 0x1c, 0x993301f0 }, /* CD */
5358 { }
5359 }
5360 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005361 [ALC889_FIXUP_VAIO_TT] = {
5362 .type = ALC_FIXUP_PINS,
5363 .v.pins = (const struct alc_pincfg[]) {
5364 { 0x17, 0x90170111 }, /* hidden surround speaker */
5365 { }
5366 }
5367 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005368 [ALC888_FIXUP_EEE1601] = {
5369 .type = ALC_FIXUP_VERBS,
5370 .v.verbs = (const struct hda_verb[]) {
5371 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5372 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5373 { }
5374 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005375 },
5376 [ALC882_FIXUP_EAPD] = {
5377 .type = ALC_FIXUP_VERBS,
5378 .v.verbs = (const struct hda_verb[]) {
5379 /* change to EAPD mode */
5380 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5381 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5382 { }
5383 }
5384 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005385 [ALC883_FIXUP_EAPD] = {
5386 .type = ALC_FIXUP_VERBS,
5387 .v.verbs = (const struct hda_verb[]) {
5388 /* change to EAPD mode */
5389 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5390 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5391 { }
5392 }
5393 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005394 [ALC883_FIXUP_ACER_EAPD] = {
5395 .type = ALC_FIXUP_VERBS,
5396 .v.verbs = (const struct hda_verb[]) {
5397 /* eanable EAPD on Acer laptops */
5398 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5399 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5400 { }
5401 }
5402 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005403 [ALC882_FIXUP_GPIO1] = {
5404 .type = ALC_FIXUP_VERBS,
5405 .v.verbs = alc_gpio1_init_verbs,
5406 },
5407 [ALC882_FIXUP_GPIO2] = {
5408 .type = ALC_FIXUP_VERBS,
5409 .v.verbs = alc_gpio2_init_verbs,
5410 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005411 [ALC882_FIXUP_GPIO3] = {
5412 .type = ALC_FIXUP_VERBS,
5413 .v.verbs = alc_gpio3_init_verbs,
5414 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005415 [ALC882_FIXUP_ASUS_W2JC] = {
5416 .type = ALC_FIXUP_VERBS,
5417 .v.verbs = alc_gpio1_init_verbs,
5418 .chained = true,
5419 .chain_id = ALC882_FIXUP_EAPD,
5420 },
5421 [ALC889_FIXUP_COEF] = {
5422 .type = ALC_FIXUP_FUNC,
5423 .v.func = alc889_fixup_coef,
5424 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005425 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5426 .type = ALC_FIXUP_PINS,
5427 .v.pins = (const struct alc_pincfg[]) {
5428 { 0x16, 0x99130111 }, /* CLFE speaker */
5429 { 0x17, 0x99130112 }, /* surround speaker */
5430 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005431 },
5432 .chained = true,
5433 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005434 },
5435 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5436 .type = ALC_FIXUP_PINS,
5437 .v.pins = (const struct alc_pincfg[]) {
5438 { 0x16, 0x99130111 }, /* CLFE speaker */
5439 { 0x1b, 0x99130112 }, /* surround speaker */
5440 { }
5441 },
5442 .chained = true,
5443 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5444 },
5445 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5446 /* additional init verbs for Acer Aspire 8930G */
5447 .type = ALC_FIXUP_VERBS,
5448 .v.verbs = (const struct hda_verb[]) {
5449 /* Enable all DACs */
5450 /* DAC DISABLE/MUTE 1? */
5451 /* setting bits 1-5 disables DAC nids 0x02-0x06
5452 * apparently. Init=0x38 */
5453 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5454 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5455 /* DAC DISABLE/MUTE 2? */
5456 /* some bit here disables the other DACs.
5457 * Init=0x4900 */
5458 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5459 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5460 /* DMIC fix
5461 * This laptop has a stereo digital microphone.
5462 * The mics are only 1cm apart which makes the stereo
5463 * useless. However, either the mic or the ALC889
5464 * makes the signal become a difference/sum signal
5465 * instead of standard stereo, which is annoying.
5466 * So instead we flip this bit which makes the
5467 * codec replicate the sum signal to both channels,
5468 * turning it into a normal mono mic.
5469 */
5470 /* DMIC_CONTROL? Init value = 0x0001 */
5471 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5472 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5473 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5474 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5475 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005476 },
5477 .chained = true,
5478 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005479 },
Takashi Iwai56710872011-11-14 17:42:11 +01005480 [ALC885_FIXUP_MACPRO_GPIO] = {
5481 .type = ALC_FIXUP_FUNC,
5482 .v.func = alc885_fixup_macpro_gpio,
5483 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005484 [ALC889_FIXUP_DAC_ROUTE] = {
5485 .type = ALC_FIXUP_FUNC,
5486 .v.func = alc889_fixup_dac_route,
5487 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005488 [ALC889_FIXUP_MBP_VREF] = {
5489 .type = ALC_FIXUP_FUNC,
5490 .v.func = alc889_fixup_mbp_vref,
5491 .chained = true,
5492 .chain_id = ALC882_FIXUP_GPIO1,
5493 },
5494 [ALC889_FIXUP_IMAC91_VREF] = {
5495 .type = ALC_FIXUP_FUNC,
5496 .v.func = alc889_fixup_imac91_vref,
5497 .chained = true,
5498 .chain_id = ALC882_FIXUP_GPIO1,
5499 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005500 [ALC882_FIXUP_INV_DMIC] = {
5501 .type = ALC_FIXUP_FUNC,
5502 .v.func = alc_fixup_inv_dmic_0x12,
5503 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005504 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5505 .type = ALC_FIXUP_FUNC,
5506 .v.func = alc882_fixup_no_primary_hp,
5507 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508};
5509
5510static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005511 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5512 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5513 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5514 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5515 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5516 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005517 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5518 ALC882_FIXUP_ACER_ASPIRE_4930G),
5519 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5520 ALC882_FIXUP_ACER_ASPIRE_4930G),
5521 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5522 ALC882_FIXUP_ACER_ASPIRE_8930G),
5523 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5524 ALC882_FIXUP_ACER_ASPIRE_8930G),
5525 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5526 ALC882_FIXUP_ACER_ASPIRE_4930G),
5527 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5528 ALC882_FIXUP_ACER_ASPIRE_4930G),
5529 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5530 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005531 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005532 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5533 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005534 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005535 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005536 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005537 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005538 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005539 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005540 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005541 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005542 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005543
5544 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005545 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5546 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5547 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005548 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5549 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5550 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005551 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5552 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005553 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005554 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5555 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5556 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5557 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005558 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005559 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5560 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5561 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005562 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005563 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005564 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5565 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5566 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005567
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005568 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005569 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005570 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005571 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005572 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005573 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5574 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005575 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005576 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005577 {}
5578};
5579
Takashi Iwai912093b2012-04-11 14:03:41 +02005580static const struct alc_model_fixup alc882_fixup_models[] = {
5581 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5582 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5583 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005584 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005585 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005586 {}
5587};
5588
Takashi Iwai1d045db2011-07-07 18:23:21 +02005589/*
5590 * BIOS auto configuration
5591 */
5592/* almost identical with ALC880 parser... */
5593static int alc882_parse_auto_config(struct hda_codec *codec)
5594{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005595 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005596 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5597 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005598}
5599
Takashi Iwai1d045db2011-07-07 18:23:21 +02005600/*
5601 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005602static int patch_alc882(struct hda_codec *codec)
5603{
5604 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005605 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005606
Takashi Iwai3de95172012-05-07 18:03:15 +02005607 err = alc_alloc_spec(codec, 0x0b);
5608 if (err < 0)
5609 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005610
Takashi Iwai3de95172012-05-07 18:03:15 +02005611 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005612
5613 switch (codec->vendor_id) {
5614 case 0x10ec0882:
5615 case 0x10ec0885:
5616 break;
5617 default:
5618 /* ALC883 and variants */
5619 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5620 break;
5621 }
5622
Takashi Iwai912093b2012-04-11 14:03:41 +02005623 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5624 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005625 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005626
5627 alc_auto_parse_customize_define(codec);
5628
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005629 /* automatic parse from the BIOS config */
5630 err = alc882_parse_auto_config(codec);
5631 if (err < 0)
5632 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005633
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005634 if (!spec->no_analog && has_cdefine_beep(codec)) {
5635 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005636 if (err < 0)
5637 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005638 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005639 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005640
Takashi Iwai1d045db2011-07-07 18:23:21 +02005641 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005642
Takashi Iwai589876e2012-02-20 15:47:55 +01005643 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5644
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005646
5647 error:
5648 alc_free(codec);
5649 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005650}
5651
5652
5653/*
5654 * ALC262 support
5655 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656static int alc262_parse_auto_config(struct hda_codec *codec)
5657{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005658 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005659 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5660 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661}
5662
5663/*
5664 * Pin config fixes
5665 */
5666enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005667 ALC262_FIXUP_FSC_H270,
5668 ALC262_FIXUP_HP_Z200,
5669 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005670 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005671 ALC262_FIXUP_BENQ,
5672 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005673 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005674};
5675
5676static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005677 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005678 .type = ALC_FIXUP_PINS,
5679 .v.pins = (const struct alc_pincfg[]) {
5680 { 0x14, 0x99130110 }, /* speaker */
5681 { 0x15, 0x0221142f }, /* front HP */
5682 { 0x1b, 0x0121141f }, /* rear HP */
5683 { }
5684 }
5685 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005686 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005687 .type = ALC_FIXUP_PINS,
5688 .v.pins = (const struct alc_pincfg[]) {
5689 { 0x16, 0x99130120 }, /* internal speaker */
5690 { }
5691 }
5692 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005693 [ALC262_FIXUP_TYAN] = {
5694 .type = ALC_FIXUP_PINS,
5695 .v.pins = (const struct alc_pincfg[]) {
5696 { 0x14, 0x1993e1f0 }, /* int AUX */
5697 { }
5698 }
5699 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005700 [ALC262_FIXUP_LENOVO_3000] = {
5701 .type = ALC_FIXUP_VERBS,
5702 .v.verbs = (const struct hda_verb[]) {
5703 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005704 {}
5705 },
5706 .chained = true,
5707 .chain_id = ALC262_FIXUP_BENQ,
5708 },
5709 [ALC262_FIXUP_BENQ] = {
5710 .type = ALC_FIXUP_VERBS,
5711 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005712 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5713 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5714 {}
5715 }
5716 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005717 [ALC262_FIXUP_BENQ_T31] = {
5718 .type = ALC_FIXUP_VERBS,
5719 .v.verbs = (const struct hda_verb[]) {
5720 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5721 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5722 {}
5723 }
5724 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005725 [ALC262_FIXUP_INV_DMIC] = {
5726 .type = ALC_FIXUP_FUNC,
5727 .v.func = alc_fixup_inv_dmic_0x12,
5728 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005729};
5730
5731static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005732 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005733 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5734 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005735 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5736 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005737 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005738 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5739 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005740 {}
5741};
5742
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005743static const struct alc_model_fixup alc262_fixup_models[] = {
5744 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5745 {}
5746};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005747
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748/*
5749 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750static int patch_alc262(struct hda_codec *codec)
5751{
5752 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753 int err;
5754
Takashi Iwai3de95172012-05-07 18:03:15 +02005755 err = alc_alloc_spec(codec, 0x0b);
5756 if (err < 0)
5757 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005758
Takashi Iwai3de95172012-05-07 18:03:15 +02005759 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01005760 spec->shared_mic_vref_pin = 0x18;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005761
5762#if 0
5763 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5764 * under-run
5765 */
5766 {
5767 int tmp;
5768 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5769 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5770 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5771 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5772 }
5773#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005774 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5775
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005776 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5777 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005778 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005779
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005780 alc_auto_parse_customize_define(codec);
5781
Takashi Iwai42399f72011-11-07 17:18:44 +01005782 /* automatic parse from the BIOS config */
5783 err = alc262_parse_auto_config(codec);
5784 if (err < 0)
5785 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005786
Takashi Iwai1d045db2011-07-07 18:23:21 +02005787 if (!spec->no_analog && has_cdefine_beep(codec)) {
5788 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005789 if (err < 0)
5790 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005791 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005792 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005793
Takashi Iwai1d045db2011-07-07 18:23:21 +02005794 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005795 spec->shutup = alc_eapd_shutup;
5796
Takashi Iwai589876e2012-02-20 15:47:55 +01005797 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5798
Takashi Iwai1d045db2011-07-07 18:23:21 +02005799 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005800
5801 error:
5802 alc_free(codec);
5803 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005804}
5805
5806/*
5807 * ALC268
5808 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005809/* bind Beep switches of both NID 0x0f and 0x10 */
5810static const struct hda_bind_ctls alc268_bind_beep_sw = {
5811 .ops = &snd_hda_bind_sw,
5812 .values = {
5813 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5814 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5815 0
5816 },
5817};
5818
5819static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5820 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5821 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5822 { }
5823};
5824
5825/* set PCBEEP vol = 0, mute connections */
5826static const struct hda_verb alc268_beep_init_verbs[] = {
5827 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5828 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5829 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5830 { }
5831};
5832
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005833enum {
5834 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005835 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005836};
5837
5838static const struct alc_fixup alc268_fixups[] = {
5839 [ALC268_FIXUP_INV_DMIC] = {
5840 .type = ALC_FIXUP_FUNC,
5841 .v.func = alc_fixup_inv_dmic_0x12,
5842 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005843 [ALC268_FIXUP_HP_EAPD] = {
5844 .type = ALC_FIXUP_VERBS,
5845 .v.verbs = (const struct hda_verb[]) {
5846 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5847 {}
5848 }
5849 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005850};
5851
5852static const struct alc_model_fixup alc268_fixup_models[] = {
5853 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005854 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5855 {}
5856};
5857
5858static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5859 /* below is codec SSID since multiple Toshiba laptops have the
5860 * same PCI SSID 1179:ff00
5861 */
5862 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005863 {}
5864};
5865
Takashi Iwai1d045db2011-07-07 18:23:21 +02005866/*
5867 * BIOS auto configuration
5868 */
5869static int alc268_parse_auto_config(struct hda_codec *codec)
5870{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005871 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005872 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005873 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5874 if (err > 0) {
5875 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5876 add_mixer(spec, alc268_beep_mixer);
Takashi Iwaic9ce6b22012-12-18 18:12:44 +01005877 snd_hda_add_verbs(codec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005878 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005879 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005880 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005881}
5882
Takashi Iwai1d045db2011-07-07 18:23:21 +02005883/*
5884 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005885static int patch_alc268(struct hda_codec *codec)
5886{
5887 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005888 int i, has_beep, err;
5889
Takashi Iwai1d045db2011-07-07 18:23:21 +02005890 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005891 err = alc_alloc_spec(codec, 0);
5892 if (err < 0)
5893 return err;
5894
5895 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005896
Takashi Iwaicb766402012-10-20 10:55:21 +02005897 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005898 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5899
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005900 /* automatic parse from the BIOS config */
5901 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005902 if (err < 0)
5903 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005904
Takashi Iwai1d045db2011-07-07 18:23:21 +02005905 has_beep = 0;
5906 for (i = 0; i < spec->num_mixers; i++) {
5907 if (spec->mixers[i] == alc268_beep_mixer) {
5908 has_beep = 1;
5909 break;
5910 }
5911 }
5912
5913 if (has_beep) {
5914 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005915 if (err < 0)
5916 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005917 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5918 /* override the amp caps for beep generator */
5919 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5920 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5921 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5922 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5923 (0 << AC_AMPCAP_MUTE_SHIFT));
5924 }
5925
Takashi Iwai1d045db2011-07-07 18:23:21 +02005926 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005927 spec->shutup = alc_eapd_shutup;
5928
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005929 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5930
Takashi Iwai1d045db2011-07-07 18:23:21 +02005931 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005932
5933 error:
5934 alc_free(codec);
5935 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005936}
5937
5938/*
5939 * ALC269
5940 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005941static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5942 .substreams = 1,
5943 .channels_min = 2,
5944 .channels_max = 8,
5945 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5946 /* NID is set in alc_build_pcms */
5947 .ops = {
5948 .open = alc_playback_pcm_open,
5949 .prepare = alc_playback_pcm_prepare,
5950 .cleanup = alc_playback_pcm_cleanup
5951 },
5952};
5953
5954static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5955 .substreams = 1,
5956 .channels_min = 2,
5957 .channels_max = 2,
5958 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5959 /* NID is set in alc_build_pcms */
5960};
5961
Takashi Iwai1d045db2011-07-07 18:23:21 +02005962/* different alc269-variants */
5963enum {
5964 ALC269_TYPE_ALC269VA,
5965 ALC269_TYPE_ALC269VB,
5966 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005967 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005968 ALC269_TYPE_ALC280,
5969 ALC269_TYPE_ALC282,
5970 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005971};
5972
5973/*
5974 * BIOS auto configuration
5975 */
5976static int alc269_parse_auto_config(struct hda_codec *codec)
5977{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005978 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005979 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5980 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5981 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005982 const hda_nid_t *ssids;
5983
5984 switch (spec->codec_variant) {
5985 case ALC269_TYPE_ALC269VA:
5986 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005987 case ALC269_TYPE_ALC280:
5988 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005989 ssids = alc269va_ssids;
5990 break;
5991 case ALC269_TYPE_ALC269VB:
5992 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005993 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005994 ssids = alc269_ssids;
5995 break;
5996 default:
5997 ssids = alc269_ssids;
5998 break;
5999 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006000
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006001 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006002}
6003
Kailang Yang1387e2d2012-11-08 10:23:18 +01006004static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006005{
6006 int val = alc_read_coef_idx(codec, 0x04);
6007 if (power_up)
6008 val |= 1 << 11;
6009 else
6010 val &= ~(1 << 11);
6011 alc_write_coef_idx(codec, 0x04, val);
6012}
6013
6014static void alc269_shutup(struct hda_codec *codec)
6015{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006016 struct alc_spec *spec = codec->spec;
6017
6018 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6019 return;
6020
Kailang Yang1387e2d2012-11-08 10:23:18 +01006021 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6022 alc269vb_toggle_power_output(codec, 0);
6023 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6024 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006025 msleep(150);
6026 }
6027}
6028
Takashi Iwai2a439522011-07-26 09:52:50 +02006029#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006030static int alc269_resume(struct hda_codec *codec)
6031{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006032 struct alc_spec *spec = codec->spec;
6033
Kailang Yang1387e2d2012-11-08 10:23:18 +01006034 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6035 alc269vb_toggle_power_output(codec, 0);
6036 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006037 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006038 msleep(150);
6039 }
6040
6041 codec->patch_ops.init(codec);
6042
Kailang Yang1387e2d2012-11-08 10:23:18 +01006043 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6044 alc269vb_toggle_power_output(codec, 1);
6045 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006046 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006047 msleep(200);
6048 }
6049
Takashi Iwai1d045db2011-07-07 18:23:21 +02006050 snd_hda_codec_resume_amp(codec);
6051 snd_hda_codec_resume_cache(codec);
6052 hda_call_check_power_status(codec, 0x01);
6053 return 0;
6054}
Takashi Iwai2a439522011-07-26 09:52:50 +02006055#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006056
David Henningsson108cc102012-07-20 10:37:25 +02006057static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6058 const struct alc_fixup *fix, int action)
6059{
6060 struct alc_spec *spec = codec->spec;
6061
6062 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6063 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6064}
6065
Takashi Iwai1d045db2011-07-07 18:23:21 +02006066static void alc269_fixup_hweq(struct hda_codec *codec,
6067 const struct alc_fixup *fix, int action)
6068{
6069 int coef;
6070
6071 if (action != ALC_FIXUP_ACT_INIT)
6072 return;
6073 coef = alc_read_coef_idx(codec, 0x1e);
6074 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6075}
6076
6077static void alc271_fixup_dmic(struct hda_codec *codec,
6078 const struct alc_fixup *fix, int action)
6079{
6080 static const struct hda_verb verbs[] = {
6081 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6082 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6083 {}
6084 };
6085 unsigned int cfg;
6086
6087 if (strcmp(codec->chip_name, "ALC271X"))
6088 return;
6089 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6090 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6091 snd_hda_sequence_write(codec, verbs);
6092}
6093
Takashi Iwai017f2a12011-07-09 14:42:25 +02006094static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6095 const struct alc_fixup *fix, int action)
6096{
6097 struct alc_spec *spec = codec->spec;
6098
6099 if (action != ALC_FIXUP_ACT_PROBE)
6100 return;
6101
6102 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6103 * fix the sample rate of analog I/O to 44.1kHz
6104 */
6105 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6106 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6107}
6108
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006109static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6110 const struct alc_fixup *fix, int action)
6111{
6112 int coef;
6113
6114 if (action != ALC_FIXUP_ACT_INIT)
6115 return;
6116 /* The digital-mic unit sends PDM (differential signal) instead of
6117 * the standard PCM, thus you can't record a valid mono stream as is.
6118 * Below is a workaround specific to ALC269 to control the dmic
6119 * signal source as mono.
6120 */
6121 coef = alc_read_coef_idx(codec, 0x07);
6122 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6123}
6124
Takashi Iwai24519912011-08-16 15:08:49 +02006125static void alc269_quanta_automute(struct hda_codec *codec)
6126{
David Henningsson42cf0d02011-09-20 12:04:56 +02006127 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006128
6129 snd_hda_codec_write(codec, 0x20, 0,
6130 AC_VERB_SET_COEF_INDEX, 0x0c);
6131 snd_hda_codec_write(codec, 0x20, 0,
6132 AC_VERB_SET_PROC_COEF, 0x680);
6133
6134 snd_hda_codec_write(codec, 0x20, 0,
6135 AC_VERB_SET_COEF_INDEX, 0x0c);
6136 snd_hda_codec_write(codec, 0x20, 0,
6137 AC_VERB_SET_PROC_COEF, 0x480);
6138}
6139
6140static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6141 const struct alc_fixup *fix, int action)
6142{
6143 struct alc_spec *spec = codec->spec;
6144 if (action != ALC_FIXUP_ACT_PROBE)
6145 return;
6146 spec->automute_hook = alc269_quanta_automute;
6147}
6148
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006149/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6150static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6151{
6152 struct hda_codec *codec = private_data;
6153 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6154 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6155 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6156}
6157
6158static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6159 const struct alc_fixup *fix, int action)
6160{
6161 struct alc_spec *spec = codec->spec;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01006162 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006163 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006164}
6165
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006166/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6167static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6168{
6169 struct hda_codec *codec = private_data;
6170 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006171 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006172}
6173
6174static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6175 const struct alc_fixup *fix, int action)
6176{
6177 struct alc_spec *spec = codec->spec;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01006178 if (action == ALC_FIXUP_ACT_PROBE)
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006179 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006180}
6181
Dylan Reid08a978d2012-11-18 22:56:40 -08006182static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6183 const struct alc_fixup *fix,
6184 int action)
6185{
6186 struct alc_spec *spec = codec->spec;
6187
6188 if (action == ALC_FIXUP_ACT_PROBE)
6189 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6190 spec->autocfg.hp_pins[0]);
6191}
David Henningsson693b6132012-06-22 19:12:10 +02006192
Takashi Iwai1d045db2011-07-07 18:23:21 +02006193enum {
6194 ALC269_FIXUP_SONY_VAIO,
6195 ALC275_FIXUP_SONY_VAIO_GPIO2,
6196 ALC269_FIXUP_DELL_M101Z,
6197 ALC269_FIXUP_SKU_IGNORE,
6198 ALC269_FIXUP_ASUS_G73JW,
6199 ALC269_FIXUP_LENOVO_EAPD,
6200 ALC275_FIXUP_SONY_HWEQ,
6201 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006202 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006203 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006204 ALC269_FIXUP_QUANTA_MUTE,
6205 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006206 ALC269_FIXUP_AMIC,
6207 ALC269_FIXUP_DMIC,
6208 ALC269VB_FIXUP_AMIC,
6209 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006210 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006211 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006212 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006213 ALC269_FIXUP_LENOVO_DOCK,
6214 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006215 ALC271_FIXUP_AMIC_MIC2,
6216 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006217};
6218
6219static const struct alc_fixup alc269_fixups[] = {
6220 [ALC269_FIXUP_SONY_VAIO] = {
6221 .type = ALC_FIXUP_VERBS,
6222 .v.verbs = (const struct hda_verb[]) {
6223 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6224 {}
6225 }
6226 },
6227 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6228 .type = ALC_FIXUP_VERBS,
6229 .v.verbs = (const struct hda_verb[]) {
6230 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6231 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6232 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6233 { }
6234 },
6235 .chained = true,
6236 .chain_id = ALC269_FIXUP_SONY_VAIO
6237 },
6238 [ALC269_FIXUP_DELL_M101Z] = {
6239 .type = ALC_FIXUP_VERBS,
6240 .v.verbs = (const struct hda_verb[]) {
6241 /* Enables internal speaker */
6242 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6243 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6244 {}
6245 }
6246 },
6247 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006248 .type = ALC_FIXUP_FUNC,
6249 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006250 },
6251 [ALC269_FIXUP_ASUS_G73JW] = {
6252 .type = ALC_FIXUP_PINS,
6253 .v.pins = (const struct alc_pincfg[]) {
6254 { 0x17, 0x99130111 }, /* subwoofer */
6255 { }
6256 }
6257 },
6258 [ALC269_FIXUP_LENOVO_EAPD] = {
6259 .type = ALC_FIXUP_VERBS,
6260 .v.verbs = (const struct hda_verb[]) {
6261 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6262 {}
6263 }
6264 },
6265 [ALC275_FIXUP_SONY_HWEQ] = {
6266 .type = ALC_FIXUP_FUNC,
6267 .v.func = alc269_fixup_hweq,
6268 .chained = true,
6269 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6270 },
6271 [ALC271_FIXUP_DMIC] = {
6272 .type = ALC_FIXUP_FUNC,
6273 .v.func = alc271_fixup_dmic,
6274 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006275 [ALC269_FIXUP_PCM_44K] = {
6276 .type = ALC_FIXUP_FUNC,
6277 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006278 .chained = true,
6279 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006280 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006281 [ALC269_FIXUP_STEREO_DMIC] = {
6282 .type = ALC_FIXUP_FUNC,
6283 .v.func = alc269_fixup_stereo_dmic,
6284 },
Takashi Iwai24519912011-08-16 15:08:49 +02006285 [ALC269_FIXUP_QUANTA_MUTE] = {
6286 .type = ALC_FIXUP_FUNC,
6287 .v.func = alc269_fixup_quanta_mute,
6288 },
6289 [ALC269_FIXUP_LIFEBOOK] = {
6290 .type = ALC_FIXUP_PINS,
6291 .v.pins = (const struct alc_pincfg[]) {
6292 { 0x1a, 0x2101103f }, /* dock line-out */
6293 { 0x1b, 0x23a11040 }, /* dock mic-in */
6294 { }
6295 },
6296 .chained = true,
6297 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6298 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006299 [ALC269_FIXUP_AMIC] = {
6300 .type = ALC_FIXUP_PINS,
6301 .v.pins = (const struct alc_pincfg[]) {
6302 { 0x14, 0x99130110 }, /* speaker */
6303 { 0x15, 0x0121401f }, /* HP out */
6304 { 0x18, 0x01a19c20 }, /* mic */
6305 { 0x19, 0x99a3092f }, /* int-mic */
6306 { }
6307 },
6308 },
6309 [ALC269_FIXUP_DMIC] = {
6310 .type = ALC_FIXUP_PINS,
6311 .v.pins = (const struct alc_pincfg[]) {
6312 { 0x12, 0x99a3092f }, /* int-mic */
6313 { 0x14, 0x99130110 }, /* speaker */
6314 { 0x15, 0x0121401f }, /* HP out */
6315 { 0x18, 0x01a19c20 }, /* mic */
6316 { }
6317 },
6318 },
6319 [ALC269VB_FIXUP_AMIC] = {
6320 .type = ALC_FIXUP_PINS,
6321 .v.pins = (const struct alc_pincfg[]) {
6322 { 0x14, 0x99130110 }, /* speaker */
6323 { 0x18, 0x01a19c20 }, /* mic */
6324 { 0x19, 0x99a3092f }, /* int-mic */
6325 { 0x21, 0x0121401f }, /* HP out */
6326 { }
6327 },
6328 },
David Henningsson2267ea92012-01-03 08:45:56 +01006329 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006330 .type = ALC_FIXUP_PINS,
6331 .v.pins = (const struct alc_pincfg[]) {
6332 { 0x12, 0x99a3092f }, /* int-mic */
6333 { 0x14, 0x99130110 }, /* speaker */
6334 { 0x18, 0x01a19c20 }, /* mic */
6335 { 0x21, 0x0121401f }, /* HP out */
6336 { }
6337 },
6338 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006339 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6340 .type = ALC_FIXUP_FUNC,
6341 .v.func = alc269_fixup_mic1_mute,
6342 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006343 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6344 .type = ALC_FIXUP_FUNC,
6345 .v.func = alc269_fixup_mic2_mute,
6346 },
David Henningsson693b6132012-06-22 19:12:10 +02006347 [ALC269_FIXUP_INV_DMIC] = {
6348 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006349 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006350 },
David Henningsson108cc102012-07-20 10:37:25 +02006351 [ALC269_FIXUP_LENOVO_DOCK] = {
6352 .type = ALC_FIXUP_PINS,
6353 .v.pins = (const struct alc_pincfg[]) {
6354 { 0x19, 0x23a11040 }, /* dock mic */
6355 { 0x1b, 0x2121103f }, /* dock headphone */
6356 { }
6357 },
6358 .chained = true,
6359 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6360 },
6361 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6362 .type = ALC_FIXUP_FUNC,
6363 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6364 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006365 [ALC271_FIXUP_AMIC_MIC2] = {
6366 .type = ALC_FIXUP_PINS,
6367 .v.pins = (const struct alc_pincfg[]) {
6368 { 0x14, 0x99130110 }, /* speaker */
6369 { 0x19, 0x01a19c20 }, /* mic */
6370 { 0x1b, 0x99a7012f }, /* int-mic */
6371 { 0x21, 0x0121401f }, /* HP out */
6372 { }
6373 },
6374 },
6375 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6376 .type = ALC_FIXUP_FUNC,
6377 .v.func = alc271_hp_gate_mic_jack,
6378 .chained = true,
6379 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6380 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006381};
6382
6383static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006384 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6385 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006386 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006387 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006388 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006389 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006390 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006391 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006392 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6393 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6394 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6395 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6396 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006397 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6398 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6399 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6400 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6401 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006402 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006403 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006404 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006405 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6406 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6407 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6408 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6409 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006410 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006411 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006412 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006413 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006414 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006415 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006416 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006417
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006418#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006419 /* Below is a quirk table taken from the old code.
6420 * Basically the device should work as is without the fixup table.
6421 * If BIOS doesn't give a proper info, enable the corresponding
6422 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006423 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006424 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6425 ALC269_FIXUP_AMIC),
6426 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006427 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6428 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6429 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6430 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6431 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6432 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6433 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6434 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6435 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6436 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6437 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6438 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6439 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6440 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6441 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6442 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6443 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6444 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6445 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6446 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6447 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6448 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6449 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6450 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6451 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6452 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6453 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6454 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6455 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6456 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6457 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6458 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6459 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6460 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6461 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6462 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6463 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6464 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6465#endif
6466 {}
6467};
6468
6469static const struct alc_model_fixup alc269_fixup_models[] = {
6470 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6471 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006472 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6473 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6474 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006475 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006476 {}
6477};
6478
6479
Takashi Iwai546bb672012-03-07 08:37:19 +01006480static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006481{
Kailang Yang526af6e2012-03-07 08:25:20 +01006482 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006483 int val;
6484
Kailang Yang526af6e2012-03-07 08:25:20 +01006485 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006486 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006487
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006488 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006489 alc_write_coef_idx(codec, 0xf, 0x960b);
6490 alc_write_coef_idx(codec, 0xe, 0x8817);
6491 }
6492
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006493 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006494 alc_write_coef_idx(codec, 0xf, 0x960b);
6495 alc_write_coef_idx(codec, 0xe, 0x8814);
6496 }
6497
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006498 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006499 val = alc_read_coef_idx(codec, 0x04);
6500 /* Power up output pin */
6501 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6502 }
6503
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006504 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006505 val = alc_read_coef_idx(codec, 0xd);
6506 if ((val & 0x0c00) >> 10 != 0x1) {
6507 /* Capless ramp up clock control */
6508 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6509 }
6510 val = alc_read_coef_idx(codec, 0x17);
6511 if ((val & 0x01c0) >> 6 != 0x4) {
6512 /* Class D power on reset */
6513 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6514 }
6515 }
6516
6517 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6518 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6519
6520 val = alc_read_coef_idx(codec, 0x4); /* HP */
6521 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006522}
6523
6524/*
6525 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006526static int patch_alc269(struct hda_codec *codec)
6527{
6528 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006529 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006530
Takashi Iwai3de95172012-05-07 18:03:15 +02006531 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006532 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006533 return err;
6534
6535 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01006536 spec->shared_mic_vref_pin = 0x18;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006537
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006538 alc_pick_fixup(codec, alc269_fixup_models,
6539 alc269_fixup_tbl, alc269_fixups);
6540 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6541
6542 alc_auto_parse_customize_define(codec);
6543
Kailang Yang065380f2013-01-10 10:25:48 +01006544 switch (codec->vendor_id) {
6545 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006546 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006547 switch (alc_get_coef0(codec) & 0x00f0) {
6548 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006549 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006550 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006551 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006552 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006553 break;
6554 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006555 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6556 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006557 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006558 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006559 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006560 case 0x0030:
6561 spec->codec_variant = ALC269_TYPE_ALC269VD;
6562 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006563 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006564 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006565 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006566 if (err < 0)
6567 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006568 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006569 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006570 break;
6571
6572 case 0x10ec0280:
6573 case 0x10ec0290:
6574 spec->codec_variant = ALC269_TYPE_ALC280;
6575 break;
6576 case 0x10ec0282:
6577 case 0x10ec0283:
6578 spec->codec_variant = ALC269_TYPE_ALC282;
6579 break;
6580 case 0x10ec0284:
6581 case 0x10ec0292:
6582 spec->codec_variant = ALC269_TYPE_ALC284;
6583 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006584 }
6585
Takashi Iwaia4297b52011-08-23 18:40:12 +02006586 /* automatic parse from the BIOS config */
6587 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006588 if (err < 0)
6589 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006590
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006591 if (!spec->no_analog && has_cdefine_beep(codec)) {
6592 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006593 if (err < 0)
6594 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006595 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006596 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006597
Takashi Iwai1d045db2011-07-07 18:23:21 +02006598 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006599#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006600 codec->patch_ops.resume = alc269_resume;
6601#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006602 spec->shutup = alc269_shutup;
6603
Takashi Iwai589876e2012-02-20 15:47:55 +01006604 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6605
Takashi Iwai1d045db2011-07-07 18:23:21 +02006606 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006607
6608 error:
6609 alc_free(codec);
6610 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006611}
6612
6613/*
6614 * ALC861
6615 */
6616
Takashi Iwai1d045db2011-07-07 18:23:21 +02006617static int alc861_parse_auto_config(struct hda_codec *codec)
6618{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006619 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006620 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6621 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006622}
6623
Takashi Iwai1d045db2011-07-07 18:23:21 +02006624/* Pin config fixes */
6625enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006626 ALC861_FIXUP_FSC_AMILO_PI1505,
6627 ALC861_FIXUP_AMP_VREF_0F,
6628 ALC861_FIXUP_NO_JACK_DETECT,
6629 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006630};
6631
Takashi Iwai31150f22012-01-30 10:54:08 +01006632/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6633static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6634 const struct alc_fixup *fix, int action)
6635{
6636 struct alc_spec *spec = codec->spec;
6637 unsigned int val;
6638
6639 if (action != ALC_FIXUP_ACT_INIT)
6640 return;
6641 val = snd_hda_codec_read(codec, 0x0f, 0,
6642 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6643 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6644 val |= AC_PINCTL_IN_EN;
6645 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006646 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006647 spec->keep_vref_in_automute = 1;
6648}
6649
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006650/* suppress the jack-detection */
6651static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6652 const struct alc_fixup *fix, int action)
6653{
6654 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6655 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006656}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006657
Takashi Iwai1d045db2011-07-07 18:23:21 +02006658static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006659 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006660 .type = ALC_FIXUP_PINS,
6661 .v.pins = (const struct alc_pincfg[]) {
6662 { 0x0b, 0x0221101f }, /* HP */
6663 { 0x0f, 0x90170310 }, /* speaker */
6664 { }
6665 }
6666 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006667 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006668 .type = ALC_FIXUP_FUNC,
6669 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006670 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006671 [ALC861_FIXUP_NO_JACK_DETECT] = {
6672 .type = ALC_FIXUP_FUNC,
6673 .v.func = alc_fixup_no_jack_detect,
6674 },
6675 [ALC861_FIXUP_ASUS_A6RP] = {
6676 .type = ALC_FIXUP_FUNC,
6677 .v.func = alc861_fixup_asus_amp_vref_0f,
6678 .chained = true,
6679 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6680 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006681};
6682
6683static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006684 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6685 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6686 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6687 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6688 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6689 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006690 {}
6691};
6692
6693/*
6694 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006695static int patch_alc861(struct hda_codec *codec)
6696{
6697 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006698 int err;
6699
Takashi Iwai3de95172012-05-07 18:03:15 +02006700 err = alc_alloc_spec(codec, 0x15);
6701 if (err < 0)
6702 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006703
Takashi Iwai3de95172012-05-07 18:03:15 +02006704 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006705
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006706 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6707 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006708
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006709 /* automatic parse from the BIOS config */
6710 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006711 if (err < 0)
6712 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006713
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006714 if (!spec->no_analog) {
6715 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006716 if (err < 0)
6717 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006718 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6719 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006720
Takashi Iwai1d045db2011-07-07 18:23:21 +02006721 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006722#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006723 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006724#endif
6725
Takashi Iwai589876e2012-02-20 15:47:55 +01006726 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6727
Takashi Iwai1d045db2011-07-07 18:23:21 +02006728 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006729
6730 error:
6731 alc_free(codec);
6732 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006733}
6734
6735/*
6736 * ALC861-VD support
6737 *
6738 * Based on ALC882
6739 *
6740 * In addition, an independent DAC
6741 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006742static int alc861vd_parse_auto_config(struct hda_codec *codec)
6743{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006744 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006745 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6746 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006747}
6748
Takashi Iwai1d045db2011-07-07 18:23:21 +02006749enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006750 ALC660VD_FIX_ASUS_GPIO1,
6751 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006752};
6753
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006754/* exclude VREF80 */
6755static void alc861vd_fixup_dallas(struct hda_codec *codec,
6756 const struct alc_fixup *fix, int action)
6757{
6758 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006759 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6760 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006761 }
6762}
6763
Takashi Iwai1d045db2011-07-07 18:23:21 +02006764static const struct alc_fixup alc861vd_fixups[] = {
6765 [ALC660VD_FIX_ASUS_GPIO1] = {
6766 .type = ALC_FIXUP_VERBS,
6767 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006768 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006769 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6770 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6771 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6772 { }
6773 }
6774 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006775 [ALC861VD_FIX_DALLAS] = {
6776 .type = ALC_FIXUP_FUNC,
6777 .v.func = alc861vd_fixup_dallas,
6778 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006779};
6780
6781static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006782 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006783 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006784 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006785 {}
6786};
6787
Takashi Iwai1d045db2011-07-07 18:23:21 +02006788/*
6789 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006790static int patch_alc861vd(struct hda_codec *codec)
6791{
6792 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006793 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006794
Takashi Iwai3de95172012-05-07 18:03:15 +02006795 err = alc_alloc_spec(codec, 0x0b);
6796 if (err < 0)
6797 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006798
Takashi Iwai3de95172012-05-07 18:03:15 +02006799 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006800
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006801 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6802 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006803
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006804 /* automatic parse from the BIOS config */
6805 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006806 if (err < 0)
6807 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006808
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006809 if (!spec->no_analog) {
6810 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006811 if (err < 0)
6812 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006813 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6814 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006815
Takashi Iwai1d045db2011-07-07 18:23:21 +02006816 codec->patch_ops = alc_patch_ops;
6817
Takashi Iwai1d045db2011-07-07 18:23:21 +02006818 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006819
Takashi Iwai589876e2012-02-20 15:47:55 +01006820 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6821
Takashi Iwai1d045db2011-07-07 18:23:21 +02006822 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006823
6824 error:
6825 alc_free(codec);
6826 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006827}
6828
6829/*
6830 * ALC662 support
6831 *
6832 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6833 * configuration. Each pin widget can choose any input DACs and a mixer.
6834 * Each ADC is connected from a mixer of all inputs. This makes possible
6835 * 6-channel independent captures.
6836 *
6837 * In addition, an independent DAC for the multi-playback (not used in this
6838 * driver yet).
6839 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006840
6841/*
6842 * BIOS auto configuration
6843 */
6844
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006845static int alc662_parse_auto_config(struct hda_codec *codec)
6846{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006847 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006848 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6849 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6850 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006851
Kailang Yang6227cdc2010-02-25 08:36:52 +01006852 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6853 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006854 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006855 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006856 ssids = alc662_ssids;
6857 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006858}
6859
Todd Broch6be79482010-12-07 16:51:05 -08006860static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006861 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006862{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006863 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006864 return;
Todd Broch6be79482010-12-07 16:51:05 -08006865 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6866 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6867 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6868 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6869 (0 << AC_AMPCAP_MUTE_SHIFT)))
6870 printk(KERN_WARNING
6871 "hda_codec: failed to override amp caps for NID 0x2\n");
6872}
6873
David Henningsson6cb3b702010-09-09 08:51:44 +02006874enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006875 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006876 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006877 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006878 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006879 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006880 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006881 ALC662_FIXUP_ASUS_MODE1,
6882 ALC662_FIXUP_ASUS_MODE2,
6883 ALC662_FIXUP_ASUS_MODE3,
6884 ALC662_FIXUP_ASUS_MODE4,
6885 ALC662_FIXUP_ASUS_MODE5,
6886 ALC662_FIXUP_ASUS_MODE6,
6887 ALC662_FIXUP_ASUS_MODE7,
6888 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006889 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006890 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006891 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006892};
6893
6894static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006895 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006896 .type = ALC_FIXUP_PINS,
6897 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006898 { 0x15, 0x99130112 }, /* subwoofer */
6899 { }
6900 }
6901 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006902 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006903 .type = ALC_FIXUP_PINS,
6904 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006905 { 0x17, 0x99130112 }, /* subwoofer */
6906 { }
6907 }
6908 },
Todd Broch6be79482010-12-07 16:51:05 -08006909 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006910 .type = ALC_FIXUP_FUNC,
6911 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006912 },
6913 [ALC662_FIXUP_CZC_P10T] = {
6914 .type = ALC_FIXUP_VERBS,
6915 .v.verbs = (const struct hda_verb[]) {
6916 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6917 {}
6918 }
6919 },
David Henningsson94024cd2011-04-29 14:10:55 +02006920 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006921 .type = ALC_FIXUP_FUNC,
6922 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006923 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006924 [ALC662_FIXUP_HP_RP5800] = {
6925 .type = ALC_FIXUP_PINS,
6926 .v.pins = (const struct alc_pincfg[]) {
6927 { 0x14, 0x0221201f }, /* HP out */
6928 { }
6929 },
6930 .chained = true,
6931 .chain_id = ALC662_FIXUP_SKU_IGNORE
6932 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006933 [ALC662_FIXUP_ASUS_MODE1] = {
6934 .type = ALC_FIXUP_PINS,
6935 .v.pins = (const struct alc_pincfg[]) {
6936 { 0x14, 0x99130110 }, /* speaker */
6937 { 0x18, 0x01a19c20 }, /* mic */
6938 { 0x19, 0x99a3092f }, /* int-mic */
6939 { 0x21, 0x0121401f }, /* HP out */
6940 { }
6941 },
6942 .chained = true,
6943 .chain_id = ALC662_FIXUP_SKU_IGNORE
6944 },
6945 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006946 .type = ALC_FIXUP_PINS,
6947 .v.pins = (const struct alc_pincfg[]) {
6948 { 0x14, 0x99130110 }, /* speaker */
6949 { 0x18, 0x01a19820 }, /* mic */
6950 { 0x19, 0x99a3092f }, /* int-mic */
6951 { 0x1b, 0x0121401f }, /* HP out */
6952 { }
6953 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006954 .chained = true,
6955 .chain_id = ALC662_FIXUP_SKU_IGNORE
6956 },
6957 [ALC662_FIXUP_ASUS_MODE3] = {
6958 .type = ALC_FIXUP_PINS,
6959 .v.pins = (const struct alc_pincfg[]) {
6960 { 0x14, 0x99130110 }, /* speaker */
6961 { 0x15, 0x0121441f }, /* HP */
6962 { 0x18, 0x01a19840 }, /* mic */
6963 { 0x19, 0x99a3094f }, /* int-mic */
6964 { 0x21, 0x01211420 }, /* HP2 */
6965 { }
6966 },
6967 .chained = true,
6968 .chain_id = ALC662_FIXUP_SKU_IGNORE
6969 },
6970 [ALC662_FIXUP_ASUS_MODE4] = {
6971 .type = ALC_FIXUP_PINS,
6972 .v.pins = (const struct alc_pincfg[]) {
6973 { 0x14, 0x99130110 }, /* speaker */
6974 { 0x16, 0x99130111 }, /* speaker */
6975 { 0x18, 0x01a19840 }, /* mic */
6976 { 0x19, 0x99a3094f }, /* int-mic */
6977 { 0x21, 0x0121441f }, /* HP */
6978 { }
6979 },
6980 .chained = true,
6981 .chain_id = ALC662_FIXUP_SKU_IGNORE
6982 },
6983 [ALC662_FIXUP_ASUS_MODE5] = {
6984 .type = ALC_FIXUP_PINS,
6985 .v.pins = (const struct alc_pincfg[]) {
6986 { 0x14, 0x99130110 }, /* speaker */
6987 { 0x15, 0x0121441f }, /* HP */
6988 { 0x16, 0x99130111 }, /* speaker */
6989 { 0x18, 0x01a19840 }, /* mic */
6990 { 0x19, 0x99a3094f }, /* int-mic */
6991 { }
6992 },
6993 .chained = true,
6994 .chain_id = ALC662_FIXUP_SKU_IGNORE
6995 },
6996 [ALC662_FIXUP_ASUS_MODE6] = {
6997 .type = ALC_FIXUP_PINS,
6998 .v.pins = (const struct alc_pincfg[]) {
6999 { 0x14, 0x99130110 }, /* speaker */
7000 { 0x15, 0x01211420 }, /* HP2 */
7001 { 0x18, 0x01a19840 }, /* mic */
7002 { 0x19, 0x99a3094f }, /* int-mic */
7003 { 0x1b, 0x0121441f }, /* HP */
7004 { }
7005 },
7006 .chained = true,
7007 .chain_id = ALC662_FIXUP_SKU_IGNORE
7008 },
7009 [ALC662_FIXUP_ASUS_MODE7] = {
7010 .type = ALC_FIXUP_PINS,
7011 .v.pins = (const struct alc_pincfg[]) {
7012 { 0x14, 0x99130110 }, /* speaker */
7013 { 0x17, 0x99130111 }, /* speaker */
7014 { 0x18, 0x01a19840 }, /* mic */
7015 { 0x19, 0x99a3094f }, /* int-mic */
7016 { 0x1b, 0x01214020 }, /* HP */
7017 { 0x21, 0x0121401f }, /* HP */
7018 { }
7019 },
7020 .chained = true,
7021 .chain_id = ALC662_FIXUP_SKU_IGNORE
7022 },
7023 [ALC662_FIXUP_ASUS_MODE8] = {
7024 .type = ALC_FIXUP_PINS,
7025 .v.pins = (const struct alc_pincfg[]) {
7026 { 0x14, 0x99130110 }, /* speaker */
7027 { 0x12, 0x99a30970 }, /* int-mic */
7028 { 0x15, 0x01214020 }, /* HP */
7029 { 0x17, 0x99130111 }, /* speaker */
7030 { 0x18, 0x01a19840 }, /* mic */
7031 { 0x21, 0x0121401f }, /* HP */
7032 { }
7033 },
7034 .chained = true,
7035 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007036 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007037 [ALC662_FIXUP_NO_JACK_DETECT] = {
7038 .type = ALC_FIXUP_FUNC,
7039 .v.func = alc_fixup_no_jack_detect,
7040 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007041 [ALC662_FIXUP_ZOTAC_Z68] = {
7042 .type = ALC_FIXUP_PINS,
7043 .v.pins = (const struct alc_pincfg[]) {
7044 { 0x1b, 0x02214020 }, /* Front HP */
7045 { }
7046 }
7047 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007048 [ALC662_FIXUP_INV_DMIC] = {
7049 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007050 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007051 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007052};
7053
Takashi Iwaia9111322011-05-02 11:30:18 +02007054static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007055 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007056 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007057 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007058 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007059 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007060 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007061 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007062 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007063 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007064 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007065 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007066 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007067 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007068
7069#if 0
7070 /* Below is a quirk table taken from the old code.
7071 * Basically the device should work as is without the fixup table.
7072 * If BIOS doesn't give a proper info, enable the corresponding
7073 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007074 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007075 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7076 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7077 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7078 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7079 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7080 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7081 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7082 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7083 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7084 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7085 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7086 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7087 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7088 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7089 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7090 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7091 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7092 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7093 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7094 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7095 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7096 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7097 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7098 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7099 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7100 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7101 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7102 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7103 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7104 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7105 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7106 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7107 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7108 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7109 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7110 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7111 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7112 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7113 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7114 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7115 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7116 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7117 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7118 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7119 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7120 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7121 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7122 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7123 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7124 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7125#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007126 {}
7127};
7128
Todd Broch6be79482010-12-07 16:51:05 -08007129static const struct alc_model_fixup alc662_fixup_models[] = {
7130 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007131 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7132 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7133 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7134 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7135 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7136 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7137 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7138 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007139 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007140 {}
7141};
David Henningsson6cb3b702010-09-09 08:51:44 +02007142
Kailang Yang8663ff72012-06-29 09:35:52 +02007143static void alc662_fill_coef(struct hda_codec *codec)
7144{
7145 int val, coef;
7146
7147 coef = alc_get_coef0(codec);
7148
7149 switch (codec->vendor_id) {
7150 case 0x10ec0662:
7151 if ((coef & 0x00f0) == 0x0030) {
7152 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7153 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7154 }
7155 break;
7156 case 0x10ec0272:
7157 case 0x10ec0273:
7158 case 0x10ec0663:
7159 case 0x10ec0665:
7160 case 0x10ec0670:
7161 case 0x10ec0671:
7162 case 0x10ec0672:
7163 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7164 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7165 break;
7166 }
7167}
David Henningsson6cb3b702010-09-09 08:51:44 +02007168
Takashi Iwai1d045db2011-07-07 18:23:21 +02007169/*
7170 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007171static int patch_alc662(struct hda_codec *codec)
7172{
7173 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007174 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007175
Takashi Iwai3de95172012-05-07 18:03:15 +02007176 err = alc_alloc_spec(codec, 0x0b);
7177 if (err < 0)
7178 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007179
Takashi Iwai3de95172012-05-07 18:03:15 +02007180 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007181
Takashi Iwai53c334a2011-08-23 18:27:14 +02007182 /* handle multiple HPs as is */
7183 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7184
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007185 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7186
Kailang Yang8663ff72012-06-29 09:35:52 +02007187 spec->init_hook = alc662_fill_coef;
7188 alc662_fill_coef(codec);
7189
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007190 alc_pick_fixup(codec, alc662_fixup_models,
7191 alc662_fixup_tbl, alc662_fixups);
7192 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7193
7194 alc_auto_parse_customize_define(codec);
7195
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007196 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007197 codec->bus->pci->subsystem_vendor == 0x1025 &&
7198 spec->cdefine.platform_type == 1) {
7199 if (alc_codec_rename(codec, "ALC272X") < 0)
7200 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007201 }
Kailang Yang274693f2009-12-03 10:07:50 +01007202
Takashi Iwaib9c51062011-08-24 18:08:07 +02007203 /* automatic parse from the BIOS config */
7204 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007205 if (err < 0)
7206 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007207
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007208 if (!spec->no_analog && has_cdefine_beep(codec)) {
7209 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007210 if (err < 0)
7211 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007212 switch (codec->vendor_id) {
7213 case 0x10ec0662:
7214 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7215 break;
7216 case 0x10ec0272:
7217 case 0x10ec0663:
7218 case 0x10ec0665:
7219 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7220 break;
7221 case 0x10ec0273:
7222 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7223 break;
7224 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007225 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007226
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007227 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02007228 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007229
Takashi Iwai589876e2012-02-20 15:47:55 +01007230 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7231
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007232 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007233
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007234 error:
7235 alc_free(codec);
7236 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007237}
7238
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007239/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007240 * ALC680 support
7241 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007242
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007243static int alc680_parse_auto_config(struct hda_codec *codec)
7244{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007245 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007246}
7247
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007248/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007249 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007250static int patch_alc680(struct hda_codec *codec)
7251{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007252 int err;
7253
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007254 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007255 err = alc_alloc_spec(codec, 0);
7256 if (err < 0)
7257 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007258
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007259 /* automatic parse from the BIOS config */
7260 err = alc680_parse_auto_config(codec);
7261 if (err < 0) {
7262 alc_free(codec);
7263 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007264 }
7265
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007266 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007267
7268 return 0;
7269}
7270
7271/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007272 * patch entries
7273 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007274static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007275 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007276 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007277 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007278 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007279 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007280 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007281 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007282 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007283 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007284 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007285 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007286 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007287 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007288 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007289 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007290 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007291 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007292 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007293 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7294 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7295 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007296 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007297 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007298 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7299 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007300 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7301 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007302 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007303 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007304 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007305 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007306 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007307 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007308 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007309 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007310 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007311 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007312 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007313 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007314 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007315 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007316 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007317 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007318 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007319 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007320 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007321 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007322 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007323 {} /* terminator */
7324};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007325
7326MODULE_ALIAS("snd-hda-codec-id:10ec*");
7327
7328MODULE_LICENSE("GPL");
7329MODULE_DESCRIPTION("Realtek HD-audio codec");
7330
7331static struct hda_codec_preset_list realtek_list = {
7332 .preset = snd_hda_preset_realtek,
7333 .owner = THIS_MODULE,
7334};
7335
7336static int __init patch_realtek_init(void)
7337{
7338 return snd_hda_add_codec_preset(&realtek_list);
7339}
7340
7341static void __exit patch_realtek_exit(void)
7342{
7343 snd_hda_delete_codec_preset(&realtek_list);
7344}
7345
7346module_init(patch_realtek_init)
7347module_exit(patch_realtek_exit)