blob: 269d41a2fea041a7ceaee4d312094b8aa49ed977 [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 Iwai36f0fd52012-12-12 17:25:00 +010098/* Widget connection path
99 *
100 * For output, stored in the order of DAC -> ... -> pin,
101 * for input, pin -> ... -> ADC.
102 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100103 * idx[i] contains the source index number to select on of the widget path[i];
104 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100105 * multi[] indicates whether it's a selector widget with multi-connectors
106 * (i.e. the connection selection is mandatory)
107 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
108 */
109struct nid_path {
110 int depth;
111 hda_nid_t path[MAX_NID_PATH_DEPTH];
112 unsigned char idx[MAX_NID_PATH_DEPTH];
113 unsigned char multi[MAX_NID_PATH_DEPTH];
114 unsigned int ctls[2]; /* 0 = volume, 1 = mute */
Takashi Iwai130e5f02012-12-14 16:09:29 +0100115 bool active;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100116};
117
Takashi Iwaiba8111272012-12-06 18:06:23 +0100118enum { NID_PATH_VOL_CTL = 0, NID_PATH_MUTE_CTL = 1 };
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200121 struct hda_gen_spec gen;
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200124 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +0200126 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100127 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200129 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200130 const struct hda_pcm_stream *stream_analog_playback;
131 const struct hda_pcm_stream *stream_analog_capture;
132 const struct hda_pcm_stream *stream_analog_alt_playback;
133 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200135 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200136 const struct hda_pcm_stream *stream_digital_playback;
137 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200140 struct hda_multi_out multiout; /* playback set-up
141 * max_channels, dacs must be set
142 * dig_out_nid and hp_nid are optional
143 */
Takashi Iwai63300792008-01-24 15:31:36 +0100144 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100145 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100146 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* capture */
149 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200150 const hda_nid_t *adc_nids;
151 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200152 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200153 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Takashi Iwai840b64c2010-07-13 22:49:01 +0200155 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200156 hda_nid_t cur_adc;
157 unsigned int cur_adc_stream_tag;
158 unsigned int cur_adc_format;
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200161 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 const struct hda_input_mux *input_mux;
163 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200164 hda_nid_t ext_mic_pin;
165 hda_nid_t dock_mic_pin;
166 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100169 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200171 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100172 int const_channel_count; /* min. channel count (for speakers) */
173 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100176 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200177
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200178 /* dynamic controls, init_verbs and input_mux */
179 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100180 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200181 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200182 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200183 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200184 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
185 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200186 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
187 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
188 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200189 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100190
Takashi Iwai463419d2012-12-05 14:17:37 +0100191 /* DAC list */
192 int num_all_dacs;
193 hda_nid_t all_dacs[16];
194
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100195 /* output paths */
196 struct snd_array out_path;
197
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100198 /* input paths */
199 struct snd_array in_path;
200
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100201 /* analog loopback paths */
202 struct snd_array loopback_path;
203
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100204 /* hooks */
205 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200206#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500207 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100208#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200209 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200210 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100211
Takashi Iwai834be882006-03-01 14:16:17 +0100212 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200213 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200214 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200215 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200216 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200217 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200218 unsigned int automute_speaker:1; /* automute speaker outputs */
219 unsigned int automute_lo:1; /* automute LO outputs */
220 unsigned int detect_hp:1; /* Headphone detection enabled */
221 unsigned int detect_lo:1; /* Line-out detection enabled */
222 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
223 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100224 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200225
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100226 /* other flags */
227 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200228 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100229 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200230 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200231 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100232 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200233 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
234 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200235 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200236
237 /* auto-mute control */
238 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200239 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200240
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200241 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200242 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100243
Takashi Iwai2134ea42008-01-10 16:53:55 +0100244 /* for virtual master */
245 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100246 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200247#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200248 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100249 int num_loopbacks;
250 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200251#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200252
253 /* for PLL fix */
254 hda_nid_t pll_nid;
255 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200256 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100257
Takashi Iwaice764ab2011-04-27 16:35:23 +0200258 /* multi-io */
259 int multi_ios;
260 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200261
262 /* bind volumes */
263 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100264};
265
Takashi Iwai44c02402011-07-08 15:14:19 +0200266static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
267 int dir, unsigned int bits)
268{
269 if (!nid)
270 return false;
271 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
272 if (query_amp_caps(codec, nid, dir) & bits)
273 return true;
274 return false;
275}
276
277#define nid_has_mute(codec, nid, dir) \
278 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
279#define nid_has_volume(codec, nid, dir) \
280 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282/*
283 * input MUX handling
284 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200285static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
289 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200290 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
291 if (mux_idx >= spec->num_mux_defs)
292 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100293 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
294 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200295 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200298static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
299 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
302 struct alc_spec *spec = codec->spec;
303 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
304
305 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
306 return 0;
307}
308
Takashi Iwai21268962011-07-07 15:01:13 +0200309static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Takashi Iwai21268962011-07-07 15:01:13 +0200311 struct alc_spec *spec = codec->spec;
312 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
313
314 if (spec->cur_adc && spec->cur_adc != new_adc) {
315 /* stream is running, let's swap the current ADC */
316 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
317 spec->cur_adc = new_adc;
318 snd_hda_codec_setup_stream(codec, new_adc,
319 spec->cur_adc_stream_tag, 0,
320 spec->cur_adc_format);
321 return true;
322 }
323 return false;
324}
325
Takashi Iwai61071592011-11-23 07:52:15 +0100326static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
327{
328 return spec->capsrc_nids ?
329 spec->capsrc_nids[idx] : spec->adc_nids[idx];
330}
331
Takashi Iwai24de1832011-11-07 17:13:39 +0100332static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200333static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100334
David Henningsson00227f12012-06-27 18:45:44 +0200335/* for shared I/O, change the pin-control accordingly */
336static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
337{
338 struct alc_spec *spec = codec->spec;
339 unsigned int val;
340 hda_nid_t pin = spec->autocfg.inputs[1].pin;
341 /* NOTE: this assumes that there are only two inputs, the
342 * first is the real internal mic and the second is HP/mic jack.
343 */
344
345 val = snd_hda_get_default_vref(codec, pin);
346
347 /* This pin does not have vref caps - let's enable vref on pin 0x18
348 instead, as suggested by Realtek */
349 if (val == AC_PINCTL_VREF_HIZ) {
350 const hda_nid_t vref_pin = 0x18;
351 /* Sanity check pin 0x18 */
352 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
353 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
354 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
355 if (vref_val != AC_PINCTL_VREF_HIZ)
356 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
357 }
358 }
359
360 val = set_as_mic ? val | PIN_IN : PIN_HP;
361 snd_hda_set_pin_ctl(codec, pin, val);
362
363 spec->automute_speaker = !set_as_mic;
364 call_update_outputs(codec);
365}
Takashi Iwai21268962011-07-07 15:01:13 +0200366
367/* select the given imux item; either unmute exclusively or select the route */
368static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
369 unsigned int idx, bool force)
370{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100372 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100373 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100374 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200375 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Takashi Iwai5803a322012-02-21 11:59:45 +0100377 if (!spec->input_mux)
378 return 0;
379
Takashi Iwaicd896c32008-11-18 12:36:33 +0100380 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
381 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100382 if (!imux->num_items && mux_idx > 0)
383 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100384 if (!imux->num_items)
385 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100386
Takashi Iwai21268962011-07-07 15:01:13 +0200387 if (idx >= imux->num_items)
388 idx = imux->num_items - 1;
389 if (spec->cur_mux[adc_idx] == idx && !force)
390 return 0;
391 spec->cur_mux[adc_idx] = idx;
392
David Henningsson00227f12012-06-27 18:45:44 +0200393 if (spec->shared_mic_hp)
394 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100395
Takashi Iwai21268962011-07-07 15:01:13 +0200396 if (spec->dyn_adc_switch) {
397 alc_dyn_adc_pcm_resetup(codec, idx);
398 adc_idx = spec->dyn_adc_idx[idx];
399 }
400
Takashi Iwai61071592011-11-23 07:52:15 +0100401 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200402
403 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200404 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100405 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200406 return 1;
407
Takashi Iwaia22d5432009-07-27 12:54:26 +0200408 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200409 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100410 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100411 int active = imux->items[idx].index;
412 for (i = 0; i < num_conns; i++) {
413 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
414 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100415 HDA_AMP_MUTE, v);
416 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100417 } else {
418 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200419 snd_hda_codec_write_cache(codec, nid, 0,
420 AC_VERB_SET_CONNECT_SEL,
421 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100422 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200423 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200424 return 1;
425}
426
427static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
428 struct snd_ctl_elem_value *ucontrol)
429{
430 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
431 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
432 return alc_mux_select(codec, adc_idx,
433 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100434}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100437 * set up the input pin config (depending on the given auto-pin type)
438 */
439static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
440 int auto_pin_type)
441{
442 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200443 if (auto_pin_type == AUTO_PIN_MIC)
444 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200445 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100446}
447
448/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200449 * Append the given mixer and verb elements for the later use
450 * The mixer array is referred in build_controls(), and init_verbs are
451 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100452 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200453static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100454{
455 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
456 return;
457 spec->mixers[spec->num_mixers++] = mix;
458}
459
Takashi Iwaid88897e2008-10-31 15:01:37 +0100460/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200461 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100462 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200463/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200464static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200465 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
466 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
467 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
468 { }
469};
470
Takashi Iwaia9111322011-05-02 11:30:18 +0200471static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200472 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
473 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
474 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
475 { }
476};
477
Takashi Iwaia9111322011-05-02 11:30:18 +0200478static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200479 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
480 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
481 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
482 { }
483};
484
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200485/*
486 * Fix hardware PLL issue
487 * On some codecs, the analog PLL gating control must be off while
488 * the default value is 1.
489 */
490static void alc_fix_pll(struct hda_codec *codec)
491{
492 struct alc_spec *spec = codec->spec;
493 unsigned int val;
494
495 if (!spec->pll_nid)
496 return;
497 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
498 spec->pll_coef_idx);
499 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
500 AC_VERB_GET_PROC_COEF, 0);
501 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
502 spec->pll_coef_idx);
503 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
504 val & ~(1 << spec->pll_coef_bit));
505}
506
507static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
508 unsigned int coef_idx, unsigned int coef_bit)
509{
510 struct alc_spec *spec = codec->spec;
511 spec->pll_nid = nid;
512 spec->pll_coef_idx = coef_idx;
513 spec->pll_coef_bit = coef_bit;
514 alc_fix_pll(codec);
515}
516
Takashi Iwai1d045db2011-07-07 18:23:21 +0200517/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200518 * Jack detections for HP auto-mute and mic-switch
519 */
520
521/* check each pin in the given array; returns true if any of them is plugged */
522static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200523{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200524 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200525
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526 for (i = 0; i < num_pins; i++) {
527 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200528 if (!nid)
529 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200530 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200531 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532 return present;
533}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200534
Takashi Iwai1d045db2011-07-07 18:23:21 +0200535/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200536static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200537 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200538{
539 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200540 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200541 int i;
542
543 for (i = 0; i < num_pins; i++) {
544 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100545 unsigned int val;
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200546 if (!nid)
547 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100548 /* don't reset VREF value in case it's controlling
549 * the amp (see alc861_fixup_asus_amp_vref_0f())
550 */
551 if (spec->keep_vref_in_automute) {
552 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100553 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100554 val &= ~PIN_HP;
555 } else
556 val = 0;
557 val |= pin_bits;
558 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200559 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200560}
561
David Henningsson42cf0d02011-09-20 12:04:56 +0200562/* Toggle outputs muting */
563static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200564{
565 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200567
Takashi Iwaic0a20262011-06-10 15:28:15 +0200568 /* Control HP pins/amps depending on master_mute state;
569 * in general, HP pins/amps control should be enabled in all cases,
570 * but currently set only for master_mute, just to be safe
571 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100572 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
573 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200574 spec->autocfg.hp_pins, spec->master_mute, true);
575
David Henningsson42cf0d02011-09-20 12:04:56 +0200576 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200577 on = 0;
578 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200579 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200580 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200581 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200582 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583
584 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200585 /* if LO is a copy of either HP or Speaker, don't need to handle it */
586 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
587 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200589 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200590 on = 0;
591 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200593 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200594 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200595 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200596}
597
David Henningsson42cf0d02011-09-20 12:04:56 +0200598static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200599{
600 struct alc_spec *spec = codec->spec;
601 if (spec->automute_hook)
602 spec->automute_hook(codec);
603 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200604 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200605}
606
Takashi Iwai1d045db2011-07-07 18:23:21 +0200607/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200608static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200609{
610 struct alc_spec *spec = codec->spec;
611
David Henningsson42cf0d02011-09-20 12:04:56 +0200612 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200613 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
614 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200615 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200616 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200617 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200618}
619
Takashi Iwai1d045db2011-07-07 18:23:21 +0200620/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200621static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200622{
623 struct alc_spec *spec = codec->spec;
624
David Henningssonf7f4b2322012-10-10 16:32:09 +0200625 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
626 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200627 /* check LO jack only when it's different from HP */
628 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
629 return;
630
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200631 spec->line_jack_present =
632 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
633 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200634 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200635 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200636 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200637}
638
Takashi Iwai8d087c72011-06-28 12:45:47 +0200639#define get_connection_index(codec, mux, nid) \
640 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200641
Takashi Iwai1d045db2011-07-07 18:23:21 +0200642/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200643static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200644{
645 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200646 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200647
Takashi Iwai21268962011-07-07 15:01:13 +0200648 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200649 return;
650 if (snd_BUG_ON(!spec->adc_nids))
651 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200652 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200653 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200654
Takashi Iwai21268962011-07-07 15:01:13 +0200655 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
656 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
657 else if (spec->dock_mic_idx >= 0 &&
658 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
659 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
660 else
661 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200662}
663
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100664/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200665static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100666{
667 unsigned int val;
668 struct snd_kcontrol *kctl;
669 struct snd_ctl_elem_value *uctl;
670
671 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
672 if (!kctl)
673 return;
674 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
675 if (!uctl)
676 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200677 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100678 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
679 val &= HDA_AMP_VOLMASK;
680 uctl->value.integer.value[0] = val;
681 uctl->value.integer.value[1] = val;
682 kctl->put(kctl, uctl);
683 kfree(uctl);
684}
685
David Henningsson29adc4b2012-09-25 11:31:00 +0200686static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100687{
David Henningsson29adc4b2012-09-25 11:31:00 +0200688 /* For some reason, the res given from ALC880 is broken.
689 Here we adjust it properly. */
690 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100691}
692
Takashi Iwai1d045db2011-07-07 18:23:21 +0200693/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200694static void alc_inithook(struct hda_codec *codec)
695{
David Henningsson29adc4b2012-09-25 11:31:00 +0200696 alc_hp_automute(codec, NULL);
697 alc_line_automute(codec, NULL);
698 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200699}
700
Kailang Yangf9423e72008-05-27 12:32:25 +0200701/* additional initialization for ALC888 variants */
702static void alc888_coef_init(struct hda_codec *codec)
703{
704 unsigned int tmp;
705
706 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
707 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
708 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100709 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200710 /* alc888S-VC */
711 snd_hda_codec_read(codec, 0x20, 0,
712 AC_VERB_SET_PROC_COEF, 0x830);
713 else
714 /* alc888-VB */
715 snd_hda_codec_read(codec, 0x20, 0,
716 AC_VERB_SET_PROC_COEF, 0x3030);
717}
718
Takashi Iwai1d045db2011-07-07 18:23:21 +0200719/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200720static void alc889_coef_init(struct hda_codec *codec)
721{
722 unsigned int tmp;
723
724 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
725 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
726 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
727 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
728}
729
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100730/* turn on/off EAPD control (only if available) */
731static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
732{
733 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
734 return;
735 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
736 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
737 on ? 2 : 0);
738}
739
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200740/* turn on/off EAPD controls of the codec */
741static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
742{
743 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200744 static hda_nid_t pins[] = {
745 0x0f, 0x10, 0x14, 0x15, 0
746 };
747 hda_nid_t *p;
748 for (p = pins; *p; p++)
749 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200750}
751
Takashi Iwai1c7161532011-04-07 10:37:16 +0200752/* generic shutup callback;
753 * just turning off EPAD and a little pause for avoiding pop-noise
754 */
755static void alc_eapd_shutup(struct hda_codec *codec)
756{
757 alc_auto_setup_eapd(codec, false);
758 msleep(200);
759}
760
Takashi Iwai1d045db2011-07-07 18:23:21 +0200761/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200762static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200763{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200764 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200765
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200766 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200767 switch (type) {
768 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200769 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
770 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200771 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200772 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
773 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200774 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200775 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
776 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200778 switch (codec->vendor_id) {
779 case 0x10ec0260:
780 snd_hda_codec_write(codec, 0x1a, 0,
781 AC_VERB_SET_COEF_INDEX, 7);
782 tmp = snd_hda_codec_read(codec, 0x1a, 0,
783 AC_VERB_GET_PROC_COEF, 0);
784 snd_hda_codec_write(codec, 0x1a, 0,
785 AC_VERB_SET_COEF_INDEX, 7);
786 snd_hda_codec_write(codec, 0x1a, 0,
787 AC_VERB_SET_PROC_COEF,
788 tmp | 0x2010);
789 break;
790 case 0x10ec0262:
791 case 0x10ec0880:
792 case 0x10ec0882:
793 case 0x10ec0883:
794 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100795 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100796 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200797 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200798 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200799 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200800 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200801 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100802#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200803 case 0x10ec0267:
804 case 0x10ec0268:
805 snd_hda_codec_write(codec, 0x20, 0,
806 AC_VERB_SET_COEF_INDEX, 7);
807 tmp = snd_hda_codec_read(codec, 0x20, 0,
808 AC_VERB_GET_PROC_COEF, 0);
809 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200810 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200811 snd_hda_codec_write(codec, 0x20, 0,
812 AC_VERB_SET_PROC_COEF,
813 tmp | 0x3000);
814 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100815#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200816 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200817 break;
818 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200819}
Kailang Yangea1fb292008-08-26 12:58:38 +0200820
Takashi Iwai1d045db2011-07-07 18:23:21 +0200821/*
822 * Auto-Mute mode mixer enum support
823 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200824static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
825 struct snd_ctl_elem_info *uinfo)
826{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200827 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
828 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200829 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100830 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200831 };
832
Takashi Iwaidda415d2012-11-30 18:34:38 +0100833 if (spec->automute_speaker_possible && spec->automute_lo_possible)
834 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
835 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200836}
837
838static int alc_automute_mode_get(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;
David Henningsson42cf0d02011-09-20 12:04:56 +0200843 unsigned int val = 0;
844 if (spec->automute_speaker)
845 val++;
846 if (spec->automute_lo)
847 val++;
848
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200849 ucontrol->value.enumerated.item[0] = val;
850 return 0;
851}
852
853static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
854 struct snd_ctl_elem_value *ucontrol)
855{
856 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
857 struct alc_spec *spec = codec->spec;
858
859 switch (ucontrol->value.enumerated.item[0]) {
860 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200861 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200862 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200863 spec->automute_speaker = 0;
864 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200865 break;
866 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200867 if (spec->automute_speaker_possible) {
868 if (!spec->automute_lo && spec->automute_speaker)
869 return 0;
870 spec->automute_speaker = 1;
871 spec->automute_lo = 0;
872 } else if (spec->automute_lo_possible) {
873 if (spec->automute_lo)
874 return 0;
875 spec->automute_lo = 1;
876 } else
877 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200878 break;
879 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200880 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200881 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200882 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200883 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 spec->automute_speaker = 1;
885 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200886 break;
887 default:
888 return -EINVAL;
889 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200890 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200891 return 1;
892}
893
Takashi Iwaia9111322011-05-02 11:30:18 +0200894static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200895 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
896 .name = "Auto-Mute Mode",
897 .info = alc_automute_mode_info,
898 .get = alc_automute_mode_get,
899 .put = alc_automute_mode_put,
900};
901
Takashi Iwai668d1e92012-11-29 14:10:17 +0100902static struct snd_kcontrol_new *
903alc_kcontrol_new(struct alc_spec *spec, const char *name,
904 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200905{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100906 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
907 if (!knew)
908 return NULL;
909 *knew = *temp;
910 knew->name = kstrdup(name, GFP_KERNEL);
911 if (!knew->name)
912 return NULL;
913 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200914}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200915
916static int alc_add_automute_mode_enum(struct hda_codec *codec)
917{
918 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200919
Takashi Iwai668d1e92012-11-29 14:10:17 +0100920 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200921 return -ENOMEM;
922 return 0;
923}
924
Takashi Iwai1d045db2011-07-07 18:23:21 +0200925/*
926 * Check the availability of HP/line-out auto-mute;
927 * Set up appropriately if really supported
928 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100929static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200930{
931 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200932 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200933 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100934 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200935
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200936 if (cfg->hp_pins[0])
937 present++;
938 if (cfg->line_out_pins[0])
939 present++;
940 if (cfg->speaker_pins[0])
941 present++;
942 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100943 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200944
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200945 if (!cfg->speaker_pins[0] &&
946 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200947 memcpy(cfg->speaker_pins, cfg->line_out_pins,
948 sizeof(cfg->speaker_pins));
949 cfg->speaker_outs = cfg->line_outs;
950 }
951
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200952 if (!cfg->hp_pins[0] &&
953 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200954 memcpy(cfg->hp_pins, cfg->line_out_pins,
955 sizeof(cfg->hp_pins));
956 cfg->hp_outs = cfg->line_outs;
957 }
958
959 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200960 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200961 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200962 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200963 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200964 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200965 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
966 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200967 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200968 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200969
David Henningsson42cf0d02011-09-20 12:04:56 +0200970 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
971 if (cfg->speaker_outs)
972 for (i = 0; i < cfg->line_outs; i++) {
973 hda_nid_t nid = cfg->line_out_pins[i];
974 if (!is_jack_detectable(codec, nid))
975 continue;
976 snd_printdd("realtek: Enable Line-Out "
977 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200978 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
979 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200980 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200981 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200982 spec->automute_lo_possible = spec->detect_hp;
983 }
984
985 spec->automute_speaker_possible = cfg->speaker_outs &&
986 (spec->detect_hp || spec->detect_lo);
987
988 spec->automute_lo = spec->automute_lo_possible;
989 spec->automute_speaker = spec->automute_speaker_possible;
990
Takashi Iwai475c3d22012-11-30 08:31:30 +0100991 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200992 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100993 err = alc_add_automute_mode_enum(codec);
994 if (err < 0)
995 return err;
996 }
997 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200998}
999
Takashi Iwai1d045db2011-07-07 18:23:21 +02001000/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001001static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1002{
1003 int i;
1004 for (i = 0; i < nums; i++)
1005 if (list[i] == nid)
1006 return i;
1007 return -1;
1008}
1009
Takashi Iwai1d045db2011-07-07 18:23:21 +02001010/* check whether dynamic ADC-switching is available */
1011static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1012{
1013 struct alc_spec *spec = codec->spec;
1014 struct hda_input_mux *imux = &spec->private_imux[0];
1015 int i, n, idx;
1016 hda_nid_t cap, pin;
1017
1018 if (imux != spec->input_mux) /* no dynamic imux? */
1019 return false;
1020
1021 for (n = 0; n < spec->num_adc_nids; n++) {
1022 cap = spec->private_capsrc_nids[n];
1023 for (i = 0; i < imux->num_items; i++) {
1024 pin = spec->imux_pins[i];
1025 if (!pin)
1026 return false;
1027 if (get_connection_index(codec, cap, pin) < 0)
1028 break;
1029 }
1030 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001031 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001032 }
1033
1034 for (i = 0; i < imux->num_items; i++) {
1035 pin = spec->imux_pins[i];
1036 for (n = 0; n < spec->num_adc_nids; n++) {
1037 cap = spec->private_capsrc_nids[n];
1038 idx = get_connection_index(codec, cap, pin);
1039 if (idx >= 0) {
1040 imux->items[i].index = idx;
1041 spec->dyn_adc_idx[i] = n;
1042 break;
1043 }
1044 }
1045 }
1046
1047 snd_printdd("realtek: enabling ADC switching\n");
1048 spec->dyn_adc_switch = 1;
1049 return true;
1050}
Takashi Iwai21268962011-07-07 15:01:13 +02001051
Takashi Iwai21268962011-07-07 15:01:13 +02001052/* check whether all auto-mic pins are valid; setup indices if OK */
1053static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1054{
1055 struct alc_spec *spec = codec->spec;
1056 const struct hda_input_mux *imux;
1057
1058 if (!spec->auto_mic)
1059 return false;
1060 if (spec->auto_mic_valid_imux)
1061 return true; /* already checked */
1062
1063 /* fill up imux indices */
1064 if (!alc_check_dyn_adc_switch(codec)) {
1065 spec->auto_mic = 0;
1066 return false;
1067 }
1068
1069 imux = spec->input_mux;
1070 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1071 spec->imux_pins, imux->num_items);
1072 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1073 spec->imux_pins, imux->num_items);
1074 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1075 spec->imux_pins, imux->num_items);
1076 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1077 spec->auto_mic = 0;
1078 return false; /* no corresponding imux */
1079 }
1080
David Henningsson29adc4b2012-09-25 11:31:00 +02001081 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1082 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001083 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001084 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1085 ALC_MIC_EVENT,
1086 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001087
1088 spec->auto_mic_valid_imux = 1;
1089 spec->auto_mic = 1;
1090 return true;
1091}
1092
Takashi Iwai1d045db2011-07-07 18:23:21 +02001093/*
1094 * Check the availability of auto-mic switch;
1095 * Set up if really supported
1096 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001097static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001098{
1099 struct alc_spec *spec = codec->spec;
1100 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001101 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001102 int i;
1103
Takashi Iwai24de1832011-11-07 17:13:39 +01001104 if (spec->shared_mic_hp)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001105 return 0; /* no auto-mic for the shared I/O */
Takashi Iwai24de1832011-11-07 17:13:39 +01001106
Takashi Iwai21268962011-07-07 15:01:13 +02001107 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1108
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001109 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001110 for (i = 0; i < cfg->num_inputs; i++) {
1111 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001112 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001113 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001114 switch (snd_hda_get_input_pin_attr(defcfg)) {
1115 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001116 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001117 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001118 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001119 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001120 fixed = nid;
1121 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001122 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001123 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001124 case INPUT_PIN_ATTR_DOCK:
1125 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001126 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001127 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001128 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001129 dock = nid;
1130 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001131 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001132 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001133 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001134 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001135 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001136 ext = nid;
1137 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001138 }
1139 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001140 if (!ext && dock) {
1141 ext = dock;
1142 dock = 0;
1143 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001144 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001145 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001146 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001147 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001148 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001149 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001150
1151 /* check imux indices */
1152 spec->ext_mic_pin = ext;
1153 spec->int_mic_pin = fixed;
1154 spec->dock_mic_pin = dock;
1155
1156 spec->auto_mic = 1;
1157 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001158 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001159
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001160 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1161 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001162
1163 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001164}
1165
Takashi Iwai1d045db2011-07-07 18:23:21 +02001166/* check the availabilities of auto-mute and auto-mic switches */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001167static int alc_auto_check_switches(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02001168{
Takashi Iwai475c3d22012-11-30 08:31:30 +01001169 int err;
1170
1171 err = alc_init_automute(codec);
1172 if (err < 0)
1173 return err;
1174 err = alc_init_auto_mic(codec);
1175 if (err < 0)
1176 return err;
1177 return 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02001178}
1179
1180/*
1181 * Realtek SSID verification
1182 */
1183
David Henningsson90622912010-10-14 14:50:18 +02001184/* Could be any non-zero and even value. When used as fixup, tells
1185 * the driver to ignore any present sku defines.
1186 */
1187#define ALC_FIXUP_SKU_IGNORE (2)
1188
Takashi Iwai23d30f22012-05-07 17:17:32 +02001189static void alc_fixup_sku_ignore(struct hda_codec *codec,
1190 const struct hda_fixup *fix, int action)
1191{
1192 struct alc_spec *spec = codec->spec;
1193 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1194 spec->cdefine.fixup = 1;
1195 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1196 }
1197}
1198
Kailang Yangda00c242010-03-19 11:23:45 +01001199static int alc_auto_parse_customize_define(struct hda_codec *codec)
1200{
1201 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001202 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001203 struct alc_spec *spec = codec->spec;
1204
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001205 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1206
David Henningsson90622912010-10-14 14:50:18 +02001207 if (spec->cdefine.fixup) {
1208 ass = spec->cdefine.sku_cfg;
1209 if (ass == ALC_FIXUP_SKU_IGNORE)
1210 return -1;
1211 goto do_sku;
1212 }
1213
Kailang Yangda00c242010-03-19 11:23:45 +01001214 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001215 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001216 goto do_sku;
1217
1218 nid = 0x1d;
1219 if (codec->vendor_id == 0x10ec0260)
1220 nid = 0x17;
1221 ass = snd_hda_codec_get_pincfg(codec, nid);
1222
1223 if (!(ass & 1)) {
1224 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1225 codec->chip_name, ass);
1226 return -1;
1227 }
1228
1229 /* check sum */
1230 tmp = 0;
1231 for (i = 1; i < 16; i++) {
1232 if ((ass >> i) & 1)
1233 tmp++;
1234 }
1235 if (((ass >> 16) & 0xf) != tmp)
1236 return -1;
1237
1238 spec->cdefine.port_connectivity = ass >> 30;
1239 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1240 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1241 spec->cdefine.customization = ass >> 8;
1242do_sku:
1243 spec->cdefine.sku_cfg = ass;
1244 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1245 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1246 spec->cdefine.swap = (ass & 0x2) >> 1;
1247 spec->cdefine.override = ass & 0x1;
1248
1249 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1250 nid, spec->cdefine.sku_cfg);
1251 snd_printd("SKU: port_connectivity=0x%x\n",
1252 spec->cdefine.port_connectivity);
1253 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1254 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1255 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1256 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1257 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1258 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1259 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1260
1261 return 0;
1262}
1263
Takashi Iwai1d045db2011-07-07 18:23:21 +02001264/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001265static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1266{
Takashi Iwai21268962011-07-07 15:01:13 +02001267 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001268}
1269
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001270/* check subsystem ID and set up device-specific initialization;
1271 * return 1 if initialized, 0 if invalid SSID
1272 */
1273/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1274 * 31 ~ 16 : Manufacture ID
1275 * 15 ~ 8 : SKU ID
1276 * 7 ~ 0 : Assembly ID
1277 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1278 */
1279static int alc_subsystem_id(struct hda_codec *codec,
1280 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001281 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001282{
1283 unsigned int ass, tmp, i;
1284 unsigned nid;
1285 struct alc_spec *spec = codec->spec;
1286
David Henningsson90622912010-10-14 14:50:18 +02001287 if (spec->cdefine.fixup) {
1288 ass = spec->cdefine.sku_cfg;
1289 if (ass == ALC_FIXUP_SKU_IGNORE)
1290 return 0;
1291 goto do_sku;
1292 }
1293
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001294 ass = codec->subsystem_id & 0xffff;
1295 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1296 goto do_sku;
1297
1298 /* invalid SSID, check the special NID pin defcfg instead */
1299 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001300 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001301 * 29~21 : reserve
1302 * 20 : PCBEEP input
1303 * 19~16 : Check sum (15:1)
1304 * 15~1 : Custom
1305 * 0 : override
1306 */
1307 nid = 0x1d;
1308 if (codec->vendor_id == 0x10ec0260)
1309 nid = 0x17;
1310 ass = snd_hda_codec_get_pincfg(codec, nid);
1311 snd_printd("realtek: No valid SSID, "
1312 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001313 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001314 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001315 return 0;
1316 if ((ass >> 30) != 1) /* no physical connection */
1317 return 0;
1318
1319 /* check sum */
1320 tmp = 0;
1321 for (i = 1; i < 16; i++) {
1322 if ((ass >> i) & 1)
1323 tmp++;
1324 }
1325 if (((ass >> 16) & 0xf) != tmp)
1326 return 0;
1327do_sku:
1328 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1329 ass & 0xffff, codec->vendor_id);
1330 /*
1331 * 0 : override
1332 * 1 : Swap Jack
1333 * 2 : 0 --> Desktop, 1 --> Laptop
1334 * 3~5 : External Amplifier control
1335 * 7~6 : Reserved
1336 */
1337 tmp = (ass & 0x38) >> 3; /* external Amp control */
1338 switch (tmp) {
1339 case 1:
1340 spec->init_amp = ALC_INIT_GPIO1;
1341 break;
1342 case 3:
1343 spec->init_amp = ALC_INIT_GPIO2;
1344 break;
1345 case 7:
1346 spec->init_amp = ALC_INIT_GPIO3;
1347 break;
1348 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001349 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001350 spec->init_amp = ALC_INIT_DEFAULT;
1351 break;
1352 }
1353
1354 /* is laptop or Desktop and enable the function "Mute internal speaker
1355 * when the external headphone out jack is plugged"
1356 */
1357 if (!(ass & 0x8000))
1358 return 1;
1359 /*
1360 * 10~8 : Jack location
1361 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1362 * 14~13: Resvered
1363 * 15 : 1 --> enable the function "Mute internal speaker
1364 * when the external headphone out jack is plugged"
1365 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001366 if (!spec->autocfg.hp_pins[0] &&
1367 !(spec->autocfg.line_out_pins[0] &&
1368 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001369 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001370 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1371 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001372 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001373 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001374 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001375 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001376 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001377 else if (tmp == 3)
1378 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001379 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001380 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001381 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1382 spec->autocfg.line_outs))
1383 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001384 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001385 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001386 return 1;
1387}
Kailang Yangea1fb292008-08-26 12:58:38 +02001388
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001389/* Check the validity of ALC subsystem-id
1390 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1391static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001392{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001393 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001394 struct alc_spec *spec = codec->spec;
1395 snd_printd("realtek: "
1396 "Enable default setup for auto mode as fallback\n");
1397 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001398 }
Takashi Iwai21268962011-07-07 15:01:13 +02001399}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001400
Takashi Iwai41e41f12005-06-08 14:48:49 +02001401/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001402 * COEF access helper functions
1403 */
Kailang Yang274693f2009-12-03 10:07:50 +01001404static int alc_read_coef_idx(struct hda_codec *codec,
1405 unsigned int coef_idx)
1406{
1407 unsigned int val;
1408 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1409 coef_idx);
1410 val = snd_hda_codec_read(codec, 0x20, 0,
1411 AC_VERB_GET_PROC_COEF, 0);
1412 return val;
1413}
1414
Kailang Yang977ddd62010-09-15 10:02:29 +02001415static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1416 unsigned int coef_val)
1417{
1418 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1419 coef_idx);
1420 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1421 coef_val);
1422}
1423
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001424/* a special bypass for COEF 0; read the cached value at the second time */
1425static unsigned int alc_get_coef0(struct hda_codec *codec)
1426{
1427 struct alc_spec *spec = codec->spec;
1428 if (!spec->coef0)
1429 spec->coef0 = alc_read_coef_idx(codec, 0);
1430 return spec->coef0;
1431}
1432
Takashi Iwai1d045db2011-07-07 18:23:21 +02001433/*
1434 * Digital I/O handling
1435 */
1436
Takashi Iwai757899a2010-07-30 10:48:14 +02001437/* set right pin controls for digital I/O */
1438static void alc_auto_init_digital(struct hda_codec *codec)
1439{
1440 struct alc_spec *spec = codec->spec;
1441 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001442 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001443
1444 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1445 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001446 if (!pin)
1447 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001448 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001449 if (!i)
1450 dac = spec->multiout.dig_out_nid;
1451 else
1452 dac = spec->slave_dig_outs[i - 1];
1453 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1454 continue;
1455 snd_hda_codec_write(codec, dac, 0,
1456 AC_VERB_SET_AMP_GAIN_MUTE,
1457 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001458 }
1459 pin = spec->autocfg.dig_in_pin;
1460 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001461 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001462}
1463
1464/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1465static void alc_auto_parse_digital(struct hda_codec *codec)
1466{
1467 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001468 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001469 hda_nid_t dig_nid;
1470
1471 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001472 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001473 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001474 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001475 err = snd_hda_get_connections(codec,
1476 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001477 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001478 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001479 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001480 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001481 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001482 spec->multiout.dig_out_nid = dig_nid;
1483 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1484 } else {
1485 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001486 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001487 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001488 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001489 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001490 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001491 }
1492
1493 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001494 dig_nid = codec->start_nid;
1495 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1496 unsigned int wcaps = get_wcaps(codec, dig_nid);
1497 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1498 continue;
1499 if (!(wcaps & AC_WCAP_DIGITAL))
1500 continue;
1501 if (!(wcaps & AC_WCAP_CONN_LIST))
1502 continue;
1503 err = get_connection_index(codec, dig_nid,
1504 spec->autocfg.dig_in_pin);
1505 if (err >= 0) {
1506 spec->dig_in_nid = dig_nid;
1507 break;
1508 }
1509 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001510 }
1511}
1512
Takashi Iwaif95474e2007-07-10 00:47:43 +02001513/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001514 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001515 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001516static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1517 struct snd_ctl_elem_info *uinfo)
1518{
1519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1520 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001521 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001522 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001523
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001524 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001525 if (spec->vol_in_capsrc)
1526 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1527 else
1528 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1529 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001530 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001531 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001532 return err;
1533}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001535static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1536 unsigned int size, unsigned int __user *tlv)
1537{
1538 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1539 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001540 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001541 int err;
1542
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001543 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001544 if (spec->vol_in_capsrc)
1545 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1546 else
1547 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1548 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001549 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001550 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001551 return err;
1552}
1553
1554typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1555 struct snd_ctl_elem_value *ucontrol);
1556
1557static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1558 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001559 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001560{
1561 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1562 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001563 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001564
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001565 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001566 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001567 for (i = 0; i < spec->num_adc_nids; i++) {
1568 kcontrol->private_value =
1569 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1570 3, 0, HDA_INPUT);
1571 err = func(kcontrol, ucontrol);
1572 if (err < 0)
1573 goto error;
1574 }
1575 } else {
1576 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001577 if (spec->vol_in_capsrc)
1578 kcontrol->private_value =
1579 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1580 3, 0, HDA_OUTPUT);
1581 else
1582 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001583 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1584 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001585 err = func(kcontrol, ucontrol);
1586 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001587 if (err >= 0 && is_put)
1588 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001589 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001590 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001591 return err;
1592}
1593
1594static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1595 struct snd_ctl_elem_value *ucontrol)
1596{
1597 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001598 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001599}
1600
1601static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1602 struct snd_ctl_elem_value *ucontrol)
1603{
1604 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001605 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001606}
1607
1608/* capture mixer elements */
1609#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1610
1611static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1612 struct snd_ctl_elem_value *ucontrol)
1613{
1614 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001615 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001616}
1617
1618static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1619 struct snd_ctl_elem_value *ucontrol)
1620{
1621 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001622 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001623}
1624
Takashi Iwaia23b6882009-03-23 15:21:36 +01001625#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001626 { \
1627 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1628 .name = "Capture Switch", \
1629 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1630 .count = num, \
1631 .info = alc_cap_sw_info, \
1632 .get = alc_cap_sw_get, \
1633 .put = alc_cap_sw_put, \
1634 }, \
1635 { \
1636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1637 .name = "Capture Volume", \
1638 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1639 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1640 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1641 .count = num, \
1642 .info = alc_cap_vol_info, \
1643 .get = alc_cap_vol_get, \
1644 .put = alc_cap_vol_put, \
1645 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001646 }
1647
1648#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001649 { \
1650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1651 /* .name = "Capture Source", */ \
1652 .name = "Input Source", \
1653 .count = num, \
1654 .info = alc_mux_enum_info, \
1655 .get = alc_mux_enum_get, \
1656 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001657 }
1658
1659#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001660static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001661 _DEFINE_CAPMIX(num), \
1662 _DEFINE_CAPSRC(num), \
1663 { } /* end */ \
1664}
1665
1666#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001667static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001668 _DEFINE_CAPMIX(num), \
1669 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001670}
1671
1672/* up to three ADCs */
1673DEFINE_CAPMIX(1);
1674DEFINE_CAPMIX(2);
1675DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001676DEFINE_CAPMIX_NOSRC(1);
1677DEFINE_CAPMIX_NOSRC(2);
1678DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001679
1680/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001681 * Inverted digital-mic handling
1682 *
1683 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1684 * gives the additional mute only to the right channel of the digital mic
1685 * capture stream. This is a workaround for avoiding the almost silence
1686 * by summing the stereo stream from some (known to be ForteMedia)
1687 * digital mic unit.
1688 *
1689 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1690 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1691 * without caching so that the cache can still keep the original value.
1692 * The cached value is then restored when the flag is set off or any other
1693 * than d-mic is used as the current input source.
1694 */
1695static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1696{
1697 struct alc_spec *spec = codec->spec;
1698 int i;
1699
1700 if (!spec->inv_dmic_fixup)
1701 return;
1702 if (!spec->inv_dmic_muted && !force)
1703 return;
1704 for (i = 0; i < spec->num_adc_nids; i++) {
1705 int src = spec->dyn_adc_switch ? 0 : i;
1706 bool dmic_fixup = false;
1707 hda_nid_t nid;
1708 int parm, dir, v;
1709
1710 if (spec->inv_dmic_muted &&
1711 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1712 dmic_fixup = true;
1713 if (!dmic_fixup && !force)
1714 continue;
1715 if (spec->vol_in_capsrc) {
1716 nid = spec->capsrc_nids[i];
1717 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1718 dir = HDA_OUTPUT;
1719 } else {
1720 nid = spec->adc_nids[i];
1721 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1722 dir = HDA_INPUT;
1723 }
1724 /* we care only right channel */
1725 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1726 if (v & 0x80) /* if already muted, we don't need to touch */
1727 continue;
1728 if (dmic_fixup) /* add mute for d-mic */
1729 v |= 0x80;
1730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1731 parm | v);
1732 }
1733}
1734
1735static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1736 struct snd_ctl_elem_value *ucontrol)
1737{
1738 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1739 struct alc_spec *spec = codec->spec;
1740
1741 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1742 return 0;
1743}
1744
1745static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol)
1747{
1748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1749 struct alc_spec *spec = codec->spec;
1750 unsigned int val = !ucontrol->value.integer.value[0];
1751
1752 if (val == spec->inv_dmic_muted)
1753 return 0;
1754 spec->inv_dmic_muted = val;
1755 alc_inv_dmic_sync(codec, true);
1756 return 0;
1757}
1758
1759static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1761 .info = snd_ctl_boolean_mono_info,
1762 .get = alc_inv_dmic_sw_get,
1763 .put = alc_inv_dmic_sw_put,
1764};
1765
1766static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1767{
1768 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001769
1770 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1771 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001772 return -ENOMEM;
1773 spec->inv_dmic_fixup = 1;
1774 spec->inv_dmic_muted = 0;
1775 spec->inv_dmic_pin = nid;
1776 return 0;
1777}
1778
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001779/* typically the digital mic is put at node 0x12 */
1780static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1781 const struct alc_fixup *fix, int action)
1782{
1783 if (action == ALC_FIXUP_ACT_PROBE)
1784 alc_add_inv_dmic_mixer(codec, 0x12);
1785}
1786
Takashi Iwai125821a2012-06-22 14:30:29 +02001787/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001788 * virtual master controls
1789 */
1790
1791/*
1792 * slave controls for virtual master
1793 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001794static const char * const alc_slave_pfxs[] = {
1795 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001796 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001797 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001798 NULL,
1799};
1800
1801/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001802 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001804
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001805#define NID_MAPPING (-1)
1806
1807#define SUBDEV_SPEAKER_ (0 << 6)
1808#define SUBDEV_HP_ (1 << 6)
1809#define SUBDEV_LINE_ (2 << 6)
1810#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1811#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1812#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1813
Takashi Iwai603c4012008-07-30 15:01:44 +02001814static void alc_free_kctls(struct hda_codec *codec);
1815
Takashi Iwai67d634c2009-11-16 15:35:59 +01001816#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001817/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001818static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001819 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001820 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001821 { } /* end */
1822};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001823#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001824
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001825static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826{
1827 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001828 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001829 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001830 int i, j, err;
1831 unsigned int u;
1832 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834 for (i = 0; i < spec->num_mixers; i++) {
1835 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1836 if (err < 0)
1837 return err;
1838 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001839 if (spec->cap_mixer) {
1840 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1841 if (err < 0)
1842 return err;
1843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001845 err = snd_hda_create_dig_out_ctls(codec,
1846 spec->multiout.dig_out_nid,
1847 spec->multiout.dig_out_nid,
1848 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 if (err < 0)
1850 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001851 if (!spec->no_analog) {
1852 err = snd_hda_create_spdif_share_sw(codec,
1853 &spec->multiout);
1854 if (err < 0)
1855 return err;
1856 spec->multiout.share_spdif = 1;
1857 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 }
1859 if (spec->dig_in_nid) {
1860 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1861 if (err < 0)
1862 return err;
1863 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001864
Takashi Iwai67d634c2009-11-16 15:35:59 +01001865#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001866 /* create beep controls if needed */
1867 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001868 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001869 for (knew = alc_beep_mixer; knew->name; knew++) {
1870 struct snd_kcontrol *kctl;
1871 kctl = snd_ctl_new1(knew, codec);
1872 if (!kctl)
1873 return -ENOMEM;
1874 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001875 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001876 if (err < 0)
1877 return err;
1878 }
1879 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001880#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001881
Takashi Iwai2134ea42008-01-10 16:53:55 +01001882 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001883 if (!spec->no_analog &&
1884 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001885 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001886 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001887 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001888 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001889 vmaster_tlv, alc_slave_pfxs,
1890 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001891 if (err < 0)
1892 return err;
1893 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001894 if (!spec->no_analog &&
1895 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001896 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1897 NULL, alc_slave_pfxs,
1898 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001899 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001900 if (err < 0)
1901 return err;
1902 }
1903
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001904 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001905 if (spec->capsrc_nids || spec->adc_nids) {
1906 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1907 if (!kctl)
1908 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1909 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001910 err = snd_hda_add_nid(codec, kctl, i,
1911 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001912 if (err < 0)
1913 return err;
1914 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001915 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001916 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001917 const char *kname = kctl ? kctl->id.name : NULL;
1918 for (knew = spec->cap_mixer; knew->name; knew++) {
1919 if (kname && strcmp(knew->name, kname) == 0)
1920 continue;
1921 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1922 for (i = 0; kctl && i < kctl->count; i++) {
1923 err = snd_hda_add_nid(codec, kctl, i,
1924 spec->adc_nids[i]);
1925 if (err < 0)
1926 return err;
1927 }
1928 }
1929 }
1930
1931 /* other nid->control mapping */
1932 for (i = 0; i < spec->num_mixers; i++) {
1933 for (knew = spec->mixers[i]; knew->name; knew++) {
1934 if (knew->iface != NID_MAPPING)
1935 continue;
1936 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1937 if (kctl == NULL)
1938 continue;
1939 u = knew->subdevice;
1940 for (j = 0; j < 4; j++, u >>= 8) {
1941 nid = u & 0x3f;
1942 if (nid == 0)
1943 continue;
1944 switch (u & 0xc0) {
1945 case SUBDEV_SPEAKER_:
1946 nid = spec->autocfg.speaker_pins[nid];
1947 break;
1948 case SUBDEV_LINE_:
1949 nid = spec->autocfg.line_out_pins[nid];
1950 break;
1951 case SUBDEV_HP_:
1952 nid = spec->autocfg.hp_pins[nid];
1953 break;
1954 default:
1955 continue;
1956 }
1957 err = snd_hda_add_nid(codec, kctl, 0, nid);
1958 if (err < 0)
1959 return err;
1960 }
1961 u = knew->private_value;
1962 for (j = 0; j < 4; j++, u >>= 8) {
1963 nid = u & 0xff;
1964 if (nid == 0)
1965 continue;
1966 err = snd_hda_add_nid(codec, kctl, 0, nid);
1967 if (err < 0)
1968 return err;
1969 }
1970 }
1971 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001972
1973 alc_free_kctls(codec); /* no longer needed */
1974
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001975 return 0;
1976}
1977
David Henningsson5780b622012-06-27 18:45:45 +02001978static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001979{
1980 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001981
1982 if (spec->shared_mic_hp) {
1983 int err;
1984 int nid = spec->autocfg.inputs[1].pin;
1985 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1986 if (err < 0)
1987 return err;
1988 err = snd_hda_jack_detect_enable(codec, nid, 0);
1989 if (err < 0)
1990 return err;
1991 }
1992
1993 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1994}
1995
1996static int alc_build_controls(struct hda_codec *codec)
1997{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001998 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001999 if (err < 0)
2000 return err;
David Henningsson5780b622012-06-27 18:45:45 +02002001
2002 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002003 if (err < 0)
2004 return err;
2005 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2006 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007}
2008
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002009
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002011 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002012 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002013
Takashi Iwai584c0c42011-03-10 12:51:11 +01002014static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002015static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002016
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017static int alc_init(struct hda_codec *codec)
2018{
2019 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002020
Takashi Iwai546bb672012-03-07 08:37:19 +01002021 if (spec->init_hook)
2022 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002023
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002024 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002025 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002026
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002027 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002028 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002029 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002030
Takashi Iwai58701122011-01-13 15:41:45 +01002031 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2032
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002033 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 return 0;
2035}
2036
Takashi Iwai83012a72012-08-24 18:38:08 +02002037#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002038static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2039{
2040 struct alc_spec *spec = codec->spec;
2041 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2042}
2043#endif
2044
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045/*
2046 * Analog playback callbacks
2047 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002048static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002050 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051{
2052 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002053 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2054 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055}
2056
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002057static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 struct hda_codec *codec,
2059 unsigned int stream_tag,
2060 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002061 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062{
2063 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002064 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2065 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066}
2067
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002068static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002070 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071{
2072 struct alc_spec *spec = codec->spec;
2073 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2074}
2075
2076/*
2077 * Digital out
2078 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002079static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002081 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082{
2083 struct alc_spec *spec = codec->spec;
2084 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2085}
2086
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002087static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002088 struct hda_codec *codec,
2089 unsigned int stream_tag,
2090 unsigned int format,
2091 struct snd_pcm_substream *substream)
2092{
2093 struct alc_spec *spec = codec->spec;
2094 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2095 stream_tag, format, substream);
2096}
2097
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002098static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002099 struct hda_codec *codec,
2100 struct snd_pcm_substream *substream)
2101{
2102 struct alc_spec *spec = codec->spec;
2103 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2104}
2105
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002106static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002108 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109{
2110 struct alc_spec *spec = codec->spec;
2111 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2112}
2113
2114/*
2115 * Analog capture
2116 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002117static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 struct hda_codec *codec,
2119 unsigned int stream_tag,
2120 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002121 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
2123 struct alc_spec *spec = codec->spec;
2124
Takashi Iwai63300792008-01-24 15:31:36 +01002125 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 stream_tag, 0, format);
2127 return 0;
2128}
2129
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002130static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002132 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
2134 struct alc_spec *spec = codec->spec;
2135
Takashi Iwai888afa12008-03-18 09:57:50 +01002136 snd_hda_codec_cleanup_stream(codec,
2137 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 return 0;
2139}
2140
Takashi Iwai840b64c2010-07-13 22:49:01 +02002141/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002142static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002143 struct hda_codec *codec,
2144 unsigned int stream_tag,
2145 unsigned int format,
2146 struct snd_pcm_substream *substream)
2147{
2148 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002149 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002150 spec->cur_adc_stream_tag = stream_tag;
2151 spec->cur_adc_format = format;
2152 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2153 return 0;
2154}
2155
Takashi Iwai21268962011-07-07 15:01:13 +02002156static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002157 struct hda_codec *codec,
2158 struct snd_pcm_substream *substream)
2159{
2160 struct alc_spec *spec = codec->spec;
2161 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2162 spec->cur_adc = 0;
2163 return 0;
2164}
2165
Takashi Iwai21268962011-07-07 15:01:13 +02002166static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002167 .substreams = 1,
2168 .channels_min = 2,
2169 .channels_max = 2,
2170 .nid = 0, /* fill later */
2171 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002172 .prepare = dyn_adc_capture_pcm_prepare,
2173 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002174 },
2175};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
2177/*
2178 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002179static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 .substreams = 1,
2181 .channels_min = 2,
2182 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002183 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002185 .open = alc_playback_pcm_open,
2186 .prepare = alc_playback_pcm_prepare,
2187 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 },
2189};
2190
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002191static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002192 .substreams = 1,
2193 .channels_min = 2,
2194 .channels_max = 2,
2195 /* NID is set in alc_build_pcms */
2196};
2197
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002198static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002199 .substreams = 1,
2200 .channels_min = 2,
2201 .channels_max = 2,
2202 /* NID is set in alc_build_pcms */
2203};
2204
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002205static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002206 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 .channels_min = 2,
2208 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002209 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002211 .prepare = alc_alt_capture_pcm_prepare,
2212 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 },
2214};
2215
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002216static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 .substreams = 1,
2218 .channels_min = 2,
2219 .channels_max = 2,
2220 /* NID is set in alc_build_pcms */
2221 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002222 .open = alc_dig_playback_pcm_open,
2223 .close = alc_dig_playback_pcm_close,
2224 .prepare = alc_dig_playback_pcm_prepare,
2225 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 },
2227};
2228
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002229static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 .substreams = 1,
2231 .channels_min = 2,
2232 .channels_max = 2,
2233 /* NID is set in alc_build_pcms */
2234};
2235
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002236/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002237static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002238 .substreams = 0,
2239 .channels_min = 0,
2240 .channels_max = 0,
2241};
2242
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243static int alc_build_pcms(struct hda_codec *codec)
2244{
2245 struct alc_spec *spec = codec->spec;
2246 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002247 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002248 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 int i;
2250
2251 codec->num_pcms = 1;
2252 codec->pcm_info = info;
2253
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002254 if (spec->no_analog)
2255 goto skip_analog;
2256
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002257 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2258 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002260
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002261 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002262 p = spec->stream_analog_playback;
2263 if (!p)
2264 p = &alc_pcm_analog_playback;
2265 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002266 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002267 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2268 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002269 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2270 spec->autocfg.line_outs == 2)
2271 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2272 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002273 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002274 if (spec->adc_nids) {
2275 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002276 if (!p) {
2277 if (spec->dyn_adc_switch)
2278 p = &dyn_adc_pcm_analog_capture;
2279 else
2280 p = &alc_pcm_analog_capture;
2281 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002282 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002283 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
Takashi Iwai4a471b72005-12-07 13:56:29 +01002286 if (spec->channel_mode) {
2287 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2288 for (i = 0; i < spec->num_channel_mode; i++) {
2289 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 }
2293 }
2294
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002295 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002296 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002298 snprintf(spec->stream_name_digital,
2299 sizeof(spec->stream_name_digital),
2300 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002301 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002302 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002303 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002305 if (spec->dig_out_type)
2306 info->pcm_type = spec->dig_out_type;
2307 else
2308 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002309 if (spec->multiout.dig_out_nid) {
2310 p = spec->stream_digital_playback;
2311 if (!p)
2312 p = &alc_pcm_digital_playback;
2313 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2315 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002316 if (spec->dig_in_nid) {
2317 p = spec->stream_digital_capture;
2318 if (!p)
2319 p = &alc_pcm_digital_capture;
2320 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2322 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002323 /* FIXME: do we need this for all Realtek codec models? */
2324 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 }
2326
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002327 if (spec->no_analog)
2328 return 0;
2329
Takashi Iwaie08a0072006-09-07 17:52:14 +02002330 /* If the use of more than one ADC is requested for the current
2331 * model, configure a second analog capture-only PCM.
2332 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002333 have_multi_adcs = (spec->num_adc_nids > 1) &&
2334 !spec->dyn_adc_switch && !spec->auto_mic &&
2335 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002336 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002337 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002338 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002339 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002340 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002341 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002342 p = spec->stream_analog_alt_playback;
2343 if (!p)
2344 p = &alc_pcm_analog_alt_playback;
2345 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002346 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2347 spec->alt_dac_nid;
2348 } else {
2349 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2350 alc_pcm_null_stream;
2351 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2352 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002353 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002354 p = spec->stream_analog_alt_capture;
2355 if (!p)
2356 p = &alc_pcm_analog_alt_capture;
2357 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002358 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2359 spec->adc_nids[1];
2360 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2361 spec->num_adc_nids - 1;
2362 } else {
2363 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2364 alc_pcm_null_stream;
2365 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002366 }
2367 }
2368
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 return 0;
2370}
2371
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002372static inline void alc_shutup(struct hda_codec *codec)
2373{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002374 struct alc_spec *spec = codec->spec;
2375
2376 if (spec && spec->shutup)
2377 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002378 snd_hda_shutup_pins(codec);
2379}
2380
Takashi Iwai603c4012008-07-30 15:01:44 +02002381static void alc_free_kctls(struct hda_codec *codec)
2382{
2383 struct alc_spec *spec = codec->spec;
2384
2385 if (spec->kctls.list) {
2386 struct snd_kcontrol_new *kctl = spec->kctls.list;
2387 int i;
2388 for (i = 0; i < spec->kctls.used; i++)
2389 kfree(kctl[i].name);
2390 }
2391 snd_array_free(&spec->kctls);
2392}
2393
Takashi Iwai23c09b02011-08-19 09:05:35 +02002394static void alc_free_bind_ctls(struct hda_codec *codec)
2395{
2396 struct alc_spec *spec = codec->spec;
2397 if (spec->bind_ctls.list) {
2398 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2399 int i;
2400 for (i = 0; i < spec->bind_ctls.used; i++)
2401 kfree(ctl[i]);
2402 }
2403 snd_array_free(&spec->bind_ctls);
2404}
2405
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406static void alc_free(struct hda_codec *codec)
2407{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002408 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002409
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002410 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002411 return;
2412
Takashi Iwai603c4012008-07-30 15:01:44 +02002413 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002414 alc_free_bind_ctls(codec);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002415 snd_array_free(&spec->out_path);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002416 snd_array_free(&spec->in_path);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002417 snd_array_free(&spec->loopback_path);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002418 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002419 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002420 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421}
2422
Takashi Iwai83012a72012-08-24 18:38:08 +02002423#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002424static void alc_power_eapd(struct hda_codec *codec)
2425{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002426 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002427}
2428
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002429static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002430{
2431 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002432 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002433 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002434 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002435 return 0;
2436}
2437#endif
2438
Takashi Iwai2a439522011-07-26 09:52:50 +02002439#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002440static int alc_resume(struct hda_codec *codec)
2441{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002442 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002443 codec->patch_ops.init(codec);
2444 snd_hda_codec_resume_amp(codec);
2445 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002446 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002447 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002448 return 0;
2449}
Takashi Iwaie044c392008-10-27 16:56:24 +01002450#endif
2451
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452/*
2453 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002454static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 .build_controls = alc_build_controls,
2456 .build_pcms = alc_build_pcms,
2457 .init = alc_init,
2458 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002459 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002460#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002461 .resume = alc_resume,
2462#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002463#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002464 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002465 .check_power_status = alc_check_power_status,
2466#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002467 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468};
2469
David Henningsson29adc4b2012-09-25 11:31:00 +02002470
Kailang Yangc027ddc2010-03-19 11:33:06 +01002471/* replace the codec chip_name with the given string */
2472static int alc_codec_rename(struct hda_codec *codec, const char *name)
2473{
2474 kfree(codec->chip_name);
2475 codec->chip_name = kstrdup(name, GFP_KERNEL);
2476 if (!codec->chip_name) {
2477 alc_free(codec);
2478 return -ENOMEM;
2479 }
2480 return 0;
2481}
2482
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002483/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002484 * Rename codecs appropriately from COEF value
2485 */
2486struct alc_codec_rename_table {
2487 unsigned int vendor_id;
2488 unsigned short coef_mask;
2489 unsigned short coef_bits;
2490 const char *name;
2491};
2492
2493static struct alc_codec_rename_table rename_tbl[] = {
2494 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2495 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2496 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2497 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2498 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2499 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2500 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002501 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002502 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2503 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2504 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2505 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2506 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2507 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2508 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2509 { } /* terminator */
2510};
2511
2512static int alc_codec_rename_from_preset(struct hda_codec *codec)
2513{
2514 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002515
2516 for (p = rename_tbl; p->vendor_id; p++) {
2517 if (p->vendor_id != codec->vendor_id)
2518 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002519 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002520 return alc_codec_rename(codec, p->name);
2521 }
2522 return 0;
2523}
2524
2525/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002526 * Automatic parse of I/O pins from the BIOS configuration
2527 */
2528
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002529enum {
2530 ALC_CTL_WIDGET_VOL,
2531 ALC_CTL_WIDGET_MUTE,
2532 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002533 ALC_CTL_BIND_VOL,
2534 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002535};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002536static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002537 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2538 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002539 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002540 HDA_BIND_VOL(NULL, 0),
2541 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002542};
2543
2544/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002545static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002546 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002547{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002548 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002549
Takashi Iwai668d1e92012-11-29 14:10:17 +01002550 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002551 if (!knew)
2552 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002553 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002554 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002555 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002556 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002557 return 0;
2558}
2559
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002560static int add_control_with_pfx(struct alc_spec *spec, int type,
2561 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002562 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002563{
2564 char name[32];
2565 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002566 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002567}
2568
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002569#define add_pb_vol_ctrl(spec, type, pfx, val) \
2570 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2571#define add_pb_sw_ctrl(spec, type, pfx, val) \
2572 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2573#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2574 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2575#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2576 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002577
Takashi Iwai23c09b02011-08-19 09:05:35 +02002578static const char * const channel_name[4] = {
2579 "Front", "Surround", "CLFE", "Side"
2580};
2581
Takashi Iwai6843ca12011-06-24 11:03:58 +02002582static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2583 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002584{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002585 struct auto_pin_cfg *cfg = &spec->autocfg;
2586
Takashi Iwai6843ca12011-06-24 11:03:58 +02002587 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002588 if (cfg->line_outs == 1 && !spec->multi_ios &&
2589 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002590 return "Master";
2591
2592 switch (cfg->line_out_type) {
2593 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002594 if (cfg->line_outs == 1)
2595 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002596 if (cfg->line_outs == 2)
2597 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002598 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002599 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002600 /* for multi-io case, only the primary out */
2601 if (ch && spec->multi_ios)
2602 break;
2603 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002604 return "Headphone";
2605 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002606 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002607 return "PCM";
2608 break;
2609 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002610 if (ch >= ARRAY_SIZE(channel_name)) {
2611 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002612 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002613 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002614
2615 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002616}
2617
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002618static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2619 hda_nid_t to_nid, int with_aa_mix,
2620 struct nid_path *path);
2621
Takashi Iwai83012a72012-08-24 18:38:08 +02002622#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002623/* add the powersave loopback-list entry */
2624static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2625{
2626 struct hda_amp_list *list;
2627
2628 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2629 return;
2630 list = spec->loopback_list + spec->num_loopbacks;
2631 list->nid = mix;
2632 list->dir = HDA_INPUT;
2633 list->idx = idx;
2634 spec->num_loopbacks++;
2635 spec->loopback.amplist = spec->loopback_list;
2636}
2637#else
2638#define add_loopback_list(spec, mix, idx) /* NOP */
2639#endif
2640
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002641/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002642static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002643 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002644 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002645{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002646 struct alc_spec *spec = codec->spec;
2647 struct nid_path *path;
2648 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002649
Takashi Iwaibd32f782012-12-12 18:08:52 +01002650 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2651 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2652 return 0; /* no need for analog loopback */
2653
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002654 path = snd_array_new(&spec->loopback_path);
2655 if (!path)
2656 return -ENOMEM;
2657 memset(path, 0, sizeof(*path));
2658 if (!parse_nid_path(codec, pin, mix_nid, 2, path))
2659 return -EINVAL;
2660
2661 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002662 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
2663 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002664 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002665 if (err < 0)
2666 return err;
2667 }
2668
2669 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
2670 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002671 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002672 if (err < 0)
2673 return err;
2674 }
2675
Takashi Iwai164f73e2012-02-21 11:27:09 +01002676 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002677 return 0;
2678}
2679
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002680static int new_capture_source(struct hda_codec *codec, int adc_idx,
2681 hda_nid_t pin, int idx, const char *label)
2682{
2683 struct alc_spec *spec = codec->spec;
2684 struct hda_input_mux *imux = &spec->private_imux[0];
2685 struct nid_path *path;
2686
2687 path = snd_array_new(&spec->in_path);
2688 if (!path)
2689 return -ENOMEM;
2690 memset(path, 0, sizeof(*path));
2691 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2692 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2693 pin, spec->adc_nids[adc_idx]);
2694 return -EINVAL;
2695 }
2696
2697 spec->imux_pins[imux->num_items] = pin;
2698 snd_hda_add_imux_item(imux, label, idx, NULL);
2699 return 0;
2700}
2701
Takashi Iwai05f5f472009-08-25 13:10:18 +02002702static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002703{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002704 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2705 return (pincap & AC_PINCAP_IN) != 0;
2706}
2707
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002708/* check whether the given two widgets can be connected */
2709static bool is_reachable_path(struct hda_codec *codec,
2710 hda_nid_t from_nid, hda_nid_t to_nid)
2711{
2712 if (!from_nid || !to_nid)
2713 return false;
2714 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2715}
2716
Takashi Iwai1d045db2011-07-07 18:23:21 +02002717/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002718static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002719{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002720 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002721 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002722 hda_nid_t *adc_nids = spec->private_adc_nids;
2723 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2724 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002725 int i, nums = 0;
2726
2727 nid = codec->start_nid;
2728 for (i = 0; i < codec->num_nodes; i++, nid++) {
2729 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002730 unsigned int caps = get_wcaps(codec, nid);
2731 int type = get_wcaps_type(caps);
2732
2733 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2734 continue;
2735 adc_nids[nums] = nid;
2736 cap_nids[nums] = nid;
2737 src = nid;
2738 for (;;) {
2739 int n;
2740 type = get_wcaps_type(get_wcaps(codec, src));
2741 if (type == AC_WID_PIN)
2742 break;
2743 if (type == AC_WID_AUD_SEL) {
2744 cap_nids[nums] = src;
2745 break;
2746 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002747 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002748 if (n > 1) {
2749 cap_nids[nums] = src;
2750 break;
2751 } else if (n != 1)
2752 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002753 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2754 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002755 }
2756 if (++nums >= max_nums)
2757 break;
2758 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002759 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002760 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002761 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002762 return nums;
2763}
2764
Takashi Iwai05f5f472009-08-25 13:10:18 +02002765/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002766static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002767{
2768 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002769 const struct auto_pin_cfg *cfg = &spec->autocfg;
2770 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002771 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002772 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002773 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002774 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002775
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002776 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002777 if (num_adcs < 0)
2778 return 0;
2779
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002780 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002781 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002782 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002783
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002784 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002785 if (!alc_is_input_pin(codec, pin))
2786 continue;
2787
David Henningsson5322bf22011-01-05 11:03:56 +01002788 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002789 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2790 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002791 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002792 type_idx++;
2793 else
2794 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002795 prev_label = label;
2796
Takashi Iwai05f5f472009-08-25 13:10:18 +02002797 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002798 if (is_reachable_path(codec, pin, mixer)) {
2799 err = new_analog_input(codec, pin,
2800 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002801 if (err < 0)
2802 return err;
2803 }
2804 }
2805
Takashi Iwaib7821702011-07-06 15:12:46 +02002806 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002807 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002808 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002809 if (idx >= 0) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002810 err = new_capture_source(codec, c, pin, idx, label);
2811 if (err < 0)
2812 return err;
Takashi Iwaib7821702011-07-06 15:12:46 +02002813 break;
2814 }
2815 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002816 }
Takashi Iwai21268962011-07-07 15:01:13 +02002817
2818 spec->num_mux_defs = 1;
2819 spec->input_mux = imux;
2820
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002821 return 0;
2822}
2823
Takashi Iwai24de1832011-11-07 17:13:39 +01002824/* create a shared input with the headphone out */
2825static int alc_auto_create_shared_input(struct hda_codec *codec)
2826{
2827 struct alc_spec *spec = codec->spec;
2828 struct auto_pin_cfg *cfg = &spec->autocfg;
2829 unsigned int defcfg;
2830 hda_nid_t nid;
2831
2832 /* only one internal input pin? */
2833 if (cfg->num_inputs != 1)
2834 return 0;
2835 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2836 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2837 return 0;
2838
2839 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2840 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2841 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2842 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2843 else
2844 return 0; /* both not available */
2845
2846 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2847 return 0; /* no input */
2848
2849 cfg->inputs[1].pin = nid;
2850 cfg->inputs[1].type = AUTO_PIN_MIC;
2851 cfg->num_inputs = 2;
2852 spec->shared_mic_hp = 1;
2853 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2854 return 0;
2855}
2856
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002857static int get_pin_type(int line_out_type)
2858{
2859 if (line_out_type == AUTO_PIN_HP_OUT)
2860 return PIN_HP;
2861 else
2862 return PIN_OUT;
2863}
2864
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002865static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002866{
2867 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002868 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002869 int i;
2870
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002871 for (i = 0; i < cfg->num_inputs; i++) {
2872 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002873 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002874 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002875 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002876 snd_hda_codec_write(codec, nid, 0,
2877 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002878 AMP_OUT_MUTE);
2879 }
2880 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002881
2882 /* mute all loopback inputs */
2883 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002884 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002885 for (i = 0; i < nums; i++)
2886 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2887 AC_VERB_SET_AMP_GAIN_MUTE,
2888 AMP_IN_MUTE(i));
2889 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002890}
2891
Takashi Iwai185d99f2012-02-16 18:39:45 +01002892static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2893{
2894 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002895 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002896
2897 for (i = 0; i < spec->out_path.used; i++) {
2898 struct nid_path *path = snd_array_elem(&spec->out_path, i);
2899 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002900 return true;
2901 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002902 return false;
2903}
2904
Takashi Iwai07b18f62011-11-10 15:42:54 +01002905/* check whether the DAC is reachable from the pin */
2906static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2907 hda_nid_t pin, hda_nid_t dac)
2908{
Takashi Iwaidc31b582012-02-17 17:27:53 +01002909 if (!pin || !dac)
2910 return false;
Takashi Iwai6a84c302012-12-05 14:08:45 +01002911 return snd_hda_get_conn_index(codec, pin, dac, true) >= 0;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002912}
2913
Takashi Iwai463419d2012-12-05 14:17:37 +01002914/* look for an empty DAC slot */
2915static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2916{
2917 struct alc_spec *spec = codec->spec;
2918 int i;
2919
2920 for (i = 0; i < spec->num_all_dacs; i++) {
2921 hda_nid_t nid = spec->all_dacs[i];
2922 if (!nid || alc_is_dac_already_used(codec, nid))
2923 continue;
2924 if (alc_auto_is_dac_reachable(codec, pin, nid))
2925 return nid;
2926 }
2927 return 0;
2928}
2929
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002930/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002931static bool __parse_nid_path(struct hda_codec *codec,
2932 hda_nid_t from_nid, hda_nid_t to_nid,
2933 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002934{
2935 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002936 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002937 int i, nums;
2938
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002939 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002940 if (!with_aa_mix)
2941 return false;
2942 with_aa_mix = 2; /* mark aa-mix is included */
2943 }
2944
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002945 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002946 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002947 if (conn[i] != from_nid) {
2948 /* special case: when from_nid is 0,
2949 * try to find an empty DAC
2950 */
2951 if (from_nid ||
2952 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2953 alc_is_dac_already_used(codec, conn[i]))
2954 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002955 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002956 /* aa-mix is requested but not included? */
2957 if (!(spec->mixer_nid && with_aa_mix == 1))
2958 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002959 }
2960 if (depth >= MAX_NID_PATH_DEPTH)
2961 return false;
2962 for (i = 0; i < nums; i++) {
2963 unsigned int type;
2964 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002965 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2966 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002967 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002968 if (__parse_nid_path(codec, from_nid, conn[i],
2969 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002970 goto found;
2971 }
2972 return false;
2973
2974 found:
2975 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002976 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002977 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002978 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002979 path->depth++;
2980 return true;
2981}
2982
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002983/* parse the widget path from the given nid to the target nid;
2984 * when @from_nid is 0, try to find an empty DAC;
2985 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2986 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2987 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002988 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002989static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2990 hda_nid_t to_nid, int with_aa_mix,
2991 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002992{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002993 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2994 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002995 path->depth++;
2996#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002997 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002998 path->depth, path->path[0], path->path[1],
2999 path->path[2], path->path[3], path->path[4]);
3000#endif
3001 return true;
3002 }
3003 return false;
3004}
3005
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003006static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3007{
Takashi Iwai140547e2012-02-16 17:23:46 +01003008 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01003009 int i;
3010 hda_nid_t nid_found = 0;
3011
3012 for (i = 0; i < spec->num_all_dacs; i++) {
3013 hda_nid_t nid = spec->all_dacs[i];
3014 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003015 continue;
Takashi Iwai463419d2012-12-05 14:17:37 +01003016 if (alc_auto_is_dac_reachable(codec, pin, nid)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003017 if (nid_found)
3018 return 0;
3019 nid_found = nid;
3020 }
3021 }
3022 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003023}
3024
Takashi Iwaiba8111272012-12-06 18:06:23 +01003025static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003026{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003027 struct alc_spec *spec = codec->spec;
3028 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003029
Takashi Iwaiba8111272012-12-06 18:06:23 +01003030 for (i = 0; i < spec->out_path.used; i++) {
3031 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3032 if (path->ctls[type] == val)
3033 return true;
3034 }
3035 return false;
3036}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003037
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003038/* badness definition */
3039enum {
3040 /* No primary DAC is found for the main output */
3041 BAD_NO_PRIMARY_DAC = 0x10000,
3042 /* No DAC is found for the extra output */
3043 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003044 /* No possible multi-ios */
3045 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003046 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003047 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003048 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003049 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003050 /* Primary DAC shared with main surrounds */
3051 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003052 /* Primary DAC shared with main CLFE */
3053 BAD_SHARED_CLFE = 0x10,
3054 /* Primary DAC shared with extra surrounds */
3055 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003056 /* Volume widget is shared */
3057 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003058};
3059
3060static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003061 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003062static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003063 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003064
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003065static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3066 hda_nid_t dac)
3067{
3068 struct alc_spec *spec = codec->spec;
3069 struct nid_path *path;
3070
3071 path = snd_array_new(&spec->out_path);
3072 if (!path)
3073 return false;
3074 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003075 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003076 return true;
3077 /* push back */
3078 spec->out_path.used--;
3079 return false;
3080}
3081
Takashi Iwaiba8111272012-12-06 18:06:23 +01003082/* get the path pointing from the given dac to pin;
3083 * passing 0 to either @pin or @dac behaves as a wildcard
3084 */
3085static struct nid_path *get_out_path(struct hda_codec *codec, hda_nid_t pin,
3086 hda_nid_t dac)
3087{
3088 struct alc_spec *spec = codec->spec;
3089 int i;
3090
3091 for (i = 0; i < spec->out_path.used; i++) {
3092 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3093 if (path->depth <= 0)
3094 continue;
3095 if ((!dac || path->path[0] == dac) &&
3096 (!pin || path->path[path->depth - 1] == pin))
3097 return path;
3098 }
3099 return NULL;
3100}
3101
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003102/* look for widgets in the path between the given NIDs appropriate for
3103 * volume and mute controls, and assign the values to ctls[].
3104 *
3105 * When no appropriate widget is found in the path, the badness value
3106 * is incremented depending on the situation. The function returns the
3107 * total badness for both volume and mute controls.
3108 */
3109static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3110 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003111{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003112 struct nid_path *path = get_out_path(codec, pin, dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003113 hda_nid_t nid;
3114 unsigned int val;
3115 int badness = 0;
3116
Takashi Iwaiba8111272012-12-06 18:06:23 +01003117 if (!path)
3118 return BAD_SHARED_VOL * 2;
3119 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003120 if (nid) {
3121 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003122 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003123 badness += BAD_SHARED_VOL;
3124 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003125 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003126 } else
3127 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003128 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003129 if (nid) {
3130 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003131 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3132 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003133 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3134 else
3135 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003136 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003137 badness += BAD_SHARED_VOL;
3138 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003139 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003140 } else
3141 badness += BAD_SHARED_VOL;
3142 return badness;
3143}
3144
Takashi Iwaidc31b582012-02-17 17:27:53 +01003145struct badness_table {
3146 int no_primary_dac; /* no primary DAC */
3147 int no_dac; /* no secondary DACs */
3148 int shared_primary; /* primary DAC is shared with main output */
3149 int shared_surr; /* secondary DAC shared with main or primary */
3150 int shared_clfe; /* third DAC shared with main or primary */
3151 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3152};
3153
3154static struct badness_table main_out_badness = {
3155 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3156 .no_dac = BAD_NO_DAC,
3157 .shared_primary = BAD_NO_PRIMARY_DAC,
3158 .shared_surr = BAD_SHARED_SURROUND,
3159 .shared_clfe = BAD_SHARED_CLFE,
3160 .shared_surr_main = BAD_SHARED_SURROUND,
3161};
3162
3163static struct badness_table extra_out_badness = {
3164 .no_primary_dac = BAD_NO_DAC,
3165 .no_dac = BAD_NO_DAC,
3166 .shared_primary = BAD_NO_EXTRA_DAC,
3167 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3168 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3169 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3170};
3171
3172/* try to assign DACs to pins and return the resultant badness */
3173static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3174 const hda_nid_t *pins, hda_nid_t *dacs,
3175 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003176{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003177 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003178 struct auto_pin_cfg *cfg = &spec->autocfg;
3179 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003180 int badness = 0;
3181 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003182
Takashi Iwai185d99f2012-02-16 18:39:45 +01003183 if (!num_outs)
3184 return 0;
3185
Takashi Iwaidc31b582012-02-17 17:27:53 +01003186 for (i = 0; i < num_outs; i++) {
3187 hda_nid_t pin = pins[i];
3188 if (!dacs[i])
3189 dacs[i] = alc_auto_look_for_dac(codec, pin);
3190 if (!dacs[i] && !i) {
3191 for (j = 1; j < num_outs; j++) {
3192 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3193 dacs[0] = dacs[j];
3194 dacs[j] = 0;
3195 break;
3196 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003197 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003198 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003199 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003200 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003201 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003202 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003203 else if (cfg->line_outs > i &&
3204 alc_auto_is_dac_reachable(codec, pin,
3205 spec->private_dac_nids[i]))
3206 dac = spec->private_dac_nids[i];
3207 if (dac) {
3208 if (!i)
3209 badness += bad->shared_primary;
3210 else if (i == 1)
3211 badness += bad->shared_surr;
3212 else
3213 badness += bad->shared_clfe;
3214 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003215 spec->private_dac_nids[0])) {
3216 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003217 badness += bad->shared_surr_main;
3218 } else if (!i)
3219 badness += bad->no_primary_dac;
3220 else
3221 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003222 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003223 if (!add_new_out_path(codec, pin, dac))
3224 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003225 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003226 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003227 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003228
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003229 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003230}
3231
3232static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003233 hda_nid_t reference_pin,
3234 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003235
Takashi Iwai185d99f2012-02-16 18:39:45 +01003236static bool alc_map_singles(struct hda_codec *codec, int outs,
3237 const hda_nid_t *pins, hda_nid_t *dacs)
3238{
3239 int i;
3240 bool found = false;
3241 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003242 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003243 if (dacs[i])
3244 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003245 dac = get_dac_if_single(codec, pins[i]);
3246 if (!dac)
3247 continue;
3248 if (add_new_out_path(codec, pins[i], dac)) {
3249 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003250 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003251 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003252 }
3253 return found;
3254}
3255
Takashi Iwai7085ec12009-10-02 09:03:58 +02003256/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003257static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003258 bool fill_hardwired,
3259 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003260{
3261 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003262 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003263 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003264
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003265 /* set num_dacs once to full for alc_auto_look_for_dac() */
3266 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003267 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003268 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3269 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3270 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003271 spec->multi_ios = 0;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003272 snd_array_free(&spec->out_path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003273 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003274
3275 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003276 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003277 bool mapped;
3278 do {
3279 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003280 cfg->line_out_pins,
3281 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003282 mapped |= alc_map_singles(codec, cfg->hp_outs,
3283 cfg->hp_pins,
3284 spec->multiout.hp_out_nid);
3285 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3286 cfg->speaker_pins,
3287 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003288 if (fill_mio_first && cfg->line_outs == 1 &&
3289 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3290 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3291 if (!err)
3292 mapped = true;
3293 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003294 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003295 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003296
Takashi Iwaidc31b582012-02-17 17:27:53 +01003297 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3298 spec->private_dac_nids,
3299 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003300
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003301 /* re-count num_dacs and squash invalid entries */
3302 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003303 for (i = 0; i < cfg->line_outs; i++) {
3304 if (spec->private_dac_nids[i])
3305 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003306 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003307 memmove(spec->private_dac_nids + i,
3308 spec->private_dac_nids + i + 1,
3309 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003310 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3311 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003312 }
3313
Takashi Iwai276dd702012-02-17 16:17:03 +01003314 if (fill_mio_first &&
3315 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003316 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003317 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003318 if (err < 0)
3319 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003320 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003321 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003322
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003323 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003324 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3325 spec->multiout.hp_out_nid,
3326 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003327 if (err < 0)
3328 return err;
3329 badness += err;
3330 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003331 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003332 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3333 cfg->speaker_pins,
3334 spec->multiout.extra_out_nid,
3335 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003336 if (err < 0)
3337 return err;
3338 badness += err;
3339 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003340 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3341 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003342 if (err < 0)
3343 return err;
3344 badness += err;
3345 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003346 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3347 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003348 int offset = 0;
3349 if (cfg->line_outs >= 3)
3350 offset = 1;
3351 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3352 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003353 if (err < 0)
3354 return err;
3355 badness += err;
3356 }
3357
3358 if (spec->multi_ios == 2) {
3359 for (i = 0; i < 2; i++)
3360 spec->private_dac_nids[spec->multiout.num_dacs++] =
3361 spec->multi_io[i].dac;
3362 spec->ext_channel_count = 2;
3363 } else if (spec->multi_ios) {
3364 spec->multi_ios = 0;
3365 badness += BAD_MULTI_IO;
3366 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003367
3368 return badness;
3369}
3370
3371#define DEBUG_BADNESS
3372
3373#ifdef DEBUG_BADNESS
3374#define debug_badness snd_printdd
3375#else
3376#define debug_badness(...)
3377#endif
3378
3379static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3380{
3381 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3382 cfg->line_out_pins[0], cfg->line_out_pins[1],
3383 cfg->line_out_pins[2], cfg->line_out_pins[2],
3384 spec->multiout.dac_nids[0],
3385 spec->multiout.dac_nids[1],
3386 spec->multiout.dac_nids[2],
3387 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003388 if (spec->multi_ios > 0)
3389 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3390 spec->multi_ios,
3391 spec->multi_io[0].pin, spec->multi_io[1].pin,
3392 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003393 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3394 cfg->hp_pins[0], cfg->hp_pins[1],
3395 cfg->hp_pins[2], cfg->hp_pins[2],
3396 spec->multiout.hp_out_nid[0],
3397 spec->multiout.hp_out_nid[1],
3398 spec->multiout.hp_out_nid[2],
3399 spec->multiout.hp_out_nid[3]);
3400 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3401 cfg->speaker_pins[0], cfg->speaker_pins[1],
3402 cfg->speaker_pins[2], cfg->speaker_pins[3],
3403 spec->multiout.extra_out_nid[0],
3404 spec->multiout.extra_out_nid[1],
3405 spec->multiout.extra_out_nid[2],
3406 spec->multiout.extra_out_nid[3]);
3407}
3408
Takashi Iwai463419d2012-12-05 14:17:37 +01003409/* find all available DACs of the codec */
3410static void alc_fill_all_nids(struct hda_codec *codec)
3411{
3412 struct alc_spec *spec = codec->spec;
3413 int i;
3414 hda_nid_t nid = codec->start_nid;
3415
3416 spec->num_all_dacs = 0;
3417 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3418 for (i = 0; i < codec->num_nodes; i++, nid++) {
3419 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3420 continue;
3421 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3422 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3423 break;
3424 }
3425 spec->all_dacs[spec->num_all_dacs++] = nid;
3426 }
3427}
3428
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003429static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3430{
3431 struct alc_spec *spec = codec->spec;
3432 struct auto_pin_cfg *cfg = &spec->autocfg;
3433 struct auto_pin_cfg *best_cfg;
3434 int best_badness = INT_MAX;
3435 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003436 bool fill_hardwired = true, fill_mio_first = true;
3437 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003438 bool hp_spk_swapped = false;
3439
Takashi Iwai463419d2012-12-05 14:17:37 +01003440 alc_fill_all_nids(codec);
3441
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003442 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3443 if (!best_cfg)
3444 return -ENOMEM;
3445 *best_cfg = *cfg;
3446
3447 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003448 badness = fill_and_eval_dacs(codec, fill_hardwired,
3449 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003450 if (badness < 0) {
3451 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003452 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003453 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003454 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3455 cfg->line_out_type, fill_hardwired, fill_mio_first,
3456 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003457 debug_show_configs(spec, cfg);
3458 if (badness < best_badness) {
3459 best_badness = badness;
3460 *best_cfg = *cfg;
3461 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003462 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003463 }
3464 if (!badness)
3465 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003466 fill_mio_first = !fill_mio_first;
3467 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003468 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003469 fill_hardwired = !fill_hardwired;
3470 if (!fill_hardwired)
3471 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003472 if (hp_spk_swapped)
3473 break;
3474 hp_spk_swapped = true;
3475 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003476 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3477 cfg->hp_outs = cfg->line_outs;
3478 memcpy(cfg->hp_pins, cfg->line_out_pins,
3479 sizeof(cfg->hp_pins));
3480 cfg->line_outs = cfg->speaker_outs;
3481 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3482 sizeof(cfg->speaker_pins));
3483 cfg->speaker_outs = 0;
3484 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3485 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003486 fill_hardwired = true;
3487 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003488 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003489 if (cfg->hp_outs > 0 &&
3490 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3491 cfg->speaker_outs = cfg->line_outs;
3492 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3493 sizeof(cfg->speaker_pins));
3494 cfg->line_outs = cfg->hp_outs;
3495 memcpy(cfg->line_out_pins, cfg->hp_pins,
3496 sizeof(cfg->hp_pins));
3497 cfg->hp_outs = 0;
3498 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3499 cfg->line_out_type = AUTO_PIN_HP_OUT;
3500 fill_hardwired = true;
3501 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003502 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003503 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003504 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003505
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003506 if (badness) {
3507 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003508 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003509 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003510 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3511 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003512 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003513
Takashi Iwaiba8111272012-12-06 18:06:23 +01003514 if (cfg->line_out_pins[0]) {
3515 struct nid_path *path = get_out_path(codec,
3516 cfg->line_out_pins[0],
3517 spec->multiout.dac_nids[0]);
3518 if (path)
3519 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3520 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003521
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003522 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003523 return 0;
3524}
3525
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003526/* replace the channels in the composed amp value with the given number */
3527static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3528{
3529 val &= ~(0x3U << 16);
3530 val |= chs << 16;
3531 return val;
3532}
3533
Takashi Iwai343a04b2011-07-06 14:28:39 +02003534static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003535 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003536 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003537 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003538{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003539 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003540 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003541 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003542 val = path->ctls[NID_PATH_VOL_CTL];
3543 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003544 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003545 val = amp_val_replace_channels(val, chs);
3546 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3547}
3548
3549/* return the channel bits suitable for the given path->ctls[] */
3550static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3551 int type)
3552{
3553 int chs = 1; /* mono (left only) */
3554 if (path) {
3555 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3556 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3557 chs = 3; /* stereo */
3558 }
3559 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003560}
3561
Takashi Iwaie29d3772011-11-14 17:13:23 +01003562static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3563 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003564 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003565{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003566 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3567 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003568}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003569
3570/* create a mute-switch for the given mixer widget;
3571 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3572 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003573static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003574 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003575 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003576 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003577{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003578 unsigned int val;
3579 int type = ALC_CTL_WIDGET_MUTE;
3580
3581 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003582 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003583 val = path->ctls[NID_PATH_MUTE_CTL];
3584 if (!val)
3585 return 0;
3586 val = amp_val_replace_channels(val, chs);
3587 if (get_amp_direction_(val) == HDA_INPUT) {
3588 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003589 int nums = snd_hda_get_num_conns(codec, nid);
3590 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003591 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003592 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003593 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003594 }
3595 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003596}
3597
Takashi Iwaie29d3772011-11-14 17:13:23 +01003598static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003599 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003600{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003601 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3602 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003603}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003604
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003605static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003606 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003607{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003608 int i;
3609
3610 for (i = path->depth - 1; i >= 0; i--) {
3611 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3612 return path->path[i];
3613 if (i != path->depth - 1 && i != 0 &&
3614 nid_has_mute(codec, path->path[i], HDA_INPUT))
3615 return path->path[i];
3616 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003617 return 0;
3618}
3619
3620static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003621 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003622{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003623 int i;
3624
3625 for (i = path->depth - 1; i >= 0; i--) {
3626 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3627 return path->path[i];
3628 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003629 return 0;
3630}
3631
Takashi Iwai7085ec12009-10-02 09:03:58 +02003632/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003633static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003634 const struct auto_pin_cfg *cfg)
3635{
3636 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003637 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003638
Takashi Iwaice764ab2011-04-27 16:35:23 +02003639 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003640 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003641 noutputs += spec->multi_ios;
3642
3643 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003644 const char *name;
3645 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003646 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003647 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003648
3649 dac = spec->multiout.dac_nids[i];
3650 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003651 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003652 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003653 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003654 index = 0;
3655 name = channel_name[i];
3656 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003657 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003658 name = alc_get_line_out_pfx(spec, i, true, &index);
3659 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003660
Takashi Iwaiba8111272012-12-06 18:06:23 +01003661 path = get_out_path(codec, pin, dac);
3662 if (!path)
3663 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003664 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003665 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003666 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003667 if (err < 0)
3668 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003669 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003670 if (err < 0)
3671 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003672 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003673 if (err < 0)
3674 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003675 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003676 if (err < 0)
3677 return err;
3678 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003679 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003680 if (err < 0)
3681 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003682 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003683 if (err < 0)
3684 return err;
3685 }
3686 }
3687 return 0;
3688}
3689
Takashi Iwai343a04b2011-07-06 14:28:39 +02003690static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003691 hda_nid_t dac, const char *pfx,
3692 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003693{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003694 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003695 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003696
Takashi Iwaiba8111272012-12-06 18:06:23 +01003697 path = get_out_path(codec, pin, dac);
3698 if (!path)
3699 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003700 /* bind volume control will be created in the case of dac = 0 */
3701 if (dac) {
3702 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3703 if (err < 0)
3704 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003705 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003706 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003707 if (err < 0)
3708 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003709 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003710}
3711
Takashi Iwai23c09b02011-08-19 09:05:35 +02003712static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3713 unsigned int nums,
3714 struct hda_ctl_ops *ops)
3715{
3716 struct alc_spec *spec = codec->spec;
3717 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003718 ctlp = snd_array_new(&spec->bind_ctls);
3719 if (!ctlp)
3720 return NULL;
3721 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3722 *ctlp = ctl;
3723 if (ctl)
3724 ctl->ops = ops;
3725 return ctl;
3726}
3727
3728/* add playback controls for speaker and HP outputs */
3729static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3730 const hda_nid_t *pins,
3731 const hda_nid_t *dacs,
3732 const char *pfx)
3733{
3734 struct alc_spec *spec = codec->spec;
3735 struct hda_bind_ctls *ctl;
3736 char name[32];
3737 int i, n, err;
3738
3739 if (!num_pins || !pins[0])
3740 return 0;
3741
Takashi Iwai527e4d72011-10-27 16:33:27 +02003742 if (num_pins == 1) {
3743 hda_nid_t dac = *dacs;
3744 if (!dac)
3745 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003746 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003747 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003748
Takashi Iwai23c09b02011-08-19 09:05:35 +02003749 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003750 hda_nid_t dac;
3751 if (dacs[num_pins - 1])
3752 dac = dacs[i]; /* with individual volumes */
3753 else
3754 dac = 0;
3755 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3756 err = alc_auto_create_extra_out(codec, pins[i], dac,
3757 "Bass Speaker", 0);
3758 } else if (num_pins >= 3) {
3759 snprintf(name, sizeof(name), "%s %s",
3760 pfx, channel_name[i]);
3761 err = alc_auto_create_extra_out(codec, pins[i], dac,
3762 name, 0);
3763 } else {
3764 err = alc_auto_create_extra_out(codec, pins[i], dac,
3765 pfx, i);
3766 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003767 if (err < 0)
3768 return err;
3769 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003770 if (dacs[num_pins - 1])
3771 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003772
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003773 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003774 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3775 if (!ctl)
3776 return -ENOMEM;
3777 n = 0;
3778 for (i = 0; i < num_pins; i++) {
3779 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003780 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003781 if (!pins[i] || !dacs[i])
3782 continue;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003783 path = get_out_path(codec, pins[i], dacs[i]);
3784 if (!path)
3785 continue;
3786 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003787 if (vol)
3788 ctl->values[n++] =
3789 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3790 }
3791 if (n) {
3792 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3793 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3794 if (err < 0)
3795 return err;
3796 }
3797 return 0;
3798}
3799
Takashi Iwai343a04b2011-07-06 14:28:39 +02003800static int alc_auto_create_hp_out(struct hda_codec *codec)
3801{
3802 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003803 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3804 spec->autocfg.hp_pins,
3805 spec->multiout.hp_out_nid,
3806 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003807}
3808
3809static int alc_auto_create_speaker_out(struct hda_codec *codec)
3810{
3811 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003812 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3813 spec->autocfg.speaker_pins,
3814 spec->multiout.extra_out_nid,
3815 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003816}
3817
Takashi Iwai130e5f02012-12-14 16:09:29 +01003818static bool is_ctl_associated_in_list(struct snd_array *array, hda_nid_t nid,
3819 int dir, int idx, int types)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003820{
Takashi Iwai78e635c2012-12-10 17:07:16 +01003821 int i, type;
3822
Takashi Iwai130e5f02012-12-14 16:09:29 +01003823 for (i = 0; i < array->used; i++) {
3824 struct nid_path *p = snd_array_elem(array, i);
3825 if (p->depth <= 0)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003826 continue;
3827 for (type = 0; type < 2; type++) {
3828 if (types & (1 << type)) {
3829 unsigned int val = p->ctls[type];
3830 if (get_amp_nid_(val) == nid &&
Takashi Iwai130e5f02012-12-14 16:09:29 +01003831 get_amp_direction_(val) == dir &&
3832 get_amp_index_(val) == idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003833 return true;
3834 }
3835 }
3836 }
3837 return false;
3838}
3839
Takashi Iwai130e5f02012-12-14 16:09:29 +01003840/* check whether a control with the given (nid, dir, idx) was assigned */
3841static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3842 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003843{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003844 struct alc_spec *spec = codec->spec;
3845 return is_ctl_associated_in_list(&spec->out_path, nid, dir, idx, 3) ||
3846 is_ctl_associated_in_list(&spec->in_path, nid, dir, idx, 3) ||
3847 is_ctl_associated_in_list(&spec->loopback_path, nid, dir, idx, 3);
3848}
3849
3850/* can have the amp-in capability? */
3851static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3852{
3853 hda_nid_t nid = path->path[idx];
3854 unsigned int caps = get_wcaps(codec, nid);
3855 unsigned int type = get_wcaps_type(caps);
3856
3857 if (!(caps & AC_WCAP_IN_AMP))
3858 return false;
3859 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3860 return false;
3861 return true;
3862}
3863
3864/* can have the amp-out capability? */
3865static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3866{
3867 hda_nid_t nid = path->path[idx];
3868 unsigned int caps = get_wcaps(codec, nid);
3869 unsigned int type = get_wcaps_type(caps);
3870
3871 if (!(caps & AC_WCAP_OUT_AMP))
3872 return false;
3873 if (type == AC_WID_PIN && !idx) /* only for output pins */
3874 return false;
3875 return true;
3876}
3877
3878static bool is_active_in_list(struct hda_codec *codec, struct snd_array *array,
3879 hda_nid_t nid, int dir, int idx)
3880{
3881 int i, n;
3882
3883 for (n = 0; n < array->used; n++) {
3884 struct nid_path *path = snd_array_elem(array, n);
3885 if (!path->active)
3886 continue;
3887 for (i = 0; i < path->depth; i++) {
3888 if (path->path[i] == nid) {
3889 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3890 return true;
3891 break;
3892 }
3893 }
3894 }
3895 return false;
3896}
3897
3898/* check whether the given (nid,dir,idx) is active */
3899static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3900 unsigned int idx, unsigned int dir)
3901{
3902 struct alc_spec *spec = codec->spec;
3903 return is_active_in_list(codec, &spec->out_path, nid, idx, dir) ||
3904 is_active_in_list(codec, &spec->in_path, nid, idx, dir) ||
3905 is_active_in_list(codec, &spec->loopback_path, nid, idx, dir);
3906}
3907
3908/* get the default amp value for the target state */
3909static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3910 int dir, bool enable)
3911{
3912 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003913 unsigned int val = 0;
3914
3915 caps = query_amp_caps(codec, nid, dir);
3916 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003917 /* set to 0dB */
3918 if (enable)
3919 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003920 }
3921 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003922 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003923 val |= HDA_AMP_MUTE;
3924 }
3925 return val;
3926}
3927
Takashi Iwai130e5f02012-12-14 16:09:29 +01003928/* initialize the amp value (only at the first time) */
3929static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3930{
3931 int val = get_amp_val_to_activate(codec, nid, dir, false);
3932 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3933}
3934
3935static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3936 int idx, bool enable)
3937{
3938 int val;
3939 if (is_ctl_associated(codec, nid, dir, idx) ||
3940 is_active_nid(codec, nid, dir, idx))
3941 return;
3942 val = get_amp_val_to_activate(codec, nid, dir, enable);
3943 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3944}
3945
3946static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3947 int i, bool enable)
3948{
3949 hda_nid_t nid = path->path[i];
3950 init_amp(codec, nid, HDA_OUTPUT, 0);
3951 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3952}
3953
3954static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
3955 int i, bool enable)
3956{
3957 struct alc_spec *spec = codec->spec;
3958 hda_nid_t conn[16];
3959 int n, nums;
3960 hda_nid_t nid = path->path[i];
3961
3962 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
3963 for (n = 0; n < nums; n++)
3964 init_amp(codec, nid, HDA_INPUT, n);
3965
3966 if (is_ctl_associated(codec, nid, HDA_INPUT, path->idx[i]))
3967 return;
3968
3969 /* here is a little bit tricky in comparison with activate_amp_out();
3970 * when aa-mixer is available, we need to enable the path as well
3971 */
3972 for (n = 0; n < nums; n++) {
3973 if (n != path->idx[i] && conn[n] != spec->mixer_nid)
3974 continue;
3975 activate_amp(codec, nid, HDA_INPUT, n, enable);
3976 }
3977}
3978
3979static void activate_path(struct hda_codec *codec, struct nid_path *path,
3980 bool enable)
3981{
3982 int i;
3983
3984 if (path->active == enable)
3985 return;
3986
3987 if (!enable)
3988 path->active = false;
3989
3990 for (i = path->depth - 1; i >= 0; i--) {
3991 if (path->multi[i])
3992 snd_hda_codec_write_cache(codec, path->path[i], 0,
3993 AC_VERB_SET_CONNECT_SEL,
3994 path->idx[i]);
3995 if (has_amp_in(codec, path, i))
3996 activate_amp_in(codec, path, i, enable);
3997 if (has_amp_out(codec, path, i))
3998 activate_amp_out(codec, path, i, enable);
3999 }
4000
4001 if (enable)
4002 path->active = true;
4003}
4004
Takashi Iwai78e635c2012-12-10 17:07:16 +01004005/* configure the path from the given dac to the pin as the proper output */
4006static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
4007 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01004008 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01004009{
Takashi Iwaiba8111272012-12-06 18:06:23 +01004010 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02004011
Takashi Iwai130e5f02012-12-14 16:09:29 +01004012 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwaiba8111272012-12-06 18:06:23 +01004013 path = get_out_path(codec, pin, dac);
4014 if (!path)
4015 return;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004016 activate_path(codec, path, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004017}
4018
Takashi Iwai343a04b2011-07-06 14:28:39 +02004019static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004020{
4021 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02004022 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004023 int i;
4024
4025 for (i = 0; i <= HDA_SIDE; i++) {
4026 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4027 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02004028 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01004029 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004030
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004031 }
4032}
4033
Takashi Iwai343a04b2011-07-06 14:28:39 +02004034static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004035{
4036 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004037 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004038 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004039
David Henningsson636030e2011-10-12 19:26:03 +02004040 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004041 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4042 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02004043 pin = spec->autocfg.hp_pins[i];
4044 if (!pin)
4045 break;
4046 dac = spec->multiout.hp_out_nid[i];
4047 if (!dac) {
4048 if (i > 0 && spec->multiout.hp_out_nid[0])
4049 dac = spec->multiout.hp_out_nid[0];
4050 else
4051 dac = spec->multiout.dac_nids[0];
4052 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004053 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004054 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02004055 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004056 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4057 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004058 pin = spec->autocfg.speaker_pins[i];
4059 if (!pin)
4060 break;
4061 dac = spec->multiout.extra_out_nid[i];
4062 if (!dac) {
4063 if (i > 0 && spec->multiout.extra_out_nid[0])
4064 dac = spec->multiout.extra_out_nid[0];
4065 else
4066 dac = spec->multiout.dac_nids[0];
4067 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004068 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004069 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004070}
4071
Takashi Iwai276dd702012-02-17 16:17:03 +01004072/* check whether the given pin can be a multi-io pin */
4073static bool can_be_multiio_pin(struct hda_codec *codec,
4074 unsigned int location, hda_nid_t nid)
4075{
4076 unsigned int defcfg, caps;
4077
4078 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4079 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4080 return false;
4081 if (location && get_defcfg_location(defcfg) != location)
4082 return false;
4083 caps = snd_hda_query_pin_caps(codec, nid);
4084 if (!(caps & AC_PINCAP_OUT))
4085 return false;
4086 return true;
4087}
4088
Takashi Iwaice764ab2011-04-27 16:35:23 +02004089/*
4090 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004091 *
4092 * When hardwired is set, try to fill ony hardwired pins, and returns
4093 * zero if any pins are filled, non-zero if nothing found.
4094 * When hardwired is off, try to fill possible input pins, and returns
4095 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004096 */
4097static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004098 hda_nid_t reference_pin,
4099 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004100{
4101 struct alc_spec *spec = codec->spec;
4102 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004103 int type, i, j, dacs, num_pins, old_pins;
4104 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4105 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004106 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004107
Takashi Iwai276dd702012-02-17 16:17:03 +01004108 old_pins = spec->multi_ios;
4109 if (old_pins >= 2)
4110 goto end_fill;
4111
4112 num_pins = 0;
4113 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4114 for (i = 0; i < cfg->num_inputs; i++) {
4115 if (cfg->inputs[i].type != type)
4116 continue;
4117 if (can_be_multiio_pin(codec, location,
4118 cfg->inputs[i].pin))
4119 num_pins++;
4120 }
4121 }
4122 if (num_pins < 2)
4123 goto end_fill;
4124
Takashi Iwai07b18f62011-11-10 15:42:54 +01004125 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004126 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4127 for (i = 0; i < cfg->num_inputs; i++) {
4128 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004129 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004130
Takashi Iwaice764ab2011-04-27 16:35:23 +02004131 if (cfg->inputs[i].type != type)
4132 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004133 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004134 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004135 for (j = 0; j < spec->multi_ios; j++) {
4136 if (nid == spec->multi_io[j].pin)
4137 break;
4138 }
4139 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004140 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004141
4142 if (offset && offset + spec->multi_ios < dacs) {
4143 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01004144 if (!alc_auto_is_dac_reachable(codec, nid, dac))
4145 dac = 0;
4146 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004147 if (hardwired)
4148 dac = get_dac_if_single(codec, nid);
4149 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01004150 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004151 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004152 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004153 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004154 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004155 if (!add_new_out_path(codec, nid, dac)) {
4156 badness++;
4157 continue;
4158 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004159 spec->multi_io[spec->multi_ios].pin = nid;
4160 spec->multi_io[spec->multi_ios].dac = dac;
4161 spec->multi_ios++;
4162 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004163 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004164 }
4165 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004166 end_fill:
4167 if (badness)
4168 badness = BAD_MULTI_IO;
4169 if (old_pins == spec->multi_ios) {
4170 if (hardwired)
4171 return 1; /* nothing found */
4172 else
4173 return badness; /* no badness if nothing found */
4174 }
4175 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004176 /* cancel newly assigned paths */
4177 spec->out_path.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004178 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004179 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004180 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004181
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004182 /* assign volume and mute controls */
4183 for (i = old_pins; i < spec->multi_ios; i++)
4184 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4185 spec->multi_io[i].dac);
4186
4187 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004188}
4189
4190static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4191 struct snd_ctl_elem_info *uinfo)
4192{
4193 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4194 struct alc_spec *spec = codec->spec;
4195
4196 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4197 uinfo->count = 1;
4198 uinfo->value.enumerated.items = spec->multi_ios + 1;
4199 if (uinfo->value.enumerated.item > spec->multi_ios)
4200 uinfo->value.enumerated.item = spec->multi_ios;
4201 sprintf(uinfo->value.enumerated.name, "%dch",
4202 (uinfo->value.enumerated.item + 1) * 2);
4203 return 0;
4204}
4205
4206static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4207 struct snd_ctl_elem_value *ucontrol)
4208{
4209 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4210 struct alc_spec *spec = codec->spec;
4211 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4212 return 0;
4213}
4214
4215static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4216{
4217 struct alc_spec *spec = codec->spec;
4218 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004219 struct nid_path *path;
4220
4221 path = get_out_path(codec, nid, spec->multi_io[idx].dac);
4222 if (!path)
4223 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004224
4225 if (!spec->multi_io[idx].ctl_in)
4226 spec->multi_io[idx].ctl_in =
Takashi Iwai130e5f02012-12-14 16:09:29 +01004227 snd_hda_codec_update_cache(codec, nid, 0,
Takashi Iwaice764ab2011-04-27 16:35:23 +02004228 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004229
Takashi Iwaice764ab2011-04-27 16:35:23 +02004230 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004231 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004232 activate_path(codec, path, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004233 } else {
Takashi Iwai130e5f02012-12-14 16:09:29 +01004234 activate_path(codec, path, false);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004235 snd_hda_set_pin_ctl_cache(codec, nid,
4236 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004237 }
4238 return 0;
4239}
4240
4241static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4242 struct snd_ctl_elem_value *ucontrol)
4243{
4244 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4245 struct alc_spec *spec = codec->spec;
4246 int i, ch;
4247
4248 ch = ucontrol->value.enumerated.item[0];
4249 if (ch < 0 || ch > spec->multi_ios)
4250 return -EINVAL;
4251 if (ch == (spec->ext_channel_count - 1) / 2)
4252 return 0;
4253 spec->ext_channel_count = (ch + 1) * 2;
4254 for (i = 0; i < spec->multi_ios; i++)
4255 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004256 spec->multiout.max_channels = max(spec->ext_channel_count,
4257 spec->const_channel_count);
4258 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004259 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004260 return 1;
4261}
4262
Takashi Iwaia9111322011-05-02 11:30:18 +02004263static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004264 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4265 .name = "Channel Mode",
4266 .info = alc_auto_ch_mode_info,
4267 .get = alc_auto_ch_mode_get,
4268 .put = alc_auto_ch_mode_put,
4269};
4270
Takashi Iwai23c09b02011-08-19 09:05:35 +02004271static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004272{
4273 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004274
Takashi Iwaic2674682011-08-24 17:57:44 +02004275 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004276 if (!alc_kcontrol_new(spec, "Channel Mode",
4277 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004278 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004279 }
4280 return 0;
4281}
4282
Takashi Iwai1d045db2011-07-07 18:23:21 +02004283/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4284 * active input pins
4285 */
4286static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4287{
4288 struct alc_spec *spec = codec->spec;
4289 const struct hda_input_mux *imux;
4290 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4291 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4292 int i, n, nums;
4293
4294 imux = spec->input_mux;
4295 if (!imux)
4296 return;
4297 if (spec->dyn_adc_switch)
4298 return;
4299
Takashi Iwai26acaf02012-03-22 14:36:50 +01004300 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004301 nums = 0;
4302 for (n = 0; n < spec->num_adc_nids; n++) {
4303 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004304 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004305 for (i = 0; i < imux->num_items; i++) {
4306 hda_nid_t pin = spec->imux_pins[i];
4307 if (pin) {
4308 if (get_connection_index(codec, cap, pin) < 0)
4309 break;
4310 } else if (num_conns <= imux->items[i].index)
4311 break;
4312 }
4313 if (i >= imux->num_items) {
4314 adc_nids[nums] = spec->private_adc_nids[n];
4315 capsrc_nids[nums++] = cap;
4316 }
4317 }
4318 if (!nums) {
4319 /* check whether ADC-switch is possible */
4320 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004321 if (spec->shared_mic_hp) {
4322 spec->shared_mic_hp = 0;
4323 spec->private_imux[0].num_items = 1;
4324 goto again;
4325 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004326 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4327 " using fallback 0x%x\n",
4328 codec->chip_name, spec->private_adc_nids[0]);
4329 spec->num_adc_nids = 1;
4330 spec->auto_mic = 0;
4331 return;
4332 }
4333 } else if (nums != spec->num_adc_nids) {
4334 memcpy(spec->private_adc_nids, adc_nids,
4335 nums * sizeof(hda_nid_t));
4336 memcpy(spec->private_capsrc_nids, capsrc_nids,
4337 nums * sizeof(hda_nid_t));
4338 spec->num_adc_nids = nums;
4339 }
4340
4341 if (spec->auto_mic)
4342 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004343 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004344 spec->num_adc_nids = 1; /* reduce to a single ADC */
4345}
4346
4347/*
4348 * initialize ADC paths
4349 */
4350static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4351{
4352 struct alc_spec *spec = codec->spec;
4353 hda_nid_t nid;
4354
4355 nid = spec->adc_nids[adc_idx];
4356 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004357 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004358 snd_hda_codec_write(codec, nid, 0,
4359 AC_VERB_SET_AMP_GAIN_MUTE,
4360 AMP_IN_MUTE(0));
4361 return;
4362 }
4363 if (!spec->capsrc_nids)
4364 return;
4365 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004366 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004367 snd_hda_codec_write(codec, nid, 0,
4368 AC_VERB_SET_AMP_GAIN_MUTE,
4369 AMP_OUT_MUTE);
4370}
4371
4372static void alc_auto_init_input_src(struct hda_codec *codec)
4373{
4374 struct alc_spec *spec = codec->spec;
4375 int c, nums;
4376
4377 for (c = 0; c < spec->num_adc_nids; c++)
4378 alc_auto_init_adc(codec, c);
4379 if (spec->dyn_adc_switch)
4380 nums = 1;
4381 else
4382 nums = spec->num_adc_nids;
4383 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004384 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385}
4386
4387/* add mic boosts if needed */
4388static int alc_auto_add_mic_boost(struct hda_codec *codec)
4389{
4390 struct alc_spec *spec = codec->spec;
4391 struct auto_pin_cfg *cfg = &spec->autocfg;
4392 int i, err;
4393 int type_idx = 0;
4394 hda_nid_t nid;
4395 const char *prev_label = NULL;
4396
4397 for (i = 0; i < cfg->num_inputs; i++) {
4398 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4399 break;
4400 nid = cfg->inputs[i].pin;
4401 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4402 const char *label;
4403 char boost_label[32];
4404
4405 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004406 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4407 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004408 if (prev_label && !strcmp(label, prev_label))
4409 type_idx++;
4410 else
4411 type_idx = 0;
4412 prev_label = label;
4413
4414 snprintf(boost_label, sizeof(boost_label),
4415 "%s Boost Volume", label);
4416 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4417 boost_label, type_idx,
4418 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4419 if (err < 0)
4420 return err;
4421 }
4422 }
4423 return 0;
4424}
4425
4426/* select or unmute the given capsrc route */
4427static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4428 int idx)
4429{
4430 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4431 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4432 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004433 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004434 snd_hda_codec_write_cache(codec, cap, 0,
4435 AC_VERB_SET_CONNECT_SEL, idx);
4436 }
4437}
4438
4439/* set the default connection to that pin */
4440static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4441{
4442 struct alc_spec *spec = codec->spec;
4443 int i;
4444
4445 if (!pin)
4446 return 0;
4447 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004448 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004449 int idx;
4450
4451 idx = get_connection_index(codec, cap, pin);
4452 if (idx < 0)
4453 continue;
4454 select_or_unmute_capsrc(codec, cap, idx);
4455 return i; /* return the found index */
4456 }
4457 return -1; /* not found */
4458}
4459
4460/* initialize some special cases for input sources */
4461static void alc_init_special_input_src(struct hda_codec *codec)
4462{
4463 struct alc_spec *spec = codec->spec;
4464 int i;
4465
4466 for (i = 0; i < spec->autocfg.num_inputs; i++)
4467 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4468}
4469
4470/* assign appropriate capture mixers */
4471static void set_capture_mixer(struct hda_codec *codec)
4472{
4473 struct alc_spec *spec = codec->spec;
4474 static const struct snd_kcontrol_new *caps[2][3] = {
4475 { alc_capture_mixer_nosrc1,
4476 alc_capture_mixer_nosrc2,
4477 alc_capture_mixer_nosrc3 },
4478 { alc_capture_mixer1,
4479 alc_capture_mixer2,
4480 alc_capture_mixer3 },
4481 };
4482
4483 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004484 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004485 if (!spec->capsrc_nids)
4486 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004487 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004488 return; /* no volume in capsrc, too */
4489 spec->vol_in_capsrc = 1;
4490 }
4491
4492 if (spec->num_adc_nids > 0) {
4493 int mux = 0;
4494 int num_adcs = 0;
4495
4496 if (spec->input_mux && spec->input_mux->num_items > 1)
4497 mux = 1;
4498 if (spec->auto_mic) {
4499 num_adcs = 1;
4500 mux = 0;
4501 } else if (spec->dyn_adc_switch)
4502 num_adcs = 1;
4503 if (!num_adcs) {
4504 if (spec->num_adc_nids > 3)
4505 spec->num_adc_nids = 3;
4506 else if (!spec->num_adc_nids)
4507 return;
4508 num_adcs = spec->num_adc_nids;
4509 }
4510 spec->cap_mixer = caps[mux][num_adcs - 1];
4511 }
4512}
4513
4514/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004515 * standard auto-parser initializations
4516 */
4517static void alc_auto_init_std(struct hda_codec *codec)
4518{
Takashi Iwaie4770622011-07-08 11:11:35 +02004519 alc_auto_init_multi_out(codec);
4520 alc_auto_init_extra_out(codec);
4521 alc_auto_init_analog_input(codec);
4522 alc_auto_init_input_src(codec);
4523 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004524 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004525}
4526
4527/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004528 * Digital-beep handlers
4529 */
4530#ifdef CONFIG_SND_HDA_INPUT_BEEP
4531#define set_beep_amp(spec, nid, idx, dir) \
4532 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4533
4534static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004535 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004536 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4537 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4538 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4539 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004540 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004541 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4542 {}
4543};
4544
4545static inline int has_cdefine_beep(struct hda_codec *codec)
4546{
4547 struct alc_spec *spec = codec->spec;
4548 const struct snd_pci_quirk *q;
4549 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4550 if (q)
4551 return q->value;
4552 return spec->cdefine.enable_pcbeep;
4553}
4554#else
4555#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4556#define has_cdefine_beep(codec) 0
4557#endif
4558
4559/* parse the BIOS configuration and set up the alc_spec */
4560/* return 1 if successful, 0 if the proper config is not found,
4561 * or a negative error code
4562 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004563static int alc_parse_auto_config(struct hda_codec *codec,
4564 const hda_nid_t *ignore_nids,
4565 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004566{
4567 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004568 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004569 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004570
Takashi Iwai53c334a2011-08-23 18:27:14 +02004571 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4572 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004573 if (err < 0)
4574 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004575 if (!cfg->line_outs) {
4576 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004577 spec->multiout.max_channels = 2;
4578 spec->no_analog = 1;
4579 goto dig_only;
4580 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004581 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004582 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004583
Takashi Iwaie427c232012-07-29 10:04:08 +02004584 if (!spec->no_primary_hp &&
4585 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004586 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004587 /* use HP as primary out */
4588 cfg->speaker_outs = cfg->line_outs;
4589 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4590 sizeof(cfg->speaker_pins));
4591 cfg->line_outs = cfg->hp_outs;
4592 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4593 cfg->hp_outs = 0;
4594 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4595 cfg->line_out_type = AUTO_PIN_HP_OUT;
4596 }
4597
Takashi Iwai1d045db2011-07-07 18:23:21 +02004598 err = alc_auto_fill_dac_nids(codec);
4599 if (err < 0)
4600 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004601 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004602 if (err < 0)
4603 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004604 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004605 if (err < 0)
4606 return err;
4607 err = alc_auto_create_hp_out(codec);
4608 if (err < 0)
4609 return err;
4610 err = alc_auto_create_speaker_out(codec);
4611 if (err < 0)
4612 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004613 err = alc_auto_create_shared_input(codec);
4614 if (err < 0)
4615 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004616 err = alc_auto_create_input_ctls(codec);
4617 if (err < 0)
4618 return err;
4619
Takashi Iwaib6adb572012-12-03 10:30:58 +01004620 /* check the multiple speaker pins */
4621 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4622 spec->const_channel_count = cfg->line_outs * 2;
4623 else
4624 spec->const_channel_count = cfg->speaker_outs * 2;
4625
4626 if (spec->multi_ios > 0)
4627 spec->multiout.max_channels = max(spec->ext_channel_count,
4628 spec->const_channel_count);
4629 else
4630 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004631
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004632 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004633 alc_auto_parse_digital(codec);
4634
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004635 if (!spec->no_analog)
4636 alc_remove_invalid_adc_nids(codec);
4637
4638 if (ssid_nids)
4639 alc_ssid_check(codec, ssid_nids);
4640
4641 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004642 err = alc_auto_check_switches(codec);
4643 if (err < 0)
4644 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004645 err = alc_auto_add_mic_boost(codec);
4646 if (err < 0)
4647 return err;
4648 }
4649
Takashi Iwai1d045db2011-07-07 18:23:21 +02004650 if (spec->kctls.list)
4651 add_mixer(spec, spec->kctls.list);
4652
Takashi Iwai070cff42012-02-21 12:54:17 +01004653 if (!spec->no_analog && !spec->cap_mixer)
4654 set_capture_mixer(codec);
4655
Takashi Iwai1d045db2011-07-07 18:23:21 +02004656 return 1;
4657}
4658
Takashi Iwai3de95172012-05-07 18:03:15 +02004659/* common preparation job for alc_spec */
4660static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4661{
4662 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4663 int err;
4664
4665 if (!spec)
4666 return -ENOMEM;
4667 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004668 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004669 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004670 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004671 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4672 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004673 snd_array_init(&spec->out_path, sizeof(struct nid_path), 8);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01004674 snd_array_init(&spec->in_path, sizeof(struct nid_path), 8);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01004675 snd_array_init(&spec->loopback_path, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004676
4677 err = alc_codec_rename_from_preset(codec);
4678 if (err < 0) {
4679 kfree(spec);
4680 return err;
4681 }
4682 return 0;
4683}
4684
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004685static int alc880_parse_auto_config(struct hda_codec *codec)
4686{
4687 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004688 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004689 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4690}
4691
Takashi Iwai1d045db2011-07-07 18:23:21 +02004692/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004693 * ALC880 fix-ups
4694 */
4695enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004696 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004697 ALC880_FIXUP_GPIO2,
4698 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004699 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004700 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004701 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004702 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004703 ALC880_FIXUP_VOL_KNOB,
4704 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004705 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004706 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004707 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004708 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004709 ALC880_FIXUP_3ST_BASE,
4710 ALC880_FIXUP_3ST,
4711 ALC880_FIXUP_3ST_DIG,
4712 ALC880_FIXUP_5ST_BASE,
4713 ALC880_FIXUP_5ST,
4714 ALC880_FIXUP_5ST_DIG,
4715 ALC880_FIXUP_6ST_BASE,
4716 ALC880_FIXUP_6ST,
4717 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004718};
4719
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004720/* enable the volume-knob widget support on NID 0x21 */
4721static void alc880_fixup_vol_knob(struct hda_codec *codec,
4722 const struct alc_fixup *fix, int action)
4723{
4724 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004725 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004726}
4727
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004728static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004729 [ALC880_FIXUP_GPIO1] = {
4730 .type = ALC_FIXUP_VERBS,
4731 .v.verbs = alc_gpio1_init_verbs,
4732 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004733 [ALC880_FIXUP_GPIO2] = {
4734 .type = ALC_FIXUP_VERBS,
4735 .v.verbs = alc_gpio2_init_verbs,
4736 },
4737 [ALC880_FIXUP_MEDION_RIM] = {
4738 .type = ALC_FIXUP_VERBS,
4739 .v.verbs = (const struct hda_verb[]) {
4740 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4741 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4742 { }
4743 },
4744 .chained = true,
4745 .chain_id = ALC880_FIXUP_GPIO2,
4746 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004747 [ALC880_FIXUP_LG] = {
4748 .type = ALC_FIXUP_PINS,
4749 .v.pins = (const struct alc_pincfg[]) {
4750 /* disable bogus unused pins */
4751 { 0x16, 0x411111f0 },
4752 { 0x18, 0x411111f0 },
4753 { 0x1a, 0x411111f0 },
4754 { }
4755 }
4756 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004757 [ALC880_FIXUP_W810] = {
4758 .type = ALC_FIXUP_PINS,
4759 .v.pins = (const struct alc_pincfg[]) {
4760 /* disable bogus unused pins */
4761 { 0x17, 0x411111f0 },
4762 { }
4763 },
4764 .chained = true,
4765 .chain_id = ALC880_FIXUP_GPIO2,
4766 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004767 [ALC880_FIXUP_EAPD_COEF] = {
4768 .type = ALC_FIXUP_VERBS,
4769 .v.verbs = (const struct hda_verb[]) {
4770 /* change to EAPD mode */
4771 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4772 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4773 {}
4774 },
4775 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004776 [ALC880_FIXUP_TCL_S700] = {
4777 .type = ALC_FIXUP_VERBS,
4778 .v.verbs = (const struct hda_verb[]) {
4779 /* change to EAPD mode */
4780 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4781 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4782 {}
4783 },
4784 .chained = true,
4785 .chain_id = ALC880_FIXUP_GPIO2,
4786 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004787 [ALC880_FIXUP_VOL_KNOB] = {
4788 .type = ALC_FIXUP_FUNC,
4789 .v.func = alc880_fixup_vol_knob,
4790 },
4791 [ALC880_FIXUP_FUJITSU] = {
4792 /* override all pins as BIOS on old Amilo is broken */
4793 .type = ALC_FIXUP_PINS,
4794 .v.pins = (const struct alc_pincfg[]) {
4795 { 0x14, 0x0121411f }, /* HP */
4796 { 0x15, 0x99030120 }, /* speaker */
4797 { 0x16, 0x99030130 }, /* bass speaker */
4798 { 0x17, 0x411111f0 }, /* N/A */
4799 { 0x18, 0x411111f0 }, /* N/A */
4800 { 0x19, 0x01a19950 }, /* mic-in */
4801 { 0x1a, 0x411111f0 }, /* N/A */
4802 { 0x1b, 0x411111f0 }, /* N/A */
4803 { 0x1c, 0x411111f0 }, /* N/A */
4804 { 0x1d, 0x411111f0 }, /* N/A */
4805 { 0x1e, 0x01454140 }, /* SPDIF out */
4806 { }
4807 },
4808 .chained = true,
4809 .chain_id = ALC880_FIXUP_VOL_KNOB,
4810 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004811 [ALC880_FIXUP_F1734] = {
4812 /* almost compatible with FUJITSU, but no bass and SPDIF */
4813 .type = ALC_FIXUP_PINS,
4814 .v.pins = (const struct alc_pincfg[]) {
4815 { 0x14, 0x0121411f }, /* HP */
4816 { 0x15, 0x99030120 }, /* speaker */
4817 { 0x16, 0x411111f0 }, /* N/A */
4818 { 0x17, 0x411111f0 }, /* N/A */
4819 { 0x18, 0x411111f0 }, /* N/A */
4820 { 0x19, 0x01a19950 }, /* mic-in */
4821 { 0x1a, 0x411111f0 }, /* N/A */
4822 { 0x1b, 0x411111f0 }, /* N/A */
4823 { 0x1c, 0x411111f0 }, /* N/A */
4824 { 0x1d, 0x411111f0 }, /* N/A */
4825 { 0x1e, 0x411111f0 }, /* N/A */
4826 { }
4827 },
4828 .chained = true,
4829 .chain_id = ALC880_FIXUP_VOL_KNOB,
4830 },
Takashi Iwai817de922012-02-20 17:20:48 +01004831 [ALC880_FIXUP_UNIWILL] = {
4832 /* need to fix HP and speaker pins to be parsed correctly */
4833 .type = ALC_FIXUP_PINS,
4834 .v.pins = (const struct alc_pincfg[]) {
4835 { 0x14, 0x0121411f }, /* HP */
4836 { 0x15, 0x99030120 }, /* speaker */
4837 { 0x16, 0x99030130 }, /* bass speaker */
4838 { }
4839 },
4840 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004841 [ALC880_FIXUP_UNIWILL_DIG] = {
4842 .type = ALC_FIXUP_PINS,
4843 .v.pins = (const struct alc_pincfg[]) {
4844 /* disable bogus unused pins */
4845 { 0x17, 0x411111f0 },
4846 { 0x19, 0x411111f0 },
4847 { 0x1b, 0x411111f0 },
4848 { 0x1f, 0x411111f0 },
4849 { }
4850 }
4851 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004852 [ALC880_FIXUP_Z71V] = {
4853 .type = ALC_FIXUP_PINS,
4854 .v.pins = (const struct alc_pincfg[]) {
4855 /* set up the whole pins as BIOS is utterly broken */
4856 { 0x14, 0x99030120 }, /* speaker */
4857 { 0x15, 0x0121411f }, /* HP */
4858 { 0x16, 0x411111f0 }, /* N/A */
4859 { 0x17, 0x411111f0 }, /* N/A */
4860 { 0x18, 0x01a19950 }, /* mic-in */
4861 { 0x19, 0x411111f0 }, /* N/A */
4862 { 0x1a, 0x01813031 }, /* line-in */
4863 { 0x1b, 0x411111f0 }, /* N/A */
4864 { 0x1c, 0x411111f0 }, /* N/A */
4865 { 0x1d, 0x411111f0 }, /* N/A */
4866 { 0x1e, 0x0144111e }, /* SPDIF */
4867 { }
4868 }
4869 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004870 [ALC880_FIXUP_3ST_BASE] = {
4871 .type = ALC_FIXUP_PINS,
4872 .v.pins = (const struct alc_pincfg[]) {
4873 { 0x14, 0x01014010 }, /* line-out */
4874 { 0x15, 0x411111f0 }, /* N/A */
4875 { 0x16, 0x411111f0 }, /* N/A */
4876 { 0x17, 0x411111f0 }, /* N/A */
4877 { 0x18, 0x01a19c30 }, /* mic-in */
4878 { 0x19, 0x0121411f }, /* HP */
4879 { 0x1a, 0x01813031 }, /* line-in */
4880 { 0x1b, 0x02a19c40 }, /* front-mic */
4881 { 0x1c, 0x411111f0 }, /* N/A */
4882 { 0x1d, 0x411111f0 }, /* N/A */
4883 /* 0x1e is filled in below */
4884 { 0x1f, 0x411111f0 }, /* N/A */
4885 { }
4886 }
4887 },
4888 [ALC880_FIXUP_3ST] = {
4889 .type = ALC_FIXUP_PINS,
4890 .v.pins = (const struct alc_pincfg[]) {
4891 { 0x1e, 0x411111f0 }, /* N/A */
4892 { }
4893 },
4894 .chained = true,
4895 .chain_id = ALC880_FIXUP_3ST_BASE,
4896 },
4897 [ALC880_FIXUP_3ST_DIG] = {
4898 .type = ALC_FIXUP_PINS,
4899 .v.pins = (const struct alc_pincfg[]) {
4900 { 0x1e, 0x0144111e }, /* SPDIF */
4901 { }
4902 },
4903 .chained = true,
4904 .chain_id = ALC880_FIXUP_3ST_BASE,
4905 },
4906 [ALC880_FIXUP_5ST_BASE] = {
4907 .type = ALC_FIXUP_PINS,
4908 .v.pins = (const struct alc_pincfg[]) {
4909 { 0x14, 0x01014010 }, /* front */
4910 { 0x15, 0x411111f0 }, /* N/A */
4911 { 0x16, 0x01011411 }, /* CLFE */
4912 { 0x17, 0x01016412 }, /* surr */
4913 { 0x18, 0x01a19c30 }, /* mic-in */
4914 { 0x19, 0x0121411f }, /* HP */
4915 { 0x1a, 0x01813031 }, /* line-in */
4916 { 0x1b, 0x02a19c40 }, /* front-mic */
4917 { 0x1c, 0x411111f0 }, /* N/A */
4918 { 0x1d, 0x411111f0 }, /* N/A */
4919 /* 0x1e is filled in below */
4920 { 0x1f, 0x411111f0 }, /* N/A */
4921 { }
4922 }
4923 },
4924 [ALC880_FIXUP_5ST] = {
4925 .type = ALC_FIXUP_PINS,
4926 .v.pins = (const struct alc_pincfg[]) {
4927 { 0x1e, 0x411111f0 }, /* N/A */
4928 { }
4929 },
4930 .chained = true,
4931 .chain_id = ALC880_FIXUP_5ST_BASE,
4932 },
4933 [ALC880_FIXUP_5ST_DIG] = {
4934 .type = ALC_FIXUP_PINS,
4935 .v.pins = (const struct alc_pincfg[]) {
4936 { 0x1e, 0x0144111e }, /* SPDIF */
4937 { }
4938 },
4939 .chained = true,
4940 .chain_id = ALC880_FIXUP_5ST_BASE,
4941 },
4942 [ALC880_FIXUP_6ST_BASE] = {
4943 .type = ALC_FIXUP_PINS,
4944 .v.pins = (const struct alc_pincfg[]) {
4945 { 0x14, 0x01014010 }, /* front */
4946 { 0x15, 0x01016412 }, /* surr */
4947 { 0x16, 0x01011411 }, /* CLFE */
4948 { 0x17, 0x01012414 }, /* side */
4949 { 0x18, 0x01a19c30 }, /* mic-in */
4950 { 0x19, 0x02a19c40 }, /* front-mic */
4951 { 0x1a, 0x01813031 }, /* line-in */
4952 { 0x1b, 0x0121411f }, /* HP */
4953 { 0x1c, 0x411111f0 }, /* N/A */
4954 { 0x1d, 0x411111f0 }, /* N/A */
4955 /* 0x1e is filled in below */
4956 { 0x1f, 0x411111f0 }, /* N/A */
4957 { }
4958 }
4959 },
4960 [ALC880_FIXUP_6ST] = {
4961 .type = ALC_FIXUP_PINS,
4962 .v.pins = (const struct alc_pincfg[]) {
4963 { 0x1e, 0x411111f0 }, /* N/A */
4964 { }
4965 },
4966 .chained = true,
4967 .chain_id = ALC880_FIXUP_6ST_BASE,
4968 },
4969 [ALC880_FIXUP_6ST_DIG] = {
4970 .type = ALC_FIXUP_PINS,
4971 .v.pins = (const struct alc_pincfg[]) {
4972 { 0x1e, 0x0144111e }, /* SPDIF */
4973 { }
4974 },
4975 .chained = true,
4976 .chain_id = ALC880_FIXUP_6ST_BASE,
4977 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004978};
4979
4980static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004981 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004982 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004983 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4984 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004985 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004986 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004987 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004988 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004989 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004990 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004991 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004992 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004993 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004994 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004995 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004996 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4997 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4998 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004999 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005000
5001 /* Below is the copied entries from alc880_quirks.c.
5002 * It's not quite sure whether BIOS sets the correct pin-config table
5003 * on these machines, thus they are kept to be compatible with
5004 * the old static quirks. Once when it's confirmed to work without
5005 * these overrides, it'd be better to remove.
5006 */
5007 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
5008 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
5009 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
5010 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
5011 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
5012 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
5013 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
5014 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
5015 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
5016 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
5017 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
5018 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
5019 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
5020 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
5021 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
5022 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
5023 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
5024 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
5025 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
5026 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
5027 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
5028 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
5029 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
5030 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5031 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5032 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5033 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5034 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5035 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5036 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5037 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5038 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5039 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5040 /* default Intel */
5041 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
5042 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
5043 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
5044 {}
5045};
5046
5047static const struct alc_model_fixup alc880_fixup_models[] = {
5048 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
5049 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
5050 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
5051 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
5052 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
5053 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01005054 {}
5055};
5056
5057
5058/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02005059 * OK, here we have finally the patch for ALC880
5060 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005061static int patch_alc880(struct hda_codec *codec)
5062{
5063 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005064 int err;
5065
Takashi Iwai3de95172012-05-07 18:03:15 +02005066 err = alc_alloc_spec(codec, 0x0b);
5067 if (err < 0)
5068 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005069
Takashi Iwai3de95172012-05-07 18:03:15 +02005070 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02005071 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005072
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005073 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
5074 alc880_fixups);
5075 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005076
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005077 /* automatic parse from the BIOS config */
5078 err = alc880_parse_auto_config(codec);
5079 if (err < 0)
5080 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005082 if (!spec->no_analog) {
5083 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005084 if (err < 0)
5085 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005086 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5087 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005088
Takashi Iwai1d045db2011-07-07 18:23:21 +02005089 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02005090 codec->patch_ops.unsol_event = alc880_unsol_event;
5091
Takashi Iwai1d045db2011-07-07 18:23:21 +02005092
Takashi Iwai589876e2012-02-20 15:47:55 +01005093 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5094
Takashi Iwai1d045db2011-07-07 18:23:21 +02005095 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005096
5097 error:
5098 alc_free(codec);
5099 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005100}
5101
5102
5103/*
5104 * ALC260 support
5105 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005106static int alc260_parse_auto_config(struct hda_codec *codec)
5107{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005108 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005109 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5110 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005111}
5112
Takashi Iwai1d045db2011-07-07 18:23:21 +02005113/*
5114 * Pin config fixes
5115 */
5116enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005117 ALC260_FIXUP_HP_DC5750,
5118 ALC260_FIXUP_HP_PIN_0F,
5119 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005120 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005121 ALC260_FIXUP_GPIO1_TOGGLE,
5122 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005123 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005124 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005125};
5126
Takashi Iwai20f7d922012-02-16 12:35:16 +01005127static void alc260_gpio1_automute(struct hda_codec *codec)
5128{
5129 struct alc_spec *spec = codec->spec;
5130 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5131 spec->hp_jack_present);
5132}
5133
5134static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5135 const struct alc_fixup *fix, int action)
5136{
5137 struct alc_spec *spec = codec->spec;
5138 if (action == ALC_FIXUP_ACT_PROBE) {
5139 /* although the machine has only one output pin, we need to
5140 * toggle GPIO1 according to the jack state
5141 */
5142 spec->automute_hook = alc260_gpio1_automute;
5143 spec->detect_hp = 1;
5144 spec->automute_speaker = 1;
5145 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005146 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5147 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005148 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005149 }
5150}
5151
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005152static void alc260_fixup_kn1(struct hda_codec *codec,
5153 const struct alc_fixup *fix, int action)
5154{
5155 struct alc_spec *spec = codec->spec;
5156 static const struct alc_pincfg pincfgs[] = {
5157 { 0x0f, 0x02214000 }, /* HP/speaker */
5158 { 0x12, 0x90a60160 }, /* int mic */
5159 { 0x13, 0x02a19000 }, /* ext mic */
5160 { 0x18, 0x01446000 }, /* SPDIF out */
5161 /* disable bogus I/O pins */
5162 { 0x10, 0x411111f0 },
5163 { 0x11, 0x411111f0 },
5164 { 0x14, 0x411111f0 },
5165 { 0x15, 0x411111f0 },
5166 { 0x16, 0x411111f0 },
5167 { 0x17, 0x411111f0 },
5168 { 0x19, 0x411111f0 },
5169 { }
5170 };
5171
5172 switch (action) {
5173 case ALC_FIXUP_ACT_PRE_PROBE:
5174 alc_apply_pincfgs(codec, pincfgs);
5175 break;
5176 case ALC_FIXUP_ACT_PROBE:
5177 spec->init_amp = ALC_INIT_NONE;
5178 break;
5179 }
5180}
5181
Takashi Iwai1d045db2011-07-07 18:23:21 +02005182static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005183 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005184 .type = ALC_FIXUP_PINS,
5185 .v.pins = (const struct alc_pincfg[]) {
5186 { 0x11, 0x90130110 }, /* speaker */
5187 { }
5188 }
5189 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005190 [ALC260_FIXUP_HP_PIN_0F] = {
5191 .type = ALC_FIXUP_PINS,
5192 .v.pins = (const struct alc_pincfg[]) {
5193 { 0x0f, 0x01214000 }, /* HP */
5194 { }
5195 }
5196 },
5197 [ALC260_FIXUP_COEF] = {
5198 .type = ALC_FIXUP_VERBS,
5199 .v.verbs = (const struct hda_verb[]) {
5200 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5201 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5202 { }
5203 },
5204 .chained = true,
5205 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5206 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005207 [ALC260_FIXUP_GPIO1] = {
5208 .type = ALC_FIXUP_VERBS,
5209 .v.verbs = alc_gpio1_init_verbs,
5210 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005211 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5212 .type = ALC_FIXUP_FUNC,
5213 .v.func = alc260_fixup_gpio1_toggle,
5214 .chained = true,
5215 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5216 },
5217 [ALC260_FIXUP_REPLACER] = {
5218 .type = ALC_FIXUP_VERBS,
5219 .v.verbs = (const struct hda_verb[]) {
5220 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5221 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5222 { }
5223 },
5224 .chained = true,
5225 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5226 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005227 [ALC260_FIXUP_HP_B1900] = {
5228 .type = ALC_FIXUP_FUNC,
5229 .v.func = alc260_fixup_gpio1_toggle,
5230 .chained = true,
5231 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005232 },
5233 [ALC260_FIXUP_KN1] = {
5234 .type = ALC_FIXUP_FUNC,
5235 .v.func = alc260_fixup_kn1,
5236 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005237};
5238
5239static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005240 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005241 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005242 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005243 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005244 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005245 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005246 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005247 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005248 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005249 {}
5250};
5251
5252/*
5253 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005254static int patch_alc260(struct hda_codec *codec)
5255{
5256 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005257 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005258
Takashi Iwai3de95172012-05-07 18:03:15 +02005259 err = alc_alloc_spec(codec, 0x07);
5260 if (err < 0)
5261 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005262
Takashi Iwai3de95172012-05-07 18:03:15 +02005263 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005264
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005265 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5266 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005267
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005268 /* automatic parse from the BIOS config */
5269 err = alc260_parse_auto_config(codec);
5270 if (err < 0)
5271 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005272
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005273 if (!spec->no_analog) {
5274 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005275 if (err < 0)
5276 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005277 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5278 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005279
Takashi Iwai1d045db2011-07-07 18:23:21 +02005280 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005281 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005282
Takashi Iwai589876e2012-02-20 15:47:55 +01005283 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5284
Takashi Iwai1d045db2011-07-07 18:23:21 +02005285 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005286
5287 error:
5288 alc_free(codec);
5289 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005290}
5291
5292
5293/*
5294 * ALC882/883/885/888/889 support
5295 *
5296 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5297 * configuration. Each pin widget can choose any input DACs and a mixer.
5298 * Each ADC is connected from a mixer of all inputs. This makes possible
5299 * 6-channel independent captures.
5300 *
5301 * In addition, an independent DAC for the multi-playback (not used in this
5302 * driver yet).
5303 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005304
5305/*
5306 * Pin config fixes
5307 */
5308enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005309 ALC882_FIXUP_ABIT_AW9D_MAX,
5310 ALC882_FIXUP_LENOVO_Y530,
5311 ALC882_FIXUP_PB_M5210,
5312 ALC882_FIXUP_ACER_ASPIRE_7736,
5313 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005314 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005315 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005316 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005317 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005318 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005319 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005320 ALC882_FIXUP_GPIO1,
5321 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005322 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005323 ALC889_FIXUP_COEF,
5324 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005325 ALC882_FIXUP_ACER_ASPIRE_4930G,
5326 ALC882_FIXUP_ACER_ASPIRE_8930G,
5327 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005328 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005329 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005330 ALC889_FIXUP_MBP_VREF,
5331 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005332 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005333 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005334};
5335
Takashi Iwai68ef0562011-11-09 18:24:44 +01005336static void alc889_fixup_coef(struct hda_codec *codec,
5337 const struct alc_fixup *fix, int action)
5338{
5339 if (action != ALC_FIXUP_ACT_INIT)
5340 return;
5341 alc889_coef_init(codec);
5342}
5343
Takashi Iwai56710872011-11-14 17:42:11 +01005344/* toggle speaker-output according to the hp-jack state */
5345static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5346{
5347 unsigned int gpiostate, gpiomask, gpiodir;
5348
5349 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5350 AC_VERB_GET_GPIO_DATA, 0);
5351
5352 if (!muted)
5353 gpiostate |= (1 << pin);
5354 else
5355 gpiostate &= ~(1 << pin);
5356
5357 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5358 AC_VERB_GET_GPIO_MASK, 0);
5359 gpiomask |= (1 << pin);
5360
5361 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5362 AC_VERB_GET_GPIO_DIRECTION, 0);
5363 gpiodir |= (1 << pin);
5364
5365
5366 snd_hda_codec_write(codec, codec->afg, 0,
5367 AC_VERB_SET_GPIO_MASK, gpiomask);
5368 snd_hda_codec_write(codec, codec->afg, 0,
5369 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5370
5371 msleep(1);
5372
5373 snd_hda_codec_write(codec, codec->afg, 0,
5374 AC_VERB_SET_GPIO_DATA, gpiostate);
5375}
5376
5377/* set up GPIO at initialization */
5378static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5379 const struct alc_fixup *fix, int action)
5380{
5381 if (action != ALC_FIXUP_ACT_INIT)
5382 return;
5383 alc882_gpio_mute(codec, 0, 0);
5384 alc882_gpio_mute(codec, 1, 0);
5385}
5386
Takashi Iwai02a237b2012-02-13 15:25:07 +01005387/* Fix the connection of some pins for ALC889:
5388 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5389 * work correctly (bko#42740)
5390 */
5391static void alc889_fixup_dac_route(struct hda_codec *codec,
5392 const struct alc_fixup *fix, int action)
5393{
5394 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005395 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005396 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5397 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5398 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5399 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5400 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5401 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005402 } else if (action == ALC_FIXUP_ACT_PROBE) {
5403 /* restore the connections */
5404 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5405 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5406 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5407 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5408 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005409 }
5410}
5411
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005412/* Set VREF on HP pin */
5413static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5414 const struct alc_fixup *fix, int action)
5415{
5416 struct alc_spec *spec = codec->spec;
5417 static hda_nid_t nids[2] = { 0x14, 0x15 };
5418 int i;
5419
5420 if (action != ALC_FIXUP_ACT_INIT)
5421 return;
5422 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5423 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5424 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5425 continue;
5426 val = snd_hda_codec_read(codec, nids[i], 0,
5427 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5428 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005429 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005430 spec->keep_vref_in_automute = 1;
5431 break;
5432 }
5433}
5434
5435/* Set VREF on speaker pins on imac91 */
5436static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5437 const struct alc_fixup *fix, int action)
5438{
5439 struct alc_spec *spec = codec->spec;
5440 static hda_nid_t nids[2] = { 0x18, 0x1a };
5441 int i;
5442
5443 if (action != ALC_FIXUP_ACT_INIT)
5444 return;
5445 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5446 unsigned int val;
5447 val = snd_hda_codec_read(codec, nids[i], 0,
5448 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5449 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005450 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005451 }
5452 spec->keep_vref_in_automute = 1;
5453}
5454
Takashi Iwaie427c232012-07-29 10:04:08 +02005455/* Don't take HP output as primary
5456 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5457 */
5458static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5459 const struct alc_fixup *fix, int action)
5460{
5461 struct alc_spec *spec = codec->spec;
5462 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5463 spec->no_primary_hp = 1;
5464}
5465
Takashi Iwai1d045db2011-07-07 18:23:21 +02005466static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005467 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005468 .type = ALC_FIXUP_PINS,
5469 .v.pins = (const struct alc_pincfg[]) {
5470 { 0x15, 0x01080104 }, /* side */
5471 { 0x16, 0x01011012 }, /* rear */
5472 { 0x17, 0x01016011 }, /* clfe */
5473 { }
5474 }
5475 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005476 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005477 .type = ALC_FIXUP_PINS,
5478 .v.pins = (const struct alc_pincfg[]) {
5479 { 0x15, 0x99130112 }, /* rear int speakers */
5480 { 0x16, 0x99130111 }, /* subwoofer */
5481 { }
5482 }
5483 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005484 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005485 .type = ALC_FIXUP_VERBS,
5486 .v.verbs = (const struct hda_verb[]) {
5487 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5488 {}
5489 }
5490 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005491 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005492 .type = ALC_FIXUP_FUNC,
5493 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005494 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005495 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005496 .type = ALC_FIXUP_PINS,
5497 .v.pins = (const struct alc_pincfg[]) {
5498 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5499 { }
5500 }
5501 },
Marton Balint8f239212012-03-05 21:33:23 +01005502 [ALC889_FIXUP_CD] = {
5503 .type = ALC_FIXUP_PINS,
5504 .v.pins = (const struct alc_pincfg[]) {
5505 { 0x1c, 0x993301f0 }, /* CD */
5506 { }
5507 }
5508 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005509 [ALC889_FIXUP_VAIO_TT] = {
5510 .type = ALC_FIXUP_PINS,
5511 .v.pins = (const struct alc_pincfg[]) {
5512 { 0x17, 0x90170111 }, /* hidden surround speaker */
5513 { }
5514 }
5515 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005516 [ALC888_FIXUP_EEE1601] = {
5517 .type = ALC_FIXUP_VERBS,
5518 .v.verbs = (const struct hda_verb[]) {
5519 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5520 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5521 { }
5522 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005523 },
5524 [ALC882_FIXUP_EAPD] = {
5525 .type = ALC_FIXUP_VERBS,
5526 .v.verbs = (const struct hda_verb[]) {
5527 /* change to EAPD mode */
5528 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5529 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5530 { }
5531 }
5532 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005533 [ALC883_FIXUP_EAPD] = {
5534 .type = ALC_FIXUP_VERBS,
5535 .v.verbs = (const struct hda_verb[]) {
5536 /* change to EAPD mode */
5537 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5538 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5539 { }
5540 }
5541 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005542 [ALC883_FIXUP_ACER_EAPD] = {
5543 .type = ALC_FIXUP_VERBS,
5544 .v.verbs = (const struct hda_verb[]) {
5545 /* eanable EAPD on Acer laptops */
5546 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5547 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5548 { }
5549 }
5550 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005551 [ALC882_FIXUP_GPIO1] = {
5552 .type = ALC_FIXUP_VERBS,
5553 .v.verbs = alc_gpio1_init_verbs,
5554 },
5555 [ALC882_FIXUP_GPIO2] = {
5556 .type = ALC_FIXUP_VERBS,
5557 .v.verbs = alc_gpio2_init_verbs,
5558 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005559 [ALC882_FIXUP_GPIO3] = {
5560 .type = ALC_FIXUP_VERBS,
5561 .v.verbs = alc_gpio3_init_verbs,
5562 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005563 [ALC882_FIXUP_ASUS_W2JC] = {
5564 .type = ALC_FIXUP_VERBS,
5565 .v.verbs = alc_gpio1_init_verbs,
5566 .chained = true,
5567 .chain_id = ALC882_FIXUP_EAPD,
5568 },
5569 [ALC889_FIXUP_COEF] = {
5570 .type = ALC_FIXUP_FUNC,
5571 .v.func = alc889_fixup_coef,
5572 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005573 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5574 .type = ALC_FIXUP_PINS,
5575 .v.pins = (const struct alc_pincfg[]) {
5576 { 0x16, 0x99130111 }, /* CLFE speaker */
5577 { 0x17, 0x99130112 }, /* surround speaker */
5578 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005579 },
5580 .chained = true,
5581 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005582 },
5583 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5584 .type = ALC_FIXUP_PINS,
5585 .v.pins = (const struct alc_pincfg[]) {
5586 { 0x16, 0x99130111 }, /* CLFE speaker */
5587 { 0x1b, 0x99130112 }, /* surround speaker */
5588 { }
5589 },
5590 .chained = true,
5591 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5592 },
5593 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5594 /* additional init verbs for Acer Aspire 8930G */
5595 .type = ALC_FIXUP_VERBS,
5596 .v.verbs = (const struct hda_verb[]) {
5597 /* Enable all DACs */
5598 /* DAC DISABLE/MUTE 1? */
5599 /* setting bits 1-5 disables DAC nids 0x02-0x06
5600 * apparently. Init=0x38 */
5601 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5602 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5603 /* DAC DISABLE/MUTE 2? */
5604 /* some bit here disables the other DACs.
5605 * Init=0x4900 */
5606 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5607 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5608 /* DMIC fix
5609 * This laptop has a stereo digital microphone.
5610 * The mics are only 1cm apart which makes the stereo
5611 * useless. However, either the mic or the ALC889
5612 * makes the signal become a difference/sum signal
5613 * instead of standard stereo, which is annoying.
5614 * So instead we flip this bit which makes the
5615 * codec replicate the sum signal to both channels,
5616 * turning it into a normal mono mic.
5617 */
5618 /* DMIC_CONTROL? Init value = 0x0001 */
5619 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5620 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5621 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5622 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5623 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005624 },
5625 .chained = true,
5626 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005627 },
Takashi Iwai56710872011-11-14 17:42:11 +01005628 [ALC885_FIXUP_MACPRO_GPIO] = {
5629 .type = ALC_FIXUP_FUNC,
5630 .v.func = alc885_fixup_macpro_gpio,
5631 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005632 [ALC889_FIXUP_DAC_ROUTE] = {
5633 .type = ALC_FIXUP_FUNC,
5634 .v.func = alc889_fixup_dac_route,
5635 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005636 [ALC889_FIXUP_MBP_VREF] = {
5637 .type = ALC_FIXUP_FUNC,
5638 .v.func = alc889_fixup_mbp_vref,
5639 .chained = true,
5640 .chain_id = ALC882_FIXUP_GPIO1,
5641 },
5642 [ALC889_FIXUP_IMAC91_VREF] = {
5643 .type = ALC_FIXUP_FUNC,
5644 .v.func = alc889_fixup_imac91_vref,
5645 .chained = true,
5646 .chain_id = ALC882_FIXUP_GPIO1,
5647 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005648 [ALC882_FIXUP_INV_DMIC] = {
5649 .type = ALC_FIXUP_FUNC,
5650 .v.func = alc_fixup_inv_dmic_0x12,
5651 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005652 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5653 .type = ALC_FIXUP_FUNC,
5654 .v.func = alc882_fixup_no_primary_hp,
5655 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656};
5657
5658static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005659 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5660 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5661 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5662 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5663 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5664 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005665 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5666 ALC882_FIXUP_ACER_ASPIRE_4930G),
5667 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5668 ALC882_FIXUP_ACER_ASPIRE_4930G),
5669 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5670 ALC882_FIXUP_ACER_ASPIRE_8930G),
5671 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5672 ALC882_FIXUP_ACER_ASPIRE_8930G),
5673 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5674 ALC882_FIXUP_ACER_ASPIRE_4930G),
5675 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5676 ALC882_FIXUP_ACER_ASPIRE_4930G),
5677 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5678 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005679 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005680 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5681 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005682 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005683 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005684 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005685 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005686 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005687 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005688 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005689 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005690 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005691
5692 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005693 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5694 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5695 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005696 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5697 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5698 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005699 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5700 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005701 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005702 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5703 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5704 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5705 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005706 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005707 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5708 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5709 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005710 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005711 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005712 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5713 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5714 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005715
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005716 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005717 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005718 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005719 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005720 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005721 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5722 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005723 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005724 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005725 {}
5726};
5727
Takashi Iwai912093b2012-04-11 14:03:41 +02005728static const struct alc_model_fixup alc882_fixup_models[] = {
5729 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5730 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5731 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005732 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005733 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005734 {}
5735};
5736
Takashi Iwai1d045db2011-07-07 18:23:21 +02005737/*
5738 * BIOS auto configuration
5739 */
5740/* almost identical with ALC880 parser... */
5741static int alc882_parse_auto_config(struct hda_codec *codec)
5742{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005744 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5745 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005746}
5747
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748/*
5749 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750static int patch_alc882(struct hda_codec *codec)
5751{
5752 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005753 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754
Takashi Iwai3de95172012-05-07 18:03:15 +02005755 err = alc_alloc_spec(codec, 0x0b);
5756 if (err < 0)
5757 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005758
Takashi Iwai3de95172012-05-07 18:03:15 +02005759 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005760
5761 switch (codec->vendor_id) {
5762 case 0x10ec0882:
5763 case 0x10ec0885:
5764 break;
5765 default:
5766 /* ALC883 and variants */
5767 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5768 break;
5769 }
5770
Takashi Iwai912093b2012-04-11 14:03:41 +02005771 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5772 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005773 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005774
5775 alc_auto_parse_customize_define(codec);
5776
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005777 /* automatic parse from the BIOS config */
5778 err = alc882_parse_auto_config(codec);
5779 if (err < 0)
5780 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005781
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005782 if (!spec->no_analog && has_cdefine_beep(codec)) {
5783 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005784 if (err < 0)
5785 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005787 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005788
Takashi Iwai1d045db2011-07-07 18:23:21 +02005789 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005790
Takashi Iwai589876e2012-02-20 15:47:55 +01005791 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5792
Takashi Iwai1d045db2011-07-07 18:23:21 +02005793 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005794
5795 error:
5796 alc_free(codec);
5797 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005798}
5799
5800
5801/*
5802 * ALC262 support
5803 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005804static int alc262_parse_auto_config(struct hda_codec *codec)
5805{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005806 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005807 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5808 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005809}
5810
5811/*
5812 * Pin config fixes
5813 */
5814enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005815 ALC262_FIXUP_FSC_H270,
5816 ALC262_FIXUP_HP_Z200,
5817 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005818 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005819 ALC262_FIXUP_BENQ,
5820 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005821 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005822};
5823
5824static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005825 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005826 .type = ALC_FIXUP_PINS,
5827 .v.pins = (const struct alc_pincfg[]) {
5828 { 0x14, 0x99130110 }, /* speaker */
5829 { 0x15, 0x0221142f }, /* front HP */
5830 { 0x1b, 0x0121141f }, /* rear HP */
5831 { }
5832 }
5833 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005834 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005835 .type = ALC_FIXUP_PINS,
5836 .v.pins = (const struct alc_pincfg[]) {
5837 { 0x16, 0x99130120 }, /* internal speaker */
5838 { }
5839 }
5840 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005841 [ALC262_FIXUP_TYAN] = {
5842 .type = ALC_FIXUP_PINS,
5843 .v.pins = (const struct alc_pincfg[]) {
5844 { 0x14, 0x1993e1f0 }, /* int AUX */
5845 { }
5846 }
5847 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005848 [ALC262_FIXUP_LENOVO_3000] = {
5849 .type = ALC_FIXUP_VERBS,
5850 .v.verbs = (const struct hda_verb[]) {
5851 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005852 {}
5853 },
5854 .chained = true,
5855 .chain_id = ALC262_FIXUP_BENQ,
5856 },
5857 [ALC262_FIXUP_BENQ] = {
5858 .type = ALC_FIXUP_VERBS,
5859 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005860 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5861 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5862 {}
5863 }
5864 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005865 [ALC262_FIXUP_BENQ_T31] = {
5866 .type = ALC_FIXUP_VERBS,
5867 .v.verbs = (const struct hda_verb[]) {
5868 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5869 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5870 {}
5871 }
5872 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005873 [ALC262_FIXUP_INV_DMIC] = {
5874 .type = ALC_FIXUP_FUNC,
5875 .v.func = alc_fixup_inv_dmic_0x12,
5876 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005877};
5878
5879static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005880 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005881 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5882 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005883 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5884 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005885 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005886 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5887 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005888 {}
5889};
5890
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005891static const struct alc_model_fixup alc262_fixup_models[] = {
5892 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5893 {}
5894};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005895
Takashi Iwai1d045db2011-07-07 18:23:21 +02005896/*
5897 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005898static int patch_alc262(struct hda_codec *codec)
5899{
5900 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005901 int err;
5902
Takashi Iwai3de95172012-05-07 18:03:15 +02005903 err = alc_alloc_spec(codec, 0x0b);
5904 if (err < 0)
5905 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005906
Takashi Iwai3de95172012-05-07 18:03:15 +02005907 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005908
5909#if 0
5910 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5911 * under-run
5912 */
5913 {
5914 int tmp;
5915 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5916 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5917 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5918 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5919 }
5920#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005921 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5922
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005923 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5924 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005925 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005926
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005927 alc_auto_parse_customize_define(codec);
5928
Takashi Iwai42399f72011-11-07 17:18:44 +01005929 /* automatic parse from the BIOS config */
5930 err = alc262_parse_auto_config(codec);
5931 if (err < 0)
5932 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005933
Takashi Iwai1d045db2011-07-07 18:23:21 +02005934 if (!spec->no_analog && has_cdefine_beep(codec)) {
5935 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005936 if (err < 0)
5937 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005938 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005939 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005940
Takashi Iwai1d045db2011-07-07 18:23:21 +02005941 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005942 spec->shutup = alc_eapd_shutup;
5943
Takashi Iwai589876e2012-02-20 15:47:55 +01005944 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5945
Takashi Iwai1d045db2011-07-07 18:23:21 +02005946 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005947
5948 error:
5949 alc_free(codec);
5950 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005951}
5952
5953/*
5954 * ALC268
5955 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005956/* bind Beep switches of both NID 0x0f and 0x10 */
5957static const struct hda_bind_ctls alc268_bind_beep_sw = {
5958 .ops = &snd_hda_bind_sw,
5959 .values = {
5960 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5961 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5962 0
5963 },
5964};
5965
5966static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5967 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5968 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5969 { }
5970};
5971
5972/* set PCBEEP vol = 0, mute connections */
5973static const struct hda_verb alc268_beep_init_verbs[] = {
5974 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5975 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5976 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5977 { }
5978};
5979
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005980enum {
5981 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005982 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005983};
5984
5985static const struct alc_fixup alc268_fixups[] = {
5986 [ALC268_FIXUP_INV_DMIC] = {
5987 .type = ALC_FIXUP_FUNC,
5988 .v.func = alc_fixup_inv_dmic_0x12,
5989 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005990 [ALC268_FIXUP_HP_EAPD] = {
5991 .type = ALC_FIXUP_VERBS,
5992 .v.verbs = (const struct hda_verb[]) {
5993 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5994 {}
5995 }
5996 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005997};
5998
5999static const struct alc_model_fixup alc268_fixup_models[] = {
6000 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02006001 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
6002 {}
6003};
6004
6005static const struct snd_pci_quirk alc268_fixup_tbl[] = {
6006 /* below is codec SSID since multiple Toshiba laptops have the
6007 * same PCI SSID 1179:ff00
6008 */
6009 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006010 {}
6011};
6012
Takashi Iwai1d045db2011-07-07 18:23:21 +02006013/*
6014 * BIOS auto configuration
6015 */
6016static int alc268_parse_auto_config(struct hda_codec *codec)
6017{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006018 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02006019 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006020 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
6021 if (err > 0) {
6022 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
6023 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02006024 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006025 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006026 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006027 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006028}
6029
Takashi Iwai1d045db2011-07-07 18:23:21 +02006030/*
6031 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006032static int patch_alc268(struct hda_codec *codec)
6033{
6034 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006035 int i, has_beep, err;
6036
Takashi Iwai1d045db2011-07-07 18:23:21 +02006037 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006038 err = alc_alloc_spec(codec, 0);
6039 if (err < 0)
6040 return err;
6041
6042 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006043
Takashi Iwaicb766402012-10-20 10:55:21 +02006044 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006045 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6046
Takashi Iwai6ebb8052011-08-16 15:15:40 +02006047 /* automatic parse from the BIOS config */
6048 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006049 if (err < 0)
6050 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006051
Takashi Iwai1d045db2011-07-07 18:23:21 +02006052 has_beep = 0;
6053 for (i = 0; i < spec->num_mixers; i++) {
6054 if (spec->mixers[i] == alc268_beep_mixer) {
6055 has_beep = 1;
6056 break;
6057 }
6058 }
6059
6060 if (has_beep) {
6061 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006062 if (err < 0)
6063 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006064 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
6065 /* override the amp caps for beep generator */
6066 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
6067 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
6068 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
6069 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6070 (0 << AC_AMPCAP_MUTE_SHIFT));
6071 }
6072
Takashi Iwai1d045db2011-07-07 18:23:21 +02006073 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006074 spec->shutup = alc_eapd_shutup;
6075
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006076 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6077
Takashi Iwai1d045db2011-07-07 18:23:21 +02006078 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006079
6080 error:
6081 alc_free(codec);
6082 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006083}
6084
6085/*
6086 * ALC269
6087 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006088static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6089 .substreams = 1,
6090 .channels_min = 2,
6091 .channels_max = 8,
6092 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6093 /* NID is set in alc_build_pcms */
6094 .ops = {
6095 .open = alc_playback_pcm_open,
6096 .prepare = alc_playback_pcm_prepare,
6097 .cleanup = alc_playback_pcm_cleanup
6098 },
6099};
6100
6101static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6102 .substreams = 1,
6103 .channels_min = 2,
6104 .channels_max = 2,
6105 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6106 /* NID is set in alc_build_pcms */
6107};
6108
Takashi Iwai1d045db2011-07-07 18:23:21 +02006109/* different alc269-variants */
6110enum {
6111 ALC269_TYPE_ALC269VA,
6112 ALC269_TYPE_ALC269VB,
6113 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006114 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006115 ALC269_TYPE_ALC280,
6116 ALC269_TYPE_ALC282,
6117 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006118};
6119
6120/*
6121 * BIOS auto configuration
6122 */
6123static int alc269_parse_auto_config(struct hda_codec *codec)
6124{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006125 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006126 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6127 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6128 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006129 const hda_nid_t *ssids;
6130
6131 switch (spec->codec_variant) {
6132 case ALC269_TYPE_ALC269VA:
6133 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006134 case ALC269_TYPE_ALC280:
6135 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006136 ssids = alc269va_ssids;
6137 break;
6138 case ALC269_TYPE_ALC269VB:
6139 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006140 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006141 ssids = alc269_ssids;
6142 break;
6143 default:
6144 ssids = alc269_ssids;
6145 break;
6146 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006147
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006148 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006149}
6150
Kailang Yang1387e2d2012-11-08 10:23:18 +01006151static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006152{
6153 int val = alc_read_coef_idx(codec, 0x04);
6154 if (power_up)
6155 val |= 1 << 11;
6156 else
6157 val &= ~(1 << 11);
6158 alc_write_coef_idx(codec, 0x04, val);
6159}
6160
6161static void alc269_shutup(struct hda_codec *codec)
6162{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006163 struct alc_spec *spec = codec->spec;
6164
6165 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6166 return;
6167
Kailang Yang1387e2d2012-11-08 10:23:18 +01006168 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6169 alc269vb_toggle_power_output(codec, 0);
6170 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6171 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006172 msleep(150);
6173 }
6174}
6175
Takashi Iwai2a439522011-07-26 09:52:50 +02006176#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006177static int alc269_resume(struct hda_codec *codec)
6178{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006179 struct alc_spec *spec = codec->spec;
6180
Kailang Yang1387e2d2012-11-08 10:23:18 +01006181 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6182 alc269vb_toggle_power_output(codec, 0);
6183 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006184 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006185 msleep(150);
6186 }
6187
6188 codec->patch_ops.init(codec);
6189
Kailang Yang1387e2d2012-11-08 10:23:18 +01006190 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6191 alc269vb_toggle_power_output(codec, 1);
6192 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006193 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006194 msleep(200);
6195 }
6196
Takashi Iwai1d045db2011-07-07 18:23:21 +02006197 snd_hda_codec_resume_amp(codec);
6198 snd_hda_codec_resume_cache(codec);
6199 hda_call_check_power_status(codec, 0x01);
6200 return 0;
6201}
Takashi Iwai2a439522011-07-26 09:52:50 +02006202#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006203
David Henningsson108cc102012-07-20 10:37:25 +02006204static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6205 const struct alc_fixup *fix, int action)
6206{
6207 struct alc_spec *spec = codec->spec;
6208
6209 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6210 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6211}
6212
Takashi Iwai1d045db2011-07-07 18:23:21 +02006213static void alc269_fixup_hweq(struct hda_codec *codec,
6214 const struct alc_fixup *fix, int action)
6215{
6216 int coef;
6217
6218 if (action != ALC_FIXUP_ACT_INIT)
6219 return;
6220 coef = alc_read_coef_idx(codec, 0x1e);
6221 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6222}
6223
6224static void alc271_fixup_dmic(struct hda_codec *codec,
6225 const struct alc_fixup *fix, int action)
6226{
6227 static const struct hda_verb verbs[] = {
6228 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6229 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6230 {}
6231 };
6232 unsigned int cfg;
6233
6234 if (strcmp(codec->chip_name, "ALC271X"))
6235 return;
6236 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6237 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6238 snd_hda_sequence_write(codec, verbs);
6239}
6240
Takashi Iwai017f2a12011-07-09 14:42:25 +02006241static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6242 const struct alc_fixup *fix, int action)
6243{
6244 struct alc_spec *spec = codec->spec;
6245
6246 if (action != ALC_FIXUP_ACT_PROBE)
6247 return;
6248
6249 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6250 * fix the sample rate of analog I/O to 44.1kHz
6251 */
6252 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6253 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6254}
6255
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006256static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6257 const struct alc_fixup *fix, int action)
6258{
6259 int coef;
6260
6261 if (action != ALC_FIXUP_ACT_INIT)
6262 return;
6263 /* The digital-mic unit sends PDM (differential signal) instead of
6264 * the standard PCM, thus you can't record a valid mono stream as is.
6265 * Below is a workaround specific to ALC269 to control the dmic
6266 * signal source as mono.
6267 */
6268 coef = alc_read_coef_idx(codec, 0x07);
6269 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6270}
6271
Takashi Iwai24519912011-08-16 15:08:49 +02006272static void alc269_quanta_automute(struct hda_codec *codec)
6273{
David Henningsson42cf0d02011-09-20 12:04:56 +02006274 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006275
6276 snd_hda_codec_write(codec, 0x20, 0,
6277 AC_VERB_SET_COEF_INDEX, 0x0c);
6278 snd_hda_codec_write(codec, 0x20, 0,
6279 AC_VERB_SET_PROC_COEF, 0x680);
6280
6281 snd_hda_codec_write(codec, 0x20, 0,
6282 AC_VERB_SET_COEF_INDEX, 0x0c);
6283 snd_hda_codec_write(codec, 0x20, 0,
6284 AC_VERB_SET_PROC_COEF, 0x480);
6285}
6286
6287static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6288 const struct alc_fixup *fix, int action)
6289{
6290 struct alc_spec *spec = codec->spec;
6291 if (action != ALC_FIXUP_ACT_PROBE)
6292 return;
6293 spec->automute_hook = alc269_quanta_automute;
6294}
6295
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006296/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6297static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6298{
6299 struct hda_codec *codec = private_data;
6300 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6301 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6302 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6303}
6304
6305static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6306 const struct alc_fixup *fix, int action)
6307{
6308 struct alc_spec *spec = codec->spec;
6309 switch (action) {
6310 case ALC_FIXUP_ACT_BUILD:
6311 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6312 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6313 /* fallthru */
6314 case ALC_FIXUP_ACT_INIT:
6315 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6316 break;
6317 }
6318}
6319
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006320/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6321static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6322{
6323 struct hda_codec *codec = private_data;
6324 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006325 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006326}
6327
6328static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6329 const struct alc_fixup *fix, int action)
6330{
6331 struct alc_spec *spec = codec->spec;
6332 switch (action) {
6333 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006334 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006335 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006336 /* fallthru */
6337 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006338 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006339 break;
6340 }
6341}
6342
Dylan Reid08a978d2012-11-18 22:56:40 -08006343static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6344 const struct alc_fixup *fix,
6345 int action)
6346{
6347 struct alc_spec *spec = codec->spec;
6348
6349 if (action == ALC_FIXUP_ACT_PROBE)
6350 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6351 spec->autocfg.hp_pins[0]);
6352}
David Henningsson693b6132012-06-22 19:12:10 +02006353
Takashi Iwai1d045db2011-07-07 18:23:21 +02006354enum {
6355 ALC269_FIXUP_SONY_VAIO,
6356 ALC275_FIXUP_SONY_VAIO_GPIO2,
6357 ALC269_FIXUP_DELL_M101Z,
6358 ALC269_FIXUP_SKU_IGNORE,
6359 ALC269_FIXUP_ASUS_G73JW,
6360 ALC269_FIXUP_LENOVO_EAPD,
6361 ALC275_FIXUP_SONY_HWEQ,
6362 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006363 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006364 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006365 ALC269_FIXUP_QUANTA_MUTE,
6366 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006367 ALC269_FIXUP_AMIC,
6368 ALC269_FIXUP_DMIC,
6369 ALC269VB_FIXUP_AMIC,
6370 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006371 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006372 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006373 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006374 ALC269_FIXUP_LENOVO_DOCK,
6375 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006376 ALC271_FIXUP_AMIC_MIC2,
6377 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006378};
6379
6380static const struct alc_fixup alc269_fixups[] = {
6381 [ALC269_FIXUP_SONY_VAIO] = {
6382 .type = ALC_FIXUP_VERBS,
6383 .v.verbs = (const struct hda_verb[]) {
6384 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6385 {}
6386 }
6387 },
6388 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6389 .type = ALC_FIXUP_VERBS,
6390 .v.verbs = (const struct hda_verb[]) {
6391 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6392 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6393 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6394 { }
6395 },
6396 .chained = true,
6397 .chain_id = ALC269_FIXUP_SONY_VAIO
6398 },
6399 [ALC269_FIXUP_DELL_M101Z] = {
6400 .type = ALC_FIXUP_VERBS,
6401 .v.verbs = (const struct hda_verb[]) {
6402 /* Enables internal speaker */
6403 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6404 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6405 {}
6406 }
6407 },
6408 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006409 .type = ALC_FIXUP_FUNC,
6410 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006411 },
6412 [ALC269_FIXUP_ASUS_G73JW] = {
6413 .type = ALC_FIXUP_PINS,
6414 .v.pins = (const struct alc_pincfg[]) {
6415 { 0x17, 0x99130111 }, /* subwoofer */
6416 { }
6417 }
6418 },
6419 [ALC269_FIXUP_LENOVO_EAPD] = {
6420 .type = ALC_FIXUP_VERBS,
6421 .v.verbs = (const struct hda_verb[]) {
6422 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6423 {}
6424 }
6425 },
6426 [ALC275_FIXUP_SONY_HWEQ] = {
6427 .type = ALC_FIXUP_FUNC,
6428 .v.func = alc269_fixup_hweq,
6429 .chained = true,
6430 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6431 },
6432 [ALC271_FIXUP_DMIC] = {
6433 .type = ALC_FIXUP_FUNC,
6434 .v.func = alc271_fixup_dmic,
6435 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006436 [ALC269_FIXUP_PCM_44K] = {
6437 .type = ALC_FIXUP_FUNC,
6438 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006439 .chained = true,
6440 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006441 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006442 [ALC269_FIXUP_STEREO_DMIC] = {
6443 .type = ALC_FIXUP_FUNC,
6444 .v.func = alc269_fixup_stereo_dmic,
6445 },
Takashi Iwai24519912011-08-16 15:08:49 +02006446 [ALC269_FIXUP_QUANTA_MUTE] = {
6447 .type = ALC_FIXUP_FUNC,
6448 .v.func = alc269_fixup_quanta_mute,
6449 },
6450 [ALC269_FIXUP_LIFEBOOK] = {
6451 .type = ALC_FIXUP_PINS,
6452 .v.pins = (const struct alc_pincfg[]) {
6453 { 0x1a, 0x2101103f }, /* dock line-out */
6454 { 0x1b, 0x23a11040 }, /* dock mic-in */
6455 { }
6456 },
6457 .chained = true,
6458 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6459 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006460 [ALC269_FIXUP_AMIC] = {
6461 .type = ALC_FIXUP_PINS,
6462 .v.pins = (const struct alc_pincfg[]) {
6463 { 0x14, 0x99130110 }, /* speaker */
6464 { 0x15, 0x0121401f }, /* HP out */
6465 { 0x18, 0x01a19c20 }, /* mic */
6466 { 0x19, 0x99a3092f }, /* int-mic */
6467 { }
6468 },
6469 },
6470 [ALC269_FIXUP_DMIC] = {
6471 .type = ALC_FIXUP_PINS,
6472 .v.pins = (const struct alc_pincfg[]) {
6473 { 0x12, 0x99a3092f }, /* int-mic */
6474 { 0x14, 0x99130110 }, /* speaker */
6475 { 0x15, 0x0121401f }, /* HP out */
6476 { 0x18, 0x01a19c20 }, /* mic */
6477 { }
6478 },
6479 },
6480 [ALC269VB_FIXUP_AMIC] = {
6481 .type = ALC_FIXUP_PINS,
6482 .v.pins = (const struct alc_pincfg[]) {
6483 { 0x14, 0x99130110 }, /* speaker */
6484 { 0x18, 0x01a19c20 }, /* mic */
6485 { 0x19, 0x99a3092f }, /* int-mic */
6486 { 0x21, 0x0121401f }, /* HP out */
6487 { }
6488 },
6489 },
David Henningsson2267ea92012-01-03 08:45:56 +01006490 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006491 .type = ALC_FIXUP_PINS,
6492 .v.pins = (const struct alc_pincfg[]) {
6493 { 0x12, 0x99a3092f }, /* int-mic */
6494 { 0x14, 0x99130110 }, /* speaker */
6495 { 0x18, 0x01a19c20 }, /* mic */
6496 { 0x21, 0x0121401f }, /* HP out */
6497 { }
6498 },
6499 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006500 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6501 .type = ALC_FIXUP_FUNC,
6502 .v.func = alc269_fixup_mic1_mute,
6503 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006504 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6505 .type = ALC_FIXUP_FUNC,
6506 .v.func = alc269_fixup_mic2_mute,
6507 },
David Henningsson693b6132012-06-22 19:12:10 +02006508 [ALC269_FIXUP_INV_DMIC] = {
6509 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006510 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006511 },
David Henningsson108cc102012-07-20 10:37:25 +02006512 [ALC269_FIXUP_LENOVO_DOCK] = {
6513 .type = ALC_FIXUP_PINS,
6514 .v.pins = (const struct alc_pincfg[]) {
6515 { 0x19, 0x23a11040 }, /* dock mic */
6516 { 0x1b, 0x2121103f }, /* dock headphone */
6517 { }
6518 },
6519 .chained = true,
6520 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6521 },
6522 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6523 .type = ALC_FIXUP_FUNC,
6524 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6525 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006526 [ALC271_FIXUP_AMIC_MIC2] = {
6527 .type = ALC_FIXUP_PINS,
6528 .v.pins = (const struct alc_pincfg[]) {
6529 { 0x14, 0x99130110 }, /* speaker */
6530 { 0x19, 0x01a19c20 }, /* mic */
6531 { 0x1b, 0x99a7012f }, /* int-mic */
6532 { 0x21, 0x0121401f }, /* HP out */
6533 { }
6534 },
6535 },
6536 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6537 .type = ALC_FIXUP_FUNC,
6538 .v.func = alc271_hp_gate_mic_jack,
6539 .chained = true,
6540 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6541 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006542};
6543
6544static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006545 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6546 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006547 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006548 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006549 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006550 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006551 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006552 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006553 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6554 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6555 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6556 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6557 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006558 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6559 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6560 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6561 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6562 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006563 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006564 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006565 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006566 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6567 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6568 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6569 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6570 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006571 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006572 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006573 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006574 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006575 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006576 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006577 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006578
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006579#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006580 /* Below is a quirk table taken from the old code.
6581 * Basically the device should work as is without the fixup table.
6582 * If BIOS doesn't give a proper info, enable the corresponding
6583 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006584 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006585 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6586 ALC269_FIXUP_AMIC),
6587 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006588 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6589 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6590 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6591 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6592 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6593 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6594 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6595 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6596 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6597 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6598 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6599 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6600 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6601 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6602 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6603 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6604 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6605 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6606 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6607 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6608 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6609 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6610 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6611 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6612 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6613 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6614 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6615 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6616 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6617 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6618 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6619 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6620 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6621 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6622 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6623 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6624 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6625 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6626#endif
6627 {}
6628};
6629
6630static const struct alc_model_fixup alc269_fixup_models[] = {
6631 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6632 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006633 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6634 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6635 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006636 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006637 {}
6638};
6639
6640
Takashi Iwai546bb672012-03-07 08:37:19 +01006641static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006642{
Kailang Yang526af6e2012-03-07 08:25:20 +01006643 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006644 int val;
6645
Kailang Yang526af6e2012-03-07 08:25:20 +01006646 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006647 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006648
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006649 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006650 alc_write_coef_idx(codec, 0xf, 0x960b);
6651 alc_write_coef_idx(codec, 0xe, 0x8817);
6652 }
6653
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006654 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006655 alc_write_coef_idx(codec, 0xf, 0x960b);
6656 alc_write_coef_idx(codec, 0xe, 0x8814);
6657 }
6658
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006659 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006660 val = alc_read_coef_idx(codec, 0x04);
6661 /* Power up output pin */
6662 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6663 }
6664
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006665 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006666 val = alc_read_coef_idx(codec, 0xd);
6667 if ((val & 0x0c00) >> 10 != 0x1) {
6668 /* Capless ramp up clock control */
6669 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6670 }
6671 val = alc_read_coef_idx(codec, 0x17);
6672 if ((val & 0x01c0) >> 6 != 0x4) {
6673 /* Class D power on reset */
6674 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6675 }
6676 }
6677
6678 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6679 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6680
6681 val = alc_read_coef_idx(codec, 0x4); /* HP */
6682 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006683}
6684
6685/*
6686 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006687static int patch_alc269(struct hda_codec *codec)
6688{
6689 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006690 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006691
Takashi Iwai3de95172012-05-07 18:03:15 +02006692 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006693 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006694 return err;
6695
6696 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006697
Herton Ronaldo Krzesinski9f720bb92012-09-27 10:38:14 -03006698 alc_pick_fixup(codec, alc269_fixup_models,
6699 alc269_fixup_tbl, alc269_fixups);
6700 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6701
6702 alc_auto_parse_customize_define(codec);
6703
Kailang Yang065380f2013-01-10 10:25:48 +01006704 switch (codec->vendor_id) {
6705 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006706 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006707 switch (alc_get_coef0(codec) & 0x00f0) {
6708 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006709 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006710 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006711 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006712 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006713 break;
6714 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006715 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6716 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006717 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006718 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006719 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006720 case 0x0030:
6721 spec->codec_variant = ALC269_TYPE_ALC269VD;
6722 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006723 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006724 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006725 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006726 if (err < 0)
6727 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006728 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006729 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006730 break;
6731
6732 case 0x10ec0280:
6733 case 0x10ec0290:
6734 spec->codec_variant = ALC269_TYPE_ALC280;
6735 break;
6736 case 0x10ec0282:
6737 case 0x10ec0283:
6738 spec->codec_variant = ALC269_TYPE_ALC282;
6739 break;
6740 case 0x10ec0284:
6741 case 0x10ec0292:
6742 spec->codec_variant = ALC269_TYPE_ALC284;
6743 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006744 }
6745
Takashi Iwaia4297b52011-08-23 18:40:12 +02006746 /* automatic parse from the BIOS config */
6747 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006748 if (err < 0)
6749 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006750
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006751 if (!spec->no_analog && has_cdefine_beep(codec)) {
6752 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006753 if (err < 0)
6754 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006755 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006756 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006757
Takashi Iwai1d045db2011-07-07 18:23:21 +02006758 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006759#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006760 codec->patch_ops.resume = alc269_resume;
6761#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006762 spec->shutup = alc269_shutup;
6763
Takashi Iwai589876e2012-02-20 15:47:55 +01006764 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6765
Takashi Iwai1d045db2011-07-07 18:23:21 +02006766 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006767
6768 error:
6769 alc_free(codec);
6770 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006771}
6772
6773/*
6774 * ALC861
6775 */
6776
Takashi Iwai1d045db2011-07-07 18:23:21 +02006777static int alc861_parse_auto_config(struct hda_codec *codec)
6778{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006779 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006780 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6781 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006782}
6783
Takashi Iwai1d045db2011-07-07 18:23:21 +02006784/* Pin config fixes */
6785enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006786 ALC861_FIXUP_FSC_AMILO_PI1505,
6787 ALC861_FIXUP_AMP_VREF_0F,
6788 ALC861_FIXUP_NO_JACK_DETECT,
6789 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006790};
6791
Takashi Iwai31150f22012-01-30 10:54:08 +01006792/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6793static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6794 const struct alc_fixup *fix, int action)
6795{
6796 struct alc_spec *spec = codec->spec;
6797 unsigned int val;
6798
6799 if (action != ALC_FIXUP_ACT_INIT)
6800 return;
6801 val = snd_hda_codec_read(codec, 0x0f, 0,
6802 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6803 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6804 val |= AC_PINCTL_IN_EN;
6805 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006806 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006807 spec->keep_vref_in_automute = 1;
6808}
6809
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006810/* suppress the jack-detection */
6811static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6812 const struct alc_fixup *fix, int action)
6813{
6814 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6815 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006816}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006817
Takashi Iwai1d045db2011-07-07 18:23:21 +02006818static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006819 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006820 .type = ALC_FIXUP_PINS,
6821 .v.pins = (const struct alc_pincfg[]) {
6822 { 0x0b, 0x0221101f }, /* HP */
6823 { 0x0f, 0x90170310 }, /* speaker */
6824 { }
6825 }
6826 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006827 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006828 .type = ALC_FIXUP_FUNC,
6829 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006830 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006831 [ALC861_FIXUP_NO_JACK_DETECT] = {
6832 .type = ALC_FIXUP_FUNC,
6833 .v.func = alc_fixup_no_jack_detect,
6834 },
6835 [ALC861_FIXUP_ASUS_A6RP] = {
6836 .type = ALC_FIXUP_FUNC,
6837 .v.func = alc861_fixup_asus_amp_vref_0f,
6838 .chained = true,
6839 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6840 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006841};
6842
6843static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006844 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6845 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6846 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6847 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6848 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6849 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006850 {}
6851};
6852
6853/*
6854 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006855static int patch_alc861(struct hda_codec *codec)
6856{
6857 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006858 int err;
6859
Takashi Iwai3de95172012-05-07 18:03:15 +02006860 err = alc_alloc_spec(codec, 0x15);
6861 if (err < 0)
6862 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006863
Takashi Iwai3de95172012-05-07 18:03:15 +02006864 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006865
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006866 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6867 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006868
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006869 /* automatic parse from the BIOS config */
6870 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006871 if (err < 0)
6872 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006873
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006874 if (!spec->no_analog) {
6875 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006876 if (err < 0)
6877 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006878 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6879 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006880
Takashi Iwai1d045db2011-07-07 18:23:21 +02006881 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006882#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006883 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006884#endif
6885
Takashi Iwai589876e2012-02-20 15:47:55 +01006886 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6887
Takashi Iwai1d045db2011-07-07 18:23:21 +02006888 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006889
6890 error:
6891 alc_free(codec);
6892 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006893}
6894
6895/*
6896 * ALC861-VD support
6897 *
6898 * Based on ALC882
6899 *
6900 * In addition, an independent DAC
6901 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006902static int alc861vd_parse_auto_config(struct hda_codec *codec)
6903{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006904 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006905 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6906 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006907}
6908
Takashi Iwai1d045db2011-07-07 18:23:21 +02006909enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006910 ALC660VD_FIX_ASUS_GPIO1,
6911 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006912};
6913
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006914/* exclude VREF80 */
6915static void alc861vd_fixup_dallas(struct hda_codec *codec,
6916 const struct alc_fixup *fix, int action)
6917{
6918 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006919 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6920 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006921 }
6922}
6923
Takashi Iwai1d045db2011-07-07 18:23:21 +02006924static const struct alc_fixup alc861vd_fixups[] = {
6925 [ALC660VD_FIX_ASUS_GPIO1] = {
6926 .type = ALC_FIXUP_VERBS,
6927 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006928 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006929 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6930 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6931 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6932 { }
6933 }
6934 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006935 [ALC861VD_FIX_DALLAS] = {
6936 .type = ALC_FIXUP_FUNC,
6937 .v.func = alc861vd_fixup_dallas,
6938 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006939};
6940
6941static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006942 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006943 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006944 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006945 {}
6946};
6947
Takashi Iwai1d045db2011-07-07 18:23:21 +02006948/*
6949 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006950static int patch_alc861vd(struct hda_codec *codec)
6951{
6952 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006953 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006954
Takashi Iwai3de95172012-05-07 18:03:15 +02006955 err = alc_alloc_spec(codec, 0x0b);
6956 if (err < 0)
6957 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006958
Takashi Iwai3de95172012-05-07 18:03:15 +02006959 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006960
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006961 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6962 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006963
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006964 /* automatic parse from the BIOS config */
6965 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006966 if (err < 0)
6967 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006968
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006969 if (!spec->no_analog) {
6970 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006971 if (err < 0)
6972 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006973 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6974 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006975
Takashi Iwai1d045db2011-07-07 18:23:21 +02006976 codec->patch_ops = alc_patch_ops;
6977
Takashi Iwai1d045db2011-07-07 18:23:21 +02006978 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006979
Takashi Iwai589876e2012-02-20 15:47:55 +01006980 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6981
Takashi Iwai1d045db2011-07-07 18:23:21 +02006982 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006983
6984 error:
6985 alc_free(codec);
6986 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006987}
6988
6989/*
6990 * ALC662 support
6991 *
6992 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6993 * configuration. Each pin widget can choose any input DACs and a mixer.
6994 * Each ADC is connected from a mixer of all inputs. This makes possible
6995 * 6-channel independent captures.
6996 *
6997 * In addition, an independent DAC for the multi-playback (not used in this
6998 * driver yet).
6999 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02007000
7001/*
7002 * BIOS auto configuration
7003 */
7004
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007005static int alc662_parse_auto_config(struct hda_codec *codec)
7006{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02007007 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007008 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
7009 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
7010 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02007011
Kailang Yang6227cdc2010-02-25 08:36:52 +01007012 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
7013 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007014 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01007015 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007016 ssids = alc662_ssids;
7017 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007018}
7019
Todd Broch6be79482010-12-07 16:51:05 -08007020static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007021 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01007022{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007023 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01007024 return;
Todd Broch6be79482010-12-07 16:51:05 -08007025 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
7026 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
7027 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
7028 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
7029 (0 << AC_AMPCAP_MUTE_SHIFT)))
7030 printk(KERN_WARNING
7031 "hda_codec: failed to override amp caps for NID 0x2\n");
7032}
7033
David Henningsson6cb3b702010-09-09 08:51:44 +02007034enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04007035 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02007036 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08007037 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007038 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02007039 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007040 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02007041 ALC662_FIXUP_ASUS_MODE1,
7042 ALC662_FIXUP_ASUS_MODE2,
7043 ALC662_FIXUP_ASUS_MODE3,
7044 ALC662_FIXUP_ASUS_MODE4,
7045 ALC662_FIXUP_ASUS_MODE5,
7046 ALC662_FIXUP_ASUS_MODE6,
7047 ALC662_FIXUP_ASUS_MODE7,
7048 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01007049 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02007050 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02007051 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02007052};
7053
7054static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04007055 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007056 .type = ALC_FIXUP_PINS,
7057 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04007058 { 0x15, 0x99130112 }, /* subwoofer */
7059 { }
7060 }
7061 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007062 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007063 .type = ALC_FIXUP_PINS,
7064 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02007065 { 0x17, 0x99130112 }, /* subwoofer */
7066 { }
7067 }
7068 },
Todd Broch6be79482010-12-07 16:51:05 -08007069 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007070 .type = ALC_FIXUP_FUNC,
7071 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007072 },
7073 [ALC662_FIXUP_CZC_P10T] = {
7074 .type = ALC_FIXUP_VERBS,
7075 .v.verbs = (const struct hda_verb[]) {
7076 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7077 {}
7078 }
7079 },
David Henningsson94024cd2011-04-29 14:10:55 +02007080 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02007081 .type = ALC_FIXUP_FUNC,
7082 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02007083 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007084 [ALC662_FIXUP_HP_RP5800] = {
7085 .type = ALC_FIXUP_PINS,
7086 .v.pins = (const struct alc_pincfg[]) {
7087 { 0x14, 0x0221201f }, /* HP out */
7088 { }
7089 },
7090 .chained = true,
7091 .chain_id = ALC662_FIXUP_SKU_IGNORE
7092 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007093 [ALC662_FIXUP_ASUS_MODE1] = {
7094 .type = ALC_FIXUP_PINS,
7095 .v.pins = (const struct alc_pincfg[]) {
7096 { 0x14, 0x99130110 }, /* speaker */
7097 { 0x18, 0x01a19c20 }, /* mic */
7098 { 0x19, 0x99a3092f }, /* int-mic */
7099 { 0x21, 0x0121401f }, /* HP out */
7100 { }
7101 },
7102 .chained = true,
7103 .chain_id = ALC662_FIXUP_SKU_IGNORE
7104 },
7105 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007106 .type = ALC_FIXUP_PINS,
7107 .v.pins = (const struct alc_pincfg[]) {
7108 { 0x14, 0x99130110 }, /* speaker */
7109 { 0x18, 0x01a19820 }, /* mic */
7110 { 0x19, 0x99a3092f }, /* int-mic */
7111 { 0x1b, 0x0121401f }, /* HP out */
7112 { }
7113 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007114 .chained = true,
7115 .chain_id = ALC662_FIXUP_SKU_IGNORE
7116 },
7117 [ALC662_FIXUP_ASUS_MODE3] = {
7118 .type = ALC_FIXUP_PINS,
7119 .v.pins = (const struct alc_pincfg[]) {
7120 { 0x14, 0x99130110 }, /* speaker */
7121 { 0x15, 0x0121441f }, /* HP */
7122 { 0x18, 0x01a19840 }, /* mic */
7123 { 0x19, 0x99a3094f }, /* int-mic */
7124 { 0x21, 0x01211420 }, /* HP2 */
7125 { }
7126 },
7127 .chained = true,
7128 .chain_id = ALC662_FIXUP_SKU_IGNORE
7129 },
7130 [ALC662_FIXUP_ASUS_MODE4] = {
7131 .type = ALC_FIXUP_PINS,
7132 .v.pins = (const struct alc_pincfg[]) {
7133 { 0x14, 0x99130110 }, /* speaker */
7134 { 0x16, 0x99130111 }, /* speaker */
7135 { 0x18, 0x01a19840 }, /* mic */
7136 { 0x19, 0x99a3094f }, /* int-mic */
7137 { 0x21, 0x0121441f }, /* HP */
7138 { }
7139 },
7140 .chained = true,
7141 .chain_id = ALC662_FIXUP_SKU_IGNORE
7142 },
7143 [ALC662_FIXUP_ASUS_MODE5] = {
7144 .type = ALC_FIXUP_PINS,
7145 .v.pins = (const struct alc_pincfg[]) {
7146 { 0x14, 0x99130110 }, /* speaker */
7147 { 0x15, 0x0121441f }, /* HP */
7148 { 0x16, 0x99130111 }, /* speaker */
7149 { 0x18, 0x01a19840 }, /* mic */
7150 { 0x19, 0x99a3094f }, /* int-mic */
7151 { }
7152 },
7153 .chained = true,
7154 .chain_id = ALC662_FIXUP_SKU_IGNORE
7155 },
7156 [ALC662_FIXUP_ASUS_MODE6] = {
7157 .type = ALC_FIXUP_PINS,
7158 .v.pins = (const struct alc_pincfg[]) {
7159 { 0x14, 0x99130110 }, /* speaker */
7160 { 0x15, 0x01211420 }, /* HP2 */
7161 { 0x18, 0x01a19840 }, /* mic */
7162 { 0x19, 0x99a3094f }, /* int-mic */
7163 { 0x1b, 0x0121441f }, /* HP */
7164 { }
7165 },
7166 .chained = true,
7167 .chain_id = ALC662_FIXUP_SKU_IGNORE
7168 },
7169 [ALC662_FIXUP_ASUS_MODE7] = {
7170 .type = ALC_FIXUP_PINS,
7171 .v.pins = (const struct alc_pincfg[]) {
7172 { 0x14, 0x99130110 }, /* speaker */
7173 { 0x17, 0x99130111 }, /* speaker */
7174 { 0x18, 0x01a19840 }, /* mic */
7175 { 0x19, 0x99a3094f }, /* int-mic */
7176 { 0x1b, 0x01214020 }, /* HP */
7177 { 0x21, 0x0121401f }, /* HP */
7178 { }
7179 },
7180 .chained = true,
7181 .chain_id = ALC662_FIXUP_SKU_IGNORE
7182 },
7183 [ALC662_FIXUP_ASUS_MODE8] = {
7184 .type = ALC_FIXUP_PINS,
7185 .v.pins = (const struct alc_pincfg[]) {
7186 { 0x14, 0x99130110 }, /* speaker */
7187 { 0x12, 0x99a30970 }, /* int-mic */
7188 { 0x15, 0x01214020 }, /* HP */
7189 { 0x17, 0x99130111 }, /* speaker */
7190 { 0x18, 0x01a19840 }, /* mic */
7191 { 0x21, 0x0121401f }, /* HP */
7192 { }
7193 },
7194 .chained = true,
7195 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007196 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007197 [ALC662_FIXUP_NO_JACK_DETECT] = {
7198 .type = ALC_FIXUP_FUNC,
7199 .v.func = alc_fixup_no_jack_detect,
7200 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007201 [ALC662_FIXUP_ZOTAC_Z68] = {
7202 .type = ALC_FIXUP_PINS,
7203 .v.pins = (const struct alc_pincfg[]) {
7204 { 0x1b, 0x02214020 }, /* Front HP */
7205 { }
7206 }
7207 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007208 [ALC662_FIXUP_INV_DMIC] = {
7209 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007210 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007211 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007212};
7213
Takashi Iwaia9111322011-05-02 11:30:18 +02007214static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007215 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007216 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007217 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007218 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007219 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007220 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007221 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007222 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007223 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007224 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007225 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007226 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007227 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007228
7229#if 0
7230 /* Below is a quirk table taken from the old code.
7231 * Basically the device should work as is without the fixup table.
7232 * If BIOS doesn't give a proper info, enable the corresponding
7233 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007234 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007235 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7236 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7237 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7238 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7239 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7240 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7241 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7242 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7243 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7244 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7245 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7246 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7247 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7248 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7249 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7250 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7251 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7252 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7253 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7254 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7255 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7256 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7257 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7258 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7259 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7260 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7261 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7262 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7263 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7264 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7265 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7266 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7267 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7268 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7269 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7270 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7271 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7272 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7273 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7274 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7275 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7276 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7277 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7278 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7279 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7280 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7281 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7282 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7283 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7284 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7285#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007286 {}
7287};
7288
Todd Broch6be79482010-12-07 16:51:05 -08007289static const struct alc_model_fixup alc662_fixup_models[] = {
7290 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007291 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7292 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7293 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7294 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7295 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7296 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7297 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7298 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007299 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007300 {}
7301};
David Henningsson6cb3b702010-09-09 08:51:44 +02007302
Kailang Yang8663ff72012-06-29 09:35:52 +02007303static void alc662_fill_coef(struct hda_codec *codec)
7304{
7305 int val, coef;
7306
7307 coef = alc_get_coef0(codec);
7308
7309 switch (codec->vendor_id) {
7310 case 0x10ec0662:
7311 if ((coef & 0x00f0) == 0x0030) {
7312 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7313 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7314 }
7315 break;
7316 case 0x10ec0272:
7317 case 0x10ec0273:
7318 case 0x10ec0663:
7319 case 0x10ec0665:
7320 case 0x10ec0670:
7321 case 0x10ec0671:
7322 case 0x10ec0672:
7323 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7324 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7325 break;
7326 }
7327}
David Henningsson6cb3b702010-09-09 08:51:44 +02007328
Takashi Iwai1d045db2011-07-07 18:23:21 +02007329/*
7330 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007331static int patch_alc662(struct hda_codec *codec)
7332{
7333 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007334 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007335
Takashi Iwai3de95172012-05-07 18:03:15 +02007336 err = alc_alloc_spec(codec, 0x0b);
7337 if (err < 0)
7338 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007339
Takashi Iwai3de95172012-05-07 18:03:15 +02007340 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007341
Takashi Iwai53c334a2011-08-23 18:27:14 +02007342 /* handle multiple HPs as is */
7343 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7344
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007345 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7346
Kailang Yang8663ff72012-06-29 09:35:52 +02007347 spec->init_hook = alc662_fill_coef;
7348 alc662_fill_coef(codec);
7349
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007350 alc_pick_fixup(codec, alc662_fixup_models,
7351 alc662_fixup_tbl, alc662_fixups);
7352 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7353
7354 alc_auto_parse_customize_define(codec);
7355
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007356 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007357 codec->bus->pci->subsystem_vendor == 0x1025 &&
7358 spec->cdefine.platform_type == 1) {
7359 if (alc_codec_rename(codec, "ALC272X") < 0)
7360 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007361 }
Kailang Yang274693f2009-12-03 10:07:50 +01007362
Takashi Iwaib9c51062011-08-24 18:08:07 +02007363 /* automatic parse from the BIOS config */
7364 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007365 if (err < 0)
7366 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007367
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007368 if (!spec->no_analog && has_cdefine_beep(codec)) {
7369 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007370 if (err < 0)
7371 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007372 switch (codec->vendor_id) {
7373 case 0x10ec0662:
7374 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7375 break;
7376 case 0x10ec0272:
7377 case 0x10ec0663:
7378 case 0x10ec0665:
7379 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7380 break;
7381 case 0x10ec0273:
7382 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7383 break;
7384 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007385 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007386
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007387 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02007388 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007389
Takashi Iwai589876e2012-02-20 15:47:55 +01007390 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7391
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007392 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007393
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007394 error:
7395 alc_free(codec);
7396 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007397}
7398
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007399/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007400 * ALC680 support
7401 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007402
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007403static int alc680_parse_auto_config(struct hda_codec *codec)
7404{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007405 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007406}
7407
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007408/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007409 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007410static int patch_alc680(struct hda_codec *codec)
7411{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007412 int err;
7413
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007414 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007415 err = alc_alloc_spec(codec, 0);
7416 if (err < 0)
7417 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007418
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007419 /* automatic parse from the BIOS config */
7420 err = alc680_parse_auto_config(codec);
7421 if (err < 0) {
7422 alc_free(codec);
7423 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007424 }
7425
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007426 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007427
7428 return 0;
7429}
7430
7431/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007432 * patch entries
7433 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007434static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007435 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007436 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007437 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007438 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007439 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007440 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007441 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007442 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007443 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007444 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007445 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007446 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007447 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007448 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007449 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007450 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007451 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007452 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007453 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7454 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7455 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007456 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007457 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007458 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7459 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007460 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7461 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007462 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007463 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007464 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007465 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007466 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007467 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007468 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007469 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007470 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007471 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007472 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007473 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007474 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007475 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007476 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007477 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007478 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007479 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007480 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007481 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007482 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007483 {} /* terminator */
7484};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007485
7486MODULE_ALIAS("snd-hda-codec-id:10ec*");
7487
7488MODULE_LICENSE("GPL");
7489MODULE_DESCRIPTION("Realtek HD-audio codec");
7490
7491static struct hda_codec_preset_list realtek_list = {
7492 .preset = snd_hda_preset_realtek,
7493 .owner = THIS_MODULE,
7494};
7495
7496static int __init patch_realtek_init(void)
7497{
7498 return snd_hda_add_codec_preset(&realtek_list);
7499}
7500
7501static void __exit patch_realtek_exit(void)
7502{
7503 snd_hda_delete_codec_preset(&realtek_list);
7504}
7505
7506module_init(patch_realtek_init)
7507module_exit(patch_realtek_exit)