blob: 3ee2be544f4da0a470006633b5f8b6eeeae07913 [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 Iwaia9111322011-05-02 11:30:18 +0200131 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100132 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200134 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200135 const struct hda_pcm_stream *stream_analog_playback;
136 const struct hda_pcm_stream *stream_analog_capture;
137 const struct hda_pcm_stream *stream_analog_alt_playback;
138 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200140 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200141 const struct hda_pcm_stream *stream_digital_playback;
142 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200145 struct hda_multi_out multiout; /* playback set-up
146 * max_channels, dacs must be set
147 * dig_out_nid and hp_nid are optional
148 */
Takashi Iwai63300792008-01-24 15:31:36 +0100149 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100150 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100151 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* capture */
154 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200155 const hda_nid_t *adc_nids;
156 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200157 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200158 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Takashi Iwai840b64c2010-07-13 22:49:01 +0200160 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200161 hda_nid_t cur_adc;
162 unsigned int cur_adc_stream_tag;
163 unsigned int cur_adc_format;
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200166 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 const struct hda_input_mux *input_mux;
168 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200169 hda_nid_t ext_mic_pin;
170 hda_nid_t dock_mic_pin;
171 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100174 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200176 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100177 int const_channel_count; /* min. channel count (for speakers) */
178 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100181 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200182
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200183 /* dynamic controls, init_verbs and input_mux */
184 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100185 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200186 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200187 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200188 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200189 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
190 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200191 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
192 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
193 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200194 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100195
Takashi Iwai463419d2012-12-05 14:17:37 +0100196 /* DAC list */
197 int num_all_dacs;
198 hda_nid_t all_dacs[16];
199
Takashi Iwaic9967f12012-12-14 16:39:22 +0100200 /* path list */
201 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100202
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100203 /* hooks */
204 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200205#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500206 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100207#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200208 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200209 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100210
Takashi Iwai834be882006-03-01 14:16:17 +0100211 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200212 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200213 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200214 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200215 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200216 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200217 unsigned int automute_speaker:1; /* automute speaker outputs */
218 unsigned int automute_lo:1; /* automute LO outputs */
219 unsigned int detect_hp:1; /* Headphone detection enabled */
220 unsigned int detect_lo:1; /* Line-out detection enabled */
221 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
222 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100223 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200224
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100225 /* other flags */
226 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200227 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100228 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200229 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200230 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100231 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200232 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
233 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200234 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200235
236 /* auto-mute control */
237 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200238 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200239
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200240 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200241 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100242
Takashi Iwai2134ea42008-01-10 16:53:55 +0100243 /* for virtual master */
244 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100245 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200246#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200247 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100248 int num_loopbacks;
249 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200250#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200251
252 /* for PLL fix */
253 hda_nid_t pll_nid;
254 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200255 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100256
Takashi Iwaice764ab2011-04-27 16:35:23 +0200257 /* multi-io */
258 int multi_ios;
259 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200260
261 /* bind volumes */
262 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100263};
264
Takashi Iwai44c02402011-07-08 15:14:19 +0200265static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
266 int dir, unsigned int bits)
267{
268 if (!nid)
269 return false;
270 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
271 if (query_amp_caps(codec, nid, dir) & bits)
272 return true;
273 return false;
274}
275
276#define nid_has_mute(codec, nid, dir) \
277 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
278#define nid_has_volume(codec, nid, dir) \
279 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
280
Takashi Iwai666a70d2012-12-17 20:29:29 +0100281static struct nid_path *
282get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid);
283static void activate_path(struct hda_codec *codec, struct nid_path *path,
284 bool enable, bool add_aamix);
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286/*
287 * input MUX handling
288 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200289static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
290 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
292 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
293 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100294 return snd_hda_input_mux_info(&spec->input_mux[0], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200297static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
301 struct alc_spec *spec = codec->spec;
302 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
303
304 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
305 return 0;
306}
307
Takashi Iwai666a70d2012-12-17 20:29:29 +0100308static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
309{
310 struct alc_spec *spec = codec->spec;
311 if (spec->dyn_adc_switch)
312 adc_idx = spec->dyn_adc_idx[imux_idx];
313 return spec->adc_nids[adc_idx];
314}
315
Takashi Iwai21268962011-07-07 15:01:13 +0200316static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Takashi Iwai21268962011-07-07 15:01:13 +0200318 struct alc_spec *spec = codec->spec;
319 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
320
321 if (spec->cur_adc && spec->cur_adc != new_adc) {
322 /* stream is running, let's swap the current ADC */
323 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
324 spec->cur_adc = new_adc;
325 snd_hda_codec_setup_stream(codec, new_adc,
326 spec->cur_adc_stream_tag, 0,
327 spec->cur_adc_format);
328 return true;
329 }
330 return false;
331}
332
Takashi Iwai24de1832011-11-07 17:13:39 +0100333static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200334static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100335static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx);
Takashi Iwai24de1832011-11-07 17:13:39 +0100336
David Henningsson00227f12012-06-27 18:45:44 +0200337/* for shared I/O, change the pin-control accordingly */
338static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
339{
340 struct alc_spec *spec = codec->spec;
341 unsigned int val;
342 hda_nid_t pin = spec->autocfg.inputs[1].pin;
343 /* NOTE: this assumes that there are only two inputs, the
344 * first is the real internal mic and the second is HP/mic jack.
345 */
346
347 val = snd_hda_get_default_vref(codec, pin);
348
349 /* This pin does not have vref caps - let's enable vref on pin 0x18
350 instead, as suggested by Realtek */
351 if (val == AC_PINCTL_VREF_HIZ) {
352 const hda_nid_t vref_pin = 0x18;
353 /* Sanity check pin 0x18 */
354 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
355 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
356 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
357 if (vref_val != AC_PINCTL_VREF_HIZ)
358 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
359 }
360 }
361
362 val = set_as_mic ? val | PIN_IN : PIN_HP;
363 snd_hda_set_pin_ctl(codec, pin, val);
364
365 spec->automute_speaker = !set_as_mic;
366 call_update_outputs(codec);
367}
Takashi Iwai21268962011-07-07 15:01:13 +0200368
369/* select the given imux item; either unmute exclusively or select the route */
370static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
371 unsigned int idx, bool force)
372{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100374 const struct hda_input_mux *imux;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100375 struct nid_path *path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Takashi Iwai666a70d2012-12-17 20:29:29 +0100377 imux = spec->input_mux;
378 if (!imux || !imux->num_items)
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100379 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100380
Takashi Iwai21268962011-07-07 15:01:13 +0200381 if (idx >= imux->num_items)
382 idx = imux->num_items - 1;
383 if (spec->cur_mux[adc_idx] == idx && !force)
384 return 0;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100385
386 path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]],
387 spec->adc_nids[adc_idx]);
388 if (!path)
389 return 0;
390 if (path->active)
391 activate_path(codec, path, false, false);
392
Takashi Iwai21268962011-07-07 15:01:13 +0200393 spec->cur_mux[adc_idx] = idx;
394
David Henningsson00227f12012-06-27 18:45:44 +0200395 if (spec->shared_mic_hp)
396 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100397
Takashi Iwai666a70d2012-12-17 20:29:29 +0100398 if (spec->dyn_adc_switch)
Takashi Iwai21268962011-07-07 15:01:13 +0200399 alc_dyn_adc_pcm_resetup(codec, idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200400
Takashi Iwai666a70d2012-12-17 20:29:29 +0100401 path = get_nid_path(codec, spec->imux_pins[idx],
402 get_adc_nid(codec, adc_idx, idx));
403 if (!path)
404 return 0;
405 if (path->active)
406 return 0;
407 activate_path(codec, path, true, false);
Takashi Iwai125821a2012-06-22 14:30:29 +0200408 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200409 return 1;
410}
411
412static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
413 struct snd_ctl_elem_value *ucontrol)
414{
415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
416 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
417 return alc_mux_select(codec, adc_idx,
418 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100419}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100422 * set up the input pin config (depending on the given auto-pin type)
423 */
424static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
425 int auto_pin_type)
426{
427 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200428 if (auto_pin_type == AUTO_PIN_MIC)
429 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200430 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100431}
432
433/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200434 * Append the given mixer and verb elements for the later use
435 * The mixer array is referred in build_controls(), and init_verbs are
436 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100437 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200438static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100439{
440 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
441 return;
442 spec->mixers[spec->num_mixers++] = mix;
443}
444
Takashi Iwaid88897e2008-10-31 15:01:37 +0100445/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200446 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100447 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200448/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200449static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200450 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
451 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
452 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
453 { }
454};
455
Takashi Iwaia9111322011-05-02 11:30:18 +0200456static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200457 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
458 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
459 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
460 { }
461};
462
Takashi Iwaia9111322011-05-02 11:30:18 +0200463static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200464 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
465 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
466 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
467 { }
468};
469
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200470/*
471 * Fix hardware PLL issue
472 * On some codecs, the analog PLL gating control must be off while
473 * the default value is 1.
474 */
475static void alc_fix_pll(struct hda_codec *codec)
476{
477 struct alc_spec *spec = codec->spec;
478 unsigned int val;
479
480 if (!spec->pll_nid)
481 return;
482 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
483 spec->pll_coef_idx);
484 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
485 AC_VERB_GET_PROC_COEF, 0);
486 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
487 spec->pll_coef_idx);
488 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
489 val & ~(1 << spec->pll_coef_bit));
490}
491
492static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
493 unsigned int coef_idx, unsigned int coef_bit)
494{
495 struct alc_spec *spec = codec->spec;
496 spec->pll_nid = nid;
497 spec->pll_coef_idx = coef_idx;
498 spec->pll_coef_bit = coef_bit;
499 alc_fix_pll(codec);
500}
501
Takashi Iwai1d045db2011-07-07 18:23:21 +0200502/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200503 * Jack detections for HP auto-mute and mic-switch
504 */
505
506/* check each pin in the given array; returns true if any of them is plugged */
507static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200508{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200509 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200510
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200511 for (i = 0; i < num_pins; i++) {
512 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200513 if (!nid)
514 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200515 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200516 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 return present;
518}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200519
Takashi Iwai1d045db2011-07-07 18:23:21 +0200520/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200521static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200522 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200523{
524 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200525 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526 int i;
527
528 for (i = 0; i < num_pins; i++) {
529 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100530 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200531 if (!nid)
532 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100533 /* don't reset VREF value in case it's controlling
534 * the amp (see alc861_fixup_asus_amp_vref_0f())
535 */
536 if (spec->keep_vref_in_automute) {
537 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100538 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100539 val &= ~PIN_HP;
540 } else
541 val = 0;
542 val |= pin_bits;
543 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200544 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200545}
546
David Henningsson42cf0d02011-09-20 12:04:56 +0200547/* Toggle outputs muting */
548static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200549{
550 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200551 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200552
Takashi Iwaic0a20262011-06-10 15:28:15 +0200553 /* Control HP pins/amps depending on master_mute state;
554 * in general, HP pins/amps control should be enabled in all cases,
555 * but currently set only for master_mute, just to be safe
556 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100557 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
558 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200559 spec->autocfg.hp_pins, spec->master_mute, true);
560
David Henningsson42cf0d02011-09-20 12:04:56 +0200561 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200562 on = 0;
563 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200564 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200566 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200567 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200568
569 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 /* if LO is a copy of either HP or Speaker, don't need to handle it */
571 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
572 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200573 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200574 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200575 on = 0;
576 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200577 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200578 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200579 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200580 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200581}
582
David Henningsson42cf0d02011-09-20 12:04:56 +0200583static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200584{
585 struct alc_spec *spec = codec->spec;
586 if (spec->automute_hook)
587 spec->automute_hook(codec);
588 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200589 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200590}
591
Takashi Iwai1d045db2011-07-07 18:23:21 +0200592/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200593static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200594{
595 struct alc_spec *spec = codec->spec;
596
David Henningsson42cf0d02011-09-20 12:04:56 +0200597 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200598 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
599 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200600 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200601 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200602 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200603}
604
Takashi Iwai1d045db2011-07-07 18:23:21 +0200605/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200606static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607{
608 struct alc_spec *spec = codec->spec;
609
David Henningssonf7f4b232012-10-10 16:32:09 +0200610 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
611 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200612 /* check LO jack only when it's different from HP */
613 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
614 return;
615
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200616 spec->line_jack_present =
617 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
618 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200619 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200620 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200621 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200622}
623
Takashi Iwai8d087c72011-06-28 12:45:47 +0200624#define get_connection_index(codec, mux, nid) \
625 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200626
Takashi Iwai1d045db2011-07-07 18:23:21 +0200627/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200628static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200629{
630 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200631 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200632
Takashi Iwai21268962011-07-07 15:01:13 +0200633 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200634 return;
635 if (snd_BUG_ON(!spec->adc_nids))
636 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200637 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200638 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200639
Takashi Iwai21268962011-07-07 15:01:13 +0200640 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
641 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
642 else if (spec->dock_mic_idx >= 0 &&
643 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
644 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
645 else
646 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200647}
648
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100649/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200650static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100651{
652 unsigned int val;
653 struct snd_kcontrol *kctl;
654 struct snd_ctl_elem_value *uctl;
655
656 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
657 if (!kctl)
658 return;
659 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
660 if (!uctl)
661 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200662 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100663 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
664 val &= HDA_AMP_VOLMASK;
665 uctl->value.integer.value[0] = val;
666 uctl->value.integer.value[1] = val;
667 kctl->put(kctl, uctl);
668 kfree(uctl);
669}
670
David Henningsson29adc4b2012-09-25 11:31:00 +0200671static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100672{
David Henningsson29adc4b2012-09-25 11:31:00 +0200673 /* For some reason, the res given from ALC880 is broken.
674 Here we adjust it properly. */
675 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100676}
677
Takashi Iwai1d045db2011-07-07 18:23:21 +0200678/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200679static void alc_inithook(struct hda_codec *codec)
680{
David Henningsson29adc4b2012-09-25 11:31:00 +0200681 alc_hp_automute(codec, NULL);
682 alc_line_automute(codec, NULL);
683 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200684}
685
Kailang Yangf9423e72008-05-27 12:32:25 +0200686/* additional initialization for ALC888 variants */
687static void alc888_coef_init(struct hda_codec *codec)
688{
689 unsigned int tmp;
690
691 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
692 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
693 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100694 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200695 /* alc888S-VC */
696 snd_hda_codec_read(codec, 0x20, 0,
697 AC_VERB_SET_PROC_COEF, 0x830);
698 else
699 /* alc888-VB */
700 snd_hda_codec_read(codec, 0x20, 0,
701 AC_VERB_SET_PROC_COEF, 0x3030);
702}
703
Takashi Iwai1d045db2011-07-07 18:23:21 +0200704/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200705static void alc889_coef_init(struct hda_codec *codec)
706{
707 unsigned int tmp;
708
709 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
710 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
711 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
712 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
713}
714
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100715/* turn on/off EAPD control (only if available) */
716static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
717{
718 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
719 return;
720 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
721 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
722 on ? 2 : 0);
723}
724
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200725/* turn on/off EAPD controls of the codec */
726static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
727{
728 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200729 static hda_nid_t pins[] = {
730 0x0f, 0x10, 0x14, 0x15, 0
731 };
732 hda_nid_t *p;
733 for (p = pins; *p; p++)
734 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200735}
736
Takashi Iwai1c716152011-04-07 10:37:16 +0200737/* generic shutup callback;
738 * just turning off EPAD and a little pause for avoiding pop-noise
739 */
740static void alc_eapd_shutup(struct hda_codec *codec)
741{
742 alc_auto_setup_eapd(codec, false);
743 msleep(200);
744}
745
Takashi Iwai1d045db2011-07-07 18:23:21 +0200746/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200747static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200748{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200749 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200750
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200751 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200752 switch (type) {
753 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200754 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
755 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200756 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200757 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
758 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200759 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200760 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
761 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200762 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200763 switch (codec->vendor_id) {
764 case 0x10ec0260:
765 snd_hda_codec_write(codec, 0x1a, 0,
766 AC_VERB_SET_COEF_INDEX, 7);
767 tmp = snd_hda_codec_read(codec, 0x1a, 0,
768 AC_VERB_GET_PROC_COEF, 0);
769 snd_hda_codec_write(codec, 0x1a, 0,
770 AC_VERB_SET_COEF_INDEX, 7);
771 snd_hda_codec_write(codec, 0x1a, 0,
772 AC_VERB_SET_PROC_COEF,
773 tmp | 0x2010);
774 break;
775 case 0x10ec0262:
776 case 0x10ec0880:
777 case 0x10ec0882:
778 case 0x10ec0883:
779 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100780 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100781 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200782 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200783 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200784 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200785 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200786 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100787#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200788 case 0x10ec0267:
789 case 0x10ec0268:
790 snd_hda_codec_write(codec, 0x20, 0,
791 AC_VERB_SET_COEF_INDEX, 7);
792 tmp = snd_hda_codec_read(codec, 0x20, 0,
793 AC_VERB_GET_PROC_COEF, 0);
794 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200795 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200796 snd_hda_codec_write(codec, 0x20, 0,
797 AC_VERB_SET_PROC_COEF,
798 tmp | 0x3000);
799 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100800#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200801 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200802 break;
803 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200804}
Kailang Yangea1fb292008-08-26 12:58:38 +0200805
Takashi Iwai1d045db2011-07-07 18:23:21 +0200806/*
807 * Auto-Mute mode mixer enum support
808 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200809static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
810 struct snd_ctl_elem_info *uinfo)
811{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200812 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
813 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200814 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100815 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200816 };
817
Takashi Iwaidda415d2012-11-30 18:34:38 +0100818 if (spec->automute_speaker_possible && spec->automute_lo_possible)
819 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
820 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200821}
822
823static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
824 struct snd_ctl_elem_value *ucontrol)
825{
826 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
827 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200828 unsigned int val = 0;
829 if (spec->automute_speaker)
830 val++;
831 if (spec->automute_lo)
832 val++;
833
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200834 ucontrol->value.enumerated.item[0] = val;
835 return 0;
836}
837
838static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
840{
841 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
842 struct alc_spec *spec = codec->spec;
843
844 switch (ucontrol->value.enumerated.item[0]) {
845 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200846 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200847 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200848 spec->automute_speaker = 0;
849 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200850 break;
851 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200852 if (spec->automute_speaker_possible) {
853 if (!spec->automute_lo && spec->automute_speaker)
854 return 0;
855 spec->automute_speaker = 1;
856 spec->automute_lo = 0;
857 } else if (spec->automute_lo_possible) {
858 if (spec->automute_lo)
859 return 0;
860 spec->automute_lo = 1;
861 } else
862 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200863 break;
864 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200865 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200866 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200867 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200868 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200869 spec->automute_speaker = 1;
870 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200871 break;
872 default:
873 return -EINVAL;
874 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200875 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200876 return 1;
877}
878
Takashi Iwaia9111322011-05-02 11:30:18 +0200879static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
881 .name = "Auto-Mute Mode",
882 .info = alc_automute_mode_info,
883 .get = alc_automute_mode_get,
884 .put = alc_automute_mode_put,
885};
886
Takashi Iwai668d1e92012-11-29 14:10:17 +0100887static struct snd_kcontrol_new *
888alc_kcontrol_new(struct alc_spec *spec, const char *name,
889 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200890{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100891 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
892 if (!knew)
893 return NULL;
894 *knew = *temp;
895 knew->name = kstrdup(name, GFP_KERNEL);
896 if (!knew->name)
897 return NULL;
898 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200899}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200900
901static int alc_add_automute_mode_enum(struct hda_codec *codec)
902{
903 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200904
Takashi Iwai668d1e92012-11-29 14:10:17 +0100905 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200906 return -ENOMEM;
907 return 0;
908}
909
Takashi Iwai1d045db2011-07-07 18:23:21 +0200910/*
911 * Check the availability of HP/line-out auto-mute;
912 * Set up appropriately if really supported
913 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100914static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200915{
916 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200917 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200918 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100919 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200920
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200921 if (cfg->hp_pins[0])
922 present++;
923 if (cfg->line_out_pins[0])
924 present++;
925 if (cfg->speaker_pins[0])
926 present++;
927 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100928 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200929
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200930 if (!cfg->speaker_pins[0] &&
931 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200932 memcpy(cfg->speaker_pins, cfg->line_out_pins,
933 sizeof(cfg->speaker_pins));
934 cfg->speaker_outs = cfg->line_outs;
935 }
936
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200937 if (!cfg->hp_pins[0] &&
938 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200939 memcpy(cfg->hp_pins, cfg->line_out_pins,
940 sizeof(cfg->hp_pins));
941 cfg->hp_outs = cfg->line_outs;
942 }
943
944 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200945 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200946 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200947 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200948 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200949 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200950 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
951 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200952 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200953 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200954
David Henningsson42cf0d02011-09-20 12:04:56 +0200955 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
956 if (cfg->speaker_outs)
957 for (i = 0; i < cfg->line_outs; i++) {
958 hda_nid_t nid = cfg->line_out_pins[i];
959 if (!is_jack_detectable(codec, nid))
960 continue;
961 snd_printdd("realtek: Enable Line-Out "
962 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200963 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
964 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200965 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200966 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200967 spec->automute_lo_possible = spec->detect_hp;
968 }
969
970 spec->automute_speaker_possible = cfg->speaker_outs &&
971 (spec->detect_hp || spec->detect_lo);
972
973 spec->automute_lo = spec->automute_lo_possible;
974 spec->automute_speaker = spec->automute_speaker_possible;
975
Takashi Iwai475c3d22012-11-30 08:31:30 +0100976 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200977 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100978 err = alc_add_automute_mode_enum(codec);
979 if (err < 0)
980 return err;
981 }
982 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200983}
984
Takashi Iwai1d045db2011-07-07 18:23:21 +0200985/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200986static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
987{
988 int i;
989 for (i = 0; i < nums; i++)
990 if (list[i] == nid)
991 return i;
992 return -1;
993}
994
Takashi Iwai21268962011-07-07 15:01:13 +0200995/* check whether all auto-mic pins are valid; setup indices if OK */
996static bool alc_auto_mic_check_imux(struct hda_codec *codec)
997{
998 struct alc_spec *spec = codec->spec;
999 const struct hda_input_mux *imux;
1000
Takashi Iwai21268962011-07-07 15:01:13 +02001001 imux = spec->input_mux;
1002 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1003 spec->imux_pins, imux->num_items);
1004 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1005 spec->imux_pins, imux->num_items);
1006 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1007 spec->imux_pins, imux->num_items);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001008 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0)
Takashi Iwai21268962011-07-07 15:01:13 +02001009 return false; /* no corresponding imux */
Takashi Iwai21268962011-07-07 15:01:13 +02001010
David Henningsson29adc4b2012-09-25 11:31:00 +02001011 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1012 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001013 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001014 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1015 ALC_MIC_EVENT,
1016 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001017
1018 spec->auto_mic_valid_imux = 1;
Takashi Iwai21268962011-07-07 15:01:13 +02001019 return true;
1020}
1021
Takashi Iwai1d045db2011-07-07 18:23:21 +02001022/*
1023 * Check the availability of auto-mic switch;
1024 * Set up if really supported
1025 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001026static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001027{
1028 struct alc_spec *spec = codec->spec;
1029 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001030 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001031 int i;
1032
Takashi Iwai21268962011-07-07 15:01:13 +02001033 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1034
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001035 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001036 for (i = 0; i < cfg->num_inputs; i++) {
1037 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001038 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001039 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001040 switch (snd_hda_get_input_pin_attr(defcfg)) {
1041 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001042 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001043 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001044 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001045 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001046 fixed = nid;
1047 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001048 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001049 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001050 case INPUT_PIN_ATTR_DOCK:
1051 if (dock)
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_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001054 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001055 dock = nid;
1056 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001057 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001058 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001059 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001060 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001061 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001062 ext = nid;
1063 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001064 }
1065 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001066 if (!ext && dock) {
1067 ext = dock;
1068 dock = 0;
1069 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001070 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001071 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001072 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001073 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001074 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001075 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001076
1077 /* check imux indices */
1078 spec->ext_mic_pin = ext;
1079 spec->int_mic_pin = fixed;
1080 spec->dock_mic_pin = dock;
1081
Takashi Iwai21268962011-07-07 15:01:13 +02001082 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001083 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001084
Takashi Iwai666a70d2012-12-17 20:29:29 +01001085 spec->auto_mic = 1;
1086 spec->num_adc_nids = 1;
1087 spec->cur_mux[0] = spec->int_mic_idx;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001088 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1089 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001090
1091 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001092}
1093
Takashi Iwai1d045db2011-07-07 18:23:21 +02001094/*
1095 * Realtek SSID verification
1096 */
1097
David Henningsson90622912010-10-14 14:50:18 +02001098/* Could be any non-zero and even value. When used as fixup, tells
1099 * the driver to ignore any present sku defines.
1100 */
1101#define ALC_FIXUP_SKU_IGNORE (2)
1102
Takashi Iwai23d30f22012-05-07 17:17:32 +02001103static void alc_fixup_sku_ignore(struct hda_codec *codec,
1104 const struct hda_fixup *fix, int action)
1105{
1106 struct alc_spec *spec = codec->spec;
1107 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1108 spec->cdefine.fixup = 1;
1109 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1110 }
1111}
1112
Kailang Yangda00c242010-03-19 11:23:45 +01001113static int alc_auto_parse_customize_define(struct hda_codec *codec)
1114{
1115 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001116 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001117 struct alc_spec *spec = codec->spec;
1118
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001119 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1120
David Henningsson90622912010-10-14 14:50:18 +02001121 if (spec->cdefine.fixup) {
1122 ass = spec->cdefine.sku_cfg;
1123 if (ass == ALC_FIXUP_SKU_IGNORE)
1124 return -1;
1125 goto do_sku;
1126 }
1127
Kailang Yangda00c242010-03-19 11:23:45 +01001128 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001129 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001130 goto do_sku;
1131
1132 nid = 0x1d;
1133 if (codec->vendor_id == 0x10ec0260)
1134 nid = 0x17;
1135 ass = snd_hda_codec_get_pincfg(codec, nid);
1136
1137 if (!(ass & 1)) {
1138 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1139 codec->chip_name, ass);
1140 return -1;
1141 }
1142
1143 /* check sum */
1144 tmp = 0;
1145 for (i = 1; i < 16; i++) {
1146 if ((ass >> i) & 1)
1147 tmp++;
1148 }
1149 if (((ass >> 16) & 0xf) != tmp)
1150 return -1;
1151
1152 spec->cdefine.port_connectivity = ass >> 30;
1153 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1154 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1155 spec->cdefine.customization = ass >> 8;
1156do_sku:
1157 spec->cdefine.sku_cfg = ass;
1158 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1159 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1160 spec->cdefine.swap = (ass & 0x2) >> 1;
1161 spec->cdefine.override = ass & 0x1;
1162
1163 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1164 nid, spec->cdefine.sku_cfg);
1165 snd_printd("SKU: port_connectivity=0x%x\n",
1166 spec->cdefine.port_connectivity);
1167 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1168 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1169 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1170 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1171 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1172 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1173 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1174
1175 return 0;
1176}
1177
Takashi Iwai1d045db2011-07-07 18:23:21 +02001178/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001179static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1180{
Takashi Iwai21268962011-07-07 15:01:13 +02001181 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001182}
1183
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001184/* check subsystem ID and set up device-specific initialization;
1185 * return 1 if initialized, 0 if invalid SSID
1186 */
1187/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1188 * 31 ~ 16 : Manufacture ID
1189 * 15 ~ 8 : SKU ID
1190 * 7 ~ 0 : Assembly ID
1191 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1192 */
1193static int alc_subsystem_id(struct hda_codec *codec,
1194 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001195 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001196{
1197 unsigned int ass, tmp, i;
1198 unsigned nid;
1199 struct alc_spec *spec = codec->spec;
1200
David Henningsson90622912010-10-14 14:50:18 +02001201 if (spec->cdefine.fixup) {
1202 ass = spec->cdefine.sku_cfg;
1203 if (ass == ALC_FIXUP_SKU_IGNORE)
1204 return 0;
1205 goto do_sku;
1206 }
1207
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001208 ass = codec->subsystem_id & 0xffff;
1209 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1210 goto do_sku;
1211
1212 /* invalid SSID, check the special NID pin defcfg instead */
1213 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001214 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001215 * 29~21 : reserve
1216 * 20 : PCBEEP input
1217 * 19~16 : Check sum (15:1)
1218 * 15~1 : Custom
1219 * 0 : override
1220 */
1221 nid = 0x1d;
1222 if (codec->vendor_id == 0x10ec0260)
1223 nid = 0x17;
1224 ass = snd_hda_codec_get_pincfg(codec, nid);
1225 snd_printd("realtek: No valid SSID, "
1226 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001227 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001228 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001229 return 0;
1230 if ((ass >> 30) != 1) /* no physical connection */
1231 return 0;
1232
1233 /* check sum */
1234 tmp = 0;
1235 for (i = 1; i < 16; i++) {
1236 if ((ass >> i) & 1)
1237 tmp++;
1238 }
1239 if (((ass >> 16) & 0xf) != tmp)
1240 return 0;
1241do_sku:
1242 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1243 ass & 0xffff, codec->vendor_id);
1244 /*
1245 * 0 : override
1246 * 1 : Swap Jack
1247 * 2 : 0 --> Desktop, 1 --> Laptop
1248 * 3~5 : External Amplifier control
1249 * 7~6 : Reserved
1250 */
1251 tmp = (ass & 0x38) >> 3; /* external Amp control */
1252 switch (tmp) {
1253 case 1:
1254 spec->init_amp = ALC_INIT_GPIO1;
1255 break;
1256 case 3:
1257 spec->init_amp = ALC_INIT_GPIO2;
1258 break;
1259 case 7:
1260 spec->init_amp = ALC_INIT_GPIO3;
1261 break;
1262 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001263 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001264 spec->init_amp = ALC_INIT_DEFAULT;
1265 break;
1266 }
1267
1268 /* is laptop or Desktop and enable the function "Mute internal speaker
1269 * when the external headphone out jack is plugged"
1270 */
1271 if (!(ass & 0x8000))
1272 return 1;
1273 /*
1274 * 10~8 : Jack location
1275 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1276 * 14~13: Resvered
1277 * 15 : 1 --> enable the function "Mute internal speaker
1278 * when the external headphone out jack is plugged"
1279 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001280 if (!spec->autocfg.hp_pins[0] &&
1281 !(spec->autocfg.line_out_pins[0] &&
1282 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001283 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001284 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1285 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001286 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001287 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001288 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001289 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001290 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001291 else if (tmp == 3)
1292 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001293 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001294 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001295 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1296 spec->autocfg.line_outs))
1297 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001298 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001299 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001300 return 1;
1301}
Kailang Yangea1fb292008-08-26 12:58:38 +02001302
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001303/* Check the validity of ALC subsystem-id
1304 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1305static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001306{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001307 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001308 struct alc_spec *spec = codec->spec;
1309 snd_printd("realtek: "
1310 "Enable default setup for auto mode as fallback\n");
1311 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001312 }
Takashi Iwai21268962011-07-07 15:01:13 +02001313}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001314
Takashi Iwai41e41f12005-06-08 14:48:49 +02001315/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001316 * COEF access helper functions
1317 */
Kailang Yang274693f2009-12-03 10:07:50 +01001318static int alc_read_coef_idx(struct hda_codec *codec,
1319 unsigned int coef_idx)
1320{
1321 unsigned int val;
1322 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1323 coef_idx);
1324 val = snd_hda_codec_read(codec, 0x20, 0,
1325 AC_VERB_GET_PROC_COEF, 0);
1326 return val;
1327}
1328
Kailang Yang977ddd62010-09-15 10:02:29 +02001329static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1330 unsigned int coef_val)
1331{
1332 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1333 coef_idx);
1334 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1335 coef_val);
1336}
1337
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001338/* a special bypass for COEF 0; read the cached value at the second time */
1339static unsigned int alc_get_coef0(struct hda_codec *codec)
1340{
1341 struct alc_spec *spec = codec->spec;
1342 if (!spec->coef0)
1343 spec->coef0 = alc_read_coef_idx(codec, 0);
1344 return spec->coef0;
1345}
1346
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001347static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1348 hda_nid_t pin, int pin_type,
1349 hda_nid_t dac);
1350static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1351 bool is_digital);
1352static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
1353 hda_nid_t dac);
1354
Takashi Iwai1d045db2011-07-07 18:23:21 +02001355/*
1356 * Digital I/O handling
1357 */
1358
Takashi Iwai757899a2010-07-30 10:48:14 +02001359/* set right pin controls for digital I/O */
1360static void alc_auto_init_digital(struct hda_codec *codec)
1361{
1362 struct alc_spec *spec = codec->spec;
1363 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001364 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001365
1366 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1367 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001368 if (!pin)
1369 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001370 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001371 }
1372 pin = spec->autocfg.dig_in_pin;
1373 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001374 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001375}
1376
1377/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1378static void alc_auto_parse_digital(struct hda_codec *codec)
1379{
1380 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001381 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001382 hda_nid_t dig_nid;
1383
1384 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001385 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001386 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001387 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1388 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1389 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001390 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001391 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001392 spec->multiout.dig_out_nid = dig_nid;
1393 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1394 } else {
1395 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001396 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001397 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001398 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001399 }
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001400 add_new_out_path(codec, pin, dig_nid);
Takashi Iwai51e41522011-11-03 16:54:06 +01001401 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001402 }
1403
1404 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001405 dig_nid = codec->start_nid;
1406 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1407 unsigned int wcaps = get_wcaps(codec, dig_nid);
1408 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1409 continue;
1410 if (!(wcaps & AC_WCAP_DIGITAL))
1411 continue;
1412 if (!(wcaps & AC_WCAP_CONN_LIST))
1413 continue;
1414 err = get_connection_index(codec, dig_nid,
1415 spec->autocfg.dig_in_pin);
1416 if (err >= 0) {
1417 spec->dig_in_nid = dig_nid;
1418 break;
1419 }
1420 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001421 }
1422}
1423
Takashi Iwaif95474e2007-07-10 00:47:43 +02001424/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001425 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001426 */
Takashi Iwai666a70d2012-12-17 20:29:29 +01001427#define alc_cap_vol_info snd_hda_mixer_amp_volume_info
1428#define alc_cap_vol_get snd_hda_mixer_amp_volume_get
1429#define alc_cap_vol_tlv snd_hda_mixer_amp_tlv
1430
1431typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
1432 struct snd_ctl_elem_value *ucontrol);
1433
1434static int alc_cap_put_caller(struct snd_kcontrol *kcontrol,
1435 struct snd_ctl_elem_value *ucontrol,
1436 put_call_t func, int type)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001437{
1438 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1439 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001440 const struct hda_input_mux *imux;
1441 struct nid_path *path;
1442 int i, adc_idx, err = 0;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001443
Takashi Iwai666a70d2012-12-17 20:29:29 +01001444 imux = spec->input_mux;
1445 adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001446 mutex_lock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001447 codec->cached_write = 1;
1448 for (i = 0; i < imux->num_items; i++) {
1449 path = get_nid_path(codec, spec->imux_pins[i],
1450 get_adc_nid(codec, adc_idx, i));
1451 if (!path->ctls[type])
1452 continue;
1453 kcontrol->private_value = path->ctls[type];
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001454 err = func(kcontrol, ucontrol);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001455 if (err < 0)
1456 goto error;
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001457 }
1458 error:
Takashi Iwai666a70d2012-12-17 20:29:29 +01001459 codec->cached_write = 0;
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001460 mutex_unlock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001461 snd_hda_codec_resume_amp(codec);
1462 if (err >= 0 && type == NID_PATH_MUTE_CTL &&
1463 spec->inv_dmic_fixup && spec->inv_dmic_muted)
1464 alc_inv_dmic_sync_adc(codec, adc_idx);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001465 return err;
1466}
1467
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001468static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1469 struct snd_ctl_elem_value *ucontrol)
1470{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001471 return alc_cap_put_caller(kcontrol, ucontrol,
1472 snd_hda_mixer_amp_volume_put,
1473 NID_PATH_VOL_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001474}
1475
1476/* capture mixer elements */
1477#define alc_cap_sw_info snd_ctl_boolean_stereo_info
Takashi Iwai666a70d2012-12-17 20:29:29 +01001478#define alc_cap_sw_get snd_hda_mixer_amp_switch_get
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001479
1480static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1481 struct snd_ctl_elem_value *ucontrol)
1482{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001483 return alc_cap_put_caller(kcontrol, ucontrol,
1484 snd_hda_mixer_amp_switch_put,
1485 NID_PATH_MUTE_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001486}
1487
Takashi Iwai666a70d2012-12-17 20:29:29 +01001488static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1489{
1490 struct alc_spec *spec = codec->spec;
1491 struct hda_input_mux *imux = &spec->private_imux[0];
1492 struct nid_path *path;
1493 hda_nid_t nid;
1494 int i, dir, parm;
1495 unsigned int val;
1496
1497 for (i = 0; i < imux->num_items; i++) {
1498 if (spec->imux_pins[i] == spec->inv_dmic_pin)
1499 break;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001500 }
Takashi Iwai666a70d2012-12-17 20:29:29 +01001501 if (i >= imux->num_items)
1502 return;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001503
Takashi Iwai666a70d2012-12-17 20:29:29 +01001504 path = get_nid_path(codec, spec->inv_dmic_pin,
1505 get_adc_nid(codec, adc_idx, i));
1506 val = path->ctls[NID_PATH_MUTE_CTL];
1507 if (!val)
1508 return;
1509 nid = get_amp_nid_(val);
1510 dir = get_amp_direction_(val);
1511 parm = AC_AMP_SET_RIGHT |
1512 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001513
Takashi Iwai666a70d2012-12-17 20:29:29 +01001514 /* we care only right channel */
1515 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1516 if (val & 0x80) /* if already muted, we don't need to touch */
1517 return;
1518 val |= 0x80;
1519 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1520 parm | val);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001521}
1522
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001523/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001524 * Inverted digital-mic handling
1525 *
1526 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1527 * gives the additional mute only to the right channel of the digital mic
1528 * capture stream. This is a workaround for avoiding the almost silence
1529 * by summing the stereo stream from some (known to be ForteMedia)
1530 * digital mic unit.
1531 *
1532 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1533 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1534 * without caching so that the cache can still keep the original value.
1535 * The cached value is then restored when the flag is set off or any other
1536 * than d-mic is used as the current input source.
1537 */
1538static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1539{
1540 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001541 int src, nums;
Takashi Iwai125821a2012-06-22 14:30:29 +02001542
1543 if (!spec->inv_dmic_fixup)
1544 return;
1545 if (!spec->inv_dmic_muted && !force)
1546 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001547 nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids;
1548 for (src = 0; src < nums; src++) {
Takashi Iwai125821a2012-06-22 14:30:29 +02001549 bool dmic_fixup = false;
Takashi Iwai125821a2012-06-22 14:30:29 +02001550
1551 if (spec->inv_dmic_muted &&
1552 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1553 dmic_fixup = true;
1554 if (!dmic_fixup && !force)
1555 continue;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001556 alc_inv_dmic_sync_adc(codec, src);
Takashi Iwai125821a2012-06-22 14:30:29 +02001557 }
1558}
1559
1560static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1561 struct snd_ctl_elem_value *ucontrol)
1562{
1563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1564 struct alc_spec *spec = codec->spec;
1565
1566 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1567 return 0;
1568}
1569
1570static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1571 struct snd_ctl_elem_value *ucontrol)
1572{
1573 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1574 struct alc_spec *spec = codec->spec;
1575 unsigned int val = !ucontrol->value.integer.value[0];
1576
1577 if (val == spec->inv_dmic_muted)
1578 return 0;
1579 spec->inv_dmic_muted = val;
1580 alc_inv_dmic_sync(codec, true);
1581 return 0;
1582}
1583
1584static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1585 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1586 .info = snd_ctl_boolean_mono_info,
1587 .get = alc_inv_dmic_sw_get,
1588 .put = alc_inv_dmic_sw_put,
1589};
1590
1591static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1592{
1593 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001594
1595 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1596 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001597 return -ENOMEM;
1598 spec->inv_dmic_fixup = 1;
1599 spec->inv_dmic_muted = 0;
1600 spec->inv_dmic_pin = nid;
1601 return 0;
1602}
1603
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001604/* typically the digital mic is put at node 0x12 */
1605static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1606 const struct alc_fixup *fix, int action)
1607{
1608 if (action == ALC_FIXUP_ACT_PROBE)
1609 alc_add_inv_dmic_mixer(codec, 0x12);
1610}
1611
Takashi Iwai125821a2012-06-22 14:30:29 +02001612/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001613 * virtual master controls
1614 */
1615
1616/*
1617 * slave controls for virtual master
1618 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001619static const char * const alc_slave_pfxs[] = {
1620 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001621 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001622 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001623 NULL,
1624};
1625
1626/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001627 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001629
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001630#define NID_MAPPING (-1)
1631
Takashi Iwai603c4012008-07-30 15:01:44 +02001632static void alc_free_kctls(struct hda_codec *codec);
1633
Takashi Iwai67d634c2009-11-16 15:35:59 +01001634#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001635/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001636static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001637 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001638 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001639 { } /* end */
1640};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001641#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001642
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001643static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
1645 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001646 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648 for (i = 0; i < spec->num_mixers; i++) {
1649 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1650 if (err < 0)
1651 return err;
1652 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001653 if (spec->cap_mixer) {
1654 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1655 if (err < 0)
1656 return err;
1657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001659 err = snd_hda_create_dig_out_ctls(codec,
1660 spec->multiout.dig_out_nid,
1661 spec->multiout.dig_out_nid,
1662 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 if (err < 0)
1664 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001665 if (!spec->no_analog) {
1666 err = snd_hda_create_spdif_share_sw(codec,
1667 &spec->multiout);
1668 if (err < 0)
1669 return err;
1670 spec->multiout.share_spdif = 1;
1671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 }
1673 if (spec->dig_in_nid) {
1674 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1675 if (err < 0)
1676 return err;
1677 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001678
Takashi Iwai67d634c2009-11-16 15:35:59 +01001679#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001680 /* create beep controls if needed */
1681 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001682 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001683 for (knew = alc_beep_mixer; knew->name; knew++) {
1684 struct snd_kcontrol *kctl;
1685 kctl = snd_ctl_new1(knew, codec);
1686 if (!kctl)
1687 return -ENOMEM;
1688 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001689 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001690 if (err < 0)
1691 return err;
1692 }
1693 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001694#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001695
Takashi Iwai2134ea42008-01-10 16:53:55 +01001696 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001697 if (!spec->no_analog &&
1698 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001699 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001700 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001701 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001702 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001703 vmaster_tlv, alc_slave_pfxs,
1704 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001705 if (err < 0)
1706 return err;
1707 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001708 if (!spec->no_analog &&
1709 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001710 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1711 NULL, alc_slave_pfxs,
1712 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001713 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001714 if (err < 0)
1715 return err;
1716 }
1717
Takashi Iwaibae84e72010-03-22 08:30:20 +01001718 alc_free_kctls(codec); /* no longer needed */
1719
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001720 return 0;
1721}
1722
David Henningsson5780b622012-06-27 18:45:45 +02001723static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001724{
1725 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001726
1727 if (spec->shared_mic_hp) {
1728 int err;
1729 int nid = spec->autocfg.inputs[1].pin;
1730 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1731 if (err < 0)
1732 return err;
1733 err = snd_hda_jack_detect_enable(codec, nid, 0);
1734 if (err < 0)
1735 return err;
1736 }
1737
1738 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1739}
1740
1741static int alc_build_controls(struct hda_codec *codec)
1742{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001743 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001744 if (err < 0)
1745 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001746
1747 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001748 if (err < 0)
1749 return err;
1750 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1751 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752}
1753
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001756 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001757 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001758
Takashi Iwai070cff42012-02-21 12:54:17 +01001759static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001760
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761static int alc_init(struct hda_codec *codec)
1762{
1763 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001764
Takashi Iwai546bb672012-03-07 08:37:19 +01001765 if (spec->init_hook)
1766 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001767
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001768 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001769 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001770
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02001771 snd_hda_gen_apply_verbs(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001772 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001773
Takashi Iwai58701122011-01-13 15:41:45 +01001774 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1775
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001776 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 return 0;
1778}
1779
Takashi Iwai83012a72012-08-24 18:38:08 +02001780#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001781static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1782{
1783 struct alc_spec *spec = codec->spec;
1784 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1785}
1786#endif
1787
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788/*
1789 * Analog playback callbacks
1790 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001791static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001793 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794{
1795 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001796 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1797 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798}
1799
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001800static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 struct hda_codec *codec,
1802 unsigned int stream_tag,
1803 unsigned int format,
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;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001807 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1808 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809}
1810
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001811static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001813 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
1815 struct alc_spec *spec = codec->spec;
1816 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1817}
1818
1819/*
1820 * Digital out
1821 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001822static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001824 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
1826 struct alc_spec *spec = codec->spec;
1827 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1828}
1829
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001830static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001831 struct hda_codec *codec,
1832 unsigned int stream_tag,
1833 unsigned int format,
1834 struct snd_pcm_substream *substream)
1835{
1836 struct alc_spec *spec = codec->spec;
1837 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1838 stream_tag, format, substream);
1839}
1840
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001841static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001842 struct hda_codec *codec,
1843 struct snd_pcm_substream *substream)
1844{
1845 struct alc_spec *spec = codec->spec;
1846 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1847}
1848
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001849static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001851 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852{
1853 struct alc_spec *spec = codec->spec;
1854 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1855}
1856
1857/*
1858 * Analog capture
1859 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001860static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 struct hda_codec *codec,
1862 unsigned int stream_tag,
1863 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001864 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865{
1866 struct alc_spec *spec = codec->spec;
1867
Takashi Iwai63300792008-01-24 15:31:36 +01001868 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 stream_tag, 0, format);
1870 return 0;
1871}
1872
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001873static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001875 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876{
1877 struct alc_spec *spec = codec->spec;
1878
Takashi Iwai888afa12008-03-18 09:57:50 +01001879 snd_hda_codec_cleanup_stream(codec,
1880 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 return 0;
1882}
1883
Takashi Iwai840b64c2010-07-13 22:49:01 +02001884/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02001885static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001886 struct hda_codec *codec,
1887 unsigned int stream_tag,
1888 unsigned int format,
1889 struct snd_pcm_substream *substream)
1890{
1891 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001892 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02001893 spec->cur_adc_stream_tag = stream_tag;
1894 spec->cur_adc_format = format;
1895 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1896 return 0;
1897}
1898
Takashi Iwai21268962011-07-07 15:01:13 +02001899static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001900 struct hda_codec *codec,
1901 struct snd_pcm_substream *substream)
1902{
1903 struct alc_spec *spec = codec->spec;
1904 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1905 spec->cur_adc = 0;
1906 return 0;
1907}
1908
Takashi Iwai21268962011-07-07 15:01:13 +02001909static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02001910 .substreams = 1,
1911 .channels_min = 2,
1912 .channels_max = 2,
1913 .nid = 0, /* fill later */
1914 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02001915 .prepare = dyn_adc_capture_pcm_prepare,
1916 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02001917 },
1918};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
1920/*
1921 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001922static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 .substreams = 1,
1924 .channels_min = 2,
1925 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001926 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001928 .open = alc_playback_pcm_open,
1929 .prepare = alc_playback_pcm_prepare,
1930 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 },
1932};
1933
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001934static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001935 .substreams = 1,
1936 .channels_min = 2,
1937 .channels_max = 2,
1938 /* NID is set in alc_build_pcms */
1939};
1940
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001941static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01001942 .substreams = 1,
1943 .channels_min = 2,
1944 .channels_max = 2,
1945 /* NID is set in alc_build_pcms */
1946};
1947
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001948static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001949 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 .channels_min = 2,
1951 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001952 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001954 .prepare = alc_alt_capture_pcm_prepare,
1955 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 },
1957};
1958
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001959static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 .substreams = 1,
1961 .channels_min = 2,
1962 .channels_max = 2,
1963 /* NID is set in alc_build_pcms */
1964 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001965 .open = alc_dig_playback_pcm_open,
1966 .close = alc_dig_playback_pcm_close,
1967 .prepare = alc_dig_playback_pcm_prepare,
1968 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 },
1970};
1971
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001972static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 .substreams = 1,
1974 .channels_min = 2,
1975 .channels_max = 2,
1976 /* NID is set in alc_build_pcms */
1977};
1978
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001979/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02001980static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001981 .substreams = 0,
1982 .channels_min = 0,
1983 .channels_max = 0,
1984};
1985
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986static int alc_build_pcms(struct hda_codec *codec)
1987{
1988 struct alc_spec *spec = codec->spec;
1989 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001990 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01001991 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 int i;
1993
1994 codec->num_pcms = 1;
1995 codec->pcm_info = info;
1996
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001997 if (spec->no_analog)
1998 goto skip_analog;
1999
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002000 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2001 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002003
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002004 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002005 p = spec->stream_analog_playback;
2006 if (!p)
2007 p = &alc_pcm_analog_playback;
2008 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002009 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002010 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2011 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002012 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2013 spec->autocfg.line_outs == 2)
2014 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2015 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002016 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002017 if (spec->adc_nids) {
2018 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002019 if (!p) {
2020 if (spec->dyn_adc_switch)
2021 p = &dyn_adc_pcm_analog_capture;
2022 else
2023 p = &alc_pcm_analog_capture;
2024 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002025 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002026 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2027 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
Takashi Iwai4a471b72005-12-07 13:56:29 +01002029 if (spec->channel_mode) {
2030 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2031 for (i = 0; i < spec->num_channel_mode; i++) {
2032 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2033 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 }
2036 }
2037
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002038 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002039 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002041 snprintf(spec->stream_name_digital,
2042 sizeof(spec->stream_name_digital),
2043 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002044 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002045 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002046 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002048 if (spec->dig_out_type)
2049 info->pcm_type = spec->dig_out_type;
2050 else
2051 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002052 if (spec->multiout.dig_out_nid) {
2053 p = spec->stream_digital_playback;
2054 if (!p)
2055 p = &alc_pcm_digital_playback;
2056 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2058 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002059 if (spec->dig_in_nid) {
2060 p = spec->stream_digital_capture;
2061 if (!p)
2062 p = &alc_pcm_digital_capture;
2063 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2065 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002066 /* FIXME: do we need this for all Realtek codec models? */
2067 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 }
2069
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002070 if (spec->no_analog)
2071 return 0;
2072
Takashi Iwaie08a0072006-09-07 17:52:14 +02002073 /* If the use of more than one ADC is requested for the current
2074 * model, configure a second analog capture-only PCM.
2075 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002076 have_multi_adcs = (spec->num_adc_nids > 1) &&
2077 !spec->dyn_adc_switch && !spec->auto_mic &&
2078 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002079 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002080 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002081 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002082 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002083 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002084 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002085 p = spec->stream_analog_alt_playback;
2086 if (!p)
2087 p = &alc_pcm_analog_alt_playback;
2088 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002089 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2090 spec->alt_dac_nid;
2091 } else {
2092 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2093 alc_pcm_null_stream;
2094 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2095 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002096 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002097 p = spec->stream_analog_alt_capture;
2098 if (!p)
2099 p = &alc_pcm_analog_alt_capture;
2100 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002101 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2102 spec->adc_nids[1];
2103 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2104 spec->num_adc_nids - 1;
2105 } else {
2106 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2107 alc_pcm_null_stream;
2108 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002109 }
2110 }
2111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 return 0;
2113}
2114
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002115static inline void alc_shutup(struct hda_codec *codec)
2116{
Takashi Iwai1c716152011-04-07 10:37:16 +02002117 struct alc_spec *spec = codec->spec;
2118
2119 if (spec && spec->shutup)
2120 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002121 snd_hda_shutup_pins(codec);
2122}
2123
Takashi Iwai603c4012008-07-30 15:01:44 +02002124static void alc_free_kctls(struct hda_codec *codec)
2125{
2126 struct alc_spec *spec = codec->spec;
2127
2128 if (spec->kctls.list) {
2129 struct snd_kcontrol_new *kctl = spec->kctls.list;
2130 int i;
2131 for (i = 0; i < spec->kctls.used; i++)
2132 kfree(kctl[i].name);
2133 }
2134 snd_array_free(&spec->kctls);
2135}
2136
Takashi Iwai23c09b02011-08-19 09:05:35 +02002137static void alc_free_bind_ctls(struct hda_codec *codec)
2138{
2139 struct alc_spec *spec = codec->spec;
2140 if (spec->bind_ctls.list) {
2141 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2142 int i;
2143 for (i = 0; i < spec->bind_ctls.used; i++)
2144 kfree(ctl[i]);
2145 }
2146 snd_array_free(&spec->bind_ctls);
2147}
2148
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149static void alc_free(struct hda_codec *codec)
2150{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002151 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002152
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002153 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002154 return;
2155
Takashi Iwai603c4012008-07-30 15:01:44 +02002156 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002157 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002158 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002159 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002160 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002161 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162}
2163
Takashi Iwai83012a72012-08-24 18:38:08 +02002164#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002165static void alc_power_eapd(struct hda_codec *codec)
2166{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002167 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002168}
2169
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002170static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002171{
2172 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002173 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002174 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002175 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002176 return 0;
2177}
2178#endif
2179
Takashi Iwai2a439522011-07-26 09:52:50 +02002180#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002181static int alc_resume(struct hda_codec *codec)
2182{
Takashi Iwai1c716152011-04-07 10:37:16 +02002183 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002184 codec->patch_ops.init(codec);
2185 snd_hda_codec_resume_amp(codec);
2186 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002187 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002188 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002189 return 0;
2190}
Takashi Iwaie044c392008-10-27 16:56:24 +01002191#endif
2192
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193/*
2194 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002195static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 .build_controls = alc_build_controls,
2197 .build_pcms = alc_build_pcms,
2198 .init = alc_init,
2199 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002200 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002201#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002202 .resume = alc_resume,
2203#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002204#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002205 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002206 .check_power_status = alc_check_power_status,
2207#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002208 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209};
2210
David Henningsson29adc4b2012-09-25 11:31:00 +02002211
Kailang Yangc027ddc2010-03-19 11:33:06 +01002212/* replace the codec chip_name with the given string */
2213static int alc_codec_rename(struct hda_codec *codec, const char *name)
2214{
2215 kfree(codec->chip_name);
2216 codec->chip_name = kstrdup(name, GFP_KERNEL);
2217 if (!codec->chip_name) {
2218 alc_free(codec);
2219 return -ENOMEM;
2220 }
2221 return 0;
2222}
2223
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002224/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002225 * Rename codecs appropriately from COEF value
2226 */
2227struct alc_codec_rename_table {
2228 unsigned int vendor_id;
2229 unsigned short coef_mask;
2230 unsigned short coef_bits;
2231 const char *name;
2232};
2233
2234static struct alc_codec_rename_table rename_tbl[] = {
2235 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2236 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2237 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2238 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2239 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2240 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2241 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002242 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002243 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2244 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2245 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2246 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2247 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2248 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2249 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2250 { } /* terminator */
2251};
2252
2253static int alc_codec_rename_from_preset(struct hda_codec *codec)
2254{
2255 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002256
2257 for (p = rename_tbl; p->vendor_id; p++) {
2258 if (p->vendor_id != codec->vendor_id)
2259 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002260 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002261 return alc_codec_rename(codec, p->name);
2262 }
2263 return 0;
2264}
2265
2266/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002267 * Automatic parse of I/O pins from the BIOS configuration
2268 */
2269
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002270enum {
2271 ALC_CTL_WIDGET_VOL,
2272 ALC_CTL_WIDGET_MUTE,
2273 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002274 ALC_CTL_BIND_VOL,
2275 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002276};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002277static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002278 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2279 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002280 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002281 HDA_BIND_VOL(NULL, 0),
2282 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002283};
2284
2285/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002286static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002287 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002288{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002289 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002290
Takashi Iwai668d1e92012-11-29 14:10:17 +01002291 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002292 if (!knew)
2293 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002294 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002295 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002296 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002297 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002298 return 0;
2299}
2300
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002301static int add_control_with_pfx(struct alc_spec *spec, int type,
2302 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002303 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002304{
2305 char name[32];
2306 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002307 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002308}
2309
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002310#define add_pb_vol_ctrl(spec, type, pfx, val) \
2311 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2312#define add_pb_sw_ctrl(spec, type, pfx, val) \
2313 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2314#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2315 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2316#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2317 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002318
Takashi Iwai23c09b02011-08-19 09:05:35 +02002319static const char * const channel_name[4] = {
2320 "Front", "Surround", "CLFE", "Side"
2321};
2322
Takashi Iwai6843ca12011-06-24 11:03:58 +02002323static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2324 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002325{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002326 struct auto_pin_cfg *cfg = &spec->autocfg;
2327
Takashi Iwai6843ca12011-06-24 11:03:58 +02002328 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002329 if (cfg->line_outs == 1 && !spec->multi_ios &&
2330 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002331 return "Master";
2332
2333 switch (cfg->line_out_type) {
2334 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002335 if (cfg->line_outs == 1)
2336 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002337 if (cfg->line_outs == 2)
2338 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002339 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002340 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002341 /* for multi-io case, only the primary out */
2342 if (ch && spec->multi_ios)
2343 break;
2344 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002345 return "Headphone";
2346 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002347 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002348 return "PCM";
2349 break;
2350 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002351 if (ch >= ARRAY_SIZE(channel_name)) {
2352 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002353 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002354 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002355
2356 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002357}
2358
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002359static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2360 hda_nid_t to_nid, int with_aa_mix,
2361 struct nid_path *path);
2362
Takashi Iwai83012a72012-08-24 18:38:08 +02002363#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002364/* add the powersave loopback-list entry */
2365static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2366{
2367 struct hda_amp_list *list;
2368
2369 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2370 return;
2371 list = spec->loopback_list + spec->num_loopbacks;
2372 list->nid = mix;
2373 list->dir = HDA_INPUT;
2374 list->idx = idx;
2375 spec->num_loopbacks++;
2376 spec->loopback.amplist = spec->loopback_list;
2377}
2378#else
2379#define add_loopback_list(spec, mix, idx) /* NOP */
2380#endif
2381
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002382/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002383static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002384 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002385 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002386{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002387 struct alc_spec *spec = codec->spec;
2388 struct nid_path *path;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002389 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002390 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002391
Takashi Iwaibd32f782012-12-12 18:08:52 +01002392 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2393 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2394 return 0; /* no need for analog loopback */
2395
Takashi Iwaic9967f12012-12-14 16:39:22 +01002396 path = snd_array_new(&spec->paths);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002397 if (!path)
2398 return -ENOMEM;
2399 memset(path, 0, sizeof(*path));
2400 if (!parse_nid_path(codec, pin, mix_nid, 2, path))
2401 return -EINVAL;
2402
2403 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002404 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002405 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2406 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002407 if (err < 0)
2408 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002409 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002410 }
2411
2412 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002413 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2414 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002415 if (err < 0)
2416 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002417 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002418 }
2419
Takashi Iwai829f69e2012-12-14 18:26:02 +01002420 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002421 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002422 return 0;
2423}
2424
Takashi Iwai05f5f472009-08-25 13:10:18 +02002425static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002426{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002427 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2428 return (pincap & AC_PINCAP_IN) != 0;
2429}
2430
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002431/* check whether the given two widgets can be connected */
2432static bool is_reachable_path(struct hda_codec *codec,
2433 hda_nid_t from_nid, hda_nid_t to_nid)
2434{
2435 if (!from_nid || !to_nid)
2436 return false;
2437 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2438}
2439
Takashi Iwai666a70d2012-12-17 20:29:29 +01002440/* Parse the codec tree and retrieve ADCs */
2441static int alc_auto_fill_adc_nids(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002442{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002443 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002444 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002445 hda_nid_t *adc_nids = spec->private_adc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002446 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002447 int i, nums = 0;
2448
2449 nid = codec->start_nid;
2450 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwaib7821702011-07-06 15:12:46 +02002451 unsigned int caps = get_wcaps(codec, nid);
2452 int type = get_wcaps_type(caps);
2453
2454 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2455 continue;
2456 adc_nids[nums] = nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002457 if (++nums >= max_nums)
2458 break;
2459 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002460 spec->adc_nids = spec->private_adc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002461 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002462 return nums;
2463}
2464
Takashi Iwai666a70d2012-12-17 20:29:29 +01002465/* filter out invalid adc_nids that don't give all active input pins;
2466 * if needed, check whether dynamic ADC-switching is available
2467 */
2468static int check_dyn_adc_switch(struct hda_codec *codec)
2469{
2470 struct alc_spec *spec = codec->spec;
2471 struct hda_input_mux *imux = &spec->private_imux[0];
2472 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
2473 int i, n, nums;
2474 hda_nid_t pin, adc;
2475
2476 again:
2477 nums = 0;
2478 for (n = 0; n < spec->num_adc_nids; n++) {
2479 adc = spec->adc_nids[n];
2480 for (i = 0; i < imux->num_items; i++) {
2481 pin = spec->imux_pins[i];
2482 if (!is_reachable_path(codec, pin, adc))
2483 break;
2484 }
2485 if (i >= imux->num_items)
2486 adc_nids[nums++] = adc;
2487 }
2488
2489 if (!nums) {
2490 if (spec->shared_mic_hp) {
2491 spec->shared_mic_hp = 0;
2492 spec->private_imux[0].num_items = 1;
2493 goto again;
2494 }
2495
2496 /* check whether ADC-switch is possible */
2497 for (i = 0; i < imux->num_items; i++) {
2498 pin = spec->imux_pins[i];
2499 for (n = 0; n < spec->num_adc_nids; n++) {
2500 adc = spec->adc_nids[n];
2501 if (is_reachable_path(codec, pin, adc)) {
2502 spec->dyn_adc_idx[i] = n;
2503 break;
2504 }
2505 }
2506 }
2507
2508 snd_printdd("realtek: enabling ADC switching\n");
2509 spec->dyn_adc_switch = 1;
2510 } else if (nums != spec->num_adc_nids) {
2511 memcpy(spec->private_adc_nids, adc_nids,
2512 nums * sizeof(hda_nid_t));
2513 spec->num_adc_nids = nums;
2514 }
2515
2516 if (spec->input_mux->num_items == 1 || spec->shared_mic_hp) {
2517 snd_printdd("realtek: reducing to a single ADC\n");
2518 spec->num_adc_nids = 1; /* reduce to a single ADC */
2519 }
2520
2521 return 0;
2522}
2523
2524/* templates for capture controls */
2525static const struct snd_kcontrol_new cap_src_temp = {
2526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2527 .name = "Input Source",
2528 .info = alc_mux_enum_info,
2529 .get = alc_mux_enum_get,
2530 .put = alc_mux_enum_put,
2531};
2532
2533static const struct snd_kcontrol_new cap_vol_temp = {
2534 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2535 .name = "Capture Volume",
2536 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2537 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2538 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2539 .info = alc_cap_vol_info,
2540 .get = alc_cap_vol_get,
2541 .put = alc_cap_vol_put,
2542 .tlv = { .c = alc_cap_vol_tlv },
2543};
2544
2545static const struct snd_kcontrol_new cap_sw_temp = {
2546 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2547 .name = "Capture Switch",
2548 .info = alc_cap_sw_info,
2549 .get = alc_cap_sw_get,
2550 .put = alc_cap_sw_put,
2551};
2552
2553static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2554{
2555 hda_nid_t nid;
2556 int i, depth;
2557
2558 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2559 for (depth = 0; depth < 3; depth++) {
2560 if (depth >= path->depth)
2561 return -EINVAL;
2562 i = path->depth - depth - 1;
2563 nid = path->path[i];
2564 if (!path->ctls[NID_PATH_VOL_CTL]) {
2565 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2566 path->ctls[NID_PATH_VOL_CTL] =
2567 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2568 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2569 int idx = path->idx[i];
2570 if (!depth && codec->single_adc_amp)
2571 idx = 0;
2572 path->ctls[NID_PATH_VOL_CTL] =
2573 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2574 }
2575 }
2576 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2577 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2578 path->ctls[NID_PATH_MUTE_CTL] =
2579 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2580 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2581 int idx = path->idx[i];
2582 if (!depth && codec->single_adc_amp)
2583 idx = 0;
2584 path->ctls[NID_PATH_MUTE_CTL] =
2585 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2586 }
2587 }
2588 }
2589 return 0;
2590}
2591
2592static int create_capture_mixers(struct hda_codec *codec)
2593{
2594 struct alc_spec *spec = codec->spec;
2595 struct hda_input_mux *imux = &spec->private_imux[0];
2596 struct snd_kcontrol_new *knew;
2597 int i, n, nums;
2598
2599 if (spec->dyn_adc_switch)
2600 nums = 1;
2601 else
2602 nums = spec->num_adc_nids;
2603
2604 if (!spec->auto_mic && imux->num_items > 1) {
2605 knew = alc_kcontrol_new(spec, "Input Source", &cap_src_temp);
2606 if (!knew)
2607 return -ENOMEM;
2608 knew->count = nums;
2609 }
2610
2611 for (n = 0; n < nums; n++) {
2612 int vol, sw;
2613
2614 vol = sw = 0;
2615 for (i = 0; i < imux->num_items; i++) {
2616 struct nid_path *path;
2617 path = get_nid_path(codec, spec->imux_pins[i],
2618 get_adc_nid(codec, n, i));
2619 if (!path)
2620 continue;
2621 parse_capvol_in_path(codec, path);
2622 if (!vol)
2623 vol = path->ctls[NID_PATH_VOL_CTL];
2624 if (!sw)
2625 sw = path->ctls[NID_PATH_MUTE_CTL];
2626 }
2627
2628 if (vol) {
2629 knew = alc_kcontrol_new(spec, "Capture Volume",
2630 &cap_vol_temp);
2631 if (!knew)
2632 return -ENOMEM;
2633 knew->index = n;
2634 knew->private_value = vol;
2635 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2636 }
2637 if (sw) {
2638 knew = alc_kcontrol_new(spec, "Capture Switch",
2639 &cap_sw_temp);
2640 if (!knew)
2641 return -ENOMEM;
2642 knew->index = n;
2643 knew->private_value = sw;
2644 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2645 }
2646 }
2647
2648 return 0;
2649}
2650
Takashi Iwai05f5f472009-08-25 13:10:18 +02002651/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002652static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002653{
2654 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002655 const struct auto_pin_cfg *cfg = &spec->autocfg;
2656 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002657 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002658 int num_adcs;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002659 int i, c, err, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002660 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002661
Takashi Iwai666a70d2012-12-17 20:29:29 +01002662 num_adcs = alc_auto_fill_adc_nids(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002663 if (num_adcs < 0)
2664 return 0;
2665
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002666 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002667 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002668 const char *label;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002669 bool imux_added;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002670
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002671 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002672 if (!alc_is_input_pin(codec, pin))
2673 continue;
2674
David Henningsson5322bf22011-01-05 11:03:56 +01002675 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002676 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2677 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002678 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002679 type_idx++;
2680 else
2681 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002682 prev_label = label;
2683
Takashi Iwai05f5f472009-08-25 13:10:18 +02002684 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002685 if (is_reachable_path(codec, pin, mixer)) {
2686 err = new_analog_input(codec, pin,
2687 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002688 if (err < 0)
2689 return err;
2690 }
2691 }
2692
Takashi Iwai666a70d2012-12-17 20:29:29 +01002693 imux_added = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002694 for (c = 0; c < num_adcs; c++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002695 struct nid_path *path;
2696 hda_nid_t adc = spec->adc_nids[c];
2697
2698 if (!is_reachable_path(codec, pin, adc))
2699 continue;
2700 path = snd_array_new(&spec->paths);
2701 if (!path)
2702 return -ENOMEM;
2703 memset(path, 0, sizeof(*path));
2704 if (!parse_nid_path(codec, pin, adc, 2, path)) {
2705 snd_printd(KERN_ERR
2706 "invalid input path 0x%x -> 0x%x\n",
2707 pin, adc);
2708 spec->paths.used--;
2709 continue;
2710 }
2711
2712 if (!imux_added) {
2713 spec->imux_pins[imux->num_items] = pin;
2714 snd_hda_add_imux_item(imux, label,
2715 imux->num_items, NULL);
2716 imux_added = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002717 }
2718 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002719 }
Takashi Iwai21268962011-07-07 15:01:13 +02002720
Takashi Iwai21268962011-07-07 15:01:13 +02002721 spec->input_mux = imux;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002722 return 0;
2723}
2724
Takashi Iwai24de1832011-11-07 17:13:39 +01002725/* create a shared input with the headphone out */
2726static int alc_auto_create_shared_input(struct hda_codec *codec)
2727{
2728 struct alc_spec *spec = codec->spec;
2729 struct auto_pin_cfg *cfg = &spec->autocfg;
2730 unsigned int defcfg;
2731 hda_nid_t nid;
2732
2733 /* only one internal input pin? */
2734 if (cfg->num_inputs != 1)
2735 return 0;
2736 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2737 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2738 return 0;
2739
2740 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2741 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2742 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2743 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2744 else
2745 return 0; /* both not available */
2746
2747 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2748 return 0; /* no input */
2749
2750 cfg->inputs[1].pin = nid;
2751 cfg->inputs[1].type = AUTO_PIN_MIC;
2752 cfg->num_inputs = 2;
2753 spec->shared_mic_hp = 1;
2754 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2755 return 0;
2756}
2757
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002758static int get_pin_type(int line_out_type)
2759{
2760 if (line_out_type == AUTO_PIN_HP_OUT)
2761 return PIN_HP;
2762 else
2763 return PIN_OUT;
2764}
2765
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002766static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002767{
2768 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002769 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002770 int i;
2771
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002772 for (i = 0; i < cfg->num_inputs; i++) {
2773 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002774 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002775 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002776 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002777 snd_hda_codec_write(codec, nid, 0,
2778 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002779 AMP_OUT_MUTE);
2780 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002781
Takashi Iwai829f69e2012-12-14 18:26:02 +01002782 /* mute loopback inputs */
2783 if (spec->mixer_nid) {
2784 struct nid_path *path;
2785 path = get_nid_path(codec, nid, spec->mixer_nid);
2786 if (path)
Takashi Iwai666a70d2012-12-17 20:29:29 +01002787 activate_path(codec, path, path->active, false);
Takashi Iwai829f69e2012-12-14 18:26:02 +01002788 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002789 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002790}
2791
Takashi Iwai185d99f2012-02-16 18:39:45 +01002792static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2793{
2794 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002795 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002796
Takashi Iwaic9967f12012-12-14 16:39:22 +01002797 for (i = 0; i < spec->paths.used; i++) {
2798 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002799 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002800 return true;
2801 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002802 return false;
2803}
2804
Takashi Iwai463419d2012-12-05 14:17:37 +01002805/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002806static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2807 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002808{
2809 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002810 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002811 int i;
2812
2813 for (i = 0; i < spec->num_all_dacs; i++) {
2814 hda_nid_t nid = spec->all_dacs[i];
2815 if (!nid || alc_is_dac_already_used(codec, nid))
2816 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002817 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2818 if (is_digital != cap_digital)
2819 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002820 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002821 return nid;
2822 }
2823 return 0;
2824}
2825
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002826/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002827static bool __parse_nid_path(struct hda_codec *codec,
2828 hda_nid_t from_nid, hda_nid_t to_nid,
2829 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002830{
2831 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002832 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002833 int i, nums;
2834
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002835 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002836 if (!with_aa_mix)
2837 return false;
2838 with_aa_mix = 2; /* mark aa-mix is included */
2839 }
2840
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002841 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002842 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002843 if (conn[i] != from_nid) {
2844 /* special case: when from_nid is 0,
2845 * try to find an empty DAC
2846 */
2847 if (from_nid ||
2848 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2849 alc_is_dac_already_used(codec, conn[i]))
2850 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002851 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002852 /* aa-mix is requested but not included? */
2853 if (!(spec->mixer_nid && with_aa_mix == 1))
2854 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002855 }
2856 if (depth >= MAX_NID_PATH_DEPTH)
2857 return false;
2858 for (i = 0; i < nums; i++) {
2859 unsigned int type;
2860 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002861 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2862 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002863 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002864 if (__parse_nid_path(codec, from_nid, conn[i],
2865 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002866 goto found;
2867 }
2868 return false;
2869
2870 found:
2871 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002872 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002873 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002874 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002875 path->depth++;
2876 return true;
2877}
2878
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002879/* parse the widget path from the given nid to the target nid;
2880 * when @from_nid is 0, try to find an empty DAC;
2881 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2882 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2883 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002884 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002885static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2886 hda_nid_t to_nid, int with_aa_mix,
2887 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002888{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002889 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2890 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002891 path->depth++;
2892#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002893 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002894 path->depth, path->path[0], path->path[1],
2895 path->path[2], path->path[3], path->path[4]);
2896#endif
2897 return true;
2898 }
2899 return false;
2900}
2901
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002902static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2903{
Takashi Iwai140547e2012-02-16 17:23:46 +01002904 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002905 int i;
2906 hda_nid_t nid_found = 0;
2907
2908 for (i = 0; i < spec->num_all_dacs; i++) {
2909 hda_nid_t nid = spec->all_dacs[i];
2910 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002911 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002912 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01002913 if (nid_found)
2914 return 0;
2915 nid_found = nid;
2916 }
2917 }
2918 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002919}
2920
Takashi Iwaiba8111272012-12-06 18:06:23 +01002921static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002922{
Takashi Iwaiba8111272012-12-06 18:06:23 +01002923 struct alc_spec *spec = codec->spec;
2924 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002925
Takashi Iwaic9967f12012-12-14 16:39:22 +01002926 for (i = 0; i < spec->paths.used; i++) {
2927 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002928 if (path->ctls[type] == val)
2929 return true;
2930 }
2931 return false;
2932}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002933
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002934/* badness definition */
2935enum {
2936 /* No primary DAC is found for the main output */
2937 BAD_NO_PRIMARY_DAC = 0x10000,
2938 /* No DAC is found for the extra output */
2939 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01002940 /* No possible multi-ios */
2941 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002942 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01002943 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002944 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01002945 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002946 /* Primary DAC shared with main surrounds */
2947 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002948 /* Primary DAC shared with main CLFE */
2949 BAD_SHARED_CLFE = 0x10,
2950 /* Primary DAC shared with extra surrounds */
2951 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01002952 /* Volume widget is shared */
2953 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002954};
2955
2956static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002957 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002958static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002959 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002960
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002961static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
2962 hda_nid_t dac)
2963{
2964 struct alc_spec *spec = codec->spec;
2965 struct nid_path *path;
2966
Takashi Iwaic9967f12012-12-14 16:39:22 +01002967 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002968 if (!path)
2969 return false;
2970 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002971 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002972 return true;
2973 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01002974 spec->paths.used--;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002975 return false;
2976}
2977
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002978/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01002979 * passing 0 to either @pin or @dac behaves as a wildcard
2980 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002981static struct nid_path *
2982get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01002983{
2984 struct alc_spec *spec = codec->spec;
2985 int i;
2986
Takashi Iwaic9967f12012-12-14 16:39:22 +01002987 for (i = 0; i < spec->paths.used; i++) {
2988 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002989 if (path->depth <= 0)
2990 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002991 if ((!from_nid || path->path[0] == from_nid) &&
2992 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01002993 return path;
2994 }
2995 return NULL;
2996}
2997
Takashi Iwai792cf2f2012-12-10 16:04:30 +01002998/* look for widgets in the path between the given NIDs appropriate for
2999 * volume and mute controls, and assign the values to ctls[].
3000 *
3001 * When no appropriate widget is found in the path, the badness value
3002 * is incremented depending on the situation. The function returns the
3003 * total badness for both volume and mute controls.
3004 */
3005static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3006 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003007{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003008 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003009 hda_nid_t nid;
3010 unsigned int val;
3011 int badness = 0;
3012
Takashi Iwaiba8111272012-12-06 18:06:23 +01003013 if (!path)
3014 return BAD_SHARED_VOL * 2;
3015 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003016 if (nid) {
3017 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003018 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003019 badness += BAD_SHARED_VOL;
3020 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003021 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003022 } else
3023 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003024 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003025 if (nid) {
3026 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003027 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3028 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003029 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3030 else
3031 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003032 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003033 badness += BAD_SHARED_VOL;
3034 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003035 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003036 } else
3037 badness += BAD_SHARED_VOL;
3038 return badness;
3039}
3040
Takashi Iwaidc31b582012-02-17 17:27:53 +01003041struct badness_table {
3042 int no_primary_dac; /* no primary DAC */
3043 int no_dac; /* no secondary DACs */
3044 int shared_primary; /* primary DAC is shared with main output */
3045 int shared_surr; /* secondary DAC shared with main or primary */
3046 int shared_clfe; /* third DAC shared with main or primary */
3047 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3048};
3049
3050static struct badness_table main_out_badness = {
3051 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3052 .no_dac = BAD_NO_DAC,
3053 .shared_primary = BAD_NO_PRIMARY_DAC,
3054 .shared_surr = BAD_SHARED_SURROUND,
3055 .shared_clfe = BAD_SHARED_CLFE,
3056 .shared_surr_main = BAD_SHARED_SURROUND,
3057};
3058
3059static struct badness_table extra_out_badness = {
3060 .no_primary_dac = BAD_NO_DAC,
3061 .no_dac = BAD_NO_DAC,
3062 .shared_primary = BAD_NO_EXTRA_DAC,
3063 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3064 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3065 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3066};
3067
3068/* try to assign DACs to pins and return the resultant badness */
3069static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3070 const hda_nid_t *pins, hda_nid_t *dacs,
3071 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003072{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003073 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003074 struct auto_pin_cfg *cfg = &spec->autocfg;
3075 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003076 int badness = 0;
3077 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003078
Takashi Iwai185d99f2012-02-16 18:39:45 +01003079 if (!num_outs)
3080 return 0;
3081
Takashi Iwaidc31b582012-02-17 17:27:53 +01003082 for (i = 0; i < num_outs; i++) {
3083 hda_nid_t pin = pins[i];
3084 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003085 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003086 if (!dacs[i] && !i) {
3087 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003088 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003089 dacs[0] = dacs[j];
3090 dacs[j] = 0;
3091 break;
3092 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003093 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003094 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003095 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003096 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003097 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003098 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003099 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003100 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003101 dac = spec->private_dac_nids[i];
3102 if (dac) {
3103 if (!i)
3104 badness += bad->shared_primary;
3105 else if (i == 1)
3106 badness += bad->shared_surr;
3107 else
3108 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003109 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003110 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003111 badness += bad->shared_surr_main;
3112 } else if (!i)
3113 badness += bad->no_primary_dac;
3114 else
3115 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003116 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003117 if (!add_new_out_path(codec, pin, dac))
3118 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003119 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003120 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003121 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003122
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003123 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003124}
3125
3126static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003127 hda_nid_t reference_pin,
3128 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003129
Takashi Iwai185d99f2012-02-16 18:39:45 +01003130static bool alc_map_singles(struct hda_codec *codec, int outs,
3131 const hda_nid_t *pins, hda_nid_t *dacs)
3132{
3133 int i;
3134 bool found = false;
3135 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003136 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003137 if (dacs[i])
3138 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003139 dac = get_dac_if_single(codec, pins[i]);
3140 if (!dac)
3141 continue;
3142 if (add_new_out_path(codec, pins[i], dac)) {
3143 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003144 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003145 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003146 }
3147 return found;
3148}
3149
Takashi Iwai7085ec12009-10-02 09:03:58 +02003150/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003151static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003152 bool fill_hardwired,
3153 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003154{
3155 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003156 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003157 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003158
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003159 /* set num_dacs once to full for alc_auto_look_for_dac() */
3160 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003161 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003162 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3163 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3164 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003165 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003166 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003167 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003168
3169 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003170 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003171 bool mapped;
3172 do {
3173 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003174 cfg->line_out_pins,
3175 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003176 mapped |= alc_map_singles(codec, cfg->hp_outs,
3177 cfg->hp_pins,
3178 spec->multiout.hp_out_nid);
3179 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3180 cfg->speaker_pins,
3181 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003182 if (fill_mio_first && cfg->line_outs == 1 &&
3183 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3184 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3185 if (!err)
3186 mapped = true;
3187 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003188 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003189 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003190
Takashi Iwaidc31b582012-02-17 17:27:53 +01003191 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3192 spec->private_dac_nids,
3193 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003194
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003195 /* re-count num_dacs and squash invalid entries */
3196 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003197 for (i = 0; i < cfg->line_outs; i++) {
3198 if (spec->private_dac_nids[i])
3199 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003200 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003201 memmove(spec->private_dac_nids + i,
3202 spec->private_dac_nids + i + 1,
3203 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003204 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3205 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003206 }
3207
Takashi Iwai276dd702012-02-17 16:17:03 +01003208 if (fill_mio_first &&
3209 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003210 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003211 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003212 if (err < 0)
3213 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003214 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003215 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003216
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003217 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003218 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3219 spec->multiout.hp_out_nid,
3220 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003221 if (err < 0)
3222 return err;
3223 badness += err;
3224 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003225 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003226 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3227 cfg->speaker_pins,
3228 spec->multiout.extra_out_nid,
3229 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003230 if (err < 0)
3231 return err;
3232 badness += err;
3233 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003234 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3235 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003236 if (err < 0)
3237 return err;
3238 badness += err;
3239 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003240 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3241 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003242 int offset = 0;
3243 if (cfg->line_outs >= 3)
3244 offset = 1;
3245 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3246 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003247 if (err < 0)
3248 return err;
3249 badness += err;
3250 }
3251
3252 if (spec->multi_ios == 2) {
3253 for (i = 0; i < 2; i++)
3254 spec->private_dac_nids[spec->multiout.num_dacs++] =
3255 spec->multi_io[i].dac;
3256 spec->ext_channel_count = 2;
3257 } else if (spec->multi_ios) {
3258 spec->multi_ios = 0;
3259 badness += BAD_MULTI_IO;
3260 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003261
3262 return badness;
3263}
3264
3265#define DEBUG_BADNESS
3266
3267#ifdef DEBUG_BADNESS
3268#define debug_badness snd_printdd
3269#else
3270#define debug_badness(...)
3271#endif
3272
3273static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3274{
3275 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3276 cfg->line_out_pins[0], cfg->line_out_pins[1],
3277 cfg->line_out_pins[2], cfg->line_out_pins[2],
3278 spec->multiout.dac_nids[0],
3279 spec->multiout.dac_nids[1],
3280 spec->multiout.dac_nids[2],
3281 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003282 if (spec->multi_ios > 0)
3283 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3284 spec->multi_ios,
3285 spec->multi_io[0].pin, spec->multi_io[1].pin,
3286 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003287 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3288 cfg->hp_pins[0], cfg->hp_pins[1],
3289 cfg->hp_pins[2], cfg->hp_pins[2],
3290 spec->multiout.hp_out_nid[0],
3291 spec->multiout.hp_out_nid[1],
3292 spec->multiout.hp_out_nid[2],
3293 spec->multiout.hp_out_nid[3]);
3294 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3295 cfg->speaker_pins[0], cfg->speaker_pins[1],
3296 cfg->speaker_pins[2], cfg->speaker_pins[3],
3297 spec->multiout.extra_out_nid[0],
3298 spec->multiout.extra_out_nid[1],
3299 spec->multiout.extra_out_nid[2],
3300 spec->multiout.extra_out_nid[3]);
3301}
3302
Takashi Iwai463419d2012-12-05 14:17:37 +01003303/* find all available DACs of the codec */
3304static void alc_fill_all_nids(struct hda_codec *codec)
3305{
3306 struct alc_spec *spec = codec->spec;
3307 int i;
3308 hda_nid_t nid = codec->start_nid;
3309
3310 spec->num_all_dacs = 0;
3311 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3312 for (i = 0; i < codec->num_nodes; i++, nid++) {
3313 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3314 continue;
3315 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3316 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3317 break;
3318 }
3319 spec->all_dacs[spec->num_all_dacs++] = nid;
3320 }
3321}
3322
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003323static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3324{
3325 struct alc_spec *spec = codec->spec;
3326 struct auto_pin_cfg *cfg = &spec->autocfg;
3327 struct auto_pin_cfg *best_cfg;
3328 int best_badness = INT_MAX;
3329 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003330 bool fill_hardwired = true, fill_mio_first = true;
3331 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003332 bool hp_spk_swapped = false;
3333
Takashi Iwai463419d2012-12-05 14:17:37 +01003334 alc_fill_all_nids(codec);
3335
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003336 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3337 if (!best_cfg)
3338 return -ENOMEM;
3339 *best_cfg = *cfg;
3340
3341 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003342 badness = fill_and_eval_dacs(codec, fill_hardwired,
3343 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003344 if (badness < 0) {
3345 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003346 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003347 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003348 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3349 cfg->line_out_type, fill_hardwired, fill_mio_first,
3350 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003351 debug_show_configs(spec, cfg);
3352 if (badness < best_badness) {
3353 best_badness = badness;
3354 *best_cfg = *cfg;
3355 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003356 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003357 }
3358 if (!badness)
3359 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003360 fill_mio_first = !fill_mio_first;
3361 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003362 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003363 fill_hardwired = !fill_hardwired;
3364 if (!fill_hardwired)
3365 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003366 if (hp_spk_swapped)
3367 break;
3368 hp_spk_swapped = true;
3369 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003370 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3371 cfg->hp_outs = cfg->line_outs;
3372 memcpy(cfg->hp_pins, cfg->line_out_pins,
3373 sizeof(cfg->hp_pins));
3374 cfg->line_outs = cfg->speaker_outs;
3375 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3376 sizeof(cfg->speaker_pins));
3377 cfg->speaker_outs = 0;
3378 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3379 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003380 fill_hardwired = true;
3381 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003382 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003383 if (cfg->hp_outs > 0 &&
3384 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3385 cfg->speaker_outs = cfg->line_outs;
3386 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3387 sizeof(cfg->speaker_pins));
3388 cfg->line_outs = cfg->hp_outs;
3389 memcpy(cfg->line_out_pins, cfg->hp_pins,
3390 sizeof(cfg->hp_pins));
3391 cfg->hp_outs = 0;
3392 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3393 cfg->line_out_type = AUTO_PIN_HP_OUT;
3394 fill_hardwired = true;
3395 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003396 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003397 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003398 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003399
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003400 if (badness) {
3401 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003402 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003403 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003404 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3405 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003406 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003407
Takashi Iwaiba8111272012-12-06 18:06:23 +01003408 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003409 struct nid_path *path = get_nid_path(codec,
3410 spec->multiout.dac_nids[0],
3411 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003412 if (path)
3413 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3414 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003415
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003416 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003417 return 0;
3418}
3419
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003420/* replace the channels in the composed amp value with the given number */
3421static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3422{
3423 val &= ~(0x3U << 16);
3424 val |= chs << 16;
3425 return val;
3426}
3427
Takashi Iwai343a04b2011-07-06 14:28:39 +02003428static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003429 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003430 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003431 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003432{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003433 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003434 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003435 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003436 val = path->ctls[NID_PATH_VOL_CTL];
3437 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003438 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003439 val = amp_val_replace_channels(val, chs);
3440 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3441}
3442
3443/* return the channel bits suitable for the given path->ctls[] */
3444static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3445 int type)
3446{
3447 int chs = 1; /* mono (left only) */
3448 if (path) {
3449 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3450 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3451 chs = 3; /* stereo */
3452 }
3453 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003454}
3455
Takashi Iwaie29d3772011-11-14 17:13:23 +01003456static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3457 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003458 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003459{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003460 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3461 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003462}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003463
3464/* create a mute-switch for the given mixer widget;
3465 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3466 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003467static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003468 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003469 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003470 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003471{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003472 unsigned int val;
3473 int type = ALC_CTL_WIDGET_MUTE;
3474
3475 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003476 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003477 val = path->ctls[NID_PATH_MUTE_CTL];
3478 if (!val)
3479 return 0;
3480 val = amp_val_replace_channels(val, chs);
3481 if (get_amp_direction_(val) == HDA_INPUT) {
3482 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003483 int nums = snd_hda_get_num_conns(codec, nid);
3484 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003485 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003486 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003487 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003488 }
3489 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003490}
3491
Takashi Iwaie29d3772011-11-14 17:13:23 +01003492static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003493 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003494{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003495 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3496 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003497}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003498
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003499static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003500 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003501{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003502 int i;
3503
3504 for (i = path->depth - 1; i >= 0; i--) {
3505 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3506 return path->path[i];
3507 if (i != path->depth - 1 && i != 0 &&
3508 nid_has_mute(codec, path->path[i], HDA_INPUT))
3509 return path->path[i];
3510 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003511 return 0;
3512}
3513
3514static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003515 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003516{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003517 int i;
3518
3519 for (i = path->depth - 1; i >= 0; i--) {
3520 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3521 return path->path[i];
3522 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003523 return 0;
3524}
3525
Takashi Iwai7085ec12009-10-02 09:03:58 +02003526/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003527static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003528 const struct auto_pin_cfg *cfg)
3529{
3530 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003531 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003532
Takashi Iwaice764ab2011-04-27 16:35:23 +02003533 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003534 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003535 noutputs += spec->multi_ios;
3536
3537 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003538 const char *name;
3539 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003540 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003541 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003542
3543 dac = spec->multiout.dac_nids[i];
3544 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003545 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003546 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003547 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003548 index = 0;
3549 name = channel_name[i];
3550 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003551 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003552 name = alc_get_line_out_pfx(spec, i, true, &index);
3553 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003554
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003555 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003556 if (!path)
3557 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003558 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003559 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003560 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003561 if (err < 0)
3562 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003563 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003564 if (err < 0)
3565 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003566 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003567 if (err < 0)
3568 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003569 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003570 if (err < 0)
3571 return err;
3572 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003573 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003574 if (err < 0)
3575 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003576 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003577 if (err < 0)
3578 return err;
3579 }
3580 }
3581 return 0;
3582}
3583
Takashi Iwai343a04b2011-07-06 14:28:39 +02003584static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003585 hda_nid_t dac, const char *pfx,
3586 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003587{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003588 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003589 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003590
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003591 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003592 if (!path)
3593 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003594 /* bind volume control will be created in the case of dac = 0 */
3595 if (dac) {
3596 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3597 if (err < 0)
3598 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003599 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003600 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003601 if (err < 0)
3602 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003603 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003604}
3605
Takashi Iwai23c09b02011-08-19 09:05:35 +02003606static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3607 unsigned int nums,
3608 struct hda_ctl_ops *ops)
3609{
3610 struct alc_spec *spec = codec->spec;
3611 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003612 ctlp = snd_array_new(&spec->bind_ctls);
3613 if (!ctlp)
3614 return NULL;
3615 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3616 *ctlp = ctl;
3617 if (ctl)
3618 ctl->ops = ops;
3619 return ctl;
3620}
3621
3622/* add playback controls for speaker and HP outputs */
3623static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3624 const hda_nid_t *pins,
3625 const hda_nid_t *dacs,
3626 const char *pfx)
3627{
3628 struct alc_spec *spec = codec->spec;
3629 struct hda_bind_ctls *ctl;
3630 char name[32];
3631 int i, n, err;
3632
3633 if (!num_pins || !pins[0])
3634 return 0;
3635
Takashi Iwai527e4d72011-10-27 16:33:27 +02003636 if (num_pins == 1) {
3637 hda_nid_t dac = *dacs;
3638 if (!dac)
3639 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003640 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003641 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003642
Takashi Iwai23c09b02011-08-19 09:05:35 +02003643 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003644 hda_nid_t dac;
3645 if (dacs[num_pins - 1])
3646 dac = dacs[i]; /* with individual volumes */
3647 else
3648 dac = 0;
3649 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3650 err = alc_auto_create_extra_out(codec, pins[i], dac,
3651 "Bass Speaker", 0);
3652 } else if (num_pins >= 3) {
3653 snprintf(name, sizeof(name), "%s %s",
3654 pfx, channel_name[i]);
3655 err = alc_auto_create_extra_out(codec, pins[i], dac,
3656 name, 0);
3657 } else {
3658 err = alc_auto_create_extra_out(codec, pins[i], dac,
3659 pfx, i);
3660 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003661 if (err < 0)
3662 return err;
3663 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003664 if (dacs[num_pins - 1])
3665 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003666
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003667 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003668 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3669 if (!ctl)
3670 return -ENOMEM;
3671 n = 0;
3672 for (i = 0; i < num_pins; i++) {
3673 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003674 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003675 if (!pins[i] || !dacs[i])
3676 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003677 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003678 if (!path)
3679 continue;
3680 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003681 if (vol)
3682 ctl->values[n++] =
3683 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3684 }
3685 if (n) {
3686 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3687 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3688 if (err < 0)
3689 return err;
3690 }
3691 return 0;
3692}
3693
Takashi Iwai343a04b2011-07-06 14:28:39 +02003694static int alc_auto_create_hp_out(struct hda_codec *codec)
3695{
3696 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003697 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3698 spec->autocfg.hp_pins,
3699 spec->multiout.hp_out_nid,
3700 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003701}
3702
3703static int alc_auto_create_speaker_out(struct hda_codec *codec)
3704{
3705 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003706 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3707 spec->autocfg.speaker_pins,
3708 spec->multiout.extra_out_nid,
3709 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003710}
3711
Takashi Iwai130e5f02012-12-14 16:09:29 +01003712/* check whether a control with the given (nid, dir, idx) was assigned */
3713static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3714 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003715{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003716 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003717 int i, type;
3718
3719 for (i = 0; i < spec->paths.used; i++) {
3720 struct nid_path *p = snd_array_elem(&spec->paths, i);
3721 if (p->depth <= 0)
3722 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003723 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003724 unsigned int val = p->ctls[type];
3725 if (get_amp_nid_(val) == nid &&
3726 get_amp_direction_(val) == dir &&
3727 get_amp_index_(val) == idx)
3728 return true;
3729 }
3730 }
3731 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003732}
3733
3734/* can have the amp-in capability? */
3735static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3736{
3737 hda_nid_t nid = path->path[idx];
3738 unsigned int caps = get_wcaps(codec, nid);
3739 unsigned int type = get_wcaps_type(caps);
3740
3741 if (!(caps & AC_WCAP_IN_AMP))
3742 return false;
3743 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3744 return false;
3745 return true;
3746}
3747
3748/* can have the amp-out capability? */
3749static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3750{
3751 hda_nid_t nid = path->path[idx];
3752 unsigned int caps = get_wcaps(codec, nid);
3753 unsigned int type = get_wcaps_type(caps);
3754
3755 if (!(caps & AC_WCAP_OUT_AMP))
3756 return false;
3757 if (type == AC_WID_PIN && !idx) /* only for output pins */
3758 return false;
3759 return true;
3760}
3761
Takashi Iwaic9967f12012-12-14 16:39:22 +01003762/* check whether the given (nid,dir,idx) is active */
3763static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3764 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003765{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003766 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003767 int i, n;
3768
Takashi Iwaic9967f12012-12-14 16:39:22 +01003769 for (n = 0; n < spec->paths.used; n++) {
3770 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003771 if (!path->active)
3772 continue;
3773 for (i = 0; i < path->depth; i++) {
3774 if (path->path[i] == nid) {
3775 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3776 return true;
3777 break;
3778 }
3779 }
3780 }
3781 return false;
3782}
3783
Takashi Iwai130e5f02012-12-14 16:09:29 +01003784/* get the default amp value for the target state */
3785static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3786 int dir, bool enable)
3787{
3788 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003789 unsigned int val = 0;
3790
3791 caps = query_amp_caps(codec, nid, dir);
3792 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003793 /* set to 0dB */
3794 if (enable)
3795 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003796 }
3797 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003798 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003799 val |= HDA_AMP_MUTE;
3800 }
3801 return val;
3802}
3803
Takashi Iwai130e5f02012-12-14 16:09:29 +01003804/* initialize the amp value (only at the first time) */
3805static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3806{
3807 int val = get_amp_val_to_activate(codec, nid, dir, false);
3808 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3809}
3810
3811static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3812 int idx, bool enable)
3813{
3814 int val;
3815 if (is_ctl_associated(codec, nid, dir, idx) ||
3816 is_active_nid(codec, nid, dir, idx))
3817 return;
3818 val = get_amp_val_to_activate(codec, nid, dir, enable);
3819 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3820}
3821
3822static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3823 int i, bool enable)
3824{
3825 hda_nid_t nid = path->path[i];
3826 init_amp(codec, nid, HDA_OUTPUT, 0);
3827 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3828}
3829
3830static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003831 int i, bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003832{
3833 struct alc_spec *spec = codec->spec;
3834 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003835 int n, nums, idx;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003836 int type;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003837 hda_nid_t nid = path->path[i];
3838
3839 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai666a70d2012-12-17 20:29:29 +01003840 type = get_wcaps_type(get_wcaps(codec, nid));
3841 if (type == AC_WID_PIN ||
3842 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003843 nums = 1;
3844 idx = 0;
3845 } else
3846 idx = path->idx[i];
3847
Takashi Iwai130e5f02012-12-14 16:09:29 +01003848 for (n = 0; n < nums; n++)
3849 init_amp(codec, nid, HDA_INPUT, n);
3850
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003851 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003852 return;
3853
3854 /* here is a little bit tricky in comparison with activate_amp_out();
3855 * when aa-mixer is available, we need to enable the path as well
3856 */
3857 for (n = 0; n < nums; n++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01003858 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003859 continue;
3860 activate_amp(codec, nid, HDA_INPUT, n, enable);
3861 }
3862}
3863
3864static void activate_path(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003865 bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003866{
3867 int i;
3868
Takashi Iwai130e5f02012-12-14 16:09:29 +01003869 if (!enable)
3870 path->active = false;
3871
3872 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003873 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003874 snd_hda_codec_write_cache(codec, path->path[i], 0,
3875 AC_VERB_SET_CONNECT_SEL,
3876 path->idx[i]);
3877 if (has_amp_in(codec, path, i))
Takashi Iwai666a70d2012-12-17 20:29:29 +01003878 activate_amp_in(codec, path, i, enable, add_aamix);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003879 if (has_amp_out(codec, path, i))
3880 activate_amp_out(codec, path, i, enable);
3881 }
3882
3883 if (enable)
3884 path->active = true;
3885}
3886
Takashi Iwai78e635c2012-12-10 17:07:16 +01003887/* configure the path from the given dac to the pin as the proper output */
3888static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3889 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003890 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003891{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003892 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003893
Takashi Iwai130e5f02012-12-14 16:09:29 +01003894 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003895 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003896 if (!path)
3897 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003898 if (path->active)
3899 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003900 activate_path(codec, path, true, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003901}
3902
Takashi Iwai343a04b2011-07-06 14:28:39 +02003903static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003904{
3905 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003906 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003907 int i;
3908
3909 for (i = 0; i <= HDA_SIDE; i++) {
3910 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3911 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003912 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003913 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003914
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003915 }
3916}
3917
Takashi Iwai343a04b2011-07-06 14:28:39 +02003918static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003919{
3920 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003921 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003922 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003923
David Henningsson636030e2011-10-12 19:26:03 +02003924 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003925 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3926 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003927 pin = spec->autocfg.hp_pins[i];
3928 if (!pin)
3929 break;
3930 dac = spec->multiout.hp_out_nid[i];
3931 if (!dac) {
3932 if (i > 0 && spec->multiout.hp_out_nid[0])
3933 dac = spec->multiout.hp_out_nid[0];
3934 else
3935 dac = spec->multiout.dac_nids[0];
3936 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003937 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003938 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003939 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003940 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3941 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003942 pin = spec->autocfg.speaker_pins[i];
3943 if (!pin)
3944 break;
3945 dac = spec->multiout.extra_out_nid[i];
3946 if (!dac) {
3947 if (i > 0 && spec->multiout.extra_out_nid[0])
3948 dac = spec->multiout.extra_out_nid[0];
3949 else
3950 dac = spec->multiout.dac_nids[0];
3951 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003952 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003953 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003954}
3955
Takashi Iwai276dd702012-02-17 16:17:03 +01003956/* check whether the given pin can be a multi-io pin */
3957static bool can_be_multiio_pin(struct hda_codec *codec,
3958 unsigned int location, hda_nid_t nid)
3959{
3960 unsigned int defcfg, caps;
3961
3962 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3963 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3964 return false;
3965 if (location && get_defcfg_location(defcfg) != location)
3966 return false;
3967 caps = snd_hda_query_pin_caps(codec, nid);
3968 if (!(caps & AC_PINCAP_OUT))
3969 return false;
3970 return true;
3971}
3972
Takashi Iwaice764ab2011-04-27 16:35:23 +02003973/*
3974 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003975 *
3976 * When hardwired is set, try to fill ony hardwired pins, and returns
3977 * zero if any pins are filled, non-zero if nothing found.
3978 * When hardwired is off, try to fill possible input pins, and returns
3979 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003980 */
3981static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003982 hda_nid_t reference_pin,
3983 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003984{
3985 struct alc_spec *spec = codec->spec;
3986 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003987 int type, i, j, dacs, num_pins, old_pins;
3988 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3989 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003990 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003991
Takashi Iwai276dd702012-02-17 16:17:03 +01003992 old_pins = spec->multi_ios;
3993 if (old_pins >= 2)
3994 goto end_fill;
3995
3996 num_pins = 0;
3997 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3998 for (i = 0; i < cfg->num_inputs; i++) {
3999 if (cfg->inputs[i].type != type)
4000 continue;
4001 if (can_be_multiio_pin(codec, location,
4002 cfg->inputs[i].pin))
4003 num_pins++;
4004 }
4005 }
4006 if (num_pins < 2)
4007 goto end_fill;
4008
Takashi Iwai07b18f62011-11-10 15:42:54 +01004009 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004010 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4011 for (i = 0; i < cfg->num_inputs; i++) {
4012 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004013 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004014
Takashi Iwaice764ab2011-04-27 16:35:23 +02004015 if (cfg->inputs[i].type != type)
4016 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004017 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004018 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004019 for (j = 0; j < spec->multi_ios; j++) {
4020 if (nid == spec->multi_io[j].pin)
4021 break;
4022 }
4023 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004024 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004025
4026 if (offset && offset + spec->multi_ios < dacs) {
4027 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004028 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004029 dac = 0;
4030 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004031 if (hardwired)
4032 dac = get_dac_if_single(codec, nid);
4033 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004034 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004035 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004036 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004037 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004038 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004039 if (!add_new_out_path(codec, nid, dac)) {
4040 badness++;
4041 continue;
4042 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004043 spec->multi_io[spec->multi_ios].pin = nid;
4044 spec->multi_io[spec->multi_ios].dac = dac;
4045 spec->multi_ios++;
4046 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004047 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004048 }
4049 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004050 end_fill:
4051 if (badness)
4052 badness = BAD_MULTI_IO;
4053 if (old_pins == spec->multi_ios) {
4054 if (hardwired)
4055 return 1; /* nothing found */
4056 else
4057 return badness; /* no badness if nothing found */
4058 }
4059 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004060 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004061 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004062 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004063 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004064 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004065
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004066 /* assign volume and mute controls */
4067 for (i = old_pins; i < spec->multi_ios; i++)
4068 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4069 spec->multi_io[i].dac);
4070
4071 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004072}
4073
4074static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4075 struct snd_ctl_elem_info *uinfo)
4076{
4077 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4078 struct alc_spec *spec = codec->spec;
4079
4080 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4081 uinfo->count = 1;
4082 uinfo->value.enumerated.items = spec->multi_ios + 1;
4083 if (uinfo->value.enumerated.item > spec->multi_ios)
4084 uinfo->value.enumerated.item = spec->multi_ios;
4085 sprintf(uinfo->value.enumerated.name, "%dch",
4086 (uinfo->value.enumerated.item + 1) * 2);
4087 return 0;
4088}
4089
4090static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4091 struct snd_ctl_elem_value *ucontrol)
4092{
4093 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4094 struct alc_spec *spec = codec->spec;
4095 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4096 return 0;
4097}
4098
4099static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4100{
4101 struct alc_spec *spec = codec->spec;
4102 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004103 struct nid_path *path;
4104
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004105 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004106 if (!path)
4107 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004108
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004109 if (path->active == output)
4110 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004111
Takashi Iwaice764ab2011-04-27 16:35:23 +02004112 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004113 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004114 activate_path(codec, path, true, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004115 } else {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004116 activate_path(codec, path, false, true);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004117 snd_hda_set_pin_ctl_cache(codec, nid,
4118 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004119 }
4120 return 0;
4121}
4122
4123static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4124 struct snd_ctl_elem_value *ucontrol)
4125{
4126 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4127 struct alc_spec *spec = codec->spec;
4128 int i, ch;
4129
4130 ch = ucontrol->value.enumerated.item[0];
4131 if (ch < 0 || ch > spec->multi_ios)
4132 return -EINVAL;
4133 if (ch == (spec->ext_channel_count - 1) / 2)
4134 return 0;
4135 spec->ext_channel_count = (ch + 1) * 2;
4136 for (i = 0; i < spec->multi_ios; i++)
4137 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004138 spec->multiout.max_channels = max(spec->ext_channel_count,
4139 spec->const_channel_count);
4140 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004141 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004142 return 1;
4143}
4144
Takashi Iwaia9111322011-05-02 11:30:18 +02004145static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004146 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4147 .name = "Channel Mode",
4148 .info = alc_auto_ch_mode_info,
4149 .get = alc_auto_ch_mode_get,
4150 .put = alc_auto_ch_mode_put,
4151};
4152
Takashi Iwai23c09b02011-08-19 09:05:35 +02004153static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004154{
4155 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004156
Takashi Iwaic2674682011-08-24 17:57:44 +02004157 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004158 if (!alc_kcontrol_new(spec, "Channel Mode",
4159 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004160 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004161 }
4162 return 0;
4163}
4164
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004165static void alc_auto_init_multi_io(struct hda_codec *codec)
4166{
4167 struct alc_spec *spec = codec->spec;
4168 int i;
4169
4170 for (i = 0; i < spec->multi_ios; i++) {
4171 hda_nid_t pin = spec->multi_io[i].pin;
4172 struct nid_path *path;
4173 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4174 if (!path)
4175 continue;
4176 if (!spec->multi_io[i].ctl_in)
4177 spec->multi_io[i].ctl_in =
4178 snd_hda_codec_update_cache(codec, pin, 0,
4179 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004180 activate_path(codec, path, path->active, true);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004181 }
4182}
4183
Takashi Iwai1d045db2011-07-07 18:23:21 +02004184/*
4185 * initialize ADC paths
4186 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004187static void alc_auto_init_input_src(struct hda_codec *codec)
4188{
4189 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004190 struct hda_input_mux *imux = &spec->private_imux[0];
4191 struct nid_path *path;
4192 int i, c, nums;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004193
Takashi Iwai1d045db2011-07-07 18:23:21 +02004194 if (spec->dyn_adc_switch)
4195 nums = 1;
4196 else
4197 nums = spec->num_adc_nids;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004198
4199 for (c = 0; c < nums; c++) {
4200 for (i = 0; i < imux->num_items; i++) {
4201 path = get_nid_path(codec, spec->imux_pins[i],
4202 get_adc_nid(codec, c, i));
4203 if (path) {
4204 bool active = path->active;
4205 if (i == spec->cur_mux[c])
4206 active = true;
4207 activate_path(codec, path, active, false);
4208 }
4209 }
4210 }
4211
4212 alc_inv_dmic_sync(codec, true);
4213 if (spec->shared_mic_hp)
4214 update_shared_mic_hp(codec, spec->cur_mux[0]);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004215}
4216
4217/* add mic boosts if needed */
4218static int alc_auto_add_mic_boost(struct hda_codec *codec)
4219{
4220 struct alc_spec *spec = codec->spec;
4221 struct auto_pin_cfg *cfg = &spec->autocfg;
4222 int i, err;
4223 int type_idx = 0;
4224 hda_nid_t nid;
4225 const char *prev_label = NULL;
4226
4227 for (i = 0; i < cfg->num_inputs; i++) {
4228 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4229 break;
4230 nid = cfg->inputs[i].pin;
4231 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4232 const char *label;
4233 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004234 struct nid_path *path;
4235 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004236
4237 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004238 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4239 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004240 if (prev_label && !strcmp(label, prev_label))
4241 type_idx++;
4242 else
4243 type_idx = 0;
4244 prev_label = label;
4245
4246 snprintf(boost_label, sizeof(boost_label),
4247 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004248 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004249 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004250 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004251 if (err < 0)
4252 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004253
4254 path = get_nid_path(codec, nid, 0);
4255 if (path)
4256 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004257 }
4258 }
4259 return 0;
4260}
4261
Takashi Iwai1d045db2011-07-07 18:23:21 +02004262/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004263 * standard auto-parser initializations
4264 */
4265static void alc_auto_init_std(struct hda_codec *codec)
4266{
Takashi Iwaie4770622011-07-08 11:11:35 +02004267 alc_auto_init_multi_out(codec);
4268 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004269 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004270 alc_auto_init_analog_input(codec);
4271 alc_auto_init_input_src(codec);
4272 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004273 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004274}
4275
4276/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004277 * Digital-beep handlers
4278 */
4279#ifdef CONFIG_SND_HDA_INPUT_BEEP
4280#define set_beep_amp(spec, nid, idx, dir) \
4281 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4282
4283static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004284 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004285 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4286 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4287 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4288 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004289 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004290 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4291 {}
4292};
4293
4294static inline int has_cdefine_beep(struct hda_codec *codec)
4295{
4296 struct alc_spec *spec = codec->spec;
4297 const struct snd_pci_quirk *q;
4298 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4299 if (q)
4300 return q->value;
4301 return spec->cdefine.enable_pcbeep;
4302}
4303#else
4304#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4305#define has_cdefine_beep(codec) 0
4306#endif
4307
4308/* parse the BIOS configuration and set up the alc_spec */
4309/* return 1 if successful, 0 if the proper config is not found,
4310 * or a negative error code
4311 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004312static int alc_parse_auto_config(struct hda_codec *codec,
4313 const hda_nid_t *ignore_nids,
4314 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004315{
4316 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004317 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004318 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004319
Takashi Iwai53c334a2011-08-23 18:27:14 +02004320 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4321 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004322 if (err < 0)
4323 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004324 if (!cfg->line_outs) {
4325 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004326 spec->multiout.max_channels = 2;
4327 spec->no_analog = 1;
4328 goto dig_only;
4329 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004330 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004331 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004332
Takashi Iwaie427c232012-07-29 10:04:08 +02004333 if (!spec->no_primary_hp &&
4334 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004335 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004336 /* use HP as primary out */
4337 cfg->speaker_outs = cfg->line_outs;
4338 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4339 sizeof(cfg->speaker_pins));
4340 cfg->line_outs = cfg->hp_outs;
4341 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4342 cfg->hp_outs = 0;
4343 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4344 cfg->line_out_type = AUTO_PIN_HP_OUT;
4345 }
4346
Takashi Iwai1d045db2011-07-07 18:23:21 +02004347 err = alc_auto_fill_dac_nids(codec);
4348 if (err < 0)
4349 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004350 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004351 if (err < 0)
4352 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004353 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004354 if (err < 0)
4355 return err;
4356 err = alc_auto_create_hp_out(codec);
4357 if (err < 0)
4358 return err;
4359 err = alc_auto_create_speaker_out(codec);
4360 if (err < 0)
4361 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004362 err = alc_auto_create_shared_input(codec);
4363 if (err < 0)
4364 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004365 err = alc_auto_create_input_ctls(codec);
4366 if (err < 0)
4367 return err;
4368
Takashi Iwaib6adb572012-12-03 10:30:58 +01004369 /* check the multiple speaker pins */
4370 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4371 spec->const_channel_count = cfg->line_outs * 2;
4372 else
4373 spec->const_channel_count = cfg->speaker_outs * 2;
4374
4375 if (spec->multi_ios > 0)
4376 spec->multiout.max_channels = max(spec->ext_channel_count,
4377 spec->const_channel_count);
4378 else
4379 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004380
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004381 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004382 alc_auto_parse_digital(codec);
4383
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004384 if (ssid_nids)
4385 alc_ssid_check(codec, ssid_nids);
4386
4387 if (!spec->no_analog) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004388 err = alc_init_automute(codec);
Takashi Iwai475c3d22012-11-30 08:31:30 +01004389 if (err < 0)
4390 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004391
4392 err = check_dyn_adc_switch(codec);
4393 if (err < 0)
4394 return err;
4395
4396 if (!spec->shared_mic_hp) {
4397 err = alc_init_auto_mic(codec);
4398 if (err < 0)
4399 return err;
4400 }
4401
4402 err = create_capture_mixers(codec);
4403 if (err < 0)
4404 return err;
4405
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004406 err = alc_auto_add_mic_boost(codec);
4407 if (err < 0)
4408 return err;
4409 }
4410
Takashi Iwai1d045db2011-07-07 18:23:21 +02004411 if (spec->kctls.list)
4412 add_mixer(spec, spec->kctls.list);
4413
Takashi Iwai1d045db2011-07-07 18:23:21 +02004414 return 1;
4415}
4416
Takashi Iwai3de95172012-05-07 18:03:15 +02004417/* common preparation job for alc_spec */
4418static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4419{
4420 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4421 int err;
4422
4423 if (!spec)
4424 return -ENOMEM;
4425 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004426 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004427 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004428 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004429 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4430 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004431 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004432
4433 err = alc_codec_rename_from_preset(codec);
4434 if (err < 0) {
4435 kfree(spec);
4436 return err;
4437 }
4438 return 0;
4439}
4440
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004441static int alc880_parse_auto_config(struct hda_codec *codec)
4442{
4443 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004444 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004445 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4446}
4447
Takashi Iwai1d045db2011-07-07 18:23:21 +02004448/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004449 * ALC880 fix-ups
4450 */
4451enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004452 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004453 ALC880_FIXUP_GPIO2,
4454 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004455 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004456 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004457 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004458 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004459 ALC880_FIXUP_VOL_KNOB,
4460 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004461 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004462 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004463 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004464 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004465 ALC880_FIXUP_3ST_BASE,
4466 ALC880_FIXUP_3ST,
4467 ALC880_FIXUP_3ST_DIG,
4468 ALC880_FIXUP_5ST_BASE,
4469 ALC880_FIXUP_5ST,
4470 ALC880_FIXUP_5ST_DIG,
4471 ALC880_FIXUP_6ST_BASE,
4472 ALC880_FIXUP_6ST,
4473 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004474};
4475
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004476/* enable the volume-knob widget support on NID 0x21 */
4477static void alc880_fixup_vol_knob(struct hda_codec *codec,
4478 const struct alc_fixup *fix, int action)
4479{
4480 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004481 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004482}
4483
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004484static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004485 [ALC880_FIXUP_GPIO1] = {
4486 .type = ALC_FIXUP_VERBS,
4487 .v.verbs = alc_gpio1_init_verbs,
4488 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004489 [ALC880_FIXUP_GPIO2] = {
4490 .type = ALC_FIXUP_VERBS,
4491 .v.verbs = alc_gpio2_init_verbs,
4492 },
4493 [ALC880_FIXUP_MEDION_RIM] = {
4494 .type = ALC_FIXUP_VERBS,
4495 .v.verbs = (const struct hda_verb[]) {
4496 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4497 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4498 { }
4499 },
4500 .chained = true,
4501 .chain_id = ALC880_FIXUP_GPIO2,
4502 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004503 [ALC880_FIXUP_LG] = {
4504 .type = ALC_FIXUP_PINS,
4505 .v.pins = (const struct alc_pincfg[]) {
4506 /* disable bogus unused pins */
4507 { 0x16, 0x411111f0 },
4508 { 0x18, 0x411111f0 },
4509 { 0x1a, 0x411111f0 },
4510 { }
4511 }
4512 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004513 [ALC880_FIXUP_W810] = {
4514 .type = ALC_FIXUP_PINS,
4515 .v.pins = (const struct alc_pincfg[]) {
4516 /* disable bogus unused pins */
4517 { 0x17, 0x411111f0 },
4518 { }
4519 },
4520 .chained = true,
4521 .chain_id = ALC880_FIXUP_GPIO2,
4522 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004523 [ALC880_FIXUP_EAPD_COEF] = {
4524 .type = ALC_FIXUP_VERBS,
4525 .v.verbs = (const struct hda_verb[]) {
4526 /* change to EAPD mode */
4527 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4528 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4529 {}
4530 },
4531 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004532 [ALC880_FIXUP_TCL_S700] = {
4533 .type = ALC_FIXUP_VERBS,
4534 .v.verbs = (const struct hda_verb[]) {
4535 /* change to EAPD mode */
4536 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4537 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4538 {}
4539 },
4540 .chained = true,
4541 .chain_id = ALC880_FIXUP_GPIO2,
4542 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004543 [ALC880_FIXUP_VOL_KNOB] = {
4544 .type = ALC_FIXUP_FUNC,
4545 .v.func = alc880_fixup_vol_knob,
4546 },
4547 [ALC880_FIXUP_FUJITSU] = {
4548 /* override all pins as BIOS on old Amilo is broken */
4549 .type = ALC_FIXUP_PINS,
4550 .v.pins = (const struct alc_pincfg[]) {
4551 { 0x14, 0x0121411f }, /* HP */
4552 { 0x15, 0x99030120 }, /* speaker */
4553 { 0x16, 0x99030130 }, /* bass speaker */
4554 { 0x17, 0x411111f0 }, /* N/A */
4555 { 0x18, 0x411111f0 }, /* N/A */
4556 { 0x19, 0x01a19950 }, /* mic-in */
4557 { 0x1a, 0x411111f0 }, /* N/A */
4558 { 0x1b, 0x411111f0 }, /* N/A */
4559 { 0x1c, 0x411111f0 }, /* N/A */
4560 { 0x1d, 0x411111f0 }, /* N/A */
4561 { 0x1e, 0x01454140 }, /* SPDIF out */
4562 { }
4563 },
4564 .chained = true,
4565 .chain_id = ALC880_FIXUP_VOL_KNOB,
4566 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004567 [ALC880_FIXUP_F1734] = {
4568 /* almost compatible with FUJITSU, but no bass and SPDIF */
4569 .type = ALC_FIXUP_PINS,
4570 .v.pins = (const struct alc_pincfg[]) {
4571 { 0x14, 0x0121411f }, /* HP */
4572 { 0x15, 0x99030120 }, /* speaker */
4573 { 0x16, 0x411111f0 }, /* N/A */
4574 { 0x17, 0x411111f0 }, /* N/A */
4575 { 0x18, 0x411111f0 }, /* N/A */
4576 { 0x19, 0x01a19950 }, /* mic-in */
4577 { 0x1a, 0x411111f0 }, /* N/A */
4578 { 0x1b, 0x411111f0 }, /* N/A */
4579 { 0x1c, 0x411111f0 }, /* N/A */
4580 { 0x1d, 0x411111f0 }, /* N/A */
4581 { 0x1e, 0x411111f0 }, /* N/A */
4582 { }
4583 },
4584 .chained = true,
4585 .chain_id = ALC880_FIXUP_VOL_KNOB,
4586 },
Takashi Iwai817de922012-02-20 17:20:48 +01004587 [ALC880_FIXUP_UNIWILL] = {
4588 /* need to fix HP and speaker pins to be parsed correctly */
4589 .type = ALC_FIXUP_PINS,
4590 .v.pins = (const struct alc_pincfg[]) {
4591 { 0x14, 0x0121411f }, /* HP */
4592 { 0x15, 0x99030120 }, /* speaker */
4593 { 0x16, 0x99030130 }, /* bass speaker */
4594 { }
4595 },
4596 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004597 [ALC880_FIXUP_UNIWILL_DIG] = {
4598 .type = ALC_FIXUP_PINS,
4599 .v.pins = (const struct alc_pincfg[]) {
4600 /* disable bogus unused pins */
4601 { 0x17, 0x411111f0 },
4602 { 0x19, 0x411111f0 },
4603 { 0x1b, 0x411111f0 },
4604 { 0x1f, 0x411111f0 },
4605 { }
4606 }
4607 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004608 [ALC880_FIXUP_Z71V] = {
4609 .type = ALC_FIXUP_PINS,
4610 .v.pins = (const struct alc_pincfg[]) {
4611 /* set up the whole pins as BIOS is utterly broken */
4612 { 0x14, 0x99030120 }, /* speaker */
4613 { 0x15, 0x0121411f }, /* HP */
4614 { 0x16, 0x411111f0 }, /* N/A */
4615 { 0x17, 0x411111f0 }, /* N/A */
4616 { 0x18, 0x01a19950 }, /* mic-in */
4617 { 0x19, 0x411111f0 }, /* N/A */
4618 { 0x1a, 0x01813031 }, /* line-in */
4619 { 0x1b, 0x411111f0 }, /* N/A */
4620 { 0x1c, 0x411111f0 }, /* N/A */
4621 { 0x1d, 0x411111f0 }, /* N/A */
4622 { 0x1e, 0x0144111e }, /* SPDIF */
4623 { }
4624 }
4625 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004626 [ALC880_FIXUP_3ST_BASE] = {
4627 .type = ALC_FIXUP_PINS,
4628 .v.pins = (const struct alc_pincfg[]) {
4629 { 0x14, 0x01014010 }, /* line-out */
4630 { 0x15, 0x411111f0 }, /* N/A */
4631 { 0x16, 0x411111f0 }, /* N/A */
4632 { 0x17, 0x411111f0 }, /* N/A */
4633 { 0x18, 0x01a19c30 }, /* mic-in */
4634 { 0x19, 0x0121411f }, /* HP */
4635 { 0x1a, 0x01813031 }, /* line-in */
4636 { 0x1b, 0x02a19c40 }, /* front-mic */
4637 { 0x1c, 0x411111f0 }, /* N/A */
4638 { 0x1d, 0x411111f0 }, /* N/A */
4639 /* 0x1e is filled in below */
4640 { 0x1f, 0x411111f0 }, /* N/A */
4641 { }
4642 }
4643 },
4644 [ALC880_FIXUP_3ST] = {
4645 .type = ALC_FIXUP_PINS,
4646 .v.pins = (const struct alc_pincfg[]) {
4647 { 0x1e, 0x411111f0 }, /* N/A */
4648 { }
4649 },
4650 .chained = true,
4651 .chain_id = ALC880_FIXUP_3ST_BASE,
4652 },
4653 [ALC880_FIXUP_3ST_DIG] = {
4654 .type = ALC_FIXUP_PINS,
4655 .v.pins = (const struct alc_pincfg[]) {
4656 { 0x1e, 0x0144111e }, /* SPDIF */
4657 { }
4658 },
4659 .chained = true,
4660 .chain_id = ALC880_FIXUP_3ST_BASE,
4661 },
4662 [ALC880_FIXUP_5ST_BASE] = {
4663 .type = ALC_FIXUP_PINS,
4664 .v.pins = (const struct alc_pincfg[]) {
4665 { 0x14, 0x01014010 }, /* front */
4666 { 0x15, 0x411111f0 }, /* N/A */
4667 { 0x16, 0x01011411 }, /* CLFE */
4668 { 0x17, 0x01016412 }, /* surr */
4669 { 0x18, 0x01a19c30 }, /* mic-in */
4670 { 0x19, 0x0121411f }, /* HP */
4671 { 0x1a, 0x01813031 }, /* line-in */
4672 { 0x1b, 0x02a19c40 }, /* front-mic */
4673 { 0x1c, 0x411111f0 }, /* N/A */
4674 { 0x1d, 0x411111f0 }, /* N/A */
4675 /* 0x1e is filled in below */
4676 { 0x1f, 0x411111f0 }, /* N/A */
4677 { }
4678 }
4679 },
4680 [ALC880_FIXUP_5ST] = {
4681 .type = ALC_FIXUP_PINS,
4682 .v.pins = (const struct alc_pincfg[]) {
4683 { 0x1e, 0x411111f0 }, /* N/A */
4684 { }
4685 },
4686 .chained = true,
4687 .chain_id = ALC880_FIXUP_5ST_BASE,
4688 },
4689 [ALC880_FIXUP_5ST_DIG] = {
4690 .type = ALC_FIXUP_PINS,
4691 .v.pins = (const struct alc_pincfg[]) {
4692 { 0x1e, 0x0144111e }, /* SPDIF */
4693 { }
4694 },
4695 .chained = true,
4696 .chain_id = ALC880_FIXUP_5ST_BASE,
4697 },
4698 [ALC880_FIXUP_6ST_BASE] = {
4699 .type = ALC_FIXUP_PINS,
4700 .v.pins = (const struct alc_pincfg[]) {
4701 { 0x14, 0x01014010 }, /* front */
4702 { 0x15, 0x01016412 }, /* surr */
4703 { 0x16, 0x01011411 }, /* CLFE */
4704 { 0x17, 0x01012414 }, /* side */
4705 { 0x18, 0x01a19c30 }, /* mic-in */
4706 { 0x19, 0x02a19c40 }, /* front-mic */
4707 { 0x1a, 0x01813031 }, /* line-in */
4708 { 0x1b, 0x0121411f }, /* HP */
4709 { 0x1c, 0x411111f0 }, /* N/A */
4710 { 0x1d, 0x411111f0 }, /* N/A */
4711 /* 0x1e is filled in below */
4712 { 0x1f, 0x411111f0 }, /* N/A */
4713 { }
4714 }
4715 },
4716 [ALC880_FIXUP_6ST] = {
4717 .type = ALC_FIXUP_PINS,
4718 .v.pins = (const struct alc_pincfg[]) {
4719 { 0x1e, 0x411111f0 }, /* N/A */
4720 { }
4721 },
4722 .chained = true,
4723 .chain_id = ALC880_FIXUP_6ST_BASE,
4724 },
4725 [ALC880_FIXUP_6ST_DIG] = {
4726 .type = ALC_FIXUP_PINS,
4727 .v.pins = (const struct alc_pincfg[]) {
4728 { 0x1e, 0x0144111e }, /* SPDIF */
4729 { }
4730 },
4731 .chained = true,
4732 .chain_id = ALC880_FIXUP_6ST_BASE,
4733 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004734};
4735
4736static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004737 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004738 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004739 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4740 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004741 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004742 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004743 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004744 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004745 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004746 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004747 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004748 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004749 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004750 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004751 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004752 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4753 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4754 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004755 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004756
4757 /* Below is the copied entries from alc880_quirks.c.
4758 * It's not quite sure whether BIOS sets the correct pin-config table
4759 * on these machines, thus they are kept to be compatible with
4760 * the old static quirks. Once when it's confirmed to work without
4761 * these overrides, it'd be better to remove.
4762 */
4763 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4764 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4765 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4766 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4767 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4768 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4769 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4770 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4771 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4772 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4773 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4774 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4775 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4776 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4777 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4778 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4779 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4780 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4781 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4782 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4783 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4784 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4785 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4786 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4787 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4788 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4789 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4790 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4791 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4792 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4793 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4794 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4795 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4796 /* default Intel */
4797 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4798 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4799 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4800 {}
4801};
4802
4803static const struct alc_model_fixup alc880_fixup_models[] = {
4804 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4805 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4806 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4807 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4808 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4809 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004810 {}
4811};
4812
4813
4814/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004815 * OK, here we have finally the patch for ALC880
4816 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004817static int patch_alc880(struct hda_codec *codec)
4818{
4819 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004820 int err;
4821
Takashi Iwai3de95172012-05-07 18:03:15 +02004822 err = alc_alloc_spec(codec, 0x0b);
4823 if (err < 0)
4824 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004825
Takashi Iwai3de95172012-05-07 18:03:15 +02004826 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004827 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004828
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004829 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4830 alc880_fixups);
4831 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004832
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004833 /* automatic parse from the BIOS config */
4834 err = alc880_parse_auto_config(codec);
4835 if (err < 0)
4836 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004837
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004838 if (!spec->no_analog) {
4839 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004840 if (err < 0)
4841 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004842 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4843 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004844
Takashi Iwai1d045db2011-07-07 18:23:21 +02004845 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004846 codec->patch_ops.unsol_event = alc880_unsol_event;
4847
Takashi Iwai1d045db2011-07-07 18:23:21 +02004848
Takashi Iwai589876e2012-02-20 15:47:55 +01004849 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4850
Takashi Iwai1d045db2011-07-07 18:23:21 +02004851 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004852
4853 error:
4854 alc_free(codec);
4855 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004856}
4857
4858
4859/*
4860 * ALC260 support
4861 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004862static int alc260_parse_auto_config(struct hda_codec *codec)
4863{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004864 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004865 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4866 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004867}
4868
Takashi Iwai1d045db2011-07-07 18:23:21 +02004869/*
4870 * Pin config fixes
4871 */
4872enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004873 ALC260_FIXUP_HP_DC5750,
4874 ALC260_FIXUP_HP_PIN_0F,
4875 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004876 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004877 ALC260_FIXUP_GPIO1_TOGGLE,
4878 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004879 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004880 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881};
4882
Takashi Iwai20f7d922012-02-16 12:35:16 +01004883static void alc260_gpio1_automute(struct hda_codec *codec)
4884{
4885 struct alc_spec *spec = codec->spec;
4886 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4887 spec->hp_jack_present);
4888}
4889
4890static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4891 const struct alc_fixup *fix, int action)
4892{
4893 struct alc_spec *spec = codec->spec;
4894 if (action == ALC_FIXUP_ACT_PROBE) {
4895 /* although the machine has only one output pin, we need to
4896 * toggle GPIO1 according to the jack state
4897 */
4898 spec->automute_hook = alc260_gpio1_automute;
4899 spec->detect_hp = 1;
4900 spec->automute_speaker = 1;
4901 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004902 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4903 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004904 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004905 }
4906}
4907
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004908static void alc260_fixup_kn1(struct hda_codec *codec,
4909 const struct alc_fixup *fix, int action)
4910{
4911 struct alc_spec *spec = codec->spec;
4912 static const struct alc_pincfg pincfgs[] = {
4913 { 0x0f, 0x02214000 }, /* HP/speaker */
4914 { 0x12, 0x90a60160 }, /* int mic */
4915 { 0x13, 0x02a19000 }, /* ext mic */
4916 { 0x18, 0x01446000 }, /* SPDIF out */
4917 /* disable bogus I/O pins */
4918 { 0x10, 0x411111f0 },
4919 { 0x11, 0x411111f0 },
4920 { 0x14, 0x411111f0 },
4921 { 0x15, 0x411111f0 },
4922 { 0x16, 0x411111f0 },
4923 { 0x17, 0x411111f0 },
4924 { 0x19, 0x411111f0 },
4925 { }
4926 };
4927
4928 switch (action) {
4929 case ALC_FIXUP_ACT_PRE_PROBE:
4930 alc_apply_pincfgs(codec, pincfgs);
4931 break;
4932 case ALC_FIXUP_ACT_PROBE:
4933 spec->init_amp = ALC_INIT_NONE;
4934 break;
4935 }
4936}
4937
Takashi Iwai1d045db2011-07-07 18:23:21 +02004938static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004939 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004940 .type = ALC_FIXUP_PINS,
4941 .v.pins = (const struct alc_pincfg[]) {
4942 { 0x11, 0x90130110 }, /* speaker */
4943 { }
4944 }
4945 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004946 [ALC260_FIXUP_HP_PIN_0F] = {
4947 .type = ALC_FIXUP_PINS,
4948 .v.pins = (const struct alc_pincfg[]) {
4949 { 0x0f, 0x01214000 }, /* HP */
4950 { }
4951 }
4952 },
4953 [ALC260_FIXUP_COEF] = {
4954 .type = ALC_FIXUP_VERBS,
4955 .v.verbs = (const struct hda_verb[]) {
4956 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4957 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4958 { }
4959 },
4960 .chained = true,
4961 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4962 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004963 [ALC260_FIXUP_GPIO1] = {
4964 .type = ALC_FIXUP_VERBS,
4965 .v.verbs = alc_gpio1_init_verbs,
4966 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004967 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4968 .type = ALC_FIXUP_FUNC,
4969 .v.func = alc260_fixup_gpio1_toggle,
4970 .chained = true,
4971 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4972 },
4973 [ALC260_FIXUP_REPLACER] = {
4974 .type = ALC_FIXUP_VERBS,
4975 .v.verbs = (const struct hda_verb[]) {
4976 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4977 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4978 { }
4979 },
4980 .chained = true,
4981 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4982 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004983 [ALC260_FIXUP_HP_B1900] = {
4984 .type = ALC_FIXUP_FUNC,
4985 .v.func = alc260_fixup_gpio1_toggle,
4986 .chained = true,
4987 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004988 },
4989 [ALC260_FIXUP_KN1] = {
4990 .type = ALC_FIXUP_FUNC,
4991 .v.func = alc260_fixup_kn1,
4992 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993};
4994
4995static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004996 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004997 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004998 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004999 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005000 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005001 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005002 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005003 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005004 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005 {}
5006};
5007
5008/*
5009 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005010static int patch_alc260(struct hda_codec *codec)
5011{
5012 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005013 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005014
Takashi Iwai3de95172012-05-07 18:03:15 +02005015 err = alc_alloc_spec(codec, 0x07);
5016 if (err < 0)
5017 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005018
Takashi Iwai3de95172012-05-07 18:03:15 +02005019 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005020
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005021 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5022 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005023
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005024 /* automatic parse from the BIOS config */
5025 err = alc260_parse_auto_config(codec);
5026 if (err < 0)
5027 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005028
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005029 if (!spec->no_analog) {
5030 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005031 if (err < 0)
5032 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005033 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5034 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005035
Takashi Iwai1d045db2011-07-07 18:23:21 +02005036 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005037 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005038
Takashi Iwai589876e2012-02-20 15:47:55 +01005039 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5040
Takashi Iwai1d045db2011-07-07 18:23:21 +02005041 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005042
5043 error:
5044 alc_free(codec);
5045 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005046}
5047
5048
5049/*
5050 * ALC882/883/885/888/889 support
5051 *
5052 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5053 * configuration. Each pin widget can choose any input DACs and a mixer.
5054 * Each ADC is connected from a mixer of all inputs. This makes possible
5055 * 6-channel independent captures.
5056 *
5057 * In addition, an independent DAC for the multi-playback (not used in this
5058 * driver yet).
5059 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005060
5061/*
5062 * Pin config fixes
5063 */
5064enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005065 ALC882_FIXUP_ABIT_AW9D_MAX,
5066 ALC882_FIXUP_LENOVO_Y530,
5067 ALC882_FIXUP_PB_M5210,
5068 ALC882_FIXUP_ACER_ASPIRE_7736,
5069 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005070 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005071 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005072 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005073 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005074 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005075 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005076 ALC882_FIXUP_GPIO1,
5077 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005078 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005079 ALC889_FIXUP_COEF,
5080 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005081 ALC882_FIXUP_ACER_ASPIRE_4930G,
5082 ALC882_FIXUP_ACER_ASPIRE_8930G,
5083 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005084 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005085 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005086 ALC889_FIXUP_MBP_VREF,
5087 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005088 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005089 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005090};
5091
Takashi Iwai68ef0562011-11-09 18:24:44 +01005092static void alc889_fixup_coef(struct hda_codec *codec,
5093 const struct alc_fixup *fix, int action)
5094{
5095 if (action != ALC_FIXUP_ACT_INIT)
5096 return;
5097 alc889_coef_init(codec);
5098}
5099
Takashi Iwai56710872011-11-14 17:42:11 +01005100/* toggle speaker-output according to the hp-jack state */
5101static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5102{
5103 unsigned int gpiostate, gpiomask, gpiodir;
5104
5105 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5106 AC_VERB_GET_GPIO_DATA, 0);
5107
5108 if (!muted)
5109 gpiostate |= (1 << pin);
5110 else
5111 gpiostate &= ~(1 << pin);
5112
5113 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5114 AC_VERB_GET_GPIO_MASK, 0);
5115 gpiomask |= (1 << pin);
5116
5117 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5118 AC_VERB_GET_GPIO_DIRECTION, 0);
5119 gpiodir |= (1 << pin);
5120
5121
5122 snd_hda_codec_write(codec, codec->afg, 0,
5123 AC_VERB_SET_GPIO_MASK, gpiomask);
5124 snd_hda_codec_write(codec, codec->afg, 0,
5125 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5126
5127 msleep(1);
5128
5129 snd_hda_codec_write(codec, codec->afg, 0,
5130 AC_VERB_SET_GPIO_DATA, gpiostate);
5131}
5132
5133/* set up GPIO at initialization */
5134static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5135 const struct alc_fixup *fix, int action)
5136{
5137 if (action != ALC_FIXUP_ACT_INIT)
5138 return;
5139 alc882_gpio_mute(codec, 0, 0);
5140 alc882_gpio_mute(codec, 1, 0);
5141}
5142
Takashi Iwai02a237b2012-02-13 15:25:07 +01005143/* Fix the connection of some pins for ALC889:
5144 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5145 * work correctly (bko#42740)
5146 */
5147static void alc889_fixup_dac_route(struct hda_codec *codec,
5148 const struct alc_fixup *fix, int action)
5149{
5150 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005151 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005152 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5153 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5154 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5155 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5156 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5157 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005158 } else if (action == ALC_FIXUP_ACT_PROBE) {
5159 /* restore the connections */
5160 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5161 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5162 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5163 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5164 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005165 }
5166}
5167
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005168/* Set VREF on HP pin */
5169static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5170 const struct alc_fixup *fix, int action)
5171{
5172 struct alc_spec *spec = codec->spec;
5173 static hda_nid_t nids[2] = { 0x14, 0x15 };
5174 int i;
5175
5176 if (action != ALC_FIXUP_ACT_INIT)
5177 return;
5178 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5179 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5180 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5181 continue;
5182 val = snd_hda_codec_read(codec, nids[i], 0,
5183 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5184 val |= AC_PINCTL_VREF_80;
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 spec->keep_vref_in_automute = 1;
5187 break;
5188 }
5189}
5190
5191/* Set VREF on speaker pins on imac91 */
5192static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5193 const struct alc_fixup *fix, int action)
5194{
5195 struct alc_spec *spec = codec->spec;
5196 static hda_nid_t nids[2] = { 0x18, 0x1a };
5197 int i;
5198
5199 if (action != ALC_FIXUP_ACT_INIT)
5200 return;
5201 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5202 unsigned int val;
5203 val = snd_hda_codec_read(codec, nids[i], 0,
5204 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5205 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005206 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005207 }
5208 spec->keep_vref_in_automute = 1;
5209}
5210
Takashi Iwaie427c232012-07-29 10:04:08 +02005211/* Don't take HP output as primary
5212 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5213 */
5214static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5215 const struct alc_fixup *fix, int action)
5216{
5217 struct alc_spec *spec = codec->spec;
5218 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5219 spec->no_primary_hp = 1;
5220}
5221
Takashi Iwai1d045db2011-07-07 18:23:21 +02005222static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005223 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005224 .type = ALC_FIXUP_PINS,
5225 .v.pins = (const struct alc_pincfg[]) {
5226 { 0x15, 0x01080104 }, /* side */
5227 { 0x16, 0x01011012 }, /* rear */
5228 { 0x17, 0x01016011 }, /* clfe */
5229 { }
5230 }
5231 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005232 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005233 .type = ALC_FIXUP_PINS,
5234 .v.pins = (const struct alc_pincfg[]) {
5235 { 0x15, 0x99130112 }, /* rear int speakers */
5236 { 0x16, 0x99130111 }, /* subwoofer */
5237 { }
5238 }
5239 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005240 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005241 .type = ALC_FIXUP_VERBS,
5242 .v.verbs = (const struct hda_verb[]) {
5243 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5244 {}
5245 }
5246 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005247 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005248 .type = ALC_FIXUP_FUNC,
5249 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005250 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005251 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005252 .type = ALC_FIXUP_PINS,
5253 .v.pins = (const struct alc_pincfg[]) {
5254 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5255 { }
5256 }
5257 },
Marton Balint8f239212012-03-05 21:33:23 +01005258 [ALC889_FIXUP_CD] = {
5259 .type = ALC_FIXUP_PINS,
5260 .v.pins = (const struct alc_pincfg[]) {
5261 { 0x1c, 0x993301f0 }, /* CD */
5262 { }
5263 }
5264 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005265 [ALC889_FIXUP_VAIO_TT] = {
5266 .type = ALC_FIXUP_PINS,
5267 .v.pins = (const struct alc_pincfg[]) {
5268 { 0x17, 0x90170111 }, /* hidden surround speaker */
5269 { }
5270 }
5271 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005272 [ALC888_FIXUP_EEE1601] = {
5273 .type = ALC_FIXUP_VERBS,
5274 .v.verbs = (const struct hda_verb[]) {
5275 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5276 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5277 { }
5278 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005279 },
5280 [ALC882_FIXUP_EAPD] = {
5281 .type = ALC_FIXUP_VERBS,
5282 .v.verbs = (const struct hda_verb[]) {
5283 /* change to EAPD mode */
5284 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5285 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5286 { }
5287 }
5288 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005289 [ALC883_FIXUP_EAPD] = {
5290 .type = ALC_FIXUP_VERBS,
5291 .v.verbs = (const struct hda_verb[]) {
5292 /* change to EAPD mode */
5293 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5294 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5295 { }
5296 }
5297 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005298 [ALC883_FIXUP_ACER_EAPD] = {
5299 .type = ALC_FIXUP_VERBS,
5300 .v.verbs = (const struct hda_verb[]) {
5301 /* eanable EAPD on Acer laptops */
5302 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5303 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5304 { }
5305 }
5306 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005307 [ALC882_FIXUP_GPIO1] = {
5308 .type = ALC_FIXUP_VERBS,
5309 .v.verbs = alc_gpio1_init_verbs,
5310 },
5311 [ALC882_FIXUP_GPIO2] = {
5312 .type = ALC_FIXUP_VERBS,
5313 .v.verbs = alc_gpio2_init_verbs,
5314 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005315 [ALC882_FIXUP_GPIO3] = {
5316 .type = ALC_FIXUP_VERBS,
5317 .v.verbs = alc_gpio3_init_verbs,
5318 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005319 [ALC882_FIXUP_ASUS_W2JC] = {
5320 .type = ALC_FIXUP_VERBS,
5321 .v.verbs = alc_gpio1_init_verbs,
5322 .chained = true,
5323 .chain_id = ALC882_FIXUP_EAPD,
5324 },
5325 [ALC889_FIXUP_COEF] = {
5326 .type = ALC_FIXUP_FUNC,
5327 .v.func = alc889_fixup_coef,
5328 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005329 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5330 .type = ALC_FIXUP_PINS,
5331 .v.pins = (const struct alc_pincfg[]) {
5332 { 0x16, 0x99130111 }, /* CLFE speaker */
5333 { 0x17, 0x99130112 }, /* surround speaker */
5334 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005335 },
5336 .chained = true,
5337 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005338 },
5339 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5340 .type = ALC_FIXUP_PINS,
5341 .v.pins = (const struct alc_pincfg[]) {
5342 { 0x16, 0x99130111 }, /* CLFE speaker */
5343 { 0x1b, 0x99130112 }, /* surround speaker */
5344 { }
5345 },
5346 .chained = true,
5347 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5348 },
5349 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5350 /* additional init verbs for Acer Aspire 8930G */
5351 .type = ALC_FIXUP_VERBS,
5352 .v.verbs = (const struct hda_verb[]) {
5353 /* Enable all DACs */
5354 /* DAC DISABLE/MUTE 1? */
5355 /* setting bits 1-5 disables DAC nids 0x02-0x06
5356 * apparently. Init=0x38 */
5357 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5358 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5359 /* DAC DISABLE/MUTE 2? */
5360 /* some bit here disables the other DACs.
5361 * Init=0x4900 */
5362 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5363 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5364 /* DMIC fix
5365 * This laptop has a stereo digital microphone.
5366 * The mics are only 1cm apart which makes the stereo
5367 * useless. However, either the mic or the ALC889
5368 * makes the signal become a difference/sum signal
5369 * instead of standard stereo, which is annoying.
5370 * So instead we flip this bit which makes the
5371 * codec replicate the sum signal to both channels,
5372 * turning it into a normal mono mic.
5373 */
5374 /* DMIC_CONTROL? Init value = 0x0001 */
5375 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5376 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5377 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5378 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5379 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005380 },
5381 .chained = true,
5382 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005383 },
Takashi Iwai56710872011-11-14 17:42:11 +01005384 [ALC885_FIXUP_MACPRO_GPIO] = {
5385 .type = ALC_FIXUP_FUNC,
5386 .v.func = alc885_fixup_macpro_gpio,
5387 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005388 [ALC889_FIXUP_DAC_ROUTE] = {
5389 .type = ALC_FIXUP_FUNC,
5390 .v.func = alc889_fixup_dac_route,
5391 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005392 [ALC889_FIXUP_MBP_VREF] = {
5393 .type = ALC_FIXUP_FUNC,
5394 .v.func = alc889_fixup_mbp_vref,
5395 .chained = true,
5396 .chain_id = ALC882_FIXUP_GPIO1,
5397 },
5398 [ALC889_FIXUP_IMAC91_VREF] = {
5399 .type = ALC_FIXUP_FUNC,
5400 .v.func = alc889_fixup_imac91_vref,
5401 .chained = true,
5402 .chain_id = ALC882_FIXUP_GPIO1,
5403 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005404 [ALC882_FIXUP_INV_DMIC] = {
5405 .type = ALC_FIXUP_FUNC,
5406 .v.func = alc_fixup_inv_dmic_0x12,
5407 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005408 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5409 .type = ALC_FIXUP_FUNC,
5410 .v.func = alc882_fixup_no_primary_hp,
5411 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005412};
5413
5414static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005415 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5416 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5417 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5418 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5419 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5420 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005421 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5422 ALC882_FIXUP_ACER_ASPIRE_4930G),
5423 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5424 ALC882_FIXUP_ACER_ASPIRE_4930G),
5425 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5426 ALC882_FIXUP_ACER_ASPIRE_8930G),
5427 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5428 ALC882_FIXUP_ACER_ASPIRE_8930G),
5429 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5430 ALC882_FIXUP_ACER_ASPIRE_4930G),
5431 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5432 ALC882_FIXUP_ACER_ASPIRE_4930G),
5433 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5434 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005435 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005436 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5437 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005438 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005439 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005440 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005441 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005442 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005443 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005444 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005445 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005446 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005447
5448 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005449 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5450 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5451 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005452 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5453 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5454 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005455 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5456 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005457 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005458 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5459 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5460 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5461 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005462 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005463 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5464 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5465 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005466 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005467 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005468 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5469 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5470 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005471
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005472 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005473 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005474 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005475 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005476 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005477 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5478 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005479 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005480 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481 {}
5482};
5483
Takashi Iwai912093b2012-04-11 14:03:41 +02005484static const struct alc_model_fixup alc882_fixup_models[] = {
5485 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5486 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5487 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005488 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005489 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005490 {}
5491};
5492
Takashi Iwai1d045db2011-07-07 18:23:21 +02005493/*
5494 * BIOS auto configuration
5495 */
5496/* almost identical with ALC880 parser... */
5497static int alc882_parse_auto_config(struct hda_codec *codec)
5498{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005500 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5501 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005502}
5503
Takashi Iwai1d045db2011-07-07 18:23:21 +02005504/*
5505 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005506static int patch_alc882(struct hda_codec *codec)
5507{
5508 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005509 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005510
Takashi Iwai3de95172012-05-07 18:03:15 +02005511 err = alc_alloc_spec(codec, 0x0b);
5512 if (err < 0)
5513 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005514
Takashi Iwai3de95172012-05-07 18:03:15 +02005515 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005516
5517 switch (codec->vendor_id) {
5518 case 0x10ec0882:
5519 case 0x10ec0885:
5520 break;
5521 default:
5522 /* ALC883 and variants */
5523 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5524 break;
5525 }
5526
Takashi Iwai912093b2012-04-11 14:03:41 +02005527 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5528 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005529 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005530
5531 alc_auto_parse_customize_define(codec);
5532
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005533 /* automatic parse from the BIOS config */
5534 err = alc882_parse_auto_config(codec);
5535 if (err < 0)
5536 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005537
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005538 if (!spec->no_analog && has_cdefine_beep(codec)) {
5539 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005540 if (err < 0)
5541 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005542 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005543 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005544
Takashi Iwai1d045db2011-07-07 18:23:21 +02005545 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005546
Takashi Iwai589876e2012-02-20 15:47:55 +01005547 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5548
Takashi Iwai1d045db2011-07-07 18:23:21 +02005549 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005550
5551 error:
5552 alc_free(codec);
5553 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005554}
5555
5556
5557/*
5558 * ALC262 support
5559 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005560static int alc262_parse_auto_config(struct hda_codec *codec)
5561{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005562 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005563 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5564 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005565}
5566
5567/*
5568 * Pin config fixes
5569 */
5570enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005571 ALC262_FIXUP_FSC_H270,
5572 ALC262_FIXUP_HP_Z200,
5573 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005574 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005575 ALC262_FIXUP_BENQ,
5576 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005577 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005578};
5579
5580static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005581 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005582 .type = ALC_FIXUP_PINS,
5583 .v.pins = (const struct alc_pincfg[]) {
5584 { 0x14, 0x99130110 }, /* speaker */
5585 { 0x15, 0x0221142f }, /* front HP */
5586 { 0x1b, 0x0121141f }, /* rear HP */
5587 { }
5588 }
5589 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005590 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005591 .type = ALC_FIXUP_PINS,
5592 .v.pins = (const struct alc_pincfg[]) {
5593 { 0x16, 0x99130120 }, /* internal speaker */
5594 { }
5595 }
5596 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005597 [ALC262_FIXUP_TYAN] = {
5598 .type = ALC_FIXUP_PINS,
5599 .v.pins = (const struct alc_pincfg[]) {
5600 { 0x14, 0x1993e1f0 }, /* int AUX */
5601 { }
5602 }
5603 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005604 [ALC262_FIXUP_LENOVO_3000] = {
5605 .type = ALC_FIXUP_VERBS,
5606 .v.verbs = (const struct hda_verb[]) {
5607 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005608 {}
5609 },
5610 .chained = true,
5611 .chain_id = ALC262_FIXUP_BENQ,
5612 },
5613 [ALC262_FIXUP_BENQ] = {
5614 .type = ALC_FIXUP_VERBS,
5615 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005616 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5617 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5618 {}
5619 }
5620 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005621 [ALC262_FIXUP_BENQ_T31] = {
5622 .type = ALC_FIXUP_VERBS,
5623 .v.verbs = (const struct hda_verb[]) {
5624 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5625 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5626 {}
5627 }
5628 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005629 [ALC262_FIXUP_INV_DMIC] = {
5630 .type = ALC_FIXUP_FUNC,
5631 .v.func = alc_fixup_inv_dmic_0x12,
5632 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005633};
5634
5635static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005636 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005637 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5638 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005639 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5640 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005641 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005642 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5643 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005644 {}
5645};
5646
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005647static const struct alc_model_fixup alc262_fixup_models[] = {
5648 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5649 {}
5650};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005651
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652/*
5653 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005654static int patch_alc262(struct hda_codec *codec)
5655{
5656 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657 int err;
5658
Takashi Iwai3de95172012-05-07 18:03:15 +02005659 err = alc_alloc_spec(codec, 0x0b);
5660 if (err < 0)
5661 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005662
Takashi Iwai3de95172012-05-07 18:03:15 +02005663 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005664
5665#if 0
5666 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5667 * under-run
5668 */
5669 {
5670 int tmp;
5671 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5672 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5673 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5674 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5675 }
5676#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005677 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5678
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005679 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5680 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005681 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005682
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005683 alc_auto_parse_customize_define(codec);
5684
Takashi Iwai42399f72011-11-07 17:18:44 +01005685 /* automatic parse from the BIOS config */
5686 err = alc262_parse_auto_config(codec);
5687 if (err < 0)
5688 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005689
Takashi Iwai1d045db2011-07-07 18:23:21 +02005690 if (!spec->no_analog && has_cdefine_beep(codec)) {
5691 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005692 if (err < 0)
5693 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005694 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005695 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005696
Takashi Iwai1d045db2011-07-07 18:23:21 +02005697 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005698 spec->shutup = alc_eapd_shutup;
5699
Takashi Iwai589876e2012-02-20 15:47:55 +01005700 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5701
Takashi Iwai1d045db2011-07-07 18:23:21 +02005702 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005703
5704 error:
5705 alc_free(codec);
5706 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005707}
5708
5709/*
5710 * ALC268
5711 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712/* bind Beep switches of both NID 0x0f and 0x10 */
5713static const struct hda_bind_ctls alc268_bind_beep_sw = {
5714 .ops = &snd_hda_bind_sw,
5715 .values = {
5716 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5717 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5718 0
5719 },
5720};
5721
5722static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5723 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5724 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5725 { }
5726};
5727
5728/* set PCBEEP vol = 0, mute connections */
5729static const struct hda_verb alc268_beep_init_verbs[] = {
5730 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5731 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5732 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5733 { }
5734};
5735
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005736enum {
5737 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005738 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005739};
5740
5741static const struct alc_fixup alc268_fixups[] = {
5742 [ALC268_FIXUP_INV_DMIC] = {
5743 .type = ALC_FIXUP_FUNC,
5744 .v.func = alc_fixup_inv_dmic_0x12,
5745 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005746 [ALC268_FIXUP_HP_EAPD] = {
5747 .type = ALC_FIXUP_VERBS,
5748 .v.verbs = (const struct hda_verb[]) {
5749 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5750 {}
5751 }
5752 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005753};
5754
5755static const struct alc_model_fixup alc268_fixup_models[] = {
5756 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005757 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5758 {}
5759};
5760
5761static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5762 /* below is codec SSID since multiple Toshiba laptops have the
5763 * same PCI SSID 1179:ff00
5764 */
5765 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005766 {}
5767};
5768
Takashi Iwai1d045db2011-07-07 18:23:21 +02005769/*
5770 * BIOS auto configuration
5771 */
5772static int alc268_parse_auto_config(struct hda_codec *codec)
5773{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005774 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005775 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005776 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5777 if (err > 0) {
5778 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5779 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005780 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005781 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005782 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005783 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005784}
5785
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786/*
5787 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005788static int patch_alc268(struct hda_codec *codec)
5789{
5790 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005791 int i, has_beep, err;
5792
Takashi Iwai1d045db2011-07-07 18:23:21 +02005793 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005794 err = alc_alloc_spec(codec, 0);
5795 if (err < 0)
5796 return err;
5797
5798 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005799
Takashi Iwaicb766402012-10-20 10:55:21 +02005800 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005801 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5802
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005803 /* automatic parse from the BIOS config */
5804 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005805 if (err < 0)
5806 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005807
Takashi Iwai1d045db2011-07-07 18:23:21 +02005808 has_beep = 0;
5809 for (i = 0; i < spec->num_mixers; i++) {
5810 if (spec->mixers[i] == alc268_beep_mixer) {
5811 has_beep = 1;
5812 break;
5813 }
5814 }
5815
5816 if (has_beep) {
5817 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005818 if (err < 0)
5819 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005820 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5821 /* override the amp caps for beep generator */
5822 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5823 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5824 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5825 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5826 (0 << AC_AMPCAP_MUTE_SHIFT));
5827 }
5828
Takashi Iwai1d045db2011-07-07 18:23:21 +02005829 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005830 spec->shutup = alc_eapd_shutup;
5831
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005832 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5833
Takashi Iwai1d045db2011-07-07 18:23:21 +02005834 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005835
5836 error:
5837 alc_free(codec);
5838 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005839}
5840
5841/*
5842 * ALC269
5843 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005844static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5845 .substreams = 1,
5846 .channels_min = 2,
5847 .channels_max = 8,
5848 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5849 /* NID is set in alc_build_pcms */
5850 .ops = {
5851 .open = alc_playback_pcm_open,
5852 .prepare = alc_playback_pcm_prepare,
5853 .cleanup = alc_playback_pcm_cleanup
5854 },
5855};
5856
5857static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5858 .substreams = 1,
5859 .channels_min = 2,
5860 .channels_max = 2,
5861 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5862 /* NID is set in alc_build_pcms */
5863};
5864
Takashi Iwai1d045db2011-07-07 18:23:21 +02005865/* different alc269-variants */
5866enum {
5867 ALC269_TYPE_ALC269VA,
5868 ALC269_TYPE_ALC269VB,
5869 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005870 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005871 ALC269_TYPE_ALC280,
5872 ALC269_TYPE_ALC282,
5873 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005874};
5875
5876/*
5877 * BIOS auto configuration
5878 */
5879static int alc269_parse_auto_config(struct hda_codec *codec)
5880{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005881 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005882 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5883 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5884 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005885 const hda_nid_t *ssids;
5886
5887 switch (spec->codec_variant) {
5888 case ALC269_TYPE_ALC269VA:
5889 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005890 case ALC269_TYPE_ALC280:
5891 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005892 ssids = alc269va_ssids;
5893 break;
5894 case ALC269_TYPE_ALC269VB:
5895 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005896 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005897 ssids = alc269_ssids;
5898 break;
5899 default:
5900 ssids = alc269_ssids;
5901 break;
5902 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005903
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005904 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005905}
5906
Kailang Yang1387e2d2012-11-08 10:23:18 +01005907static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005908{
5909 int val = alc_read_coef_idx(codec, 0x04);
5910 if (power_up)
5911 val |= 1 << 11;
5912 else
5913 val &= ~(1 << 11);
5914 alc_write_coef_idx(codec, 0x04, val);
5915}
5916
5917static void alc269_shutup(struct hda_codec *codec)
5918{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005919 struct alc_spec *spec = codec->spec;
5920
5921 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5922 return;
5923
Kailang Yang1387e2d2012-11-08 10:23:18 +01005924 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5925 alc269vb_toggle_power_output(codec, 0);
5926 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5927 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005928 msleep(150);
5929 }
5930}
5931
Takashi Iwai2a439522011-07-26 09:52:50 +02005932#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005933static int alc269_resume(struct hda_codec *codec)
5934{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005935 struct alc_spec *spec = codec->spec;
5936
Kailang Yang1387e2d2012-11-08 10:23:18 +01005937 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5938 alc269vb_toggle_power_output(codec, 0);
5939 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005940 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005941 msleep(150);
5942 }
5943
5944 codec->patch_ops.init(codec);
5945
Kailang Yang1387e2d2012-11-08 10:23:18 +01005946 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5947 alc269vb_toggle_power_output(codec, 1);
5948 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005949 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005950 msleep(200);
5951 }
5952
Takashi Iwai1d045db2011-07-07 18:23:21 +02005953 snd_hda_codec_resume_amp(codec);
5954 snd_hda_codec_resume_cache(codec);
5955 hda_call_check_power_status(codec, 0x01);
5956 return 0;
5957}
Takashi Iwai2a439522011-07-26 09:52:50 +02005958#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005959
David Henningsson108cc102012-07-20 10:37:25 +02005960static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5961 const struct alc_fixup *fix, int action)
5962{
5963 struct alc_spec *spec = codec->spec;
5964
5965 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5966 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5967}
5968
Takashi Iwai1d045db2011-07-07 18:23:21 +02005969static void alc269_fixup_hweq(struct hda_codec *codec,
5970 const struct alc_fixup *fix, int action)
5971{
5972 int coef;
5973
5974 if (action != ALC_FIXUP_ACT_INIT)
5975 return;
5976 coef = alc_read_coef_idx(codec, 0x1e);
5977 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5978}
5979
5980static void alc271_fixup_dmic(struct hda_codec *codec,
5981 const struct alc_fixup *fix, int action)
5982{
5983 static const struct hda_verb verbs[] = {
5984 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5985 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5986 {}
5987 };
5988 unsigned int cfg;
5989
5990 if (strcmp(codec->chip_name, "ALC271X"))
5991 return;
5992 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5993 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5994 snd_hda_sequence_write(codec, verbs);
5995}
5996
Takashi Iwai017f2a12011-07-09 14:42:25 +02005997static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5998 const struct alc_fixup *fix, int action)
5999{
6000 struct alc_spec *spec = codec->spec;
6001
6002 if (action != ALC_FIXUP_ACT_PROBE)
6003 return;
6004
6005 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6006 * fix the sample rate of analog I/O to 44.1kHz
6007 */
6008 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6009 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6010}
6011
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006012static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6013 const struct alc_fixup *fix, int action)
6014{
6015 int coef;
6016
6017 if (action != ALC_FIXUP_ACT_INIT)
6018 return;
6019 /* The digital-mic unit sends PDM (differential signal) instead of
6020 * the standard PCM, thus you can't record a valid mono stream as is.
6021 * Below is a workaround specific to ALC269 to control the dmic
6022 * signal source as mono.
6023 */
6024 coef = alc_read_coef_idx(codec, 0x07);
6025 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6026}
6027
Takashi Iwai24519912011-08-16 15:08:49 +02006028static void alc269_quanta_automute(struct hda_codec *codec)
6029{
David Henningsson42cf0d02011-09-20 12:04:56 +02006030 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006031
6032 snd_hda_codec_write(codec, 0x20, 0,
6033 AC_VERB_SET_COEF_INDEX, 0x0c);
6034 snd_hda_codec_write(codec, 0x20, 0,
6035 AC_VERB_SET_PROC_COEF, 0x680);
6036
6037 snd_hda_codec_write(codec, 0x20, 0,
6038 AC_VERB_SET_COEF_INDEX, 0x0c);
6039 snd_hda_codec_write(codec, 0x20, 0,
6040 AC_VERB_SET_PROC_COEF, 0x480);
6041}
6042
6043static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6044 const struct alc_fixup *fix, int action)
6045{
6046 struct alc_spec *spec = codec->spec;
6047 if (action != ALC_FIXUP_ACT_PROBE)
6048 return;
6049 spec->automute_hook = alc269_quanta_automute;
6050}
6051
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006052/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6053static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6054{
6055 struct hda_codec *codec = private_data;
6056 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6057 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6058 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6059}
6060
6061static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6062 const struct alc_fixup *fix, int action)
6063{
6064 struct alc_spec *spec = codec->spec;
6065 switch (action) {
6066 case ALC_FIXUP_ACT_BUILD:
6067 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6068 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6069 /* fallthru */
6070 case ALC_FIXUP_ACT_INIT:
6071 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6072 break;
6073 }
6074}
6075
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006076/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6077static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6078{
6079 struct hda_codec *codec = private_data;
6080 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006081 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006082}
6083
6084static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6085 const struct alc_fixup *fix, int action)
6086{
6087 struct alc_spec *spec = codec->spec;
6088 switch (action) {
6089 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006090 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006091 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006092 /* fallthru */
6093 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006094 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006095 break;
6096 }
6097}
6098
Dylan Reid08a978d2012-11-18 22:56:40 -08006099static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6100 const struct alc_fixup *fix,
6101 int action)
6102{
6103 struct alc_spec *spec = codec->spec;
6104
6105 if (action == ALC_FIXUP_ACT_PROBE)
6106 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6107 spec->autocfg.hp_pins[0]);
6108}
David Henningsson693b6132012-06-22 19:12:10 +02006109
Takashi Iwai1d045db2011-07-07 18:23:21 +02006110enum {
6111 ALC269_FIXUP_SONY_VAIO,
6112 ALC275_FIXUP_SONY_VAIO_GPIO2,
6113 ALC269_FIXUP_DELL_M101Z,
6114 ALC269_FIXUP_SKU_IGNORE,
6115 ALC269_FIXUP_ASUS_G73JW,
6116 ALC269_FIXUP_LENOVO_EAPD,
6117 ALC275_FIXUP_SONY_HWEQ,
6118 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006119 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006120 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006121 ALC269_FIXUP_QUANTA_MUTE,
6122 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006123 ALC269_FIXUP_AMIC,
6124 ALC269_FIXUP_DMIC,
6125 ALC269VB_FIXUP_AMIC,
6126 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006127 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006128 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006129 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006130 ALC269_FIXUP_LENOVO_DOCK,
6131 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006132 ALC271_FIXUP_AMIC_MIC2,
6133 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006134};
6135
6136static const struct alc_fixup alc269_fixups[] = {
6137 [ALC269_FIXUP_SONY_VAIO] = {
6138 .type = ALC_FIXUP_VERBS,
6139 .v.verbs = (const struct hda_verb[]) {
6140 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6141 {}
6142 }
6143 },
6144 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6145 .type = ALC_FIXUP_VERBS,
6146 .v.verbs = (const struct hda_verb[]) {
6147 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6148 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6149 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6150 { }
6151 },
6152 .chained = true,
6153 .chain_id = ALC269_FIXUP_SONY_VAIO
6154 },
6155 [ALC269_FIXUP_DELL_M101Z] = {
6156 .type = ALC_FIXUP_VERBS,
6157 .v.verbs = (const struct hda_verb[]) {
6158 /* Enables internal speaker */
6159 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6160 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6161 {}
6162 }
6163 },
6164 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006165 .type = ALC_FIXUP_FUNC,
6166 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006167 },
6168 [ALC269_FIXUP_ASUS_G73JW] = {
6169 .type = ALC_FIXUP_PINS,
6170 .v.pins = (const struct alc_pincfg[]) {
6171 { 0x17, 0x99130111 }, /* subwoofer */
6172 { }
6173 }
6174 },
6175 [ALC269_FIXUP_LENOVO_EAPD] = {
6176 .type = ALC_FIXUP_VERBS,
6177 .v.verbs = (const struct hda_verb[]) {
6178 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6179 {}
6180 }
6181 },
6182 [ALC275_FIXUP_SONY_HWEQ] = {
6183 .type = ALC_FIXUP_FUNC,
6184 .v.func = alc269_fixup_hweq,
6185 .chained = true,
6186 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6187 },
6188 [ALC271_FIXUP_DMIC] = {
6189 .type = ALC_FIXUP_FUNC,
6190 .v.func = alc271_fixup_dmic,
6191 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006192 [ALC269_FIXUP_PCM_44K] = {
6193 .type = ALC_FIXUP_FUNC,
6194 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006195 .chained = true,
6196 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006197 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006198 [ALC269_FIXUP_STEREO_DMIC] = {
6199 .type = ALC_FIXUP_FUNC,
6200 .v.func = alc269_fixup_stereo_dmic,
6201 },
Takashi Iwai24519912011-08-16 15:08:49 +02006202 [ALC269_FIXUP_QUANTA_MUTE] = {
6203 .type = ALC_FIXUP_FUNC,
6204 .v.func = alc269_fixup_quanta_mute,
6205 },
6206 [ALC269_FIXUP_LIFEBOOK] = {
6207 .type = ALC_FIXUP_PINS,
6208 .v.pins = (const struct alc_pincfg[]) {
6209 { 0x1a, 0x2101103f }, /* dock line-out */
6210 { 0x1b, 0x23a11040 }, /* dock mic-in */
6211 { }
6212 },
6213 .chained = true,
6214 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6215 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006216 [ALC269_FIXUP_AMIC] = {
6217 .type = ALC_FIXUP_PINS,
6218 .v.pins = (const struct alc_pincfg[]) {
6219 { 0x14, 0x99130110 }, /* speaker */
6220 { 0x15, 0x0121401f }, /* HP out */
6221 { 0x18, 0x01a19c20 }, /* mic */
6222 { 0x19, 0x99a3092f }, /* int-mic */
6223 { }
6224 },
6225 },
6226 [ALC269_FIXUP_DMIC] = {
6227 .type = ALC_FIXUP_PINS,
6228 .v.pins = (const struct alc_pincfg[]) {
6229 { 0x12, 0x99a3092f }, /* int-mic */
6230 { 0x14, 0x99130110 }, /* speaker */
6231 { 0x15, 0x0121401f }, /* HP out */
6232 { 0x18, 0x01a19c20 }, /* mic */
6233 { }
6234 },
6235 },
6236 [ALC269VB_FIXUP_AMIC] = {
6237 .type = ALC_FIXUP_PINS,
6238 .v.pins = (const struct alc_pincfg[]) {
6239 { 0x14, 0x99130110 }, /* speaker */
6240 { 0x18, 0x01a19c20 }, /* mic */
6241 { 0x19, 0x99a3092f }, /* int-mic */
6242 { 0x21, 0x0121401f }, /* HP out */
6243 { }
6244 },
6245 },
David Henningsson2267ea92012-01-03 08:45:56 +01006246 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006247 .type = ALC_FIXUP_PINS,
6248 .v.pins = (const struct alc_pincfg[]) {
6249 { 0x12, 0x99a3092f }, /* int-mic */
6250 { 0x14, 0x99130110 }, /* speaker */
6251 { 0x18, 0x01a19c20 }, /* mic */
6252 { 0x21, 0x0121401f }, /* HP out */
6253 { }
6254 },
6255 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006256 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6257 .type = ALC_FIXUP_FUNC,
6258 .v.func = alc269_fixup_mic1_mute,
6259 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006260 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6261 .type = ALC_FIXUP_FUNC,
6262 .v.func = alc269_fixup_mic2_mute,
6263 },
David Henningsson693b6132012-06-22 19:12:10 +02006264 [ALC269_FIXUP_INV_DMIC] = {
6265 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006266 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006267 },
David Henningsson108cc102012-07-20 10:37:25 +02006268 [ALC269_FIXUP_LENOVO_DOCK] = {
6269 .type = ALC_FIXUP_PINS,
6270 .v.pins = (const struct alc_pincfg[]) {
6271 { 0x19, 0x23a11040 }, /* dock mic */
6272 { 0x1b, 0x2121103f }, /* dock headphone */
6273 { }
6274 },
6275 .chained = true,
6276 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6277 },
6278 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6279 .type = ALC_FIXUP_FUNC,
6280 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6281 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006282 [ALC271_FIXUP_AMIC_MIC2] = {
6283 .type = ALC_FIXUP_PINS,
6284 .v.pins = (const struct alc_pincfg[]) {
6285 { 0x14, 0x99130110 }, /* speaker */
6286 { 0x19, 0x01a19c20 }, /* mic */
6287 { 0x1b, 0x99a7012f }, /* int-mic */
6288 { 0x21, 0x0121401f }, /* HP out */
6289 { }
6290 },
6291 },
6292 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6293 .type = ALC_FIXUP_FUNC,
6294 .v.func = alc271_hp_gate_mic_jack,
6295 .chained = true,
6296 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6297 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006298};
6299
6300static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006301 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6302 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006303 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006304 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006305 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006306 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006307 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006308 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006309 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6310 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6311 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6312 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6313 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006314 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6315 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6316 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6317 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6318 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006319 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006320 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006321 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006322 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6323 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6324 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6325 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6326 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006327 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006328 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006329 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006330 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006331 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006332 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006333 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006334
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006335#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006336 /* Below is a quirk table taken from the old code.
6337 * Basically the device should work as is without the fixup table.
6338 * If BIOS doesn't give a proper info, enable the corresponding
6339 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006340 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006341 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6342 ALC269_FIXUP_AMIC),
6343 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006344 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6345 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6346 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6347 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6348 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6349 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6350 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6351 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6352 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6353 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6354 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6355 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6356 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6357 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6358 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6359 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6360 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6361 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6362 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6363 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6364 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6365 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6366 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6367 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6368 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6369 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6370 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6371 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6372 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6373 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6374 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6375 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6376 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6377 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6378 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6379 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6380 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6381 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6382#endif
6383 {}
6384};
6385
6386static const struct alc_model_fixup alc269_fixup_models[] = {
6387 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6388 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006389 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6390 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6391 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006392 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006393 {}
6394};
6395
6396
Takashi Iwai546bb672012-03-07 08:37:19 +01006397static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006398{
Kailang Yang526af6e2012-03-07 08:25:20 +01006399 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006400 int val;
6401
Kailang Yang526af6e2012-03-07 08:25:20 +01006402 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006403 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006404
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006405 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006406 alc_write_coef_idx(codec, 0xf, 0x960b);
6407 alc_write_coef_idx(codec, 0xe, 0x8817);
6408 }
6409
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006410 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006411 alc_write_coef_idx(codec, 0xf, 0x960b);
6412 alc_write_coef_idx(codec, 0xe, 0x8814);
6413 }
6414
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006415 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006416 val = alc_read_coef_idx(codec, 0x04);
6417 /* Power up output pin */
6418 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6419 }
6420
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006421 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006422 val = alc_read_coef_idx(codec, 0xd);
6423 if ((val & 0x0c00) >> 10 != 0x1) {
6424 /* Capless ramp up clock control */
6425 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6426 }
6427 val = alc_read_coef_idx(codec, 0x17);
6428 if ((val & 0x01c0) >> 6 != 0x4) {
6429 /* Class D power on reset */
6430 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6431 }
6432 }
6433
6434 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6435 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6436
6437 val = alc_read_coef_idx(codec, 0x4); /* HP */
6438 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006439}
6440
6441/*
6442 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006443static int patch_alc269(struct hda_codec *codec)
6444{
6445 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006446 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006447
Takashi Iwai3de95172012-05-07 18:03:15 +02006448 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006449 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006450 return err;
6451
6452 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006453
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006454 alc_pick_fixup(codec, alc269_fixup_models,
6455 alc269_fixup_tbl, alc269_fixups);
6456 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6457
6458 alc_auto_parse_customize_define(codec);
6459
Kailang Yang065380f2013-01-10 10:25:48 +01006460 switch (codec->vendor_id) {
6461 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006462 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006463 switch (alc_get_coef0(codec) & 0x00f0) {
6464 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006465 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006466 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006467 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006468 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006469 break;
6470 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006471 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6472 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006473 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006474 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006475 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006476 case 0x0030:
6477 spec->codec_variant = ALC269_TYPE_ALC269VD;
6478 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006479 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006480 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006481 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006482 if (err < 0)
6483 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006484 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006485 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006486 break;
6487
6488 case 0x10ec0280:
6489 case 0x10ec0290:
6490 spec->codec_variant = ALC269_TYPE_ALC280;
6491 break;
6492 case 0x10ec0282:
6493 case 0x10ec0283:
6494 spec->codec_variant = ALC269_TYPE_ALC282;
6495 break;
6496 case 0x10ec0284:
6497 case 0x10ec0292:
6498 spec->codec_variant = ALC269_TYPE_ALC284;
6499 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006500 }
6501
Takashi Iwaia4297b52011-08-23 18:40:12 +02006502 /* automatic parse from the BIOS config */
6503 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006504 if (err < 0)
6505 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006506
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006507 if (!spec->no_analog && has_cdefine_beep(codec)) {
6508 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006509 if (err < 0)
6510 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006511 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006512 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006513
Takashi Iwai1d045db2011-07-07 18:23:21 +02006514 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006515#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006516 codec->patch_ops.resume = alc269_resume;
6517#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006518 spec->shutup = alc269_shutup;
6519
Takashi Iwai589876e2012-02-20 15:47:55 +01006520 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6521
Takashi Iwai1d045db2011-07-07 18:23:21 +02006522 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006523
6524 error:
6525 alc_free(codec);
6526 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006527}
6528
6529/*
6530 * ALC861
6531 */
6532
Takashi Iwai1d045db2011-07-07 18:23:21 +02006533static int alc861_parse_auto_config(struct hda_codec *codec)
6534{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006535 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006536 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6537 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006538}
6539
Takashi Iwai1d045db2011-07-07 18:23:21 +02006540/* Pin config fixes */
6541enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006542 ALC861_FIXUP_FSC_AMILO_PI1505,
6543 ALC861_FIXUP_AMP_VREF_0F,
6544 ALC861_FIXUP_NO_JACK_DETECT,
6545 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006546};
6547
Takashi Iwai31150f22012-01-30 10:54:08 +01006548/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6549static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6550 const struct alc_fixup *fix, int action)
6551{
6552 struct alc_spec *spec = codec->spec;
6553 unsigned int val;
6554
6555 if (action != ALC_FIXUP_ACT_INIT)
6556 return;
6557 val = snd_hda_codec_read(codec, 0x0f, 0,
6558 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6559 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6560 val |= AC_PINCTL_IN_EN;
6561 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006562 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006563 spec->keep_vref_in_automute = 1;
6564}
6565
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006566/* suppress the jack-detection */
6567static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6568 const struct alc_fixup *fix, int action)
6569{
6570 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6571 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006572}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006573
Takashi Iwai1d045db2011-07-07 18:23:21 +02006574static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006575 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006576 .type = ALC_FIXUP_PINS,
6577 .v.pins = (const struct alc_pincfg[]) {
6578 { 0x0b, 0x0221101f }, /* HP */
6579 { 0x0f, 0x90170310 }, /* speaker */
6580 { }
6581 }
6582 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006583 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006584 .type = ALC_FIXUP_FUNC,
6585 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006586 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006587 [ALC861_FIXUP_NO_JACK_DETECT] = {
6588 .type = ALC_FIXUP_FUNC,
6589 .v.func = alc_fixup_no_jack_detect,
6590 },
6591 [ALC861_FIXUP_ASUS_A6RP] = {
6592 .type = ALC_FIXUP_FUNC,
6593 .v.func = alc861_fixup_asus_amp_vref_0f,
6594 .chained = true,
6595 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6596 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006597};
6598
6599static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006600 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6601 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6602 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6603 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6604 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6605 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006606 {}
6607};
6608
6609/*
6610 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006611static int patch_alc861(struct hda_codec *codec)
6612{
6613 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006614 int err;
6615
Takashi Iwai3de95172012-05-07 18:03:15 +02006616 err = alc_alloc_spec(codec, 0x15);
6617 if (err < 0)
6618 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006619
Takashi Iwai3de95172012-05-07 18:03:15 +02006620 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006621
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006622 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6623 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006624
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006625 /* automatic parse from the BIOS config */
6626 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006627 if (err < 0)
6628 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006629
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006630 if (!spec->no_analog) {
6631 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006632 if (err < 0)
6633 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006634 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6635 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006636
Takashi Iwai1d045db2011-07-07 18:23:21 +02006637 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006638#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006639 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006640#endif
6641
Takashi Iwai589876e2012-02-20 15:47:55 +01006642 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6643
Takashi Iwai1d045db2011-07-07 18:23:21 +02006644 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006645
6646 error:
6647 alc_free(codec);
6648 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006649}
6650
6651/*
6652 * ALC861-VD support
6653 *
6654 * Based on ALC882
6655 *
6656 * In addition, an independent DAC
6657 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006658static int alc861vd_parse_auto_config(struct hda_codec *codec)
6659{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006660 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006661 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6662 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006663}
6664
Takashi Iwai1d045db2011-07-07 18:23:21 +02006665enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006666 ALC660VD_FIX_ASUS_GPIO1,
6667 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006668};
6669
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006670/* exclude VREF80 */
6671static void alc861vd_fixup_dallas(struct hda_codec *codec,
6672 const struct alc_fixup *fix, int action)
6673{
6674 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006675 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6676 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006677 }
6678}
6679
Takashi Iwai1d045db2011-07-07 18:23:21 +02006680static const struct alc_fixup alc861vd_fixups[] = {
6681 [ALC660VD_FIX_ASUS_GPIO1] = {
6682 .type = ALC_FIXUP_VERBS,
6683 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006684 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006685 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6686 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6687 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6688 { }
6689 }
6690 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006691 [ALC861VD_FIX_DALLAS] = {
6692 .type = ALC_FIXUP_FUNC,
6693 .v.func = alc861vd_fixup_dallas,
6694 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006695};
6696
6697static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006698 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006699 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006700 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006701 {}
6702};
6703
Takashi Iwai1d045db2011-07-07 18:23:21 +02006704/*
6705 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006706static int patch_alc861vd(struct hda_codec *codec)
6707{
6708 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006709 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006710
Takashi Iwai3de95172012-05-07 18:03:15 +02006711 err = alc_alloc_spec(codec, 0x0b);
6712 if (err < 0)
6713 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006714
Takashi Iwai3de95172012-05-07 18:03:15 +02006715 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006716
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006717 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6718 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006719
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006720 /* automatic parse from the BIOS config */
6721 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006722 if (err < 0)
6723 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006724
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006725 if (!spec->no_analog) {
6726 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006727 if (err < 0)
6728 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006729 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6730 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006731
Takashi Iwai1d045db2011-07-07 18:23:21 +02006732 codec->patch_ops = alc_patch_ops;
6733
Takashi Iwai1d045db2011-07-07 18:23:21 +02006734 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006735
Takashi Iwai589876e2012-02-20 15:47:55 +01006736 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6737
Takashi Iwai1d045db2011-07-07 18:23:21 +02006738 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006739
6740 error:
6741 alc_free(codec);
6742 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006743}
6744
6745/*
6746 * ALC662 support
6747 *
6748 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6749 * configuration. Each pin widget can choose any input DACs and a mixer.
6750 * Each ADC is connected from a mixer of all inputs. This makes possible
6751 * 6-channel independent captures.
6752 *
6753 * In addition, an independent DAC for the multi-playback (not used in this
6754 * driver yet).
6755 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006756
6757/*
6758 * BIOS auto configuration
6759 */
6760
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006761static int alc662_parse_auto_config(struct hda_codec *codec)
6762{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006763 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006764 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6765 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6766 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006767
Kailang Yang6227cdc2010-02-25 08:36:52 +01006768 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6769 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006770 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006771 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006772 ssids = alc662_ssids;
6773 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006774}
6775
Todd Broch6be79482010-12-07 16:51:05 -08006776static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006777 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006778{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006779 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006780 return;
Todd Broch6be79482010-12-07 16:51:05 -08006781 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6782 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6783 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6784 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6785 (0 << AC_AMPCAP_MUTE_SHIFT)))
6786 printk(KERN_WARNING
6787 "hda_codec: failed to override amp caps for NID 0x2\n");
6788}
6789
David Henningsson6cb3b702010-09-09 08:51:44 +02006790enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006791 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006792 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006793 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006794 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006795 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006796 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006797 ALC662_FIXUP_ASUS_MODE1,
6798 ALC662_FIXUP_ASUS_MODE2,
6799 ALC662_FIXUP_ASUS_MODE3,
6800 ALC662_FIXUP_ASUS_MODE4,
6801 ALC662_FIXUP_ASUS_MODE5,
6802 ALC662_FIXUP_ASUS_MODE6,
6803 ALC662_FIXUP_ASUS_MODE7,
6804 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006805 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006806 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006807 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006808};
6809
6810static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006811 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006812 .type = ALC_FIXUP_PINS,
6813 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006814 { 0x15, 0x99130112 }, /* subwoofer */
6815 { }
6816 }
6817 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006818 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006819 .type = ALC_FIXUP_PINS,
6820 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006821 { 0x17, 0x99130112 }, /* subwoofer */
6822 { }
6823 }
6824 },
Todd Broch6be79482010-12-07 16:51:05 -08006825 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006826 .type = ALC_FIXUP_FUNC,
6827 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006828 },
6829 [ALC662_FIXUP_CZC_P10T] = {
6830 .type = ALC_FIXUP_VERBS,
6831 .v.verbs = (const struct hda_verb[]) {
6832 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6833 {}
6834 }
6835 },
David Henningsson94024cd2011-04-29 14:10:55 +02006836 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006837 .type = ALC_FIXUP_FUNC,
6838 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006839 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006840 [ALC662_FIXUP_HP_RP5800] = {
6841 .type = ALC_FIXUP_PINS,
6842 .v.pins = (const struct alc_pincfg[]) {
6843 { 0x14, 0x0221201f }, /* HP out */
6844 { }
6845 },
6846 .chained = true,
6847 .chain_id = ALC662_FIXUP_SKU_IGNORE
6848 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006849 [ALC662_FIXUP_ASUS_MODE1] = {
6850 .type = ALC_FIXUP_PINS,
6851 .v.pins = (const struct alc_pincfg[]) {
6852 { 0x14, 0x99130110 }, /* speaker */
6853 { 0x18, 0x01a19c20 }, /* mic */
6854 { 0x19, 0x99a3092f }, /* int-mic */
6855 { 0x21, 0x0121401f }, /* HP out */
6856 { }
6857 },
6858 .chained = true,
6859 .chain_id = ALC662_FIXUP_SKU_IGNORE
6860 },
6861 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006862 .type = ALC_FIXUP_PINS,
6863 .v.pins = (const struct alc_pincfg[]) {
6864 { 0x14, 0x99130110 }, /* speaker */
6865 { 0x18, 0x01a19820 }, /* mic */
6866 { 0x19, 0x99a3092f }, /* int-mic */
6867 { 0x1b, 0x0121401f }, /* HP out */
6868 { }
6869 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006870 .chained = true,
6871 .chain_id = ALC662_FIXUP_SKU_IGNORE
6872 },
6873 [ALC662_FIXUP_ASUS_MODE3] = {
6874 .type = ALC_FIXUP_PINS,
6875 .v.pins = (const struct alc_pincfg[]) {
6876 { 0x14, 0x99130110 }, /* speaker */
6877 { 0x15, 0x0121441f }, /* HP */
6878 { 0x18, 0x01a19840 }, /* mic */
6879 { 0x19, 0x99a3094f }, /* int-mic */
6880 { 0x21, 0x01211420 }, /* HP2 */
6881 { }
6882 },
6883 .chained = true,
6884 .chain_id = ALC662_FIXUP_SKU_IGNORE
6885 },
6886 [ALC662_FIXUP_ASUS_MODE4] = {
6887 .type = ALC_FIXUP_PINS,
6888 .v.pins = (const struct alc_pincfg[]) {
6889 { 0x14, 0x99130110 }, /* speaker */
6890 { 0x16, 0x99130111 }, /* speaker */
6891 { 0x18, 0x01a19840 }, /* mic */
6892 { 0x19, 0x99a3094f }, /* int-mic */
6893 { 0x21, 0x0121441f }, /* HP */
6894 { }
6895 },
6896 .chained = true,
6897 .chain_id = ALC662_FIXUP_SKU_IGNORE
6898 },
6899 [ALC662_FIXUP_ASUS_MODE5] = {
6900 .type = ALC_FIXUP_PINS,
6901 .v.pins = (const struct alc_pincfg[]) {
6902 { 0x14, 0x99130110 }, /* speaker */
6903 { 0x15, 0x0121441f }, /* HP */
6904 { 0x16, 0x99130111 }, /* speaker */
6905 { 0x18, 0x01a19840 }, /* mic */
6906 { 0x19, 0x99a3094f }, /* int-mic */
6907 { }
6908 },
6909 .chained = true,
6910 .chain_id = ALC662_FIXUP_SKU_IGNORE
6911 },
6912 [ALC662_FIXUP_ASUS_MODE6] = {
6913 .type = ALC_FIXUP_PINS,
6914 .v.pins = (const struct alc_pincfg[]) {
6915 { 0x14, 0x99130110 }, /* speaker */
6916 { 0x15, 0x01211420 }, /* HP2 */
6917 { 0x18, 0x01a19840 }, /* mic */
6918 { 0x19, 0x99a3094f }, /* int-mic */
6919 { 0x1b, 0x0121441f }, /* HP */
6920 { }
6921 },
6922 .chained = true,
6923 .chain_id = ALC662_FIXUP_SKU_IGNORE
6924 },
6925 [ALC662_FIXUP_ASUS_MODE7] = {
6926 .type = ALC_FIXUP_PINS,
6927 .v.pins = (const struct alc_pincfg[]) {
6928 { 0x14, 0x99130110 }, /* speaker */
6929 { 0x17, 0x99130111 }, /* speaker */
6930 { 0x18, 0x01a19840 }, /* mic */
6931 { 0x19, 0x99a3094f }, /* int-mic */
6932 { 0x1b, 0x01214020 }, /* HP */
6933 { 0x21, 0x0121401f }, /* HP */
6934 { }
6935 },
6936 .chained = true,
6937 .chain_id = ALC662_FIXUP_SKU_IGNORE
6938 },
6939 [ALC662_FIXUP_ASUS_MODE8] = {
6940 .type = ALC_FIXUP_PINS,
6941 .v.pins = (const struct alc_pincfg[]) {
6942 { 0x14, 0x99130110 }, /* speaker */
6943 { 0x12, 0x99a30970 }, /* int-mic */
6944 { 0x15, 0x01214020 }, /* HP */
6945 { 0x17, 0x99130111 }, /* speaker */
6946 { 0x18, 0x01a19840 }, /* mic */
6947 { 0x21, 0x0121401f }, /* HP */
6948 { }
6949 },
6950 .chained = true,
6951 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006952 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006953 [ALC662_FIXUP_NO_JACK_DETECT] = {
6954 .type = ALC_FIXUP_FUNC,
6955 .v.func = alc_fixup_no_jack_detect,
6956 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006957 [ALC662_FIXUP_ZOTAC_Z68] = {
6958 .type = ALC_FIXUP_PINS,
6959 .v.pins = (const struct alc_pincfg[]) {
6960 { 0x1b, 0x02214020 }, /* Front HP */
6961 { }
6962 }
6963 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006964 [ALC662_FIXUP_INV_DMIC] = {
6965 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006966 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006967 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006968};
6969
Takashi Iwaia9111322011-05-02 11:30:18 +02006970static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006971 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006972 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006973 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006974 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006975 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006976 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006977 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006978 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006979 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006980 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006981 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006982 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006983 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006984
6985#if 0
6986 /* Below is a quirk table taken from the old code.
6987 * Basically the device should work as is without the fixup table.
6988 * If BIOS doesn't give a proper info, enable the corresponding
6989 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006990 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006991 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6992 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6993 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6994 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6995 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6996 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6997 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6998 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6999 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7000 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7001 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7002 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7003 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7004 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7005 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7006 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7007 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7008 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7009 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7010 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7011 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7012 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7013 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7014 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7015 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7016 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7017 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7018 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7019 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7020 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7021 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7022 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7023 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7024 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7025 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7026 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7027 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7028 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7029 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7030 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7031 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7032 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7033 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7034 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7035 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7036 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7037 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7038 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7039 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7040 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7041#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007042 {}
7043};
7044
Todd Broch6be79482010-12-07 16:51:05 -08007045static const struct alc_model_fixup alc662_fixup_models[] = {
7046 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007047 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7048 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7049 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7050 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7051 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7052 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7053 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7054 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007055 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007056 {}
7057};
David Henningsson6cb3b702010-09-09 08:51:44 +02007058
Kailang Yang8663ff72012-06-29 09:35:52 +02007059static void alc662_fill_coef(struct hda_codec *codec)
7060{
7061 int val, coef;
7062
7063 coef = alc_get_coef0(codec);
7064
7065 switch (codec->vendor_id) {
7066 case 0x10ec0662:
7067 if ((coef & 0x00f0) == 0x0030) {
7068 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7069 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7070 }
7071 break;
7072 case 0x10ec0272:
7073 case 0x10ec0273:
7074 case 0x10ec0663:
7075 case 0x10ec0665:
7076 case 0x10ec0670:
7077 case 0x10ec0671:
7078 case 0x10ec0672:
7079 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7080 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7081 break;
7082 }
7083}
David Henningsson6cb3b702010-09-09 08:51:44 +02007084
Takashi Iwai1d045db2011-07-07 18:23:21 +02007085/*
7086 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007087static int patch_alc662(struct hda_codec *codec)
7088{
7089 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007090 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007091
Takashi Iwai3de95172012-05-07 18:03:15 +02007092 err = alc_alloc_spec(codec, 0x0b);
7093 if (err < 0)
7094 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007095
Takashi Iwai3de95172012-05-07 18:03:15 +02007096 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007097
Takashi Iwai53c334a2011-08-23 18:27:14 +02007098 /* handle multiple HPs as is */
7099 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7100
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007101 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7102
Kailang Yang8663ff72012-06-29 09:35:52 +02007103 spec->init_hook = alc662_fill_coef;
7104 alc662_fill_coef(codec);
7105
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007106 alc_pick_fixup(codec, alc662_fixup_models,
7107 alc662_fixup_tbl, alc662_fixups);
7108 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7109
7110 alc_auto_parse_customize_define(codec);
7111
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007112 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007113 codec->bus->pci->subsystem_vendor == 0x1025 &&
7114 spec->cdefine.platform_type == 1) {
7115 if (alc_codec_rename(codec, "ALC272X") < 0)
7116 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007117 }
Kailang Yang274693f2009-12-03 10:07:50 +01007118
Takashi Iwaib9c51062011-08-24 18:08:07 +02007119 /* automatic parse from the BIOS config */
7120 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007121 if (err < 0)
7122 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007123
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007124 if (!spec->no_analog && has_cdefine_beep(codec)) {
7125 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007126 if (err < 0)
7127 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007128 switch (codec->vendor_id) {
7129 case 0x10ec0662:
7130 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7131 break;
7132 case 0x10ec0272:
7133 case 0x10ec0663:
7134 case 0x10ec0665:
7135 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7136 break;
7137 case 0x10ec0273:
7138 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7139 break;
7140 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007141 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007142
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007143 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007144 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007145
Takashi Iwai589876e2012-02-20 15:47:55 +01007146 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7147
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007148 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007149
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007150 error:
7151 alc_free(codec);
7152 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007153}
7154
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007155/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007156 * ALC680 support
7157 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007158
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007159static int alc680_parse_auto_config(struct hda_codec *codec)
7160{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007161 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007162}
7163
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007164/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007165 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007166static int patch_alc680(struct hda_codec *codec)
7167{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007168 int err;
7169
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007170 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007171 err = alc_alloc_spec(codec, 0);
7172 if (err < 0)
7173 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007174
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007175 /* automatic parse from the BIOS config */
7176 err = alc680_parse_auto_config(codec);
7177 if (err < 0) {
7178 alc_free(codec);
7179 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007180 }
7181
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007182 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007183
7184 return 0;
7185}
7186
7187/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007188 * patch entries
7189 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007190static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007191 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007192 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007193 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007194 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007195 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007196 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007197 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007198 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007199 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007200 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007201 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007202 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007203 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007204 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007205 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007206 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007207 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007208 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007209 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7210 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7211 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007212 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007213 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007214 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7215 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007216 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7217 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007218 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007219 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007220 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007221 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007222 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007223 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007224 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007225 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007226 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007227 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007228 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007229 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007230 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007231 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007232 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007233 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007234 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007235 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007236 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007237 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007238 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007239 {} /* terminator */
7240};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007241
7242MODULE_ALIAS("snd-hda-codec-id:10ec*");
7243
7244MODULE_LICENSE("GPL");
7245MODULE_DESCRIPTION("Realtek HD-audio codec");
7246
7247static struct hda_codec_preset_list realtek_list = {
7248 .preset = snd_hda_preset_realtek,
7249 .owner = THIS_MODULE,
7250};
7251
7252static int __init patch_realtek_init(void)
7253{
7254 return snd_hda_add_codec_preset(&realtek_list);
7255}
7256
7257static void __exit patch_realtek_exit(void)
7258{
7259 snd_hda_delete_codec_preset(&realtek_list);
7260}
7261
7262module_init(patch_realtek_init)
7263module_exit(patch_realtek_exit)