blob: d9c3b4af41d44be4df7018443a2e42c7eb668f90 [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 Iwai834be882006-03-01 14:16:17 +0100190
Takashi Iwai463419d2012-12-05 14:17:37 +0100191 /* DAC list */
192 int num_all_dacs;
193 hda_nid_t all_dacs[16];
194
Takashi Iwaic9967f12012-12-14 16:39:22 +0100195 /* path list */
196 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100197
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100198 /* hooks */
199 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200200#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500201 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100202#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200203 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200204 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100205
Takashi Iwai834be882006-03-01 14:16:17 +0100206 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200207 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200208 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200209 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200210 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200211 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
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 */
346 if (val == AC_PINCTL_VREF_HIZ) {
347 const hda_nid_t vref_pin = 0x18;
348 /* Sanity check pin 0x18 */
349 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
350 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
351 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
352 if (vref_val != AC_PINCTL_VREF_HIZ)
353 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
354 }
355 }
356
357 val = set_as_mic ? val | PIN_IN : PIN_HP;
358 snd_hda_set_pin_ctl(codec, pin, val);
359
360 spec->automute_speaker = !set_as_mic;
361 call_update_outputs(codec);
362}
Takashi Iwai21268962011-07-07 15:01:13 +0200363
364/* select the given imux item; either unmute exclusively or select the route */
365static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
366 unsigned int idx, bool force)
367{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100369 const struct hda_input_mux *imux;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100370 struct nid_path *path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Takashi Iwai27d31532012-12-18 08:57:05 +0100372 imux = &spec->input_mux;
373 if (!imux->num_items)
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100374 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100375
Takashi Iwai21268962011-07-07 15:01:13 +0200376 if (idx >= imux->num_items)
377 idx = imux->num_items - 1;
378 if (spec->cur_mux[adc_idx] == idx && !force)
379 return 0;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100380
381 path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]],
382 spec->adc_nids[adc_idx]);
383 if (!path)
384 return 0;
385 if (path->active)
386 activate_path(codec, path, false, false);
387
Takashi Iwai21268962011-07-07 15:01:13 +0200388 spec->cur_mux[adc_idx] = idx;
389
David Henningsson00227f12012-06-27 18:45:44 +0200390 if (spec->shared_mic_hp)
391 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100392
Takashi Iwai666a70d2012-12-17 20:29:29 +0100393 if (spec->dyn_adc_switch)
Takashi Iwai21268962011-07-07 15:01:13 +0200394 alc_dyn_adc_pcm_resetup(codec, idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200395
Takashi Iwai666a70d2012-12-17 20:29:29 +0100396 path = get_nid_path(codec, spec->imux_pins[idx],
397 get_adc_nid(codec, adc_idx, idx));
398 if (!path)
399 return 0;
400 if (path->active)
401 return 0;
402 activate_path(codec, path, true, false);
Takashi Iwai125821a2012-06-22 14:30:29 +0200403 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200404 return 1;
405}
406
407static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
408 struct snd_ctl_elem_value *ucontrol)
409{
410 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
411 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412 return alc_mux_select(codec, adc_idx,
413 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100414}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100417 * set up the input pin config (depending on the given auto-pin type)
418 */
419static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
420 int auto_pin_type)
421{
422 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200423 if (auto_pin_type == AUTO_PIN_MIC)
424 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200425 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100426}
427
428/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200429 * Append the given mixer and verb elements for the later use
430 * The mixer array is referred in build_controls(), and init_verbs are
431 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100432 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200433static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100434{
435 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
436 return;
437 spec->mixers[spec->num_mixers++] = mix;
438}
439
Takashi Iwaid88897e2008-10-31 15:01:37 +0100440/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200441 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100442 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200443/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200444static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200445 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
446 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
447 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
448 { }
449};
450
Takashi Iwaia9111322011-05-02 11:30:18 +0200451static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200452 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
453 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
454 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
455 { }
456};
457
Takashi Iwaia9111322011-05-02 11:30:18 +0200458static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200459 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
460 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
461 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
462 { }
463};
464
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200465/*
466 * Fix hardware PLL issue
467 * On some codecs, the analog PLL gating control must be off while
468 * the default value is 1.
469 */
470static void alc_fix_pll(struct hda_codec *codec)
471{
472 struct alc_spec *spec = codec->spec;
473 unsigned int val;
474
475 if (!spec->pll_nid)
476 return;
477 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
478 spec->pll_coef_idx);
479 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
480 AC_VERB_GET_PROC_COEF, 0);
481 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
482 spec->pll_coef_idx);
483 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
484 val & ~(1 << spec->pll_coef_bit));
485}
486
487static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
488 unsigned int coef_idx, unsigned int coef_bit)
489{
490 struct alc_spec *spec = codec->spec;
491 spec->pll_nid = nid;
492 spec->pll_coef_idx = coef_idx;
493 spec->pll_coef_bit = coef_bit;
494 alc_fix_pll(codec);
495}
496
Takashi Iwai1d045db2011-07-07 18:23:21 +0200497/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200498 * Jack detections for HP auto-mute and mic-switch
499 */
500
501/* check each pin in the given array; returns true if any of them is plugged */
502static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200503{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200504 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200505
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200506 for (i = 0; i < num_pins; i++) {
507 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200508 if (!nid)
509 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200510 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200511 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200512 return present;
513}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200514
Takashi Iwai1d045db2011-07-07 18:23:21 +0200515/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200516static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200517 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200518{
519 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200520 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200521 int i;
522
523 for (i = 0; i < num_pins; i++) {
524 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100525 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200526 if (!nid)
527 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100528 /* don't reset VREF value in case it's controlling
529 * the amp (see alc861_fixup_asus_amp_vref_0f())
530 */
531 if (spec->keep_vref_in_automute) {
532 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100533 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100534 val &= ~PIN_HP;
535 } else
536 val = 0;
537 val |= pin_bits;
538 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200539 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200540}
541
David Henningsson42cf0d02011-09-20 12:04:56 +0200542/* Toggle outputs muting */
543static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200544{
545 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200546 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200547
Takashi Iwaic0a20262011-06-10 15:28:15 +0200548 /* Control HP pins/amps depending on master_mute state;
549 * in general, HP pins/amps control should be enabled in all cases,
550 * but currently set only for master_mute, just to be safe
551 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100552 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
553 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200554 spec->autocfg.hp_pins, spec->master_mute, true);
555
David Henningsson42cf0d02011-09-20 12:04:56 +0200556 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200557 on = 0;
558 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200559 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200562 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200563
564 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 /* if LO is a copy of either HP or Speaker, don't need to handle it */
566 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
567 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200568 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200569 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 on = 0;
571 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200572 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200573 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200574 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200575 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200576}
577
David Henningsson42cf0d02011-09-20 12:04:56 +0200578static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200579{
580 struct alc_spec *spec = codec->spec;
581 if (spec->automute_hook)
582 spec->automute_hook(codec);
583 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200584 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200585}
586
Takashi Iwai1d045db2011-07-07 18:23:21 +0200587/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200588static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200589{
590 struct alc_spec *spec = codec->spec;
591
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200593 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
594 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200595 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200596 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200597 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200598}
599
Takashi Iwai1d045db2011-07-07 18:23:21 +0200600/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200601static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602{
603 struct alc_spec *spec = codec->spec;
604
David Henningssonf7f4b2322012-10-10 16:32:09 +0200605 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
606 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200607 /* check LO jack only when it's different from HP */
608 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
609 return;
610
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200611 spec->line_jack_present =
612 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
613 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200614 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200615 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200616 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200617}
618
Takashi Iwai8d087c72011-06-28 12:45:47 +0200619#define get_connection_index(codec, mux, nid) \
620 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200621
Takashi Iwai1d045db2011-07-07 18:23:21 +0200622/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200623static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200624{
625 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200626 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200627
Takashi Iwai21268962011-07-07 15:01:13 +0200628 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200629 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200630 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200631 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200632
Takashi Iwai21268962011-07-07 15:01:13 +0200633 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
634 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
635 else if (spec->dock_mic_idx >= 0 &&
636 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
637 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
638 else
639 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200640}
641
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100642/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200643static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100644{
645 unsigned int val;
646 struct snd_kcontrol *kctl;
647 struct snd_ctl_elem_value *uctl;
648
649 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
650 if (!kctl)
651 return;
652 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
653 if (!uctl)
654 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200655 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100656 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
657 val &= HDA_AMP_VOLMASK;
658 uctl->value.integer.value[0] = val;
659 uctl->value.integer.value[1] = val;
660 kctl->put(kctl, uctl);
661 kfree(uctl);
662}
663
David Henningsson29adc4b2012-09-25 11:31:00 +0200664static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100665{
David Henningsson29adc4b2012-09-25 11:31:00 +0200666 /* For some reason, the res given from ALC880 is broken.
667 Here we adjust it properly. */
668 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100669}
670
Takashi Iwai1d045db2011-07-07 18:23:21 +0200671/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200672static void alc_inithook(struct hda_codec *codec)
673{
David Henningsson29adc4b2012-09-25 11:31:00 +0200674 alc_hp_automute(codec, NULL);
675 alc_line_automute(codec, NULL);
676 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200677}
678
Kailang Yangf9423e72008-05-27 12:32:25 +0200679/* additional initialization for ALC888 variants */
680static void alc888_coef_init(struct hda_codec *codec)
681{
682 unsigned int tmp;
683
684 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
685 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
686 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100687 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200688 /* alc888S-VC */
689 snd_hda_codec_read(codec, 0x20, 0,
690 AC_VERB_SET_PROC_COEF, 0x830);
691 else
692 /* alc888-VB */
693 snd_hda_codec_read(codec, 0x20, 0,
694 AC_VERB_SET_PROC_COEF, 0x3030);
695}
696
Takashi Iwai1d045db2011-07-07 18:23:21 +0200697/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200698static void alc889_coef_init(struct hda_codec *codec)
699{
700 unsigned int tmp;
701
702 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
703 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
704 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
705 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
706}
707
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100708/* turn on/off EAPD control (only if available) */
709static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
710{
711 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
712 return;
713 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
714 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
715 on ? 2 : 0);
716}
717
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200718/* turn on/off EAPD controls of the codec */
719static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
720{
721 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200722 static hda_nid_t pins[] = {
723 0x0f, 0x10, 0x14, 0x15, 0
724 };
725 hda_nid_t *p;
726 for (p = pins; *p; p++)
727 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200728}
729
Takashi Iwai1c716152011-04-07 10:37:16 +0200730/* generic shutup callback;
731 * just turning off EPAD and a little pause for avoiding pop-noise
732 */
733static void alc_eapd_shutup(struct hda_codec *codec)
734{
735 alc_auto_setup_eapd(codec, false);
736 msleep(200);
737}
738
Takashi Iwai1d045db2011-07-07 18:23:21 +0200739/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200740static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200741{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200742 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200743
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200744 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200745 switch (type) {
746 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200747 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
748 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200749 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200750 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
751 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200752 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200753 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
754 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200755 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200756 switch (codec->vendor_id) {
757 case 0x10ec0260:
758 snd_hda_codec_write(codec, 0x1a, 0,
759 AC_VERB_SET_COEF_INDEX, 7);
760 tmp = snd_hda_codec_read(codec, 0x1a, 0,
761 AC_VERB_GET_PROC_COEF, 0);
762 snd_hda_codec_write(codec, 0x1a, 0,
763 AC_VERB_SET_COEF_INDEX, 7);
764 snd_hda_codec_write(codec, 0x1a, 0,
765 AC_VERB_SET_PROC_COEF,
766 tmp | 0x2010);
767 break;
768 case 0x10ec0262:
769 case 0x10ec0880:
770 case 0x10ec0882:
771 case 0x10ec0883:
772 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100773 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100774 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200775 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200776 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200777 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200778 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200779 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100780#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200781 case 0x10ec0267:
782 case 0x10ec0268:
783 snd_hda_codec_write(codec, 0x20, 0,
784 AC_VERB_SET_COEF_INDEX, 7);
785 tmp = snd_hda_codec_read(codec, 0x20, 0,
786 AC_VERB_GET_PROC_COEF, 0);
787 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200788 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200789 snd_hda_codec_write(codec, 0x20, 0,
790 AC_VERB_SET_PROC_COEF,
791 tmp | 0x3000);
792 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100793#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200794 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200795 break;
796 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200797}
Kailang Yangea1fb292008-08-26 12:58:38 +0200798
Takashi Iwai1d045db2011-07-07 18:23:21 +0200799/*
800 * Auto-Mute mode mixer enum support
801 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200802static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
803 struct snd_ctl_elem_info *uinfo)
804{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200805 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
806 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200807 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100808 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200809 };
810
Takashi Iwaidda415d2012-11-30 18:34:38 +0100811 if (spec->automute_speaker_possible && spec->automute_lo_possible)
812 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
813 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200814}
815
816static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
817 struct snd_ctl_elem_value *ucontrol)
818{
819 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
820 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200821 unsigned int val = 0;
822 if (spec->automute_speaker)
823 val++;
824 if (spec->automute_lo)
825 val++;
826
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200827 ucontrol->value.enumerated.item[0] = val;
828 return 0;
829}
830
831static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
832 struct snd_ctl_elem_value *ucontrol)
833{
834 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
835 struct alc_spec *spec = codec->spec;
836
837 switch (ucontrol->value.enumerated.item[0]) {
838 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200839 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200840 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200841 spec->automute_speaker = 0;
842 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200843 break;
844 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200845 if (spec->automute_speaker_possible) {
846 if (!spec->automute_lo && spec->automute_speaker)
847 return 0;
848 spec->automute_speaker = 1;
849 spec->automute_lo = 0;
850 } else if (spec->automute_lo_possible) {
851 if (spec->automute_lo)
852 return 0;
853 spec->automute_lo = 1;
854 } else
855 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200856 break;
857 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200858 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200859 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200860 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200861 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200862 spec->automute_speaker = 1;
863 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200864 break;
865 default:
866 return -EINVAL;
867 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200868 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200869 return 1;
870}
871
Takashi Iwaia9111322011-05-02 11:30:18 +0200872static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200873 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
874 .name = "Auto-Mute Mode",
875 .info = alc_automute_mode_info,
876 .get = alc_automute_mode_get,
877 .put = alc_automute_mode_put,
878};
879
Takashi Iwai668d1e92012-11-29 14:10:17 +0100880static struct snd_kcontrol_new *
881alc_kcontrol_new(struct alc_spec *spec, const char *name,
882 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200883{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100884 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
885 if (!knew)
886 return NULL;
887 *knew = *temp;
888 knew->name = kstrdup(name, GFP_KERNEL);
889 if (!knew->name)
890 return NULL;
891 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200892}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200893
894static int alc_add_automute_mode_enum(struct hda_codec *codec)
895{
896 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200897
Takashi Iwai668d1e92012-11-29 14:10:17 +0100898 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899 return -ENOMEM;
900 return 0;
901}
902
Takashi Iwai1d045db2011-07-07 18:23:21 +0200903/*
904 * Check the availability of HP/line-out auto-mute;
905 * Set up appropriately if really supported
906 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100907static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200908{
909 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200910 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200911 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100912 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200913
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200914 if (cfg->hp_pins[0])
915 present++;
916 if (cfg->line_out_pins[0])
917 present++;
918 if (cfg->speaker_pins[0])
919 present++;
920 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100921 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200922
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200923 if (!cfg->speaker_pins[0] &&
924 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200925 memcpy(cfg->speaker_pins, cfg->line_out_pins,
926 sizeof(cfg->speaker_pins));
927 cfg->speaker_outs = cfg->line_outs;
928 }
929
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200930 if (!cfg->hp_pins[0] &&
931 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200932 memcpy(cfg->hp_pins, cfg->line_out_pins,
933 sizeof(cfg->hp_pins));
934 cfg->hp_outs = cfg->line_outs;
935 }
936
937 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200938 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200939 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200940 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200941 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200942 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200943 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
944 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200945 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200946 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200947
David Henningsson42cf0d02011-09-20 12:04:56 +0200948 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
949 if (cfg->speaker_outs)
950 for (i = 0; i < cfg->line_outs; i++) {
951 hda_nid_t nid = cfg->line_out_pins[i];
952 if (!is_jack_detectable(codec, nid))
953 continue;
954 snd_printdd("realtek: Enable Line-Out "
955 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200956 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
957 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200958 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200959 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200960 spec->automute_lo_possible = spec->detect_hp;
961 }
962
963 spec->automute_speaker_possible = cfg->speaker_outs &&
964 (spec->detect_hp || spec->detect_lo);
965
966 spec->automute_lo = spec->automute_lo_possible;
967 spec->automute_speaker = spec->automute_speaker_possible;
968
Takashi Iwai475c3d22012-11-30 08:31:30 +0100969 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200970 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100971 err = alc_add_automute_mode_enum(codec);
972 if (err < 0)
973 return err;
974 }
975 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200976}
977
Takashi Iwai1d045db2011-07-07 18:23:21 +0200978/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200979static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
980{
981 int i;
982 for (i = 0; i < nums; i++)
983 if (list[i] == nid)
984 return i;
985 return -1;
986}
987
Takashi Iwai21268962011-07-07 15:01:13 +0200988/* check whether all auto-mic pins are valid; setup indices if OK */
989static bool alc_auto_mic_check_imux(struct hda_codec *codec)
990{
991 struct alc_spec *spec = codec->spec;
992 const struct hda_input_mux *imux;
993
Takashi Iwai27d31532012-12-18 08:57:05 +0100994 imux = &spec->input_mux;
Takashi Iwai21268962011-07-07 15:01:13 +0200995 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
996 spec->imux_pins, imux->num_items);
997 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
998 spec->imux_pins, imux->num_items);
999 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1000 spec->imux_pins, imux->num_items);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001001 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0)
Takashi Iwai21268962011-07-07 15:01:13 +02001002 return false; /* no corresponding imux */
Takashi Iwai21268962011-07-07 15:01:13 +02001003
David Henningsson29adc4b2012-09-25 11:31:00 +02001004 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1005 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001006 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001007 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1008 ALC_MIC_EVENT,
1009 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001010
1011 spec->auto_mic_valid_imux = 1;
Takashi Iwai21268962011-07-07 15:01:13 +02001012 return true;
1013}
1014
Takashi Iwai1d045db2011-07-07 18:23:21 +02001015/*
1016 * Check the availability of auto-mic switch;
1017 * Set up if really supported
1018 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001019static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001020{
1021 struct alc_spec *spec = codec->spec;
1022 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001023 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001024 int i;
1025
Takashi Iwai21268962011-07-07 15:01:13 +02001026 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1027
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001028 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001029 for (i = 0; i < cfg->num_inputs; i++) {
1030 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001031 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001032 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001033 switch (snd_hda_get_input_pin_attr(defcfg)) {
1034 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001035 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001036 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001037 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001038 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001039 fixed = nid;
1040 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001041 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001042 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001043 case INPUT_PIN_ATTR_DOCK:
1044 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001045 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001046 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001047 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001048 dock = nid;
1049 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001050 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001051 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001052 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001053 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001054 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001055 ext = nid;
1056 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001057 }
1058 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001059 if (!ext && dock) {
1060 ext = dock;
1061 dock = 0;
1062 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001063 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001064 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001065 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001066 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001067 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001068 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001069
1070 /* check imux indices */
1071 spec->ext_mic_pin = ext;
1072 spec->int_mic_pin = fixed;
1073 spec->dock_mic_pin = dock;
1074
Takashi Iwai21268962011-07-07 15:01:13 +02001075 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001076 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001077
Takashi Iwai666a70d2012-12-17 20:29:29 +01001078 spec->auto_mic = 1;
1079 spec->num_adc_nids = 1;
1080 spec->cur_mux[0] = spec->int_mic_idx;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001081 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1082 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001083
1084 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001085}
1086
Takashi Iwai1d045db2011-07-07 18:23:21 +02001087/*
1088 * Realtek SSID verification
1089 */
1090
David Henningsson90622912010-10-14 14:50:18 +02001091/* Could be any non-zero and even value. When used as fixup, tells
1092 * the driver to ignore any present sku defines.
1093 */
1094#define ALC_FIXUP_SKU_IGNORE (2)
1095
Takashi Iwai23d30f22012-05-07 17:17:32 +02001096static void alc_fixup_sku_ignore(struct hda_codec *codec,
1097 const struct hda_fixup *fix, int action)
1098{
1099 struct alc_spec *spec = codec->spec;
1100 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1101 spec->cdefine.fixup = 1;
1102 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1103 }
1104}
1105
Kailang Yangda00c242010-03-19 11:23:45 +01001106static int alc_auto_parse_customize_define(struct hda_codec *codec)
1107{
1108 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001109 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001110 struct alc_spec *spec = codec->spec;
1111
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001112 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1113
David Henningsson90622912010-10-14 14:50:18 +02001114 if (spec->cdefine.fixup) {
1115 ass = spec->cdefine.sku_cfg;
1116 if (ass == ALC_FIXUP_SKU_IGNORE)
1117 return -1;
1118 goto do_sku;
1119 }
1120
Kailang Yangda00c242010-03-19 11:23:45 +01001121 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001122 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001123 goto do_sku;
1124
1125 nid = 0x1d;
1126 if (codec->vendor_id == 0x10ec0260)
1127 nid = 0x17;
1128 ass = snd_hda_codec_get_pincfg(codec, nid);
1129
1130 if (!(ass & 1)) {
1131 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1132 codec->chip_name, ass);
1133 return -1;
1134 }
1135
1136 /* check sum */
1137 tmp = 0;
1138 for (i = 1; i < 16; i++) {
1139 if ((ass >> i) & 1)
1140 tmp++;
1141 }
1142 if (((ass >> 16) & 0xf) != tmp)
1143 return -1;
1144
1145 spec->cdefine.port_connectivity = ass >> 30;
1146 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1147 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1148 spec->cdefine.customization = ass >> 8;
1149do_sku:
1150 spec->cdefine.sku_cfg = ass;
1151 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1152 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1153 spec->cdefine.swap = (ass & 0x2) >> 1;
1154 spec->cdefine.override = ass & 0x1;
1155
1156 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1157 nid, spec->cdefine.sku_cfg);
1158 snd_printd("SKU: port_connectivity=0x%x\n",
1159 spec->cdefine.port_connectivity);
1160 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1161 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1162 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1163 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1164 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1165 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1166 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1167
1168 return 0;
1169}
1170
Takashi Iwai1d045db2011-07-07 18:23:21 +02001171/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001172static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1173{
Takashi Iwai21268962011-07-07 15:01:13 +02001174 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001175}
1176
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001177/* check subsystem ID and set up device-specific initialization;
1178 * return 1 if initialized, 0 if invalid SSID
1179 */
1180/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1181 * 31 ~ 16 : Manufacture ID
1182 * 15 ~ 8 : SKU ID
1183 * 7 ~ 0 : Assembly ID
1184 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1185 */
1186static int alc_subsystem_id(struct hda_codec *codec,
1187 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001188 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001189{
1190 unsigned int ass, tmp, i;
1191 unsigned nid;
1192 struct alc_spec *spec = codec->spec;
1193
David Henningsson90622912010-10-14 14:50:18 +02001194 if (spec->cdefine.fixup) {
1195 ass = spec->cdefine.sku_cfg;
1196 if (ass == ALC_FIXUP_SKU_IGNORE)
1197 return 0;
1198 goto do_sku;
1199 }
1200
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001201 ass = codec->subsystem_id & 0xffff;
1202 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1203 goto do_sku;
1204
1205 /* invalid SSID, check the special NID pin defcfg instead */
1206 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001207 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001208 * 29~21 : reserve
1209 * 20 : PCBEEP input
1210 * 19~16 : Check sum (15:1)
1211 * 15~1 : Custom
1212 * 0 : override
1213 */
1214 nid = 0x1d;
1215 if (codec->vendor_id == 0x10ec0260)
1216 nid = 0x17;
1217 ass = snd_hda_codec_get_pincfg(codec, nid);
1218 snd_printd("realtek: No valid SSID, "
1219 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001220 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001221 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001222 return 0;
1223 if ((ass >> 30) != 1) /* no physical connection */
1224 return 0;
1225
1226 /* check sum */
1227 tmp = 0;
1228 for (i = 1; i < 16; i++) {
1229 if ((ass >> i) & 1)
1230 tmp++;
1231 }
1232 if (((ass >> 16) & 0xf) != tmp)
1233 return 0;
1234do_sku:
1235 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1236 ass & 0xffff, codec->vendor_id);
1237 /*
1238 * 0 : override
1239 * 1 : Swap Jack
1240 * 2 : 0 --> Desktop, 1 --> Laptop
1241 * 3~5 : External Amplifier control
1242 * 7~6 : Reserved
1243 */
1244 tmp = (ass & 0x38) >> 3; /* external Amp control */
1245 switch (tmp) {
1246 case 1:
1247 spec->init_amp = ALC_INIT_GPIO1;
1248 break;
1249 case 3:
1250 spec->init_amp = ALC_INIT_GPIO2;
1251 break;
1252 case 7:
1253 spec->init_amp = ALC_INIT_GPIO3;
1254 break;
1255 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001256 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001257 spec->init_amp = ALC_INIT_DEFAULT;
1258 break;
1259 }
1260
1261 /* is laptop or Desktop and enable the function "Mute internal speaker
1262 * when the external headphone out jack is plugged"
1263 */
1264 if (!(ass & 0x8000))
1265 return 1;
1266 /*
1267 * 10~8 : Jack location
1268 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1269 * 14~13: Resvered
1270 * 15 : 1 --> enable the function "Mute internal speaker
1271 * when the external headphone out jack is plugged"
1272 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001273 if (!spec->autocfg.hp_pins[0] &&
1274 !(spec->autocfg.line_out_pins[0] &&
1275 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001276 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001277 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1278 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001279 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001280 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001281 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001282 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001283 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001284 else if (tmp == 3)
1285 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001286 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001287 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001288 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1289 spec->autocfg.line_outs))
1290 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001291 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001292 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001293 return 1;
1294}
Kailang Yangea1fb292008-08-26 12:58:38 +02001295
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001296/* Check the validity of ALC subsystem-id
1297 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1298static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001299{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001300 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001301 struct alc_spec *spec = codec->spec;
1302 snd_printd("realtek: "
1303 "Enable default setup for auto mode as fallback\n");
1304 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001305 }
Takashi Iwai21268962011-07-07 15:01:13 +02001306}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001307
Takashi Iwai41e41f12005-06-08 14:48:49 +02001308/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001309 * COEF access helper functions
1310 */
Kailang Yang274693f2009-12-03 10:07:50 +01001311static int alc_read_coef_idx(struct hda_codec *codec,
1312 unsigned int coef_idx)
1313{
1314 unsigned int val;
1315 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1316 coef_idx);
1317 val = snd_hda_codec_read(codec, 0x20, 0,
1318 AC_VERB_GET_PROC_COEF, 0);
1319 return val;
1320}
1321
Kailang Yang977ddd62010-09-15 10:02:29 +02001322static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1323 unsigned int coef_val)
1324{
1325 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1326 coef_idx);
1327 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1328 coef_val);
1329}
1330
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001331/* a special bypass for COEF 0; read the cached value at the second time */
1332static unsigned int alc_get_coef0(struct hda_codec *codec)
1333{
1334 struct alc_spec *spec = codec->spec;
1335 if (!spec->coef0)
1336 spec->coef0 = alc_read_coef_idx(codec, 0);
1337 return spec->coef0;
1338}
1339
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001340static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1341 hda_nid_t pin, int pin_type,
1342 hda_nid_t dac);
1343static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1344 bool is_digital);
Takashi Iwai965cceb2012-12-18 11:46:37 +01001345static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
1346 hda_nid_t to_nid, int with_aa_mix,
1347 struct nid_path *path);
1348static struct nid_path *add_new_nid_path(struct hda_codec *codec,
1349 hda_nid_t from_nid, hda_nid_t to_nid,
1350 int with_aa_mix);
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001351
Takashi Iwai1d045db2011-07-07 18:23:21 +02001352/*
1353 * Digital I/O handling
1354 */
1355
Takashi Iwai757899a2010-07-30 10:48:14 +02001356/* set right pin controls for digital I/O */
1357static void alc_auto_init_digital(struct hda_codec *codec)
1358{
1359 struct alc_spec *spec = codec->spec;
1360 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001361 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001362
1363 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1364 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001365 if (!pin)
1366 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001367 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001368 }
1369 pin = spec->autocfg.dig_in_pin;
1370 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001371 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001372}
1373
1374/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1375static void alc_auto_parse_digital(struct hda_codec *codec)
1376{
1377 struct alc_spec *spec = codec->spec;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001378 int i, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001379 hda_nid_t dig_nid;
1380
1381 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001382 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001383 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001384 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1385 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1386 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001387 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001388 if (!add_new_nid_path(codec, dig_nid, pin, 2))
1389 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001390 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001391 spec->multiout.dig_out_nid = dig_nid;
1392 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1393 } else {
1394 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001395 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001396 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001397 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001398 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001399 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001400 }
1401
1402 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001403 dig_nid = codec->start_nid;
1404 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1405 unsigned int wcaps = get_wcaps(codec, dig_nid);
1406 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1407 continue;
1408 if (!(wcaps & AC_WCAP_DIGITAL))
1409 continue;
1410 if (!(wcaps & AC_WCAP_CONN_LIST))
1411 continue;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001412 if (err >= 0) {
1413 spec->dig_in_nid = dig_nid;
1414 break;
1415 }
1416 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001417 }
1418}
1419
Takashi Iwaif95474e2007-07-10 00:47:43 +02001420/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001421 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001422 */
Takashi Iwai666a70d2012-12-17 20:29:29 +01001423#define alc_cap_vol_info snd_hda_mixer_amp_volume_info
1424#define alc_cap_vol_get snd_hda_mixer_amp_volume_get
1425#define alc_cap_vol_tlv snd_hda_mixer_amp_tlv
1426
1427typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
1428 struct snd_ctl_elem_value *ucontrol);
1429
1430static int alc_cap_put_caller(struct snd_kcontrol *kcontrol,
1431 struct snd_ctl_elem_value *ucontrol,
1432 put_call_t func, int type)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001433{
1434 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1435 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001436 const struct hda_input_mux *imux;
1437 struct nid_path *path;
1438 int i, adc_idx, err = 0;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001439
Takashi Iwai27d31532012-12-18 08:57:05 +01001440 imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001441 adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001442 mutex_lock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001443 codec->cached_write = 1;
1444 for (i = 0; i < imux->num_items; i++) {
1445 path = get_nid_path(codec, spec->imux_pins[i],
1446 get_adc_nid(codec, adc_idx, i));
1447 if (!path->ctls[type])
1448 continue;
1449 kcontrol->private_value = path->ctls[type];
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001450 err = func(kcontrol, ucontrol);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001451 if (err < 0)
1452 goto error;
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001453 }
1454 error:
Takashi Iwai666a70d2012-12-17 20:29:29 +01001455 codec->cached_write = 0;
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001456 mutex_unlock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001457 snd_hda_codec_resume_amp(codec);
1458 if (err >= 0 && type == NID_PATH_MUTE_CTL &&
1459 spec->inv_dmic_fixup && spec->inv_dmic_muted)
1460 alc_inv_dmic_sync_adc(codec, adc_idx);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001461 return err;
1462}
1463
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001464static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1465 struct snd_ctl_elem_value *ucontrol)
1466{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001467 return alc_cap_put_caller(kcontrol, ucontrol,
1468 snd_hda_mixer_amp_volume_put,
1469 NID_PATH_VOL_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001470}
1471
1472/* capture mixer elements */
1473#define alc_cap_sw_info snd_ctl_boolean_stereo_info
Takashi Iwai666a70d2012-12-17 20:29:29 +01001474#define alc_cap_sw_get snd_hda_mixer_amp_switch_get
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001475
1476static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1477 struct snd_ctl_elem_value *ucontrol)
1478{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001479 return alc_cap_put_caller(kcontrol, ucontrol,
1480 snd_hda_mixer_amp_switch_put,
1481 NID_PATH_MUTE_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001482}
1483
Takashi Iwai666a70d2012-12-17 20:29:29 +01001484static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1485{
1486 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01001487 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001488 struct nid_path *path;
1489 hda_nid_t nid;
1490 int i, dir, parm;
1491 unsigned int val;
1492
1493 for (i = 0; i < imux->num_items; i++) {
1494 if (spec->imux_pins[i] == spec->inv_dmic_pin)
1495 break;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001496 }
Takashi Iwai666a70d2012-12-17 20:29:29 +01001497 if (i >= imux->num_items)
1498 return;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001499
Takashi Iwai666a70d2012-12-17 20:29:29 +01001500 path = get_nid_path(codec, spec->inv_dmic_pin,
1501 get_adc_nid(codec, adc_idx, i));
1502 val = path->ctls[NID_PATH_MUTE_CTL];
1503 if (!val)
1504 return;
1505 nid = get_amp_nid_(val);
1506 dir = get_amp_direction_(val);
1507 parm = AC_AMP_SET_RIGHT |
1508 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001509
Takashi Iwai666a70d2012-12-17 20:29:29 +01001510 /* we care only right channel */
1511 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1512 if (val & 0x80) /* if already muted, we don't need to touch */
1513 return;
1514 val |= 0x80;
1515 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1516 parm | val);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001517}
1518
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001519/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001520 * Inverted digital-mic handling
1521 *
1522 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1523 * gives the additional mute only to the right channel of the digital mic
1524 * capture stream. This is a workaround for avoiding the almost silence
1525 * by summing the stereo stream from some (known to be ForteMedia)
1526 * digital mic unit.
1527 *
1528 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1529 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1530 * without caching so that the cache can still keep the original value.
1531 * The cached value is then restored when the flag is set off or any other
1532 * than d-mic is used as the current input source.
1533 */
1534static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1535{
1536 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001537 int src, nums;
Takashi Iwai125821a2012-06-22 14:30:29 +02001538
1539 if (!spec->inv_dmic_fixup)
1540 return;
1541 if (!spec->inv_dmic_muted && !force)
1542 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001543 nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids;
1544 for (src = 0; src < nums; src++) {
Takashi Iwai125821a2012-06-22 14:30:29 +02001545 bool dmic_fixup = false;
Takashi Iwai125821a2012-06-22 14:30:29 +02001546
1547 if (spec->inv_dmic_muted &&
1548 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1549 dmic_fixup = true;
1550 if (!dmic_fixup && !force)
1551 continue;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001552 alc_inv_dmic_sync_adc(codec, src);
Takashi Iwai125821a2012-06-22 14:30:29 +02001553 }
1554}
1555
1556static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1557 struct snd_ctl_elem_value *ucontrol)
1558{
1559 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1560 struct alc_spec *spec = codec->spec;
1561
1562 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1563 return 0;
1564}
1565
1566static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1567 struct snd_ctl_elem_value *ucontrol)
1568{
1569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1570 struct alc_spec *spec = codec->spec;
1571 unsigned int val = !ucontrol->value.integer.value[0];
1572
1573 if (val == spec->inv_dmic_muted)
1574 return 0;
1575 spec->inv_dmic_muted = val;
1576 alc_inv_dmic_sync(codec, true);
1577 return 0;
1578}
1579
1580static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1582 .info = snd_ctl_boolean_mono_info,
1583 .get = alc_inv_dmic_sw_get,
1584 .put = alc_inv_dmic_sw_put,
1585};
1586
1587static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1588{
1589 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001590
1591 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1592 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001593 return -ENOMEM;
1594 spec->inv_dmic_fixup = 1;
1595 spec->inv_dmic_muted = 0;
1596 spec->inv_dmic_pin = nid;
1597 return 0;
1598}
1599
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001600/* typically the digital mic is put at node 0x12 */
1601static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1602 const struct alc_fixup *fix, int action)
1603{
1604 if (action == ALC_FIXUP_ACT_PROBE)
1605 alc_add_inv_dmic_mixer(codec, 0x12);
1606}
1607
Takashi Iwai125821a2012-06-22 14:30:29 +02001608/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001609 * virtual master controls
1610 */
1611
1612/*
1613 * slave controls for virtual master
1614 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001615static const char * const alc_slave_pfxs[] = {
1616 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001617 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001618 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001619 NULL,
1620};
1621
1622/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001623 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001625
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001626#define NID_MAPPING (-1)
1627
Takashi Iwai603c4012008-07-30 15:01:44 +02001628static void alc_free_kctls(struct hda_codec *codec);
1629
Takashi Iwai67d634c2009-11-16 15:35:59 +01001630#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001631/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001632static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001633 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001634 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001635 { } /* end */
1636};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001637#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001638
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001639static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640{
1641 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001642 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
1644 for (i = 0; i < spec->num_mixers; i++) {
1645 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1646 if (err < 0)
1647 return err;
1648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001650 err = snd_hda_create_dig_out_ctls(codec,
1651 spec->multiout.dig_out_nid,
1652 spec->multiout.dig_out_nid,
1653 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 if (err < 0)
1655 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001656 if (!spec->no_analog) {
1657 err = snd_hda_create_spdif_share_sw(codec,
1658 &spec->multiout);
1659 if (err < 0)
1660 return err;
1661 spec->multiout.share_spdif = 1;
1662 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 }
1664 if (spec->dig_in_nid) {
1665 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1666 if (err < 0)
1667 return err;
1668 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001669
Takashi Iwai67d634c2009-11-16 15:35:59 +01001670#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001671 /* create beep controls if needed */
1672 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001673 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001674 for (knew = alc_beep_mixer; knew->name; knew++) {
1675 struct snd_kcontrol *kctl;
1676 kctl = snd_ctl_new1(knew, codec);
1677 if (!kctl)
1678 return -ENOMEM;
1679 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001680 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001681 if (err < 0)
1682 return err;
1683 }
1684 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001685#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001686
Takashi Iwai2134ea42008-01-10 16:53:55 +01001687 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001688 if (!spec->no_analog &&
1689 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001690 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001691 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001692 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001693 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001694 vmaster_tlv, alc_slave_pfxs,
1695 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001696 if (err < 0)
1697 return err;
1698 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001699 if (!spec->no_analog &&
1700 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001701 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1702 NULL, alc_slave_pfxs,
1703 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001704 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001705 if (err < 0)
1706 return err;
1707 }
1708
Takashi Iwaibae84e72010-03-22 08:30:20 +01001709 alc_free_kctls(codec); /* no longer needed */
1710
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001711 return 0;
1712}
1713
David Henningsson5780b622012-06-27 18:45:45 +02001714static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001715{
1716 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001717
1718 if (spec->shared_mic_hp) {
1719 int err;
1720 int nid = spec->autocfg.inputs[1].pin;
1721 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1722 if (err < 0)
1723 return err;
1724 err = snd_hda_jack_detect_enable(codec, nid, 0);
1725 if (err < 0)
1726 return err;
1727 }
1728
1729 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1730}
1731
1732static int alc_build_controls(struct hda_codec *codec)
1733{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001734 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001735 if (err < 0)
1736 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001737
1738 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001739 if (err < 0)
1740 return err;
1741 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1742 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743}
1744
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001747 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001748 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001749
Takashi Iwai070cff42012-02-21 12:54:17 +01001750static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001751
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752static int alc_init(struct hda_codec *codec)
1753{
1754 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001755
Takashi Iwai546bb672012-03-07 08:37:19 +01001756 if (spec->init_hook)
1757 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001758
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001759 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001760 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001761
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02001762 snd_hda_gen_apply_verbs(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001763 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001764
Takashi Iwai58701122011-01-13 15:41:45 +01001765 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1766
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001767 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 return 0;
1769}
1770
Takashi Iwai83012a72012-08-24 18:38:08 +02001771#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001772static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1773{
1774 struct alc_spec *spec = codec->spec;
1775 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1776}
1777#endif
1778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779/*
1780 * Analog playback callbacks
1781 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001782static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001784 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785{
1786 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001787 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1788 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789}
1790
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001791static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 struct hda_codec *codec,
1793 unsigned int stream_tag,
1794 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001795 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796{
1797 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001798 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1799 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800}
1801
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001802static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001804 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805{
1806 struct alc_spec *spec = codec->spec;
1807 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1808}
1809
1810/*
1811 * Digital out
1812 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001813static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001815 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816{
1817 struct alc_spec *spec = codec->spec;
1818 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1819}
1820
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001821static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001822 struct hda_codec *codec,
1823 unsigned int stream_tag,
1824 unsigned int format,
1825 struct snd_pcm_substream *substream)
1826{
1827 struct alc_spec *spec = codec->spec;
1828 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1829 stream_tag, format, substream);
1830}
1831
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001832static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001833 struct hda_codec *codec,
1834 struct snd_pcm_substream *substream)
1835{
1836 struct alc_spec *spec = codec->spec;
1837 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1838}
1839
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001840static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001842 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843{
1844 struct alc_spec *spec = codec->spec;
1845 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1846}
1847
1848/*
1849 * Analog capture
1850 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001851static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 struct hda_codec *codec,
1853 unsigned int stream_tag,
1854 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001855 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856{
1857 struct alc_spec *spec = codec->spec;
1858
Takashi Iwai63300792008-01-24 15:31:36 +01001859 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 stream_tag, 0, format);
1861 return 0;
1862}
1863
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001864static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001866 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867{
1868 struct alc_spec *spec = codec->spec;
1869
Takashi Iwai888afa12008-03-18 09:57:50 +01001870 snd_hda_codec_cleanup_stream(codec,
1871 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 return 0;
1873}
1874
Takashi Iwai840b64c2010-07-13 22:49:01 +02001875/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02001876static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001877 struct hda_codec *codec,
1878 unsigned int stream_tag,
1879 unsigned int format,
1880 struct snd_pcm_substream *substream)
1881{
1882 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001883 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02001884 spec->cur_adc_stream_tag = stream_tag;
1885 spec->cur_adc_format = format;
1886 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1887 return 0;
1888}
1889
Takashi Iwai21268962011-07-07 15:01:13 +02001890static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001891 struct hda_codec *codec,
1892 struct snd_pcm_substream *substream)
1893{
1894 struct alc_spec *spec = codec->spec;
1895 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1896 spec->cur_adc = 0;
1897 return 0;
1898}
1899
Takashi Iwai21268962011-07-07 15:01:13 +02001900static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02001901 .substreams = 1,
1902 .channels_min = 2,
1903 .channels_max = 2,
1904 .nid = 0, /* fill later */
1905 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02001906 .prepare = dyn_adc_capture_pcm_prepare,
1907 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02001908 },
1909};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910
1911/*
1912 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001913static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 .substreams = 1,
1915 .channels_min = 2,
1916 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001917 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001919 .open = alc_playback_pcm_open,
1920 .prepare = alc_playback_pcm_prepare,
1921 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 },
1923};
1924
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001925static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001926 .substreams = 1,
1927 .channels_min = 2,
1928 .channels_max = 2,
1929 /* NID is set in alc_build_pcms */
1930};
1931
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001932static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01001933 .substreams = 1,
1934 .channels_min = 2,
1935 .channels_max = 2,
1936 /* NID is set in alc_build_pcms */
1937};
1938
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001939static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001940 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 .channels_min = 2,
1942 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001943 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001945 .prepare = alc_alt_capture_pcm_prepare,
1946 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 },
1948};
1949
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001950static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 .substreams = 1,
1952 .channels_min = 2,
1953 .channels_max = 2,
1954 /* NID is set in alc_build_pcms */
1955 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001956 .open = alc_dig_playback_pcm_open,
1957 .close = alc_dig_playback_pcm_close,
1958 .prepare = alc_dig_playback_pcm_prepare,
1959 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 },
1961};
1962
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001963static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 .substreams = 1,
1965 .channels_min = 2,
1966 .channels_max = 2,
1967 /* NID is set in alc_build_pcms */
1968};
1969
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001970/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02001971static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001972 .substreams = 0,
1973 .channels_min = 0,
1974 .channels_max = 0,
1975};
1976
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977static int alc_build_pcms(struct hda_codec *codec)
1978{
1979 struct alc_spec *spec = codec->spec;
1980 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001981 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01001982 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 int i;
1984
1985 codec->num_pcms = 1;
1986 codec->pcm_info = info;
1987
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001988 if (spec->no_analog)
1989 goto skip_analog;
1990
Takashi Iwai812a2cc2009-05-16 10:00:49 +02001991 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1992 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01001994
Takashi Iwaieedec3d2012-02-06 10:24:04 +01001995 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001996 p = spec->stream_analog_playback;
1997 if (!p)
1998 p = &alc_pcm_analog_playback;
1999 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002000 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002001 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2002 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002003 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2004 spec->autocfg.line_outs == 2)
2005 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2006 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002007 }
Takashi Iwai27d31532012-12-18 08:57:05 +01002008 if (spec->num_adc_nids) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002009 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002010 if (!p) {
2011 if (spec->dyn_adc_switch)
2012 p = &dyn_adc_pcm_analog_capture;
2013 else
2014 p = &alc_pcm_analog_capture;
2015 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002016 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002017 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
Takashi Iwai4a471b72005-12-07 13:56:29 +01002020 if (spec->channel_mode) {
2021 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2022 for (i = 0; i < spec->num_channel_mode; i++) {
2023 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2024 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 }
2027 }
2028
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002029 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002030 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002032 snprintf(spec->stream_name_digital,
2033 sizeof(spec->stream_name_digital),
2034 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002035 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002036 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002037 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002039 if (spec->dig_out_type)
2040 info->pcm_type = spec->dig_out_type;
2041 else
2042 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002043 if (spec->multiout.dig_out_nid) {
2044 p = spec->stream_digital_playback;
2045 if (!p)
2046 p = &alc_pcm_digital_playback;
2047 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2049 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002050 if (spec->dig_in_nid) {
2051 p = spec->stream_digital_capture;
2052 if (!p)
2053 p = &alc_pcm_digital_capture;
2054 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2056 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002057 /* FIXME: do we need this for all Realtek codec models? */
2058 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 }
2060
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002061 if (spec->no_analog)
2062 return 0;
2063
Takashi Iwaie08a0072006-09-07 17:52:14 +02002064 /* If the use of more than one ADC is requested for the current
2065 * model, configure a second analog capture-only PCM.
2066 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002067 have_multi_adcs = (spec->num_adc_nids > 1) &&
Takashi Iwai27d31532012-12-18 08:57:05 +01002068 !spec->dyn_adc_switch && !spec->auto_mic;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002069 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002070 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002071 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002072 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002073 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002074 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002075 p = spec->stream_analog_alt_playback;
2076 if (!p)
2077 p = &alc_pcm_analog_alt_playback;
2078 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002079 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2080 spec->alt_dac_nid;
2081 } else {
2082 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2083 alc_pcm_null_stream;
2084 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2085 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002086 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002087 p = spec->stream_analog_alt_capture;
2088 if (!p)
2089 p = &alc_pcm_analog_alt_capture;
2090 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002091 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2092 spec->adc_nids[1];
2093 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2094 spec->num_adc_nids - 1;
2095 } else {
2096 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2097 alc_pcm_null_stream;
2098 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002099 }
2100 }
2101
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 return 0;
2103}
2104
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002105static inline void alc_shutup(struct hda_codec *codec)
2106{
Takashi Iwai1c716152011-04-07 10:37:16 +02002107 struct alc_spec *spec = codec->spec;
2108
2109 if (spec && spec->shutup)
2110 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002111 snd_hda_shutup_pins(codec);
2112}
2113
Takashi Iwai603c4012008-07-30 15:01:44 +02002114static void alc_free_kctls(struct hda_codec *codec)
2115{
2116 struct alc_spec *spec = codec->spec;
2117
2118 if (spec->kctls.list) {
2119 struct snd_kcontrol_new *kctl = spec->kctls.list;
2120 int i;
2121 for (i = 0; i < spec->kctls.used; i++)
2122 kfree(kctl[i].name);
2123 }
2124 snd_array_free(&spec->kctls);
2125}
2126
Takashi Iwai23c09b02011-08-19 09:05:35 +02002127static void alc_free_bind_ctls(struct hda_codec *codec)
2128{
2129 struct alc_spec *spec = codec->spec;
2130 if (spec->bind_ctls.list) {
2131 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2132 int i;
2133 for (i = 0; i < spec->bind_ctls.used; i++)
2134 kfree(ctl[i]);
2135 }
2136 snd_array_free(&spec->bind_ctls);
2137}
2138
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139static void alc_free(struct hda_codec *codec)
2140{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002141 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002142
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002143 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002144 return;
2145
Takashi Iwai603c4012008-07-30 15:01:44 +02002146 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002147 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002148 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002149 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002150 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002151 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152}
2153
Takashi Iwai83012a72012-08-24 18:38:08 +02002154#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002155static void alc_power_eapd(struct hda_codec *codec)
2156{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002157 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002158}
2159
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002160static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002161{
2162 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002163 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002164 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002165 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002166 return 0;
2167}
2168#endif
2169
Takashi Iwai2a439522011-07-26 09:52:50 +02002170#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002171static int alc_resume(struct hda_codec *codec)
2172{
Takashi Iwai1c716152011-04-07 10:37:16 +02002173 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002174 codec->patch_ops.init(codec);
2175 snd_hda_codec_resume_amp(codec);
2176 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002177 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002178 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002179 return 0;
2180}
Takashi Iwaie044c392008-10-27 16:56:24 +01002181#endif
2182
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183/*
2184 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002185static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 .build_controls = alc_build_controls,
2187 .build_pcms = alc_build_pcms,
2188 .init = alc_init,
2189 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002190 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002191#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002192 .resume = alc_resume,
2193#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002194#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002195 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002196 .check_power_status = alc_check_power_status,
2197#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002198 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199};
2200
David Henningsson29adc4b2012-09-25 11:31:00 +02002201
Kailang Yangc027ddc2010-03-19 11:33:06 +01002202/* replace the codec chip_name with the given string */
2203static int alc_codec_rename(struct hda_codec *codec, const char *name)
2204{
2205 kfree(codec->chip_name);
2206 codec->chip_name = kstrdup(name, GFP_KERNEL);
2207 if (!codec->chip_name) {
2208 alc_free(codec);
2209 return -ENOMEM;
2210 }
2211 return 0;
2212}
2213
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002214/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002215 * Rename codecs appropriately from COEF value
2216 */
2217struct alc_codec_rename_table {
2218 unsigned int vendor_id;
2219 unsigned short coef_mask;
2220 unsigned short coef_bits;
2221 const char *name;
2222};
2223
2224static struct alc_codec_rename_table rename_tbl[] = {
2225 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2226 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2227 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2228 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2229 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2230 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2231 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002232 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002233 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2234 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2235 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2236 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2237 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2238 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2239 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2240 { } /* terminator */
2241};
2242
2243static int alc_codec_rename_from_preset(struct hda_codec *codec)
2244{
2245 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002246
2247 for (p = rename_tbl; p->vendor_id; p++) {
2248 if (p->vendor_id != codec->vendor_id)
2249 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002250 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002251 return alc_codec_rename(codec, p->name);
2252 }
2253 return 0;
2254}
2255
2256/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002257 * Automatic parse of I/O pins from the BIOS configuration
2258 */
2259
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002260enum {
2261 ALC_CTL_WIDGET_VOL,
2262 ALC_CTL_WIDGET_MUTE,
2263 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002264 ALC_CTL_BIND_VOL,
2265 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002266};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002267static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002268 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2269 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002270 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002271 HDA_BIND_VOL(NULL, 0),
2272 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002273};
2274
2275/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002276static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002277 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002278{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002279 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002280
Takashi Iwai668d1e92012-11-29 14:10:17 +01002281 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002282 if (!knew)
2283 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002284 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002285 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002286 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002287 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002288 return 0;
2289}
2290
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002291static int add_control_with_pfx(struct alc_spec *spec, int type,
2292 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002293 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002294{
2295 char name[32];
2296 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002297 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002298}
2299
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002300#define add_pb_vol_ctrl(spec, type, pfx, val) \
2301 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2302#define add_pb_sw_ctrl(spec, type, pfx, val) \
2303 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2304#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2305 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2306#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2307 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002308
Takashi Iwai23c09b02011-08-19 09:05:35 +02002309static const char * const channel_name[4] = {
2310 "Front", "Surround", "CLFE", "Side"
2311};
2312
Takashi Iwai6843ca12011-06-24 11:03:58 +02002313static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2314 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002315{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002316 struct auto_pin_cfg *cfg = &spec->autocfg;
2317
Takashi Iwai6843ca12011-06-24 11:03:58 +02002318 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002319 if (cfg->line_outs == 1 && !spec->multi_ios &&
2320 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002321 return "Master";
2322
2323 switch (cfg->line_out_type) {
2324 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002325 if (cfg->line_outs == 1)
2326 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002327 if (cfg->line_outs == 2)
2328 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002329 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002330 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002331 /* for multi-io case, only the primary out */
2332 if (ch && spec->multi_ios)
2333 break;
2334 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002335 return "Headphone";
2336 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002337 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002338 return "PCM";
2339 break;
2340 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002341 if (ch >= ARRAY_SIZE(channel_name)) {
2342 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002343 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002344 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002345
2346 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002347}
2348
Takashi Iwai83012a72012-08-24 18:38:08 +02002349#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002350/* add the powersave loopback-list entry */
2351static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2352{
2353 struct hda_amp_list *list;
2354
2355 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2356 return;
2357 list = spec->loopback_list + spec->num_loopbacks;
2358 list->nid = mix;
2359 list->dir = HDA_INPUT;
2360 list->idx = idx;
2361 spec->num_loopbacks++;
2362 spec->loopback.amplist = spec->loopback_list;
2363}
2364#else
2365#define add_loopback_list(spec, mix, idx) /* NOP */
2366#endif
2367
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002368/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002369static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002370 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002371 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002372{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002373 struct alc_spec *spec = codec->spec;
2374 struct nid_path *path;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002375 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002376 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002377
Takashi Iwaibd32f782012-12-12 18:08:52 +01002378 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2379 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2380 return 0; /* no need for analog loopback */
2381
Takashi Iwai965cceb2012-12-18 11:46:37 +01002382 path = add_new_nid_path(codec, pin, mix_nid, 2);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002383 if (!path)
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002384 return -EINVAL;
2385
2386 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002387 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002388 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2389 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002390 if (err < 0)
2391 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002392 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002393 }
2394
2395 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002396 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2397 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002398 if (err < 0)
2399 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002400 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002401 }
2402
Takashi Iwai829f69e2012-12-14 18:26:02 +01002403 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002404 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002405 return 0;
2406}
2407
Takashi Iwai05f5f472009-08-25 13:10:18 +02002408static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002409{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002410 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2411 return (pincap & AC_PINCAP_IN) != 0;
2412}
2413
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002414/* check whether the given two widgets can be connected */
2415static bool is_reachable_path(struct hda_codec *codec,
2416 hda_nid_t from_nid, hda_nid_t to_nid)
2417{
2418 if (!from_nid || !to_nid)
2419 return false;
2420 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2421}
2422
Takashi Iwai666a70d2012-12-17 20:29:29 +01002423/* Parse the codec tree and retrieve ADCs */
2424static int alc_auto_fill_adc_nids(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002425{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002426 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002427 hda_nid_t nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002428 hda_nid_t *adc_nids = spec->adc_nids;
2429 int max_nums = ARRAY_SIZE(spec->adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002430 int i, nums = 0;
2431
2432 nid = codec->start_nid;
2433 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwaib7821702011-07-06 15:12:46 +02002434 unsigned int caps = get_wcaps(codec, nid);
2435 int type = get_wcaps_type(caps);
2436
2437 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2438 continue;
2439 adc_nids[nums] = nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002440 if (++nums >= max_nums)
2441 break;
2442 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002443 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002444 return nums;
2445}
2446
Takashi Iwai666a70d2012-12-17 20:29:29 +01002447/* filter out invalid adc_nids that don't give all active input pins;
2448 * if needed, check whether dynamic ADC-switching is available
2449 */
2450static int check_dyn_adc_switch(struct hda_codec *codec)
2451{
2452 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002453 struct hda_input_mux *imux = &spec->input_mux;
2454 hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)];
Takashi Iwai666a70d2012-12-17 20:29:29 +01002455 int i, n, nums;
2456 hda_nid_t pin, adc;
2457
2458 again:
2459 nums = 0;
2460 for (n = 0; n < spec->num_adc_nids; n++) {
2461 adc = spec->adc_nids[n];
2462 for (i = 0; i < imux->num_items; i++) {
2463 pin = spec->imux_pins[i];
2464 if (!is_reachable_path(codec, pin, adc))
2465 break;
2466 }
2467 if (i >= imux->num_items)
2468 adc_nids[nums++] = adc;
2469 }
2470
2471 if (!nums) {
2472 if (spec->shared_mic_hp) {
2473 spec->shared_mic_hp = 0;
Takashi Iwai27d31532012-12-18 08:57:05 +01002474 imux->num_items = 1;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002475 goto again;
2476 }
2477
2478 /* check whether ADC-switch is possible */
2479 for (i = 0; i < imux->num_items; i++) {
2480 pin = spec->imux_pins[i];
2481 for (n = 0; n < spec->num_adc_nids; n++) {
2482 adc = spec->adc_nids[n];
2483 if (is_reachable_path(codec, pin, adc)) {
2484 spec->dyn_adc_idx[i] = n;
2485 break;
2486 }
2487 }
2488 }
2489
2490 snd_printdd("realtek: enabling ADC switching\n");
2491 spec->dyn_adc_switch = 1;
2492 } else if (nums != spec->num_adc_nids) {
Takashi Iwai27d31532012-12-18 08:57:05 +01002493 memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t));
Takashi Iwai666a70d2012-12-17 20:29:29 +01002494 spec->num_adc_nids = nums;
2495 }
2496
Takashi Iwai27d31532012-12-18 08:57:05 +01002497 if (imux->num_items == 1 || spec->shared_mic_hp) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002498 snd_printdd("realtek: reducing to a single ADC\n");
2499 spec->num_adc_nids = 1; /* reduce to a single ADC */
2500 }
2501
2502 return 0;
2503}
2504
2505/* templates for capture controls */
2506static const struct snd_kcontrol_new cap_src_temp = {
2507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2508 .name = "Input Source",
2509 .info = alc_mux_enum_info,
2510 .get = alc_mux_enum_get,
2511 .put = alc_mux_enum_put,
2512};
2513
2514static const struct snd_kcontrol_new cap_vol_temp = {
2515 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2516 .name = "Capture Volume",
2517 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2518 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2519 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2520 .info = alc_cap_vol_info,
2521 .get = alc_cap_vol_get,
2522 .put = alc_cap_vol_put,
2523 .tlv = { .c = alc_cap_vol_tlv },
2524};
2525
2526static const struct snd_kcontrol_new cap_sw_temp = {
2527 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2528 .name = "Capture Switch",
2529 .info = alc_cap_sw_info,
2530 .get = alc_cap_sw_get,
2531 .put = alc_cap_sw_put,
2532};
2533
2534static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2535{
2536 hda_nid_t nid;
2537 int i, depth;
2538
2539 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2540 for (depth = 0; depth < 3; depth++) {
2541 if (depth >= path->depth)
2542 return -EINVAL;
2543 i = path->depth - depth - 1;
2544 nid = path->path[i];
2545 if (!path->ctls[NID_PATH_VOL_CTL]) {
2546 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2547 path->ctls[NID_PATH_VOL_CTL] =
2548 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2549 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2550 int idx = path->idx[i];
2551 if (!depth && codec->single_adc_amp)
2552 idx = 0;
2553 path->ctls[NID_PATH_VOL_CTL] =
2554 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2555 }
2556 }
2557 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2558 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2559 path->ctls[NID_PATH_MUTE_CTL] =
2560 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2561 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2562 int idx = path->idx[i];
2563 if (!depth && codec->single_adc_amp)
2564 idx = 0;
2565 path->ctls[NID_PATH_MUTE_CTL] =
2566 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2567 }
2568 }
2569 }
2570 return 0;
2571}
2572
2573static int create_capture_mixers(struct hda_codec *codec)
2574{
2575 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002576 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002577 struct snd_kcontrol_new *knew;
2578 int i, n, nums;
2579
2580 if (spec->dyn_adc_switch)
2581 nums = 1;
2582 else
2583 nums = spec->num_adc_nids;
2584
2585 if (!spec->auto_mic && imux->num_items > 1) {
2586 knew = alc_kcontrol_new(spec, "Input Source", &cap_src_temp);
2587 if (!knew)
2588 return -ENOMEM;
2589 knew->count = nums;
2590 }
2591
2592 for (n = 0; n < nums; n++) {
2593 int vol, sw;
2594
2595 vol = sw = 0;
2596 for (i = 0; i < imux->num_items; i++) {
2597 struct nid_path *path;
2598 path = get_nid_path(codec, spec->imux_pins[i],
2599 get_adc_nid(codec, n, i));
2600 if (!path)
2601 continue;
2602 parse_capvol_in_path(codec, path);
2603 if (!vol)
2604 vol = path->ctls[NID_PATH_VOL_CTL];
2605 if (!sw)
2606 sw = path->ctls[NID_PATH_MUTE_CTL];
2607 }
2608
2609 if (vol) {
2610 knew = alc_kcontrol_new(spec, "Capture Volume",
2611 &cap_vol_temp);
2612 if (!knew)
2613 return -ENOMEM;
2614 knew->index = n;
2615 knew->private_value = vol;
2616 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2617 }
2618 if (sw) {
2619 knew = alc_kcontrol_new(spec, "Capture Switch",
2620 &cap_sw_temp);
2621 if (!knew)
2622 return -ENOMEM;
2623 knew->index = n;
2624 knew->private_value = sw;
2625 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2626 }
2627 }
2628
2629 return 0;
2630}
2631
Takashi Iwai05f5f472009-08-25 13:10:18 +02002632/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002633static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002634{
2635 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002636 const struct auto_pin_cfg *cfg = &spec->autocfg;
2637 hda_nid_t mixer = spec->mixer_nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002638 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwaib7821702011-07-06 15:12:46 +02002639 int num_adcs;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002640 int i, c, err, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002641 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002642
Takashi Iwai666a70d2012-12-17 20:29:29 +01002643 num_adcs = alc_auto_fill_adc_nids(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002644 if (num_adcs < 0)
2645 return 0;
2646
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002647 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002648 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002649 const char *label;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002650 bool imux_added;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002651
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002652 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002653 if (!alc_is_input_pin(codec, pin))
2654 continue;
2655
David Henningsson5322bf22011-01-05 11:03:56 +01002656 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002657 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2658 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002659 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002660 type_idx++;
2661 else
2662 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002663 prev_label = label;
2664
Takashi Iwai05f5f472009-08-25 13:10:18 +02002665 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002666 if (is_reachable_path(codec, pin, mixer)) {
2667 err = new_analog_input(codec, pin,
2668 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002669 if (err < 0)
2670 return err;
2671 }
2672 }
2673
Takashi Iwai666a70d2012-12-17 20:29:29 +01002674 imux_added = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002675 for (c = 0; c < num_adcs; c++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002676 struct nid_path *path;
2677 hda_nid_t adc = spec->adc_nids[c];
2678
2679 if (!is_reachable_path(codec, pin, adc))
2680 continue;
2681 path = snd_array_new(&spec->paths);
2682 if (!path)
2683 return -ENOMEM;
2684 memset(path, 0, sizeof(*path));
2685 if (!parse_nid_path(codec, pin, adc, 2, path)) {
2686 snd_printd(KERN_ERR
2687 "invalid input path 0x%x -> 0x%x\n",
2688 pin, adc);
2689 spec->paths.used--;
2690 continue;
2691 }
2692
2693 if (!imux_added) {
2694 spec->imux_pins[imux->num_items] = pin;
2695 snd_hda_add_imux_item(imux, label,
2696 imux->num_items, NULL);
2697 imux_added = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002698 }
2699 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002700 }
Takashi Iwai21268962011-07-07 15:01:13 +02002701
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002702 return 0;
2703}
2704
Takashi Iwai24de1832011-11-07 17:13:39 +01002705/* create a shared input with the headphone out */
2706static int alc_auto_create_shared_input(struct hda_codec *codec)
2707{
2708 struct alc_spec *spec = codec->spec;
2709 struct auto_pin_cfg *cfg = &spec->autocfg;
2710 unsigned int defcfg;
2711 hda_nid_t nid;
2712
2713 /* only one internal input pin? */
2714 if (cfg->num_inputs != 1)
2715 return 0;
2716 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2717 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2718 return 0;
2719
2720 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2721 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2722 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2723 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2724 else
2725 return 0; /* both not available */
2726
2727 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2728 return 0; /* no input */
2729
2730 cfg->inputs[1].pin = nid;
2731 cfg->inputs[1].type = AUTO_PIN_MIC;
2732 cfg->num_inputs = 2;
2733 spec->shared_mic_hp = 1;
2734 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2735 return 0;
2736}
2737
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002738static int get_pin_type(int line_out_type)
2739{
2740 if (line_out_type == AUTO_PIN_HP_OUT)
2741 return PIN_HP;
2742 else
2743 return PIN_OUT;
2744}
2745
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002746static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002747{
2748 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002749 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002750 int i;
2751
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002752 for (i = 0; i < cfg->num_inputs; i++) {
2753 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai62343992012-12-18 09:06:01 +01002754 if (alc_is_input_pin(codec, nid))
Takashi Iwai30ea0982010-09-16 18:47:56 +02002755 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002756
Takashi Iwai829f69e2012-12-14 18:26:02 +01002757 /* mute loopback inputs */
2758 if (spec->mixer_nid) {
2759 struct nid_path *path;
2760 path = get_nid_path(codec, nid, spec->mixer_nid);
2761 if (path)
Takashi Iwai666a70d2012-12-17 20:29:29 +01002762 activate_path(codec, path, path->active, false);
Takashi Iwai829f69e2012-12-14 18:26:02 +01002763 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002764 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002765}
2766
Takashi Iwai185d99f2012-02-16 18:39:45 +01002767static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2768{
2769 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002770 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002771
Takashi Iwaic9967f12012-12-14 16:39:22 +01002772 for (i = 0; i < spec->paths.used; i++) {
2773 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002774 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002775 return true;
2776 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002777 return false;
2778}
2779
Takashi Iwai463419d2012-12-05 14:17:37 +01002780/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002781static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2782 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002783{
2784 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002785 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002786 int i;
2787
2788 for (i = 0; i < spec->num_all_dacs; i++) {
2789 hda_nid_t nid = spec->all_dacs[i];
2790 if (!nid || alc_is_dac_already_used(codec, nid))
2791 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002792 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2793 if (is_digital != cap_digital)
2794 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002795 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002796 return nid;
2797 }
2798 return 0;
2799}
2800
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002801/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002802static bool __parse_nid_path(struct hda_codec *codec,
2803 hda_nid_t from_nid, hda_nid_t to_nid,
2804 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002805{
2806 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002807 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002808 int i, nums;
2809
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002810 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002811 if (!with_aa_mix)
2812 return false;
2813 with_aa_mix = 2; /* mark aa-mix is included */
2814 }
2815
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002816 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002817 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002818 if (conn[i] != from_nid) {
2819 /* special case: when from_nid is 0,
2820 * try to find an empty DAC
2821 */
2822 if (from_nid ||
2823 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2824 alc_is_dac_already_used(codec, conn[i]))
2825 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002826 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002827 /* aa-mix is requested but not included? */
2828 if (!(spec->mixer_nid && with_aa_mix == 1))
2829 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002830 }
2831 if (depth >= MAX_NID_PATH_DEPTH)
2832 return false;
2833 for (i = 0; i < nums; i++) {
2834 unsigned int type;
2835 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002836 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2837 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002838 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002839 if (__parse_nid_path(codec, from_nid, conn[i],
2840 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002841 goto found;
2842 }
2843 return false;
2844
2845 found:
2846 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002847 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002848 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002849 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002850 path->depth++;
2851 return true;
2852}
2853
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002854/* parse the widget path from the given nid to the target nid;
2855 * when @from_nid is 0, try to find an empty DAC;
2856 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2857 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2858 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002859 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002860static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2861 hda_nid_t to_nid, int with_aa_mix,
2862 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002863{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002864 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2865 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002866 path->depth++;
2867#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002868 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002869 path->depth, path->path[0], path->path[1],
2870 path->path[2], path->path[3], path->path[4]);
2871#endif
2872 return true;
2873 }
2874 return false;
2875}
2876
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002877static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2878{
Takashi Iwai140547e2012-02-16 17:23:46 +01002879 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002880 int i;
2881 hda_nid_t nid_found = 0;
2882
2883 for (i = 0; i < spec->num_all_dacs; i++) {
2884 hda_nid_t nid = spec->all_dacs[i];
2885 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002886 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002887 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01002888 if (nid_found)
2889 return 0;
2890 nid_found = nid;
2891 }
2892 }
2893 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002894}
2895
Takashi Iwaiba8111272012-12-06 18:06:23 +01002896static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002897{
Takashi Iwaiba8111272012-12-06 18:06:23 +01002898 struct alc_spec *spec = codec->spec;
2899 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002900
Takashi Iwaic9967f12012-12-14 16:39:22 +01002901 for (i = 0; i < spec->paths.used; i++) {
2902 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002903 if (path->ctls[type] == val)
2904 return true;
2905 }
2906 return false;
2907}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002908
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002909/* badness definition */
2910enum {
2911 /* No primary DAC is found for the main output */
2912 BAD_NO_PRIMARY_DAC = 0x10000,
2913 /* No DAC is found for the extra output */
2914 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01002915 /* No possible multi-ios */
2916 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002917 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01002918 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002919 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01002920 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002921 /* Primary DAC shared with main surrounds */
2922 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002923 /* Primary DAC shared with main CLFE */
2924 BAD_SHARED_CLFE = 0x10,
2925 /* Primary DAC shared with extra surrounds */
2926 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01002927 /* Volume widget is shared */
2928 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002929};
2930
2931static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002932 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002933static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002934 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002935
Takashi Iwai965cceb2012-12-18 11:46:37 +01002936static struct nid_path *add_new_nid_path(struct hda_codec *codec,
2937 hda_nid_t from_nid, hda_nid_t to_nid,
2938 int with_aa_mix)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002939{
2940 struct alc_spec *spec = codec->spec;
2941 struct nid_path *path;
2942
Takashi Iwai965cceb2012-12-18 11:46:37 +01002943 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
2944 return NULL;
2945
Takashi Iwaic9967f12012-12-14 16:39:22 +01002946 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002947 if (!path)
Takashi Iwai965cceb2012-12-18 11:46:37 +01002948 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002949 memset(path, 0, sizeof(*path));
Takashi Iwai965cceb2012-12-18 11:46:37 +01002950 if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path))
2951 return path;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002952 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01002953 spec->paths.used--;
Takashi Iwai965cceb2012-12-18 11:46:37 +01002954 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002955}
2956
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002957/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01002958 * passing 0 to either @pin or @dac behaves as a wildcard
2959 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002960static struct nid_path *
2961get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01002962{
2963 struct alc_spec *spec = codec->spec;
2964 int i;
2965
Takashi Iwaic9967f12012-12-14 16:39:22 +01002966 for (i = 0; i < spec->paths.used; i++) {
2967 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002968 if (path->depth <= 0)
2969 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002970 if ((!from_nid || path->path[0] == from_nid) &&
2971 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01002972 return path;
2973 }
2974 return NULL;
2975}
2976
Takashi Iwai792cf2f2012-12-10 16:04:30 +01002977/* look for widgets in the path between the given NIDs appropriate for
2978 * volume and mute controls, and assign the values to ctls[].
2979 *
2980 * When no appropriate widget is found in the path, the badness value
2981 * is incremented depending on the situation. The function returns the
2982 * total badness for both volume and mute controls.
2983 */
2984static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
2985 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002986{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002987 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002988 hda_nid_t nid;
2989 unsigned int val;
2990 int badness = 0;
2991
Takashi Iwaiba8111272012-12-06 18:06:23 +01002992 if (!path)
2993 return BAD_SHARED_VOL * 2;
2994 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002995 if (nid) {
2996 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002997 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002998 badness += BAD_SHARED_VOL;
2999 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003000 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003001 } else
3002 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003003 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003004 if (nid) {
3005 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003006 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3007 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003008 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3009 else
3010 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003011 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003012 badness += BAD_SHARED_VOL;
3013 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003014 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003015 } else
3016 badness += BAD_SHARED_VOL;
3017 return badness;
3018}
3019
Takashi Iwaidc31b582012-02-17 17:27:53 +01003020struct badness_table {
3021 int no_primary_dac; /* no primary DAC */
3022 int no_dac; /* no secondary DACs */
3023 int shared_primary; /* primary DAC is shared with main output */
3024 int shared_surr; /* secondary DAC shared with main or primary */
3025 int shared_clfe; /* third DAC shared with main or primary */
3026 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3027};
3028
3029static struct badness_table main_out_badness = {
3030 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3031 .no_dac = BAD_NO_DAC,
3032 .shared_primary = BAD_NO_PRIMARY_DAC,
3033 .shared_surr = BAD_SHARED_SURROUND,
3034 .shared_clfe = BAD_SHARED_CLFE,
3035 .shared_surr_main = BAD_SHARED_SURROUND,
3036};
3037
3038static struct badness_table extra_out_badness = {
3039 .no_primary_dac = BAD_NO_DAC,
3040 .no_dac = BAD_NO_DAC,
3041 .shared_primary = BAD_NO_EXTRA_DAC,
3042 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3043 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3044 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3045};
3046
3047/* try to assign DACs to pins and return the resultant badness */
3048static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3049 const hda_nid_t *pins, hda_nid_t *dacs,
3050 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003051{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003052 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003053 struct auto_pin_cfg *cfg = &spec->autocfg;
3054 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003055 int badness = 0;
3056 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003057
Takashi Iwai185d99f2012-02-16 18:39:45 +01003058 if (!num_outs)
3059 return 0;
3060
Takashi Iwaidc31b582012-02-17 17:27:53 +01003061 for (i = 0; i < num_outs; i++) {
3062 hda_nid_t pin = pins[i];
3063 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003064 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003065 if (!dacs[i] && !i) {
3066 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003067 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003068 dacs[0] = dacs[j];
3069 dacs[j] = 0;
3070 break;
3071 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003072 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003073 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003074 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003075 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003076 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003077 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003078 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003079 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003080 dac = spec->private_dac_nids[i];
3081 if (dac) {
3082 if (!i)
3083 badness += bad->shared_primary;
3084 else if (i == 1)
3085 badness += bad->shared_surr;
3086 else
3087 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003088 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003089 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003090 badness += bad->shared_surr_main;
3091 } else if (!i)
3092 badness += bad->no_primary_dac;
3093 else
3094 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003095 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003096 if (!add_new_nid_path(codec, dac, pin, 0))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003097 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003098 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003099 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003100 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003101
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003102 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003103}
3104
3105static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003106 hda_nid_t reference_pin,
3107 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003108
Takashi Iwai185d99f2012-02-16 18:39:45 +01003109static bool alc_map_singles(struct hda_codec *codec, int outs,
3110 const hda_nid_t *pins, hda_nid_t *dacs)
3111{
3112 int i;
3113 bool found = false;
3114 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003115 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003116 if (dacs[i])
3117 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003118 dac = get_dac_if_single(codec, pins[i]);
3119 if (!dac)
3120 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003121 if (add_new_nid_path(codec, dac, pins[i], 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003122 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003123 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003124 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003125 }
3126 return found;
3127}
3128
Takashi Iwai7085ec12009-10-02 09:03:58 +02003129/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003130static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003131 bool fill_hardwired,
3132 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003133{
3134 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003135 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003136 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003137
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003138 /* set num_dacs once to full for alc_auto_look_for_dac() */
3139 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003140 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003141 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3142 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3143 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003144 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003145 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003146 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003147
3148 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003149 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003150 bool mapped;
3151 do {
3152 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003153 cfg->line_out_pins,
3154 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003155 mapped |= alc_map_singles(codec, cfg->hp_outs,
3156 cfg->hp_pins,
3157 spec->multiout.hp_out_nid);
3158 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3159 cfg->speaker_pins,
3160 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003161 if (fill_mio_first && cfg->line_outs == 1 &&
3162 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3163 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3164 if (!err)
3165 mapped = true;
3166 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003167 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003168 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003169
Takashi Iwaidc31b582012-02-17 17:27:53 +01003170 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3171 spec->private_dac_nids,
3172 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003173
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003174 /* re-count num_dacs and squash invalid entries */
3175 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003176 for (i = 0; i < cfg->line_outs; i++) {
3177 if (spec->private_dac_nids[i])
3178 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003179 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003180 memmove(spec->private_dac_nids + i,
3181 spec->private_dac_nids + i + 1,
3182 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003183 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3184 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003185 }
3186
Takashi Iwai276dd702012-02-17 16:17:03 +01003187 if (fill_mio_first &&
3188 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003189 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003190 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003191 if (err < 0)
3192 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003193 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003194 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003195
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003196 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003197 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3198 spec->multiout.hp_out_nid,
3199 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003200 if (err < 0)
3201 return err;
3202 badness += err;
3203 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003204 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003205 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3206 cfg->speaker_pins,
3207 spec->multiout.extra_out_nid,
3208 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003209 if (err < 0)
3210 return err;
3211 badness += err;
3212 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003213 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3214 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003215 if (err < 0)
3216 return err;
3217 badness += err;
3218 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003219 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3220 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003221 int offset = 0;
3222 if (cfg->line_outs >= 3)
3223 offset = 1;
3224 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3225 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003226 if (err < 0)
3227 return err;
3228 badness += err;
3229 }
3230
3231 if (spec->multi_ios == 2) {
3232 for (i = 0; i < 2; i++)
3233 spec->private_dac_nids[spec->multiout.num_dacs++] =
3234 spec->multi_io[i].dac;
3235 spec->ext_channel_count = 2;
3236 } else if (spec->multi_ios) {
3237 spec->multi_ios = 0;
3238 badness += BAD_MULTI_IO;
3239 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003240
3241 return badness;
3242}
3243
3244#define DEBUG_BADNESS
3245
3246#ifdef DEBUG_BADNESS
3247#define debug_badness snd_printdd
3248#else
3249#define debug_badness(...)
3250#endif
3251
3252static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3253{
3254 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3255 cfg->line_out_pins[0], cfg->line_out_pins[1],
3256 cfg->line_out_pins[2], cfg->line_out_pins[2],
3257 spec->multiout.dac_nids[0],
3258 spec->multiout.dac_nids[1],
3259 spec->multiout.dac_nids[2],
3260 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003261 if (spec->multi_ios > 0)
3262 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3263 spec->multi_ios,
3264 spec->multi_io[0].pin, spec->multi_io[1].pin,
3265 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003266 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3267 cfg->hp_pins[0], cfg->hp_pins[1],
3268 cfg->hp_pins[2], cfg->hp_pins[2],
3269 spec->multiout.hp_out_nid[0],
3270 spec->multiout.hp_out_nid[1],
3271 spec->multiout.hp_out_nid[2],
3272 spec->multiout.hp_out_nid[3]);
3273 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3274 cfg->speaker_pins[0], cfg->speaker_pins[1],
3275 cfg->speaker_pins[2], cfg->speaker_pins[3],
3276 spec->multiout.extra_out_nid[0],
3277 spec->multiout.extra_out_nid[1],
3278 spec->multiout.extra_out_nid[2],
3279 spec->multiout.extra_out_nid[3]);
3280}
3281
Takashi Iwai463419d2012-12-05 14:17:37 +01003282/* find all available DACs of the codec */
3283static void alc_fill_all_nids(struct hda_codec *codec)
3284{
3285 struct alc_spec *spec = codec->spec;
3286 int i;
3287 hda_nid_t nid = codec->start_nid;
3288
3289 spec->num_all_dacs = 0;
3290 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3291 for (i = 0; i < codec->num_nodes; i++, nid++) {
3292 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3293 continue;
3294 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3295 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3296 break;
3297 }
3298 spec->all_dacs[spec->num_all_dacs++] = nid;
3299 }
3300}
3301
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003302static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3303{
3304 struct alc_spec *spec = codec->spec;
3305 struct auto_pin_cfg *cfg = &spec->autocfg;
3306 struct auto_pin_cfg *best_cfg;
3307 int best_badness = INT_MAX;
3308 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003309 bool fill_hardwired = true, fill_mio_first = true;
3310 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003311 bool hp_spk_swapped = false;
3312
Takashi Iwai463419d2012-12-05 14:17:37 +01003313 alc_fill_all_nids(codec);
3314
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003315 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3316 if (!best_cfg)
3317 return -ENOMEM;
3318 *best_cfg = *cfg;
3319
3320 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003321 badness = fill_and_eval_dacs(codec, fill_hardwired,
3322 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003323 if (badness < 0) {
3324 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003325 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003326 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003327 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3328 cfg->line_out_type, fill_hardwired, fill_mio_first,
3329 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003330 debug_show_configs(spec, cfg);
3331 if (badness < best_badness) {
3332 best_badness = badness;
3333 *best_cfg = *cfg;
3334 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003335 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003336 }
3337 if (!badness)
3338 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003339 fill_mio_first = !fill_mio_first;
3340 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003341 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003342 fill_hardwired = !fill_hardwired;
3343 if (!fill_hardwired)
3344 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003345 if (hp_spk_swapped)
3346 break;
3347 hp_spk_swapped = true;
3348 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003349 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3350 cfg->hp_outs = cfg->line_outs;
3351 memcpy(cfg->hp_pins, cfg->line_out_pins,
3352 sizeof(cfg->hp_pins));
3353 cfg->line_outs = cfg->speaker_outs;
3354 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3355 sizeof(cfg->speaker_pins));
3356 cfg->speaker_outs = 0;
3357 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3358 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003359 fill_hardwired = true;
3360 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003361 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003362 if (cfg->hp_outs > 0 &&
3363 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3364 cfg->speaker_outs = cfg->line_outs;
3365 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3366 sizeof(cfg->speaker_pins));
3367 cfg->line_outs = cfg->hp_outs;
3368 memcpy(cfg->line_out_pins, cfg->hp_pins,
3369 sizeof(cfg->hp_pins));
3370 cfg->hp_outs = 0;
3371 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3372 cfg->line_out_type = AUTO_PIN_HP_OUT;
3373 fill_hardwired = true;
3374 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003375 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003376 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003377 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003378
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003379 if (badness) {
3380 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003381 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003382 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003383 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3384 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003385 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003386
Takashi Iwaiba8111272012-12-06 18:06:23 +01003387 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003388 struct nid_path *path = get_nid_path(codec,
3389 spec->multiout.dac_nids[0],
3390 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003391 if (path)
3392 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3393 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003394
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003395 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003396 return 0;
3397}
3398
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003399/* replace the channels in the composed amp value with the given number */
3400static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3401{
3402 val &= ~(0x3U << 16);
3403 val |= chs << 16;
3404 return val;
3405}
3406
Takashi Iwai343a04b2011-07-06 14:28:39 +02003407static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003408 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003409 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003410 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003411{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003412 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003413 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003414 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003415 val = path->ctls[NID_PATH_VOL_CTL];
3416 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003417 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003418 val = amp_val_replace_channels(val, chs);
3419 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3420}
3421
3422/* return the channel bits suitable for the given path->ctls[] */
3423static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3424 int type)
3425{
3426 int chs = 1; /* mono (left only) */
3427 if (path) {
3428 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3429 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3430 chs = 3; /* stereo */
3431 }
3432 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003433}
3434
Takashi Iwaie29d3772011-11-14 17:13:23 +01003435static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3436 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003437 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003438{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003439 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3440 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003441}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003442
3443/* create a mute-switch for the given mixer widget;
3444 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3445 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003446static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003447 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003448 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003449 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003450{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003451 unsigned int val;
3452 int type = ALC_CTL_WIDGET_MUTE;
3453
3454 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003455 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003456 val = path->ctls[NID_PATH_MUTE_CTL];
3457 if (!val)
3458 return 0;
3459 val = amp_val_replace_channels(val, chs);
3460 if (get_amp_direction_(val) == HDA_INPUT) {
3461 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003462 int nums = snd_hda_get_num_conns(codec, nid);
3463 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003464 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003465 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003466 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003467 }
3468 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003469}
3470
Takashi Iwaie29d3772011-11-14 17:13:23 +01003471static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003472 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003473{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003474 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3475 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003476}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003477
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003478static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003479 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003480{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003481 int i;
3482
3483 for (i = path->depth - 1; i >= 0; i--) {
3484 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3485 return path->path[i];
3486 if (i != path->depth - 1 && i != 0 &&
3487 nid_has_mute(codec, path->path[i], HDA_INPUT))
3488 return path->path[i];
3489 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003490 return 0;
3491}
3492
3493static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003494 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003495{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003496 int i;
3497
3498 for (i = path->depth - 1; i >= 0; i--) {
3499 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3500 return path->path[i];
3501 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003502 return 0;
3503}
3504
Takashi Iwai7085ec12009-10-02 09:03:58 +02003505/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003506static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003507 const struct auto_pin_cfg *cfg)
3508{
3509 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003510 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003511
Takashi Iwaice764ab2011-04-27 16:35:23 +02003512 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003513 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003514 noutputs += spec->multi_ios;
3515
3516 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003517 const char *name;
3518 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003519 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003520 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003521
3522 dac = spec->multiout.dac_nids[i];
3523 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003524 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003525 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003526 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003527 index = 0;
3528 name = channel_name[i];
3529 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003530 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003531 name = alc_get_line_out_pfx(spec, i, true, &index);
3532 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003533
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003534 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003535 if (!path)
3536 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003537 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003538 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003539 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003540 if (err < 0)
3541 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003542 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003543 if (err < 0)
3544 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003545 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003546 if (err < 0)
3547 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003548 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003549 if (err < 0)
3550 return err;
3551 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003552 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003553 if (err < 0)
3554 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003555 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003556 if (err < 0)
3557 return err;
3558 }
3559 }
3560 return 0;
3561}
3562
Takashi Iwai343a04b2011-07-06 14:28:39 +02003563static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003564 hda_nid_t dac, const char *pfx,
3565 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003566{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003567 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003568 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003569
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003570 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003571 if (!path)
3572 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003573 /* bind volume control will be created in the case of dac = 0 */
3574 if (dac) {
3575 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3576 if (err < 0)
3577 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003578 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003579 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003580 if (err < 0)
3581 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003582 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003583}
3584
Takashi Iwai23c09b02011-08-19 09:05:35 +02003585static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3586 unsigned int nums,
3587 struct hda_ctl_ops *ops)
3588{
3589 struct alc_spec *spec = codec->spec;
3590 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003591 ctlp = snd_array_new(&spec->bind_ctls);
3592 if (!ctlp)
3593 return NULL;
3594 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3595 *ctlp = ctl;
3596 if (ctl)
3597 ctl->ops = ops;
3598 return ctl;
3599}
3600
3601/* add playback controls for speaker and HP outputs */
3602static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3603 const hda_nid_t *pins,
3604 const hda_nid_t *dacs,
3605 const char *pfx)
3606{
3607 struct alc_spec *spec = codec->spec;
3608 struct hda_bind_ctls *ctl;
3609 char name[32];
3610 int i, n, err;
3611
3612 if (!num_pins || !pins[0])
3613 return 0;
3614
Takashi Iwai527e4d72011-10-27 16:33:27 +02003615 if (num_pins == 1) {
3616 hda_nid_t dac = *dacs;
3617 if (!dac)
3618 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003619 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003620 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003621
Takashi Iwai23c09b02011-08-19 09:05:35 +02003622 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003623 hda_nid_t dac;
3624 if (dacs[num_pins - 1])
3625 dac = dacs[i]; /* with individual volumes */
3626 else
3627 dac = 0;
3628 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3629 err = alc_auto_create_extra_out(codec, pins[i], dac,
3630 "Bass Speaker", 0);
3631 } else if (num_pins >= 3) {
3632 snprintf(name, sizeof(name), "%s %s",
3633 pfx, channel_name[i]);
3634 err = alc_auto_create_extra_out(codec, pins[i], dac,
3635 name, 0);
3636 } else {
3637 err = alc_auto_create_extra_out(codec, pins[i], dac,
3638 pfx, i);
3639 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003640 if (err < 0)
3641 return err;
3642 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003643 if (dacs[num_pins - 1])
3644 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003645
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003646 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003647 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3648 if (!ctl)
3649 return -ENOMEM;
3650 n = 0;
3651 for (i = 0; i < num_pins; i++) {
3652 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003653 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003654 if (!pins[i] || !dacs[i])
3655 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003656 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003657 if (!path)
3658 continue;
3659 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003660 if (vol)
3661 ctl->values[n++] =
3662 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3663 }
3664 if (n) {
3665 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3666 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3667 if (err < 0)
3668 return err;
3669 }
3670 return 0;
3671}
3672
Takashi Iwai343a04b2011-07-06 14:28:39 +02003673static int alc_auto_create_hp_out(struct hda_codec *codec)
3674{
3675 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003676 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3677 spec->autocfg.hp_pins,
3678 spec->multiout.hp_out_nid,
3679 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003680}
3681
3682static int alc_auto_create_speaker_out(struct hda_codec *codec)
3683{
3684 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003685 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3686 spec->autocfg.speaker_pins,
3687 spec->multiout.extra_out_nid,
3688 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003689}
3690
Takashi Iwai130e5f02012-12-14 16:09:29 +01003691/* check whether a control with the given (nid, dir, idx) was assigned */
3692static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3693 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003694{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003695 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003696 int i, type;
3697
3698 for (i = 0; i < spec->paths.used; i++) {
3699 struct nid_path *p = snd_array_elem(&spec->paths, i);
3700 if (p->depth <= 0)
3701 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003702 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003703 unsigned int val = p->ctls[type];
3704 if (get_amp_nid_(val) == nid &&
3705 get_amp_direction_(val) == dir &&
3706 get_amp_index_(val) == idx)
3707 return true;
3708 }
3709 }
3710 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003711}
3712
3713/* can have the amp-in capability? */
3714static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3715{
3716 hda_nid_t nid = path->path[idx];
3717 unsigned int caps = get_wcaps(codec, nid);
3718 unsigned int type = get_wcaps_type(caps);
3719
3720 if (!(caps & AC_WCAP_IN_AMP))
3721 return false;
3722 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3723 return false;
3724 return true;
3725}
3726
3727/* can have the amp-out capability? */
3728static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3729{
3730 hda_nid_t nid = path->path[idx];
3731 unsigned int caps = get_wcaps(codec, nid);
3732 unsigned int type = get_wcaps_type(caps);
3733
3734 if (!(caps & AC_WCAP_OUT_AMP))
3735 return false;
3736 if (type == AC_WID_PIN && !idx) /* only for output pins */
3737 return false;
3738 return true;
3739}
3740
Takashi Iwaic9967f12012-12-14 16:39:22 +01003741/* check whether the given (nid,dir,idx) is active */
3742static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3743 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003744{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003745 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003746 int i, n;
3747
Takashi Iwaic9967f12012-12-14 16:39:22 +01003748 for (n = 0; n < spec->paths.used; n++) {
3749 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003750 if (!path->active)
3751 continue;
3752 for (i = 0; i < path->depth; i++) {
3753 if (path->path[i] == nid) {
3754 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3755 return true;
3756 break;
3757 }
3758 }
3759 }
3760 return false;
3761}
3762
Takashi Iwai130e5f02012-12-14 16:09:29 +01003763/* get the default amp value for the target state */
3764static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3765 int dir, bool enable)
3766{
3767 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003768 unsigned int val = 0;
3769
3770 caps = query_amp_caps(codec, nid, dir);
3771 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003772 /* set to 0dB */
3773 if (enable)
3774 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003775 }
3776 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003777 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003778 val |= HDA_AMP_MUTE;
3779 }
3780 return val;
3781}
3782
Takashi Iwai130e5f02012-12-14 16:09:29 +01003783/* initialize the amp value (only at the first time) */
3784static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3785{
3786 int val = get_amp_val_to_activate(codec, nid, dir, false);
3787 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3788}
3789
3790static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3791 int idx, bool enable)
3792{
3793 int val;
3794 if (is_ctl_associated(codec, nid, dir, idx) ||
3795 is_active_nid(codec, nid, dir, idx))
3796 return;
3797 val = get_amp_val_to_activate(codec, nid, dir, enable);
3798 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3799}
3800
3801static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3802 int i, bool enable)
3803{
3804 hda_nid_t nid = path->path[i];
3805 init_amp(codec, nid, HDA_OUTPUT, 0);
3806 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3807}
3808
3809static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003810 int i, bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003811{
3812 struct alc_spec *spec = codec->spec;
3813 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003814 int n, nums, idx;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003815 int type;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003816 hda_nid_t nid = path->path[i];
3817
3818 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai666a70d2012-12-17 20:29:29 +01003819 type = get_wcaps_type(get_wcaps(codec, nid));
3820 if (type == AC_WID_PIN ||
3821 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003822 nums = 1;
3823 idx = 0;
3824 } else
3825 idx = path->idx[i];
3826
Takashi Iwai130e5f02012-12-14 16:09:29 +01003827 for (n = 0; n < nums; n++)
3828 init_amp(codec, nid, HDA_INPUT, n);
3829
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003830 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003831 return;
3832
3833 /* here is a little bit tricky in comparison with activate_amp_out();
3834 * when aa-mixer is available, we need to enable the path as well
3835 */
3836 for (n = 0; n < nums; n++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01003837 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003838 continue;
3839 activate_amp(codec, nid, HDA_INPUT, n, enable);
3840 }
3841}
3842
3843static void activate_path(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003844 bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003845{
3846 int i;
3847
Takashi Iwai130e5f02012-12-14 16:09:29 +01003848 if (!enable)
3849 path->active = false;
3850
3851 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003852 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003853 snd_hda_codec_write_cache(codec, path->path[i], 0,
3854 AC_VERB_SET_CONNECT_SEL,
3855 path->idx[i]);
3856 if (has_amp_in(codec, path, i))
Takashi Iwai666a70d2012-12-17 20:29:29 +01003857 activate_amp_in(codec, path, i, enable, add_aamix);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003858 if (has_amp_out(codec, path, i))
3859 activate_amp_out(codec, path, i, enable);
3860 }
3861
3862 if (enable)
3863 path->active = true;
3864}
3865
Takashi Iwai78e635c2012-12-10 17:07:16 +01003866/* configure the path from the given dac to the pin as the proper output */
3867static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3868 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003869 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003870{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003871 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003872
Takashi Iwai130e5f02012-12-14 16:09:29 +01003873 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003874 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003875 if (!path)
3876 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003877 if (path->active)
3878 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003879 activate_path(codec, path, true, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003880}
3881
Takashi Iwai343a04b2011-07-06 14:28:39 +02003882static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003883{
3884 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003885 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003886 int i;
3887
3888 for (i = 0; i <= HDA_SIDE; i++) {
3889 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3890 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003891 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003892 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003893
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003894 }
3895}
3896
Takashi Iwai343a04b2011-07-06 14:28:39 +02003897static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003898{
3899 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003900 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003901 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003902
David Henningsson636030e2011-10-12 19:26:03 +02003903 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003904 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3905 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003906 pin = spec->autocfg.hp_pins[i];
3907 if (!pin)
3908 break;
3909 dac = spec->multiout.hp_out_nid[i];
3910 if (!dac) {
3911 if (i > 0 && spec->multiout.hp_out_nid[0])
3912 dac = spec->multiout.hp_out_nid[0];
3913 else
3914 dac = spec->multiout.dac_nids[0];
3915 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003916 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003917 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003918 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003919 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3920 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003921 pin = spec->autocfg.speaker_pins[i];
3922 if (!pin)
3923 break;
3924 dac = spec->multiout.extra_out_nid[i];
3925 if (!dac) {
3926 if (i > 0 && spec->multiout.extra_out_nid[0])
3927 dac = spec->multiout.extra_out_nid[0];
3928 else
3929 dac = spec->multiout.dac_nids[0];
3930 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003931 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003932 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003933}
3934
Takashi Iwai276dd702012-02-17 16:17:03 +01003935/* check whether the given pin can be a multi-io pin */
3936static bool can_be_multiio_pin(struct hda_codec *codec,
3937 unsigned int location, hda_nid_t nid)
3938{
3939 unsigned int defcfg, caps;
3940
3941 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3942 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3943 return false;
3944 if (location && get_defcfg_location(defcfg) != location)
3945 return false;
3946 caps = snd_hda_query_pin_caps(codec, nid);
3947 if (!(caps & AC_PINCAP_OUT))
3948 return false;
3949 return true;
3950}
3951
Takashi Iwaice764ab2011-04-27 16:35:23 +02003952/*
3953 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003954 *
3955 * When hardwired is set, try to fill ony hardwired pins, and returns
3956 * zero if any pins are filled, non-zero if nothing found.
3957 * When hardwired is off, try to fill possible input pins, and returns
3958 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003959 */
3960static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003961 hda_nid_t reference_pin,
3962 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003963{
3964 struct alc_spec *spec = codec->spec;
3965 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003966 int type, i, j, dacs, num_pins, old_pins;
3967 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3968 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003969 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003970
Takashi Iwai276dd702012-02-17 16:17:03 +01003971 old_pins = spec->multi_ios;
3972 if (old_pins >= 2)
3973 goto end_fill;
3974
3975 num_pins = 0;
3976 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3977 for (i = 0; i < cfg->num_inputs; i++) {
3978 if (cfg->inputs[i].type != type)
3979 continue;
3980 if (can_be_multiio_pin(codec, location,
3981 cfg->inputs[i].pin))
3982 num_pins++;
3983 }
3984 }
3985 if (num_pins < 2)
3986 goto end_fill;
3987
Takashi Iwai07b18f62011-11-10 15:42:54 +01003988 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003989 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3990 for (i = 0; i < cfg->num_inputs; i++) {
3991 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003992 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003993
Takashi Iwaice764ab2011-04-27 16:35:23 +02003994 if (cfg->inputs[i].type != type)
3995 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003996 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003997 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003998 for (j = 0; j < spec->multi_ios; j++) {
3999 if (nid == spec->multi_io[j].pin)
4000 break;
4001 }
4002 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004003 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004004
4005 if (offset && offset + spec->multi_ios < dacs) {
4006 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004007 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004008 dac = 0;
4009 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004010 if (hardwired)
4011 dac = get_dac_if_single(codec, nid);
4012 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004013 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004014 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004015 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004016 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004017 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01004018 if (!add_new_nid_path(codec, dac, nid, 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004019 badness++;
4020 continue;
4021 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004022 spec->multi_io[spec->multi_ios].pin = nid;
4023 spec->multi_io[spec->multi_ios].dac = dac;
4024 spec->multi_ios++;
4025 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004026 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004027 }
4028 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004029 end_fill:
4030 if (badness)
4031 badness = BAD_MULTI_IO;
4032 if (old_pins == spec->multi_ios) {
4033 if (hardwired)
4034 return 1; /* nothing found */
4035 else
4036 return badness; /* no badness if nothing found */
4037 }
4038 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004039 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004040 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004041 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004042 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004043 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004044
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004045 /* assign volume and mute controls */
4046 for (i = old_pins; i < spec->multi_ios; i++)
4047 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4048 spec->multi_io[i].dac);
4049
4050 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004051}
4052
4053static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4054 struct snd_ctl_elem_info *uinfo)
4055{
4056 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4057 struct alc_spec *spec = codec->spec;
4058
4059 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4060 uinfo->count = 1;
4061 uinfo->value.enumerated.items = spec->multi_ios + 1;
4062 if (uinfo->value.enumerated.item > spec->multi_ios)
4063 uinfo->value.enumerated.item = spec->multi_ios;
4064 sprintf(uinfo->value.enumerated.name, "%dch",
4065 (uinfo->value.enumerated.item + 1) * 2);
4066 return 0;
4067}
4068
4069static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4070 struct snd_ctl_elem_value *ucontrol)
4071{
4072 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4073 struct alc_spec *spec = codec->spec;
4074 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4075 return 0;
4076}
4077
4078static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4079{
4080 struct alc_spec *spec = codec->spec;
4081 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004082 struct nid_path *path;
4083
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004084 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004085 if (!path)
4086 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004087
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004088 if (path->active == output)
4089 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004090
Takashi Iwaice764ab2011-04-27 16:35:23 +02004091 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004092 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004093 activate_path(codec, path, true, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004094 } else {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004095 activate_path(codec, path, false, true);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004096 snd_hda_set_pin_ctl_cache(codec, nid,
4097 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004098 }
4099 return 0;
4100}
4101
4102static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4103 struct snd_ctl_elem_value *ucontrol)
4104{
4105 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4106 struct alc_spec *spec = codec->spec;
4107 int i, ch;
4108
4109 ch = ucontrol->value.enumerated.item[0];
4110 if (ch < 0 || ch > spec->multi_ios)
4111 return -EINVAL;
4112 if (ch == (spec->ext_channel_count - 1) / 2)
4113 return 0;
4114 spec->ext_channel_count = (ch + 1) * 2;
4115 for (i = 0; i < spec->multi_ios; i++)
4116 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004117 spec->multiout.max_channels = max(spec->ext_channel_count,
4118 spec->const_channel_count);
4119 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004120 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004121 return 1;
4122}
4123
Takashi Iwaia9111322011-05-02 11:30:18 +02004124static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004125 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4126 .name = "Channel Mode",
4127 .info = alc_auto_ch_mode_info,
4128 .get = alc_auto_ch_mode_get,
4129 .put = alc_auto_ch_mode_put,
4130};
4131
Takashi Iwai23c09b02011-08-19 09:05:35 +02004132static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004133{
4134 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004135
Takashi Iwaic2674682011-08-24 17:57:44 +02004136 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004137 if (!alc_kcontrol_new(spec, "Channel Mode",
4138 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004139 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004140 }
4141 return 0;
4142}
4143
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004144static void alc_auto_init_multi_io(struct hda_codec *codec)
4145{
4146 struct alc_spec *spec = codec->spec;
4147 int i;
4148
4149 for (i = 0; i < spec->multi_ios; i++) {
4150 hda_nid_t pin = spec->multi_io[i].pin;
4151 struct nid_path *path;
4152 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4153 if (!path)
4154 continue;
4155 if (!spec->multi_io[i].ctl_in)
4156 spec->multi_io[i].ctl_in =
4157 snd_hda_codec_update_cache(codec, pin, 0,
4158 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004159 activate_path(codec, path, path->active, true);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004160 }
4161}
4162
Takashi Iwai1d045db2011-07-07 18:23:21 +02004163/*
4164 * initialize ADC paths
4165 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004166static void alc_auto_init_input_src(struct hda_codec *codec)
4167{
4168 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01004169 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004170 struct nid_path *path;
4171 int i, c, nums;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004172
Takashi Iwai1d045db2011-07-07 18:23:21 +02004173 if (spec->dyn_adc_switch)
4174 nums = 1;
4175 else
4176 nums = spec->num_adc_nids;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004177
4178 for (c = 0; c < nums; c++) {
4179 for (i = 0; i < imux->num_items; i++) {
4180 path = get_nid_path(codec, spec->imux_pins[i],
4181 get_adc_nid(codec, c, i));
4182 if (path) {
4183 bool active = path->active;
4184 if (i == spec->cur_mux[c])
4185 active = true;
4186 activate_path(codec, path, active, false);
4187 }
4188 }
4189 }
4190
4191 alc_inv_dmic_sync(codec, true);
4192 if (spec->shared_mic_hp)
4193 update_shared_mic_hp(codec, spec->cur_mux[0]);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004194}
4195
4196/* add mic boosts if needed */
4197static int alc_auto_add_mic_boost(struct hda_codec *codec)
4198{
4199 struct alc_spec *spec = codec->spec;
4200 struct auto_pin_cfg *cfg = &spec->autocfg;
4201 int i, err;
4202 int type_idx = 0;
4203 hda_nid_t nid;
4204 const char *prev_label = NULL;
4205
4206 for (i = 0; i < cfg->num_inputs; i++) {
4207 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4208 break;
4209 nid = cfg->inputs[i].pin;
4210 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4211 const char *label;
4212 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004213 struct nid_path *path;
4214 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004215
4216 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004217 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4218 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004219 if (prev_label && !strcmp(label, prev_label))
4220 type_idx++;
4221 else
4222 type_idx = 0;
4223 prev_label = label;
4224
4225 snprintf(boost_label, sizeof(boost_label),
4226 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004227 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004228 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004229 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004230 if (err < 0)
4231 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004232
4233 path = get_nid_path(codec, nid, 0);
4234 if (path)
4235 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004236 }
4237 }
4238 return 0;
4239}
4240
Takashi Iwai1d045db2011-07-07 18:23:21 +02004241/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004242 * standard auto-parser initializations
4243 */
4244static void alc_auto_init_std(struct hda_codec *codec)
4245{
Takashi Iwaie4770622011-07-08 11:11:35 +02004246 alc_auto_init_multi_out(codec);
4247 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004248 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004249 alc_auto_init_analog_input(codec);
4250 alc_auto_init_input_src(codec);
4251 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004252 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004253}
4254
4255/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004256 * Digital-beep handlers
4257 */
4258#ifdef CONFIG_SND_HDA_INPUT_BEEP
4259#define set_beep_amp(spec, nid, idx, dir) \
4260 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4261
4262static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004263 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004264 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4265 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4266 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4267 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004268 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004269 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4270 {}
4271};
4272
4273static inline int has_cdefine_beep(struct hda_codec *codec)
4274{
4275 struct alc_spec *spec = codec->spec;
4276 const struct snd_pci_quirk *q;
4277 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4278 if (q)
4279 return q->value;
4280 return spec->cdefine.enable_pcbeep;
4281}
4282#else
4283#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4284#define has_cdefine_beep(codec) 0
4285#endif
4286
4287/* parse the BIOS configuration and set up the alc_spec */
4288/* return 1 if successful, 0 if the proper config is not found,
4289 * or a negative error code
4290 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004291static int alc_parse_auto_config(struct hda_codec *codec,
4292 const hda_nid_t *ignore_nids,
4293 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004294{
4295 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004296 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004297 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004298
Takashi Iwai53c334a2011-08-23 18:27:14 +02004299 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4300 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004301 if (err < 0)
4302 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004303 if (!cfg->line_outs) {
4304 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004305 spec->multiout.max_channels = 2;
4306 spec->no_analog = 1;
4307 goto dig_only;
4308 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004309 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004310 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004311
Takashi Iwaie427c232012-07-29 10:04:08 +02004312 if (!spec->no_primary_hp &&
4313 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004314 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004315 /* use HP as primary out */
4316 cfg->speaker_outs = cfg->line_outs;
4317 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4318 sizeof(cfg->speaker_pins));
4319 cfg->line_outs = cfg->hp_outs;
4320 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4321 cfg->hp_outs = 0;
4322 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4323 cfg->line_out_type = AUTO_PIN_HP_OUT;
4324 }
4325
Takashi Iwai1d045db2011-07-07 18:23:21 +02004326 err = alc_auto_fill_dac_nids(codec);
4327 if (err < 0)
4328 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004329 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004330 if (err < 0)
4331 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004332 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004333 if (err < 0)
4334 return err;
4335 err = alc_auto_create_hp_out(codec);
4336 if (err < 0)
4337 return err;
4338 err = alc_auto_create_speaker_out(codec);
4339 if (err < 0)
4340 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004341 err = alc_auto_create_shared_input(codec);
4342 if (err < 0)
4343 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004344 err = alc_auto_create_input_ctls(codec);
4345 if (err < 0)
4346 return err;
4347
Takashi Iwaib6adb572012-12-03 10:30:58 +01004348 /* check the multiple speaker pins */
4349 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4350 spec->const_channel_count = cfg->line_outs * 2;
4351 else
4352 spec->const_channel_count = cfg->speaker_outs * 2;
4353
4354 if (spec->multi_ios > 0)
4355 spec->multiout.max_channels = max(spec->ext_channel_count,
4356 spec->const_channel_count);
4357 else
4358 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004359
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004360 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004361 alc_auto_parse_digital(codec);
4362
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004363 if (ssid_nids)
4364 alc_ssid_check(codec, ssid_nids);
4365
4366 if (!spec->no_analog) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004367 err = alc_init_automute(codec);
Takashi Iwai475c3d22012-11-30 08:31:30 +01004368 if (err < 0)
4369 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004370
4371 err = check_dyn_adc_switch(codec);
4372 if (err < 0)
4373 return err;
4374
4375 if (!spec->shared_mic_hp) {
4376 err = alc_init_auto_mic(codec);
4377 if (err < 0)
4378 return err;
4379 }
4380
4381 err = create_capture_mixers(codec);
4382 if (err < 0)
4383 return err;
4384
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004385 err = alc_auto_add_mic_boost(codec);
4386 if (err < 0)
4387 return err;
4388 }
4389
Takashi Iwai1d045db2011-07-07 18:23:21 +02004390 if (spec->kctls.list)
4391 add_mixer(spec, spec->kctls.list);
4392
Takashi Iwai1d045db2011-07-07 18:23:21 +02004393 return 1;
4394}
4395
Takashi Iwai3de95172012-05-07 18:03:15 +02004396/* common preparation job for alc_spec */
4397static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4398{
4399 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4400 int err;
4401
4402 if (!spec)
4403 return -ENOMEM;
4404 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004405 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004406 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004407 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004408 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4409 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004410 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004411
4412 err = alc_codec_rename_from_preset(codec);
4413 if (err < 0) {
4414 kfree(spec);
4415 return err;
4416 }
4417 return 0;
4418}
4419
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004420static int alc880_parse_auto_config(struct hda_codec *codec)
4421{
4422 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004423 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004424 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4425}
4426
Takashi Iwai1d045db2011-07-07 18:23:21 +02004427/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004428 * ALC880 fix-ups
4429 */
4430enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004431 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004432 ALC880_FIXUP_GPIO2,
4433 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004434 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004435 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004436 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004437 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004438 ALC880_FIXUP_VOL_KNOB,
4439 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004440 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004441 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004442 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004443 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004444 ALC880_FIXUP_3ST_BASE,
4445 ALC880_FIXUP_3ST,
4446 ALC880_FIXUP_3ST_DIG,
4447 ALC880_FIXUP_5ST_BASE,
4448 ALC880_FIXUP_5ST,
4449 ALC880_FIXUP_5ST_DIG,
4450 ALC880_FIXUP_6ST_BASE,
4451 ALC880_FIXUP_6ST,
4452 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004453};
4454
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004455/* enable the volume-knob widget support on NID 0x21 */
4456static void alc880_fixup_vol_knob(struct hda_codec *codec,
4457 const struct alc_fixup *fix, int action)
4458{
4459 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004460 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004461}
4462
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004463static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004464 [ALC880_FIXUP_GPIO1] = {
4465 .type = ALC_FIXUP_VERBS,
4466 .v.verbs = alc_gpio1_init_verbs,
4467 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004468 [ALC880_FIXUP_GPIO2] = {
4469 .type = ALC_FIXUP_VERBS,
4470 .v.verbs = alc_gpio2_init_verbs,
4471 },
4472 [ALC880_FIXUP_MEDION_RIM] = {
4473 .type = ALC_FIXUP_VERBS,
4474 .v.verbs = (const struct hda_verb[]) {
4475 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4476 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4477 { }
4478 },
4479 .chained = true,
4480 .chain_id = ALC880_FIXUP_GPIO2,
4481 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004482 [ALC880_FIXUP_LG] = {
4483 .type = ALC_FIXUP_PINS,
4484 .v.pins = (const struct alc_pincfg[]) {
4485 /* disable bogus unused pins */
4486 { 0x16, 0x411111f0 },
4487 { 0x18, 0x411111f0 },
4488 { 0x1a, 0x411111f0 },
4489 { }
4490 }
4491 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004492 [ALC880_FIXUP_W810] = {
4493 .type = ALC_FIXUP_PINS,
4494 .v.pins = (const struct alc_pincfg[]) {
4495 /* disable bogus unused pins */
4496 { 0x17, 0x411111f0 },
4497 { }
4498 },
4499 .chained = true,
4500 .chain_id = ALC880_FIXUP_GPIO2,
4501 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004502 [ALC880_FIXUP_EAPD_COEF] = {
4503 .type = ALC_FIXUP_VERBS,
4504 .v.verbs = (const struct hda_verb[]) {
4505 /* change to EAPD mode */
4506 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4507 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4508 {}
4509 },
4510 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004511 [ALC880_FIXUP_TCL_S700] = {
4512 .type = ALC_FIXUP_VERBS,
4513 .v.verbs = (const struct hda_verb[]) {
4514 /* change to EAPD mode */
4515 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4516 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4517 {}
4518 },
4519 .chained = true,
4520 .chain_id = ALC880_FIXUP_GPIO2,
4521 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004522 [ALC880_FIXUP_VOL_KNOB] = {
4523 .type = ALC_FIXUP_FUNC,
4524 .v.func = alc880_fixup_vol_knob,
4525 },
4526 [ALC880_FIXUP_FUJITSU] = {
4527 /* override all pins as BIOS on old Amilo is broken */
4528 .type = ALC_FIXUP_PINS,
4529 .v.pins = (const struct alc_pincfg[]) {
4530 { 0x14, 0x0121411f }, /* HP */
4531 { 0x15, 0x99030120 }, /* speaker */
4532 { 0x16, 0x99030130 }, /* bass speaker */
4533 { 0x17, 0x411111f0 }, /* N/A */
4534 { 0x18, 0x411111f0 }, /* N/A */
4535 { 0x19, 0x01a19950 }, /* mic-in */
4536 { 0x1a, 0x411111f0 }, /* N/A */
4537 { 0x1b, 0x411111f0 }, /* N/A */
4538 { 0x1c, 0x411111f0 }, /* N/A */
4539 { 0x1d, 0x411111f0 }, /* N/A */
4540 { 0x1e, 0x01454140 }, /* SPDIF out */
4541 { }
4542 },
4543 .chained = true,
4544 .chain_id = ALC880_FIXUP_VOL_KNOB,
4545 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004546 [ALC880_FIXUP_F1734] = {
4547 /* almost compatible with FUJITSU, but no bass and SPDIF */
4548 .type = ALC_FIXUP_PINS,
4549 .v.pins = (const struct alc_pincfg[]) {
4550 { 0x14, 0x0121411f }, /* HP */
4551 { 0x15, 0x99030120 }, /* speaker */
4552 { 0x16, 0x411111f0 }, /* N/A */
4553 { 0x17, 0x411111f0 }, /* N/A */
4554 { 0x18, 0x411111f0 }, /* N/A */
4555 { 0x19, 0x01a19950 }, /* mic-in */
4556 { 0x1a, 0x411111f0 }, /* N/A */
4557 { 0x1b, 0x411111f0 }, /* N/A */
4558 { 0x1c, 0x411111f0 }, /* N/A */
4559 { 0x1d, 0x411111f0 }, /* N/A */
4560 { 0x1e, 0x411111f0 }, /* N/A */
4561 { }
4562 },
4563 .chained = true,
4564 .chain_id = ALC880_FIXUP_VOL_KNOB,
4565 },
Takashi Iwai817de922012-02-20 17:20:48 +01004566 [ALC880_FIXUP_UNIWILL] = {
4567 /* need to fix HP and speaker pins to be parsed correctly */
4568 .type = ALC_FIXUP_PINS,
4569 .v.pins = (const struct alc_pincfg[]) {
4570 { 0x14, 0x0121411f }, /* HP */
4571 { 0x15, 0x99030120 }, /* speaker */
4572 { 0x16, 0x99030130 }, /* bass speaker */
4573 { }
4574 },
4575 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004576 [ALC880_FIXUP_UNIWILL_DIG] = {
4577 .type = ALC_FIXUP_PINS,
4578 .v.pins = (const struct alc_pincfg[]) {
4579 /* disable bogus unused pins */
4580 { 0x17, 0x411111f0 },
4581 { 0x19, 0x411111f0 },
4582 { 0x1b, 0x411111f0 },
4583 { 0x1f, 0x411111f0 },
4584 { }
4585 }
4586 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004587 [ALC880_FIXUP_Z71V] = {
4588 .type = ALC_FIXUP_PINS,
4589 .v.pins = (const struct alc_pincfg[]) {
4590 /* set up the whole pins as BIOS is utterly broken */
4591 { 0x14, 0x99030120 }, /* speaker */
4592 { 0x15, 0x0121411f }, /* HP */
4593 { 0x16, 0x411111f0 }, /* N/A */
4594 { 0x17, 0x411111f0 }, /* N/A */
4595 { 0x18, 0x01a19950 }, /* mic-in */
4596 { 0x19, 0x411111f0 }, /* N/A */
4597 { 0x1a, 0x01813031 }, /* line-in */
4598 { 0x1b, 0x411111f0 }, /* N/A */
4599 { 0x1c, 0x411111f0 }, /* N/A */
4600 { 0x1d, 0x411111f0 }, /* N/A */
4601 { 0x1e, 0x0144111e }, /* SPDIF */
4602 { }
4603 }
4604 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004605 [ALC880_FIXUP_3ST_BASE] = {
4606 .type = ALC_FIXUP_PINS,
4607 .v.pins = (const struct alc_pincfg[]) {
4608 { 0x14, 0x01014010 }, /* line-out */
4609 { 0x15, 0x411111f0 }, /* N/A */
4610 { 0x16, 0x411111f0 }, /* N/A */
4611 { 0x17, 0x411111f0 }, /* N/A */
4612 { 0x18, 0x01a19c30 }, /* mic-in */
4613 { 0x19, 0x0121411f }, /* HP */
4614 { 0x1a, 0x01813031 }, /* line-in */
4615 { 0x1b, 0x02a19c40 }, /* front-mic */
4616 { 0x1c, 0x411111f0 }, /* N/A */
4617 { 0x1d, 0x411111f0 }, /* N/A */
4618 /* 0x1e is filled in below */
4619 { 0x1f, 0x411111f0 }, /* N/A */
4620 { }
4621 }
4622 },
4623 [ALC880_FIXUP_3ST] = {
4624 .type = ALC_FIXUP_PINS,
4625 .v.pins = (const struct alc_pincfg[]) {
4626 { 0x1e, 0x411111f0 }, /* N/A */
4627 { }
4628 },
4629 .chained = true,
4630 .chain_id = ALC880_FIXUP_3ST_BASE,
4631 },
4632 [ALC880_FIXUP_3ST_DIG] = {
4633 .type = ALC_FIXUP_PINS,
4634 .v.pins = (const struct alc_pincfg[]) {
4635 { 0x1e, 0x0144111e }, /* SPDIF */
4636 { }
4637 },
4638 .chained = true,
4639 .chain_id = ALC880_FIXUP_3ST_BASE,
4640 },
4641 [ALC880_FIXUP_5ST_BASE] = {
4642 .type = ALC_FIXUP_PINS,
4643 .v.pins = (const struct alc_pincfg[]) {
4644 { 0x14, 0x01014010 }, /* front */
4645 { 0x15, 0x411111f0 }, /* N/A */
4646 { 0x16, 0x01011411 }, /* CLFE */
4647 { 0x17, 0x01016412 }, /* surr */
4648 { 0x18, 0x01a19c30 }, /* mic-in */
4649 { 0x19, 0x0121411f }, /* HP */
4650 { 0x1a, 0x01813031 }, /* line-in */
4651 { 0x1b, 0x02a19c40 }, /* front-mic */
4652 { 0x1c, 0x411111f0 }, /* N/A */
4653 { 0x1d, 0x411111f0 }, /* N/A */
4654 /* 0x1e is filled in below */
4655 { 0x1f, 0x411111f0 }, /* N/A */
4656 { }
4657 }
4658 },
4659 [ALC880_FIXUP_5ST] = {
4660 .type = ALC_FIXUP_PINS,
4661 .v.pins = (const struct alc_pincfg[]) {
4662 { 0x1e, 0x411111f0 }, /* N/A */
4663 { }
4664 },
4665 .chained = true,
4666 .chain_id = ALC880_FIXUP_5ST_BASE,
4667 },
4668 [ALC880_FIXUP_5ST_DIG] = {
4669 .type = ALC_FIXUP_PINS,
4670 .v.pins = (const struct alc_pincfg[]) {
4671 { 0x1e, 0x0144111e }, /* SPDIF */
4672 { }
4673 },
4674 .chained = true,
4675 .chain_id = ALC880_FIXUP_5ST_BASE,
4676 },
4677 [ALC880_FIXUP_6ST_BASE] = {
4678 .type = ALC_FIXUP_PINS,
4679 .v.pins = (const struct alc_pincfg[]) {
4680 { 0x14, 0x01014010 }, /* front */
4681 { 0x15, 0x01016412 }, /* surr */
4682 { 0x16, 0x01011411 }, /* CLFE */
4683 { 0x17, 0x01012414 }, /* side */
4684 { 0x18, 0x01a19c30 }, /* mic-in */
4685 { 0x19, 0x02a19c40 }, /* front-mic */
4686 { 0x1a, 0x01813031 }, /* line-in */
4687 { 0x1b, 0x0121411f }, /* HP */
4688 { 0x1c, 0x411111f0 }, /* N/A */
4689 { 0x1d, 0x411111f0 }, /* N/A */
4690 /* 0x1e is filled in below */
4691 { 0x1f, 0x411111f0 }, /* N/A */
4692 { }
4693 }
4694 },
4695 [ALC880_FIXUP_6ST] = {
4696 .type = ALC_FIXUP_PINS,
4697 .v.pins = (const struct alc_pincfg[]) {
4698 { 0x1e, 0x411111f0 }, /* N/A */
4699 { }
4700 },
4701 .chained = true,
4702 .chain_id = ALC880_FIXUP_6ST_BASE,
4703 },
4704 [ALC880_FIXUP_6ST_DIG] = {
4705 .type = ALC_FIXUP_PINS,
4706 .v.pins = (const struct alc_pincfg[]) {
4707 { 0x1e, 0x0144111e }, /* SPDIF */
4708 { }
4709 },
4710 .chained = true,
4711 .chain_id = ALC880_FIXUP_6ST_BASE,
4712 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004713};
4714
4715static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004716 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004717 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004718 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4719 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004720 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004721 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004722 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004723 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004724 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004725 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004726 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004727 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004728 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004729 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004730 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004731 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4732 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4733 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004734 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004735
4736 /* Below is the copied entries from alc880_quirks.c.
4737 * It's not quite sure whether BIOS sets the correct pin-config table
4738 * on these machines, thus they are kept to be compatible with
4739 * the old static quirks. Once when it's confirmed to work without
4740 * these overrides, it'd be better to remove.
4741 */
4742 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4743 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4744 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4745 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4746 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4747 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4748 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4749 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4750 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4751 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4752 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4753 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4754 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4755 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4756 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4757 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4758 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4759 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4760 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4761 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4762 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4763 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4764 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4765 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4766 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4767 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4768 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4769 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4770 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4771 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4772 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4773 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4774 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4775 /* default Intel */
4776 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4777 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4778 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4779 {}
4780};
4781
4782static const struct alc_model_fixup alc880_fixup_models[] = {
4783 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4784 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4785 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4786 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4787 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4788 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004789 {}
4790};
4791
4792
4793/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004794 * OK, here we have finally the patch for ALC880
4795 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004796static int patch_alc880(struct hda_codec *codec)
4797{
4798 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004799 int err;
4800
Takashi Iwai3de95172012-05-07 18:03:15 +02004801 err = alc_alloc_spec(codec, 0x0b);
4802 if (err < 0)
4803 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004804
Takashi Iwai3de95172012-05-07 18:03:15 +02004805 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004806 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004807
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004808 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4809 alc880_fixups);
4810 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004811
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004812 /* automatic parse from the BIOS config */
4813 err = alc880_parse_auto_config(codec);
4814 if (err < 0)
4815 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004816
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004817 if (!spec->no_analog) {
4818 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004819 if (err < 0)
4820 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004821 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4822 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004823
Takashi Iwai1d045db2011-07-07 18:23:21 +02004824 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004825 codec->patch_ops.unsol_event = alc880_unsol_event;
4826
Takashi Iwai1d045db2011-07-07 18:23:21 +02004827
Takashi Iwai589876e2012-02-20 15:47:55 +01004828 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4829
Takashi Iwai1d045db2011-07-07 18:23:21 +02004830 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004831
4832 error:
4833 alc_free(codec);
4834 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004835}
4836
4837
4838/*
4839 * ALC260 support
4840 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004841static int alc260_parse_auto_config(struct hda_codec *codec)
4842{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004843 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004844 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4845 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004846}
4847
Takashi Iwai1d045db2011-07-07 18:23:21 +02004848/*
4849 * Pin config fixes
4850 */
4851enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004852 ALC260_FIXUP_HP_DC5750,
4853 ALC260_FIXUP_HP_PIN_0F,
4854 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004855 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004856 ALC260_FIXUP_GPIO1_TOGGLE,
4857 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004858 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004859 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004860};
4861
Takashi Iwai20f7d922012-02-16 12:35:16 +01004862static void alc260_gpio1_automute(struct hda_codec *codec)
4863{
4864 struct alc_spec *spec = codec->spec;
4865 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4866 spec->hp_jack_present);
4867}
4868
4869static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4870 const struct alc_fixup *fix, int action)
4871{
4872 struct alc_spec *spec = codec->spec;
4873 if (action == ALC_FIXUP_ACT_PROBE) {
4874 /* although the machine has only one output pin, we need to
4875 * toggle GPIO1 according to the jack state
4876 */
4877 spec->automute_hook = alc260_gpio1_automute;
4878 spec->detect_hp = 1;
4879 spec->automute_speaker = 1;
4880 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004881 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4882 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004883 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004884 }
4885}
4886
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004887static void alc260_fixup_kn1(struct hda_codec *codec,
4888 const struct alc_fixup *fix, int action)
4889{
4890 struct alc_spec *spec = codec->spec;
4891 static const struct alc_pincfg pincfgs[] = {
4892 { 0x0f, 0x02214000 }, /* HP/speaker */
4893 { 0x12, 0x90a60160 }, /* int mic */
4894 { 0x13, 0x02a19000 }, /* ext mic */
4895 { 0x18, 0x01446000 }, /* SPDIF out */
4896 /* disable bogus I/O pins */
4897 { 0x10, 0x411111f0 },
4898 { 0x11, 0x411111f0 },
4899 { 0x14, 0x411111f0 },
4900 { 0x15, 0x411111f0 },
4901 { 0x16, 0x411111f0 },
4902 { 0x17, 0x411111f0 },
4903 { 0x19, 0x411111f0 },
4904 { }
4905 };
4906
4907 switch (action) {
4908 case ALC_FIXUP_ACT_PRE_PROBE:
4909 alc_apply_pincfgs(codec, pincfgs);
4910 break;
4911 case ALC_FIXUP_ACT_PROBE:
4912 spec->init_amp = ALC_INIT_NONE;
4913 break;
4914 }
4915}
4916
Takashi Iwai1d045db2011-07-07 18:23:21 +02004917static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004918 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004919 .type = ALC_FIXUP_PINS,
4920 .v.pins = (const struct alc_pincfg[]) {
4921 { 0x11, 0x90130110 }, /* speaker */
4922 { }
4923 }
4924 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004925 [ALC260_FIXUP_HP_PIN_0F] = {
4926 .type = ALC_FIXUP_PINS,
4927 .v.pins = (const struct alc_pincfg[]) {
4928 { 0x0f, 0x01214000 }, /* HP */
4929 { }
4930 }
4931 },
4932 [ALC260_FIXUP_COEF] = {
4933 .type = ALC_FIXUP_VERBS,
4934 .v.verbs = (const struct hda_verb[]) {
4935 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4936 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4937 { }
4938 },
4939 .chained = true,
4940 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4941 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004942 [ALC260_FIXUP_GPIO1] = {
4943 .type = ALC_FIXUP_VERBS,
4944 .v.verbs = alc_gpio1_init_verbs,
4945 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004946 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4947 .type = ALC_FIXUP_FUNC,
4948 .v.func = alc260_fixup_gpio1_toggle,
4949 .chained = true,
4950 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4951 },
4952 [ALC260_FIXUP_REPLACER] = {
4953 .type = ALC_FIXUP_VERBS,
4954 .v.verbs = (const struct hda_verb[]) {
4955 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4956 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4957 { }
4958 },
4959 .chained = true,
4960 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4961 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004962 [ALC260_FIXUP_HP_B1900] = {
4963 .type = ALC_FIXUP_FUNC,
4964 .v.func = alc260_fixup_gpio1_toggle,
4965 .chained = true,
4966 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004967 },
4968 [ALC260_FIXUP_KN1] = {
4969 .type = ALC_FIXUP_FUNC,
4970 .v.func = alc260_fixup_kn1,
4971 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004972};
4973
4974static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004975 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004976 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004977 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004978 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004979 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004980 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004981 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004982 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004983 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004984 {}
4985};
4986
4987/*
4988 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989static int patch_alc260(struct hda_codec *codec)
4990{
4991 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004992 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993
Takashi Iwai3de95172012-05-07 18:03:15 +02004994 err = alc_alloc_spec(codec, 0x07);
4995 if (err < 0)
4996 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004997
Takashi Iwai3de95172012-05-07 18:03:15 +02004998 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004999
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005000 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5001 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005002
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005003 /* automatic parse from the BIOS config */
5004 err = alc260_parse_auto_config(codec);
5005 if (err < 0)
5006 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005007
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005008 if (!spec->no_analog) {
5009 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005010 if (err < 0)
5011 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005012 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5013 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005014
Takashi Iwai1d045db2011-07-07 18:23:21 +02005015 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005016 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005017
Takashi Iwai589876e2012-02-20 15:47:55 +01005018 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5019
Takashi Iwai1d045db2011-07-07 18:23:21 +02005020 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005021
5022 error:
5023 alc_free(codec);
5024 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005025}
5026
5027
5028/*
5029 * ALC882/883/885/888/889 support
5030 *
5031 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5032 * configuration. Each pin widget can choose any input DACs and a mixer.
5033 * Each ADC is connected from a mixer of all inputs. This makes possible
5034 * 6-channel independent captures.
5035 *
5036 * In addition, an independent DAC for the multi-playback (not used in this
5037 * driver yet).
5038 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005039
5040/*
5041 * Pin config fixes
5042 */
5043enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005044 ALC882_FIXUP_ABIT_AW9D_MAX,
5045 ALC882_FIXUP_LENOVO_Y530,
5046 ALC882_FIXUP_PB_M5210,
5047 ALC882_FIXUP_ACER_ASPIRE_7736,
5048 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005049 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005050 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005051 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005052 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005053 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005054 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005055 ALC882_FIXUP_GPIO1,
5056 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005057 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005058 ALC889_FIXUP_COEF,
5059 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005060 ALC882_FIXUP_ACER_ASPIRE_4930G,
5061 ALC882_FIXUP_ACER_ASPIRE_8930G,
5062 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005063 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005064 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005065 ALC889_FIXUP_MBP_VREF,
5066 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005067 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005068 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005069};
5070
Takashi Iwai68ef0562011-11-09 18:24:44 +01005071static void alc889_fixup_coef(struct hda_codec *codec,
5072 const struct alc_fixup *fix, int action)
5073{
5074 if (action != ALC_FIXUP_ACT_INIT)
5075 return;
5076 alc889_coef_init(codec);
5077}
5078
Takashi Iwai56710872011-11-14 17:42:11 +01005079/* toggle speaker-output according to the hp-jack state */
5080static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5081{
5082 unsigned int gpiostate, gpiomask, gpiodir;
5083
5084 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5085 AC_VERB_GET_GPIO_DATA, 0);
5086
5087 if (!muted)
5088 gpiostate |= (1 << pin);
5089 else
5090 gpiostate &= ~(1 << pin);
5091
5092 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5093 AC_VERB_GET_GPIO_MASK, 0);
5094 gpiomask |= (1 << pin);
5095
5096 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5097 AC_VERB_GET_GPIO_DIRECTION, 0);
5098 gpiodir |= (1 << pin);
5099
5100
5101 snd_hda_codec_write(codec, codec->afg, 0,
5102 AC_VERB_SET_GPIO_MASK, gpiomask);
5103 snd_hda_codec_write(codec, codec->afg, 0,
5104 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5105
5106 msleep(1);
5107
5108 snd_hda_codec_write(codec, codec->afg, 0,
5109 AC_VERB_SET_GPIO_DATA, gpiostate);
5110}
5111
5112/* set up GPIO at initialization */
5113static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5114 const struct alc_fixup *fix, int action)
5115{
5116 if (action != ALC_FIXUP_ACT_INIT)
5117 return;
5118 alc882_gpio_mute(codec, 0, 0);
5119 alc882_gpio_mute(codec, 1, 0);
5120}
5121
Takashi Iwai02a237b2012-02-13 15:25:07 +01005122/* Fix the connection of some pins for ALC889:
5123 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5124 * work correctly (bko#42740)
5125 */
5126static void alc889_fixup_dac_route(struct hda_codec *codec,
5127 const struct alc_fixup *fix, int action)
5128{
5129 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005130 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005131 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5132 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5133 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5134 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5135 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5136 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005137 } else if (action == ALC_FIXUP_ACT_PROBE) {
5138 /* restore the connections */
5139 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5140 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5141 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5142 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5143 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005144 }
5145}
5146
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005147/* Set VREF on HP pin */
5148static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5149 const struct alc_fixup *fix, int action)
5150{
5151 struct alc_spec *spec = codec->spec;
5152 static hda_nid_t nids[2] = { 0x14, 0x15 };
5153 int i;
5154
5155 if (action != ALC_FIXUP_ACT_INIT)
5156 return;
5157 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5158 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5159 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5160 continue;
5161 val = snd_hda_codec_read(codec, nids[i], 0,
5162 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5163 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005164 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005165 spec->keep_vref_in_automute = 1;
5166 break;
5167 }
5168}
5169
5170/* Set VREF on speaker pins on imac91 */
5171static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5172 const struct alc_fixup *fix, int action)
5173{
5174 struct alc_spec *spec = codec->spec;
5175 static hda_nid_t nids[2] = { 0x18, 0x1a };
5176 int i;
5177
5178 if (action != ALC_FIXUP_ACT_INIT)
5179 return;
5180 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5181 unsigned int val;
5182 val = snd_hda_codec_read(codec, nids[i], 0,
5183 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5184 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005185 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005186 }
5187 spec->keep_vref_in_automute = 1;
5188}
5189
Takashi Iwaie427c232012-07-29 10:04:08 +02005190/* Don't take HP output as primary
5191 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5192 */
5193static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5194 const struct alc_fixup *fix, int action)
5195{
5196 struct alc_spec *spec = codec->spec;
5197 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5198 spec->no_primary_hp = 1;
5199}
5200
Takashi Iwai1d045db2011-07-07 18:23:21 +02005201static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005202 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005203 .type = ALC_FIXUP_PINS,
5204 .v.pins = (const struct alc_pincfg[]) {
5205 { 0x15, 0x01080104 }, /* side */
5206 { 0x16, 0x01011012 }, /* rear */
5207 { 0x17, 0x01016011 }, /* clfe */
5208 { }
5209 }
5210 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005211 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005212 .type = ALC_FIXUP_PINS,
5213 .v.pins = (const struct alc_pincfg[]) {
5214 { 0x15, 0x99130112 }, /* rear int speakers */
5215 { 0x16, 0x99130111 }, /* subwoofer */
5216 { }
5217 }
5218 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005219 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005220 .type = ALC_FIXUP_VERBS,
5221 .v.verbs = (const struct hda_verb[]) {
5222 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5223 {}
5224 }
5225 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005226 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005227 .type = ALC_FIXUP_FUNC,
5228 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005229 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005230 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005231 .type = ALC_FIXUP_PINS,
5232 .v.pins = (const struct alc_pincfg[]) {
5233 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5234 { }
5235 }
5236 },
Marton Balint8f239212012-03-05 21:33:23 +01005237 [ALC889_FIXUP_CD] = {
5238 .type = ALC_FIXUP_PINS,
5239 .v.pins = (const struct alc_pincfg[]) {
5240 { 0x1c, 0x993301f0 }, /* CD */
5241 { }
5242 }
5243 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005244 [ALC889_FIXUP_VAIO_TT] = {
5245 .type = ALC_FIXUP_PINS,
5246 .v.pins = (const struct alc_pincfg[]) {
5247 { 0x17, 0x90170111 }, /* hidden surround speaker */
5248 { }
5249 }
5250 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005251 [ALC888_FIXUP_EEE1601] = {
5252 .type = ALC_FIXUP_VERBS,
5253 .v.verbs = (const struct hda_verb[]) {
5254 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5255 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5256 { }
5257 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005258 },
5259 [ALC882_FIXUP_EAPD] = {
5260 .type = ALC_FIXUP_VERBS,
5261 .v.verbs = (const struct hda_verb[]) {
5262 /* change to EAPD mode */
5263 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5264 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5265 { }
5266 }
5267 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005268 [ALC883_FIXUP_EAPD] = {
5269 .type = ALC_FIXUP_VERBS,
5270 .v.verbs = (const struct hda_verb[]) {
5271 /* change to EAPD mode */
5272 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5273 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5274 { }
5275 }
5276 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005277 [ALC883_FIXUP_ACER_EAPD] = {
5278 .type = ALC_FIXUP_VERBS,
5279 .v.verbs = (const struct hda_verb[]) {
5280 /* eanable EAPD on Acer laptops */
5281 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5282 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5283 { }
5284 }
5285 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005286 [ALC882_FIXUP_GPIO1] = {
5287 .type = ALC_FIXUP_VERBS,
5288 .v.verbs = alc_gpio1_init_verbs,
5289 },
5290 [ALC882_FIXUP_GPIO2] = {
5291 .type = ALC_FIXUP_VERBS,
5292 .v.verbs = alc_gpio2_init_verbs,
5293 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005294 [ALC882_FIXUP_GPIO3] = {
5295 .type = ALC_FIXUP_VERBS,
5296 .v.verbs = alc_gpio3_init_verbs,
5297 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005298 [ALC882_FIXUP_ASUS_W2JC] = {
5299 .type = ALC_FIXUP_VERBS,
5300 .v.verbs = alc_gpio1_init_verbs,
5301 .chained = true,
5302 .chain_id = ALC882_FIXUP_EAPD,
5303 },
5304 [ALC889_FIXUP_COEF] = {
5305 .type = ALC_FIXUP_FUNC,
5306 .v.func = alc889_fixup_coef,
5307 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005308 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5309 .type = ALC_FIXUP_PINS,
5310 .v.pins = (const struct alc_pincfg[]) {
5311 { 0x16, 0x99130111 }, /* CLFE speaker */
5312 { 0x17, 0x99130112 }, /* surround speaker */
5313 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005314 },
5315 .chained = true,
5316 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005317 },
5318 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5319 .type = ALC_FIXUP_PINS,
5320 .v.pins = (const struct alc_pincfg[]) {
5321 { 0x16, 0x99130111 }, /* CLFE speaker */
5322 { 0x1b, 0x99130112 }, /* surround speaker */
5323 { }
5324 },
5325 .chained = true,
5326 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5327 },
5328 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5329 /* additional init verbs for Acer Aspire 8930G */
5330 .type = ALC_FIXUP_VERBS,
5331 .v.verbs = (const struct hda_verb[]) {
5332 /* Enable all DACs */
5333 /* DAC DISABLE/MUTE 1? */
5334 /* setting bits 1-5 disables DAC nids 0x02-0x06
5335 * apparently. Init=0x38 */
5336 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5337 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5338 /* DAC DISABLE/MUTE 2? */
5339 /* some bit here disables the other DACs.
5340 * Init=0x4900 */
5341 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5342 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5343 /* DMIC fix
5344 * This laptop has a stereo digital microphone.
5345 * The mics are only 1cm apart which makes the stereo
5346 * useless. However, either the mic or the ALC889
5347 * makes the signal become a difference/sum signal
5348 * instead of standard stereo, which is annoying.
5349 * So instead we flip this bit which makes the
5350 * codec replicate the sum signal to both channels,
5351 * turning it into a normal mono mic.
5352 */
5353 /* DMIC_CONTROL? Init value = 0x0001 */
5354 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5355 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5356 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5357 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5358 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005359 },
5360 .chained = true,
5361 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005362 },
Takashi Iwai56710872011-11-14 17:42:11 +01005363 [ALC885_FIXUP_MACPRO_GPIO] = {
5364 .type = ALC_FIXUP_FUNC,
5365 .v.func = alc885_fixup_macpro_gpio,
5366 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005367 [ALC889_FIXUP_DAC_ROUTE] = {
5368 .type = ALC_FIXUP_FUNC,
5369 .v.func = alc889_fixup_dac_route,
5370 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005371 [ALC889_FIXUP_MBP_VREF] = {
5372 .type = ALC_FIXUP_FUNC,
5373 .v.func = alc889_fixup_mbp_vref,
5374 .chained = true,
5375 .chain_id = ALC882_FIXUP_GPIO1,
5376 },
5377 [ALC889_FIXUP_IMAC91_VREF] = {
5378 .type = ALC_FIXUP_FUNC,
5379 .v.func = alc889_fixup_imac91_vref,
5380 .chained = true,
5381 .chain_id = ALC882_FIXUP_GPIO1,
5382 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005383 [ALC882_FIXUP_INV_DMIC] = {
5384 .type = ALC_FIXUP_FUNC,
5385 .v.func = alc_fixup_inv_dmic_0x12,
5386 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005387 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5388 .type = ALC_FIXUP_FUNC,
5389 .v.func = alc882_fixup_no_primary_hp,
5390 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005391};
5392
5393static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005394 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5395 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5396 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5397 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5398 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5399 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005400 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5401 ALC882_FIXUP_ACER_ASPIRE_4930G),
5402 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5403 ALC882_FIXUP_ACER_ASPIRE_4930G),
5404 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5405 ALC882_FIXUP_ACER_ASPIRE_8930G),
5406 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5407 ALC882_FIXUP_ACER_ASPIRE_8930G),
5408 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5409 ALC882_FIXUP_ACER_ASPIRE_4930G),
5410 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5411 ALC882_FIXUP_ACER_ASPIRE_4930G),
5412 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5413 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005414 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005415 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5416 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005417 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005418 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005419 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005420 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005421 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005422 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005423 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005424 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005425 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005426
5427 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005428 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5429 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5430 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005431 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5432 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5433 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005434 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5435 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005436 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005437 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5438 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5439 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5440 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005441 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005442 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5443 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5444 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005445 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005446 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005447 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5448 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5449 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005450
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005451 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005452 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005453 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005454 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005455 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005456 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5457 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005458 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005459 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005460 {}
5461};
5462
Takashi Iwai912093b2012-04-11 14:03:41 +02005463static const struct alc_model_fixup alc882_fixup_models[] = {
5464 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5465 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5466 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005467 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005468 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005469 {}
5470};
5471
Takashi Iwai1d045db2011-07-07 18:23:21 +02005472/*
5473 * BIOS auto configuration
5474 */
5475/* almost identical with ALC880 parser... */
5476static int alc882_parse_auto_config(struct hda_codec *codec)
5477{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005478 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005479 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5480 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481}
5482
Takashi Iwai1d045db2011-07-07 18:23:21 +02005483/*
5484 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005485static int patch_alc882(struct hda_codec *codec)
5486{
5487 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005488 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489
Takashi Iwai3de95172012-05-07 18:03:15 +02005490 err = alc_alloc_spec(codec, 0x0b);
5491 if (err < 0)
5492 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005493
Takashi Iwai3de95172012-05-07 18:03:15 +02005494 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005495
5496 switch (codec->vendor_id) {
5497 case 0x10ec0882:
5498 case 0x10ec0885:
5499 break;
5500 default:
5501 /* ALC883 and variants */
5502 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5503 break;
5504 }
5505
Takashi Iwai912093b2012-04-11 14:03:41 +02005506 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5507 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005508 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005509
5510 alc_auto_parse_customize_define(codec);
5511
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005512 /* automatic parse from the BIOS config */
5513 err = alc882_parse_auto_config(codec);
5514 if (err < 0)
5515 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005516
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005517 if (!spec->no_analog && has_cdefine_beep(codec)) {
5518 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005519 if (err < 0)
5520 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005521 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005522 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005523
Takashi Iwai1d045db2011-07-07 18:23:21 +02005524 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005525
Takashi Iwai589876e2012-02-20 15:47:55 +01005526 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5527
Takashi Iwai1d045db2011-07-07 18:23:21 +02005528 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005529
5530 error:
5531 alc_free(codec);
5532 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005533}
5534
5535
5536/*
5537 * ALC262 support
5538 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005539static int alc262_parse_auto_config(struct hda_codec *codec)
5540{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005541 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005542 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5543 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005544}
5545
5546/*
5547 * Pin config fixes
5548 */
5549enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005550 ALC262_FIXUP_FSC_H270,
5551 ALC262_FIXUP_HP_Z200,
5552 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005553 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005554 ALC262_FIXUP_BENQ,
5555 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005556 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005557};
5558
5559static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005560 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005561 .type = ALC_FIXUP_PINS,
5562 .v.pins = (const struct alc_pincfg[]) {
5563 { 0x14, 0x99130110 }, /* speaker */
5564 { 0x15, 0x0221142f }, /* front HP */
5565 { 0x1b, 0x0121141f }, /* rear HP */
5566 { }
5567 }
5568 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005569 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005570 .type = ALC_FIXUP_PINS,
5571 .v.pins = (const struct alc_pincfg[]) {
5572 { 0x16, 0x99130120 }, /* internal speaker */
5573 { }
5574 }
5575 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005576 [ALC262_FIXUP_TYAN] = {
5577 .type = ALC_FIXUP_PINS,
5578 .v.pins = (const struct alc_pincfg[]) {
5579 { 0x14, 0x1993e1f0 }, /* int AUX */
5580 { }
5581 }
5582 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005583 [ALC262_FIXUP_LENOVO_3000] = {
5584 .type = ALC_FIXUP_VERBS,
5585 .v.verbs = (const struct hda_verb[]) {
5586 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005587 {}
5588 },
5589 .chained = true,
5590 .chain_id = ALC262_FIXUP_BENQ,
5591 },
5592 [ALC262_FIXUP_BENQ] = {
5593 .type = ALC_FIXUP_VERBS,
5594 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005595 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5596 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5597 {}
5598 }
5599 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005600 [ALC262_FIXUP_BENQ_T31] = {
5601 .type = ALC_FIXUP_VERBS,
5602 .v.verbs = (const struct hda_verb[]) {
5603 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5604 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5605 {}
5606 }
5607 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005608 [ALC262_FIXUP_INV_DMIC] = {
5609 .type = ALC_FIXUP_FUNC,
5610 .v.func = alc_fixup_inv_dmic_0x12,
5611 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005612};
5613
5614static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005615 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005616 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5617 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005618 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5619 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005620 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005621 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5622 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005623 {}
5624};
5625
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005626static const struct alc_model_fixup alc262_fixup_models[] = {
5627 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5628 {}
5629};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005630
Takashi Iwai1d045db2011-07-07 18:23:21 +02005631/*
5632 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005633static int patch_alc262(struct hda_codec *codec)
5634{
5635 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005636 int err;
5637
Takashi Iwai3de95172012-05-07 18:03:15 +02005638 err = alc_alloc_spec(codec, 0x0b);
5639 if (err < 0)
5640 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005641
Takashi Iwai3de95172012-05-07 18:03:15 +02005642 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643
5644#if 0
5645 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5646 * under-run
5647 */
5648 {
5649 int tmp;
5650 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5651 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5652 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5653 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5654 }
5655#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5657
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005658 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5659 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005660 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005662 alc_auto_parse_customize_define(codec);
5663
Takashi Iwai42399f72011-11-07 17:18:44 +01005664 /* automatic parse from the BIOS config */
5665 err = alc262_parse_auto_config(codec);
5666 if (err < 0)
5667 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005668
Takashi Iwai1d045db2011-07-07 18:23:21 +02005669 if (!spec->no_analog && has_cdefine_beep(codec)) {
5670 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005671 if (err < 0)
5672 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005673 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005674 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005675
Takashi Iwai1d045db2011-07-07 18:23:21 +02005676 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005677 spec->shutup = alc_eapd_shutup;
5678
Takashi Iwai589876e2012-02-20 15:47:55 +01005679 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5680
Takashi Iwai1d045db2011-07-07 18:23:21 +02005681 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005682
5683 error:
5684 alc_free(codec);
5685 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005686}
5687
5688/*
5689 * ALC268
5690 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691/* bind Beep switches of both NID 0x0f and 0x10 */
5692static const struct hda_bind_ctls alc268_bind_beep_sw = {
5693 .ops = &snd_hda_bind_sw,
5694 .values = {
5695 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5696 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5697 0
5698 },
5699};
5700
5701static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5702 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5703 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5704 { }
5705};
5706
5707/* set PCBEEP vol = 0, mute connections */
5708static const struct hda_verb alc268_beep_init_verbs[] = {
5709 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5710 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5711 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5712 { }
5713};
5714
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005715enum {
5716 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005717 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005718};
5719
5720static const struct alc_fixup alc268_fixups[] = {
5721 [ALC268_FIXUP_INV_DMIC] = {
5722 .type = ALC_FIXUP_FUNC,
5723 .v.func = alc_fixup_inv_dmic_0x12,
5724 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005725 [ALC268_FIXUP_HP_EAPD] = {
5726 .type = ALC_FIXUP_VERBS,
5727 .v.verbs = (const struct hda_verb[]) {
5728 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5729 {}
5730 }
5731 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005732};
5733
5734static const struct alc_model_fixup alc268_fixup_models[] = {
5735 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005736 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5737 {}
5738};
5739
5740static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5741 /* below is codec SSID since multiple Toshiba laptops have the
5742 * same PCI SSID 1179:ff00
5743 */
5744 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005745 {}
5746};
5747
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748/*
5749 * BIOS auto configuration
5750 */
5751static int alc268_parse_auto_config(struct hda_codec *codec)
5752{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005753 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005755 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5756 if (err > 0) {
5757 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5758 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005759 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005760 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005761 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005762 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005763}
5764
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765/*
5766 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767static int patch_alc268(struct hda_codec *codec)
5768{
5769 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005770 int i, has_beep, err;
5771
Takashi Iwai1d045db2011-07-07 18:23:21 +02005772 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005773 err = alc_alloc_spec(codec, 0);
5774 if (err < 0)
5775 return err;
5776
5777 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005778
Takashi Iwaicb766402012-10-20 10:55:21 +02005779 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005780 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5781
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005782 /* automatic parse from the BIOS config */
5783 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005784 if (err < 0)
5785 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786
Takashi Iwai1d045db2011-07-07 18:23:21 +02005787 has_beep = 0;
5788 for (i = 0; i < spec->num_mixers; i++) {
5789 if (spec->mixers[i] == alc268_beep_mixer) {
5790 has_beep = 1;
5791 break;
5792 }
5793 }
5794
5795 if (has_beep) {
5796 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005797 if (err < 0)
5798 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005799 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5800 /* override the amp caps for beep generator */
5801 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5802 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5803 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5804 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5805 (0 << AC_AMPCAP_MUTE_SHIFT));
5806 }
5807
Takashi Iwai1d045db2011-07-07 18:23:21 +02005808 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005809 spec->shutup = alc_eapd_shutup;
5810
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005811 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5812
Takashi Iwai1d045db2011-07-07 18:23:21 +02005813 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005814
5815 error:
5816 alc_free(codec);
5817 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005818}
5819
5820/*
5821 * ALC269
5822 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005823static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5824 .substreams = 1,
5825 .channels_min = 2,
5826 .channels_max = 8,
5827 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5828 /* NID is set in alc_build_pcms */
5829 .ops = {
5830 .open = alc_playback_pcm_open,
5831 .prepare = alc_playback_pcm_prepare,
5832 .cleanup = alc_playback_pcm_cleanup
5833 },
5834};
5835
5836static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5837 .substreams = 1,
5838 .channels_min = 2,
5839 .channels_max = 2,
5840 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5841 /* NID is set in alc_build_pcms */
5842};
5843
Takashi Iwai1d045db2011-07-07 18:23:21 +02005844/* different alc269-variants */
5845enum {
5846 ALC269_TYPE_ALC269VA,
5847 ALC269_TYPE_ALC269VB,
5848 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005849 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005850 ALC269_TYPE_ALC280,
5851 ALC269_TYPE_ALC282,
5852 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005853};
5854
5855/*
5856 * BIOS auto configuration
5857 */
5858static int alc269_parse_auto_config(struct hda_codec *codec)
5859{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005860 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005861 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5862 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5863 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005864 const hda_nid_t *ssids;
5865
5866 switch (spec->codec_variant) {
5867 case ALC269_TYPE_ALC269VA:
5868 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005869 case ALC269_TYPE_ALC280:
5870 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005871 ssids = alc269va_ssids;
5872 break;
5873 case ALC269_TYPE_ALC269VB:
5874 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005875 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005876 ssids = alc269_ssids;
5877 break;
5878 default:
5879 ssids = alc269_ssids;
5880 break;
5881 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005882
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005883 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005884}
5885
Kailang Yang1387e2d2012-11-08 10:23:18 +01005886static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887{
5888 int val = alc_read_coef_idx(codec, 0x04);
5889 if (power_up)
5890 val |= 1 << 11;
5891 else
5892 val &= ~(1 << 11);
5893 alc_write_coef_idx(codec, 0x04, val);
5894}
5895
5896static void alc269_shutup(struct hda_codec *codec)
5897{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005898 struct alc_spec *spec = codec->spec;
5899
5900 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5901 return;
5902
Kailang Yang1387e2d2012-11-08 10:23:18 +01005903 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5904 alc269vb_toggle_power_output(codec, 0);
5905 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5906 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005907 msleep(150);
5908 }
5909}
5910
Takashi Iwai2a439522011-07-26 09:52:50 +02005911#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005912static int alc269_resume(struct hda_codec *codec)
5913{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005914 struct alc_spec *spec = codec->spec;
5915
Kailang Yang1387e2d2012-11-08 10:23:18 +01005916 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5917 alc269vb_toggle_power_output(codec, 0);
5918 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005919 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005920 msleep(150);
5921 }
5922
5923 codec->patch_ops.init(codec);
5924
Kailang Yang1387e2d2012-11-08 10:23:18 +01005925 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5926 alc269vb_toggle_power_output(codec, 1);
5927 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005928 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005929 msleep(200);
5930 }
5931
Takashi Iwai1d045db2011-07-07 18:23:21 +02005932 snd_hda_codec_resume_amp(codec);
5933 snd_hda_codec_resume_cache(codec);
5934 hda_call_check_power_status(codec, 0x01);
5935 return 0;
5936}
Takashi Iwai2a439522011-07-26 09:52:50 +02005937#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005938
David Henningsson108cc102012-07-20 10:37:25 +02005939static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5940 const struct alc_fixup *fix, int action)
5941{
5942 struct alc_spec *spec = codec->spec;
5943
5944 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5945 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5946}
5947
Takashi Iwai1d045db2011-07-07 18:23:21 +02005948static void alc269_fixup_hweq(struct hda_codec *codec,
5949 const struct alc_fixup *fix, int action)
5950{
5951 int coef;
5952
5953 if (action != ALC_FIXUP_ACT_INIT)
5954 return;
5955 coef = alc_read_coef_idx(codec, 0x1e);
5956 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5957}
5958
5959static void alc271_fixup_dmic(struct hda_codec *codec,
5960 const struct alc_fixup *fix, int action)
5961{
5962 static const struct hda_verb verbs[] = {
5963 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5964 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5965 {}
5966 };
5967 unsigned int cfg;
5968
5969 if (strcmp(codec->chip_name, "ALC271X"))
5970 return;
5971 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5972 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5973 snd_hda_sequence_write(codec, verbs);
5974}
5975
Takashi Iwai017f2a12011-07-09 14:42:25 +02005976static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5977 const struct alc_fixup *fix, int action)
5978{
5979 struct alc_spec *spec = codec->spec;
5980
5981 if (action != ALC_FIXUP_ACT_PROBE)
5982 return;
5983
5984 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5985 * fix the sample rate of analog I/O to 44.1kHz
5986 */
5987 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5988 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5989}
5990
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005991static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5992 const struct alc_fixup *fix, int action)
5993{
5994 int coef;
5995
5996 if (action != ALC_FIXUP_ACT_INIT)
5997 return;
5998 /* The digital-mic unit sends PDM (differential signal) instead of
5999 * the standard PCM, thus you can't record a valid mono stream as is.
6000 * Below is a workaround specific to ALC269 to control the dmic
6001 * signal source as mono.
6002 */
6003 coef = alc_read_coef_idx(codec, 0x07);
6004 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6005}
6006
Takashi Iwai24519912011-08-16 15:08:49 +02006007static void alc269_quanta_automute(struct hda_codec *codec)
6008{
David Henningsson42cf0d02011-09-20 12:04:56 +02006009 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006010
6011 snd_hda_codec_write(codec, 0x20, 0,
6012 AC_VERB_SET_COEF_INDEX, 0x0c);
6013 snd_hda_codec_write(codec, 0x20, 0,
6014 AC_VERB_SET_PROC_COEF, 0x680);
6015
6016 snd_hda_codec_write(codec, 0x20, 0,
6017 AC_VERB_SET_COEF_INDEX, 0x0c);
6018 snd_hda_codec_write(codec, 0x20, 0,
6019 AC_VERB_SET_PROC_COEF, 0x480);
6020}
6021
6022static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6023 const struct alc_fixup *fix, int action)
6024{
6025 struct alc_spec *spec = codec->spec;
6026 if (action != ALC_FIXUP_ACT_PROBE)
6027 return;
6028 spec->automute_hook = alc269_quanta_automute;
6029}
6030
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006031/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6032static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6033{
6034 struct hda_codec *codec = private_data;
6035 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6036 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6037 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6038}
6039
6040static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6041 const struct alc_fixup *fix, int action)
6042{
6043 struct alc_spec *spec = codec->spec;
6044 switch (action) {
6045 case ALC_FIXUP_ACT_BUILD:
6046 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6047 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6048 /* fallthru */
6049 case ALC_FIXUP_ACT_INIT:
6050 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6051 break;
6052 }
6053}
6054
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006055/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6056static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6057{
6058 struct hda_codec *codec = private_data;
6059 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006060 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006061}
6062
6063static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6064 const struct alc_fixup *fix, int action)
6065{
6066 struct alc_spec *spec = codec->spec;
6067 switch (action) {
6068 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006069 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006070 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006071 /* fallthru */
6072 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006073 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006074 break;
6075 }
6076}
6077
Dylan Reid08a978d2012-11-18 22:56:40 -08006078static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6079 const struct alc_fixup *fix,
6080 int action)
6081{
6082 struct alc_spec *spec = codec->spec;
6083
6084 if (action == ALC_FIXUP_ACT_PROBE)
6085 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6086 spec->autocfg.hp_pins[0]);
6087}
David Henningsson693b6132012-06-22 19:12:10 +02006088
Takashi Iwai1d045db2011-07-07 18:23:21 +02006089enum {
6090 ALC269_FIXUP_SONY_VAIO,
6091 ALC275_FIXUP_SONY_VAIO_GPIO2,
6092 ALC269_FIXUP_DELL_M101Z,
6093 ALC269_FIXUP_SKU_IGNORE,
6094 ALC269_FIXUP_ASUS_G73JW,
6095 ALC269_FIXUP_LENOVO_EAPD,
6096 ALC275_FIXUP_SONY_HWEQ,
6097 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006098 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006099 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006100 ALC269_FIXUP_QUANTA_MUTE,
6101 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006102 ALC269_FIXUP_AMIC,
6103 ALC269_FIXUP_DMIC,
6104 ALC269VB_FIXUP_AMIC,
6105 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006106 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006107 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006108 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006109 ALC269_FIXUP_LENOVO_DOCK,
6110 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006111 ALC271_FIXUP_AMIC_MIC2,
6112 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006113};
6114
6115static const struct alc_fixup alc269_fixups[] = {
6116 [ALC269_FIXUP_SONY_VAIO] = {
6117 .type = ALC_FIXUP_VERBS,
6118 .v.verbs = (const struct hda_verb[]) {
6119 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6120 {}
6121 }
6122 },
6123 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6124 .type = ALC_FIXUP_VERBS,
6125 .v.verbs = (const struct hda_verb[]) {
6126 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6127 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6128 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6129 { }
6130 },
6131 .chained = true,
6132 .chain_id = ALC269_FIXUP_SONY_VAIO
6133 },
6134 [ALC269_FIXUP_DELL_M101Z] = {
6135 .type = ALC_FIXUP_VERBS,
6136 .v.verbs = (const struct hda_verb[]) {
6137 /* Enables internal speaker */
6138 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6139 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6140 {}
6141 }
6142 },
6143 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006144 .type = ALC_FIXUP_FUNC,
6145 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006146 },
6147 [ALC269_FIXUP_ASUS_G73JW] = {
6148 .type = ALC_FIXUP_PINS,
6149 .v.pins = (const struct alc_pincfg[]) {
6150 { 0x17, 0x99130111 }, /* subwoofer */
6151 { }
6152 }
6153 },
6154 [ALC269_FIXUP_LENOVO_EAPD] = {
6155 .type = ALC_FIXUP_VERBS,
6156 .v.verbs = (const struct hda_verb[]) {
6157 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6158 {}
6159 }
6160 },
6161 [ALC275_FIXUP_SONY_HWEQ] = {
6162 .type = ALC_FIXUP_FUNC,
6163 .v.func = alc269_fixup_hweq,
6164 .chained = true,
6165 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6166 },
6167 [ALC271_FIXUP_DMIC] = {
6168 .type = ALC_FIXUP_FUNC,
6169 .v.func = alc271_fixup_dmic,
6170 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006171 [ALC269_FIXUP_PCM_44K] = {
6172 .type = ALC_FIXUP_FUNC,
6173 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006174 .chained = true,
6175 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006176 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006177 [ALC269_FIXUP_STEREO_DMIC] = {
6178 .type = ALC_FIXUP_FUNC,
6179 .v.func = alc269_fixup_stereo_dmic,
6180 },
Takashi Iwai24519912011-08-16 15:08:49 +02006181 [ALC269_FIXUP_QUANTA_MUTE] = {
6182 .type = ALC_FIXUP_FUNC,
6183 .v.func = alc269_fixup_quanta_mute,
6184 },
6185 [ALC269_FIXUP_LIFEBOOK] = {
6186 .type = ALC_FIXUP_PINS,
6187 .v.pins = (const struct alc_pincfg[]) {
6188 { 0x1a, 0x2101103f }, /* dock line-out */
6189 { 0x1b, 0x23a11040 }, /* dock mic-in */
6190 { }
6191 },
6192 .chained = true,
6193 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6194 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006195 [ALC269_FIXUP_AMIC] = {
6196 .type = ALC_FIXUP_PINS,
6197 .v.pins = (const struct alc_pincfg[]) {
6198 { 0x14, 0x99130110 }, /* speaker */
6199 { 0x15, 0x0121401f }, /* HP out */
6200 { 0x18, 0x01a19c20 }, /* mic */
6201 { 0x19, 0x99a3092f }, /* int-mic */
6202 { }
6203 },
6204 },
6205 [ALC269_FIXUP_DMIC] = {
6206 .type = ALC_FIXUP_PINS,
6207 .v.pins = (const struct alc_pincfg[]) {
6208 { 0x12, 0x99a3092f }, /* int-mic */
6209 { 0x14, 0x99130110 }, /* speaker */
6210 { 0x15, 0x0121401f }, /* HP out */
6211 { 0x18, 0x01a19c20 }, /* mic */
6212 { }
6213 },
6214 },
6215 [ALC269VB_FIXUP_AMIC] = {
6216 .type = ALC_FIXUP_PINS,
6217 .v.pins = (const struct alc_pincfg[]) {
6218 { 0x14, 0x99130110 }, /* speaker */
6219 { 0x18, 0x01a19c20 }, /* mic */
6220 { 0x19, 0x99a3092f }, /* int-mic */
6221 { 0x21, 0x0121401f }, /* HP out */
6222 { }
6223 },
6224 },
David Henningsson2267ea92012-01-03 08:45:56 +01006225 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006226 .type = ALC_FIXUP_PINS,
6227 .v.pins = (const struct alc_pincfg[]) {
6228 { 0x12, 0x99a3092f }, /* int-mic */
6229 { 0x14, 0x99130110 }, /* speaker */
6230 { 0x18, 0x01a19c20 }, /* mic */
6231 { 0x21, 0x0121401f }, /* HP out */
6232 { }
6233 },
6234 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006235 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6236 .type = ALC_FIXUP_FUNC,
6237 .v.func = alc269_fixup_mic1_mute,
6238 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006239 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6240 .type = ALC_FIXUP_FUNC,
6241 .v.func = alc269_fixup_mic2_mute,
6242 },
David Henningsson693b6132012-06-22 19:12:10 +02006243 [ALC269_FIXUP_INV_DMIC] = {
6244 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006245 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006246 },
David Henningsson108cc102012-07-20 10:37:25 +02006247 [ALC269_FIXUP_LENOVO_DOCK] = {
6248 .type = ALC_FIXUP_PINS,
6249 .v.pins = (const struct alc_pincfg[]) {
6250 { 0x19, 0x23a11040 }, /* dock mic */
6251 { 0x1b, 0x2121103f }, /* dock headphone */
6252 { }
6253 },
6254 .chained = true,
6255 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6256 },
6257 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6258 .type = ALC_FIXUP_FUNC,
6259 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6260 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006261 [ALC271_FIXUP_AMIC_MIC2] = {
6262 .type = ALC_FIXUP_PINS,
6263 .v.pins = (const struct alc_pincfg[]) {
6264 { 0x14, 0x99130110 }, /* speaker */
6265 { 0x19, 0x01a19c20 }, /* mic */
6266 { 0x1b, 0x99a7012f }, /* int-mic */
6267 { 0x21, 0x0121401f }, /* HP out */
6268 { }
6269 },
6270 },
6271 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6272 .type = ALC_FIXUP_FUNC,
6273 .v.func = alc271_hp_gate_mic_jack,
6274 .chained = true,
6275 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6276 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006277};
6278
6279static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006280 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6281 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006282 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006283 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006284 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006285 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006286 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006287 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006288 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6289 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6290 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6291 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6292 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006293 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6294 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6295 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6296 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6297 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006298 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006300 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006301 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6302 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6303 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6304 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6305 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006306 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006307 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006308 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006309 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006310 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006311 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006312 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006313
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006314#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006315 /* Below is a quirk table taken from the old code.
6316 * Basically the device should work as is without the fixup table.
6317 * If BIOS doesn't give a proper info, enable the corresponding
6318 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006319 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006320 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6321 ALC269_FIXUP_AMIC),
6322 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006323 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6324 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6325 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6326 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6327 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6328 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6329 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6330 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6331 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6332 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6333 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6334 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6335 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6336 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6337 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6338 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6339 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6340 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6341 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6342 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6343 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6344 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6345 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6346 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6347 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6348 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6349 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6350 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6351 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6352 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6353 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6354 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6355 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6356 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6357 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6358 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6359 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6360 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6361#endif
6362 {}
6363};
6364
6365static const struct alc_model_fixup alc269_fixup_models[] = {
6366 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6367 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006368 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6369 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6370 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006371 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006372 {}
6373};
6374
6375
Takashi Iwai546bb672012-03-07 08:37:19 +01006376static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006377{
Kailang Yang526af6e2012-03-07 08:25:20 +01006378 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006379 int val;
6380
Kailang Yang526af6e2012-03-07 08:25:20 +01006381 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006382 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006383
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006384 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006385 alc_write_coef_idx(codec, 0xf, 0x960b);
6386 alc_write_coef_idx(codec, 0xe, 0x8817);
6387 }
6388
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006389 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006390 alc_write_coef_idx(codec, 0xf, 0x960b);
6391 alc_write_coef_idx(codec, 0xe, 0x8814);
6392 }
6393
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006394 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006395 val = alc_read_coef_idx(codec, 0x04);
6396 /* Power up output pin */
6397 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6398 }
6399
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006400 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006401 val = alc_read_coef_idx(codec, 0xd);
6402 if ((val & 0x0c00) >> 10 != 0x1) {
6403 /* Capless ramp up clock control */
6404 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6405 }
6406 val = alc_read_coef_idx(codec, 0x17);
6407 if ((val & 0x01c0) >> 6 != 0x4) {
6408 /* Class D power on reset */
6409 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6410 }
6411 }
6412
6413 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6414 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6415
6416 val = alc_read_coef_idx(codec, 0x4); /* HP */
6417 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006418}
6419
6420/*
6421 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006422static int patch_alc269(struct hda_codec *codec)
6423{
6424 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006425 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006426
Takashi Iwai3de95172012-05-07 18:03:15 +02006427 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006428 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006429 return err;
6430
6431 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006432
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006433 alc_pick_fixup(codec, alc269_fixup_models,
6434 alc269_fixup_tbl, alc269_fixups);
6435 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6436
6437 alc_auto_parse_customize_define(codec);
6438
Kailang Yang065380f2013-01-10 10:25:48 +01006439 switch (codec->vendor_id) {
6440 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006441 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006442 switch (alc_get_coef0(codec) & 0x00f0) {
6443 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006444 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006445 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006446 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006447 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006448 break;
6449 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006450 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6451 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006452 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006453 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006454 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006455 case 0x0030:
6456 spec->codec_variant = ALC269_TYPE_ALC269VD;
6457 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006458 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006459 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006460 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006461 if (err < 0)
6462 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006463 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006464 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006465 break;
6466
6467 case 0x10ec0280:
6468 case 0x10ec0290:
6469 spec->codec_variant = ALC269_TYPE_ALC280;
6470 break;
6471 case 0x10ec0282:
6472 case 0x10ec0283:
6473 spec->codec_variant = ALC269_TYPE_ALC282;
6474 break;
6475 case 0x10ec0284:
6476 case 0x10ec0292:
6477 spec->codec_variant = ALC269_TYPE_ALC284;
6478 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006479 }
6480
Takashi Iwaia4297b52011-08-23 18:40:12 +02006481 /* automatic parse from the BIOS config */
6482 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006483 if (err < 0)
6484 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006485
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006486 if (!spec->no_analog && has_cdefine_beep(codec)) {
6487 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006488 if (err < 0)
6489 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006490 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006491 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006492
Takashi Iwai1d045db2011-07-07 18:23:21 +02006493 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006494#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006495 codec->patch_ops.resume = alc269_resume;
6496#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006497 spec->shutup = alc269_shutup;
6498
Takashi Iwai589876e2012-02-20 15:47:55 +01006499 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6500
Takashi Iwai1d045db2011-07-07 18:23:21 +02006501 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006502
6503 error:
6504 alc_free(codec);
6505 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006506}
6507
6508/*
6509 * ALC861
6510 */
6511
Takashi Iwai1d045db2011-07-07 18:23:21 +02006512static int alc861_parse_auto_config(struct hda_codec *codec)
6513{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006514 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006515 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6516 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006517}
6518
Takashi Iwai1d045db2011-07-07 18:23:21 +02006519/* Pin config fixes */
6520enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006521 ALC861_FIXUP_FSC_AMILO_PI1505,
6522 ALC861_FIXUP_AMP_VREF_0F,
6523 ALC861_FIXUP_NO_JACK_DETECT,
6524 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006525};
6526
Takashi Iwai31150f22012-01-30 10:54:08 +01006527/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6528static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6529 const struct alc_fixup *fix, int action)
6530{
6531 struct alc_spec *spec = codec->spec;
6532 unsigned int val;
6533
6534 if (action != ALC_FIXUP_ACT_INIT)
6535 return;
6536 val = snd_hda_codec_read(codec, 0x0f, 0,
6537 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6538 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6539 val |= AC_PINCTL_IN_EN;
6540 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006541 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006542 spec->keep_vref_in_automute = 1;
6543}
6544
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006545/* suppress the jack-detection */
6546static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6547 const struct alc_fixup *fix, int action)
6548{
6549 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6550 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006551}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006552
Takashi Iwai1d045db2011-07-07 18:23:21 +02006553static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006554 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006555 .type = ALC_FIXUP_PINS,
6556 .v.pins = (const struct alc_pincfg[]) {
6557 { 0x0b, 0x0221101f }, /* HP */
6558 { 0x0f, 0x90170310 }, /* speaker */
6559 { }
6560 }
6561 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006562 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006563 .type = ALC_FIXUP_FUNC,
6564 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006565 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006566 [ALC861_FIXUP_NO_JACK_DETECT] = {
6567 .type = ALC_FIXUP_FUNC,
6568 .v.func = alc_fixup_no_jack_detect,
6569 },
6570 [ALC861_FIXUP_ASUS_A6RP] = {
6571 .type = ALC_FIXUP_FUNC,
6572 .v.func = alc861_fixup_asus_amp_vref_0f,
6573 .chained = true,
6574 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6575 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006576};
6577
6578static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006579 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6580 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6581 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6582 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6583 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6584 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006585 {}
6586};
6587
6588/*
6589 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006590static int patch_alc861(struct hda_codec *codec)
6591{
6592 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006593 int err;
6594
Takashi Iwai3de95172012-05-07 18:03:15 +02006595 err = alc_alloc_spec(codec, 0x15);
6596 if (err < 0)
6597 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006598
Takashi Iwai3de95172012-05-07 18:03:15 +02006599 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006600
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006601 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6602 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006603
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006604 /* automatic parse from the BIOS config */
6605 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006606 if (err < 0)
6607 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006608
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006609 if (!spec->no_analog) {
6610 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006611 if (err < 0)
6612 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006613 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6614 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006615
Takashi Iwai1d045db2011-07-07 18:23:21 +02006616 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006617#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006618 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006619#endif
6620
Takashi Iwai589876e2012-02-20 15:47:55 +01006621 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6622
Takashi Iwai1d045db2011-07-07 18:23:21 +02006623 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006624
6625 error:
6626 alc_free(codec);
6627 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006628}
6629
6630/*
6631 * ALC861-VD support
6632 *
6633 * Based on ALC882
6634 *
6635 * In addition, an independent DAC
6636 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006637static int alc861vd_parse_auto_config(struct hda_codec *codec)
6638{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006639 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006640 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6641 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006642}
6643
Takashi Iwai1d045db2011-07-07 18:23:21 +02006644enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006645 ALC660VD_FIX_ASUS_GPIO1,
6646 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006647};
6648
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006649/* exclude VREF80 */
6650static void alc861vd_fixup_dallas(struct hda_codec *codec,
6651 const struct alc_fixup *fix, int action)
6652{
6653 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006654 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6655 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006656 }
6657}
6658
Takashi Iwai1d045db2011-07-07 18:23:21 +02006659static const struct alc_fixup alc861vd_fixups[] = {
6660 [ALC660VD_FIX_ASUS_GPIO1] = {
6661 .type = ALC_FIXUP_VERBS,
6662 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006663 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006664 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6665 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6666 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6667 { }
6668 }
6669 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006670 [ALC861VD_FIX_DALLAS] = {
6671 .type = ALC_FIXUP_FUNC,
6672 .v.func = alc861vd_fixup_dallas,
6673 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006674};
6675
6676static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006677 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006678 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006679 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006680 {}
6681};
6682
Takashi Iwai1d045db2011-07-07 18:23:21 +02006683/*
6684 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006685static int patch_alc861vd(struct hda_codec *codec)
6686{
6687 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006688 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006689
Takashi Iwai3de95172012-05-07 18:03:15 +02006690 err = alc_alloc_spec(codec, 0x0b);
6691 if (err < 0)
6692 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006693
Takashi Iwai3de95172012-05-07 18:03:15 +02006694 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006695
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006696 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6697 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006698
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006699 /* automatic parse from the BIOS config */
6700 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006701 if (err < 0)
6702 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006703
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006704 if (!spec->no_analog) {
6705 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006706 if (err < 0)
6707 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006708 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6709 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006710
Takashi Iwai1d045db2011-07-07 18:23:21 +02006711 codec->patch_ops = alc_patch_ops;
6712
Takashi Iwai1d045db2011-07-07 18:23:21 +02006713 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006714
Takashi Iwai589876e2012-02-20 15:47:55 +01006715 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6716
Takashi Iwai1d045db2011-07-07 18:23:21 +02006717 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006718
6719 error:
6720 alc_free(codec);
6721 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006722}
6723
6724/*
6725 * ALC662 support
6726 *
6727 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6728 * configuration. Each pin widget can choose any input DACs and a mixer.
6729 * Each ADC is connected from a mixer of all inputs. This makes possible
6730 * 6-channel independent captures.
6731 *
6732 * In addition, an independent DAC for the multi-playback (not used in this
6733 * driver yet).
6734 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006735
6736/*
6737 * BIOS auto configuration
6738 */
6739
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006740static int alc662_parse_auto_config(struct hda_codec *codec)
6741{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006742 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006743 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6744 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6745 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006746
Kailang Yang6227cdc2010-02-25 08:36:52 +01006747 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6748 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006749 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006750 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006751 ssids = alc662_ssids;
6752 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006753}
6754
Todd Broch6be79482010-12-07 16:51:05 -08006755static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006756 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006757{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006758 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006759 return;
Todd Broch6be79482010-12-07 16:51:05 -08006760 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6761 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6762 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6763 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6764 (0 << AC_AMPCAP_MUTE_SHIFT)))
6765 printk(KERN_WARNING
6766 "hda_codec: failed to override amp caps for NID 0x2\n");
6767}
6768
David Henningsson6cb3b702010-09-09 08:51:44 +02006769enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006770 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006771 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006772 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006773 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006774 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006775 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006776 ALC662_FIXUP_ASUS_MODE1,
6777 ALC662_FIXUP_ASUS_MODE2,
6778 ALC662_FIXUP_ASUS_MODE3,
6779 ALC662_FIXUP_ASUS_MODE4,
6780 ALC662_FIXUP_ASUS_MODE5,
6781 ALC662_FIXUP_ASUS_MODE6,
6782 ALC662_FIXUP_ASUS_MODE7,
6783 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006784 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006785 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006786 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006787};
6788
6789static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006790 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006791 .type = ALC_FIXUP_PINS,
6792 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006793 { 0x15, 0x99130112 }, /* subwoofer */
6794 { }
6795 }
6796 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006797 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006798 .type = ALC_FIXUP_PINS,
6799 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006800 { 0x17, 0x99130112 }, /* subwoofer */
6801 { }
6802 }
6803 },
Todd Broch6be79482010-12-07 16:51:05 -08006804 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006805 .type = ALC_FIXUP_FUNC,
6806 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006807 },
6808 [ALC662_FIXUP_CZC_P10T] = {
6809 .type = ALC_FIXUP_VERBS,
6810 .v.verbs = (const struct hda_verb[]) {
6811 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6812 {}
6813 }
6814 },
David Henningsson94024cd2011-04-29 14:10:55 +02006815 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006816 .type = ALC_FIXUP_FUNC,
6817 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006818 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006819 [ALC662_FIXUP_HP_RP5800] = {
6820 .type = ALC_FIXUP_PINS,
6821 .v.pins = (const struct alc_pincfg[]) {
6822 { 0x14, 0x0221201f }, /* HP out */
6823 { }
6824 },
6825 .chained = true,
6826 .chain_id = ALC662_FIXUP_SKU_IGNORE
6827 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006828 [ALC662_FIXUP_ASUS_MODE1] = {
6829 .type = ALC_FIXUP_PINS,
6830 .v.pins = (const struct alc_pincfg[]) {
6831 { 0x14, 0x99130110 }, /* speaker */
6832 { 0x18, 0x01a19c20 }, /* mic */
6833 { 0x19, 0x99a3092f }, /* int-mic */
6834 { 0x21, 0x0121401f }, /* HP out */
6835 { }
6836 },
6837 .chained = true,
6838 .chain_id = ALC662_FIXUP_SKU_IGNORE
6839 },
6840 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006841 .type = ALC_FIXUP_PINS,
6842 .v.pins = (const struct alc_pincfg[]) {
6843 { 0x14, 0x99130110 }, /* speaker */
6844 { 0x18, 0x01a19820 }, /* mic */
6845 { 0x19, 0x99a3092f }, /* int-mic */
6846 { 0x1b, 0x0121401f }, /* HP out */
6847 { }
6848 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006849 .chained = true,
6850 .chain_id = ALC662_FIXUP_SKU_IGNORE
6851 },
6852 [ALC662_FIXUP_ASUS_MODE3] = {
6853 .type = ALC_FIXUP_PINS,
6854 .v.pins = (const struct alc_pincfg[]) {
6855 { 0x14, 0x99130110 }, /* speaker */
6856 { 0x15, 0x0121441f }, /* HP */
6857 { 0x18, 0x01a19840 }, /* mic */
6858 { 0x19, 0x99a3094f }, /* int-mic */
6859 { 0x21, 0x01211420 }, /* HP2 */
6860 { }
6861 },
6862 .chained = true,
6863 .chain_id = ALC662_FIXUP_SKU_IGNORE
6864 },
6865 [ALC662_FIXUP_ASUS_MODE4] = {
6866 .type = ALC_FIXUP_PINS,
6867 .v.pins = (const struct alc_pincfg[]) {
6868 { 0x14, 0x99130110 }, /* speaker */
6869 { 0x16, 0x99130111 }, /* speaker */
6870 { 0x18, 0x01a19840 }, /* mic */
6871 { 0x19, 0x99a3094f }, /* int-mic */
6872 { 0x21, 0x0121441f }, /* HP */
6873 { }
6874 },
6875 .chained = true,
6876 .chain_id = ALC662_FIXUP_SKU_IGNORE
6877 },
6878 [ALC662_FIXUP_ASUS_MODE5] = {
6879 .type = ALC_FIXUP_PINS,
6880 .v.pins = (const struct alc_pincfg[]) {
6881 { 0x14, 0x99130110 }, /* speaker */
6882 { 0x15, 0x0121441f }, /* HP */
6883 { 0x16, 0x99130111 }, /* speaker */
6884 { 0x18, 0x01a19840 }, /* mic */
6885 { 0x19, 0x99a3094f }, /* int-mic */
6886 { }
6887 },
6888 .chained = true,
6889 .chain_id = ALC662_FIXUP_SKU_IGNORE
6890 },
6891 [ALC662_FIXUP_ASUS_MODE6] = {
6892 .type = ALC_FIXUP_PINS,
6893 .v.pins = (const struct alc_pincfg[]) {
6894 { 0x14, 0x99130110 }, /* speaker */
6895 { 0x15, 0x01211420 }, /* HP2 */
6896 { 0x18, 0x01a19840 }, /* mic */
6897 { 0x19, 0x99a3094f }, /* int-mic */
6898 { 0x1b, 0x0121441f }, /* HP */
6899 { }
6900 },
6901 .chained = true,
6902 .chain_id = ALC662_FIXUP_SKU_IGNORE
6903 },
6904 [ALC662_FIXUP_ASUS_MODE7] = {
6905 .type = ALC_FIXUP_PINS,
6906 .v.pins = (const struct alc_pincfg[]) {
6907 { 0x14, 0x99130110 }, /* speaker */
6908 { 0x17, 0x99130111 }, /* speaker */
6909 { 0x18, 0x01a19840 }, /* mic */
6910 { 0x19, 0x99a3094f }, /* int-mic */
6911 { 0x1b, 0x01214020 }, /* HP */
6912 { 0x21, 0x0121401f }, /* HP */
6913 { }
6914 },
6915 .chained = true,
6916 .chain_id = ALC662_FIXUP_SKU_IGNORE
6917 },
6918 [ALC662_FIXUP_ASUS_MODE8] = {
6919 .type = ALC_FIXUP_PINS,
6920 .v.pins = (const struct alc_pincfg[]) {
6921 { 0x14, 0x99130110 }, /* speaker */
6922 { 0x12, 0x99a30970 }, /* int-mic */
6923 { 0x15, 0x01214020 }, /* HP */
6924 { 0x17, 0x99130111 }, /* speaker */
6925 { 0x18, 0x01a19840 }, /* mic */
6926 { 0x21, 0x0121401f }, /* HP */
6927 { }
6928 },
6929 .chained = true,
6930 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006931 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006932 [ALC662_FIXUP_NO_JACK_DETECT] = {
6933 .type = ALC_FIXUP_FUNC,
6934 .v.func = alc_fixup_no_jack_detect,
6935 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006936 [ALC662_FIXUP_ZOTAC_Z68] = {
6937 .type = ALC_FIXUP_PINS,
6938 .v.pins = (const struct alc_pincfg[]) {
6939 { 0x1b, 0x02214020 }, /* Front HP */
6940 { }
6941 }
6942 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006943 [ALC662_FIXUP_INV_DMIC] = {
6944 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006945 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006946 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006947};
6948
Takashi Iwaia9111322011-05-02 11:30:18 +02006949static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006950 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006951 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006952 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006953 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006954 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006955 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006956 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006957 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006958 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006959 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006960 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006961 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006962 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006963
6964#if 0
6965 /* Below is a quirk table taken from the old code.
6966 * Basically the device should work as is without the fixup table.
6967 * If BIOS doesn't give a proper info, enable the corresponding
6968 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006969 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006970 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6971 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6972 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6973 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6974 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6975 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6976 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6977 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6978 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6979 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6980 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6981 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6982 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6983 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6984 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6985 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6986 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6987 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6988 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6989 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6990 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6991 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6992 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6993 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6994 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6995 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6996 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6997 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6998 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6999 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7000 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7001 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7002 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7003 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7004 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7005 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7006 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7007 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7008 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7009 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7010 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7011 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7012 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7013 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7014 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7015 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7016 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7017 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7018 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7019 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7020#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007021 {}
7022};
7023
Todd Broch6be79482010-12-07 16:51:05 -08007024static const struct alc_model_fixup alc662_fixup_models[] = {
7025 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007026 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7027 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7028 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7029 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7030 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7031 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7032 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7033 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007034 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007035 {}
7036};
David Henningsson6cb3b702010-09-09 08:51:44 +02007037
Kailang Yang8663ff72012-06-29 09:35:52 +02007038static void alc662_fill_coef(struct hda_codec *codec)
7039{
7040 int val, coef;
7041
7042 coef = alc_get_coef0(codec);
7043
7044 switch (codec->vendor_id) {
7045 case 0x10ec0662:
7046 if ((coef & 0x00f0) == 0x0030) {
7047 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7048 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7049 }
7050 break;
7051 case 0x10ec0272:
7052 case 0x10ec0273:
7053 case 0x10ec0663:
7054 case 0x10ec0665:
7055 case 0x10ec0670:
7056 case 0x10ec0671:
7057 case 0x10ec0672:
7058 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7059 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7060 break;
7061 }
7062}
David Henningsson6cb3b702010-09-09 08:51:44 +02007063
Takashi Iwai1d045db2011-07-07 18:23:21 +02007064/*
7065 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007066static int patch_alc662(struct hda_codec *codec)
7067{
7068 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007069 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007070
Takashi Iwai3de95172012-05-07 18:03:15 +02007071 err = alc_alloc_spec(codec, 0x0b);
7072 if (err < 0)
7073 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007074
Takashi Iwai3de95172012-05-07 18:03:15 +02007075 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007076
Takashi Iwai53c334a2011-08-23 18:27:14 +02007077 /* handle multiple HPs as is */
7078 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7079
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007080 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7081
Kailang Yang8663ff72012-06-29 09:35:52 +02007082 spec->init_hook = alc662_fill_coef;
7083 alc662_fill_coef(codec);
7084
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007085 alc_pick_fixup(codec, alc662_fixup_models,
7086 alc662_fixup_tbl, alc662_fixups);
7087 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7088
7089 alc_auto_parse_customize_define(codec);
7090
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007091 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007092 codec->bus->pci->subsystem_vendor == 0x1025 &&
7093 spec->cdefine.platform_type == 1) {
7094 if (alc_codec_rename(codec, "ALC272X") < 0)
7095 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007096 }
Kailang Yang274693f2009-12-03 10:07:50 +01007097
Takashi Iwaib9c51062011-08-24 18:08:07 +02007098 /* automatic parse from the BIOS config */
7099 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007100 if (err < 0)
7101 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007102
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007103 if (!spec->no_analog && has_cdefine_beep(codec)) {
7104 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007105 if (err < 0)
7106 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007107 switch (codec->vendor_id) {
7108 case 0x10ec0662:
7109 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7110 break;
7111 case 0x10ec0272:
7112 case 0x10ec0663:
7113 case 0x10ec0665:
7114 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7115 break;
7116 case 0x10ec0273:
7117 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7118 break;
7119 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007120 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007121
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007122 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007123 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007124
Takashi Iwai589876e2012-02-20 15:47:55 +01007125 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7126
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007127 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007128
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007129 error:
7130 alc_free(codec);
7131 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007132}
7133
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007134/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007135 * ALC680 support
7136 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007137
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007138static int alc680_parse_auto_config(struct hda_codec *codec)
7139{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007140 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007141}
7142
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007143/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007144 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007145static int patch_alc680(struct hda_codec *codec)
7146{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007147 int err;
7148
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007149 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007150 err = alc_alloc_spec(codec, 0);
7151 if (err < 0)
7152 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007153
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007154 /* automatic parse from the BIOS config */
7155 err = alc680_parse_auto_config(codec);
7156 if (err < 0) {
7157 alc_free(codec);
7158 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007159 }
7160
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007161 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007162
7163 return 0;
7164}
7165
7166/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007167 * patch entries
7168 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007169static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007170 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007171 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007172 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007173 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007174 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007175 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007176 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007177 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007178 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007179 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007180 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007181 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007182 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007183 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007184 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007185 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007186 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007187 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007188 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7189 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7190 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007191 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007192 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007193 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7194 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007195 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7196 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007197 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007198 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007199 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007200 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007201 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007202 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007203 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007204 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007205 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007206 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007207 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007208 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007209 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007210 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007211 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007212 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007213 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007214 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007215 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007216 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007217 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007218 {} /* terminator */
7219};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007220
7221MODULE_ALIAS("snd-hda-codec-id:10ec*");
7222
7223MODULE_LICENSE("GPL");
7224MODULE_DESCRIPTION("Realtek HD-audio codec");
7225
7226static struct hda_codec_preset_list realtek_list = {
7227 .preset = snd_hda_preset_realtek,
7228 .owner = THIS_MODULE,
7229};
7230
7231static int __init patch_realtek_init(void)
7232{
7233 return snd_hda_add_codec_preset(&realtek_list);
7234}
7235
7236static void __exit patch_realtek_exit(void)
7237{
7238 snd_hda_delete_codec_preset(&realtek_list);
7239}
7240
7241module_init(patch_realtek_init)
7242module_exit(patch_realtek_exit)