blob: e3fe7350b359a2ff2f0e8206ca416f9250ee27ce [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe409a3e92012-03-27 13:01:01 +10309 * Jonathan Woithe <jwoithe@just42.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Takashi Iwai23d30f22012-05-07 17:17:32 +020035#include "hda_auto_parser.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090036#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020037#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Takashi Iwai1d045db2011-07-07 18:23:21 +020039/* unsol event tags */
40#define ALC_FRONT_EVENT 0x01
41#define ALC_DCVOL_EVENT 0x02
42#define ALC_HP_EVENT 0x04
43#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020044
Kailang Yangdf694da2005-12-05 19:42:22 +010045/* for GPIO Poll */
46#define GPIO_MASK 0x03
47
Takashi Iwai4a79ba32009-04-22 16:31:35 +020048/* extra amp-initialization sequence types */
49enum {
50 ALC_INIT_NONE,
51 ALC_INIT_DEFAULT,
52 ALC_INIT_GPIO1,
53 ALC_INIT_GPIO2,
54 ALC_INIT_GPIO3,
55};
56
Kailang Yangda00c242010-03-19 11:23:45 +010057struct alc_customize_define {
58 unsigned int sku_cfg;
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
65 unsigned int swap:1;
66 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020067 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010068};
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwaic14c95f2012-02-16 16:38:07 +010076#define MAX_VOL_NIDS 0x40
77
Takashi Iwai23d30f22012-05-07 17:17:32 +020078/* make compatible with old code */
79#define alc_apply_pincfgs snd_hda_apply_pincfgs
80#define alc_apply_fixup snd_hda_apply_fixup
81#define alc_pick_fixup snd_hda_pick_fixup
82#define alc_fixup hda_fixup
83#define alc_pincfg hda_pintbl
84#define alc_model_fixup hda_model_fixup
85
86#define ALC_FIXUP_PINS HDA_FIXUP_PINS
87#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
88#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
89
90#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
91#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
92#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
93#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
94
95
Takashi Iwai30dcd3b2012-12-06 15:45:38 +010096#define MAX_NID_PATH_DEPTH 5
97
Takashi Iwai8dd48672012-12-14 18:19:04 +010098enum {
99 NID_PATH_VOL_CTL,
100 NID_PATH_MUTE_CTL,
101 NID_PATH_BOOST_CTL,
102 NID_PATH_NUM_CTLS
103};
104
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100105/* Widget connection path
106 *
107 * For output, stored in the order of DAC -> ... -> pin,
108 * for input, pin -> ... -> ADC.
109 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100110 * idx[i] contains the source index number to select on of the widget path[i];
111 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100112 * multi[] indicates whether it's a selector widget with multi-connectors
113 * (i.e. the connection selection is mandatory)
114 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
115 */
116struct nid_path {
117 int depth;
118 hda_nid_t path[MAX_NID_PATH_DEPTH];
119 unsigned char idx[MAX_NID_PATH_DEPTH];
120 unsigned char multi[MAX_NID_PATH_DEPTH];
Takashi Iwai8dd48672012-12-14 18:19:04 +0100121 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
Takashi Iwai130e5f02012-12-14 16:09:29 +0100122 bool active;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100123};
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200126 struct hda_gen_spec gen;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200129 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 unsigned int num_mixers;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100131 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200133 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200134 const struct hda_pcm_stream *stream_analog_playback;
135 const struct hda_pcm_stream *stream_analog_capture;
136 const struct hda_pcm_stream *stream_analog_alt_playback;
137 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200139 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200140 const struct hda_pcm_stream *stream_digital_playback;
141 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200144 struct hda_multi_out multiout; /* playback set-up
145 * max_channels, dacs must be set
146 * dig_out_nid and hp_nid are optional
147 */
Takashi Iwai63300792008-01-24 15:31:36 +0100148 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100149 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100150 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 /* capture */
153 unsigned int num_adc_nids;
Takashi Iwai27d31532012-12-18 08:57:05 +0100154 hda_nid_t adc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai16ded522005-06-10 19:58:24 +0200155 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200156 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Takashi Iwai840b64c2010-07-13 22:49:01 +0200158 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200159 hda_nid_t cur_adc;
160 unsigned int cur_adc_stream_tag;
161 unsigned int cur_adc_format;
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200164 unsigned int num_mux_defs;
Takashi Iwai27d31532012-12-18 08:57:05 +0100165 struct hda_input_mux input_mux;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200167 hda_nid_t ext_mic_pin;
168 hda_nid_t dock_mic_pin;
169 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100172 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200174 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100175 int const_channel_count; /* min. channel count (for speakers) */
176 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100179 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200180
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200181 /* dynamic controls, init_verbs and input_mux */
182 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100183 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200184 struct snd_array kctls;
Takashi Iwai41923e42007-10-22 17:20:10 +0200185 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200186 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
187 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
188 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200189 hda_nid_t inv_dmic_pin;
Takashi Iwai37c04202012-12-18 14:22:45 +0100190 hda_nid_t shared_mic_vref_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100191
Takashi Iwai463419d2012-12-05 14:17:37 +0100192 /* DAC list */
193 int num_all_dacs;
194 hda_nid_t all_dacs[16];
195
Takashi Iwaic9967f12012-12-14 16:39:22 +0100196 /* path list */
197 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100198
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100199 /* hooks */
200 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200201#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500202 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100203#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200204 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200205 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100206
Takashi Iwai834be882006-03-01 14:16:17 +0100207 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200208 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200209 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200210 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200211 unsigned int auto_mic:1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200212 unsigned int automute_speaker:1; /* automute speaker outputs */
213 unsigned int automute_lo:1; /* automute LO outputs */
214 unsigned int detect_hp:1; /* Headphone detection enabled */
215 unsigned int detect_lo:1; /* Line-out detection enabled */
216 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
217 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100218 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200219
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100220 /* other flags */
221 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200222 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100223 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200224 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200225 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100226 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200227 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
228 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200229 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200230
231 /* auto-mute control */
232 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200233 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200234
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200235 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200236 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100237
Takashi Iwai2134ea42008-01-10 16:53:55 +0100238 /* for virtual master */
239 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100240 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200241#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200242 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100243 int num_loopbacks;
244 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200245#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200246
247 /* for PLL fix */
248 hda_nid_t pll_nid;
249 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200250 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100251
Takashi Iwaice764ab2011-04-27 16:35:23 +0200252 /* multi-io */
253 int multi_ios;
254 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200255
256 /* bind volumes */
257 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100258};
259
Takashi Iwai44c02402011-07-08 15:14:19 +0200260static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
261 int dir, unsigned int bits)
262{
263 if (!nid)
264 return false;
265 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
266 if (query_amp_caps(codec, nid, dir) & bits)
267 return true;
268 return false;
269}
270
271#define nid_has_mute(codec, nid, dir) \
272 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
273#define nid_has_volume(codec, nid, dir) \
274 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
275
Takashi Iwai666a70d2012-12-17 20:29:29 +0100276static struct nid_path *
277get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid);
278static void activate_path(struct hda_codec *codec, struct nid_path *path,
279 bool enable, bool add_aamix);
280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281/*
282 * input MUX handling
283 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200284static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
285 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
288 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +0100289 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200292static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
296 struct alc_spec *spec = codec->spec;
297 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
298
299 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
300 return 0;
301}
302
Takashi Iwai666a70d2012-12-17 20:29:29 +0100303static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
304{
305 struct alc_spec *spec = codec->spec;
306 if (spec->dyn_adc_switch)
307 adc_idx = spec->dyn_adc_idx[imux_idx];
308 return spec->adc_nids[adc_idx];
309}
310
Takashi Iwai21268962011-07-07 15:01:13 +0200311static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Takashi Iwai21268962011-07-07 15:01:13 +0200313 struct alc_spec *spec = codec->spec;
314 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
315
316 if (spec->cur_adc && spec->cur_adc != new_adc) {
317 /* stream is running, let's swap the current ADC */
318 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
319 spec->cur_adc = new_adc;
320 snd_hda_codec_setup_stream(codec, new_adc,
321 spec->cur_adc_stream_tag, 0,
322 spec->cur_adc_format);
323 return true;
324 }
325 return false;
326}
327
Takashi Iwai24de1832011-11-07 17:13:39 +0100328static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200329static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100330static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx);
Takashi Iwai24de1832011-11-07 17:13:39 +0100331
David Henningsson00227f12012-06-27 18:45:44 +0200332/* for shared I/O, change the pin-control accordingly */
333static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
334{
335 struct alc_spec *spec = codec->spec;
336 unsigned int val;
337 hda_nid_t pin = spec->autocfg.inputs[1].pin;
338 /* NOTE: this assumes that there are only two inputs, the
339 * first is the real internal mic and the second is HP/mic jack.
340 */
341
342 val = snd_hda_get_default_vref(codec, pin);
343
344 /* This pin does not have vref caps - let's enable vref on pin 0x18
345 instead, as suggested by Realtek */
Takashi Iwai37c04202012-12-18 14:22:45 +0100346 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
347 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
348 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
349 if (vref_val != AC_PINCTL_VREF_HIZ)
350 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
David Henningsson00227f12012-06-27 18:45:44 +0200351 }
352
353 val = set_as_mic ? val | PIN_IN : PIN_HP;
354 snd_hda_set_pin_ctl(codec, pin, val);
355
356 spec->automute_speaker = !set_as_mic;
357 call_update_outputs(codec);
358}
Takashi Iwai21268962011-07-07 15:01:13 +0200359
360/* select the given imux item; either unmute exclusively or select the route */
361static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
362 unsigned int idx, bool force)
363{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100365 const struct hda_input_mux *imux;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100366 struct nid_path *path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Takashi Iwai27d31532012-12-18 08:57:05 +0100368 imux = &spec->input_mux;
369 if (!imux->num_items)
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100370 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100371
Takashi Iwai21268962011-07-07 15:01:13 +0200372 if (idx >= imux->num_items)
373 idx = imux->num_items - 1;
374 if (spec->cur_mux[adc_idx] == idx && !force)
375 return 0;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100376
377 path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]],
378 spec->adc_nids[adc_idx]);
379 if (!path)
380 return 0;
381 if (path->active)
382 activate_path(codec, path, false, false);
383
Takashi Iwai21268962011-07-07 15:01:13 +0200384 spec->cur_mux[adc_idx] = idx;
385
David Henningsson00227f12012-06-27 18:45:44 +0200386 if (spec->shared_mic_hp)
387 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100388
Takashi Iwai666a70d2012-12-17 20:29:29 +0100389 if (spec->dyn_adc_switch)
Takashi Iwai21268962011-07-07 15:01:13 +0200390 alc_dyn_adc_pcm_resetup(codec, idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200391
Takashi Iwai666a70d2012-12-17 20:29:29 +0100392 path = get_nid_path(codec, spec->imux_pins[idx],
393 get_adc_nid(codec, adc_idx, idx));
394 if (!path)
395 return 0;
396 if (path->active)
397 return 0;
398 activate_path(codec, path, true, false);
Takashi Iwai125821a2012-06-22 14:30:29 +0200399 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200400 return 1;
401}
402
403static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
404 struct snd_ctl_elem_value *ucontrol)
405{
406 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
408 return alc_mux_select(codec, adc_idx,
409 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100410}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100413 * set up the input pin config (depending on the given auto-pin type)
414 */
415static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
416 int auto_pin_type)
417{
418 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200419 if (auto_pin_type == AUTO_PIN_MIC)
420 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200421 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100422}
423
424/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200425 * Append the given mixer and verb elements for the later use
426 * The mixer array is referred in build_controls(), and init_verbs are
427 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100428 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200429static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100430{
431 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
432 return;
433 spec->mixers[spec->num_mixers++] = mix;
434}
435
Takashi Iwaid88897e2008-10-31 15:01:37 +0100436/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200437 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100438 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200439/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200440static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200441 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
442 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
443 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
444 { }
445};
446
Takashi Iwaia9111322011-05-02 11:30:18 +0200447static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200448 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
449 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
450 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
451 { }
452};
453
Takashi Iwaia9111322011-05-02 11:30:18 +0200454static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200455 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
456 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
457 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
458 { }
459};
460
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200461/*
462 * Fix hardware PLL issue
463 * On some codecs, the analog PLL gating control must be off while
464 * the default value is 1.
465 */
466static void alc_fix_pll(struct hda_codec *codec)
467{
468 struct alc_spec *spec = codec->spec;
469 unsigned int val;
470
471 if (!spec->pll_nid)
472 return;
473 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
474 spec->pll_coef_idx);
475 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
476 AC_VERB_GET_PROC_COEF, 0);
477 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
478 spec->pll_coef_idx);
479 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
480 val & ~(1 << spec->pll_coef_bit));
481}
482
483static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
484 unsigned int coef_idx, unsigned int coef_bit)
485{
486 struct alc_spec *spec = codec->spec;
487 spec->pll_nid = nid;
488 spec->pll_coef_idx = coef_idx;
489 spec->pll_coef_bit = coef_bit;
490 alc_fix_pll(codec);
491}
492
Takashi Iwai1d045db2011-07-07 18:23:21 +0200493/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200494 * Jack detections for HP auto-mute and mic-switch
495 */
496
497/* check each pin in the given array; returns true if any of them is plugged */
498static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200499{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200500 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200501
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200502 for (i = 0; i < num_pins; i++) {
503 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200504 if (!nid)
505 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200506 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200507 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200508 return present;
509}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200510
Takashi Iwai1d045db2011-07-07 18:23:21 +0200511/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200512static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200513 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200514{
515 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200516 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 int i;
518
519 for (i = 0; i < num_pins; i++) {
520 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100521 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200522 if (!nid)
523 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100524 /* don't reset VREF value in case it's controlling
525 * the amp (see alc861_fixup_asus_amp_vref_0f())
526 */
527 if (spec->keep_vref_in_automute) {
528 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100529 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100530 val &= ~PIN_HP;
531 } else
532 val = 0;
533 val |= pin_bits;
534 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200535 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200536}
537
David Henningsson42cf0d02011-09-20 12:04:56 +0200538/* Toggle outputs muting */
539static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200540{
541 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200542 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543
Takashi Iwaic0a20262011-06-10 15:28:15 +0200544 /* Control HP pins/amps depending on master_mute state;
545 * in general, HP pins/amps control should be enabled in all cases,
546 * but currently set only for master_mute, just to be safe
547 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100548 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
549 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200550 spec->autocfg.hp_pins, spec->master_mute, true);
551
David Henningsson42cf0d02011-09-20 12:04:56 +0200552 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200553 on = 0;
554 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200555 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200556 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200557 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200558 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200559
560 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200561 /* if LO is a copy of either HP or Speaker, don't need to handle it */
562 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
563 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200564 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200565 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 on = 0;
567 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200568 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200569 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200570 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200571 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200572}
573
David Henningsson42cf0d02011-09-20 12:04:56 +0200574static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200575{
576 struct alc_spec *spec = codec->spec;
577 if (spec->automute_hook)
578 spec->automute_hook(codec);
579 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200580 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200581}
582
Takashi Iwai1d045db2011-07-07 18:23:21 +0200583/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200584static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200585{
586 struct alc_spec *spec = codec->spec;
587
David Henningsson42cf0d02011-09-20 12:04:56 +0200588 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200589 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
590 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200591 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200592 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200593 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200594}
595
Takashi Iwai1d045db2011-07-07 18:23:21 +0200596/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200597static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200598{
599 struct alc_spec *spec = codec->spec;
600
David Henningssonf7f4b232012-10-10 16:32:09 +0200601 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
602 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200603 /* check LO jack only when it's different from HP */
604 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
605 return;
606
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607 spec->line_jack_present =
608 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
609 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200610 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200611 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200612 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200613}
614
Takashi Iwai8d087c72011-06-28 12:45:47 +0200615#define get_connection_index(codec, mux, nid) \
616 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200617
Takashi Iwai1d045db2011-07-07 18:23:21 +0200618/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200619static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200620{
621 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200622 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200623
Takashi Iwai480967d2012-12-18 14:29:52 +0100624 if (!spec->auto_mic)
Takashi Iwai6c819492009-08-10 18:47:44 +0200625 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200626 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200627 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200628
Takashi Iwai21268962011-07-07 15:01:13 +0200629 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
630 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
631 else if (spec->dock_mic_idx >= 0 &&
632 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
633 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
634 else
635 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200636}
637
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100638/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200639static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100640{
641 unsigned int val;
642 struct snd_kcontrol *kctl;
643 struct snd_ctl_elem_value *uctl;
644
645 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
646 if (!kctl)
647 return;
648 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
649 if (!uctl)
650 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200651 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100652 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
653 val &= HDA_AMP_VOLMASK;
654 uctl->value.integer.value[0] = val;
655 uctl->value.integer.value[1] = val;
656 kctl->put(kctl, uctl);
657 kfree(uctl);
658}
659
David Henningsson29adc4b2012-09-25 11:31:00 +0200660static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100661{
David Henningsson29adc4b2012-09-25 11:31:00 +0200662 /* For some reason, the res given from ALC880 is broken.
663 Here we adjust it properly. */
664 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100665}
666
Takashi Iwai1d045db2011-07-07 18:23:21 +0200667/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200668static void alc_inithook(struct hda_codec *codec)
669{
David Henningsson29adc4b2012-09-25 11:31:00 +0200670 alc_hp_automute(codec, NULL);
671 alc_line_automute(codec, NULL);
672 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200673}
674
Kailang Yangf9423e72008-05-27 12:32:25 +0200675/* additional initialization for ALC888 variants */
676static void alc888_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, 0);
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);
Takashi Iwai37db6232009-03-05 09:40:16 +0100683 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200684 /* alc888S-VC */
685 snd_hda_codec_read(codec, 0x20, 0,
686 AC_VERB_SET_PROC_COEF, 0x830);
687 else
688 /* alc888-VB */
689 snd_hda_codec_read(codec, 0x20, 0,
690 AC_VERB_SET_PROC_COEF, 0x3030);
691}
692
Takashi Iwai1d045db2011-07-07 18:23:21 +0200693/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200694static void alc889_coef_init(struct hda_codec *codec)
695{
696 unsigned int tmp;
697
698 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
699 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
700 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
701 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
702}
703
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100704/* turn on/off EAPD control (only if available) */
705static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
706{
707 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
708 return;
709 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
710 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
711 on ? 2 : 0);
712}
713
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200714/* turn on/off EAPD controls of the codec */
715static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
716{
717 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200718 static hda_nid_t pins[] = {
719 0x0f, 0x10, 0x14, 0x15, 0
720 };
721 hda_nid_t *p;
722 for (p = pins; *p; p++)
723 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200724}
725
Takashi Iwai1c716152011-04-07 10:37:16 +0200726/* generic shutup callback;
727 * just turning off EPAD and a little pause for avoiding pop-noise
728 */
729static void alc_eapd_shutup(struct hda_codec *codec)
730{
731 alc_auto_setup_eapd(codec, false);
732 msleep(200);
733}
734
Takashi Iwai1d045db2011-07-07 18:23:21 +0200735/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200736static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200737{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200738 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200739
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200740 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200741 switch (type) {
742 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200743 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
744 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200745 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200746 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
747 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200748 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200749 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
750 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200751 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200752 switch (codec->vendor_id) {
753 case 0x10ec0260:
754 snd_hda_codec_write(codec, 0x1a, 0,
755 AC_VERB_SET_COEF_INDEX, 7);
756 tmp = snd_hda_codec_read(codec, 0x1a, 0,
757 AC_VERB_GET_PROC_COEF, 0);
758 snd_hda_codec_write(codec, 0x1a, 0,
759 AC_VERB_SET_COEF_INDEX, 7);
760 snd_hda_codec_write(codec, 0x1a, 0,
761 AC_VERB_SET_PROC_COEF,
762 tmp | 0x2010);
763 break;
764 case 0x10ec0262:
765 case 0x10ec0880:
766 case 0x10ec0882:
767 case 0x10ec0883:
768 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100769 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100770 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200771 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200772 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200773 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200774 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200775 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100776#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200777 case 0x10ec0267:
778 case 0x10ec0268:
779 snd_hda_codec_write(codec, 0x20, 0,
780 AC_VERB_SET_COEF_INDEX, 7);
781 tmp = snd_hda_codec_read(codec, 0x20, 0,
782 AC_VERB_GET_PROC_COEF, 0);
783 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200784 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200785 snd_hda_codec_write(codec, 0x20, 0,
786 AC_VERB_SET_PROC_COEF,
787 tmp | 0x3000);
788 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100789#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200790 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200791 break;
792 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200793}
Kailang Yangea1fb292008-08-26 12:58:38 +0200794
Takashi Iwai1d045db2011-07-07 18:23:21 +0200795/*
796 * Auto-Mute mode mixer enum support
797 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200798static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
799 struct snd_ctl_elem_info *uinfo)
800{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
802 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200803 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100804 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200805 };
806
Takashi Iwaidda415d2012-11-30 18:34:38 +0100807 if (spec->automute_speaker_possible && spec->automute_lo_possible)
808 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
809 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200810}
811
812static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
813 struct snd_ctl_elem_value *ucontrol)
814{
815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
816 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200817 unsigned int val = 0;
818 if (spec->automute_speaker)
819 val++;
820 if (spec->automute_lo)
821 val++;
822
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200823 ucontrol->value.enumerated.item[0] = val;
824 return 0;
825}
826
827static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_value *ucontrol)
829{
830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831 struct alc_spec *spec = codec->spec;
832
833 switch (ucontrol->value.enumerated.item[0]) {
834 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200835 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200836 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200837 spec->automute_speaker = 0;
838 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200839 break;
840 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200841 if (spec->automute_speaker_possible) {
842 if (!spec->automute_lo && spec->automute_speaker)
843 return 0;
844 spec->automute_speaker = 1;
845 spec->automute_lo = 0;
846 } else if (spec->automute_lo_possible) {
847 if (spec->automute_lo)
848 return 0;
849 spec->automute_lo = 1;
850 } else
851 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200852 break;
853 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200854 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200855 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200856 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200857 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200858 spec->automute_speaker = 1;
859 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200860 break;
861 default:
862 return -EINVAL;
863 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200864 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200865 return 1;
866}
867
Takashi Iwaia9111322011-05-02 11:30:18 +0200868static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200869 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
870 .name = "Auto-Mute Mode",
871 .info = alc_automute_mode_info,
872 .get = alc_automute_mode_get,
873 .put = alc_automute_mode_put,
874};
875
Takashi Iwai668d1e92012-11-29 14:10:17 +0100876static struct snd_kcontrol_new *
877alc_kcontrol_new(struct alc_spec *spec, const char *name,
878 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200879{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100880 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
881 if (!knew)
882 return NULL;
883 *knew = *temp;
884 knew->name = kstrdup(name, GFP_KERNEL);
885 if (!knew->name)
886 return NULL;
887 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200888}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200889
890static int alc_add_automute_mode_enum(struct hda_codec *codec)
891{
892 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200893
Takashi Iwai668d1e92012-11-29 14:10:17 +0100894 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200895 return -ENOMEM;
896 return 0;
897}
898
Takashi Iwai1d045db2011-07-07 18:23:21 +0200899/*
900 * Check the availability of HP/line-out auto-mute;
901 * Set up appropriately if really supported
902 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100903static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200904{
905 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200906 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200907 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100908 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200909
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200910 if (cfg->hp_pins[0])
911 present++;
912 if (cfg->line_out_pins[0])
913 present++;
914 if (cfg->speaker_pins[0])
915 present++;
916 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100917 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200918
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200919 if (!cfg->speaker_pins[0] &&
920 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200921 memcpy(cfg->speaker_pins, cfg->line_out_pins,
922 sizeof(cfg->speaker_pins));
923 cfg->speaker_outs = cfg->line_outs;
924 }
925
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200926 if (!cfg->hp_pins[0] &&
927 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200928 memcpy(cfg->hp_pins, cfg->line_out_pins,
929 sizeof(cfg->hp_pins));
930 cfg->hp_outs = cfg->line_outs;
931 }
932
933 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200934 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200935 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200936 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200937 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200938 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200939 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
940 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200941 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200942 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200943
David Henningsson42cf0d02011-09-20 12:04:56 +0200944 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
945 if (cfg->speaker_outs)
946 for (i = 0; i < cfg->line_outs; i++) {
947 hda_nid_t nid = cfg->line_out_pins[i];
948 if (!is_jack_detectable(codec, nid))
949 continue;
950 snd_printdd("realtek: Enable Line-Out "
951 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200952 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
953 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200954 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200955 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200956 spec->automute_lo_possible = spec->detect_hp;
957 }
958
959 spec->automute_speaker_possible = cfg->speaker_outs &&
960 (spec->detect_hp || spec->detect_lo);
961
962 spec->automute_lo = spec->automute_lo_possible;
963 spec->automute_speaker = spec->automute_speaker_possible;
964
Takashi Iwai475c3d22012-11-30 08:31:30 +0100965 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200966 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100967 err = alc_add_automute_mode_enum(codec);
968 if (err < 0)
969 return err;
970 }
971 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200972}
973
Takashi Iwai1d045db2011-07-07 18:23:21 +0200974/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200975static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
976{
977 int i;
978 for (i = 0; i < nums; i++)
979 if (list[i] == nid)
980 return i;
981 return -1;
982}
983
Takashi Iwai21268962011-07-07 15:01:13 +0200984/* check whether all auto-mic pins are valid; setup indices if OK */
985static bool alc_auto_mic_check_imux(struct hda_codec *codec)
986{
987 struct alc_spec *spec = codec->spec;
988 const struct hda_input_mux *imux;
989
Takashi Iwai27d31532012-12-18 08:57:05 +0100990 imux = &spec->input_mux;
Takashi Iwai21268962011-07-07 15:01:13 +0200991 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
992 spec->imux_pins, imux->num_items);
993 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
994 spec->imux_pins, imux->num_items);
995 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
996 spec->imux_pins, imux->num_items);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100997 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0)
Takashi Iwai21268962011-07-07 15:01:13 +0200998 return false; /* no corresponding imux */
Takashi Iwai21268962011-07-07 15:01:13 +0200999
David Henningsson29adc4b2012-09-25 11:31:00 +02001000 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1001 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001002 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001003 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1004 ALC_MIC_EVENT,
1005 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001006 return true;
1007}
1008
Takashi Iwai1d045db2011-07-07 18:23:21 +02001009/*
1010 * Check the availability of auto-mic switch;
1011 * Set up if really supported
1012 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001013static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001014{
1015 struct alc_spec *spec = codec->spec;
1016 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001017 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001018 int i;
1019
Takashi Iwai21268962011-07-07 15:01:13 +02001020 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1021
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001022 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001023 for (i = 0; i < cfg->num_inputs; i++) {
1024 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001025 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001026 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001027 switch (snd_hda_get_input_pin_attr(defcfg)) {
1028 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001029 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001030 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001031 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001032 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001033 fixed = nid;
1034 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001035 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001036 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001037 case INPUT_PIN_ATTR_DOCK:
1038 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001039 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001040 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001041 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001042 dock = nid;
1043 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001044 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001045 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001046 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001047 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001048 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001049 ext = nid;
1050 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001051 }
1052 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001053 if (!ext && dock) {
1054 ext = dock;
1055 dock = 0;
1056 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001057 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001058 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001059 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001060 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001061 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001062 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001063
1064 /* check imux indices */
1065 spec->ext_mic_pin = ext;
1066 spec->int_mic_pin = fixed;
1067 spec->dock_mic_pin = dock;
1068
Takashi Iwai21268962011-07-07 15:01:13 +02001069 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001070 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001071
Takashi Iwai666a70d2012-12-17 20:29:29 +01001072 spec->auto_mic = 1;
1073 spec->num_adc_nids = 1;
1074 spec->cur_mux[0] = spec->int_mic_idx;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001075 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1076 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001077
1078 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001079}
1080
Takashi Iwai1d045db2011-07-07 18:23:21 +02001081/*
1082 * Realtek SSID verification
1083 */
1084
David Henningsson90622912010-10-14 14:50:18 +02001085/* Could be any non-zero and even value. When used as fixup, tells
1086 * the driver to ignore any present sku defines.
1087 */
1088#define ALC_FIXUP_SKU_IGNORE (2)
1089
Takashi Iwai23d30f22012-05-07 17:17:32 +02001090static void alc_fixup_sku_ignore(struct hda_codec *codec,
1091 const struct hda_fixup *fix, int action)
1092{
1093 struct alc_spec *spec = codec->spec;
1094 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1095 spec->cdefine.fixup = 1;
1096 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1097 }
1098}
1099
Kailang Yangda00c242010-03-19 11:23:45 +01001100static int alc_auto_parse_customize_define(struct hda_codec *codec)
1101{
1102 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001103 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001104 struct alc_spec *spec = codec->spec;
1105
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001106 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1107
David Henningsson90622912010-10-14 14:50:18 +02001108 if (spec->cdefine.fixup) {
1109 ass = spec->cdefine.sku_cfg;
1110 if (ass == ALC_FIXUP_SKU_IGNORE)
1111 return -1;
1112 goto do_sku;
1113 }
1114
Kailang Yangda00c242010-03-19 11:23:45 +01001115 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001116 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001117 goto do_sku;
1118
1119 nid = 0x1d;
1120 if (codec->vendor_id == 0x10ec0260)
1121 nid = 0x17;
1122 ass = snd_hda_codec_get_pincfg(codec, nid);
1123
1124 if (!(ass & 1)) {
1125 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1126 codec->chip_name, ass);
1127 return -1;
1128 }
1129
1130 /* check sum */
1131 tmp = 0;
1132 for (i = 1; i < 16; i++) {
1133 if ((ass >> i) & 1)
1134 tmp++;
1135 }
1136 if (((ass >> 16) & 0xf) != tmp)
1137 return -1;
1138
1139 spec->cdefine.port_connectivity = ass >> 30;
1140 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1141 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1142 spec->cdefine.customization = ass >> 8;
1143do_sku:
1144 spec->cdefine.sku_cfg = ass;
1145 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1146 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1147 spec->cdefine.swap = (ass & 0x2) >> 1;
1148 spec->cdefine.override = ass & 0x1;
1149
1150 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1151 nid, spec->cdefine.sku_cfg);
1152 snd_printd("SKU: port_connectivity=0x%x\n",
1153 spec->cdefine.port_connectivity);
1154 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1155 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1156 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1157 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1158 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1159 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1160 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1161
1162 return 0;
1163}
1164
Takashi Iwai1d045db2011-07-07 18:23:21 +02001165/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001166static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1167{
Takashi Iwai21268962011-07-07 15:01:13 +02001168 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001169}
1170
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001171/* check subsystem ID and set up device-specific initialization;
1172 * return 1 if initialized, 0 if invalid SSID
1173 */
1174/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1175 * 31 ~ 16 : Manufacture ID
1176 * 15 ~ 8 : SKU ID
1177 * 7 ~ 0 : Assembly ID
1178 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1179 */
1180static int alc_subsystem_id(struct hda_codec *codec,
1181 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001182 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001183{
1184 unsigned int ass, tmp, i;
1185 unsigned nid;
1186 struct alc_spec *spec = codec->spec;
1187
David Henningsson90622912010-10-14 14:50:18 +02001188 if (spec->cdefine.fixup) {
1189 ass = spec->cdefine.sku_cfg;
1190 if (ass == ALC_FIXUP_SKU_IGNORE)
1191 return 0;
1192 goto do_sku;
1193 }
1194
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001195 ass = codec->subsystem_id & 0xffff;
1196 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1197 goto do_sku;
1198
1199 /* invalid SSID, check the special NID pin defcfg instead */
1200 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001201 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001202 * 29~21 : reserve
1203 * 20 : PCBEEP input
1204 * 19~16 : Check sum (15:1)
1205 * 15~1 : Custom
1206 * 0 : override
1207 */
1208 nid = 0x1d;
1209 if (codec->vendor_id == 0x10ec0260)
1210 nid = 0x17;
1211 ass = snd_hda_codec_get_pincfg(codec, nid);
1212 snd_printd("realtek: No valid SSID, "
1213 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001214 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001215 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001216 return 0;
1217 if ((ass >> 30) != 1) /* no physical connection */
1218 return 0;
1219
1220 /* check sum */
1221 tmp = 0;
1222 for (i = 1; i < 16; i++) {
1223 if ((ass >> i) & 1)
1224 tmp++;
1225 }
1226 if (((ass >> 16) & 0xf) != tmp)
1227 return 0;
1228do_sku:
1229 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1230 ass & 0xffff, codec->vendor_id);
1231 /*
1232 * 0 : override
1233 * 1 : Swap Jack
1234 * 2 : 0 --> Desktop, 1 --> Laptop
1235 * 3~5 : External Amplifier control
1236 * 7~6 : Reserved
1237 */
1238 tmp = (ass & 0x38) >> 3; /* external Amp control */
1239 switch (tmp) {
1240 case 1:
1241 spec->init_amp = ALC_INIT_GPIO1;
1242 break;
1243 case 3:
1244 spec->init_amp = ALC_INIT_GPIO2;
1245 break;
1246 case 7:
1247 spec->init_amp = ALC_INIT_GPIO3;
1248 break;
1249 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001250 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001251 spec->init_amp = ALC_INIT_DEFAULT;
1252 break;
1253 }
1254
1255 /* is laptop or Desktop and enable the function "Mute internal speaker
1256 * when the external headphone out jack is plugged"
1257 */
1258 if (!(ass & 0x8000))
1259 return 1;
1260 /*
1261 * 10~8 : Jack location
1262 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1263 * 14~13: Resvered
1264 * 15 : 1 --> enable the function "Mute internal speaker
1265 * when the external headphone out jack is plugged"
1266 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001267 if (!spec->autocfg.hp_pins[0] &&
1268 !(spec->autocfg.line_out_pins[0] &&
1269 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001270 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001271 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1272 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001273 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001274 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001275 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001276 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001277 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001278 else if (tmp == 3)
1279 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001280 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001281 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001282 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1283 spec->autocfg.line_outs))
1284 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001285 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001286 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001287 return 1;
1288}
Kailang Yangea1fb292008-08-26 12:58:38 +02001289
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001290/* Check the validity of ALC subsystem-id
1291 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1292static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001293{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001294 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001295 struct alc_spec *spec = codec->spec;
1296 snd_printd("realtek: "
1297 "Enable default setup for auto mode as fallback\n");
1298 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001299 }
Takashi Iwai21268962011-07-07 15:01:13 +02001300}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001301
Takashi Iwai41e41f12005-06-08 14:48:49 +02001302/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001303 * COEF access helper functions
1304 */
Kailang Yang274693f2009-12-03 10:07:50 +01001305static int alc_read_coef_idx(struct hda_codec *codec,
1306 unsigned int coef_idx)
1307{
1308 unsigned int val;
1309 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1310 coef_idx);
1311 val = snd_hda_codec_read(codec, 0x20, 0,
1312 AC_VERB_GET_PROC_COEF, 0);
1313 return val;
1314}
1315
Kailang Yang977ddd62010-09-15 10:02:29 +02001316static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1317 unsigned int coef_val)
1318{
1319 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1320 coef_idx);
1321 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1322 coef_val);
1323}
1324
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001325/* a special bypass for COEF 0; read the cached value at the second time */
1326static unsigned int alc_get_coef0(struct hda_codec *codec)
1327{
1328 struct alc_spec *spec = codec->spec;
1329 if (!spec->coef0)
1330 spec->coef0 = alc_read_coef_idx(codec, 0);
1331 return spec->coef0;
1332}
1333
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001334static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1335 hda_nid_t pin, int pin_type,
1336 hda_nid_t dac);
1337static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1338 bool is_digital);
Takashi Iwai965cceb2012-12-18 11:46:37 +01001339static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
1340 hda_nid_t to_nid, int with_aa_mix,
1341 struct nid_path *path);
1342static struct nid_path *add_new_nid_path(struct hda_codec *codec,
1343 hda_nid_t from_nid, hda_nid_t to_nid,
1344 int with_aa_mix);
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001345
Takashi Iwai1d045db2011-07-07 18:23:21 +02001346/*
1347 * Digital I/O handling
1348 */
1349
Takashi Iwai757899a2010-07-30 10:48:14 +02001350/* set right pin controls for digital I/O */
1351static void alc_auto_init_digital(struct hda_codec *codec)
1352{
1353 struct alc_spec *spec = codec->spec;
1354 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001355 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001356
1357 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1358 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001359 if (!pin)
1360 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001361 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001362 }
1363 pin = spec->autocfg.dig_in_pin;
1364 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001365 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001366}
1367
1368/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1369static void alc_auto_parse_digital(struct hda_codec *codec)
1370{
1371 struct alc_spec *spec = codec->spec;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001372 int i, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001373 hda_nid_t dig_nid;
1374
1375 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001376 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001377 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001378 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1379 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1380 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001381 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001382 if (!add_new_nid_path(codec, dig_nid, pin, 2))
1383 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001384 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001385 spec->multiout.dig_out_nid = dig_nid;
1386 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1387 } else {
1388 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001389 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001390 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001391 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001392 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001393 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001394 }
1395
1396 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001397 dig_nid = codec->start_nid;
1398 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001399 struct nid_path *path;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001400 unsigned int wcaps = get_wcaps(codec, dig_nid);
1401 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1402 continue;
1403 if (!(wcaps & AC_WCAP_DIGITAL))
1404 continue;
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001405 path = add_new_nid_path(codec, spec->autocfg.dig_in_pin,
1406 dig_nid, 2);
1407 if (path) {
1408 path->active = true;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001409 spec->dig_in_nid = dig_nid;
1410 break;
1411 }
1412 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001413 }
1414}
1415
Takashi Iwaif95474e2007-07-10 00:47:43 +02001416/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001417 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001418 */
Takashi Iwai666a70d2012-12-17 20:29:29 +01001419#define alc_cap_vol_info snd_hda_mixer_amp_volume_info
1420#define alc_cap_vol_get snd_hda_mixer_amp_volume_get
1421#define alc_cap_vol_tlv snd_hda_mixer_amp_tlv
1422
1423typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
1424 struct snd_ctl_elem_value *ucontrol);
1425
1426static int alc_cap_put_caller(struct snd_kcontrol *kcontrol,
1427 struct snd_ctl_elem_value *ucontrol,
1428 put_call_t func, int type)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001429{
1430 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1431 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001432 const struct hda_input_mux *imux;
1433 struct nid_path *path;
1434 int i, adc_idx, err = 0;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001435
Takashi Iwai27d31532012-12-18 08:57:05 +01001436 imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001437 adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001438 mutex_lock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001439 codec->cached_write = 1;
1440 for (i = 0; i < imux->num_items; i++) {
1441 path = get_nid_path(codec, spec->imux_pins[i],
1442 get_adc_nid(codec, adc_idx, i));
1443 if (!path->ctls[type])
1444 continue;
1445 kcontrol->private_value = path->ctls[type];
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001446 err = func(kcontrol, ucontrol);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001447 if (err < 0)
1448 goto error;
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001449 }
1450 error:
Takashi Iwai666a70d2012-12-17 20:29:29 +01001451 codec->cached_write = 0;
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001452 mutex_unlock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001453 snd_hda_codec_resume_amp(codec);
1454 if (err >= 0 && type == NID_PATH_MUTE_CTL &&
1455 spec->inv_dmic_fixup && spec->inv_dmic_muted)
1456 alc_inv_dmic_sync_adc(codec, adc_idx);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001457 return err;
1458}
1459
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001460static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1461 struct snd_ctl_elem_value *ucontrol)
1462{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001463 return alc_cap_put_caller(kcontrol, ucontrol,
1464 snd_hda_mixer_amp_volume_put,
1465 NID_PATH_VOL_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001466}
1467
1468/* capture mixer elements */
1469#define alc_cap_sw_info snd_ctl_boolean_stereo_info
Takashi Iwai666a70d2012-12-17 20:29:29 +01001470#define alc_cap_sw_get snd_hda_mixer_amp_switch_get
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001471
1472static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1473 struct snd_ctl_elem_value *ucontrol)
1474{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001475 return alc_cap_put_caller(kcontrol, ucontrol,
1476 snd_hda_mixer_amp_switch_put,
1477 NID_PATH_MUTE_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001478}
1479
Takashi Iwai666a70d2012-12-17 20:29:29 +01001480static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1481{
1482 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01001483 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001484 struct nid_path *path;
1485 hda_nid_t nid;
1486 int i, dir, parm;
1487 unsigned int val;
1488
1489 for (i = 0; i < imux->num_items; i++) {
1490 if (spec->imux_pins[i] == spec->inv_dmic_pin)
1491 break;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001492 }
Takashi Iwai666a70d2012-12-17 20:29:29 +01001493 if (i >= imux->num_items)
1494 return;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001495
Takashi Iwai666a70d2012-12-17 20:29:29 +01001496 path = get_nid_path(codec, spec->inv_dmic_pin,
1497 get_adc_nid(codec, adc_idx, i));
1498 val = path->ctls[NID_PATH_MUTE_CTL];
1499 if (!val)
1500 return;
1501 nid = get_amp_nid_(val);
1502 dir = get_amp_direction_(val);
1503 parm = AC_AMP_SET_RIGHT |
1504 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001505
Takashi Iwai666a70d2012-12-17 20:29:29 +01001506 /* we care only right channel */
1507 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1508 if (val & 0x80) /* if already muted, we don't need to touch */
1509 return;
1510 val |= 0x80;
1511 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1512 parm | val);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001513}
1514
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001515/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001516 * Inverted digital-mic handling
1517 *
1518 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1519 * gives the additional mute only to the right channel of the digital mic
1520 * capture stream. This is a workaround for avoiding the almost silence
1521 * by summing the stereo stream from some (known to be ForteMedia)
1522 * digital mic unit.
1523 *
1524 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1525 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1526 * without caching so that the cache can still keep the original value.
1527 * The cached value is then restored when the flag is set off or any other
1528 * than d-mic is used as the current input source.
1529 */
1530static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1531{
1532 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001533 int src, nums;
Takashi Iwai125821a2012-06-22 14:30:29 +02001534
1535 if (!spec->inv_dmic_fixup)
1536 return;
1537 if (!spec->inv_dmic_muted && !force)
1538 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001539 nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids;
1540 for (src = 0; src < nums; src++) {
Takashi Iwai125821a2012-06-22 14:30:29 +02001541 bool dmic_fixup = false;
Takashi Iwai125821a2012-06-22 14:30:29 +02001542
1543 if (spec->inv_dmic_muted &&
1544 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1545 dmic_fixup = true;
1546 if (!dmic_fixup && !force)
1547 continue;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001548 alc_inv_dmic_sync_adc(codec, src);
Takashi Iwai125821a2012-06-22 14:30:29 +02001549 }
1550}
1551
1552static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1553 struct snd_ctl_elem_value *ucontrol)
1554{
1555 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1556 struct alc_spec *spec = codec->spec;
1557
1558 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1559 return 0;
1560}
1561
1562static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1563 struct snd_ctl_elem_value *ucontrol)
1564{
1565 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1566 struct alc_spec *spec = codec->spec;
1567 unsigned int val = !ucontrol->value.integer.value[0];
1568
1569 if (val == spec->inv_dmic_muted)
1570 return 0;
1571 spec->inv_dmic_muted = val;
1572 alc_inv_dmic_sync(codec, true);
1573 return 0;
1574}
1575
1576static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1577 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1578 .info = snd_ctl_boolean_mono_info,
1579 .get = alc_inv_dmic_sw_get,
1580 .put = alc_inv_dmic_sw_put,
1581};
1582
1583static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1584{
1585 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001586
1587 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1588 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001589 return -ENOMEM;
1590 spec->inv_dmic_fixup = 1;
1591 spec->inv_dmic_muted = 0;
1592 spec->inv_dmic_pin = nid;
1593 return 0;
1594}
1595
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001596/* typically the digital mic is put at node 0x12 */
1597static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1598 const struct alc_fixup *fix, int action)
1599{
1600 if (action == ALC_FIXUP_ACT_PROBE)
1601 alc_add_inv_dmic_mixer(codec, 0x12);
1602}
1603
Takashi Iwai125821a2012-06-22 14:30:29 +02001604/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001605 * virtual master controls
1606 */
1607
1608/*
1609 * slave controls for virtual master
1610 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001611static const char * const alc_slave_pfxs[] = {
1612 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001613 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001614 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001615 NULL,
1616};
1617
1618/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001619 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001621
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001622#define NID_MAPPING (-1)
1623
Takashi Iwai603c4012008-07-30 15:01:44 +02001624static void alc_free_kctls(struct hda_codec *codec);
1625
Takashi Iwai67d634c2009-11-16 15:35:59 +01001626#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001627/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001628static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001629 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001630 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001631 { } /* end */
1632};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001633#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001634
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001635static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
1637 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001638 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
1640 for (i = 0; i < spec->num_mixers; i++) {
1641 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1642 if (err < 0)
1643 return err;
1644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001646 err = snd_hda_create_dig_out_ctls(codec,
1647 spec->multiout.dig_out_nid,
1648 spec->multiout.dig_out_nid,
1649 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 if (err < 0)
1651 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001652 if (!spec->no_analog) {
1653 err = snd_hda_create_spdif_share_sw(codec,
1654 &spec->multiout);
1655 if (err < 0)
1656 return err;
1657 spec->multiout.share_spdif = 1;
1658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 }
1660 if (spec->dig_in_nid) {
1661 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1662 if (err < 0)
1663 return err;
1664 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001665
Takashi Iwai67d634c2009-11-16 15:35:59 +01001666#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001667 /* create beep controls if needed */
1668 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001669 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001670 for (knew = alc_beep_mixer; knew->name; knew++) {
1671 struct snd_kcontrol *kctl;
1672 kctl = snd_ctl_new1(knew, codec);
1673 if (!kctl)
1674 return -ENOMEM;
1675 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001676 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001677 if (err < 0)
1678 return err;
1679 }
1680 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001681#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001682
Takashi Iwai2134ea42008-01-10 16:53:55 +01001683 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001684 if (!spec->no_analog &&
1685 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001686 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001687 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001688 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001689 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001690 vmaster_tlv, alc_slave_pfxs,
1691 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001692 if (err < 0)
1693 return err;
1694 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001695 if (!spec->no_analog &&
1696 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001697 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1698 NULL, alc_slave_pfxs,
1699 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001700 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001701 if (err < 0)
1702 return err;
1703 }
1704
Takashi Iwaibae84e72010-03-22 08:30:20 +01001705 alc_free_kctls(codec); /* no longer needed */
1706
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001707 return 0;
1708}
1709
David Henningsson5780b622012-06-27 18:45:45 +02001710static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001711{
1712 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001713
1714 if (spec->shared_mic_hp) {
1715 int err;
1716 int nid = spec->autocfg.inputs[1].pin;
1717 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1718 if (err < 0)
1719 return err;
1720 err = snd_hda_jack_detect_enable(codec, nid, 0);
1721 if (err < 0)
1722 return err;
1723 }
1724
1725 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1726}
1727
1728static int alc_build_controls(struct hda_codec *codec)
1729{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001730 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001731 if (err < 0)
1732 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001733
1734 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001735 if (err < 0)
1736 return err;
1737 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1738 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739}
1740
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001741
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001743 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001744 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001745
Takashi Iwai070cff42012-02-21 12:54:17 +01001746static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748static int alc_init(struct hda_codec *codec)
1749{
1750 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001751
Takashi Iwai546bb672012-03-07 08:37:19 +01001752 if (spec->init_hook)
1753 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001754
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001755 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001756 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001757
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02001758 snd_hda_gen_apply_verbs(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001759 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001760
Takashi Iwai58701122011-01-13 15:41:45 +01001761 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1762
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001763 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 return 0;
1765}
1766
Takashi Iwai83012a72012-08-24 18:38:08 +02001767#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001768static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1769{
1770 struct alc_spec *spec = codec->spec;
1771 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1772}
1773#endif
1774
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775/*
1776 * Analog playback callbacks
1777 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001778static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001780 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
1782 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001783 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1784 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785}
1786
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001787static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 struct hda_codec *codec,
1789 unsigned int stream_tag,
1790 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001791 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792{
1793 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001794 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1795 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796}
1797
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001798static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001800 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801{
1802 struct alc_spec *spec = codec->spec;
1803 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1804}
1805
1806/*
1807 * Digital out
1808 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001809static int alc_dig_playback_pcm_open(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_open(codec, &spec->multiout);
1815}
1816
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001817static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001818 struct hda_codec *codec,
1819 unsigned int stream_tag,
1820 unsigned int format,
1821 struct snd_pcm_substream *substream)
1822{
1823 struct alc_spec *spec = codec->spec;
1824 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1825 stream_tag, format, substream);
1826}
1827
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001828static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001829 struct hda_codec *codec,
1830 struct snd_pcm_substream *substream)
1831{
1832 struct alc_spec *spec = codec->spec;
1833 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1834}
1835
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001836static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001838 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839{
1840 struct alc_spec *spec = codec->spec;
1841 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1842}
1843
1844/*
1845 * Analog capture
1846 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001847static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 struct hda_codec *codec,
1849 unsigned int stream_tag,
1850 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001851 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852{
1853 struct alc_spec *spec = codec->spec;
1854
Takashi Iwai63300792008-01-24 15:31:36 +01001855 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 stream_tag, 0, format);
1857 return 0;
1858}
1859
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001860static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001862 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863{
1864 struct alc_spec *spec = codec->spec;
1865
Takashi Iwai888afa12008-03-18 09:57:50 +01001866 snd_hda_codec_cleanup_stream(codec,
1867 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 return 0;
1869}
1870
Takashi Iwai840b64c2010-07-13 22:49:01 +02001871/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02001872static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001873 struct hda_codec *codec,
1874 unsigned int stream_tag,
1875 unsigned int format,
1876 struct snd_pcm_substream *substream)
1877{
1878 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001879 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02001880 spec->cur_adc_stream_tag = stream_tag;
1881 spec->cur_adc_format = format;
1882 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1883 return 0;
1884}
1885
Takashi Iwai21268962011-07-07 15:01:13 +02001886static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001887 struct hda_codec *codec,
1888 struct snd_pcm_substream *substream)
1889{
1890 struct alc_spec *spec = codec->spec;
1891 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1892 spec->cur_adc = 0;
1893 return 0;
1894}
1895
Takashi Iwai21268962011-07-07 15:01:13 +02001896static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02001897 .substreams = 1,
1898 .channels_min = 2,
1899 .channels_max = 2,
1900 .nid = 0, /* fill later */
1901 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02001902 .prepare = dyn_adc_capture_pcm_prepare,
1903 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02001904 },
1905};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
1907/*
1908 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001909static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 .substreams = 1,
1911 .channels_min = 2,
1912 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001913 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001915 .open = alc_playback_pcm_open,
1916 .prepare = alc_playback_pcm_prepare,
1917 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 },
1919};
1920
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001921static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001922 .substreams = 1,
1923 .channels_min = 2,
1924 .channels_max = 2,
1925 /* NID is set in alc_build_pcms */
1926};
1927
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001928static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01001929 .substreams = 1,
1930 .channels_min = 2,
1931 .channels_max = 2,
1932 /* NID is set in alc_build_pcms */
1933};
1934
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001935static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001936 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 .channels_min = 2,
1938 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001939 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001941 .prepare = alc_alt_capture_pcm_prepare,
1942 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 },
1944};
1945
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001946static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 .substreams = 1,
1948 .channels_min = 2,
1949 .channels_max = 2,
1950 /* NID is set in alc_build_pcms */
1951 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001952 .open = alc_dig_playback_pcm_open,
1953 .close = alc_dig_playback_pcm_close,
1954 .prepare = alc_dig_playback_pcm_prepare,
1955 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 },
1957};
1958
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001959static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 .substreams = 1,
1961 .channels_min = 2,
1962 .channels_max = 2,
1963 /* NID is set in alc_build_pcms */
1964};
1965
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001966/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02001967static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001968 .substreams = 0,
1969 .channels_min = 0,
1970 .channels_max = 0,
1971};
1972
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973static int alc_build_pcms(struct hda_codec *codec)
1974{
1975 struct alc_spec *spec = codec->spec;
1976 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001977 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01001978 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 int i;
1980
1981 codec->num_pcms = 1;
1982 codec->pcm_info = info;
1983
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001984 if (spec->no_analog)
1985 goto skip_analog;
1986
Takashi Iwai812a2cc2009-05-16 10:00:49 +02001987 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1988 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01001990
Takashi Iwaieedec3d2012-02-06 10:24:04 +01001991 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001992 p = spec->stream_analog_playback;
1993 if (!p)
1994 p = &alc_pcm_analog_playback;
1995 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001996 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02001997 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1998 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01001999 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2000 spec->autocfg.line_outs == 2)
2001 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2002 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002003 }
Takashi Iwai27d31532012-12-18 08:57:05 +01002004 if (spec->num_adc_nids) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002005 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002006 if (!p) {
2007 if (spec->dyn_adc_switch)
2008 p = &dyn_adc_pcm_analog_capture;
2009 else
2010 p = &alc_pcm_analog_capture;
2011 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002012 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002013 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2014 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
Takashi Iwai4a471b72005-12-07 13:56:29 +01002016 if (spec->channel_mode) {
2017 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2018 for (i = 0; i < spec->num_channel_mode; i++) {
2019 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2020 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 }
2023 }
2024
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002025 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002026 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002028 snprintf(spec->stream_name_digital,
2029 sizeof(spec->stream_name_digital),
2030 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002031 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002032 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002033 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002035 if (spec->dig_out_type)
2036 info->pcm_type = spec->dig_out_type;
2037 else
2038 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002039 if (spec->multiout.dig_out_nid) {
2040 p = spec->stream_digital_playback;
2041 if (!p)
2042 p = &alc_pcm_digital_playback;
2043 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2045 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002046 if (spec->dig_in_nid) {
2047 p = spec->stream_digital_capture;
2048 if (!p)
2049 p = &alc_pcm_digital_capture;
2050 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2052 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002053 /* FIXME: do we need this for all Realtek codec models? */
2054 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 }
2056
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002057 if (spec->no_analog)
2058 return 0;
2059
Takashi Iwaie08a0072006-09-07 17:52:14 +02002060 /* If the use of more than one ADC is requested for the current
2061 * model, configure a second analog capture-only PCM.
2062 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002063 have_multi_adcs = (spec->num_adc_nids > 1) &&
Takashi Iwai27d31532012-12-18 08:57:05 +01002064 !spec->dyn_adc_switch && !spec->auto_mic;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002065 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002066 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002067 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002068 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002069 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002070 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002071 p = spec->stream_analog_alt_playback;
2072 if (!p)
2073 p = &alc_pcm_analog_alt_playback;
2074 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002075 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2076 spec->alt_dac_nid;
2077 } else {
2078 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2079 alc_pcm_null_stream;
2080 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2081 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002082 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002083 p = spec->stream_analog_alt_capture;
2084 if (!p)
2085 p = &alc_pcm_analog_alt_capture;
2086 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002087 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2088 spec->adc_nids[1];
2089 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2090 spec->num_adc_nids - 1;
2091 } else {
2092 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2093 alc_pcm_null_stream;
2094 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002095 }
2096 }
2097
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 return 0;
2099}
2100
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002101static inline void alc_shutup(struct hda_codec *codec)
2102{
Takashi Iwai1c716152011-04-07 10:37:16 +02002103 struct alc_spec *spec = codec->spec;
2104
2105 if (spec && spec->shutup)
2106 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002107 snd_hda_shutup_pins(codec);
2108}
2109
Takashi Iwai603c4012008-07-30 15:01:44 +02002110static void alc_free_kctls(struct hda_codec *codec)
2111{
2112 struct alc_spec *spec = codec->spec;
2113
2114 if (spec->kctls.list) {
2115 struct snd_kcontrol_new *kctl = spec->kctls.list;
2116 int i;
2117 for (i = 0; i < spec->kctls.used; i++)
2118 kfree(kctl[i].name);
2119 }
2120 snd_array_free(&spec->kctls);
2121}
2122
Takashi Iwai23c09b02011-08-19 09:05:35 +02002123static void alc_free_bind_ctls(struct hda_codec *codec)
2124{
2125 struct alc_spec *spec = codec->spec;
2126 if (spec->bind_ctls.list) {
2127 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2128 int i;
2129 for (i = 0; i < spec->bind_ctls.used; i++)
2130 kfree(ctl[i]);
2131 }
2132 snd_array_free(&spec->bind_ctls);
2133}
2134
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135static void alc_free(struct hda_codec *codec)
2136{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002137 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002138
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002139 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002140 return;
2141
Takashi Iwai603c4012008-07-30 15:01:44 +02002142 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002143 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002144 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002145 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002146 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002147 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148}
2149
Takashi Iwai83012a72012-08-24 18:38:08 +02002150#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002151static void alc_power_eapd(struct hda_codec *codec)
2152{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002153 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002154}
2155
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002156static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002157{
2158 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002159 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002160 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002161 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002162 return 0;
2163}
2164#endif
2165
Takashi Iwai2a439522011-07-26 09:52:50 +02002166#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002167static int alc_resume(struct hda_codec *codec)
2168{
Takashi Iwai1c716152011-04-07 10:37:16 +02002169 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002170 codec->patch_ops.init(codec);
2171 snd_hda_codec_resume_amp(codec);
2172 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002173 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002174 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002175 return 0;
2176}
Takashi Iwaie044c392008-10-27 16:56:24 +01002177#endif
2178
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179/*
2180 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002181static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 .build_controls = alc_build_controls,
2183 .build_pcms = alc_build_pcms,
2184 .init = alc_init,
2185 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002186 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002187#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002188 .resume = alc_resume,
2189#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002190#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002191 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002192 .check_power_status = alc_check_power_status,
2193#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002194 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195};
2196
David Henningsson29adc4b2012-09-25 11:31:00 +02002197
Kailang Yangc027ddc2010-03-19 11:33:06 +01002198/* replace the codec chip_name with the given string */
2199static int alc_codec_rename(struct hda_codec *codec, const char *name)
2200{
2201 kfree(codec->chip_name);
2202 codec->chip_name = kstrdup(name, GFP_KERNEL);
2203 if (!codec->chip_name) {
2204 alc_free(codec);
2205 return -ENOMEM;
2206 }
2207 return 0;
2208}
2209
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002210/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002211 * Rename codecs appropriately from COEF value
2212 */
2213struct alc_codec_rename_table {
2214 unsigned int vendor_id;
2215 unsigned short coef_mask;
2216 unsigned short coef_bits;
2217 const char *name;
2218};
2219
2220static struct alc_codec_rename_table rename_tbl[] = {
2221 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2222 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2223 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2224 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2225 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2226 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2227 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002228 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002229 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2230 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2231 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2232 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2233 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2234 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2235 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2236 { } /* terminator */
2237};
2238
2239static int alc_codec_rename_from_preset(struct hda_codec *codec)
2240{
2241 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002242
2243 for (p = rename_tbl; p->vendor_id; p++) {
2244 if (p->vendor_id != codec->vendor_id)
2245 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002246 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002247 return alc_codec_rename(codec, p->name);
2248 }
2249 return 0;
2250}
2251
2252/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002253 * Automatic parse of I/O pins from the BIOS configuration
2254 */
2255
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002256enum {
2257 ALC_CTL_WIDGET_VOL,
2258 ALC_CTL_WIDGET_MUTE,
2259 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002260 ALC_CTL_BIND_VOL,
2261 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002262};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002263static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002264 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2265 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002266 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002267 HDA_BIND_VOL(NULL, 0),
2268 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002269};
2270
2271/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002272static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002273 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002274{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002275 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002276
Takashi Iwai668d1e92012-11-29 14:10:17 +01002277 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002278 if (!knew)
2279 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002280 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002281 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002282 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002283 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002284 return 0;
2285}
2286
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002287static int add_control_with_pfx(struct alc_spec *spec, int type,
2288 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002289 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002290{
2291 char name[32];
2292 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002293 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002294}
2295
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002296#define add_pb_vol_ctrl(spec, type, pfx, val) \
2297 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2298#define add_pb_sw_ctrl(spec, type, pfx, val) \
2299 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2300#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2301 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2302#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2303 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002304
Takashi Iwai23c09b02011-08-19 09:05:35 +02002305static const char * const channel_name[4] = {
2306 "Front", "Surround", "CLFE", "Side"
2307};
2308
Takashi Iwai6843ca12011-06-24 11:03:58 +02002309static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2310 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002311{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002312 struct auto_pin_cfg *cfg = &spec->autocfg;
2313
Takashi Iwai6843ca12011-06-24 11:03:58 +02002314 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002315 if (cfg->line_outs == 1 && !spec->multi_ios &&
2316 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002317 return "Master";
2318
2319 switch (cfg->line_out_type) {
2320 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002321 if (cfg->line_outs == 1)
2322 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002323 if (cfg->line_outs == 2)
2324 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002325 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002326 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002327 /* for multi-io case, only the primary out */
2328 if (ch && spec->multi_ios)
2329 break;
2330 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002331 return "Headphone";
2332 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002333 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002334 return "PCM";
2335 break;
2336 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002337 if (ch >= ARRAY_SIZE(channel_name)) {
2338 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002339 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002340 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002341
2342 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002343}
2344
Takashi Iwai83012a72012-08-24 18:38:08 +02002345#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002346/* add the powersave loopback-list entry */
2347static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2348{
2349 struct hda_amp_list *list;
2350
2351 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2352 return;
2353 list = spec->loopback_list + spec->num_loopbacks;
2354 list->nid = mix;
2355 list->dir = HDA_INPUT;
2356 list->idx = idx;
2357 spec->num_loopbacks++;
2358 spec->loopback.amplist = spec->loopback_list;
2359}
2360#else
2361#define add_loopback_list(spec, mix, idx) /* NOP */
2362#endif
2363
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002364/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002365static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002366 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002367 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002368{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002369 struct alc_spec *spec = codec->spec;
2370 struct nid_path *path;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002371 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002372 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002373
Takashi Iwaibd32f782012-12-12 18:08:52 +01002374 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2375 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2376 return 0; /* no need for analog loopback */
2377
Takashi Iwai965cceb2012-12-18 11:46:37 +01002378 path = add_new_nid_path(codec, pin, mix_nid, 2);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002379 if (!path)
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002380 return -EINVAL;
2381
2382 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002383 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002384 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2385 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002386 if (err < 0)
2387 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002388 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002389 }
2390
2391 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002392 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2393 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002394 if (err < 0)
2395 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002396 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002397 }
2398
Takashi Iwai829f69e2012-12-14 18:26:02 +01002399 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002400 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002401 return 0;
2402}
2403
Takashi Iwai05f5f472009-08-25 13:10:18 +02002404static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002405{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002406 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2407 return (pincap & AC_PINCAP_IN) != 0;
2408}
2409
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002410/* check whether the given two widgets can be connected */
2411static bool is_reachable_path(struct hda_codec *codec,
2412 hda_nid_t from_nid, hda_nid_t to_nid)
2413{
2414 if (!from_nid || !to_nid)
2415 return false;
2416 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2417}
2418
Takashi Iwai666a70d2012-12-17 20:29:29 +01002419/* Parse the codec tree and retrieve ADCs */
2420static int alc_auto_fill_adc_nids(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002421{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002422 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002423 hda_nid_t nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002424 hda_nid_t *adc_nids = spec->adc_nids;
2425 int max_nums = ARRAY_SIZE(spec->adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002426 int i, nums = 0;
2427
2428 nid = codec->start_nid;
2429 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwaib7821702011-07-06 15:12:46 +02002430 unsigned int caps = get_wcaps(codec, nid);
2431 int type = get_wcaps_type(caps);
2432
2433 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2434 continue;
2435 adc_nids[nums] = nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002436 if (++nums >= max_nums)
2437 break;
2438 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002439 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002440 return nums;
2441}
2442
Takashi Iwai666a70d2012-12-17 20:29:29 +01002443/* filter out invalid adc_nids that don't give all active input pins;
2444 * if needed, check whether dynamic ADC-switching is available
2445 */
2446static int check_dyn_adc_switch(struct hda_codec *codec)
2447{
2448 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002449 struct hda_input_mux *imux = &spec->input_mux;
2450 hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)];
Takashi Iwai666a70d2012-12-17 20:29:29 +01002451 int i, n, nums;
2452 hda_nid_t pin, adc;
2453
2454 again:
2455 nums = 0;
2456 for (n = 0; n < spec->num_adc_nids; n++) {
2457 adc = spec->adc_nids[n];
2458 for (i = 0; i < imux->num_items; i++) {
2459 pin = spec->imux_pins[i];
2460 if (!is_reachable_path(codec, pin, adc))
2461 break;
2462 }
2463 if (i >= imux->num_items)
2464 adc_nids[nums++] = adc;
2465 }
2466
2467 if (!nums) {
2468 if (spec->shared_mic_hp) {
2469 spec->shared_mic_hp = 0;
Takashi Iwai27d31532012-12-18 08:57:05 +01002470 imux->num_items = 1;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002471 goto again;
2472 }
2473
2474 /* check whether ADC-switch is possible */
2475 for (i = 0; i < imux->num_items; i++) {
2476 pin = spec->imux_pins[i];
2477 for (n = 0; n < spec->num_adc_nids; n++) {
2478 adc = spec->adc_nids[n];
2479 if (is_reachable_path(codec, pin, adc)) {
2480 spec->dyn_adc_idx[i] = n;
2481 break;
2482 }
2483 }
2484 }
2485
2486 snd_printdd("realtek: enabling ADC switching\n");
2487 spec->dyn_adc_switch = 1;
2488 } else if (nums != spec->num_adc_nids) {
Takashi Iwai27d31532012-12-18 08:57:05 +01002489 memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t));
Takashi Iwai666a70d2012-12-17 20:29:29 +01002490 spec->num_adc_nids = nums;
2491 }
2492
Takashi Iwai27d31532012-12-18 08:57:05 +01002493 if (imux->num_items == 1 || spec->shared_mic_hp) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002494 snd_printdd("realtek: reducing to a single ADC\n");
2495 spec->num_adc_nids = 1; /* reduce to a single ADC */
2496 }
2497
2498 return 0;
2499}
2500
2501/* templates for capture controls */
2502static const struct snd_kcontrol_new cap_src_temp = {
2503 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2504 .name = "Input Source",
2505 .info = alc_mux_enum_info,
2506 .get = alc_mux_enum_get,
2507 .put = alc_mux_enum_put,
2508};
2509
2510static const struct snd_kcontrol_new cap_vol_temp = {
2511 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2512 .name = "Capture Volume",
2513 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2514 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2515 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2516 .info = alc_cap_vol_info,
2517 .get = alc_cap_vol_get,
2518 .put = alc_cap_vol_put,
2519 .tlv = { .c = alc_cap_vol_tlv },
2520};
2521
2522static const struct snd_kcontrol_new cap_sw_temp = {
2523 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2524 .name = "Capture Switch",
2525 .info = alc_cap_sw_info,
2526 .get = alc_cap_sw_get,
2527 .put = alc_cap_sw_put,
2528};
2529
2530static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2531{
2532 hda_nid_t nid;
2533 int i, depth;
2534
2535 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2536 for (depth = 0; depth < 3; depth++) {
2537 if (depth >= path->depth)
2538 return -EINVAL;
2539 i = path->depth - depth - 1;
2540 nid = path->path[i];
2541 if (!path->ctls[NID_PATH_VOL_CTL]) {
2542 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2543 path->ctls[NID_PATH_VOL_CTL] =
2544 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2545 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2546 int idx = path->idx[i];
2547 if (!depth && codec->single_adc_amp)
2548 idx = 0;
2549 path->ctls[NID_PATH_VOL_CTL] =
2550 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2551 }
2552 }
2553 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2554 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2555 path->ctls[NID_PATH_MUTE_CTL] =
2556 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2557 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2558 int idx = path->idx[i];
2559 if (!depth && codec->single_adc_amp)
2560 idx = 0;
2561 path->ctls[NID_PATH_MUTE_CTL] =
2562 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2563 }
2564 }
2565 }
2566 return 0;
2567}
2568
2569static int create_capture_mixers(struct hda_codec *codec)
2570{
2571 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002572 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002573 struct snd_kcontrol_new *knew;
2574 int i, n, nums;
2575
2576 if (spec->dyn_adc_switch)
2577 nums = 1;
2578 else
2579 nums = spec->num_adc_nids;
2580
2581 if (!spec->auto_mic && imux->num_items > 1) {
2582 knew = alc_kcontrol_new(spec, "Input Source", &cap_src_temp);
2583 if (!knew)
2584 return -ENOMEM;
2585 knew->count = nums;
2586 }
2587
2588 for (n = 0; n < nums; n++) {
2589 int vol, sw;
2590
2591 vol = sw = 0;
2592 for (i = 0; i < imux->num_items; i++) {
2593 struct nid_path *path;
2594 path = get_nid_path(codec, spec->imux_pins[i],
2595 get_adc_nid(codec, n, i));
2596 if (!path)
2597 continue;
2598 parse_capvol_in_path(codec, path);
2599 if (!vol)
2600 vol = path->ctls[NID_PATH_VOL_CTL];
2601 if (!sw)
2602 sw = path->ctls[NID_PATH_MUTE_CTL];
2603 }
2604
2605 if (vol) {
2606 knew = alc_kcontrol_new(spec, "Capture Volume",
2607 &cap_vol_temp);
2608 if (!knew)
2609 return -ENOMEM;
2610 knew->index = n;
2611 knew->private_value = vol;
2612 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2613 }
2614 if (sw) {
2615 knew = alc_kcontrol_new(spec, "Capture Switch",
2616 &cap_sw_temp);
2617 if (!knew)
2618 return -ENOMEM;
2619 knew->index = n;
2620 knew->private_value = sw;
2621 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2622 }
2623 }
2624
2625 return 0;
2626}
2627
Takashi Iwai05f5f472009-08-25 13:10:18 +02002628/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002629static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002630{
2631 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002632 const struct auto_pin_cfg *cfg = &spec->autocfg;
2633 hda_nid_t mixer = spec->mixer_nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002634 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwaib7821702011-07-06 15:12:46 +02002635 int num_adcs;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002636 int i, c, err, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002637 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002638
Takashi Iwai666a70d2012-12-17 20:29:29 +01002639 num_adcs = alc_auto_fill_adc_nids(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002640 if (num_adcs < 0)
2641 return 0;
2642
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002643 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002644 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002645 const char *label;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002646 bool imux_added;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002647
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002648 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002649 if (!alc_is_input_pin(codec, pin))
2650 continue;
2651
David Henningsson5322bf22011-01-05 11:03:56 +01002652 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002653 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2654 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002655 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002656 type_idx++;
2657 else
2658 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002659 prev_label = label;
2660
Takashi Iwai05f5f472009-08-25 13:10:18 +02002661 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002662 if (is_reachable_path(codec, pin, mixer)) {
2663 err = new_analog_input(codec, pin,
2664 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002665 if (err < 0)
2666 return err;
2667 }
2668 }
2669
Takashi Iwai666a70d2012-12-17 20:29:29 +01002670 imux_added = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002671 for (c = 0; c < num_adcs; c++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002672 struct nid_path *path;
2673 hda_nid_t adc = spec->adc_nids[c];
2674
2675 if (!is_reachable_path(codec, pin, adc))
2676 continue;
2677 path = snd_array_new(&spec->paths);
2678 if (!path)
2679 return -ENOMEM;
2680 memset(path, 0, sizeof(*path));
2681 if (!parse_nid_path(codec, pin, adc, 2, path)) {
2682 snd_printd(KERN_ERR
2683 "invalid input path 0x%x -> 0x%x\n",
2684 pin, adc);
2685 spec->paths.used--;
2686 continue;
2687 }
2688
2689 if (!imux_added) {
2690 spec->imux_pins[imux->num_items] = pin;
2691 snd_hda_add_imux_item(imux, label,
2692 imux->num_items, NULL);
2693 imux_added = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002694 }
2695 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002696 }
Takashi Iwai21268962011-07-07 15:01:13 +02002697
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002698 return 0;
2699}
2700
Takashi Iwai24de1832011-11-07 17:13:39 +01002701/* create a shared input with the headphone out */
2702static int alc_auto_create_shared_input(struct hda_codec *codec)
2703{
2704 struct alc_spec *spec = codec->spec;
2705 struct auto_pin_cfg *cfg = &spec->autocfg;
2706 unsigned int defcfg;
2707 hda_nid_t nid;
2708
2709 /* only one internal input pin? */
2710 if (cfg->num_inputs != 1)
2711 return 0;
2712 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2713 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2714 return 0;
2715
2716 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2717 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2718 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2719 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2720 else
2721 return 0; /* both not available */
2722
2723 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2724 return 0; /* no input */
2725
2726 cfg->inputs[1].pin = nid;
2727 cfg->inputs[1].type = AUTO_PIN_MIC;
2728 cfg->num_inputs = 2;
2729 spec->shared_mic_hp = 1;
2730 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2731 return 0;
2732}
2733
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002734static int get_pin_type(int line_out_type)
2735{
2736 if (line_out_type == AUTO_PIN_HP_OUT)
2737 return PIN_HP;
2738 else
2739 return PIN_OUT;
2740}
2741
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002742static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002743{
2744 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002745 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002746 int i;
2747
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002748 for (i = 0; i < cfg->num_inputs; i++) {
2749 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai62343992012-12-18 09:06:01 +01002750 if (alc_is_input_pin(codec, nid))
Takashi Iwai30ea0982010-09-16 18:47:56 +02002751 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002752
Takashi Iwai829f69e2012-12-14 18:26:02 +01002753 /* mute loopback inputs */
2754 if (spec->mixer_nid) {
2755 struct nid_path *path;
2756 path = get_nid_path(codec, nid, spec->mixer_nid);
2757 if (path)
Takashi Iwai666a70d2012-12-17 20:29:29 +01002758 activate_path(codec, path, path->active, false);
Takashi Iwai829f69e2012-12-14 18:26:02 +01002759 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002760 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002761}
2762
Takashi Iwai185d99f2012-02-16 18:39:45 +01002763static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2764{
2765 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002766 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002767
Takashi Iwaic9967f12012-12-14 16:39:22 +01002768 for (i = 0; i < spec->paths.used; i++) {
2769 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002770 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002771 return true;
2772 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002773 return false;
2774}
2775
Takashi Iwai463419d2012-12-05 14:17:37 +01002776/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002777static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2778 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002779{
2780 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002781 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002782 int i;
2783
2784 for (i = 0; i < spec->num_all_dacs; i++) {
2785 hda_nid_t nid = spec->all_dacs[i];
2786 if (!nid || alc_is_dac_already_used(codec, nid))
2787 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002788 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2789 if (is_digital != cap_digital)
2790 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002791 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002792 return nid;
2793 }
2794 return 0;
2795}
2796
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002797/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002798static bool __parse_nid_path(struct hda_codec *codec,
2799 hda_nid_t from_nid, hda_nid_t to_nid,
2800 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002801{
2802 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002803 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002804 int i, nums;
2805
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002806 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002807 if (!with_aa_mix)
2808 return false;
2809 with_aa_mix = 2; /* mark aa-mix is included */
2810 }
2811
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002812 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002813 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002814 if (conn[i] != from_nid) {
2815 /* special case: when from_nid is 0,
2816 * try to find an empty DAC
2817 */
2818 if (from_nid ||
2819 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2820 alc_is_dac_already_used(codec, conn[i]))
2821 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002822 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002823 /* aa-mix is requested but not included? */
2824 if (!(spec->mixer_nid && with_aa_mix == 1))
2825 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002826 }
2827 if (depth >= MAX_NID_PATH_DEPTH)
2828 return false;
2829 for (i = 0; i < nums; i++) {
2830 unsigned int type;
2831 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002832 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2833 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002834 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002835 if (__parse_nid_path(codec, from_nid, conn[i],
2836 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002837 goto found;
2838 }
2839 return false;
2840
2841 found:
2842 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002843 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002844 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002845 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002846 path->depth++;
2847 return true;
2848}
2849
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002850/* parse the widget path from the given nid to the target nid;
2851 * when @from_nid is 0, try to find an empty DAC;
2852 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2853 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2854 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002855 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002856static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2857 hda_nid_t to_nid, int with_aa_mix,
2858 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002859{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002860 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2861 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002862 path->depth++;
2863#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002864 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002865 path->depth, path->path[0], path->path[1],
2866 path->path[2], path->path[3], path->path[4]);
2867#endif
2868 return true;
2869 }
2870 return false;
2871}
2872
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002873static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2874{
Takashi Iwai140547e2012-02-16 17:23:46 +01002875 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002876 int i;
2877 hda_nid_t nid_found = 0;
2878
2879 for (i = 0; i < spec->num_all_dacs; i++) {
2880 hda_nid_t nid = spec->all_dacs[i];
2881 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002882 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002883 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01002884 if (nid_found)
2885 return 0;
2886 nid_found = nid;
2887 }
2888 }
2889 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002890}
2891
Takashi Iwaiba8111272012-12-06 18:06:23 +01002892static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002893{
Takashi Iwaiba8111272012-12-06 18:06:23 +01002894 struct alc_spec *spec = codec->spec;
2895 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002896
Takashi Iwaic9967f12012-12-14 16:39:22 +01002897 for (i = 0; i < spec->paths.used; i++) {
2898 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002899 if (path->ctls[type] == val)
2900 return true;
2901 }
2902 return false;
2903}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002904
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002905/* badness definition */
2906enum {
2907 /* No primary DAC is found for the main output */
2908 BAD_NO_PRIMARY_DAC = 0x10000,
2909 /* No DAC is found for the extra output */
2910 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01002911 /* No possible multi-ios */
2912 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002913 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01002914 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002915 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01002916 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002917 /* Primary DAC shared with main surrounds */
2918 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002919 /* Primary DAC shared with main CLFE */
2920 BAD_SHARED_CLFE = 0x10,
2921 /* Primary DAC shared with extra surrounds */
2922 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01002923 /* Volume widget is shared */
2924 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002925};
2926
2927static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002928 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002929static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002930 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002931
Takashi Iwai965cceb2012-12-18 11:46:37 +01002932static struct nid_path *add_new_nid_path(struct hda_codec *codec,
2933 hda_nid_t from_nid, hda_nid_t to_nid,
2934 int with_aa_mix)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002935{
2936 struct alc_spec *spec = codec->spec;
2937 struct nid_path *path;
2938
Takashi Iwai965cceb2012-12-18 11:46:37 +01002939 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
2940 return NULL;
2941
Takashi Iwaic9967f12012-12-14 16:39:22 +01002942 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002943 if (!path)
Takashi Iwai965cceb2012-12-18 11:46:37 +01002944 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002945 memset(path, 0, sizeof(*path));
Takashi Iwai965cceb2012-12-18 11:46:37 +01002946 if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path))
2947 return path;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002948 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01002949 spec->paths.used--;
Takashi Iwai965cceb2012-12-18 11:46:37 +01002950 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002951}
2952
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002953/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01002954 * passing 0 to either @pin or @dac behaves as a wildcard
2955 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002956static struct nid_path *
2957get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01002958{
2959 struct alc_spec *spec = codec->spec;
2960 int i;
2961
Takashi Iwaic9967f12012-12-14 16:39:22 +01002962 for (i = 0; i < spec->paths.used; i++) {
2963 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002964 if (path->depth <= 0)
2965 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002966 if ((!from_nid || path->path[0] == from_nid) &&
2967 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01002968 return path;
2969 }
2970 return NULL;
2971}
2972
Takashi Iwai792cf2f2012-12-10 16:04:30 +01002973/* look for widgets in the path between the given NIDs appropriate for
2974 * volume and mute controls, and assign the values to ctls[].
2975 *
2976 * When no appropriate widget is found in the path, the badness value
2977 * is incremented depending on the situation. The function returns the
2978 * total badness for both volume and mute controls.
2979 */
2980static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
2981 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002982{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002983 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002984 hda_nid_t nid;
2985 unsigned int val;
2986 int badness = 0;
2987
Takashi Iwaiba8111272012-12-06 18:06:23 +01002988 if (!path)
2989 return BAD_SHARED_VOL * 2;
2990 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002991 if (nid) {
2992 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002993 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002994 badness += BAD_SHARED_VOL;
2995 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01002996 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002997 } else
2998 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01002999 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003000 if (nid) {
3001 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003002 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3003 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003004 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3005 else
3006 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003007 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003008 badness += BAD_SHARED_VOL;
3009 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003010 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003011 } else
3012 badness += BAD_SHARED_VOL;
3013 return badness;
3014}
3015
Takashi Iwaidc31b582012-02-17 17:27:53 +01003016struct badness_table {
3017 int no_primary_dac; /* no primary DAC */
3018 int no_dac; /* no secondary DACs */
3019 int shared_primary; /* primary DAC is shared with main output */
3020 int shared_surr; /* secondary DAC shared with main or primary */
3021 int shared_clfe; /* third DAC shared with main or primary */
3022 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3023};
3024
3025static struct badness_table main_out_badness = {
3026 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3027 .no_dac = BAD_NO_DAC,
3028 .shared_primary = BAD_NO_PRIMARY_DAC,
3029 .shared_surr = BAD_SHARED_SURROUND,
3030 .shared_clfe = BAD_SHARED_CLFE,
3031 .shared_surr_main = BAD_SHARED_SURROUND,
3032};
3033
3034static struct badness_table extra_out_badness = {
3035 .no_primary_dac = BAD_NO_DAC,
3036 .no_dac = BAD_NO_DAC,
3037 .shared_primary = BAD_NO_EXTRA_DAC,
3038 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3039 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3040 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3041};
3042
3043/* try to assign DACs to pins and return the resultant badness */
3044static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3045 const hda_nid_t *pins, hda_nid_t *dacs,
3046 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003047{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003048 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003049 struct auto_pin_cfg *cfg = &spec->autocfg;
3050 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003051 int badness = 0;
3052 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003053
Takashi Iwai185d99f2012-02-16 18:39:45 +01003054 if (!num_outs)
3055 return 0;
3056
Takashi Iwaidc31b582012-02-17 17:27:53 +01003057 for (i = 0; i < num_outs; i++) {
3058 hda_nid_t pin = pins[i];
3059 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003060 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003061 if (!dacs[i] && !i) {
3062 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003063 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003064 dacs[0] = dacs[j];
3065 dacs[j] = 0;
3066 break;
3067 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003068 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003069 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003070 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003071 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003072 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003073 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003074 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003075 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003076 dac = spec->private_dac_nids[i];
3077 if (dac) {
3078 if (!i)
3079 badness += bad->shared_primary;
3080 else if (i == 1)
3081 badness += bad->shared_surr;
3082 else
3083 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003084 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003085 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003086 badness += bad->shared_surr_main;
3087 } else if (!i)
3088 badness += bad->no_primary_dac;
3089 else
3090 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003091 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003092 if (!add_new_nid_path(codec, dac, pin, 0))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003093 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003094 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003095 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003096 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003097
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003098 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003099}
3100
3101static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003102 hda_nid_t reference_pin,
3103 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003104
Takashi Iwai185d99f2012-02-16 18:39:45 +01003105static bool alc_map_singles(struct hda_codec *codec, int outs,
3106 const hda_nid_t *pins, hda_nid_t *dacs)
3107{
3108 int i;
3109 bool found = false;
3110 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003111 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003112 if (dacs[i])
3113 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003114 dac = get_dac_if_single(codec, pins[i]);
3115 if (!dac)
3116 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003117 if (add_new_nid_path(codec, dac, pins[i], 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003118 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003119 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003120 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003121 }
3122 return found;
3123}
3124
Takashi Iwai7085ec12009-10-02 09:03:58 +02003125/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003126static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003127 bool fill_hardwired,
3128 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003129{
3130 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003131 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003132 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003133
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003134 /* set num_dacs once to full for alc_auto_look_for_dac() */
3135 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003136 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003137 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3138 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3139 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003140 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003141 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003142 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003143
3144 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003145 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003146 bool mapped;
3147 do {
3148 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003149 cfg->line_out_pins,
3150 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003151 mapped |= alc_map_singles(codec, cfg->hp_outs,
3152 cfg->hp_pins,
3153 spec->multiout.hp_out_nid);
3154 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3155 cfg->speaker_pins,
3156 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003157 if (fill_mio_first && cfg->line_outs == 1 &&
3158 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3159 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3160 if (!err)
3161 mapped = true;
3162 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003163 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003164 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003165
Takashi Iwaidc31b582012-02-17 17:27:53 +01003166 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3167 spec->private_dac_nids,
3168 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003169
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003170 /* re-count num_dacs and squash invalid entries */
3171 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003172 for (i = 0; i < cfg->line_outs; i++) {
3173 if (spec->private_dac_nids[i])
3174 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003175 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003176 memmove(spec->private_dac_nids + i,
3177 spec->private_dac_nids + i + 1,
3178 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003179 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3180 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003181 }
3182
Takashi Iwai276dd702012-02-17 16:17:03 +01003183 if (fill_mio_first &&
3184 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003185 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003186 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003187 if (err < 0)
3188 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003189 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003190 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003191
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003192 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003193 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3194 spec->multiout.hp_out_nid,
3195 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003196 if (err < 0)
3197 return err;
3198 badness += err;
3199 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003200 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003201 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3202 cfg->speaker_pins,
3203 spec->multiout.extra_out_nid,
3204 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003205 if (err < 0)
3206 return err;
3207 badness += err;
3208 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003209 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3210 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003211 if (err < 0)
3212 return err;
3213 badness += err;
3214 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003215 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3216 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003217 int offset = 0;
3218 if (cfg->line_outs >= 3)
3219 offset = 1;
3220 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3221 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003222 if (err < 0)
3223 return err;
3224 badness += err;
3225 }
3226
3227 if (spec->multi_ios == 2) {
3228 for (i = 0; i < 2; i++)
3229 spec->private_dac_nids[spec->multiout.num_dacs++] =
3230 spec->multi_io[i].dac;
3231 spec->ext_channel_count = 2;
3232 } else if (spec->multi_ios) {
3233 spec->multi_ios = 0;
3234 badness += BAD_MULTI_IO;
3235 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003236
3237 return badness;
3238}
3239
3240#define DEBUG_BADNESS
3241
3242#ifdef DEBUG_BADNESS
3243#define debug_badness snd_printdd
3244#else
3245#define debug_badness(...)
3246#endif
3247
3248static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3249{
3250 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3251 cfg->line_out_pins[0], cfg->line_out_pins[1],
3252 cfg->line_out_pins[2], cfg->line_out_pins[2],
3253 spec->multiout.dac_nids[0],
3254 spec->multiout.dac_nids[1],
3255 spec->multiout.dac_nids[2],
3256 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003257 if (spec->multi_ios > 0)
3258 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3259 spec->multi_ios,
3260 spec->multi_io[0].pin, spec->multi_io[1].pin,
3261 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003262 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3263 cfg->hp_pins[0], cfg->hp_pins[1],
3264 cfg->hp_pins[2], cfg->hp_pins[2],
3265 spec->multiout.hp_out_nid[0],
3266 spec->multiout.hp_out_nid[1],
3267 spec->multiout.hp_out_nid[2],
3268 spec->multiout.hp_out_nid[3]);
3269 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3270 cfg->speaker_pins[0], cfg->speaker_pins[1],
3271 cfg->speaker_pins[2], cfg->speaker_pins[3],
3272 spec->multiout.extra_out_nid[0],
3273 spec->multiout.extra_out_nid[1],
3274 spec->multiout.extra_out_nid[2],
3275 spec->multiout.extra_out_nid[3]);
3276}
3277
Takashi Iwai463419d2012-12-05 14:17:37 +01003278/* find all available DACs of the codec */
3279static void alc_fill_all_nids(struct hda_codec *codec)
3280{
3281 struct alc_spec *spec = codec->spec;
3282 int i;
3283 hda_nid_t nid = codec->start_nid;
3284
3285 spec->num_all_dacs = 0;
3286 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3287 for (i = 0; i < codec->num_nodes; i++, nid++) {
3288 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3289 continue;
3290 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3291 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3292 break;
3293 }
3294 spec->all_dacs[spec->num_all_dacs++] = nid;
3295 }
3296}
3297
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003298static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3299{
3300 struct alc_spec *spec = codec->spec;
3301 struct auto_pin_cfg *cfg = &spec->autocfg;
3302 struct auto_pin_cfg *best_cfg;
3303 int best_badness = INT_MAX;
3304 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003305 bool fill_hardwired = true, fill_mio_first = true;
3306 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003307 bool hp_spk_swapped = false;
3308
Takashi Iwai463419d2012-12-05 14:17:37 +01003309 alc_fill_all_nids(codec);
3310
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003311 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3312 if (!best_cfg)
3313 return -ENOMEM;
3314 *best_cfg = *cfg;
3315
3316 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003317 badness = fill_and_eval_dacs(codec, fill_hardwired,
3318 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003319 if (badness < 0) {
3320 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003321 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003322 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003323 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3324 cfg->line_out_type, fill_hardwired, fill_mio_first,
3325 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003326 debug_show_configs(spec, cfg);
3327 if (badness < best_badness) {
3328 best_badness = badness;
3329 *best_cfg = *cfg;
3330 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003331 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003332 }
3333 if (!badness)
3334 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003335 fill_mio_first = !fill_mio_first;
3336 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003337 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003338 fill_hardwired = !fill_hardwired;
3339 if (!fill_hardwired)
3340 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003341 if (hp_spk_swapped)
3342 break;
3343 hp_spk_swapped = true;
3344 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003345 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3346 cfg->hp_outs = cfg->line_outs;
3347 memcpy(cfg->hp_pins, cfg->line_out_pins,
3348 sizeof(cfg->hp_pins));
3349 cfg->line_outs = cfg->speaker_outs;
3350 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3351 sizeof(cfg->speaker_pins));
3352 cfg->speaker_outs = 0;
3353 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3354 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003355 fill_hardwired = true;
3356 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003357 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003358 if (cfg->hp_outs > 0 &&
3359 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3360 cfg->speaker_outs = cfg->line_outs;
3361 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3362 sizeof(cfg->speaker_pins));
3363 cfg->line_outs = cfg->hp_outs;
3364 memcpy(cfg->line_out_pins, cfg->hp_pins,
3365 sizeof(cfg->hp_pins));
3366 cfg->hp_outs = 0;
3367 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3368 cfg->line_out_type = AUTO_PIN_HP_OUT;
3369 fill_hardwired = true;
3370 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003371 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003372 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003373 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003374
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003375 if (badness) {
3376 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003377 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003378 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003379 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3380 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003381 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003382
Takashi Iwaiba8111272012-12-06 18:06:23 +01003383 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003384 struct nid_path *path = get_nid_path(codec,
3385 spec->multiout.dac_nids[0],
3386 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003387 if (path)
3388 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3389 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003390
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003391 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003392 return 0;
3393}
3394
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003395/* replace the channels in the composed amp value with the given number */
3396static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3397{
3398 val &= ~(0x3U << 16);
3399 val |= chs << 16;
3400 return val;
3401}
3402
Takashi Iwai343a04b2011-07-06 14:28:39 +02003403static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003404 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003405 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003406 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003407{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003408 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003409 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003410 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003411 val = path->ctls[NID_PATH_VOL_CTL];
3412 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003413 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003414 val = amp_val_replace_channels(val, chs);
3415 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3416}
3417
3418/* return the channel bits suitable for the given path->ctls[] */
3419static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3420 int type)
3421{
3422 int chs = 1; /* mono (left only) */
3423 if (path) {
3424 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3425 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3426 chs = 3; /* stereo */
3427 }
3428 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003429}
3430
Takashi Iwaie29d3772011-11-14 17:13:23 +01003431static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3432 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003433 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003434{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003435 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3436 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003437}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003438
3439/* create a mute-switch for the given mixer widget;
3440 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3441 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003442static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003443 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003444 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003445 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003446{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003447 unsigned int val;
3448 int type = ALC_CTL_WIDGET_MUTE;
3449
3450 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003451 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003452 val = path->ctls[NID_PATH_MUTE_CTL];
3453 if (!val)
3454 return 0;
3455 val = amp_val_replace_channels(val, chs);
3456 if (get_amp_direction_(val) == HDA_INPUT) {
3457 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003458 int nums = snd_hda_get_num_conns(codec, nid);
3459 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003460 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003461 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003462 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003463 }
3464 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003465}
3466
Takashi Iwaie29d3772011-11-14 17:13:23 +01003467static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003468 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003469{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003470 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3471 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003472}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003473
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003474static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003475 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003476{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003477 int i;
3478
3479 for (i = path->depth - 1; i >= 0; i--) {
3480 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3481 return path->path[i];
3482 if (i != path->depth - 1 && i != 0 &&
3483 nid_has_mute(codec, path->path[i], HDA_INPUT))
3484 return path->path[i];
3485 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003486 return 0;
3487}
3488
3489static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003490 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003491{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003492 int i;
3493
3494 for (i = path->depth - 1; i >= 0; i--) {
3495 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3496 return path->path[i];
3497 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003498 return 0;
3499}
3500
Takashi Iwai7085ec12009-10-02 09:03:58 +02003501/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003502static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003503 const struct auto_pin_cfg *cfg)
3504{
3505 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003506 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003507
Takashi Iwaice764ab2011-04-27 16:35:23 +02003508 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003509 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003510 noutputs += spec->multi_ios;
3511
3512 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003513 const char *name;
3514 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003515 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003516 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003517
3518 dac = spec->multiout.dac_nids[i];
3519 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003520 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003521 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003522 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003523 index = 0;
3524 name = channel_name[i];
3525 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003526 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003527 name = alc_get_line_out_pfx(spec, i, true, &index);
3528 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003529
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003530 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003531 if (!path)
3532 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003533 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003534 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003535 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003536 if (err < 0)
3537 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003538 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003539 if (err < 0)
3540 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003541 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003542 if (err < 0)
3543 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003544 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003545 if (err < 0)
3546 return err;
3547 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003548 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003549 if (err < 0)
3550 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003551 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003552 if (err < 0)
3553 return err;
3554 }
3555 }
3556 return 0;
3557}
3558
Takashi Iwai343a04b2011-07-06 14:28:39 +02003559static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003560 hda_nid_t dac, const char *pfx,
3561 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003562{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003563 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003564 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003565
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003566 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003567 if (!path)
3568 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003569 /* bind volume control will be created in the case of dac = 0 */
3570 if (dac) {
3571 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3572 if (err < 0)
3573 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003574 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003575 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003576 if (err < 0)
3577 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003578 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003579}
3580
Takashi Iwai23c09b02011-08-19 09:05:35 +02003581static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3582 unsigned int nums,
3583 struct hda_ctl_ops *ops)
3584{
3585 struct alc_spec *spec = codec->spec;
3586 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003587 ctlp = snd_array_new(&spec->bind_ctls);
3588 if (!ctlp)
3589 return NULL;
3590 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3591 *ctlp = ctl;
3592 if (ctl)
3593 ctl->ops = ops;
3594 return ctl;
3595}
3596
3597/* add playback controls for speaker and HP outputs */
3598static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3599 const hda_nid_t *pins,
3600 const hda_nid_t *dacs,
3601 const char *pfx)
3602{
3603 struct alc_spec *spec = codec->spec;
3604 struct hda_bind_ctls *ctl;
3605 char name[32];
3606 int i, n, err;
3607
3608 if (!num_pins || !pins[0])
3609 return 0;
3610
Takashi Iwai527e4d72011-10-27 16:33:27 +02003611 if (num_pins == 1) {
3612 hda_nid_t dac = *dacs;
3613 if (!dac)
3614 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003615 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003616 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003617
Takashi Iwai23c09b02011-08-19 09:05:35 +02003618 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003619 hda_nid_t dac;
3620 if (dacs[num_pins - 1])
3621 dac = dacs[i]; /* with individual volumes */
3622 else
3623 dac = 0;
3624 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3625 err = alc_auto_create_extra_out(codec, pins[i], dac,
3626 "Bass Speaker", 0);
3627 } else if (num_pins >= 3) {
3628 snprintf(name, sizeof(name), "%s %s",
3629 pfx, channel_name[i]);
3630 err = alc_auto_create_extra_out(codec, pins[i], dac,
3631 name, 0);
3632 } else {
3633 err = alc_auto_create_extra_out(codec, pins[i], dac,
3634 pfx, i);
3635 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003636 if (err < 0)
3637 return err;
3638 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003639 if (dacs[num_pins - 1])
3640 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003641
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003642 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003643 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3644 if (!ctl)
3645 return -ENOMEM;
3646 n = 0;
3647 for (i = 0; i < num_pins; i++) {
3648 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003649 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003650 if (!pins[i] || !dacs[i])
3651 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003652 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003653 if (!path)
3654 continue;
3655 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003656 if (vol)
3657 ctl->values[n++] =
3658 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3659 }
3660 if (n) {
3661 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3662 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3663 if (err < 0)
3664 return err;
3665 }
3666 return 0;
3667}
3668
Takashi Iwai343a04b2011-07-06 14:28:39 +02003669static int alc_auto_create_hp_out(struct hda_codec *codec)
3670{
3671 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003672 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3673 spec->autocfg.hp_pins,
3674 spec->multiout.hp_out_nid,
3675 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003676}
3677
3678static int alc_auto_create_speaker_out(struct hda_codec *codec)
3679{
3680 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003681 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3682 spec->autocfg.speaker_pins,
3683 spec->multiout.extra_out_nid,
3684 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003685}
3686
Takashi Iwai130e5f02012-12-14 16:09:29 +01003687/* check whether a control with the given (nid, dir, idx) was assigned */
3688static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3689 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003690{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003691 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003692 int i, type;
3693
3694 for (i = 0; i < spec->paths.used; i++) {
3695 struct nid_path *p = snd_array_elem(&spec->paths, i);
3696 if (p->depth <= 0)
3697 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003698 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003699 unsigned int val = p->ctls[type];
3700 if (get_amp_nid_(val) == nid &&
3701 get_amp_direction_(val) == dir &&
3702 get_amp_index_(val) == idx)
3703 return true;
3704 }
3705 }
3706 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003707}
3708
3709/* can have the amp-in capability? */
3710static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3711{
3712 hda_nid_t nid = path->path[idx];
3713 unsigned int caps = get_wcaps(codec, nid);
3714 unsigned int type = get_wcaps_type(caps);
3715
3716 if (!(caps & AC_WCAP_IN_AMP))
3717 return false;
3718 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3719 return false;
3720 return true;
3721}
3722
3723/* can have the amp-out capability? */
3724static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3725{
3726 hda_nid_t nid = path->path[idx];
3727 unsigned int caps = get_wcaps(codec, nid);
3728 unsigned int type = get_wcaps_type(caps);
3729
3730 if (!(caps & AC_WCAP_OUT_AMP))
3731 return false;
3732 if (type == AC_WID_PIN && !idx) /* only for output pins */
3733 return false;
3734 return true;
3735}
3736
Takashi Iwaic9967f12012-12-14 16:39:22 +01003737/* check whether the given (nid,dir,idx) is active */
3738static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3739 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003740{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003741 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003742 int i, n;
3743
Takashi Iwaic9967f12012-12-14 16:39:22 +01003744 for (n = 0; n < spec->paths.used; n++) {
3745 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003746 if (!path->active)
3747 continue;
3748 for (i = 0; i < path->depth; i++) {
3749 if (path->path[i] == nid) {
3750 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3751 return true;
3752 break;
3753 }
3754 }
3755 }
3756 return false;
3757}
3758
Takashi Iwai130e5f02012-12-14 16:09:29 +01003759/* get the default amp value for the target state */
3760static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3761 int dir, bool enable)
3762{
3763 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003764 unsigned int val = 0;
3765
3766 caps = query_amp_caps(codec, nid, dir);
3767 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003768 /* set to 0dB */
3769 if (enable)
3770 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003771 }
3772 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003773 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003774 val |= HDA_AMP_MUTE;
3775 }
3776 return val;
3777}
3778
Takashi Iwai130e5f02012-12-14 16:09:29 +01003779/* initialize the amp value (only at the first time) */
3780static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3781{
3782 int val = get_amp_val_to_activate(codec, nid, dir, false);
3783 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3784}
3785
3786static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3787 int idx, bool enable)
3788{
3789 int val;
3790 if (is_ctl_associated(codec, nid, dir, idx) ||
3791 is_active_nid(codec, nid, dir, idx))
3792 return;
3793 val = get_amp_val_to_activate(codec, nid, dir, enable);
3794 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3795}
3796
3797static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3798 int i, bool enable)
3799{
3800 hda_nid_t nid = path->path[i];
3801 init_amp(codec, nid, HDA_OUTPUT, 0);
3802 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3803}
3804
3805static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003806 int i, bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003807{
3808 struct alc_spec *spec = codec->spec;
3809 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003810 int n, nums, idx;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003811 int type;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003812 hda_nid_t nid = path->path[i];
3813
3814 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai666a70d2012-12-17 20:29:29 +01003815 type = get_wcaps_type(get_wcaps(codec, nid));
3816 if (type == AC_WID_PIN ||
3817 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003818 nums = 1;
3819 idx = 0;
3820 } else
3821 idx = path->idx[i];
3822
Takashi Iwai130e5f02012-12-14 16:09:29 +01003823 for (n = 0; n < nums; n++)
3824 init_amp(codec, nid, HDA_INPUT, n);
3825
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003826 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003827 return;
3828
3829 /* here is a little bit tricky in comparison with activate_amp_out();
3830 * when aa-mixer is available, we need to enable the path as well
3831 */
3832 for (n = 0; n < nums; n++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01003833 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003834 continue;
3835 activate_amp(codec, nid, HDA_INPUT, n, enable);
3836 }
3837}
3838
3839static void activate_path(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003840 bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003841{
3842 int i;
3843
Takashi Iwai130e5f02012-12-14 16:09:29 +01003844 if (!enable)
3845 path->active = false;
3846
3847 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003848 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003849 snd_hda_codec_write_cache(codec, path->path[i], 0,
3850 AC_VERB_SET_CONNECT_SEL,
3851 path->idx[i]);
3852 if (has_amp_in(codec, path, i))
Takashi Iwai666a70d2012-12-17 20:29:29 +01003853 activate_amp_in(codec, path, i, enable, add_aamix);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003854 if (has_amp_out(codec, path, i))
3855 activate_amp_out(codec, path, i, enable);
3856 }
3857
3858 if (enable)
3859 path->active = true;
3860}
3861
Takashi Iwai78e635c2012-12-10 17:07:16 +01003862/* configure the path from the given dac to the pin as the proper output */
3863static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3864 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003865 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003866{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003867 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003868
Takashi Iwai130e5f02012-12-14 16:09:29 +01003869 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003870 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003871 if (!path)
3872 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003873 if (path->active)
3874 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003875 activate_path(codec, path, true, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003876}
3877
Takashi Iwai343a04b2011-07-06 14:28:39 +02003878static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003879{
3880 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003881 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003882 int i;
3883
3884 for (i = 0; i <= HDA_SIDE; i++) {
3885 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3886 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003887 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003888 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003889
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003890 }
3891}
3892
Takashi Iwai343a04b2011-07-06 14:28:39 +02003893static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003894{
3895 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003896 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003897 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003898
David Henningsson636030e2011-10-12 19:26:03 +02003899 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003900 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3901 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003902 pin = spec->autocfg.hp_pins[i];
3903 if (!pin)
3904 break;
3905 dac = spec->multiout.hp_out_nid[i];
3906 if (!dac) {
3907 if (i > 0 && spec->multiout.hp_out_nid[0])
3908 dac = spec->multiout.hp_out_nid[0];
3909 else
3910 dac = spec->multiout.dac_nids[0];
3911 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003912 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003913 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003914 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003915 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3916 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003917 pin = spec->autocfg.speaker_pins[i];
3918 if (!pin)
3919 break;
3920 dac = spec->multiout.extra_out_nid[i];
3921 if (!dac) {
3922 if (i > 0 && spec->multiout.extra_out_nid[0])
3923 dac = spec->multiout.extra_out_nid[0];
3924 else
3925 dac = spec->multiout.dac_nids[0];
3926 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003927 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003928 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003929}
3930
Takashi Iwai276dd702012-02-17 16:17:03 +01003931/* check whether the given pin can be a multi-io pin */
3932static bool can_be_multiio_pin(struct hda_codec *codec,
3933 unsigned int location, hda_nid_t nid)
3934{
3935 unsigned int defcfg, caps;
3936
3937 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3938 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3939 return false;
3940 if (location && get_defcfg_location(defcfg) != location)
3941 return false;
3942 caps = snd_hda_query_pin_caps(codec, nid);
3943 if (!(caps & AC_PINCAP_OUT))
3944 return false;
3945 return true;
3946}
3947
Takashi Iwaice764ab2011-04-27 16:35:23 +02003948/*
3949 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003950 *
3951 * When hardwired is set, try to fill ony hardwired pins, and returns
3952 * zero if any pins are filled, non-zero if nothing found.
3953 * When hardwired is off, try to fill possible input pins, and returns
3954 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003955 */
3956static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003957 hda_nid_t reference_pin,
3958 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003959{
3960 struct alc_spec *spec = codec->spec;
3961 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003962 int type, i, j, dacs, num_pins, old_pins;
3963 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3964 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003965 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003966
Takashi Iwai276dd702012-02-17 16:17:03 +01003967 old_pins = spec->multi_ios;
3968 if (old_pins >= 2)
3969 goto end_fill;
3970
3971 num_pins = 0;
3972 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3973 for (i = 0; i < cfg->num_inputs; i++) {
3974 if (cfg->inputs[i].type != type)
3975 continue;
3976 if (can_be_multiio_pin(codec, location,
3977 cfg->inputs[i].pin))
3978 num_pins++;
3979 }
3980 }
3981 if (num_pins < 2)
3982 goto end_fill;
3983
Takashi Iwai07b18f62011-11-10 15:42:54 +01003984 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003985 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3986 for (i = 0; i < cfg->num_inputs; i++) {
3987 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003988 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003989
Takashi Iwaice764ab2011-04-27 16:35:23 +02003990 if (cfg->inputs[i].type != type)
3991 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003992 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003993 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003994 for (j = 0; j < spec->multi_ios; j++) {
3995 if (nid == spec->multi_io[j].pin)
3996 break;
3997 }
3998 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003999 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004000
4001 if (offset && offset + spec->multi_ios < dacs) {
4002 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004003 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004004 dac = 0;
4005 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004006 if (hardwired)
4007 dac = get_dac_if_single(codec, nid);
4008 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004009 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004010 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004011 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004012 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004013 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01004014 if (!add_new_nid_path(codec, dac, nid, 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004015 badness++;
4016 continue;
4017 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004018 spec->multi_io[spec->multi_ios].pin = nid;
4019 spec->multi_io[spec->multi_ios].dac = dac;
4020 spec->multi_ios++;
4021 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004022 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004023 }
4024 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004025 end_fill:
4026 if (badness)
4027 badness = BAD_MULTI_IO;
4028 if (old_pins == spec->multi_ios) {
4029 if (hardwired)
4030 return 1; /* nothing found */
4031 else
4032 return badness; /* no badness if nothing found */
4033 }
4034 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004035 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004036 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004037 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004038 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004039 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004040
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004041 /* assign volume and mute controls */
4042 for (i = old_pins; i < spec->multi_ios; i++)
4043 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4044 spec->multi_io[i].dac);
4045
4046 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004047}
4048
4049static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4050 struct snd_ctl_elem_info *uinfo)
4051{
4052 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4053 struct alc_spec *spec = codec->spec;
4054
4055 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4056 uinfo->count = 1;
4057 uinfo->value.enumerated.items = spec->multi_ios + 1;
4058 if (uinfo->value.enumerated.item > spec->multi_ios)
4059 uinfo->value.enumerated.item = spec->multi_ios;
4060 sprintf(uinfo->value.enumerated.name, "%dch",
4061 (uinfo->value.enumerated.item + 1) * 2);
4062 return 0;
4063}
4064
4065static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4066 struct snd_ctl_elem_value *ucontrol)
4067{
4068 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4069 struct alc_spec *spec = codec->spec;
4070 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4071 return 0;
4072}
4073
4074static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4075{
4076 struct alc_spec *spec = codec->spec;
4077 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004078 struct nid_path *path;
4079
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004080 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004081 if (!path)
4082 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004083
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004084 if (path->active == output)
4085 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004086
Takashi Iwaice764ab2011-04-27 16:35:23 +02004087 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004088 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004089 activate_path(codec, path, true, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004090 } else {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004091 activate_path(codec, path, false, true);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004092 snd_hda_set_pin_ctl_cache(codec, nid,
4093 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004094 }
4095 return 0;
4096}
4097
4098static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4099 struct snd_ctl_elem_value *ucontrol)
4100{
4101 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4102 struct alc_spec *spec = codec->spec;
4103 int i, ch;
4104
4105 ch = ucontrol->value.enumerated.item[0];
4106 if (ch < 0 || ch > spec->multi_ios)
4107 return -EINVAL;
4108 if (ch == (spec->ext_channel_count - 1) / 2)
4109 return 0;
4110 spec->ext_channel_count = (ch + 1) * 2;
4111 for (i = 0; i < spec->multi_ios; i++)
4112 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004113 spec->multiout.max_channels = max(spec->ext_channel_count,
4114 spec->const_channel_count);
4115 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004116 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004117 return 1;
4118}
4119
Takashi Iwaia9111322011-05-02 11:30:18 +02004120static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004121 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4122 .name = "Channel Mode",
4123 .info = alc_auto_ch_mode_info,
4124 .get = alc_auto_ch_mode_get,
4125 .put = alc_auto_ch_mode_put,
4126};
4127
Takashi Iwai23c09b02011-08-19 09:05:35 +02004128static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004129{
4130 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004131
Takashi Iwaic2674682011-08-24 17:57:44 +02004132 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004133 if (!alc_kcontrol_new(spec, "Channel Mode",
4134 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004135 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004136 }
4137 return 0;
4138}
4139
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004140static void alc_auto_init_multi_io(struct hda_codec *codec)
4141{
4142 struct alc_spec *spec = codec->spec;
4143 int i;
4144
4145 for (i = 0; i < spec->multi_ios; i++) {
4146 hda_nid_t pin = spec->multi_io[i].pin;
4147 struct nid_path *path;
4148 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4149 if (!path)
4150 continue;
4151 if (!spec->multi_io[i].ctl_in)
4152 spec->multi_io[i].ctl_in =
4153 snd_hda_codec_update_cache(codec, pin, 0,
4154 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004155 activate_path(codec, path, path->active, true);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004156 }
4157}
4158
Takashi Iwai1d045db2011-07-07 18:23:21 +02004159/*
4160 * initialize ADC paths
4161 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004162static void alc_auto_init_input_src(struct hda_codec *codec)
4163{
4164 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01004165 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004166 struct nid_path *path;
4167 int i, c, nums;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004168
Takashi Iwai1d045db2011-07-07 18:23:21 +02004169 if (spec->dyn_adc_switch)
4170 nums = 1;
4171 else
4172 nums = spec->num_adc_nids;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004173
4174 for (c = 0; c < nums; c++) {
4175 for (i = 0; i < imux->num_items; i++) {
4176 path = get_nid_path(codec, spec->imux_pins[i],
4177 get_adc_nid(codec, c, i));
4178 if (path) {
4179 bool active = path->active;
4180 if (i == spec->cur_mux[c])
4181 active = true;
4182 activate_path(codec, path, active, false);
4183 }
4184 }
4185 }
4186
4187 alc_inv_dmic_sync(codec, true);
4188 if (spec->shared_mic_hp)
4189 update_shared_mic_hp(codec, spec->cur_mux[0]);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004190}
4191
4192/* add mic boosts if needed */
4193static int alc_auto_add_mic_boost(struct hda_codec *codec)
4194{
4195 struct alc_spec *spec = codec->spec;
4196 struct auto_pin_cfg *cfg = &spec->autocfg;
4197 int i, err;
4198 int type_idx = 0;
4199 hda_nid_t nid;
4200 const char *prev_label = NULL;
4201
4202 for (i = 0; i < cfg->num_inputs; i++) {
4203 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4204 break;
4205 nid = cfg->inputs[i].pin;
4206 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4207 const char *label;
4208 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004209 struct nid_path *path;
4210 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004211
4212 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004213 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4214 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004215 if (prev_label && !strcmp(label, prev_label))
4216 type_idx++;
4217 else
4218 type_idx = 0;
4219 prev_label = label;
4220
4221 snprintf(boost_label, sizeof(boost_label),
4222 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004223 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004224 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004225 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004226 if (err < 0)
4227 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004228
4229 path = get_nid_path(codec, nid, 0);
4230 if (path)
4231 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004232 }
4233 }
4234 return 0;
4235}
4236
Takashi Iwai1d045db2011-07-07 18:23:21 +02004237/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004238 * standard auto-parser initializations
4239 */
4240static void alc_auto_init_std(struct hda_codec *codec)
4241{
Takashi Iwaie4770622011-07-08 11:11:35 +02004242 alc_auto_init_multi_out(codec);
4243 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004244 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004245 alc_auto_init_analog_input(codec);
4246 alc_auto_init_input_src(codec);
4247 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004248 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004249}
4250
4251/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004252 * Digital-beep handlers
4253 */
4254#ifdef CONFIG_SND_HDA_INPUT_BEEP
4255#define set_beep_amp(spec, nid, idx, dir) \
4256 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4257
4258static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004259 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004260 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4261 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4262 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4263 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004264 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004265 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4266 {}
4267};
4268
4269static inline int has_cdefine_beep(struct hda_codec *codec)
4270{
4271 struct alc_spec *spec = codec->spec;
4272 const struct snd_pci_quirk *q;
4273 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4274 if (q)
4275 return q->value;
4276 return spec->cdefine.enable_pcbeep;
4277}
4278#else
4279#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4280#define has_cdefine_beep(codec) 0
4281#endif
4282
4283/* parse the BIOS configuration and set up the alc_spec */
4284/* return 1 if successful, 0 if the proper config is not found,
4285 * or a negative error code
4286 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004287static int alc_parse_auto_config(struct hda_codec *codec,
4288 const hda_nid_t *ignore_nids,
4289 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004290{
4291 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004292 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004293 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004294
Takashi Iwai53c334a2011-08-23 18:27:14 +02004295 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4296 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004297 if (err < 0)
4298 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004299 if (!cfg->line_outs) {
4300 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004301 spec->multiout.max_channels = 2;
4302 spec->no_analog = 1;
4303 goto dig_only;
4304 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004305 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004306 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004307
Takashi Iwaie427c232012-07-29 10:04:08 +02004308 if (!spec->no_primary_hp &&
4309 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004310 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004311 /* use HP as primary out */
4312 cfg->speaker_outs = cfg->line_outs;
4313 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4314 sizeof(cfg->speaker_pins));
4315 cfg->line_outs = cfg->hp_outs;
4316 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4317 cfg->hp_outs = 0;
4318 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4319 cfg->line_out_type = AUTO_PIN_HP_OUT;
4320 }
4321
Takashi Iwai1d045db2011-07-07 18:23:21 +02004322 err = alc_auto_fill_dac_nids(codec);
4323 if (err < 0)
4324 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004325 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004326 if (err < 0)
4327 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004328 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004329 if (err < 0)
4330 return err;
4331 err = alc_auto_create_hp_out(codec);
4332 if (err < 0)
4333 return err;
4334 err = alc_auto_create_speaker_out(codec);
4335 if (err < 0)
4336 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004337 err = alc_auto_create_shared_input(codec);
4338 if (err < 0)
4339 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004340 err = alc_auto_create_input_ctls(codec);
4341 if (err < 0)
4342 return err;
4343
Takashi Iwaib6adb572012-12-03 10:30:58 +01004344 /* check the multiple speaker pins */
4345 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4346 spec->const_channel_count = cfg->line_outs * 2;
4347 else
4348 spec->const_channel_count = cfg->speaker_outs * 2;
4349
4350 if (spec->multi_ios > 0)
4351 spec->multiout.max_channels = max(spec->ext_channel_count,
4352 spec->const_channel_count);
4353 else
4354 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004355
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004356 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004357 alc_auto_parse_digital(codec);
4358
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004359 if (ssid_nids)
4360 alc_ssid_check(codec, ssid_nids);
4361
4362 if (!spec->no_analog) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004363 err = alc_init_automute(codec);
Takashi Iwai475c3d22012-11-30 08:31:30 +01004364 if (err < 0)
4365 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004366
4367 err = check_dyn_adc_switch(codec);
4368 if (err < 0)
4369 return err;
4370
4371 if (!spec->shared_mic_hp) {
4372 err = alc_init_auto_mic(codec);
4373 if (err < 0)
4374 return err;
4375 }
4376
4377 err = create_capture_mixers(codec);
4378 if (err < 0)
4379 return err;
4380
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004381 err = alc_auto_add_mic_boost(codec);
4382 if (err < 0)
4383 return err;
4384 }
4385
Takashi Iwai1d045db2011-07-07 18:23:21 +02004386 if (spec->kctls.list)
4387 add_mixer(spec, spec->kctls.list);
4388
Takashi Iwai1d045db2011-07-07 18:23:21 +02004389 return 1;
4390}
4391
Takashi Iwai3de95172012-05-07 18:03:15 +02004392/* common preparation job for alc_spec */
4393static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4394{
4395 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4396 int err;
4397
4398 if (!spec)
4399 return -ENOMEM;
4400 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004401 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004402 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004403 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004404 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4405 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004406 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004407
4408 err = alc_codec_rename_from_preset(codec);
4409 if (err < 0) {
4410 kfree(spec);
4411 return err;
4412 }
4413 return 0;
4414}
4415
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004416static int alc880_parse_auto_config(struct hda_codec *codec)
4417{
4418 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004419 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004420 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4421}
4422
Takashi Iwai1d045db2011-07-07 18:23:21 +02004423/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004424 * ALC880 fix-ups
4425 */
4426enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004427 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004428 ALC880_FIXUP_GPIO2,
4429 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004430 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004431 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004432 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004433 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004434 ALC880_FIXUP_VOL_KNOB,
4435 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004436 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004437 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004438 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004439 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004440 ALC880_FIXUP_3ST_BASE,
4441 ALC880_FIXUP_3ST,
4442 ALC880_FIXUP_3ST_DIG,
4443 ALC880_FIXUP_5ST_BASE,
4444 ALC880_FIXUP_5ST,
4445 ALC880_FIXUP_5ST_DIG,
4446 ALC880_FIXUP_6ST_BASE,
4447 ALC880_FIXUP_6ST,
4448 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004449};
4450
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004451/* enable the volume-knob widget support on NID 0x21 */
4452static void alc880_fixup_vol_knob(struct hda_codec *codec,
4453 const struct alc_fixup *fix, int action)
4454{
4455 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004456 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004457}
4458
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004459static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004460 [ALC880_FIXUP_GPIO1] = {
4461 .type = ALC_FIXUP_VERBS,
4462 .v.verbs = alc_gpio1_init_verbs,
4463 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004464 [ALC880_FIXUP_GPIO2] = {
4465 .type = ALC_FIXUP_VERBS,
4466 .v.verbs = alc_gpio2_init_verbs,
4467 },
4468 [ALC880_FIXUP_MEDION_RIM] = {
4469 .type = ALC_FIXUP_VERBS,
4470 .v.verbs = (const struct hda_verb[]) {
4471 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4472 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4473 { }
4474 },
4475 .chained = true,
4476 .chain_id = ALC880_FIXUP_GPIO2,
4477 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004478 [ALC880_FIXUP_LG] = {
4479 .type = ALC_FIXUP_PINS,
4480 .v.pins = (const struct alc_pincfg[]) {
4481 /* disable bogus unused pins */
4482 { 0x16, 0x411111f0 },
4483 { 0x18, 0x411111f0 },
4484 { 0x1a, 0x411111f0 },
4485 { }
4486 }
4487 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004488 [ALC880_FIXUP_W810] = {
4489 .type = ALC_FIXUP_PINS,
4490 .v.pins = (const struct alc_pincfg[]) {
4491 /* disable bogus unused pins */
4492 { 0x17, 0x411111f0 },
4493 { }
4494 },
4495 .chained = true,
4496 .chain_id = ALC880_FIXUP_GPIO2,
4497 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004498 [ALC880_FIXUP_EAPD_COEF] = {
4499 .type = ALC_FIXUP_VERBS,
4500 .v.verbs = (const struct hda_verb[]) {
4501 /* change to EAPD mode */
4502 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4503 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4504 {}
4505 },
4506 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004507 [ALC880_FIXUP_TCL_S700] = {
4508 .type = ALC_FIXUP_VERBS,
4509 .v.verbs = (const struct hda_verb[]) {
4510 /* change to EAPD mode */
4511 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4512 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4513 {}
4514 },
4515 .chained = true,
4516 .chain_id = ALC880_FIXUP_GPIO2,
4517 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004518 [ALC880_FIXUP_VOL_KNOB] = {
4519 .type = ALC_FIXUP_FUNC,
4520 .v.func = alc880_fixup_vol_knob,
4521 },
4522 [ALC880_FIXUP_FUJITSU] = {
4523 /* override all pins as BIOS on old Amilo is broken */
4524 .type = ALC_FIXUP_PINS,
4525 .v.pins = (const struct alc_pincfg[]) {
4526 { 0x14, 0x0121411f }, /* HP */
4527 { 0x15, 0x99030120 }, /* speaker */
4528 { 0x16, 0x99030130 }, /* bass speaker */
4529 { 0x17, 0x411111f0 }, /* N/A */
4530 { 0x18, 0x411111f0 }, /* N/A */
4531 { 0x19, 0x01a19950 }, /* mic-in */
4532 { 0x1a, 0x411111f0 }, /* N/A */
4533 { 0x1b, 0x411111f0 }, /* N/A */
4534 { 0x1c, 0x411111f0 }, /* N/A */
4535 { 0x1d, 0x411111f0 }, /* N/A */
4536 { 0x1e, 0x01454140 }, /* SPDIF out */
4537 { }
4538 },
4539 .chained = true,
4540 .chain_id = ALC880_FIXUP_VOL_KNOB,
4541 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004542 [ALC880_FIXUP_F1734] = {
4543 /* almost compatible with FUJITSU, but no bass and SPDIF */
4544 .type = ALC_FIXUP_PINS,
4545 .v.pins = (const struct alc_pincfg[]) {
4546 { 0x14, 0x0121411f }, /* HP */
4547 { 0x15, 0x99030120 }, /* speaker */
4548 { 0x16, 0x411111f0 }, /* N/A */
4549 { 0x17, 0x411111f0 }, /* N/A */
4550 { 0x18, 0x411111f0 }, /* N/A */
4551 { 0x19, 0x01a19950 }, /* mic-in */
4552 { 0x1a, 0x411111f0 }, /* N/A */
4553 { 0x1b, 0x411111f0 }, /* N/A */
4554 { 0x1c, 0x411111f0 }, /* N/A */
4555 { 0x1d, 0x411111f0 }, /* N/A */
4556 { 0x1e, 0x411111f0 }, /* N/A */
4557 { }
4558 },
4559 .chained = true,
4560 .chain_id = ALC880_FIXUP_VOL_KNOB,
4561 },
Takashi Iwai817de922012-02-20 17:20:48 +01004562 [ALC880_FIXUP_UNIWILL] = {
4563 /* need to fix HP and speaker pins to be parsed correctly */
4564 .type = ALC_FIXUP_PINS,
4565 .v.pins = (const struct alc_pincfg[]) {
4566 { 0x14, 0x0121411f }, /* HP */
4567 { 0x15, 0x99030120 }, /* speaker */
4568 { 0x16, 0x99030130 }, /* bass speaker */
4569 { }
4570 },
4571 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004572 [ALC880_FIXUP_UNIWILL_DIG] = {
4573 .type = ALC_FIXUP_PINS,
4574 .v.pins = (const struct alc_pincfg[]) {
4575 /* disable bogus unused pins */
4576 { 0x17, 0x411111f0 },
4577 { 0x19, 0x411111f0 },
4578 { 0x1b, 0x411111f0 },
4579 { 0x1f, 0x411111f0 },
4580 { }
4581 }
4582 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004583 [ALC880_FIXUP_Z71V] = {
4584 .type = ALC_FIXUP_PINS,
4585 .v.pins = (const struct alc_pincfg[]) {
4586 /* set up the whole pins as BIOS is utterly broken */
4587 { 0x14, 0x99030120 }, /* speaker */
4588 { 0x15, 0x0121411f }, /* HP */
4589 { 0x16, 0x411111f0 }, /* N/A */
4590 { 0x17, 0x411111f0 }, /* N/A */
4591 { 0x18, 0x01a19950 }, /* mic-in */
4592 { 0x19, 0x411111f0 }, /* N/A */
4593 { 0x1a, 0x01813031 }, /* line-in */
4594 { 0x1b, 0x411111f0 }, /* N/A */
4595 { 0x1c, 0x411111f0 }, /* N/A */
4596 { 0x1d, 0x411111f0 }, /* N/A */
4597 { 0x1e, 0x0144111e }, /* SPDIF */
4598 { }
4599 }
4600 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004601 [ALC880_FIXUP_3ST_BASE] = {
4602 .type = ALC_FIXUP_PINS,
4603 .v.pins = (const struct alc_pincfg[]) {
4604 { 0x14, 0x01014010 }, /* line-out */
4605 { 0x15, 0x411111f0 }, /* N/A */
4606 { 0x16, 0x411111f0 }, /* N/A */
4607 { 0x17, 0x411111f0 }, /* N/A */
4608 { 0x18, 0x01a19c30 }, /* mic-in */
4609 { 0x19, 0x0121411f }, /* HP */
4610 { 0x1a, 0x01813031 }, /* line-in */
4611 { 0x1b, 0x02a19c40 }, /* front-mic */
4612 { 0x1c, 0x411111f0 }, /* N/A */
4613 { 0x1d, 0x411111f0 }, /* N/A */
4614 /* 0x1e is filled in below */
4615 { 0x1f, 0x411111f0 }, /* N/A */
4616 { }
4617 }
4618 },
4619 [ALC880_FIXUP_3ST] = {
4620 .type = ALC_FIXUP_PINS,
4621 .v.pins = (const struct alc_pincfg[]) {
4622 { 0x1e, 0x411111f0 }, /* N/A */
4623 { }
4624 },
4625 .chained = true,
4626 .chain_id = ALC880_FIXUP_3ST_BASE,
4627 },
4628 [ALC880_FIXUP_3ST_DIG] = {
4629 .type = ALC_FIXUP_PINS,
4630 .v.pins = (const struct alc_pincfg[]) {
4631 { 0x1e, 0x0144111e }, /* SPDIF */
4632 { }
4633 },
4634 .chained = true,
4635 .chain_id = ALC880_FIXUP_3ST_BASE,
4636 },
4637 [ALC880_FIXUP_5ST_BASE] = {
4638 .type = ALC_FIXUP_PINS,
4639 .v.pins = (const struct alc_pincfg[]) {
4640 { 0x14, 0x01014010 }, /* front */
4641 { 0x15, 0x411111f0 }, /* N/A */
4642 { 0x16, 0x01011411 }, /* CLFE */
4643 { 0x17, 0x01016412 }, /* surr */
4644 { 0x18, 0x01a19c30 }, /* mic-in */
4645 { 0x19, 0x0121411f }, /* HP */
4646 { 0x1a, 0x01813031 }, /* line-in */
4647 { 0x1b, 0x02a19c40 }, /* front-mic */
4648 { 0x1c, 0x411111f0 }, /* N/A */
4649 { 0x1d, 0x411111f0 }, /* N/A */
4650 /* 0x1e is filled in below */
4651 { 0x1f, 0x411111f0 }, /* N/A */
4652 { }
4653 }
4654 },
4655 [ALC880_FIXUP_5ST] = {
4656 .type = ALC_FIXUP_PINS,
4657 .v.pins = (const struct alc_pincfg[]) {
4658 { 0x1e, 0x411111f0 }, /* N/A */
4659 { }
4660 },
4661 .chained = true,
4662 .chain_id = ALC880_FIXUP_5ST_BASE,
4663 },
4664 [ALC880_FIXUP_5ST_DIG] = {
4665 .type = ALC_FIXUP_PINS,
4666 .v.pins = (const struct alc_pincfg[]) {
4667 { 0x1e, 0x0144111e }, /* SPDIF */
4668 { }
4669 },
4670 .chained = true,
4671 .chain_id = ALC880_FIXUP_5ST_BASE,
4672 },
4673 [ALC880_FIXUP_6ST_BASE] = {
4674 .type = ALC_FIXUP_PINS,
4675 .v.pins = (const struct alc_pincfg[]) {
4676 { 0x14, 0x01014010 }, /* front */
4677 { 0x15, 0x01016412 }, /* surr */
4678 { 0x16, 0x01011411 }, /* CLFE */
4679 { 0x17, 0x01012414 }, /* side */
4680 { 0x18, 0x01a19c30 }, /* mic-in */
4681 { 0x19, 0x02a19c40 }, /* front-mic */
4682 { 0x1a, 0x01813031 }, /* line-in */
4683 { 0x1b, 0x0121411f }, /* HP */
4684 { 0x1c, 0x411111f0 }, /* N/A */
4685 { 0x1d, 0x411111f0 }, /* N/A */
4686 /* 0x1e is filled in below */
4687 { 0x1f, 0x411111f0 }, /* N/A */
4688 { }
4689 }
4690 },
4691 [ALC880_FIXUP_6ST] = {
4692 .type = ALC_FIXUP_PINS,
4693 .v.pins = (const struct alc_pincfg[]) {
4694 { 0x1e, 0x411111f0 }, /* N/A */
4695 { }
4696 },
4697 .chained = true,
4698 .chain_id = ALC880_FIXUP_6ST_BASE,
4699 },
4700 [ALC880_FIXUP_6ST_DIG] = {
4701 .type = ALC_FIXUP_PINS,
4702 .v.pins = (const struct alc_pincfg[]) {
4703 { 0x1e, 0x0144111e }, /* SPDIF */
4704 { }
4705 },
4706 .chained = true,
4707 .chain_id = ALC880_FIXUP_6ST_BASE,
4708 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004709};
4710
4711static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004712 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004713 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004714 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4715 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004716 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004717 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004718 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004719 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004720 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004721 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004722 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004723 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004724 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004725 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004726 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004727 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4728 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4729 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004730 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004731
4732 /* Below is the copied entries from alc880_quirks.c.
4733 * It's not quite sure whether BIOS sets the correct pin-config table
4734 * on these machines, thus they are kept to be compatible with
4735 * the old static quirks. Once when it's confirmed to work without
4736 * these overrides, it'd be better to remove.
4737 */
4738 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4739 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4740 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4741 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4742 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4743 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4744 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4745 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4746 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4747 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4748 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4749 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4750 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4751 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4752 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4753 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4754 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4755 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4756 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4757 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4758 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4759 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4760 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4761 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4762 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4763 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4764 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4765 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4766 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4767 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4768 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4769 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4770 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4771 /* default Intel */
4772 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4773 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4774 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4775 {}
4776};
4777
4778static const struct alc_model_fixup alc880_fixup_models[] = {
4779 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4780 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4781 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4782 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4783 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4784 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004785 {}
4786};
4787
4788
4789/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004790 * OK, here we have finally the patch for ALC880
4791 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004792static int patch_alc880(struct hda_codec *codec)
4793{
4794 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004795 int err;
4796
Takashi Iwai3de95172012-05-07 18:03:15 +02004797 err = alc_alloc_spec(codec, 0x0b);
4798 if (err < 0)
4799 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004800
Takashi Iwai3de95172012-05-07 18:03:15 +02004801 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004802 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004803
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004804 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4805 alc880_fixups);
4806 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004807
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004808 /* automatic parse from the BIOS config */
4809 err = alc880_parse_auto_config(codec);
4810 if (err < 0)
4811 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004812
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004813 if (!spec->no_analog) {
4814 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004815 if (err < 0)
4816 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004817 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4818 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004819
Takashi Iwai1d045db2011-07-07 18:23:21 +02004820 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004821 codec->patch_ops.unsol_event = alc880_unsol_event;
4822
Takashi Iwai1d045db2011-07-07 18:23:21 +02004823
Takashi Iwai589876e2012-02-20 15:47:55 +01004824 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4825
Takashi Iwai1d045db2011-07-07 18:23:21 +02004826 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004827
4828 error:
4829 alc_free(codec);
4830 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004831}
4832
4833
4834/*
4835 * ALC260 support
4836 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004837static int alc260_parse_auto_config(struct hda_codec *codec)
4838{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004839 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004840 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4841 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004842}
4843
Takashi Iwai1d045db2011-07-07 18:23:21 +02004844/*
4845 * Pin config fixes
4846 */
4847enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004848 ALC260_FIXUP_HP_DC5750,
4849 ALC260_FIXUP_HP_PIN_0F,
4850 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004851 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004852 ALC260_FIXUP_GPIO1_TOGGLE,
4853 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004854 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004855 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004856};
4857
Takashi Iwai20f7d922012-02-16 12:35:16 +01004858static void alc260_gpio1_automute(struct hda_codec *codec)
4859{
4860 struct alc_spec *spec = codec->spec;
4861 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4862 spec->hp_jack_present);
4863}
4864
4865static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4866 const struct alc_fixup *fix, int action)
4867{
4868 struct alc_spec *spec = codec->spec;
4869 if (action == ALC_FIXUP_ACT_PROBE) {
4870 /* although the machine has only one output pin, we need to
4871 * toggle GPIO1 according to the jack state
4872 */
4873 spec->automute_hook = alc260_gpio1_automute;
4874 spec->detect_hp = 1;
4875 spec->automute_speaker = 1;
4876 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004877 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4878 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004879 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004880 }
4881}
4882
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004883static void alc260_fixup_kn1(struct hda_codec *codec,
4884 const struct alc_fixup *fix, int action)
4885{
4886 struct alc_spec *spec = codec->spec;
4887 static const struct alc_pincfg pincfgs[] = {
4888 { 0x0f, 0x02214000 }, /* HP/speaker */
4889 { 0x12, 0x90a60160 }, /* int mic */
4890 { 0x13, 0x02a19000 }, /* ext mic */
4891 { 0x18, 0x01446000 }, /* SPDIF out */
4892 /* disable bogus I/O pins */
4893 { 0x10, 0x411111f0 },
4894 { 0x11, 0x411111f0 },
4895 { 0x14, 0x411111f0 },
4896 { 0x15, 0x411111f0 },
4897 { 0x16, 0x411111f0 },
4898 { 0x17, 0x411111f0 },
4899 { 0x19, 0x411111f0 },
4900 { }
4901 };
4902
4903 switch (action) {
4904 case ALC_FIXUP_ACT_PRE_PROBE:
4905 alc_apply_pincfgs(codec, pincfgs);
4906 break;
4907 case ALC_FIXUP_ACT_PROBE:
4908 spec->init_amp = ALC_INIT_NONE;
4909 break;
4910 }
4911}
4912
Takashi Iwai1d045db2011-07-07 18:23:21 +02004913static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004914 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004915 .type = ALC_FIXUP_PINS,
4916 .v.pins = (const struct alc_pincfg[]) {
4917 { 0x11, 0x90130110 }, /* speaker */
4918 { }
4919 }
4920 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004921 [ALC260_FIXUP_HP_PIN_0F] = {
4922 .type = ALC_FIXUP_PINS,
4923 .v.pins = (const struct alc_pincfg[]) {
4924 { 0x0f, 0x01214000 }, /* HP */
4925 { }
4926 }
4927 },
4928 [ALC260_FIXUP_COEF] = {
4929 .type = ALC_FIXUP_VERBS,
4930 .v.verbs = (const struct hda_verb[]) {
4931 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4932 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4933 { }
4934 },
4935 .chained = true,
4936 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4937 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004938 [ALC260_FIXUP_GPIO1] = {
4939 .type = ALC_FIXUP_VERBS,
4940 .v.verbs = alc_gpio1_init_verbs,
4941 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004942 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4943 .type = ALC_FIXUP_FUNC,
4944 .v.func = alc260_fixup_gpio1_toggle,
4945 .chained = true,
4946 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4947 },
4948 [ALC260_FIXUP_REPLACER] = {
4949 .type = ALC_FIXUP_VERBS,
4950 .v.verbs = (const struct hda_verb[]) {
4951 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4952 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4953 { }
4954 },
4955 .chained = true,
4956 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4957 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004958 [ALC260_FIXUP_HP_B1900] = {
4959 .type = ALC_FIXUP_FUNC,
4960 .v.func = alc260_fixup_gpio1_toggle,
4961 .chained = true,
4962 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004963 },
4964 [ALC260_FIXUP_KN1] = {
4965 .type = ALC_FIXUP_FUNC,
4966 .v.func = alc260_fixup_kn1,
4967 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004968};
4969
4970static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004971 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004972 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004973 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004974 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004975 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004976 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004977 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004978 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004979 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004980 {}
4981};
4982
4983/*
4984 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004985static int patch_alc260(struct hda_codec *codec)
4986{
4987 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004988 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989
Takashi Iwai3de95172012-05-07 18:03:15 +02004990 err = alc_alloc_spec(codec, 0x07);
4991 if (err < 0)
4992 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993
Takashi Iwai3de95172012-05-07 18:03:15 +02004994 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004996 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4997 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004998
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004999 /* automatic parse from the BIOS config */
5000 err = alc260_parse_auto_config(codec);
5001 if (err < 0)
5002 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005003
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005004 if (!spec->no_analog) {
5005 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005006 if (err < 0)
5007 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005008 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5009 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005010
Takashi Iwai1d045db2011-07-07 18:23:21 +02005011 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005012 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005013
Takashi Iwai589876e2012-02-20 15:47:55 +01005014 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5015
Takashi Iwai1d045db2011-07-07 18:23:21 +02005016 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005017
5018 error:
5019 alc_free(codec);
5020 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005021}
5022
5023
5024/*
5025 * ALC882/883/885/888/889 support
5026 *
5027 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5028 * configuration. Each pin widget can choose any input DACs and a mixer.
5029 * Each ADC is connected from a mixer of all inputs. This makes possible
5030 * 6-channel independent captures.
5031 *
5032 * In addition, an independent DAC for the multi-playback (not used in this
5033 * driver yet).
5034 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005035
5036/*
5037 * Pin config fixes
5038 */
5039enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005040 ALC882_FIXUP_ABIT_AW9D_MAX,
5041 ALC882_FIXUP_LENOVO_Y530,
5042 ALC882_FIXUP_PB_M5210,
5043 ALC882_FIXUP_ACER_ASPIRE_7736,
5044 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005045 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005046 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005047 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005048 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005049 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005050 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005051 ALC882_FIXUP_GPIO1,
5052 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005053 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005054 ALC889_FIXUP_COEF,
5055 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005056 ALC882_FIXUP_ACER_ASPIRE_4930G,
5057 ALC882_FIXUP_ACER_ASPIRE_8930G,
5058 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005059 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005060 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005061 ALC889_FIXUP_MBP_VREF,
5062 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005063 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005064 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005065};
5066
Takashi Iwai68ef0562011-11-09 18:24:44 +01005067static void alc889_fixup_coef(struct hda_codec *codec,
5068 const struct alc_fixup *fix, int action)
5069{
5070 if (action != ALC_FIXUP_ACT_INIT)
5071 return;
5072 alc889_coef_init(codec);
5073}
5074
Takashi Iwai56710872011-11-14 17:42:11 +01005075/* toggle speaker-output according to the hp-jack state */
5076static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5077{
5078 unsigned int gpiostate, gpiomask, gpiodir;
5079
5080 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5081 AC_VERB_GET_GPIO_DATA, 0);
5082
5083 if (!muted)
5084 gpiostate |= (1 << pin);
5085 else
5086 gpiostate &= ~(1 << pin);
5087
5088 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5089 AC_VERB_GET_GPIO_MASK, 0);
5090 gpiomask |= (1 << pin);
5091
5092 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5093 AC_VERB_GET_GPIO_DIRECTION, 0);
5094 gpiodir |= (1 << pin);
5095
5096
5097 snd_hda_codec_write(codec, codec->afg, 0,
5098 AC_VERB_SET_GPIO_MASK, gpiomask);
5099 snd_hda_codec_write(codec, codec->afg, 0,
5100 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5101
5102 msleep(1);
5103
5104 snd_hda_codec_write(codec, codec->afg, 0,
5105 AC_VERB_SET_GPIO_DATA, gpiostate);
5106}
5107
5108/* set up GPIO at initialization */
5109static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5110 const struct alc_fixup *fix, int action)
5111{
5112 if (action != ALC_FIXUP_ACT_INIT)
5113 return;
5114 alc882_gpio_mute(codec, 0, 0);
5115 alc882_gpio_mute(codec, 1, 0);
5116}
5117
Takashi Iwai02a237b2012-02-13 15:25:07 +01005118/* Fix the connection of some pins for ALC889:
5119 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5120 * work correctly (bko#42740)
5121 */
5122static void alc889_fixup_dac_route(struct hda_codec *codec,
5123 const struct alc_fixup *fix, int action)
5124{
5125 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005126 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005127 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5128 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5129 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5130 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5131 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5132 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005133 } else if (action == ALC_FIXUP_ACT_PROBE) {
5134 /* restore the connections */
5135 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5136 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5137 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5138 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5139 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005140 }
5141}
5142
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005143/* Set VREF on HP pin */
5144static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5145 const struct alc_fixup *fix, int action)
5146{
5147 struct alc_spec *spec = codec->spec;
5148 static hda_nid_t nids[2] = { 0x14, 0x15 };
5149 int i;
5150
5151 if (action != ALC_FIXUP_ACT_INIT)
5152 return;
5153 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5154 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5155 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5156 continue;
5157 val = snd_hda_codec_read(codec, nids[i], 0,
5158 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5159 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005160 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005161 spec->keep_vref_in_automute = 1;
5162 break;
5163 }
5164}
5165
5166/* Set VREF on speaker pins on imac91 */
5167static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5168 const struct alc_fixup *fix, int action)
5169{
5170 struct alc_spec *spec = codec->spec;
5171 static hda_nid_t nids[2] = { 0x18, 0x1a };
5172 int i;
5173
5174 if (action != ALC_FIXUP_ACT_INIT)
5175 return;
5176 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5177 unsigned int val;
5178 val = snd_hda_codec_read(codec, nids[i], 0,
5179 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5180 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005181 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005182 }
5183 spec->keep_vref_in_automute = 1;
5184}
5185
Takashi Iwaie427c232012-07-29 10:04:08 +02005186/* Don't take HP output as primary
5187 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5188 */
5189static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5190 const struct alc_fixup *fix, int action)
5191{
5192 struct alc_spec *spec = codec->spec;
5193 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5194 spec->no_primary_hp = 1;
5195}
5196
Takashi Iwai1d045db2011-07-07 18:23:21 +02005197static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005198 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005199 .type = ALC_FIXUP_PINS,
5200 .v.pins = (const struct alc_pincfg[]) {
5201 { 0x15, 0x01080104 }, /* side */
5202 { 0x16, 0x01011012 }, /* rear */
5203 { 0x17, 0x01016011 }, /* clfe */
5204 { }
5205 }
5206 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005207 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005208 .type = ALC_FIXUP_PINS,
5209 .v.pins = (const struct alc_pincfg[]) {
5210 { 0x15, 0x99130112 }, /* rear int speakers */
5211 { 0x16, 0x99130111 }, /* subwoofer */
5212 { }
5213 }
5214 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005215 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005216 .type = ALC_FIXUP_VERBS,
5217 .v.verbs = (const struct hda_verb[]) {
5218 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5219 {}
5220 }
5221 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005222 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005223 .type = ALC_FIXUP_FUNC,
5224 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005225 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005226 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005227 .type = ALC_FIXUP_PINS,
5228 .v.pins = (const struct alc_pincfg[]) {
5229 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5230 { }
5231 }
5232 },
Marton Balint8f239212012-03-05 21:33:23 +01005233 [ALC889_FIXUP_CD] = {
5234 .type = ALC_FIXUP_PINS,
5235 .v.pins = (const struct alc_pincfg[]) {
5236 { 0x1c, 0x993301f0 }, /* CD */
5237 { }
5238 }
5239 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005240 [ALC889_FIXUP_VAIO_TT] = {
5241 .type = ALC_FIXUP_PINS,
5242 .v.pins = (const struct alc_pincfg[]) {
5243 { 0x17, 0x90170111 }, /* hidden surround speaker */
5244 { }
5245 }
5246 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005247 [ALC888_FIXUP_EEE1601] = {
5248 .type = ALC_FIXUP_VERBS,
5249 .v.verbs = (const struct hda_verb[]) {
5250 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5251 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5252 { }
5253 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005254 },
5255 [ALC882_FIXUP_EAPD] = {
5256 .type = ALC_FIXUP_VERBS,
5257 .v.verbs = (const struct hda_verb[]) {
5258 /* change to EAPD mode */
5259 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5260 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5261 { }
5262 }
5263 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005264 [ALC883_FIXUP_EAPD] = {
5265 .type = ALC_FIXUP_VERBS,
5266 .v.verbs = (const struct hda_verb[]) {
5267 /* change to EAPD mode */
5268 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5269 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5270 { }
5271 }
5272 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005273 [ALC883_FIXUP_ACER_EAPD] = {
5274 .type = ALC_FIXUP_VERBS,
5275 .v.verbs = (const struct hda_verb[]) {
5276 /* eanable EAPD on Acer laptops */
5277 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5278 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5279 { }
5280 }
5281 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005282 [ALC882_FIXUP_GPIO1] = {
5283 .type = ALC_FIXUP_VERBS,
5284 .v.verbs = alc_gpio1_init_verbs,
5285 },
5286 [ALC882_FIXUP_GPIO2] = {
5287 .type = ALC_FIXUP_VERBS,
5288 .v.verbs = alc_gpio2_init_verbs,
5289 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005290 [ALC882_FIXUP_GPIO3] = {
5291 .type = ALC_FIXUP_VERBS,
5292 .v.verbs = alc_gpio3_init_verbs,
5293 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005294 [ALC882_FIXUP_ASUS_W2JC] = {
5295 .type = ALC_FIXUP_VERBS,
5296 .v.verbs = alc_gpio1_init_verbs,
5297 .chained = true,
5298 .chain_id = ALC882_FIXUP_EAPD,
5299 },
5300 [ALC889_FIXUP_COEF] = {
5301 .type = ALC_FIXUP_FUNC,
5302 .v.func = alc889_fixup_coef,
5303 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005304 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5305 .type = ALC_FIXUP_PINS,
5306 .v.pins = (const struct alc_pincfg[]) {
5307 { 0x16, 0x99130111 }, /* CLFE speaker */
5308 { 0x17, 0x99130112 }, /* surround speaker */
5309 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005310 },
5311 .chained = true,
5312 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005313 },
5314 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5315 .type = ALC_FIXUP_PINS,
5316 .v.pins = (const struct alc_pincfg[]) {
5317 { 0x16, 0x99130111 }, /* CLFE speaker */
5318 { 0x1b, 0x99130112 }, /* surround speaker */
5319 { }
5320 },
5321 .chained = true,
5322 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5323 },
5324 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5325 /* additional init verbs for Acer Aspire 8930G */
5326 .type = ALC_FIXUP_VERBS,
5327 .v.verbs = (const struct hda_verb[]) {
5328 /* Enable all DACs */
5329 /* DAC DISABLE/MUTE 1? */
5330 /* setting bits 1-5 disables DAC nids 0x02-0x06
5331 * apparently. Init=0x38 */
5332 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5333 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5334 /* DAC DISABLE/MUTE 2? */
5335 /* some bit here disables the other DACs.
5336 * Init=0x4900 */
5337 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5338 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5339 /* DMIC fix
5340 * This laptop has a stereo digital microphone.
5341 * The mics are only 1cm apart which makes the stereo
5342 * useless. However, either the mic or the ALC889
5343 * makes the signal become a difference/sum signal
5344 * instead of standard stereo, which is annoying.
5345 * So instead we flip this bit which makes the
5346 * codec replicate the sum signal to both channels,
5347 * turning it into a normal mono mic.
5348 */
5349 /* DMIC_CONTROL? Init value = 0x0001 */
5350 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5351 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5352 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5353 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5354 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005355 },
5356 .chained = true,
5357 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005358 },
Takashi Iwai56710872011-11-14 17:42:11 +01005359 [ALC885_FIXUP_MACPRO_GPIO] = {
5360 .type = ALC_FIXUP_FUNC,
5361 .v.func = alc885_fixup_macpro_gpio,
5362 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005363 [ALC889_FIXUP_DAC_ROUTE] = {
5364 .type = ALC_FIXUP_FUNC,
5365 .v.func = alc889_fixup_dac_route,
5366 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005367 [ALC889_FIXUP_MBP_VREF] = {
5368 .type = ALC_FIXUP_FUNC,
5369 .v.func = alc889_fixup_mbp_vref,
5370 .chained = true,
5371 .chain_id = ALC882_FIXUP_GPIO1,
5372 },
5373 [ALC889_FIXUP_IMAC91_VREF] = {
5374 .type = ALC_FIXUP_FUNC,
5375 .v.func = alc889_fixup_imac91_vref,
5376 .chained = true,
5377 .chain_id = ALC882_FIXUP_GPIO1,
5378 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005379 [ALC882_FIXUP_INV_DMIC] = {
5380 .type = ALC_FIXUP_FUNC,
5381 .v.func = alc_fixup_inv_dmic_0x12,
5382 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005383 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5384 .type = ALC_FIXUP_FUNC,
5385 .v.func = alc882_fixup_no_primary_hp,
5386 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005387};
5388
5389static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005390 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5391 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5392 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5393 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5394 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5395 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005396 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5397 ALC882_FIXUP_ACER_ASPIRE_4930G),
5398 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5399 ALC882_FIXUP_ACER_ASPIRE_4930G),
5400 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5401 ALC882_FIXUP_ACER_ASPIRE_8930G),
5402 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5403 ALC882_FIXUP_ACER_ASPIRE_8930G),
5404 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5405 ALC882_FIXUP_ACER_ASPIRE_4930G),
5406 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5407 ALC882_FIXUP_ACER_ASPIRE_4930G),
5408 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5409 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005410 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005411 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5412 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005413 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005414 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005415 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005416 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005417 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005418 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005419 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005420 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005421 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005422
5423 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005424 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5425 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5426 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005427 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5428 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5429 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005430 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5431 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005432 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005433 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5434 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5435 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5436 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005437 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005438 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5439 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5440 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005441 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005442 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005443 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5444 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5445 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005446
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005447 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005448 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005449 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005450 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005451 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005452 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5453 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005454 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005455 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005456 {}
5457};
5458
Takashi Iwai912093b2012-04-11 14:03:41 +02005459static const struct alc_model_fixup alc882_fixup_models[] = {
5460 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5461 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5462 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005463 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005464 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005465 {}
5466};
5467
Takashi Iwai1d045db2011-07-07 18:23:21 +02005468/*
5469 * BIOS auto configuration
5470 */
5471/* almost identical with ALC880 parser... */
5472static int alc882_parse_auto_config(struct hda_codec *codec)
5473{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005474 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005475 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5476 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005477}
5478
Takashi Iwai1d045db2011-07-07 18:23:21 +02005479/*
5480 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481static int patch_alc882(struct hda_codec *codec)
5482{
5483 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005484 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005485
Takashi Iwai3de95172012-05-07 18:03:15 +02005486 err = alc_alloc_spec(codec, 0x0b);
5487 if (err < 0)
5488 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489
Takashi Iwai3de95172012-05-07 18:03:15 +02005490 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005491
5492 switch (codec->vendor_id) {
5493 case 0x10ec0882:
5494 case 0x10ec0885:
5495 break;
5496 default:
5497 /* ALC883 and variants */
5498 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5499 break;
5500 }
5501
Takashi Iwai912093b2012-04-11 14:03:41 +02005502 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5503 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005504 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505
5506 alc_auto_parse_customize_define(codec);
5507
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005508 /* automatic parse from the BIOS config */
5509 err = alc882_parse_auto_config(codec);
5510 if (err < 0)
5511 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005513 if (!spec->no_analog && has_cdefine_beep(codec)) {
5514 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005515 if (err < 0)
5516 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005517 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005518 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005519
Takashi Iwai1d045db2011-07-07 18:23:21 +02005520 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005521
Takashi Iwai589876e2012-02-20 15:47:55 +01005522 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5523
Takashi Iwai1d045db2011-07-07 18:23:21 +02005524 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005525
5526 error:
5527 alc_free(codec);
5528 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005529}
5530
5531
5532/*
5533 * ALC262 support
5534 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005535static int alc262_parse_auto_config(struct hda_codec *codec)
5536{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005537 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005538 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5539 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005540}
5541
5542/*
5543 * Pin config fixes
5544 */
5545enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005546 ALC262_FIXUP_FSC_H270,
5547 ALC262_FIXUP_HP_Z200,
5548 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005549 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005550 ALC262_FIXUP_BENQ,
5551 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005552 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005553};
5554
5555static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005556 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005557 .type = ALC_FIXUP_PINS,
5558 .v.pins = (const struct alc_pincfg[]) {
5559 { 0x14, 0x99130110 }, /* speaker */
5560 { 0x15, 0x0221142f }, /* front HP */
5561 { 0x1b, 0x0121141f }, /* rear HP */
5562 { }
5563 }
5564 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005565 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005566 .type = ALC_FIXUP_PINS,
5567 .v.pins = (const struct alc_pincfg[]) {
5568 { 0x16, 0x99130120 }, /* internal speaker */
5569 { }
5570 }
5571 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005572 [ALC262_FIXUP_TYAN] = {
5573 .type = ALC_FIXUP_PINS,
5574 .v.pins = (const struct alc_pincfg[]) {
5575 { 0x14, 0x1993e1f0 }, /* int AUX */
5576 { }
5577 }
5578 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005579 [ALC262_FIXUP_LENOVO_3000] = {
5580 .type = ALC_FIXUP_VERBS,
5581 .v.verbs = (const struct hda_verb[]) {
5582 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005583 {}
5584 },
5585 .chained = true,
5586 .chain_id = ALC262_FIXUP_BENQ,
5587 },
5588 [ALC262_FIXUP_BENQ] = {
5589 .type = ALC_FIXUP_VERBS,
5590 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005591 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5592 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5593 {}
5594 }
5595 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005596 [ALC262_FIXUP_BENQ_T31] = {
5597 .type = ALC_FIXUP_VERBS,
5598 .v.verbs = (const struct hda_verb[]) {
5599 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5600 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5601 {}
5602 }
5603 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005604 [ALC262_FIXUP_INV_DMIC] = {
5605 .type = ALC_FIXUP_FUNC,
5606 .v.func = alc_fixup_inv_dmic_0x12,
5607 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005608};
5609
5610static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005611 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005612 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5613 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005614 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5615 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005616 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005617 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5618 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005619 {}
5620};
5621
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005622static const struct alc_model_fixup alc262_fixup_models[] = {
5623 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5624 {}
5625};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005626
Takashi Iwai1d045db2011-07-07 18:23:21 +02005627/*
5628 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005629static int patch_alc262(struct hda_codec *codec)
5630{
5631 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005632 int err;
5633
Takashi Iwai3de95172012-05-07 18:03:15 +02005634 err = alc_alloc_spec(codec, 0x0b);
5635 if (err < 0)
5636 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005637
Takashi Iwai3de95172012-05-07 18:03:15 +02005638 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01005639 spec->shared_mic_vref_pin = 0x18;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005640
5641#if 0
5642 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5643 * under-run
5644 */
5645 {
5646 int tmp;
5647 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5648 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5649 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5650 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5651 }
5652#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005653 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5654
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005655 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5656 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005657 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005658
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005659 alc_auto_parse_customize_define(codec);
5660
Takashi Iwai42399f72011-11-07 17:18:44 +01005661 /* automatic parse from the BIOS config */
5662 err = alc262_parse_auto_config(codec);
5663 if (err < 0)
5664 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005665
Takashi Iwai1d045db2011-07-07 18:23:21 +02005666 if (!spec->no_analog && has_cdefine_beep(codec)) {
5667 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005668 if (err < 0)
5669 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005670 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005671 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005672
Takashi Iwai1d045db2011-07-07 18:23:21 +02005673 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005674 spec->shutup = alc_eapd_shutup;
5675
Takashi Iwai589876e2012-02-20 15:47:55 +01005676 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5677
Takashi Iwai1d045db2011-07-07 18:23:21 +02005678 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005679
5680 error:
5681 alc_free(codec);
5682 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005683}
5684
5685/*
5686 * ALC268
5687 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005688/* bind Beep switches of both NID 0x0f and 0x10 */
5689static const struct hda_bind_ctls alc268_bind_beep_sw = {
5690 .ops = &snd_hda_bind_sw,
5691 .values = {
5692 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5693 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5694 0
5695 },
5696};
5697
5698static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5699 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5700 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5701 { }
5702};
5703
5704/* set PCBEEP vol = 0, mute connections */
5705static const struct hda_verb alc268_beep_init_verbs[] = {
5706 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5707 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5708 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5709 { }
5710};
5711
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005712enum {
5713 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005714 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005715};
5716
5717static const struct alc_fixup alc268_fixups[] = {
5718 [ALC268_FIXUP_INV_DMIC] = {
5719 .type = ALC_FIXUP_FUNC,
5720 .v.func = alc_fixup_inv_dmic_0x12,
5721 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005722 [ALC268_FIXUP_HP_EAPD] = {
5723 .type = ALC_FIXUP_VERBS,
5724 .v.verbs = (const struct hda_verb[]) {
5725 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5726 {}
5727 }
5728 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005729};
5730
5731static const struct alc_model_fixup alc268_fixup_models[] = {
5732 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005733 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5734 {}
5735};
5736
5737static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5738 /* below is codec SSID since multiple Toshiba laptops have the
5739 * same PCI SSID 1179:ff00
5740 */
5741 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005742 {}
5743};
5744
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745/*
5746 * BIOS auto configuration
5747 */
5748static int alc268_parse_auto_config(struct hda_codec *codec)
5749{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005750 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005751 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005752 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5753 if (err > 0) {
5754 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5755 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005756 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005758 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005759 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005760}
5761
Takashi Iwai1d045db2011-07-07 18:23:21 +02005762/*
5763 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005764static int patch_alc268(struct hda_codec *codec)
5765{
5766 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767 int i, has_beep, err;
5768
Takashi Iwai1d045db2011-07-07 18:23:21 +02005769 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005770 err = alc_alloc_spec(codec, 0);
5771 if (err < 0)
5772 return err;
5773
5774 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005775
Takashi Iwaicb766402012-10-20 10:55:21 +02005776 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005777 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5778
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005779 /* automatic parse from the BIOS config */
5780 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005781 if (err < 0)
5782 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005783
Takashi Iwai1d045db2011-07-07 18:23:21 +02005784 has_beep = 0;
5785 for (i = 0; i < spec->num_mixers; i++) {
5786 if (spec->mixers[i] == alc268_beep_mixer) {
5787 has_beep = 1;
5788 break;
5789 }
5790 }
5791
5792 if (has_beep) {
5793 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005794 if (err < 0)
5795 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005796 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5797 /* override the amp caps for beep generator */
5798 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5799 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5800 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5801 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5802 (0 << AC_AMPCAP_MUTE_SHIFT));
5803 }
5804
Takashi Iwai1d045db2011-07-07 18:23:21 +02005805 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005806 spec->shutup = alc_eapd_shutup;
5807
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005808 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5809
Takashi Iwai1d045db2011-07-07 18:23:21 +02005810 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005811
5812 error:
5813 alc_free(codec);
5814 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005815}
5816
5817/*
5818 * ALC269
5819 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005820static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5821 .substreams = 1,
5822 .channels_min = 2,
5823 .channels_max = 8,
5824 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5825 /* NID is set in alc_build_pcms */
5826 .ops = {
5827 .open = alc_playback_pcm_open,
5828 .prepare = alc_playback_pcm_prepare,
5829 .cleanup = alc_playback_pcm_cleanup
5830 },
5831};
5832
5833static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5834 .substreams = 1,
5835 .channels_min = 2,
5836 .channels_max = 2,
5837 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5838 /* NID is set in alc_build_pcms */
5839};
5840
Takashi Iwai1d045db2011-07-07 18:23:21 +02005841/* different alc269-variants */
5842enum {
5843 ALC269_TYPE_ALC269VA,
5844 ALC269_TYPE_ALC269VB,
5845 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005846 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005847 ALC269_TYPE_ALC280,
5848 ALC269_TYPE_ALC282,
5849 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005850};
5851
5852/*
5853 * BIOS auto configuration
5854 */
5855static int alc269_parse_auto_config(struct hda_codec *codec)
5856{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005857 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005858 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5859 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5860 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005861 const hda_nid_t *ssids;
5862
5863 switch (spec->codec_variant) {
5864 case ALC269_TYPE_ALC269VA:
5865 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005866 case ALC269_TYPE_ALC280:
5867 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005868 ssids = alc269va_ssids;
5869 break;
5870 case ALC269_TYPE_ALC269VB:
5871 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005872 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005873 ssids = alc269_ssids;
5874 break;
5875 default:
5876 ssids = alc269_ssids;
5877 break;
5878 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005879
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005880 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005881}
5882
Kailang Yang1387e2d2012-11-08 10:23:18 +01005883static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005884{
5885 int val = alc_read_coef_idx(codec, 0x04);
5886 if (power_up)
5887 val |= 1 << 11;
5888 else
5889 val &= ~(1 << 11);
5890 alc_write_coef_idx(codec, 0x04, val);
5891}
5892
5893static void alc269_shutup(struct hda_codec *codec)
5894{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005895 struct alc_spec *spec = codec->spec;
5896
5897 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5898 return;
5899
Kailang Yang1387e2d2012-11-08 10:23:18 +01005900 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5901 alc269vb_toggle_power_output(codec, 0);
5902 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5903 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005904 msleep(150);
5905 }
5906}
5907
Takashi Iwai2a439522011-07-26 09:52:50 +02005908#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005909static int alc269_resume(struct hda_codec *codec)
5910{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005911 struct alc_spec *spec = codec->spec;
5912
Kailang Yang1387e2d2012-11-08 10:23:18 +01005913 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5914 alc269vb_toggle_power_output(codec, 0);
5915 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005916 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005917 msleep(150);
5918 }
5919
5920 codec->patch_ops.init(codec);
5921
Kailang Yang1387e2d2012-11-08 10:23:18 +01005922 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5923 alc269vb_toggle_power_output(codec, 1);
5924 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005925 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005926 msleep(200);
5927 }
5928
Takashi Iwai1d045db2011-07-07 18:23:21 +02005929 snd_hda_codec_resume_amp(codec);
5930 snd_hda_codec_resume_cache(codec);
5931 hda_call_check_power_status(codec, 0x01);
5932 return 0;
5933}
Takashi Iwai2a439522011-07-26 09:52:50 +02005934#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005935
David Henningsson108cc102012-07-20 10:37:25 +02005936static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5937 const struct alc_fixup *fix, int action)
5938{
5939 struct alc_spec *spec = codec->spec;
5940
5941 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5942 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5943}
5944
Takashi Iwai1d045db2011-07-07 18:23:21 +02005945static void alc269_fixup_hweq(struct hda_codec *codec,
5946 const struct alc_fixup *fix, int action)
5947{
5948 int coef;
5949
5950 if (action != ALC_FIXUP_ACT_INIT)
5951 return;
5952 coef = alc_read_coef_idx(codec, 0x1e);
5953 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5954}
5955
5956static void alc271_fixup_dmic(struct hda_codec *codec,
5957 const struct alc_fixup *fix, int action)
5958{
5959 static const struct hda_verb verbs[] = {
5960 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5961 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5962 {}
5963 };
5964 unsigned int cfg;
5965
5966 if (strcmp(codec->chip_name, "ALC271X"))
5967 return;
5968 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5969 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5970 snd_hda_sequence_write(codec, verbs);
5971}
5972
Takashi Iwai017f2a12011-07-09 14:42:25 +02005973static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5974 const struct alc_fixup *fix, int action)
5975{
5976 struct alc_spec *spec = codec->spec;
5977
5978 if (action != ALC_FIXUP_ACT_PROBE)
5979 return;
5980
5981 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5982 * fix the sample rate of analog I/O to 44.1kHz
5983 */
5984 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5985 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5986}
5987
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005988static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5989 const struct alc_fixup *fix, int action)
5990{
5991 int coef;
5992
5993 if (action != ALC_FIXUP_ACT_INIT)
5994 return;
5995 /* The digital-mic unit sends PDM (differential signal) instead of
5996 * the standard PCM, thus you can't record a valid mono stream as is.
5997 * Below is a workaround specific to ALC269 to control the dmic
5998 * signal source as mono.
5999 */
6000 coef = alc_read_coef_idx(codec, 0x07);
6001 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6002}
6003
Takashi Iwai24519912011-08-16 15:08:49 +02006004static void alc269_quanta_automute(struct hda_codec *codec)
6005{
David Henningsson42cf0d02011-09-20 12:04:56 +02006006 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006007
6008 snd_hda_codec_write(codec, 0x20, 0,
6009 AC_VERB_SET_COEF_INDEX, 0x0c);
6010 snd_hda_codec_write(codec, 0x20, 0,
6011 AC_VERB_SET_PROC_COEF, 0x680);
6012
6013 snd_hda_codec_write(codec, 0x20, 0,
6014 AC_VERB_SET_COEF_INDEX, 0x0c);
6015 snd_hda_codec_write(codec, 0x20, 0,
6016 AC_VERB_SET_PROC_COEF, 0x480);
6017}
6018
6019static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6020 const struct alc_fixup *fix, int action)
6021{
6022 struct alc_spec *spec = codec->spec;
6023 if (action != ALC_FIXUP_ACT_PROBE)
6024 return;
6025 spec->automute_hook = alc269_quanta_automute;
6026}
6027
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006028/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6029static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6030{
6031 struct hda_codec *codec = private_data;
6032 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6033 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6034 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6035}
6036
6037static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6038 const struct alc_fixup *fix, int action)
6039{
6040 struct alc_spec *spec = codec->spec;
6041 switch (action) {
6042 case ALC_FIXUP_ACT_BUILD:
6043 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6044 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6045 /* fallthru */
6046 case ALC_FIXUP_ACT_INIT:
6047 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6048 break;
6049 }
6050}
6051
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006052/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6053static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6054{
6055 struct hda_codec *codec = private_data;
6056 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006057 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006058}
6059
6060static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6061 const struct alc_fixup *fix, int action)
6062{
6063 struct alc_spec *spec = codec->spec;
6064 switch (action) {
6065 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006066 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006067 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006068 /* fallthru */
6069 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006070 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006071 break;
6072 }
6073}
6074
Dylan Reid08a978d2012-11-18 22:56:40 -08006075static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6076 const struct alc_fixup *fix,
6077 int action)
6078{
6079 struct alc_spec *spec = codec->spec;
6080
6081 if (action == ALC_FIXUP_ACT_PROBE)
6082 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6083 spec->autocfg.hp_pins[0]);
6084}
David Henningsson693b6132012-06-22 19:12:10 +02006085
Takashi Iwai1d045db2011-07-07 18:23:21 +02006086enum {
6087 ALC269_FIXUP_SONY_VAIO,
6088 ALC275_FIXUP_SONY_VAIO_GPIO2,
6089 ALC269_FIXUP_DELL_M101Z,
6090 ALC269_FIXUP_SKU_IGNORE,
6091 ALC269_FIXUP_ASUS_G73JW,
6092 ALC269_FIXUP_LENOVO_EAPD,
6093 ALC275_FIXUP_SONY_HWEQ,
6094 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006095 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006096 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006097 ALC269_FIXUP_QUANTA_MUTE,
6098 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006099 ALC269_FIXUP_AMIC,
6100 ALC269_FIXUP_DMIC,
6101 ALC269VB_FIXUP_AMIC,
6102 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006103 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006104 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006105 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006106 ALC269_FIXUP_LENOVO_DOCK,
6107 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006108 ALC271_FIXUP_AMIC_MIC2,
6109 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006110};
6111
6112static const struct alc_fixup alc269_fixups[] = {
6113 [ALC269_FIXUP_SONY_VAIO] = {
6114 .type = ALC_FIXUP_VERBS,
6115 .v.verbs = (const struct hda_verb[]) {
6116 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6117 {}
6118 }
6119 },
6120 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6121 .type = ALC_FIXUP_VERBS,
6122 .v.verbs = (const struct hda_verb[]) {
6123 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6124 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6125 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6126 { }
6127 },
6128 .chained = true,
6129 .chain_id = ALC269_FIXUP_SONY_VAIO
6130 },
6131 [ALC269_FIXUP_DELL_M101Z] = {
6132 .type = ALC_FIXUP_VERBS,
6133 .v.verbs = (const struct hda_verb[]) {
6134 /* Enables internal speaker */
6135 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6136 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6137 {}
6138 }
6139 },
6140 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006141 .type = ALC_FIXUP_FUNC,
6142 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006143 },
6144 [ALC269_FIXUP_ASUS_G73JW] = {
6145 .type = ALC_FIXUP_PINS,
6146 .v.pins = (const struct alc_pincfg[]) {
6147 { 0x17, 0x99130111 }, /* subwoofer */
6148 { }
6149 }
6150 },
6151 [ALC269_FIXUP_LENOVO_EAPD] = {
6152 .type = ALC_FIXUP_VERBS,
6153 .v.verbs = (const struct hda_verb[]) {
6154 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6155 {}
6156 }
6157 },
6158 [ALC275_FIXUP_SONY_HWEQ] = {
6159 .type = ALC_FIXUP_FUNC,
6160 .v.func = alc269_fixup_hweq,
6161 .chained = true,
6162 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6163 },
6164 [ALC271_FIXUP_DMIC] = {
6165 .type = ALC_FIXUP_FUNC,
6166 .v.func = alc271_fixup_dmic,
6167 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006168 [ALC269_FIXUP_PCM_44K] = {
6169 .type = ALC_FIXUP_FUNC,
6170 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006171 .chained = true,
6172 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006173 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006174 [ALC269_FIXUP_STEREO_DMIC] = {
6175 .type = ALC_FIXUP_FUNC,
6176 .v.func = alc269_fixup_stereo_dmic,
6177 },
Takashi Iwai24519912011-08-16 15:08:49 +02006178 [ALC269_FIXUP_QUANTA_MUTE] = {
6179 .type = ALC_FIXUP_FUNC,
6180 .v.func = alc269_fixup_quanta_mute,
6181 },
6182 [ALC269_FIXUP_LIFEBOOK] = {
6183 .type = ALC_FIXUP_PINS,
6184 .v.pins = (const struct alc_pincfg[]) {
6185 { 0x1a, 0x2101103f }, /* dock line-out */
6186 { 0x1b, 0x23a11040 }, /* dock mic-in */
6187 { }
6188 },
6189 .chained = true,
6190 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6191 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006192 [ALC269_FIXUP_AMIC] = {
6193 .type = ALC_FIXUP_PINS,
6194 .v.pins = (const struct alc_pincfg[]) {
6195 { 0x14, 0x99130110 }, /* speaker */
6196 { 0x15, 0x0121401f }, /* HP out */
6197 { 0x18, 0x01a19c20 }, /* mic */
6198 { 0x19, 0x99a3092f }, /* int-mic */
6199 { }
6200 },
6201 },
6202 [ALC269_FIXUP_DMIC] = {
6203 .type = ALC_FIXUP_PINS,
6204 .v.pins = (const struct alc_pincfg[]) {
6205 { 0x12, 0x99a3092f }, /* int-mic */
6206 { 0x14, 0x99130110 }, /* speaker */
6207 { 0x15, 0x0121401f }, /* HP out */
6208 { 0x18, 0x01a19c20 }, /* mic */
6209 { }
6210 },
6211 },
6212 [ALC269VB_FIXUP_AMIC] = {
6213 .type = ALC_FIXUP_PINS,
6214 .v.pins = (const struct alc_pincfg[]) {
6215 { 0x14, 0x99130110 }, /* speaker */
6216 { 0x18, 0x01a19c20 }, /* mic */
6217 { 0x19, 0x99a3092f }, /* int-mic */
6218 { 0x21, 0x0121401f }, /* HP out */
6219 { }
6220 },
6221 },
David Henningsson2267ea92012-01-03 08:45:56 +01006222 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006223 .type = ALC_FIXUP_PINS,
6224 .v.pins = (const struct alc_pincfg[]) {
6225 { 0x12, 0x99a3092f }, /* int-mic */
6226 { 0x14, 0x99130110 }, /* speaker */
6227 { 0x18, 0x01a19c20 }, /* mic */
6228 { 0x21, 0x0121401f }, /* HP out */
6229 { }
6230 },
6231 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006232 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6233 .type = ALC_FIXUP_FUNC,
6234 .v.func = alc269_fixup_mic1_mute,
6235 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006236 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6237 .type = ALC_FIXUP_FUNC,
6238 .v.func = alc269_fixup_mic2_mute,
6239 },
David Henningsson693b6132012-06-22 19:12:10 +02006240 [ALC269_FIXUP_INV_DMIC] = {
6241 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006242 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006243 },
David Henningsson108cc102012-07-20 10:37:25 +02006244 [ALC269_FIXUP_LENOVO_DOCK] = {
6245 .type = ALC_FIXUP_PINS,
6246 .v.pins = (const struct alc_pincfg[]) {
6247 { 0x19, 0x23a11040 }, /* dock mic */
6248 { 0x1b, 0x2121103f }, /* dock headphone */
6249 { }
6250 },
6251 .chained = true,
6252 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6253 },
6254 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6255 .type = ALC_FIXUP_FUNC,
6256 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6257 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006258 [ALC271_FIXUP_AMIC_MIC2] = {
6259 .type = ALC_FIXUP_PINS,
6260 .v.pins = (const struct alc_pincfg[]) {
6261 { 0x14, 0x99130110 }, /* speaker */
6262 { 0x19, 0x01a19c20 }, /* mic */
6263 { 0x1b, 0x99a7012f }, /* int-mic */
6264 { 0x21, 0x0121401f }, /* HP out */
6265 { }
6266 },
6267 },
6268 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6269 .type = ALC_FIXUP_FUNC,
6270 .v.func = alc271_hp_gate_mic_jack,
6271 .chained = true,
6272 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6273 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006274};
6275
6276static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006277 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6278 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006279 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006280 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006281 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006282 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006283 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006284 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006285 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6286 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6287 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6288 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6289 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006290 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6291 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6292 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6293 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6294 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006295 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006296 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006297 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006298 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6299 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6300 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6301 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6302 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006303 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006304 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006305 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006306 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006307 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006308 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006309 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006310
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006311#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006312 /* Below is a quirk table taken from the old code.
6313 * Basically the device should work as is without the fixup table.
6314 * If BIOS doesn't give a proper info, enable the corresponding
6315 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006316 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006317 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6318 ALC269_FIXUP_AMIC),
6319 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006320 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6321 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6322 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6323 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6324 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6325 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6326 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6327 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6328 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6329 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6330 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6331 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6332 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6333 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6334 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6335 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6336 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6337 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6338 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6339 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6340 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6341 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6342 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6343 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6344 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6345 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6346 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6347 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6348 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6349 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6350 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6351 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6352 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6353 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6354 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6355 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6356 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6357 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6358#endif
6359 {}
6360};
6361
6362static const struct alc_model_fixup alc269_fixup_models[] = {
6363 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6364 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006365 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6366 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6367 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006368 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006369 {}
6370};
6371
6372
Takashi Iwai546bb672012-03-07 08:37:19 +01006373static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006374{
Kailang Yang526af6e2012-03-07 08:25:20 +01006375 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006376 int val;
6377
Kailang Yang526af6e2012-03-07 08:25:20 +01006378 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006379 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006380
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006381 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006382 alc_write_coef_idx(codec, 0xf, 0x960b);
6383 alc_write_coef_idx(codec, 0xe, 0x8817);
6384 }
6385
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006386 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006387 alc_write_coef_idx(codec, 0xf, 0x960b);
6388 alc_write_coef_idx(codec, 0xe, 0x8814);
6389 }
6390
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006391 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006392 val = alc_read_coef_idx(codec, 0x04);
6393 /* Power up output pin */
6394 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6395 }
6396
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006397 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006398 val = alc_read_coef_idx(codec, 0xd);
6399 if ((val & 0x0c00) >> 10 != 0x1) {
6400 /* Capless ramp up clock control */
6401 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6402 }
6403 val = alc_read_coef_idx(codec, 0x17);
6404 if ((val & 0x01c0) >> 6 != 0x4) {
6405 /* Class D power on reset */
6406 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6407 }
6408 }
6409
6410 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6411 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6412
6413 val = alc_read_coef_idx(codec, 0x4); /* HP */
6414 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006415}
6416
6417/*
6418 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006419static int patch_alc269(struct hda_codec *codec)
6420{
6421 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006422 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006423
Takashi Iwai3de95172012-05-07 18:03:15 +02006424 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006425 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006426 return err;
6427
6428 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01006429 spec->shared_mic_vref_pin = 0x18;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006430
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006431 alc_pick_fixup(codec, alc269_fixup_models,
6432 alc269_fixup_tbl, alc269_fixups);
6433 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6434
6435 alc_auto_parse_customize_define(codec);
6436
Kailang Yang065380f2013-01-10 10:25:48 +01006437 switch (codec->vendor_id) {
6438 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006439 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006440 switch (alc_get_coef0(codec) & 0x00f0) {
6441 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006442 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006443 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006444 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006445 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006446 break;
6447 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006448 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6449 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006450 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006451 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006452 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006453 case 0x0030:
6454 spec->codec_variant = ALC269_TYPE_ALC269VD;
6455 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006456 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006457 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006458 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006459 if (err < 0)
6460 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006461 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006462 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006463 break;
6464
6465 case 0x10ec0280:
6466 case 0x10ec0290:
6467 spec->codec_variant = ALC269_TYPE_ALC280;
6468 break;
6469 case 0x10ec0282:
6470 case 0x10ec0283:
6471 spec->codec_variant = ALC269_TYPE_ALC282;
6472 break;
6473 case 0x10ec0284:
6474 case 0x10ec0292:
6475 spec->codec_variant = ALC269_TYPE_ALC284;
6476 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006477 }
6478
Takashi Iwaia4297b52011-08-23 18:40:12 +02006479 /* automatic parse from the BIOS config */
6480 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006481 if (err < 0)
6482 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006483
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006484 if (!spec->no_analog && has_cdefine_beep(codec)) {
6485 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006486 if (err < 0)
6487 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006488 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006489 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006490
Takashi Iwai1d045db2011-07-07 18:23:21 +02006491 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006492#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006493 codec->patch_ops.resume = alc269_resume;
6494#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006495 spec->shutup = alc269_shutup;
6496
Takashi Iwai589876e2012-02-20 15:47:55 +01006497 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6498
Takashi Iwai1d045db2011-07-07 18:23:21 +02006499 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006500
6501 error:
6502 alc_free(codec);
6503 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006504}
6505
6506/*
6507 * ALC861
6508 */
6509
Takashi Iwai1d045db2011-07-07 18:23:21 +02006510static int alc861_parse_auto_config(struct hda_codec *codec)
6511{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006512 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006513 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6514 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006515}
6516
Takashi Iwai1d045db2011-07-07 18:23:21 +02006517/* Pin config fixes */
6518enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006519 ALC861_FIXUP_FSC_AMILO_PI1505,
6520 ALC861_FIXUP_AMP_VREF_0F,
6521 ALC861_FIXUP_NO_JACK_DETECT,
6522 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006523};
6524
Takashi Iwai31150f22012-01-30 10:54:08 +01006525/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6526static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6527 const struct alc_fixup *fix, int action)
6528{
6529 struct alc_spec *spec = codec->spec;
6530 unsigned int val;
6531
6532 if (action != ALC_FIXUP_ACT_INIT)
6533 return;
6534 val = snd_hda_codec_read(codec, 0x0f, 0,
6535 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6536 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6537 val |= AC_PINCTL_IN_EN;
6538 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006539 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006540 spec->keep_vref_in_automute = 1;
6541}
6542
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006543/* suppress the jack-detection */
6544static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6545 const struct alc_fixup *fix, int action)
6546{
6547 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6548 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006549}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006550
Takashi Iwai1d045db2011-07-07 18:23:21 +02006551static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006552 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006553 .type = ALC_FIXUP_PINS,
6554 .v.pins = (const struct alc_pincfg[]) {
6555 { 0x0b, 0x0221101f }, /* HP */
6556 { 0x0f, 0x90170310 }, /* speaker */
6557 { }
6558 }
6559 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006560 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006561 .type = ALC_FIXUP_FUNC,
6562 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006563 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006564 [ALC861_FIXUP_NO_JACK_DETECT] = {
6565 .type = ALC_FIXUP_FUNC,
6566 .v.func = alc_fixup_no_jack_detect,
6567 },
6568 [ALC861_FIXUP_ASUS_A6RP] = {
6569 .type = ALC_FIXUP_FUNC,
6570 .v.func = alc861_fixup_asus_amp_vref_0f,
6571 .chained = true,
6572 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6573 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006574};
6575
6576static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006577 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6578 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6579 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6580 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6581 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6582 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006583 {}
6584};
6585
6586/*
6587 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006588static int patch_alc861(struct hda_codec *codec)
6589{
6590 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006591 int err;
6592
Takashi Iwai3de95172012-05-07 18:03:15 +02006593 err = alc_alloc_spec(codec, 0x15);
6594 if (err < 0)
6595 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006596
Takashi Iwai3de95172012-05-07 18:03:15 +02006597 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006598
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006599 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6600 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006601
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006602 /* automatic parse from the BIOS config */
6603 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006604 if (err < 0)
6605 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006606
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006607 if (!spec->no_analog) {
6608 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006609 if (err < 0)
6610 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006611 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6612 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006613
Takashi Iwai1d045db2011-07-07 18:23:21 +02006614 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006615#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006616 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006617#endif
6618
Takashi Iwai589876e2012-02-20 15:47:55 +01006619 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6620
Takashi Iwai1d045db2011-07-07 18:23:21 +02006621 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006622
6623 error:
6624 alc_free(codec);
6625 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006626}
6627
6628/*
6629 * ALC861-VD support
6630 *
6631 * Based on ALC882
6632 *
6633 * In addition, an independent DAC
6634 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006635static int alc861vd_parse_auto_config(struct hda_codec *codec)
6636{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006637 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006638 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6639 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006640}
6641
Takashi Iwai1d045db2011-07-07 18:23:21 +02006642enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006643 ALC660VD_FIX_ASUS_GPIO1,
6644 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006645};
6646
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006647/* exclude VREF80 */
6648static void alc861vd_fixup_dallas(struct hda_codec *codec,
6649 const struct alc_fixup *fix, int action)
6650{
6651 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006652 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6653 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006654 }
6655}
6656
Takashi Iwai1d045db2011-07-07 18:23:21 +02006657static const struct alc_fixup alc861vd_fixups[] = {
6658 [ALC660VD_FIX_ASUS_GPIO1] = {
6659 .type = ALC_FIXUP_VERBS,
6660 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006661 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006662 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6663 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6664 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6665 { }
6666 }
6667 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006668 [ALC861VD_FIX_DALLAS] = {
6669 .type = ALC_FIXUP_FUNC,
6670 .v.func = alc861vd_fixup_dallas,
6671 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006672};
6673
6674static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006675 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006676 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006677 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006678 {}
6679};
6680
Takashi Iwai1d045db2011-07-07 18:23:21 +02006681/*
6682 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006683static int patch_alc861vd(struct hda_codec *codec)
6684{
6685 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006686 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006687
Takashi Iwai3de95172012-05-07 18:03:15 +02006688 err = alc_alloc_spec(codec, 0x0b);
6689 if (err < 0)
6690 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006691
Takashi Iwai3de95172012-05-07 18:03:15 +02006692 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006693
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006694 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6695 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006696
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006697 /* automatic parse from the BIOS config */
6698 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006699 if (err < 0)
6700 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006701
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006702 if (!spec->no_analog) {
6703 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006704 if (err < 0)
6705 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006706 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6707 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006708
Takashi Iwai1d045db2011-07-07 18:23:21 +02006709 codec->patch_ops = alc_patch_ops;
6710
Takashi Iwai1d045db2011-07-07 18:23:21 +02006711 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006712
Takashi Iwai589876e2012-02-20 15:47:55 +01006713 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6714
Takashi Iwai1d045db2011-07-07 18:23:21 +02006715 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006716
6717 error:
6718 alc_free(codec);
6719 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006720}
6721
6722/*
6723 * ALC662 support
6724 *
6725 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6726 * configuration. Each pin widget can choose any input DACs and a mixer.
6727 * Each ADC is connected from a mixer of all inputs. This makes possible
6728 * 6-channel independent captures.
6729 *
6730 * In addition, an independent DAC for the multi-playback (not used in this
6731 * driver yet).
6732 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006733
6734/*
6735 * BIOS auto configuration
6736 */
6737
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006738static int alc662_parse_auto_config(struct hda_codec *codec)
6739{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006740 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006741 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6742 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6743 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006744
Kailang Yang6227cdc2010-02-25 08:36:52 +01006745 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6746 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006747 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006748 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006749 ssids = alc662_ssids;
6750 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006751}
6752
Todd Broch6be79482010-12-07 16:51:05 -08006753static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006754 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006755{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006756 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006757 return;
Todd Broch6be79482010-12-07 16:51:05 -08006758 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6759 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6760 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6761 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6762 (0 << AC_AMPCAP_MUTE_SHIFT)))
6763 printk(KERN_WARNING
6764 "hda_codec: failed to override amp caps for NID 0x2\n");
6765}
6766
David Henningsson6cb3b702010-09-09 08:51:44 +02006767enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006768 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006769 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006770 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006771 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006772 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006773 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006774 ALC662_FIXUP_ASUS_MODE1,
6775 ALC662_FIXUP_ASUS_MODE2,
6776 ALC662_FIXUP_ASUS_MODE3,
6777 ALC662_FIXUP_ASUS_MODE4,
6778 ALC662_FIXUP_ASUS_MODE5,
6779 ALC662_FIXUP_ASUS_MODE6,
6780 ALC662_FIXUP_ASUS_MODE7,
6781 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006782 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006783 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006784 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006785};
6786
6787static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006788 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006789 .type = ALC_FIXUP_PINS,
6790 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006791 { 0x15, 0x99130112 }, /* subwoofer */
6792 { }
6793 }
6794 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006795 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006796 .type = ALC_FIXUP_PINS,
6797 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006798 { 0x17, 0x99130112 }, /* subwoofer */
6799 { }
6800 }
6801 },
Todd Broch6be79482010-12-07 16:51:05 -08006802 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006803 .type = ALC_FIXUP_FUNC,
6804 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006805 },
6806 [ALC662_FIXUP_CZC_P10T] = {
6807 .type = ALC_FIXUP_VERBS,
6808 .v.verbs = (const struct hda_verb[]) {
6809 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6810 {}
6811 }
6812 },
David Henningsson94024cd2011-04-29 14:10:55 +02006813 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006814 .type = ALC_FIXUP_FUNC,
6815 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006816 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006817 [ALC662_FIXUP_HP_RP5800] = {
6818 .type = ALC_FIXUP_PINS,
6819 .v.pins = (const struct alc_pincfg[]) {
6820 { 0x14, 0x0221201f }, /* HP out */
6821 { }
6822 },
6823 .chained = true,
6824 .chain_id = ALC662_FIXUP_SKU_IGNORE
6825 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006826 [ALC662_FIXUP_ASUS_MODE1] = {
6827 .type = ALC_FIXUP_PINS,
6828 .v.pins = (const struct alc_pincfg[]) {
6829 { 0x14, 0x99130110 }, /* speaker */
6830 { 0x18, 0x01a19c20 }, /* mic */
6831 { 0x19, 0x99a3092f }, /* int-mic */
6832 { 0x21, 0x0121401f }, /* HP out */
6833 { }
6834 },
6835 .chained = true,
6836 .chain_id = ALC662_FIXUP_SKU_IGNORE
6837 },
6838 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006839 .type = ALC_FIXUP_PINS,
6840 .v.pins = (const struct alc_pincfg[]) {
6841 { 0x14, 0x99130110 }, /* speaker */
6842 { 0x18, 0x01a19820 }, /* mic */
6843 { 0x19, 0x99a3092f }, /* int-mic */
6844 { 0x1b, 0x0121401f }, /* HP out */
6845 { }
6846 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006847 .chained = true,
6848 .chain_id = ALC662_FIXUP_SKU_IGNORE
6849 },
6850 [ALC662_FIXUP_ASUS_MODE3] = {
6851 .type = ALC_FIXUP_PINS,
6852 .v.pins = (const struct alc_pincfg[]) {
6853 { 0x14, 0x99130110 }, /* speaker */
6854 { 0x15, 0x0121441f }, /* HP */
6855 { 0x18, 0x01a19840 }, /* mic */
6856 { 0x19, 0x99a3094f }, /* int-mic */
6857 { 0x21, 0x01211420 }, /* HP2 */
6858 { }
6859 },
6860 .chained = true,
6861 .chain_id = ALC662_FIXUP_SKU_IGNORE
6862 },
6863 [ALC662_FIXUP_ASUS_MODE4] = {
6864 .type = ALC_FIXUP_PINS,
6865 .v.pins = (const struct alc_pincfg[]) {
6866 { 0x14, 0x99130110 }, /* speaker */
6867 { 0x16, 0x99130111 }, /* speaker */
6868 { 0x18, 0x01a19840 }, /* mic */
6869 { 0x19, 0x99a3094f }, /* int-mic */
6870 { 0x21, 0x0121441f }, /* HP */
6871 { }
6872 },
6873 .chained = true,
6874 .chain_id = ALC662_FIXUP_SKU_IGNORE
6875 },
6876 [ALC662_FIXUP_ASUS_MODE5] = {
6877 .type = ALC_FIXUP_PINS,
6878 .v.pins = (const struct alc_pincfg[]) {
6879 { 0x14, 0x99130110 }, /* speaker */
6880 { 0x15, 0x0121441f }, /* HP */
6881 { 0x16, 0x99130111 }, /* speaker */
6882 { 0x18, 0x01a19840 }, /* mic */
6883 { 0x19, 0x99a3094f }, /* int-mic */
6884 { }
6885 },
6886 .chained = true,
6887 .chain_id = ALC662_FIXUP_SKU_IGNORE
6888 },
6889 [ALC662_FIXUP_ASUS_MODE6] = {
6890 .type = ALC_FIXUP_PINS,
6891 .v.pins = (const struct alc_pincfg[]) {
6892 { 0x14, 0x99130110 }, /* speaker */
6893 { 0x15, 0x01211420 }, /* HP2 */
6894 { 0x18, 0x01a19840 }, /* mic */
6895 { 0x19, 0x99a3094f }, /* int-mic */
6896 { 0x1b, 0x0121441f }, /* HP */
6897 { }
6898 },
6899 .chained = true,
6900 .chain_id = ALC662_FIXUP_SKU_IGNORE
6901 },
6902 [ALC662_FIXUP_ASUS_MODE7] = {
6903 .type = ALC_FIXUP_PINS,
6904 .v.pins = (const struct alc_pincfg[]) {
6905 { 0x14, 0x99130110 }, /* speaker */
6906 { 0x17, 0x99130111 }, /* speaker */
6907 { 0x18, 0x01a19840 }, /* mic */
6908 { 0x19, 0x99a3094f }, /* int-mic */
6909 { 0x1b, 0x01214020 }, /* HP */
6910 { 0x21, 0x0121401f }, /* HP */
6911 { }
6912 },
6913 .chained = true,
6914 .chain_id = ALC662_FIXUP_SKU_IGNORE
6915 },
6916 [ALC662_FIXUP_ASUS_MODE8] = {
6917 .type = ALC_FIXUP_PINS,
6918 .v.pins = (const struct alc_pincfg[]) {
6919 { 0x14, 0x99130110 }, /* speaker */
6920 { 0x12, 0x99a30970 }, /* int-mic */
6921 { 0x15, 0x01214020 }, /* HP */
6922 { 0x17, 0x99130111 }, /* speaker */
6923 { 0x18, 0x01a19840 }, /* mic */
6924 { 0x21, 0x0121401f }, /* HP */
6925 { }
6926 },
6927 .chained = true,
6928 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006929 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006930 [ALC662_FIXUP_NO_JACK_DETECT] = {
6931 .type = ALC_FIXUP_FUNC,
6932 .v.func = alc_fixup_no_jack_detect,
6933 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006934 [ALC662_FIXUP_ZOTAC_Z68] = {
6935 .type = ALC_FIXUP_PINS,
6936 .v.pins = (const struct alc_pincfg[]) {
6937 { 0x1b, 0x02214020 }, /* Front HP */
6938 { }
6939 }
6940 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006941 [ALC662_FIXUP_INV_DMIC] = {
6942 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006943 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006944 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006945};
6946
Takashi Iwaia9111322011-05-02 11:30:18 +02006947static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006948 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006949 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006950 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006951 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006952 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006953 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006954 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006955 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006956 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006957 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006958 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006959 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006960 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006961
6962#if 0
6963 /* Below is a quirk table taken from the old code.
6964 * Basically the device should work as is without the fixup table.
6965 * If BIOS doesn't give a proper info, enable the corresponding
6966 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006967 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006968 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6969 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6970 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6971 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6972 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6973 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6974 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6975 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6976 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6977 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6978 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6979 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6980 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6981 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6982 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6983 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6984 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6985 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6986 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6987 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6988 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6989 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6990 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6991 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6992 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6993 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6994 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6995 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6996 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6997 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6998 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6999 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7000 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7001 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7002 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7003 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7004 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7005 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7006 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7007 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7008 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7009 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7010 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7011 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7012 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7013 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7014 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7015 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7016 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7017 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7018#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007019 {}
7020};
7021
Todd Broch6be79482010-12-07 16:51:05 -08007022static const struct alc_model_fixup alc662_fixup_models[] = {
7023 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007024 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7025 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7026 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7027 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7028 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7029 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7030 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7031 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007032 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007033 {}
7034};
David Henningsson6cb3b702010-09-09 08:51:44 +02007035
Kailang Yang8663ff72012-06-29 09:35:52 +02007036static void alc662_fill_coef(struct hda_codec *codec)
7037{
7038 int val, coef;
7039
7040 coef = alc_get_coef0(codec);
7041
7042 switch (codec->vendor_id) {
7043 case 0x10ec0662:
7044 if ((coef & 0x00f0) == 0x0030) {
7045 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7046 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7047 }
7048 break;
7049 case 0x10ec0272:
7050 case 0x10ec0273:
7051 case 0x10ec0663:
7052 case 0x10ec0665:
7053 case 0x10ec0670:
7054 case 0x10ec0671:
7055 case 0x10ec0672:
7056 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7057 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7058 break;
7059 }
7060}
David Henningsson6cb3b702010-09-09 08:51:44 +02007061
Takashi Iwai1d045db2011-07-07 18:23:21 +02007062/*
7063 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007064static int patch_alc662(struct hda_codec *codec)
7065{
7066 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007067 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007068
Takashi Iwai3de95172012-05-07 18:03:15 +02007069 err = alc_alloc_spec(codec, 0x0b);
7070 if (err < 0)
7071 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007072
Takashi Iwai3de95172012-05-07 18:03:15 +02007073 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007074
Takashi Iwai53c334a2011-08-23 18:27:14 +02007075 /* handle multiple HPs as is */
7076 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7077
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007078 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7079
Kailang Yang8663ff72012-06-29 09:35:52 +02007080 spec->init_hook = alc662_fill_coef;
7081 alc662_fill_coef(codec);
7082
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007083 alc_pick_fixup(codec, alc662_fixup_models,
7084 alc662_fixup_tbl, alc662_fixups);
7085 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7086
7087 alc_auto_parse_customize_define(codec);
7088
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007089 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007090 codec->bus->pci->subsystem_vendor == 0x1025 &&
7091 spec->cdefine.platform_type == 1) {
7092 if (alc_codec_rename(codec, "ALC272X") < 0)
7093 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007094 }
Kailang Yang274693f2009-12-03 10:07:50 +01007095
Takashi Iwaib9c51062011-08-24 18:08:07 +02007096 /* automatic parse from the BIOS config */
7097 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007098 if (err < 0)
7099 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007100
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007101 if (!spec->no_analog && has_cdefine_beep(codec)) {
7102 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007103 if (err < 0)
7104 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007105 switch (codec->vendor_id) {
7106 case 0x10ec0662:
7107 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7108 break;
7109 case 0x10ec0272:
7110 case 0x10ec0663:
7111 case 0x10ec0665:
7112 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7113 break;
7114 case 0x10ec0273:
7115 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7116 break;
7117 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007118 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007119
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007120 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007121 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007122
Takashi Iwai589876e2012-02-20 15:47:55 +01007123 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7124
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007125 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007126
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007127 error:
7128 alc_free(codec);
7129 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007130}
7131
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007132/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007133 * ALC680 support
7134 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007135
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007136static int alc680_parse_auto_config(struct hda_codec *codec)
7137{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007138 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007139}
7140
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007141/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007142 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007143static int patch_alc680(struct hda_codec *codec)
7144{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007145 int err;
7146
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007147 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007148 err = alc_alloc_spec(codec, 0);
7149 if (err < 0)
7150 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007151
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007152 /* automatic parse from the BIOS config */
7153 err = alc680_parse_auto_config(codec);
7154 if (err < 0) {
7155 alc_free(codec);
7156 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007157 }
7158
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007159 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007160
7161 return 0;
7162}
7163
7164/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007165 * patch entries
7166 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007167static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007168 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007169 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007170 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007171 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007172 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007173 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007174 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007175 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007176 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007177 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007178 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007179 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007180 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007181 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007182 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007183 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007184 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007185 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007186 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7187 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7188 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007189 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007190 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007191 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7192 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007193 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7194 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007195 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007196 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007197 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007198 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007199 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007200 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007201 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007202 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007203 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007204 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007205 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007206 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007207 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007208 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007209 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007210 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007211 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007212 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007213 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007214 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007215 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007216 {} /* terminator */
7217};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007218
7219MODULE_ALIAS("snd-hda-codec-id:10ec*");
7220
7221MODULE_LICENSE("GPL");
7222MODULE_DESCRIPTION("Realtek HD-audio codec");
7223
7224static struct hda_codec_preset_list realtek_list = {
7225 .preset = snd_hda_preset_realtek,
7226 .owner = THIS_MODULE,
7227};
7228
7229static int __init patch_realtek_init(void)
7230{
7231 return snd_hda_add_codec_preset(&realtek_list);
7232}
7233
7234static void __exit patch_realtek_exit(void)
7235{
7236 snd_hda_delete_codec_preset(&realtek_list);
7237}
7238
7239module_init(patch_realtek_init)
7240module_exit(patch_realtek_exit)