blob: 04713a8744b1fe9b6e317a7069397f3acfe2a6df [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 Iwai1c716152011-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 Iwaia9fd4f32009-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 Iwaia9fd4f32009-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 Henningssonf7f4b232012-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 Iwai1c716152011-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 Iwai1c716152011-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 Iwai1c716152011-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 Iwai463419d2012-12-05 14:17:37 +01002905/* look for an empty DAC slot */
2906static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2907{
2908 struct alc_spec *spec = codec->spec;
2909 int i;
2910
2911 for (i = 0; i < spec->num_all_dacs; i++) {
2912 hda_nid_t nid = spec->all_dacs[i];
2913 if (!nid || alc_is_dac_already_used(codec, nid))
2914 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002915 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002916 return nid;
2917 }
2918 return 0;
2919}
2920
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002921/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002922static bool __parse_nid_path(struct hda_codec *codec,
2923 hda_nid_t from_nid, hda_nid_t to_nid,
2924 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002925{
2926 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002927 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002928 int i, nums;
2929
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002930 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002931 if (!with_aa_mix)
2932 return false;
2933 with_aa_mix = 2; /* mark aa-mix is included */
2934 }
2935
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002936 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002937 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002938 if (conn[i] != from_nid) {
2939 /* special case: when from_nid is 0,
2940 * try to find an empty DAC
2941 */
2942 if (from_nid ||
2943 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2944 alc_is_dac_already_used(codec, conn[i]))
2945 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002946 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002947 /* aa-mix is requested but not included? */
2948 if (!(spec->mixer_nid && with_aa_mix == 1))
2949 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002950 }
2951 if (depth >= MAX_NID_PATH_DEPTH)
2952 return false;
2953 for (i = 0; i < nums; i++) {
2954 unsigned int type;
2955 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002956 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2957 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002958 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002959 if (__parse_nid_path(codec, from_nid, conn[i],
2960 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002961 goto found;
2962 }
2963 return false;
2964
2965 found:
2966 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002967 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002968 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002969 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002970 path->depth++;
2971 return true;
2972}
2973
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002974/* parse the widget path from the given nid to the target nid;
2975 * when @from_nid is 0, try to find an empty DAC;
2976 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2977 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2978 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002979 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002980static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2981 hda_nid_t to_nid, int with_aa_mix,
2982 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002983{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002984 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2985 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002986 path->depth++;
2987#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002988 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002989 path->depth, path->path[0], path->path[1],
2990 path->path[2], path->path[3], path->path[4]);
2991#endif
2992 return true;
2993 }
2994 return false;
2995}
2996
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002997static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2998{
Takashi Iwai140547e2012-02-16 17:23:46 +01002999 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01003000 int i;
3001 hda_nid_t nid_found = 0;
3002
3003 for (i = 0; i < spec->num_all_dacs; i++) {
3004 hda_nid_t nid = spec->all_dacs[i];
3005 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003006 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01003007 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003008 if (nid_found)
3009 return 0;
3010 nid_found = nid;
3011 }
3012 }
3013 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003014}
3015
Takashi Iwaiba8111272012-12-06 18:06:23 +01003016static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003017{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003018 struct alc_spec *spec = codec->spec;
3019 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003020
Takashi Iwaiba8111272012-12-06 18:06:23 +01003021 for (i = 0; i < spec->out_path.used; i++) {
3022 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3023 if (path->ctls[type] == val)
3024 return true;
3025 }
3026 return false;
3027}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003028
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003029/* badness definition */
3030enum {
3031 /* No primary DAC is found for the main output */
3032 BAD_NO_PRIMARY_DAC = 0x10000,
3033 /* No DAC is found for the extra output */
3034 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003035 /* No possible multi-ios */
3036 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003037 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003038 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003039 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003040 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003041 /* Primary DAC shared with main surrounds */
3042 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003043 /* Primary DAC shared with main CLFE */
3044 BAD_SHARED_CLFE = 0x10,
3045 /* Primary DAC shared with extra surrounds */
3046 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003047 /* Volume widget is shared */
3048 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003049};
3050
3051static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003052 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003053static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003054 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003055
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003056static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3057 hda_nid_t dac)
3058{
3059 struct alc_spec *spec = codec->spec;
3060 struct nid_path *path;
3061
3062 path = snd_array_new(&spec->out_path);
3063 if (!path)
3064 return false;
3065 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003066 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003067 return true;
3068 /* push back */
3069 spec->out_path.used--;
3070 return false;
3071}
3072
Takashi Iwaiba8111272012-12-06 18:06:23 +01003073/* get the path pointing from the given dac to pin;
3074 * passing 0 to either @pin or @dac behaves as a wildcard
3075 */
3076static struct nid_path *get_out_path(struct hda_codec *codec, hda_nid_t pin,
3077 hda_nid_t dac)
3078{
3079 struct alc_spec *spec = codec->spec;
3080 int i;
3081
3082 for (i = 0; i < spec->out_path.used; i++) {
3083 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3084 if (path->depth <= 0)
3085 continue;
3086 if ((!dac || path->path[0] == dac) &&
3087 (!pin || path->path[path->depth - 1] == pin))
3088 return path;
3089 }
3090 return NULL;
3091}
3092
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003093/* look for widgets in the path between the given NIDs appropriate for
3094 * volume and mute controls, and assign the values to ctls[].
3095 *
3096 * When no appropriate widget is found in the path, the badness value
3097 * is incremented depending on the situation. The function returns the
3098 * total badness for both volume and mute controls.
3099 */
3100static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3101 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003102{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003103 struct nid_path *path = get_out_path(codec, pin, dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003104 hda_nid_t nid;
3105 unsigned int val;
3106 int badness = 0;
3107
Takashi Iwaiba8111272012-12-06 18:06:23 +01003108 if (!path)
3109 return BAD_SHARED_VOL * 2;
3110 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003111 if (nid) {
3112 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003113 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003114 badness += BAD_SHARED_VOL;
3115 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003116 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003117 } else
3118 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003119 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003120 if (nid) {
3121 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003122 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3123 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003124 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3125 else
3126 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003127 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003128 badness += BAD_SHARED_VOL;
3129 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003130 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003131 } else
3132 badness += BAD_SHARED_VOL;
3133 return badness;
3134}
3135
Takashi Iwaidc31b582012-02-17 17:27:53 +01003136struct badness_table {
3137 int no_primary_dac; /* no primary DAC */
3138 int no_dac; /* no secondary DACs */
3139 int shared_primary; /* primary DAC is shared with main output */
3140 int shared_surr; /* secondary DAC shared with main or primary */
3141 int shared_clfe; /* third DAC shared with main or primary */
3142 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3143};
3144
3145static struct badness_table main_out_badness = {
3146 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3147 .no_dac = BAD_NO_DAC,
3148 .shared_primary = BAD_NO_PRIMARY_DAC,
3149 .shared_surr = BAD_SHARED_SURROUND,
3150 .shared_clfe = BAD_SHARED_CLFE,
3151 .shared_surr_main = BAD_SHARED_SURROUND,
3152};
3153
3154static struct badness_table extra_out_badness = {
3155 .no_primary_dac = BAD_NO_DAC,
3156 .no_dac = BAD_NO_DAC,
3157 .shared_primary = BAD_NO_EXTRA_DAC,
3158 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3159 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3160 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3161};
3162
3163/* try to assign DACs to pins and return the resultant badness */
3164static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3165 const hda_nid_t *pins, hda_nid_t *dacs,
3166 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003167{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003168 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003169 struct auto_pin_cfg *cfg = &spec->autocfg;
3170 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003171 int badness = 0;
3172 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003173
Takashi Iwai185d99f2012-02-16 18:39:45 +01003174 if (!num_outs)
3175 return 0;
3176
Takashi Iwaidc31b582012-02-17 17:27:53 +01003177 for (i = 0; i < num_outs; i++) {
3178 hda_nid_t pin = pins[i];
3179 if (!dacs[i])
3180 dacs[i] = alc_auto_look_for_dac(codec, pin);
3181 if (!dacs[i] && !i) {
3182 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003183 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003184 dacs[0] = dacs[j];
3185 dacs[j] = 0;
3186 break;
3187 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003188 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003189 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003190 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003191 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003192 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003193 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003194 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003195 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003196 dac = spec->private_dac_nids[i];
3197 if (dac) {
3198 if (!i)
3199 badness += bad->shared_primary;
3200 else if (i == 1)
3201 badness += bad->shared_surr;
3202 else
3203 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003204 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003205 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003206 badness += bad->shared_surr_main;
3207 } else if (!i)
3208 badness += bad->no_primary_dac;
3209 else
3210 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003211 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003212 if (!add_new_out_path(codec, pin, dac))
3213 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003214 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003215 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003216 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003217
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003218 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003219}
3220
3221static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003222 hda_nid_t reference_pin,
3223 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003224
Takashi Iwai185d99f2012-02-16 18:39:45 +01003225static bool alc_map_singles(struct hda_codec *codec, int outs,
3226 const hda_nid_t *pins, hda_nid_t *dacs)
3227{
3228 int i;
3229 bool found = false;
3230 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003231 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003232 if (dacs[i])
3233 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003234 dac = get_dac_if_single(codec, pins[i]);
3235 if (!dac)
3236 continue;
3237 if (add_new_out_path(codec, pins[i], dac)) {
3238 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003239 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003240 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003241 }
3242 return found;
3243}
3244
Takashi Iwai7085ec12009-10-02 09:03:58 +02003245/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003246static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003247 bool fill_hardwired,
3248 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003249{
3250 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003251 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003252 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003253
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003254 /* set num_dacs once to full for alc_auto_look_for_dac() */
3255 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003256 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003257 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3258 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3259 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003260 spec->multi_ios = 0;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003261 snd_array_free(&spec->out_path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003262 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003263
3264 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003265 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003266 bool mapped;
3267 do {
3268 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003269 cfg->line_out_pins,
3270 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003271 mapped |= alc_map_singles(codec, cfg->hp_outs,
3272 cfg->hp_pins,
3273 spec->multiout.hp_out_nid);
3274 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3275 cfg->speaker_pins,
3276 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003277 if (fill_mio_first && cfg->line_outs == 1 &&
3278 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3279 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3280 if (!err)
3281 mapped = true;
3282 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003283 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003284 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003285
Takashi Iwaidc31b582012-02-17 17:27:53 +01003286 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3287 spec->private_dac_nids,
3288 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003289
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003290 /* re-count num_dacs and squash invalid entries */
3291 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003292 for (i = 0; i < cfg->line_outs; i++) {
3293 if (spec->private_dac_nids[i])
3294 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003295 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003296 memmove(spec->private_dac_nids + i,
3297 spec->private_dac_nids + i + 1,
3298 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003299 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3300 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003301 }
3302
Takashi Iwai276dd702012-02-17 16:17:03 +01003303 if (fill_mio_first &&
3304 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003305 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003306 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003307 if (err < 0)
3308 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003309 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003310 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003311
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003312 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003313 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3314 spec->multiout.hp_out_nid,
3315 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003316 if (err < 0)
3317 return err;
3318 badness += err;
3319 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003320 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003321 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3322 cfg->speaker_pins,
3323 spec->multiout.extra_out_nid,
3324 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003325 if (err < 0)
3326 return err;
3327 badness += err;
3328 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003329 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3330 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003331 if (err < 0)
3332 return err;
3333 badness += err;
3334 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003335 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3336 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003337 int offset = 0;
3338 if (cfg->line_outs >= 3)
3339 offset = 1;
3340 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3341 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003342 if (err < 0)
3343 return err;
3344 badness += err;
3345 }
3346
3347 if (spec->multi_ios == 2) {
3348 for (i = 0; i < 2; i++)
3349 spec->private_dac_nids[spec->multiout.num_dacs++] =
3350 spec->multi_io[i].dac;
3351 spec->ext_channel_count = 2;
3352 } else if (spec->multi_ios) {
3353 spec->multi_ios = 0;
3354 badness += BAD_MULTI_IO;
3355 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003356
3357 return badness;
3358}
3359
3360#define DEBUG_BADNESS
3361
3362#ifdef DEBUG_BADNESS
3363#define debug_badness snd_printdd
3364#else
3365#define debug_badness(...)
3366#endif
3367
3368static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3369{
3370 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3371 cfg->line_out_pins[0], cfg->line_out_pins[1],
3372 cfg->line_out_pins[2], cfg->line_out_pins[2],
3373 spec->multiout.dac_nids[0],
3374 spec->multiout.dac_nids[1],
3375 spec->multiout.dac_nids[2],
3376 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003377 if (spec->multi_ios > 0)
3378 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3379 spec->multi_ios,
3380 spec->multi_io[0].pin, spec->multi_io[1].pin,
3381 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003382 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3383 cfg->hp_pins[0], cfg->hp_pins[1],
3384 cfg->hp_pins[2], cfg->hp_pins[2],
3385 spec->multiout.hp_out_nid[0],
3386 spec->multiout.hp_out_nid[1],
3387 spec->multiout.hp_out_nid[2],
3388 spec->multiout.hp_out_nid[3]);
3389 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3390 cfg->speaker_pins[0], cfg->speaker_pins[1],
3391 cfg->speaker_pins[2], cfg->speaker_pins[3],
3392 spec->multiout.extra_out_nid[0],
3393 spec->multiout.extra_out_nid[1],
3394 spec->multiout.extra_out_nid[2],
3395 spec->multiout.extra_out_nid[3]);
3396}
3397
Takashi Iwai463419d2012-12-05 14:17:37 +01003398/* find all available DACs of the codec */
3399static void alc_fill_all_nids(struct hda_codec *codec)
3400{
3401 struct alc_spec *spec = codec->spec;
3402 int i;
3403 hda_nid_t nid = codec->start_nid;
3404
3405 spec->num_all_dacs = 0;
3406 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3407 for (i = 0; i < codec->num_nodes; i++, nid++) {
3408 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3409 continue;
3410 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3411 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3412 break;
3413 }
3414 spec->all_dacs[spec->num_all_dacs++] = nid;
3415 }
3416}
3417
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003418static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3419{
3420 struct alc_spec *spec = codec->spec;
3421 struct auto_pin_cfg *cfg = &spec->autocfg;
3422 struct auto_pin_cfg *best_cfg;
3423 int best_badness = INT_MAX;
3424 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003425 bool fill_hardwired = true, fill_mio_first = true;
3426 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003427 bool hp_spk_swapped = false;
3428
Takashi Iwai463419d2012-12-05 14:17:37 +01003429 alc_fill_all_nids(codec);
3430
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003431 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3432 if (!best_cfg)
3433 return -ENOMEM;
3434 *best_cfg = *cfg;
3435
3436 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003437 badness = fill_and_eval_dacs(codec, fill_hardwired,
3438 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003439 if (badness < 0) {
3440 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003441 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003442 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003443 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3444 cfg->line_out_type, fill_hardwired, fill_mio_first,
3445 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003446 debug_show_configs(spec, cfg);
3447 if (badness < best_badness) {
3448 best_badness = badness;
3449 *best_cfg = *cfg;
3450 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003451 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003452 }
3453 if (!badness)
3454 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003455 fill_mio_first = !fill_mio_first;
3456 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003457 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003458 fill_hardwired = !fill_hardwired;
3459 if (!fill_hardwired)
3460 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003461 if (hp_spk_swapped)
3462 break;
3463 hp_spk_swapped = true;
3464 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003465 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3466 cfg->hp_outs = cfg->line_outs;
3467 memcpy(cfg->hp_pins, cfg->line_out_pins,
3468 sizeof(cfg->hp_pins));
3469 cfg->line_outs = cfg->speaker_outs;
3470 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3471 sizeof(cfg->speaker_pins));
3472 cfg->speaker_outs = 0;
3473 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3474 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003475 fill_hardwired = true;
3476 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003477 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003478 if (cfg->hp_outs > 0 &&
3479 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3480 cfg->speaker_outs = cfg->line_outs;
3481 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3482 sizeof(cfg->speaker_pins));
3483 cfg->line_outs = cfg->hp_outs;
3484 memcpy(cfg->line_out_pins, cfg->hp_pins,
3485 sizeof(cfg->hp_pins));
3486 cfg->hp_outs = 0;
3487 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3488 cfg->line_out_type = AUTO_PIN_HP_OUT;
3489 fill_hardwired = true;
3490 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003491 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003492 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003493 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003494
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003495 if (badness) {
3496 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003497 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003498 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003499 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3500 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003501 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003502
Takashi Iwaiba8111272012-12-06 18:06:23 +01003503 if (cfg->line_out_pins[0]) {
3504 struct nid_path *path = get_out_path(codec,
3505 cfg->line_out_pins[0],
3506 spec->multiout.dac_nids[0]);
3507 if (path)
3508 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3509 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003510
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003511 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003512 return 0;
3513}
3514
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003515/* replace the channels in the composed amp value with the given number */
3516static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3517{
3518 val &= ~(0x3U << 16);
3519 val |= chs << 16;
3520 return val;
3521}
3522
Takashi Iwai343a04b2011-07-06 14:28:39 +02003523static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003524 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003525 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003526 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003527{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003528 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003529 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003530 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003531 val = path->ctls[NID_PATH_VOL_CTL];
3532 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003533 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003534 val = amp_val_replace_channels(val, chs);
3535 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3536}
3537
3538/* return the channel bits suitable for the given path->ctls[] */
3539static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3540 int type)
3541{
3542 int chs = 1; /* mono (left only) */
3543 if (path) {
3544 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3545 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3546 chs = 3; /* stereo */
3547 }
3548 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003549}
3550
Takashi Iwaie29d3772011-11-14 17:13:23 +01003551static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3552 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003553 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003554{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003555 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3556 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003557}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003558
3559/* create a mute-switch for the given mixer widget;
3560 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3561 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003562static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003563 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003564 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003565 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003566{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003567 unsigned int val;
3568 int type = ALC_CTL_WIDGET_MUTE;
3569
3570 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003571 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003572 val = path->ctls[NID_PATH_MUTE_CTL];
3573 if (!val)
3574 return 0;
3575 val = amp_val_replace_channels(val, chs);
3576 if (get_amp_direction_(val) == HDA_INPUT) {
3577 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003578 int nums = snd_hda_get_num_conns(codec, nid);
3579 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003580 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003581 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003582 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003583 }
3584 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003585}
3586
Takashi Iwaie29d3772011-11-14 17:13:23 +01003587static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003588 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003589{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003590 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3591 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003592}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003593
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003594static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003595 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003596{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003597 int i;
3598
3599 for (i = path->depth - 1; i >= 0; i--) {
3600 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3601 return path->path[i];
3602 if (i != path->depth - 1 && i != 0 &&
3603 nid_has_mute(codec, path->path[i], HDA_INPUT))
3604 return path->path[i];
3605 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003606 return 0;
3607}
3608
3609static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003610 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003611{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003612 int i;
3613
3614 for (i = path->depth - 1; i >= 0; i--) {
3615 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3616 return path->path[i];
3617 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003618 return 0;
3619}
3620
Takashi Iwai7085ec12009-10-02 09:03:58 +02003621/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003622static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003623 const struct auto_pin_cfg *cfg)
3624{
3625 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003626 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003627
Takashi Iwaice764ab2011-04-27 16:35:23 +02003628 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003629 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003630 noutputs += spec->multi_ios;
3631
3632 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003633 const char *name;
3634 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003635 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003636 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003637
3638 dac = spec->multiout.dac_nids[i];
3639 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003640 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003641 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003642 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003643 index = 0;
3644 name = channel_name[i];
3645 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003646 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003647 name = alc_get_line_out_pfx(spec, i, true, &index);
3648 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003649
Takashi Iwaiba8111272012-12-06 18:06:23 +01003650 path = get_out_path(codec, pin, dac);
3651 if (!path)
3652 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003653 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003654 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003655 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003656 if (err < 0)
3657 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003658 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003659 if (err < 0)
3660 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003661 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003662 if (err < 0)
3663 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003664 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003665 if (err < 0)
3666 return err;
3667 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003668 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003669 if (err < 0)
3670 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003671 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003672 if (err < 0)
3673 return err;
3674 }
3675 }
3676 return 0;
3677}
3678
Takashi Iwai343a04b2011-07-06 14:28:39 +02003679static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003680 hda_nid_t dac, const char *pfx,
3681 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003682{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003683 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003684 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003685
Takashi Iwaiba8111272012-12-06 18:06:23 +01003686 path = get_out_path(codec, pin, dac);
3687 if (!path)
3688 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003689 /* bind volume control will be created in the case of dac = 0 */
3690 if (dac) {
3691 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3692 if (err < 0)
3693 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003694 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003695 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003696 if (err < 0)
3697 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003698 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003699}
3700
Takashi Iwai23c09b02011-08-19 09:05:35 +02003701static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3702 unsigned int nums,
3703 struct hda_ctl_ops *ops)
3704{
3705 struct alc_spec *spec = codec->spec;
3706 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003707 ctlp = snd_array_new(&spec->bind_ctls);
3708 if (!ctlp)
3709 return NULL;
3710 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3711 *ctlp = ctl;
3712 if (ctl)
3713 ctl->ops = ops;
3714 return ctl;
3715}
3716
3717/* add playback controls for speaker and HP outputs */
3718static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3719 const hda_nid_t *pins,
3720 const hda_nid_t *dacs,
3721 const char *pfx)
3722{
3723 struct alc_spec *spec = codec->spec;
3724 struct hda_bind_ctls *ctl;
3725 char name[32];
3726 int i, n, err;
3727
3728 if (!num_pins || !pins[0])
3729 return 0;
3730
Takashi Iwai527e4d72011-10-27 16:33:27 +02003731 if (num_pins == 1) {
3732 hda_nid_t dac = *dacs;
3733 if (!dac)
3734 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003735 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003736 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003737
Takashi Iwai23c09b02011-08-19 09:05:35 +02003738 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003739 hda_nid_t dac;
3740 if (dacs[num_pins - 1])
3741 dac = dacs[i]; /* with individual volumes */
3742 else
3743 dac = 0;
3744 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3745 err = alc_auto_create_extra_out(codec, pins[i], dac,
3746 "Bass Speaker", 0);
3747 } else if (num_pins >= 3) {
3748 snprintf(name, sizeof(name), "%s %s",
3749 pfx, channel_name[i]);
3750 err = alc_auto_create_extra_out(codec, pins[i], dac,
3751 name, 0);
3752 } else {
3753 err = alc_auto_create_extra_out(codec, pins[i], dac,
3754 pfx, i);
3755 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003756 if (err < 0)
3757 return err;
3758 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003759 if (dacs[num_pins - 1])
3760 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003761
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003762 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003763 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3764 if (!ctl)
3765 return -ENOMEM;
3766 n = 0;
3767 for (i = 0; i < num_pins; i++) {
3768 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003769 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003770 if (!pins[i] || !dacs[i])
3771 continue;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003772 path = get_out_path(codec, pins[i], dacs[i]);
3773 if (!path)
3774 continue;
3775 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003776 if (vol)
3777 ctl->values[n++] =
3778 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3779 }
3780 if (n) {
3781 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3782 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3783 if (err < 0)
3784 return err;
3785 }
3786 return 0;
3787}
3788
Takashi Iwai343a04b2011-07-06 14:28:39 +02003789static int alc_auto_create_hp_out(struct hda_codec *codec)
3790{
3791 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003792 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3793 spec->autocfg.hp_pins,
3794 spec->multiout.hp_out_nid,
3795 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003796}
3797
3798static int alc_auto_create_speaker_out(struct hda_codec *codec)
3799{
3800 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003801 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3802 spec->autocfg.speaker_pins,
3803 spec->multiout.extra_out_nid,
3804 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003805}
3806
Takashi Iwai130e5f02012-12-14 16:09:29 +01003807static bool is_ctl_associated_in_list(struct snd_array *array, hda_nid_t nid,
3808 int dir, int idx, int types)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003809{
Takashi Iwai78e635c2012-12-10 17:07:16 +01003810 int i, type;
3811
Takashi Iwai130e5f02012-12-14 16:09:29 +01003812 for (i = 0; i < array->used; i++) {
3813 struct nid_path *p = snd_array_elem(array, i);
3814 if (p->depth <= 0)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003815 continue;
3816 for (type = 0; type < 2; type++) {
3817 if (types & (1 << type)) {
3818 unsigned int val = p->ctls[type];
3819 if (get_amp_nid_(val) == nid &&
Takashi Iwai130e5f02012-12-14 16:09:29 +01003820 get_amp_direction_(val) == dir &&
3821 get_amp_index_(val) == idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003822 return true;
3823 }
3824 }
3825 }
3826 return false;
3827}
3828
Takashi Iwai130e5f02012-12-14 16:09:29 +01003829/* check whether a control with the given (nid, dir, idx) was assigned */
3830static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3831 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003832{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003833 struct alc_spec *spec = codec->spec;
3834 return is_ctl_associated_in_list(&spec->out_path, nid, dir, idx, 3) ||
3835 is_ctl_associated_in_list(&spec->in_path, nid, dir, idx, 3) ||
3836 is_ctl_associated_in_list(&spec->loopback_path, nid, dir, idx, 3);
3837}
3838
3839/* can have the amp-in capability? */
3840static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3841{
3842 hda_nid_t nid = path->path[idx];
3843 unsigned int caps = get_wcaps(codec, nid);
3844 unsigned int type = get_wcaps_type(caps);
3845
3846 if (!(caps & AC_WCAP_IN_AMP))
3847 return false;
3848 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3849 return false;
3850 return true;
3851}
3852
3853/* can have the amp-out capability? */
3854static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3855{
3856 hda_nid_t nid = path->path[idx];
3857 unsigned int caps = get_wcaps(codec, nid);
3858 unsigned int type = get_wcaps_type(caps);
3859
3860 if (!(caps & AC_WCAP_OUT_AMP))
3861 return false;
3862 if (type == AC_WID_PIN && !idx) /* only for output pins */
3863 return false;
3864 return true;
3865}
3866
3867static bool is_active_in_list(struct hda_codec *codec, struct snd_array *array,
3868 hda_nid_t nid, int dir, int idx)
3869{
3870 int i, n;
3871
3872 for (n = 0; n < array->used; n++) {
3873 struct nid_path *path = snd_array_elem(array, n);
3874 if (!path->active)
3875 continue;
3876 for (i = 0; i < path->depth; i++) {
3877 if (path->path[i] == nid) {
3878 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3879 return true;
3880 break;
3881 }
3882 }
3883 }
3884 return false;
3885}
3886
3887/* check whether the given (nid,dir,idx) is active */
3888static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3889 unsigned int idx, unsigned int dir)
3890{
3891 struct alc_spec *spec = codec->spec;
3892 return is_active_in_list(codec, &spec->out_path, nid, idx, dir) ||
3893 is_active_in_list(codec, &spec->in_path, nid, idx, dir) ||
3894 is_active_in_list(codec, &spec->loopback_path, nid, idx, dir);
3895}
3896
3897/* get the default amp value for the target state */
3898static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3899 int dir, bool enable)
3900{
3901 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003902 unsigned int val = 0;
3903
3904 caps = query_amp_caps(codec, nid, dir);
3905 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003906 /* set to 0dB */
3907 if (enable)
3908 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003909 }
3910 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003911 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003912 val |= HDA_AMP_MUTE;
3913 }
3914 return val;
3915}
3916
Takashi Iwai130e5f02012-12-14 16:09:29 +01003917/* initialize the amp value (only at the first time) */
3918static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3919{
3920 int val = get_amp_val_to_activate(codec, nid, dir, false);
3921 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3922}
3923
3924static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3925 int idx, bool enable)
3926{
3927 int val;
3928 if (is_ctl_associated(codec, nid, dir, idx) ||
3929 is_active_nid(codec, nid, dir, idx))
3930 return;
3931 val = get_amp_val_to_activate(codec, nid, dir, enable);
3932 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3933}
3934
3935static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3936 int i, bool enable)
3937{
3938 hda_nid_t nid = path->path[i];
3939 init_amp(codec, nid, HDA_OUTPUT, 0);
3940 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3941}
3942
3943static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
3944 int i, bool enable)
3945{
3946 struct alc_spec *spec = codec->spec;
3947 hda_nid_t conn[16];
3948 int n, nums;
3949 hda_nid_t nid = path->path[i];
3950
3951 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
3952 for (n = 0; n < nums; n++)
3953 init_amp(codec, nid, HDA_INPUT, n);
3954
3955 if (is_ctl_associated(codec, nid, HDA_INPUT, path->idx[i]))
3956 return;
3957
3958 /* here is a little bit tricky in comparison with activate_amp_out();
3959 * when aa-mixer is available, we need to enable the path as well
3960 */
3961 for (n = 0; n < nums; n++) {
3962 if (n != path->idx[i] && conn[n] != spec->mixer_nid)
3963 continue;
3964 activate_amp(codec, nid, HDA_INPUT, n, enable);
3965 }
3966}
3967
3968static void activate_path(struct hda_codec *codec, struct nid_path *path,
3969 bool enable)
3970{
3971 int i;
3972
3973 if (path->active == enable)
3974 return;
3975
3976 if (!enable)
3977 path->active = false;
3978
3979 for (i = path->depth - 1; i >= 0; i--) {
3980 if (path->multi[i])
3981 snd_hda_codec_write_cache(codec, path->path[i], 0,
3982 AC_VERB_SET_CONNECT_SEL,
3983 path->idx[i]);
3984 if (has_amp_in(codec, path, i))
3985 activate_amp_in(codec, path, i, enable);
3986 if (has_amp_out(codec, path, i))
3987 activate_amp_out(codec, path, i, enable);
3988 }
3989
3990 if (enable)
3991 path->active = true;
3992}
3993
Takashi Iwai78e635c2012-12-10 17:07:16 +01003994/* configure the path from the given dac to the pin as the proper output */
3995static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3996 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003997 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003998{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003999 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02004000
Takashi Iwai130e5f02012-12-14 16:09:29 +01004001 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwaiba8111272012-12-06 18:06:23 +01004002 path = get_out_path(codec, pin, dac);
4003 if (!path)
4004 return;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004005 activate_path(codec, path, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004006}
4007
Takashi Iwai343a04b2011-07-06 14:28:39 +02004008static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004009{
4010 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02004011 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004012 int i;
4013
4014 for (i = 0; i <= HDA_SIDE; i++) {
4015 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4016 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02004017 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01004018 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004019
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004020 }
4021}
4022
Takashi Iwai343a04b2011-07-06 14:28:39 +02004023static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004024{
4025 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004026 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004027 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004028
David Henningsson636030e2011-10-12 19:26:03 +02004029 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004030 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4031 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02004032 pin = spec->autocfg.hp_pins[i];
4033 if (!pin)
4034 break;
4035 dac = spec->multiout.hp_out_nid[i];
4036 if (!dac) {
4037 if (i > 0 && spec->multiout.hp_out_nid[0])
4038 dac = spec->multiout.hp_out_nid[0];
4039 else
4040 dac = spec->multiout.dac_nids[0];
4041 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004042 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004043 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02004044 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004045 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4046 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004047 pin = spec->autocfg.speaker_pins[i];
4048 if (!pin)
4049 break;
4050 dac = spec->multiout.extra_out_nid[i];
4051 if (!dac) {
4052 if (i > 0 && spec->multiout.extra_out_nid[0])
4053 dac = spec->multiout.extra_out_nid[0];
4054 else
4055 dac = spec->multiout.dac_nids[0];
4056 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004057 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004058 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004059}
4060
Takashi Iwai276dd702012-02-17 16:17:03 +01004061/* check whether the given pin can be a multi-io pin */
4062static bool can_be_multiio_pin(struct hda_codec *codec,
4063 unsigned int location, hda_nid_t nid)
4064{
4065 unsigned int defcfg, caps;
4066
4067 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4068 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4069 return false;
4070 if (location && get_defcfg_location(defcfg) != location)
4071 return false;
4072 caps = snd_hda_query_pin_caps(codec, nid);
4073 if (!(caps & AC_PINCAP_OUT))
4074 return false;
4075 return true;
4076}
4077
Takashi Iwaice764ab2011-04-27 16:35:23 +02004078/*
4079 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004080 *
4081 * When hardwired is set, try to fill ony hardwired pins, and returns
4082 * zero if any pins are filled, non-zero if nothing found.
4083 * When hardwired is off, try to fill possible input pins, and returns
4084 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004085 */
4086static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004087 hda_nid_t reference_pin,
4088 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004089{
4090 struct alc_spec *spec = codec->spec;
4091 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004092 int type, i, j, dacs, num_pins, old_pins;
4093 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4094 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004095 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004096
Takashi Iwai276dd702012-02-17 16:17:03 +01004097 old_pins = spec->multi_ios;
4098 if (old_pins >= 2)
4099 goto end_fill;
4100
4101 num_pins = 0;
4102 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4103 for (i = 0; i < cfg->num_inputs; i++) {
4104 if (cfg->inputs[i].type != type)
4105 continue;
4106 if (can_be_multiio_pin(codec, location,
4107 cfg->inputs[i].pin))
4108 num_pins++;
4109 }
4110 }
4111 if (num_pins < 2)
4112 goto end_fill;
4113
Takashi Iwai07b18f62011-11-10 15:42:54 +01004114 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004115 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4116 for (i = 0; i < cfg->num_inputs; i++) {
4117 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004118 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004119
Takashi Iwaice764ab2011-04-27 16:35:23 +02004120 if (cfg->inputs[i].type != type)
4121 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004122 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004123 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004124 for (j = 0; j < spec->multi_ios; j++) {
4125 if (nid == spec->multi_io[j].pin)
4126 break;
4127 }
4128 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004129 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004130
4131 if (offset && offset + spec->multi_ios < dacs) {
4132 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004133 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004134 dac = 0;
4135 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004136 if (hardwired)
4137 dac = get_dac_if_single(codec, nid);
4138 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01004139 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004140 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004141 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004142 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004143 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004144 if (!add_new_out_path(codec, nid, dac)) {
4145 badness++;
4146 continue;
4147 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004148 spec->multi_io[spec->multi_ios].pin = nid;
4149 spec->multi_io[spec->multi_ios].dac = dac;
4150 spec->multi_ios++;
4151 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004152 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004153 }
4154 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004155 end_fill:
4156 if (badness)
4157 badness = BAD_MULTI_IO;
4158 if (old_pins == spec->multi_ios) {
4159 if (hardwired)
4160 return 1; /* nothing found */
4161 else
4162 return badness; /* no badness if nothing found */
4163 }
4164 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004165 /* cancel newly assigned paths */
4166 spec->out_path.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004167 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004168 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004169 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004170
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004171 /* assign volume and mute controls */
4172 for (i = old_pins; i < spec->multi_ios; i++)
4173 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4174 spec->multi_io[i].dac);
4175
4176 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004177}
4178
4179static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4180 struct snd_ctl_elem_info *uinfo)
4181{
4182 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4183 struct alc_spec *spec = codec->spec;
4184
4185 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4186 uinfo->count = 1;
4187 uinfo->value.enumerated.items = spec->multi_ios + 1;
4188 if (uinfo->value.enumerated.item > spec->multi_ios)
4189 uinfo->value.enumerated.item = spec->multi_ios;
4190 sprintf(uinfo->value.enumerated.name, "%dch",
4191 (uinfo->value.enumerated.item + 1) * 2);
4192 return 0;
4193}
4194
4195static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4196 struct snd_ctl_elem_value *ucontrol)
4197{
4198 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4199 struct alc_spec *spec = codec->spec;
4200 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4201 return 0;
4202}
4203
4204static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4205{
4206 struct alc_spec *spec = codec->spec;
4207 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004208 struct nid_path *path;
4209
4210 path = get_out_path(codec, nid, spec->multi_io[idx].dac);
4211 if (!path)
4212 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004213
4214 if (!spec->multi_io[idx].ctl_in)
4215 spec->multi_io[idx].ctl_in =
Takashi Iwai130e5f02012-12-14 16:09:29 +01004216 snd_hda_codec_update_cache(codec, nid, 0,
Takashi Iwaice764ab2011-04-27 16:35:23 +02004217 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004218
Takashi Iwaice764ab2011-04-27 16:35:23 +02004219 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004220 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004221 activate_path(codec, path, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004222 } else {
Takashi Iwai130e5f02012-12-14 16:09:29 +01004223 activate_path(codec, path, false);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004224 snd_hda_set_pin_ctl_cache(codec, nid,
4225 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004226 }
4227 return 0;
4228}
4229
4230static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4231 struct snd_ctl_elem_value *ucontrol)
4232{
4233 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4234 struct alc_spec *spec = codec->spec;
4235 int i, ch;
4236
4237 ch = ucontrol->value.enumerated.item[0];
4238 if (ch < 0 || ch > spec->multi_ios)
4239 return -EINVAL;
4240 if (ch == (spec->ext_channel_count - 1) / 2)
4241 return 0;
4242 spec->ext_channel_count = (ch + 1) * 2;
4243 for (i = 0; i < spec->multi_ios; i++)
4244 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004245 spec->multiout.max_channels = max(spec->ext_channel_count,
4246 spec->const_channel_count);
4247 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004248 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004249 return 1;
4250}
4251
Takashi Iwaia9111322011-05-02 11:30:18 +02004252static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004253 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4254 .name = "Channel Mode",
4255 .info = alc_auto_ch_mode_info,
4256 .get = alc_auto_ch_mode_get,
4257 .put = alc_auto_ch_mode_put,
4258};
4259
Takashi Iwai23c09b02011-08-19 09:05:35 +02004260static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004261{
4262 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004263
Takashi Iwaic2674682011-08-24 17:57:44 +02004264 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004265 if (!alc_kcontrol_new(spec, "Channel Mode",
4266 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004267 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004268 }
4269 return 0;
4270}
4271
Takashi Iwai1d045db2011-07-07 18:23:21 +02004272/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4273 * active input pins
4274 */
4275static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4276{
4277 struct alc_spec *spec = codec->spec;
4278 const struct hda_input_mux *imux;
4279 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4280 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4281 int i, n, nums;
4282
4283 imux = spec->input_mux;
4284 if (!imux)
4285 return;
4286 if (spec->dyn_adc_switch)
4287 return;
4288
Takashi Iwai26acaf02012-03-22 14:36:50 +01004289 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004290 nums = 0;
4291 for (n = 0; n < spec->num_adc_nids; n++) {
4292 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004293 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004294 for (i = 0; i < imux->num_items; i++) {
4295 hda_nid_t pin = spec->imux_pins[i];
4296 if (pin) {
4297 if (get_connection_index(codec, cap, pin) < 0)
4298 break;
4299 } else if (num_conns <= imux->items[i].index)
4300 break;
4301 }
4302 if (i >= imux->num_items) {
4303 adc_nids[nums] = spec->private_adc_nids[n];
4304 capsrc_nids[nums++] = cap;
4305 }
4306 }
4307 if (!nums) {
4308 /* check whether ADC-switch is possible */
4309 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004310 if (spec->shared_mic_hp) {
4311 spec->shared_mic_hp = 0;
4312 spec->private_imux[0].num_items = 1;
4313 goto again;
4314 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004315 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4316 " using fallback 0x%x\n",
4317 codec->chip_name, spec->private_adc_nids[0]);
4318 spec->num_adc_nids = 1;
4319 spec->auto_mic = 0;
4320 return;
4321 }
4322 } else if (nums != spec->num_adc_nids) {
4323 memcpy(spec->private_adc_nids, adc_nids,
4324 nums * sizeof(hda_nid_t));
4325 memcpy(spec->private_capsrc_nids, capsrc_nids,
4326 nums * sizeof(hda_nid_t));
4327 spec->num_adc_nids = nums;
4328 }
4329
4330 if (spec->auto_mic)
4331 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004332 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004333 spec->num_adc_nids = 1; /* reduce to a single ADC */
4334}
4335
4336/*
4337 * initialize ADC paths
4338 */
4339static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4340{
4341 struct alc_spec *spec = codec->spec;
4342 hda_nid_t nid;
4343
4344 nid = spec->adc_nids[adc_idx];
4345 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004346 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004347 snd_hda_codec_write(codec, nid, 0,
4348 AC_VERB_SET_AMP_GAIN_MUTE,
4349 AMP_IN_MUTE(0));
4350 return;
4351 }
4352 if (!spec->capsrc_nids)
4353 return;
4354 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004355 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004356 snd_hda_codec_write(codec, nid, 0,
4357 AC_VERB_SET_AMP_GAIN_MUTE,
4358 AMP_OUT_MUTE);
4359}
4360
4361static void alc_auto_init_input_src(struct hda_codec *codec)
4362{
4363 struct alc_spec *spec = codec->spec;
4364 int c, nums;
4365
4366 for (c = 0; c < spec->num_adc_nids; c++)
4367 alc_auto_init_adc(codec, c);
4368 if (spec->dyn_adc_switch)
4369 nums = 1;
4370 else
4371 nums = spec->num_adc_nids;
4372 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004373 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004374}
4375
4376/* add mic boosts if needed */
4377static int alc_auto_add_mic_boost(struct hda_codec *codec)
4378{
4379 struct alc_spec *spec = codec->spec;
4380 struct auto_pin_cfg *cfg = &spec->autocfg;
4381 int i, err;
4382 int type_idx = 0;
4383 hda_nid_t nid;
4384 const char *prev_label = NULL;
4385
4386 for (i = 0; i < cfg->num_inputs; i++) {
4387 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4388 break;
4389 nid = cfg->inputs[i].pin;
4390 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4391 const char *label;
4392 char boost_label[32];
4393
4394 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004395 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4396 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004397 if (prev_label && !strcmp(label, prev_label))
4398 type_idx++;
4399 else
4400 type_idx = 0;
4401 prev_label = label;
4402
4403 snprintf(boost_label, sizeof(boost_label),
4404 "%s Boost Volume", label);
4405 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4406 boost_label, type_idx,
4407 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4408 if (err < 0)
4409 return err;
4410 }
4411 }
4412 return 0;
4413}
4414
4415/* select or unmute the given capsrc route */
4416static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4417 int idx)
4418{
4419 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4420 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4421 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004422 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004423 snd_hda_codec_write_cache(codec, cap, 0,
4424 AC_VERB_SET_CONNECT_SEL, idx);
4425 }
4426}
4427
4428/* set the default connection to that pin */
4429static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4430{
4431 struct alc_spec *spec = codec->spec;
4432 int i;
4433
4434 if (!pin)
4435 return 0;
4436 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004437 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004438 int idx;
4439
4440 idx = get_connection_index(codec, cap, pin);
4441 if (idx < 0)
4442 continue;
4443 select_or_unmute_capsrc(codec, cap, idx);
4444 return i; /* return the found index */
4445 }
4446 return -1; /* not found */
4447}
4448
4449/* initialize some special cases for input sources */
4450static void alc_init_special_input_src(struct hda_codec *codec)
4451{
4452 struct alc_spec *spec = codec->spec;
4453 int i;
4454
4455 for (i = 0; i < spec->autocfg.num_inputs; i++)
4456 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4457}
4458
4459/* assign appropriate capture mixers */
4460static void set_capture_mixer(struct hda_codec *codec)
4461{
4462 struct alc_spec *spec = codec->spec;
4463 static const struct snd_kcontrol_new *caps[2][3] = {
4464 { alc_capture_mixer_nosrc1,
4465 alc_capture_mixer_nosrc2,
4466 alc_capture_mixer_nosrc3 },
4467 { alc_capture_mixer1,
4468 alc_capture_mixer2,
4469 alc_capture_mixer3 },
4470 };
4471
4472 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004473 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004474 if (!spec->capsrc_nids)
4475 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004476 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004477 return; /* no volume in capsrc, too */
4478 spec->vol_in_capsrc = 1;
4479 }
4480
4481 if (spec->num_adc_nids > 0) {
4482 int mux = 0;
4483 int num_adcs = 0;
4484
4485 if (spec->input_mux && spec->input_mux->num_items > 1)
4486 mux = 1;
4487 if (spec->auto_mic) {
4488 num_adcs = 1;
4489 mux = 0;
4490 } else if (spec->dyn_adc_switch)
4491 num_adcs = 1;
4492 if (!num_adcs) {
4493 if (spec->num_adc_nids > 3)
4494 spec->num_adc_nids = 3;
4495 else if (!spec->num_adc_nids)
4496 return;
4497 num_adcs = spec->num_adc_nids;
4498 }
4499 spec->cap_mixer = caps[mux][num_adcs - 1];
4500 }
4501}
4502
4503/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004504 * standard auto-parser initializations
4505 */
4506static void alc_auto_init_std(struct hda_codec *codec)
4507{
Takashi Iwaie4770622011-07-08 11:11:35 +02004508 alc_auto_init_multi_out(codec);
4509 alc_auto_init_extra_out(codec);
4510 alc_auto_init_analog_input(codec);
4511 alc_auto_init_input_src(codec);
4512 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004513 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004514}
4515
4516/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004517 * Digital-beep handlers
4518 */
4519#ifdef CONFIG_SND_HDA_INPUT_BEEP
4520#define set_beep_amp(spec, nid, idx, dir) \
4521 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4522
4523static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004524 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004525 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4526 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4527 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4528 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004529 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004530 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4531 {}
4532};
4533
4534static inline int has_cdefine_beep(struct hda_codec *codec)
4535{
4536 struct alc_spec *spec = codec->spec;
4537 const struct snd_pci_quirk *q;
4538 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4539 if (q)
4540 return q->value;
4541 return spec->cdefine.enable_pcbeep;
4542}
4543#else
4544#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4545#define has_cdefine_beep(codec) 0
4546#endif
4547
4548/* parse the BIOS configuration and set up the alc_spec */
4549/* return 1 if successful, 0 if the proper config is not found,
4550 * or a negative error code
4551 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004552static int alc_parse_auto_config(struct hda_codec *codec,
4553 const hda_nid_t *ignore_nids,
4554 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004555{
4556 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004557 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004558 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004559
Takashi Iwai53c334a2011-08-23 18:27:14 +02004560 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4561 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004562 if (err < 0)
4563 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004564 if (!cfg->line_outs) {
4565 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004566 spec->multiout.max_channels = 2;
4567 spec->no_analog = 1;
4568 goto dig_only;
4569 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004570 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004571 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004572
Takashi Iwaie427c232012-07-29 10:04:08 +02004573 if (!spec->no_primary_hp &&
4574 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004575 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004576 /* use HP as primary out */
4577 cfg->speaker_outs = cfg->line_outs;
4578 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4579 sizeof(cfg->speaker_pins));
4580 cfg->line_outs = cfg->hp_outs;
4581 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4582 cfg->hp_outs = 0;
4583 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4584 cfg->line_out_type = AUTO_PIN_HP_OUT;
4585 }
4586
Takashi Iwai1d045db2011-07-07 18:23:21 +02004587 err = alc_auto_fill_dac_nids(codec);
4588 if (err < 0)
4589 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004590 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004591 if (err < 0)
4592 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004593 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004594 if (err < 0)
4595 return err;
4596 err = alc_auto_create_hp_out(codec);
4597 if (err < 0)
4598 return err;
4599 err = alc_auto_create_speaker_out(codec);
4600 if (err < 0)
4601 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004602 err = alc_auto_create_shared_input(codec);
4603 if (err < 0)
4604 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004605 err = alc_auto_create_input_ctls(codec);
4606 if (err < 0)
4607 return err;
4608
Takashi Iwaib6adb572012-12-03 10:30:58 +01004609 /* check the multiple speaker pins */
4610 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4611 spec->const_channel_count = cfg->line_outs * 2;
4612 else
4613 spec->const_channel_count = cfg->speaker_outs * 2;
4614
4615 if (spec->multi_ios > 0)
4616 spec->multiout.max_channels = max(spec->ext_channel_count,
4617 spec->const_channel_count);
4618 else
4619 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004620
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004621 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004622 alc_auto_parse_digital(codec);
4623
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004624 if (!spec->no_analog)
4625 alc_remove_invalid_adc_nids(codec);
4626
4627 if (ssid_nids)
4628 alc_ssid_check(codec, ssid_nids);
4629
4630 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004631 err = alc_auto_check_switches(codec);
4632 if (err < 0)
4633 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004634 err = alc_auto_add_mic_boost(codec);
4635 if (err < 0)
4636 return err;
4637 }
4638
Takashi Iwai1d045db2011-07-07 18:23:21 +02004639 if (spec->kctls.list)
4640 add_mixer(spec, spec->kctls.list);
4641
Takashi Iwai070cff42012-02-21 12:54:17 +01004642 if (!spec->no_analog && !spec->cap_mixer)
4643 set_capture_mixer(codec);
4644
Takashi Iwai1d045db2011-07-07 18:23:21 +02004645 return 1;
4646}
4647
Takashi Iwai3de95172012-05-07 18:03:15 +02004648/* common preparation job for alc_spec */
4649static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4650{
4651 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4652 int err;
4653
4654 if (!spec)
4655 return -ENOMEM;
4656 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004657 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004658 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004659 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004660 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4661 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004662 snd_array_init(&spec->out_path, sizeof(struct nid_path), 8);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01004663 snd_array_init(&spec->in_path, sizeof(struct nid_path), 8);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01004664 snd_array_init(&spec->loopback_path, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004665
4666 err = alc_codec_rename_from_preset(codec);
4667 if (err < 0) {
4668 kfree(spec);
4669 return err;
4670 }
4671 return 0;
4672}
4673
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004674static int alc880_parse_auto_config(struct hda_codec *codec)
4675{
4676 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004677 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004678 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4679}
4680
Takashi Iwai1d045db2011-07-07 18:23:21 +02004681/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004682 * ALC880 fix-ups
4683 */
4684enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004685 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004686 ALC880_FIXUP_GPIO2,
4687 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004688 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004689 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004690 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004691 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004692 ALC880_FIXUP_VOL_KNOB,
4693 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004694 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004695 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004696 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004697 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004698 ALC880_FIXUP_3ST_BASE,
4699 ALC880_FIXUP_3ST,
4700 ALC880_FIXUP_3ST_DIG,
4701 ALC880_FIXUP_5ST_BASE,
4702 ALC880_FIXUP_5ST,
4703 ALC880_FIXUP_5ST_DIG,
4704 ALC880_FIXUP_6ST_BASE,
4705 ALC880_FIXUP_6ST,
4706 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004707};
4708
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004709/* enable the volume-knob widget support on NID 0x21 */
4710static void alc880_fixup_vol_knob(struct hda_codec *codec,
4711 const struct alc_fixup *fix, int action)
4712{
4713 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004714 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004715}
4716
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004717static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004718 [ALC880_FIXUP_GPIO1] = {
4719 .type = ALC_FIXUP_VERBS,
4720 .v.verbs = alc_gpio1_init_verbs,
4721 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004722 [ALC880_FIXUP_GPIO2] = {
4723 .type = ALC_FIXUP_VERBS,
4724 .v.verbs = alc_gpio2_init_verbs,
4725 },
4726 [ALC880_FIXUP_MEDION_RIM] = {
4727 .type = ALC_FIXUP_VERBS,
4728 .v.verbs = (const struct hda_verb[]) {
4729 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4730 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4731 { }
4732 },
4733 .chained = true,
4734 .chain_id = ALC880_FIXUP_GPIO2,
4735 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004736 [ALC880_FIXUP_LG] = {
4737 .type = ALC_FIXUP_PINS,
4738 .v.pins = (const struct alc_pincfg[]) {
4739 /* disable bogus unused pins */
4740 { 0x16, 0x411111f0 },
4741 { 0x18, 0x411111f0 },
4742 { 0x1a, 0x411111f0 },
4743 { }
4744 }
4745 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004746 [ALC880_FIXUP_W810] = {
4747 .type = ALC_FIXUP_PINS,
4748 .v.pins = (const struct alc_pincfg[]) {
4749 /* disable bogus unused pins */
4750 { 0x17, 0x411111f0 },
4751 { }
4752 },
4753 .chained = true,
4754 .chain_id = ALC880_FIXUP_GPIO2,
4755 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004756 [ALC880_FIXUP_EAPD_COEF] = {
4757 .type = ALC_FIXUP_VERBS,
4758 .v.verbs = (const struct hda_verb[]) {
4759 /* change to EAPD mode */
4760 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4761 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4762 {}
4763 },
4764 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004765 [ALC880_FIXUP_TCL_S700] = {
4766 .type = ALC_FIXUP_VERBS,
4767 .v.verbs = (const struct hda_verb[]) {
4768 /* change to EAPD mode */
4769 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4770 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4771 {}
4772 },
4773 .chained = true,
4774 .chain_id = ALC880_FIXUP_GPIO2,
4775 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004776 [ALC880_FIXUP_VOL_KNOB] = {
4777 .type = ALC_FIXUP_FUNC,
4778 .v.func = alc880_fixup_vol_knob,
4779 },
4780 [ALC880_FIXUP_FUJITSU] = {
4781 /* override all pins as BIOS on old Amilo is broken */
4782 .type = ALC_FIXUP_PINS,
4783 .v.pins = (const struct alc_pincfg[]) {
4784 { 0x14, 0x0121411f }, /* HP */
4785 { 0x15, 0x99030120 }, /* speaker */
4786 { 0x16, 0x99030130 }, /* bass speaker */
4787 { 0x17, 0x411111f0 }, /* N/A */
4788 { 0x18, 0x411111f0 }, /* N/A */
4789 { 0x19, 0x01a19950 }, /* mic-in */
4790 { 0x1a, 0x411111f0 }, /* N/A */
4791 { 0x1b, 0x411111f0 }, /* N/A */
4792 { 0x1c, 0x411111f0 }, /* N/A */
4793 { 0x1d, 0x411111f0 }, /* N/A */
4794 { 0x1e, 0x01454140 }, /* SPDIF out */
4795 { }
4796 },
4797 .chained = true,
4798 .chain_id = ALC880_FIXUP_VOL_KNOB,
4799 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004800 [ALC880_FIXUP_F1734] = {
4801 /* almost compatible with FUJITSU, but no bass and SPDIF */
4802 .type = ALC_FIXUP_PINS,
4803 .v.pins = (const struct alc_pincfg[]) {
4804 { 0x14, 0x0121411f }, /* HP */
4805 { 0x15, 0x99030120 }, /* speaker */
4806 { 0x16, 0x411111f0 }, /* N/A */
4807 { 0x17, 0x411111f0 }, /* N/A */
4808 { 0x18, 0x411111f0 }, /* N/A */
4809 { 0x19, 0x01a19950 }, /* mic-in */
4810 { 0x1a, 0x411111f0 }, /* N/A */
4811 { 0x1b, 0x411111f0 }, /* N/A */
4812 { 0x1c, 0x411111f0 }, /* N/A */
4813 { 0x1d, 0x411111f0 }, /* N/A */
4814 { 0x1e, 0x411111f0 }, /* N/A */
4815 { }
4816 },
4817 .chained = true,
4818 .chain_id = ALC880_FIXUP_VOL_KNOB,
4819 },
Takashi Iwai817de922012-02-20 17:20:48 +01004820 [ALC880_FIXUP_UNIWILL] = {
4821 /* need to fix HP and speaker pins to be parsed correctly */
4822 .type = ALC_FIXUP_PINS,
4823 .v.pins = (const struct alc_pincfg[]) {
4824 { 0x14, 0x0121411f }, /* HP */
4825 { 0x15, 0x99030120 }, /* speaker */
4826 { 0x16, 0x99030130 }, /* bass speaker */
4827 { }
4828 },
4829 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004830 [ALC880_FIXUP_UNIWILL_DIG] = {
4831 .type = ALC_FIXUP_PINS,
4832 .v.pins = (const struct alc_pincfg[]) {
4833 /* disable bogus unused pins */
4834 { 0x17, 0x411111f0 },
4835 { 0x19, 0x411111f0 },
4836 { 0x1b, 0x411111f0 },
4837 { 0x1f, 0x411111f0 },
4838 { }
4839 }
4840 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004841 [ALC880_FIXUP_Z71V] = {
4842 .type = ALC_FIXUP_PINS,
4843 .v.pins = (const struct alc_pincfg[]) {
4844 /* set up the whole pins as BIOS is utterly broken */
4845 { 0x14, 0x99030120 }, /* speaker */
4846 { 0x15, 0x0121411f }, /* HP */
4847 { 0x16, 0x411111f0 }, /* N/A */
4848 { 0x17, 0x411111f0 }, /* N/A */
4849 { 0x18, 0x01a19950 }, /* mic-in */
4850 { 0x19, 0x411111f0 }, /* N/A */
4851 { 0x1a, 0x01813031 }, /* line-in */
4852 { 0x1b, 0x411111f0 }, /* N/A */
4853 { 0x1c, 0x411111f0 }, /* N/A */
4854 { 0x1d, 0x411111f0 }, /* N/A */
4855 { 0x1e, 0x0144111e }, /* SPDIF */
4856 { }
4857 }
4858 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004859 [ALC880_FIXUP_3ST_BASE] = {
4860 .type = ALC_FIXUP_PINS,
4861 .v.pins = (const struct alc_pincfg[]) {
4862 { 0x14, 0x01014010 }, /* line-out */
4863 { 0x15, 0x411111f0 }, /* N/A */
4864 { 0x16, 0x411111f0 }, /* N/A */
4865 { 0x17, 0x411111f0 }, /* N/A */
4866 { 0x18, 0x01a19c30 }, /* mic-in */
4867 { 0x19, 0x0121411f }, /* HP */
4868 { 0x1a, 0x01813031 }, /* line-in */
4869 { 0x1b, 0x02a19c40 }, /* front-mic */
4870 { 0x1c, 0x411111f0 }, /* N/A */
4871 { 0x1d, 0x411111f0 }, /* N/A */
4872 /* 0x1e is filled in below */
4873 { 0x1f, 0x411111f0 }, /* N/A */
4874 { }
4875 }
4876 },
4877 [ALC880_FIXUP_3ST] = {
4878 .type = ALC_FIXUP_PINS,
4879 .v.pins = (const struct alc_pincfg[]) {
4880 { 0x1e, 0x411111f0 }, /* N/A */
4881 { }
4882 },
4883 .chained = true,
4884 .chain_id = ALC880_FIXUP_3ST_BASE,
4885 },
4886 [ALC880_FIXUP_3ST_DIG] = {
4887 .type = ALC_FIXUP_PINS,
4888 .v.pins = (const struct alc_pincfg[]) {
4889 { 0x1e, 0x0144111e }, /* SPDIF */
4890 { }
4891 },
4892 .chained = true,
4893 .chain_id = ALC880_FIXUP_3ST_BASE,
4894 },
4895 [ALC880_FIXUP_5ST_BASE] = {
4896 .type = ALC_FIXUP_PINS,
4897 .v.pins = (const struct alc_pincfg[]) {
4898 { 0x14, 0x01014010 }, /* front */
4899 { 0x15, 0x411111f0 }, /* N/A */
4900 { 0x16, 0x01011411 }, /* CLFE */
4901 { 0x17, 0x01016412 }, /* surr */
4902 { 0x18, 0x01a19c30 }, /* mic-in */
4903 { 0x19, 0x0121411f }, /* HP */
4904 { 0x1a, 0x01813031 }, /* line-in */
4905 { 0x1b, 0x02a19c40 }, /* front-mic */
4906 { 0x1c, 0x411111f0 }, /* N/A */
4907 { 0x1d, 0x411111f0 }, /* N/A */
4908 /* 0x1e is filled in below */
4909 { 0x1f, 0x411111f0 }, /* N/A */
4910 { }
4911 }
4912 },
4913 [ALC880_FIXUP_5ST] = {
4914 .type = ALC_FIXUP_PINS,
4915 .v.pins = (const struct alc_pincfg[]) {
4916 { 0x1e, 0x411111f0 }, /* N/A */
4917 { }
4918 },
4919 .chained = true,
4920 .chain_id = ALC880_FIXUP_5ST_BASE,
4921 },
4922 [ALC880_FIXUP_5ST_DIG] = {
4923 .type = ALC_FIXUP_PINS,
4924 .v.pins = (const struct alc_pincfg[]) {
4925 { 0x1e, 0x0144111e }, /* SPDIF */
4926 { }
4927 },
4928 .chained = true,
4929 .chain_id = ALC880_FIXUP_5ST_BASE,
4930 },
4931 [ALC880_FIXUP_6ST_BASE] = {
4932 .type = ALC_FIXUP_PINS,
4933 .v.pins = (const struct alc_pincfg[]) {
4934 { 0x14, 0x01014010 }, /* front */
4935 { 0x15, 0x01016412 }, /* surr */
4936 { 0x16, 0x01011411 }, /* CLFE */
4937 { 0x17, 0x01012414 }, /* side */
4938 { 0x18, 0x01a19c30 }, /* mic-in */
4939 { 0x19, 0x02a19c40 }, /* front-mic */
4940 { 0x1a, 0x01813031 }, /* line-in */
4941 { 0x1b, 0x0121411f }, /* HP */
4942 { 0x1c, 0x411111f0 }, /* N/A */
4943 { 0x1d, 0x411111f0 }, /* N/A */
4944 /* 0x1e is filled in below */
4945 { 0x1f, 0x411111f0 }, /* N/A */
4946 { }
4947 }
4948 },
4949 [ALC880_FIXUP_6ST] = {
4950 .type = ALC_FIXUP_PINS,
4951 .v.pins = (const struct alc_pincfg[]) {
4952 { 0x1e, 0x411111f0 }, /* N/A */
4953 { }
4954 },
4955 .chained = true,
4956 .chain_id = ALC880_FIXUP_6ST_BASE,
4957 },
4958 [ALC880_FIXUP_6ST_DIG] = {
4959 .type = ALC_FIXUP_PINS,
4960 .v.pins = (const struct alc_pincfg[]) {
4961 { 0x1e, 0x0144111e }, /* SPDIF */
4962 { }
4963 },
4964 .chained = true,
4965 .chain_id = ALC880_FIXUP_6ST_BASE,
4966 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004967};
4968
4969static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004970 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004971 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004972 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4973 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004974 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004975 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004976 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004977 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004978 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004979 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004980 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004981 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004982 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004983 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004984 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004985 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4986 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4987 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004988 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004989
4990 /* Below is the copied entries from alc880_quirks.c.
4991 * It's not quite sure whether BIOS sets the correct pin-config table
4992 * on these machines, thus they are kept to be compatible with
4993 * the old static quirks. Once when it's confirmed to work without
4994 * these overrides, it'd be better to remove.
4995 */
4996 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4997 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4998 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4999 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
5000 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
5001 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
5002 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
5003 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
5004 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
5005 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
5006 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
5007 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
5008 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
5009 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
5010 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
5011 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
5012 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
5013 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
5014 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
5015 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
5016 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
5017 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
5018 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
5019 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5020 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5021 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5022 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5023 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5024 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5025 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5026 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5027 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5028 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5029 /* default Intel */
5030 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
5031 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
5032 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
5033 {}
5034};
5035
5036static const struct alc_model_fixup alc880_fixup_models[] = {
5037 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
5038 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
5039 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
5040 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
5041 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
5042 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01005043 {}
5044};
5045
5046
5047/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02005048 * OK, here we have finally the patch for ALC880
5049 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005050static int patch_alc880(struct hda_codec *codec)
5051{
5052 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005053 int err;
5054
Takashi Iwai3de95172012-05-07 18:03:15 +02005055 err = alc_alloc_spec(codec, 0x0b);
5056 if (err < 0)
5057 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005058
Takashi Iwai3de95172012-05-07 18:03:15 +02005059 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02005060 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005061
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005062 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
5063 alc880_fixups);
5064 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005065
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005066 /* automatic parse from the BIOS config */
5067 err = alc880_parse_auto_config(codec);
5068 if (err < 0)
5069 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005070
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005071 if (!spec->no_analog) {
5072 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005073 if (err < 0)
5074 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005075 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5076 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005077
Takashi Iwai1d045db2011-07-07 18:23:21 +02005078 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02005079 codec->patch_ops.unsol_event = alc880_unsol_event;
5080
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081
Takashi Iwai589876e2012-02-20 15:47:55 +01005082 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5083
Takashi Iwai1d045db2011-07-07 18:23:21 +02005084 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005085
5086 error:
5087 alc_free(codec);
5088 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005089}
5090
5091
5092/*
5093 * ALC260 support
5094 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005095static int alc260_parse_auto_config(struct hda_codec *codec)
5096{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005097 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005098 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5099 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005100}
5101
Takashi Iwai1d045db2011-07-07 18:23:21 +02005102/*
5103 * Pin config fixes
5104 */
5105enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005106 ALC260_FIXUP_HP_DC5750,
5107 ALC260_FIXUP_HP_PIN_0F,
5108 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005109 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005110 ALC260_FIXUP_GPIO1_TOGGLE,
5111 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005112 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005113 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005114};
5115
Takashi Iwai20f7d922012-02-16 12:35:16 +01005116static void alc260_gpio1_automute(struct hda_codec *codec)
5117{
5118 struct alc_spec *spec = codec->spec;
5119 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5120 spec->hp_jack_present);
5121}
5122
5123static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5124 const struct alc_fixup *fix, int action)
5125{
5126 struct alc_spec *spec = codec->spec;
5127 if (action == ALC_FIXUP_ACT_PROBE) {
5128 /* although the machine has only one output pin, we need to
5129 * toggle GPIO1 according to the jack state
5130 */
5131 spec->automute_hook = alc260_gpio1_automute;
5132 spec->detect_hp = 1;
5133 spec->automute_speaker = 1;
5134 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005135 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5136 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005137 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005138 }
5139}
5140
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005141static void alc260_fixup_kn1(struct hda_codec *codec,
5142 const struct alc_fixup *fix, int action)
5143{
5144 struct alc_spec *spec = codec->spec;
5145 static const struct alc_pincfg pincfgs[] = {
5146 { 0x0f, 0x02214000 }, /* HP/speaker */
5147 { 0x12, 0x90a60160 }, /* int mic */
5148 { 0x13, 0x02a19000 }, /* ext mic */
5149 { 0x18, 0x01446000 }, /* SPDIF out */
5150 /* disable bogus I/O pins */
5151 { 0x10, 0x411111f0 },
5152 { 0x11, 0x411111f0 },
5153 { 0x14, 0x411111f0 },
5154 { 0x15, 0x411111f0 },
5155 { 0x16, 0x411111f0 },
5156 { 0x17, 0x411111f0 },
5157 { 0x19, 0x411111f0 },
5158 { }
5159 };
5160
5161 switch (action) {
5162 case ALC_FIXUP_ACT_PRE_PROBE:
5163 alc_apply_pincfgs(codec, pincfgs);
5164 break;
5165 case ALC_FIXUP_ACT_PROBE:
5166 spec->init_amp = ALC_INIT_NONE;
5167 break;
5168 }
5169}
5170
Takashi Iwai1d045db2011-07-07 18:23:21 +02005171static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005172 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005173 .type = ALC_FIXUP_PINS,
5174 .v.pins = (const struct alc_pincfg[]) {
5175 { 0x11, 0x90130110 }, /* speaker */
5176 { }
5177 }
5178 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005179 [ALC260_FIXUP_HP_PIN_0F] = {
5180 .type = ALC_FIXUP_PINS,
5181 .v.pins = (const struct alc_pincfg[]) {
5182 { 0x0f, 0x01214000 }, /* HP */
5183 { }
5184 }
5185 },
5186 [ALC260_FIXUP_COEF] = {
5187 .type = ALC_FIXUP_VERBS,
5188 .v.verbs = (const struct hda_verb[]) {
5189 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5190 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5191 { }
5192 },
5193 .chained = true,
5194 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5195 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005196 [ALC260_FIXUP_GPIO1] = {
5197 .type = ALC_FIXUP_VERBS,
5198 .v.verbs = alc_gpio1_init_verbs,
5199 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005200 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5201 .type = ALC_FIXUP_FUNC,
5202 .v.func = alc260_fixup_gpio1_toggle,
5203 .chained = true,
5204 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5205 },
5206 [ALC260_FIXUP_REPLACER] = {
5207 .type = ALC_FIXUP_VERBS,
5208 .v.verbs = (const struct hda_verb[]) {
5209 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5210 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5211 { }
5212 },
5213 .chained = true,
5214 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5215 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005216 [ALC260_FIXUP_HP_B1900] = {
5217 .type = ALC_FIXUP_FUNC,
5218 .v.func = alc260_fixup_gpio1_toggle,
5219 .chained = true,
5220 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005221 },
5222 [ALC260_FIXUP_KN1] = {
5223 .type = ALC_FIXUP_FUNC,
5224 .v.func = alc260_fixup_kn1,
5225 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005226};
5227
5228static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005229 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005230 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005231 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005232 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005233 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005234 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005235 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005236 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005237 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005238 {}
5239};
5240
5241/*
5242 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005243static int patch_alc260(struct hda_codec *codec)
5244{
5245 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005246 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005247
Takashi Iwai3de95172012-05-07 18:03:15 +02005248 err = alc_alloc_spec(codec, 0x07);
5249 if (err < 0)
5250 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005251
Takashi Iwai3de95172012-05-07 18:03:15 +02005252 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005253
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005254 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5255 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005256
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005257 /* automatic parse from the BIOS config */
5258 err = alc260_parse_auto_config(codec);
5259 if (err < 0)
5260 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005261
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005262 if (!spec->no_analog) {
5263 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005264 if (err < 0)
5265 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005266 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5267 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005268
Takashi Iwai1d045db2011-07-07 18:23:21 +02005269 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005270 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005271
Takashi Iwai589876e2012-02-20 15:47:55 +01005272 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5273
Takashi Iwai1d045db2011-07-07 18:23:21 +02005274 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005275
5276 error:
5277 alc_free(codec);
5278 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005279}
5280
5281
5282/*
5283 * ALC882/883/885/888/889 support
5284 *
5285 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5286 * configuration. Each pin widget can choose any input DACs and a mixer.
5287 * Each ADC is connected from a mixer of all inputs. This makes possible
5288 * 6-channel independent captures.
5289 *
5290 * In addition, an independent DAC for the multi-playback (not used in this
5291 * driver yet).
5292 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005293
5294/*
5295 * Pin config fixes
5296 */
5297enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005298 ALC882_FIXUP_ABIT_AW9D_MAX,
5299 ALC882_FIXUP_LENOVO_Y530,
5300 ALC882_FIXUP_PB_M5210,
5301 ALC882_FIXUP_ACER_ASPIRE_7736,
5302 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005303 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005304 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005305 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005306 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005307 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005308 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005309 ALC882_FIXUP_GPIO1,
5310 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005311 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005312 ALC889_FIXUP_COEF,
5313 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005314 ALC882_FIXUP_ACER_ASPIRE_4930G,
5315 ALC882_FIXUP_ACER_ASPIRE_8930G,
5316 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005317 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005318 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005319 ALC889_FIXUP_MBP_VREF,
5320 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005321 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005322 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005323};
5324
Takashi Iwai68ef0562011-11-09 18:24:44 +01005325static void alc889_fixup_coef(struct hda_codec *codec,
5326 const struct alc_fixup *fix, int action)
5327{
5328 if (action != ALC_FIXUP_ACT_INIT)
5329 return;
5330 alc889_coef_init(codec);
5331}
5332
Takashi Iwai56710872011-11-14 17:42:11 +01005333/* toggle speaker-output according to the hp-jack state */
5334static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5335{
5336 unsigned int gpiostate, gpiomask, gpiodir;
5337
5338 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5339 AC_VERB_GET_GPIO_DATA, 0);
5340
5341 if (!muted)
5342 gpiostate |= (1 << pin);
5343 else
5344 gpiostate &= ~(1 << pin);
5345
5346 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5347 AC_VERB_GET_GPIO_MASK, 0);
5348 gpiomask |= (1 << pin);
5349
5350 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5351 AC_VERB_GET_GPIO_DIRECTION, 0);
5352 gpiodir |= (1 << pin);
5353
5354
5355 snd_hda_codec_write(codec, codec->afg, 0,
5356 AC_VERB_SET_GPIO_MASK, gpiomask);
5357 snd_hda_codec_write(codec, codec->afg, 0,
5358 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5359
5360 msleep(1);
5361
5362 snd_hda_codec_write(codec, codec->afg, 0,
5363 AC_VERB_SET_GPIO_DATA, gpiostate);
5364}
5365
5366/* set up GPIO at initialization */
5367static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5368 const struct alc_fixup *fix, int action)
5369{
5370 if (action != ALC_FIXUP_ACT_INIT)
5371 return;
5372 alc882_gpio_mute(codec, 0, 0);
5373 alc882_gpio_mute(codec, 1, 0);
5374}
5375
Takashi Iwai02a237b2012-02-13 15:25:07 +01005376/* Fix the connection of some pins for ALC889:
5377 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5378 * work correctly (bko#42740)
5379 */
5380static void alc889_fixup_dac_route(struct hda_codec *codec,
5381 const struct alc_fixup *fix, int action)
5382{
5383 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005384 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005385 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5386 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5387 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5388 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5389 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5390 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005391 } else if (action == ALC_FIXUP_ACT_PROBE) {
5392 /* restore the connections */
5393 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5394 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5395 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5396 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5397 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005398 }
5399}
5400
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005401/* Set VREF on HP pin */
5402static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5403 const struct alc_fixup *fix, int action)
5404{
5405 struct alc_spec *spec = codec->spec;
5406 static hda_nid_t nids[2] = { 0x14, 0x15 };
5407 int i;
5408
5409 if (action != ALC_FIXUP_ACT_INIT)
5410 return;
5411 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5412 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5413 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5414 continue;
5415 val = snd_hda_codec_read(codec, nids[i], 0,
5416 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5417 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005418 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005419 spec->keep_vref_in_automute = 1;
5420 break;
5421 }
5422}
5423
5424/* Set VREF on speaker pins on imac91 */
5425static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5426 const struct alc_fixup *fix, int action)
5427{
5428 struct alc_spec *spec = codec->spec;
5429 static hda_nid_t nids[2] = { 0x18, 0x1a };
5430 int i;
5431
5432 if (action != ALC_FIXUP_ACT_INIT)
5433 return;
5434 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5435 unsigned int val;
5436 val = snd_hda_codec_read(codec, nids[i], 0,
5437 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5438 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005439 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005440 }
5441 spec->keep_vref_in_automute = 1;
5442}
5443
Takashi Iwaie427c232012-07-29 10:04:08 +02005444/* Don't take HP output as primary
5445 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5446 */
5447static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5448 const struct alc_fixup *fix, int action)
5449{
5450 struct alc_spec *spec = codec->spec;
5451 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5452 spec->no_primary_hp = 1;
5453}
5454
Takashi Iwai1d045db2011-07-07 18:23:21 +02005455static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005456 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005457 .type = ALC_FIXUP_PINS,
5458 .v.pins = (const struct alc_pincfg[]) {
5459 { 0x15, 0x01080104 }, /* side */
5460 { 0x16, 0x01011012 }, /* rear */
5461 { 0x17, 0x01016011 }, /* clfe */
5462 { }
5463 }
5464 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005465 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005466 .type = ALC_FIXUP_PINS,
5467 .v.pins = (const struct alc_pincfg[]) {
5468 { 0x15, 0x99130112 }, /* rear int speakers */
5469 { 0x16, 0x99130111 }, /* subwoofer */
5470 { }
5471 }
5472 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005473 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005474 .type = ALC_FIXUP_VERBS,
5475 .v.verbs = (const struct hda_verb[]) {
5476 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5477 {}
5478 }
5479 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005480 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005481 .type = ALC_FIXUP_FUNC,
5482 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005483 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005484 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005485 .type = ALC_FIXUP_PINS,
5486 .v.pins = (const struct alc_pincfg[]) {
5487 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5488 { }
5489 }
5490 },
Marton Balint8f239212012-03-05 21:33:23 +01005491 [ALC889_FIXUP_CD] = {
5492 .type = ALC_FIXUP_PINS,
5493 .v.pins = (const struct alc_pincfg[]) {
5494 { 0x1c, 0x993301f0 }, /* CD */
5495 { }
5496 }
5497 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005498 [ALC889_FIXUP_VAIO_TT] = {
5499 .type = ALC_FIXUP_PINS,
5500 .v.pins = (const struct alc_pincfg[]) {
5501 { 0x17, 0x90170111 }, /* hidden surround speaker */
5502 { }
5503 }
5504 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005505 [ALC888_FIXUP_EEE1601] = {
5506 .type = ALC_FIXUP_VERBS,
5507 .v.verbs = (const struct hda_verb[]) {
5508 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5509 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5510 { }
5511 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005512 },
5513 [ALC882_FIXUP_EAPD] = {
5514 .type = ALC_FIXUP_VERBS,
5515 .v.verbs = (const struct hda_verb[]) {
5516 /* change to EAPD mode */
5517 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5518 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5519 { }
5520 }
5521 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005522 [ALC883_FIXUP_EAPD] = {
5523 .type = ALC_FIXUP_VERBS,
5524 .v.verbs = (const struct hda_verb[]) {
5525 /* change to EAPD mode */
5526 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5527 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5528 { }
5529 }
5530 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005531 [ALC883_FIXUP_ACER_EAPD] = {
5532 .type = ALC_FIXUP_VERBS,
5533 .v.verbs = (const struct hda_verb[]) {
5534 /* eanable EAPD on Acer laptops */
5535 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5536 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5537 { }
5538 }
5539 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005540 [ALC882_FIXUP_GPIO1] = {
5541 .type = ALC_FIXUP_VERBS,
5542 .v.verbs = alc_gpio1_init_verbs,
5543 },
5544 [ALC882_FIXUP_GPIO2] = {
5545 .type = ALC_FIXUP_VERBS,
5546 .v.verbs = alc_gpio2_init_verbs,
5547 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005548 [ALC882_FIXUP_GPIO3] = {
5549 .type = ALC_FIXUP_VERBS,
5550 .v.verbs = alc_gpio3_init_verbs,
5551 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005552 [ALC882_FIXUP_ASUS_W2JC] = {
5553 .type = ALC_FIXUP_VERBS,
5554 .v.verbs = alc_gpio1_init_verbs,
5555 .chained = true,
5556 .chain_id = ALC882_FIXUP_EAPD,
5557 },
5558 [ALC889_FIXUP_COEF] = {
5559 .type = ALC_FIXUP_FUNC,
5560 .v.func = alc889_fixup_coef,
5561 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005562 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5563 .type = ALC_FIXUP_PINS,
5564 .v.pins = (const struct alc_pincfg[]) {
5565 { 0x16, 0x99130111 }, /* CLFE speaker */
5566 { 0x17, 0x99130112 }, /* surround speaker */
5567 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005568 },
5569 .chained = true,
5570 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005571 },
5572 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5573 .type = ALC_FIXUP_PINS,
5574 .v.pins = (const struct alc_pincfg[]) {
5575 { 0x16, 0x99130111 }, /* CLFE speaker */
5576 { 0x1b, 0x99130112 }, /* surround speaker */
5577 { }
5578 },
5579 .chained = true,
5580 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5581 },
5582 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5583 /* additional init verbs for Acer Aspire 8930G */
5584 .type = ALC_FIXUP_VERBS,
5585 .v.verbs = (const struct hda_verb[]) {
5586 /* Enable all DACs */
5587 /* DAC DISABLE/MUTE 1? */
5588 /* setting bits 1-5 disables DAC nids 0x02-0x06
5589 * apparently. Init=0x38 */
5590 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5591 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5592 /* DAC DISABLE/MUTE 2? */
5593 /* some bit here disables the other DACs.
5594 * Init=0x4900 */
5595 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5596 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5597 /* DMIC fix
5598 * This laptop has a stereo digital microphone.
5599 * The mics are only 1cm apart which makes the stereo
5600 * useless. However, either the mic or the ALC889
5601 * makes the signal become a difference/sum signal
5602 * instead of standard stereo, which is annoying.
5603 * So instead we flip this bit which makes the
5604 * codec replicate the sum signal to both channels,
5605 * turning it into a normal mono mic.
5606 */
5607 /* DMIC_CONTROL? Init value = 0x0001 */
5608 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5609 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5610 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5611 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5612 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005613 },
5614 .chained = true,
5615 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005616 },
Takashi Iwai56710872011-11-14 17:42:11 +01005617 [ALC885_FIXUP_MACPRO_GPIO] = {
5618 .type = ALC_FIXUP_FUNC,
5619 .v.func = alc885_fixup_macpro_gpio,
5620 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005621 [ALC889_FIXUP_DAC_ROUTE] = {
5622 .type = ALC_FIXUP_FUNC,
5623 .v.func = alc889_fixup_dac_route,
5624 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005625 [ALC889_FIXUP_MBP_VREF] = {
5626 .type = ALC_FIXUP_FUNC,
5627 .v.func = alc889_fixup_mbp_vref,
5628 .chained = true,
5629 .chain_id = ALC882_FIXUP_GPIO1,
5630 },
5631 [ALC889_FIXUP_IMAC91_VREF] = {
5632 .type = ALC_FIXUP_FUNC,
5633 .v.func = alc889_fixup_imac91_vref,
5634 .chained = true,
5635 .chain_id = ALC882_FIXUP_GPIO1,
5636 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005637 [ALC882_FIXUP_INV_DMIC] = {
5638 .type = ALC_FIXUP_FUNC,
5639 .v.func = alc_fixup_inv_dmic_0x12,
5640 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005641 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5642 .type = ALC_FIXUP_FUNC,
5643 .v.func = alc882_fixup_no_primary_hp,
5644 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645};
5646
5647static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005648 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5649 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5650 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5651 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5652 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5653 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005654 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5655 ALC882_FIXUP_ACER_ASPIRE_4930G),
5656 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5657 ALC882_FIXUP_ACER_ASPIRE_4930G),
5658 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5659 ALC882_FIXUP_ACER_ASPIRE_8930G),
5660 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5661 ALC882_FIXUP_ACER_ASPIRE_8930G),
5662 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5663 ALC882_FIXUP_ACER_ASPIRE_4930G),
5664 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5665 ALC882_FIXUP_ACER_ASPIRE_4930G),
5666 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5667 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005668 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005669 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5670 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005671 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005672 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005673 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005674 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005675 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005676 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005677 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005678 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005679 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005680
5681 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005682 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5683 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5684 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005685 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5686 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5687 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005688 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5689 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005690 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005691 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5692 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5693 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5694 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005695 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005696 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5697 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5698 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005699 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005700 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005701 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5702 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5703 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005704
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005705 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005706 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005707 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005708 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005709 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005710 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5711 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005712 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005713 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005714 {}
5715};
5716
Takashi Iwai912093b2012-04-11 14:03:41 +02005717static const struct alc_model_fixup alc882_fixup_models[] = {
5718 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5719 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5720 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005721 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005722 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005723 {}
5724};
5725
Takashi Iwai1d045db2011-07-07 18:23:21 +02005726/*
5727 * BIOS auto configuration
5728 */
5729/* almost identical with ALC880 parser... */
5730static int alc882_parse_auto_config(struct hda_codec *codec)
5731{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005732 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005733 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5734 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005735}
5736
Takashi Iwai1d045db2011-07-07 18:23:21 +02005737/*
5738 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005739static int patch_alc882(struct hda_codec *codec)
5740{
5741 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005742 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743
Takashi Iwai3de95172012-05-07 18:03:15 +02005744 err = alc_alloc_spec(codec, 0x0b);
5745 if (err < 0)
5746 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005747
Takashi Iwai3de95172012-05-07 18:03:15 +02005748 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005749
5750 switch (codec->vendor_id) {
5751 case 0x10ec0882:
5752 case 0x10ec0885:
5753 break;
5754 default:
5755 /* ALC883 and variants */
5756 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5757 break;
5758 }
5759
Takashi Iwai912093b2012-04-11 14:03:41 +02005760 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5761 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005762 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005763
5764 alc_auto_parse_customize_define(codec);
5765
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005766 /* automatic parse from the BIOS config */
5767 err = alc882_parse_auto_config(codec);
5768 if (err < 0)
5769 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005770
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005771 if (!spec->no_analog && has_cdefine_beep(codec)) {
5772 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005773 if (err < 0)
5774 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005775 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005776 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005777
Takashi Iwai1d045db2011-07-07 18:23:21 +02005778 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005779
Takashi Iwai589876e2012-02-20 15:47:55 +01005780 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5781
Takashi Iwai1d045db2011-07-07 18:23:21 +02005782 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005783
5784 error:
5785 alc_free(codec);
5786 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005787}
5788
5789
5790/*
5791 * ALC262 support
5792 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005793static int alc262_parse_auto_config(struct hda_codec *codec)
5794{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005795 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005796 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5797 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005798}
5799
5800/*
5801 * Pin config fixes
5802 */
5803enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005804 ALC262_FIXUP_FSC_H270,
5805 ALC262_FIXUP_HP_Z200,
5806 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005807 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005808 ALC262_FIXUP_BENQ,
5809 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005810 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005811};
5812
5813static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005814 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005815 .type = ALC_FIXUP_PINS,
5816 .v.pins = (const struct alc_pincfg[]) {
5817 { 0x14, 0x99130110 }, /* speaker */
5818 { 0x15, 0x0221142f }, /* front HP */
5819 { 0x1b, 0x0121141f }, /* rear HP */
5820 { }
5821 }
5822 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005823 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005824 .type = ALC_FIXUP_PINS,
5825 .v.pins = (const struct alc_pincfg[]) {
5826 { 0x16, 0x99130120 }, /* internal speaker */
5827 { }
5828 }
5829 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005830 [ALC262_FIXUP_TYAN] = {
5831 .type = ALC_FIXUP_PINS,
5832 .v.pins = (const struct alc_pincfg[]) {
5833 { 0x14, 0x1993e1f0 }, /* int AUX */
5834 { }
5835 }
5836 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005837 [ALC262_FIXUP_LENOVO_3000] = {
5838 .type = ALC_FIXUP_VERBS,
5839 .v.verbs = (const struct hda_verb[]) {
5840 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005841 {}
5842 },
5843 .chained = true,
5844 .chain_id = ALC262_FIXUP_BENQ,
5845 },
5846 [ALC262_FIXUP_BENQ] = {
5847 .type = ALC_FIXUP_VERBS,
5848 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005849 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5850 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5851 {}
5852 }
5853 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005854 [ALC262_FIXUP_BENQ_T31] = {
5855 .type = ALC_FIXUP_VERBS,
5856 .v.verbs = (const struct hda_verb[]) {
5857 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5858 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5859 {}
5860 }
5861 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005862 [ALC262_FIXUP_INV_DMIC] = {
5863 .type = ALC_FIXUP_FUNC,
5864 .v.func = alc_fixup_inv_dmic_0x12,
5865 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005866};
5867
5868static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005869 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005870 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5871 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005872 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5873 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005874 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005875 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5876 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005877 {}
5878};
5879
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005880static const struct alc_model_fixup alc262_fixup_models[] = {
5881 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5882 {}
5883};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005884
Takashi Iwai1d045db2011-07-07 18:23:21 +02005885/*
5886 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887static int patch_alc262(struct hda_codec *codec)
5888{
5889 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005890 int err;
5891
Takashi Iwai3de95172012-05-07 18:03:15 +02005892 err = alc_alloc_spec(codec, 0x0b);
5893 if (err < 0)
5894 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005895
Takashi Iwai3de95172012-05-07 18:03:15 +02005896 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005897
5898#if 0
5899 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5900 * under-run
5901 */
5902 {
5903 int tmp;
5904 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5905 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5906 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5907 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5908 }
5909#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005910 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5911
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005912 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5913 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005914 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005915
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005916 alc_auto_parse_customize_define(codec);
5917
Takashi Iwai42399f72011-11-07 17:18:44 +01005918 /* automatic parse from the BIOS config */
5919 err = alc262_parse_auto_config(codec);
5920 if (err < 0)
5921 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005922
Takashi Iwai1d045db2011-07-07 18:23:21 +02005923 if (!spec->no_analog && has_cdefine_beep(codec)) {
5924 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005925 if (err < 0)
5926 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005927 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005928 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005929
Takashi Iwai1d045db2011-07-07 18:23:21 +02005930 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005931 spec->shutup = alc_eapd_shutup;
5932
Takashi Iwai589876e2012-02-20 15:47:55 +01005933 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5934
Takashi Iwai1d045db2011-07-07 18:23:21 +02005935 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005936
5937 error:
5938 alc_free(codec);
5939 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005940}
5941
5942/*
5943 * ALC268
5944 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005945/* bind Beep switches of both NID 0x0f and 0x10 */
5946static const struct hda_bind_ctls alc268_bind_beep_sw = {
5947 .ops = &snd_hda_bind_sw,
5948 .values = {
5949 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5950 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5951 0
5952 },
5953};
5954
5955static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5956 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5957 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5958 { }
5959};
5960
5961/* set PCBEEP vol = 0, mute connections */
5962static const struct hda_verb alc268_beep_init_verbs[] = {
5963 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5964 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5965 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5966 { }
5967};
5968
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005969enum {
5970 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005971 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005972};
5973
5974static const struct alc_fixup alc268_fixups[] = {
5975 [ALC268_FIXUP_INV_DMIC] = {
5976 .type = ALC_FIXUP_FUNC,
5977 .v.func = alc_fixup_inv_dmic_0x12,
5978 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005979 [ALC268_FIXUP_HP_EAPD] = {
5980 .type = ALC_FIXUP_VERBS,
5981 .v.verbs = (const struct hda_verb[]) {
5982 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5983 {}
5984 }
5985 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005986};
5987
5988static const struct alc_model_fixup alc268_fixup_models[] = {
5989 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005990 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5991 {}
5992};
5993
5994static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5995 /* below is codec SSID since multiple Toshiba laptops have the
5996 * same PCI SSID 1179:ff00
5997 */
5998 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005999 {}
6000};
6001
Takashi Iwai1d045db2011-07-07 18:23:21 +02006002/*
6003 * BIOS auto configuration
6004 */
6005static int alc268_parse_auto_config(struct hda_codec *codec)
6006{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006007 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02006008 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006009 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
6010 if (err > 0) {
6011 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
6012 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02006013 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006014 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006015 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006016 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006017}
6018
Takashi Iwai1d045db2011-07-07 18:23:21 +02006019/*
6020 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006021static int patch_alc268(struct hda_codec *codec)
6022{
6023 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006024 int i, has_beep, err;
6025
Takashi Iwai1d045db2011-07-07 18:23:21 +02006026 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006027 err = alc_alloc_spec(codec, 0);
6028 if (err < 0)
6029 return err;
6030
6031 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006032
Takashi Iwaicb766402012-10-20 10:55:21 +02006033 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006034 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6035
Takashi Iwai6ebb8052011-08-16 15:15:40 +02006036 /* automatic parse from the BIOS config */
6037 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006038 if (err < 0)
6039 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006040
Takashi Iwai1d045db2011-07-07 18:23:21 +02006041 has_beep = 0;
6042 for (i = 0; i < spec->num_mixers; i++) {
6043 if (spec->mixers[i] == alc268_beep_mixer) {
6044 has_beep = 1;
6045 break;
6046 }
6047 }
6048
6049 if (has_beep) {
6050 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006051 if (err < 0)
6052 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006053 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
6054 /* override the amp caps for beep generator */
6055 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
6056 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
6057 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
6058 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6059 (0 << AC_AMPCAP_MUTE_SHIFT));
6060 }
6061
Takashi Iwai1d045db2011-07-07 18:23:21 +02006062 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006063 spec->shutup = alc_eapd_shutup;
6064
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006065 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6066
Takashi Iwai1d045db2011-07-07 18:23:21 +02006067 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006068
6069 error:
6070 alc_free(codec);
6071 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006072}
6073
6074/*
6075 * ALC269
6076 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006077static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6078 .substreams = 1,
6079 .channels_min = 2,
6080 .channels_max = 8,
6081 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6082 /* NID is set in alc_build_pcms */
6083 .ops = {
6084 .open = alc_playback_pcm_open,
6085 .prepare = alc_playback_pcm_prepare,
6086 .cleanup = alc_playback_pcm_cleanup
6087 },
6088};
6089
6090static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6091 .substreams = 1,
6092 .channels_min = 2,
6093 .channels_max = 2,
6094 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6095 /* NID is set in alc_build_pcms */
6096};
6097
Takashi Iwai1d045db2011-07-07 18:23:21 +02006098/* different alc269-variants */
6099enum {
6100 ALC269_TYPE_ALC269VA,
6101 ALC269_TYPE_ALC269VB,
6102 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006103 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006104 ALC269_TYPE_ALC280,
6105 ALC269_TYPE_ALC282,
6106 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006107};
6108
6109/*
6110 * BIOS auto configuration
6111 */
6112static int alc269_parse_auto_config(struct hda_codec *codec)
6113{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006114 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006115 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6116 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6117 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006118 const hda_nid_t *ssids;
6119
6120 switch (spec->codec_variant) {
6121 case ALC269_TYPE_ALC269VA:
6122 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006123 case ALC269_TYPE_ALC280:
6124 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006125 ssids = alc269va_ssids;
6126 break;
6127 case ALC269_TYPE_ALC269VB:
6128 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006129 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006130 ssids = alc269_ssids;
6131 break;
6132 default:
6133 ssids = alc269_ssids;
6134 break;
6135 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006136
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006137 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006138}
6139
Kailang Yang1387e2d2012-11-08 10:23:18 +01006140static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006141{
6142 int val = alc_read_coef_idx(codec, 0x04);
6143 if (power_up)
6144 val |= 1 << 11;
6145 else
6146 val &= ~(1 << 11);
6147 alc_write_coef_idx(codec, 0x04, val);
6148}
6149
6150static void alc269_shutup(struct hda_codec *codec)
6151{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006152 struct alc_spec *spec = codec->spec;
6153
6154 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6155 return;
6156
Kailang Yang1387e2d2012-11-08 10:23:18 +01006157 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6158 alc269vb_toggle_power_output(codec, 0);
6159 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6160 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006161 msleep(150);
6162 }
6163}
6164
Takashi Iwai2a439522011-07-26 09:52:50 +02006165#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006166static int alc269_resume(struct hda_codec *codec)
6167{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006168 struct alc_spec *spec = codec->spec;
6169
Kailang Yang1387e2d2012-11-08 10:23:18 +01006170 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6171 alc269vb_toggle_power_output(codec, 0);
6172 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006173 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006174 msleep(150);
6175 }
6176
6177 codec->patch_ops.init(codec);
6178
Kailang Yang1387e2d2012-11-08 10:23:18 +01006179 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6180 alc269vb_toggle_power_output(codec, 1);
6181 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006182 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006183 msleep(200);
6184 }
6185
Takashi Iwai1d045db2011-07-07 18:23:21 +02006186 snd_hda_codec_resume_amp(codec);
6187 snd_hda_codec_resume_cache(codec);
6188 hda_call_check_power_status(codec, 0x01);
6189 return 0;
6190}
Takashi Iwai2a439522011-07-26 09:52:50 +02006191#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006192
David Henningsson108cc102012-07-20 10:37:25 +02006193static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6194 const struct alc_fixup *fix, int action)
6195{
6196 struct alc_spec *spec = codec->spec;
6197
6198 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6199 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6200}
6201
Takashi Iwai1d045db2011-07-07 18:23:21 +02006202static void alc269_fixup_hweq(struct hda_codec *codec,
6203 const struct alc_fixup *fix, int action)
6204{
6205 int coef;
6206
6207 if (action != ALC_FIXUP_ACT_INIT)
6208 return;
6209 coef = alc_read_coef_idx(codec, 0x1e);
6210 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6211}
6212
6213static void alc271_fixup_dmic(struct hda_codec *codec,
6214 const struct alc_fixup *fix, int action)
6215{
6216 static const struct hda_verb verbs[] = {
6217 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6218 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6219 {}
6220 };
6221 unsigned int cfg;
6222
6223 if (strcmp(codec->chip_name, "ALC271X"))
6224 return;
6225 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6226 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6227 snd_hda_sequence_write(codec, verbs);
6228}
6229
Takashi Iwai017f2a12011-07-09 14:42:25 +02006230static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6231 const struct alc_fixup *fix, int action)
6232{
6233 struct alc_spec *spec = codec->spec;
6234
6235 if (action != ALC_FIXUP_ACT_PROBE)
6236 return;
6237
6238 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6239 * fix the sample rate of analog I/O to 44.1kHz
6240 */
6241 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6242 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6243}
6244
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006245static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6246 const struct alc_fixup *fix, int action)
6247{
6248 int coef;
6249
6250 if (action != ALC_FIXUP_ACT_INIT)
6251 return;
6252 /* The digital-mic unit sends PDM (differential signal) instead of
6253 * the standard PCM, thus you can't record a valid mono stream as is.
6254 * Below is a workaround specific to ALC269 to control the dmic
6255 * signal source as mono.
6256 */
6257 coef = alc_read_coef_idx(codec, 0x07);
6258 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6259}
6260
Takashi Iwai24519912011-08-16 15:08:49 +02006261static void alc269_quanta_automute(struct hda_codec *codec)
6262{
David Henningsson42cf0d02011-09-20 12:04:56 +02006263 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006264
6265 snd_hda_codec_write(codec, 0x20, 0,
6266 AC_VERB_SET_COEF_INDEX, 0x0c);
6267 snd_hda_codec_write(codec, 0x20, 0,
6268 AC_VERB_SET_PROC_COEF, 0x680);
6269
6270 snd_hda_codec_write(codec, 0x20, 0,
6271 AC_VERB_SET_COEF_INDEX, 0x0c);
6272 snd_hda_codec_write(codec, 0x20, 0,
6273 AC_VERB_SET_PROC_COEF, 0x480);
6274}
6275
6276static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6277 const struct alc_fixup *fix, int action)
6278{
6279 struct alc_spec *spec = codec->spec;
6280 if (action != ALC_FIXUP_ACT_PROBE)
6281 return;
6282 spec->automute_hook = alc269_quanta_automute;
6283}
6284
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006285/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6286static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6287{
6288 struct hda_codec *codec = private_data;
6289 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6290 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6291 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6292}
6293
6294static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6295 const struct alc_fixup *fix, int action)
6296{
6297 struct alc_spec *spec = codec->spec;
6298 switch (action) {
6299 case ALC_FIXUP_ACT_BUILD:
6300 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6301 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6302 /* fallthru */
6303 case ALC_FIXUP_ACT_INIT:
6304 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6305 break;
6306 }
6307}
6308
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006309/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6310static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6311{
6312 struct hda_codec *codec = private_data;
6313 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006314 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006315}
6316
6317static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6318 const struct alc_fixup *fix, int action)
6319{
6320 struct alc_spec *spec = codec->spec;
6321 switch (action) {
6322 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006323 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006324 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006325 /* fallthru */
6326 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006327 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006328 break;
6329 }
6330}
6331
Dylan Reid08a978d2012-11-18 22:56:40 -08006332static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6333 const struct alc_fixup *fix,
6334 int action)
6335{
6336 struct alc_spec *spec = codec->spec;
6337
6338 if (action == ALC_FIXUP_ACT_PROBE)
6339 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6340 spec->autocfg.hp_pins[0]);
6341}
David Henningsson693b6132012-06-22 19:12:10 +02006342
Takashi Iwai1d045db2011-07-07 18:23:21 +02006343enum {
6344 ALC269_FIXUP_SONY_VAIO,
6345 ALC275_FIXUP_SONY_VAIO_GPIO2,
6346 ALC269_FIXUP_DELL_M101Z,
6347 ALC269_FIXUP_SKU_IGNORE,
6348 ALC269_FIXUP_ASUS_G73JW,
6349 ALC269_FIXUP_LENOVO_EAPD,
6350 ALC275_FIXUP_SONY_HWEQ,
6351 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006352 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006353 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006354 ALC269_FIXUP_QUANTA_MUTE,
6355 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006356 ALC269_FIXUP_AMIC,
6357 ALC269_FIXUP_DMIC,
6358 ALC269VB_FIXUP_AMIC,
6359 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006360 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006361 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006362 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006363 ALC269_FIXUP_LENOVO_DOCK,
6364 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006365 ALC271_FIXUP_AMIC_MIC2,
6366 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006367};
6368
6369static const struct alc_fixup alc269_fixups[] = {
6370 [ALC269_FIXUP_SONY_VAIO] = {
6371 .type = ALC_FIXUP_VERBS,
6372 .v.verbs = (const struct hda_verb[]) {
6373 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6374 {}
6375 }
6376 },
6377 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6378 .type = ALC_FIXUP_VERBS,
6379 .v.verbs = (const struct hda_verb[]) {
6380 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6381 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6382 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6383 { }
6384 },
6385 .chained = true,
6386 .chain_id = ALC269_FIXUP_SONY_VAIO
6387 },
6388 [ALC269_FIXUP_DELL_M101Z] = {
6389 .type = ALC_FIXUP_VERBS,
6390 .v.verbs = (const struct hda_verb[]) {
6391 /* Enables internal speaker */
6392 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6393 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6394 {}
6395 }
6396 },
6397 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006398 .type = ALC_FIXUP_FUNC,
6399 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006400 },
6401 [ALC269_FIXUP_ASUS_G73JW] = {
6402 .type = ALC_FIXUP_PINS,
6403 .v.pins = (const struct alc_pincfg[]) {
6404 { 0x17, 0x99130111 }, /* subwoofer */
6405 { }
6406 }
6407 },
6408 [ALC269_FIXUP_LENOVO_EAPD] = {
6409 .type = ALC_FIXUP_VERBS,
6410 .v.verbs = (const struct hda_verb[]) {
6411 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6412 {}
6413 }
6414 },
6415 [ALC275_FIXUP_SONY_HWEQ] = {
6416 .type = ALC_FIXUP_FUNC,
6417 .v.func = alc269_fixup_hweq,
6418 .chained = true,
6419 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6420 },
6421 [ALC271_FIXUP_DMIC] = {
6422 .type = ALC_FIXUP_FUNC,
6423 .v.func = alc271_fixup_dmic,
6424 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006425 [ALC269_FIXUP_PCM_44K] = {
6426 .type = ALC_FIXUP_FUNC,
6427 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006428 .chained = true,
6429 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006430 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006431 [ALC269_FIXUP_STEREO_DMIC] = {
6432 .type = ALC_FIXUP_FUNC,
6433 .v.func = alc269_fixup_stereo_dmic,
6434 },
Takashi Iwai24519912011-08-16 15:08:49 +02006435 [ALC269_FIXUP_QUANTA_MUTE] = {
6436 .type = ALC_FIXUP_FUNC,
6437 .v.func = alc269_fixup_quanta_mute,
6438 },
6439 [ALC269_FIXUP_LIFEBOOK] = {
6440 .type = ALC_FIXUP_PINS,
6441 .v.pins = (const struct alc_pincfg[]) {
6442 { 0x1a, 0x2101103f }, /* dock line-out */
6443 { 0x1b, 0x23a11040 }, /* dock mic-in */
6444 { }
6445 },
6446 .chained = true,
6447 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6448 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006449 [ALC269_FIXUP_AMIC] = {
6450 .type = ALC_FIXUP_PINS,
6451 .v.pins = (const struct alc_pincfg[]) {
6452 { 0x14, 0x99130110 }, /* speaker */
6453 { 0x15, 0x0121401f }, /* HP out */
6454 { 0x18, 0x01a19c20 }, /* mic */
6455 { 0x19, 0x99a3092f }, /* int-mic */
6456 { }
6457 },
6458 },
6459 [ALC269_FIXUP_DMIC] = {
6460 .type = ALC_FIXUP_PINS,
6461 .v.pins = (const struct alc_pincfg[]) {
6462 { 0x12, 0x99a3092f }, /* int-mic */
6463 { 0x14, 0x99130110 }, /* speaker */
6464 { 0x15, 0x0121401f }, /* HP out */
6465 { 0x18, 0x01a19c20 }, /* mic */
6466 { }
6467 },
6468 },
6469 [ALC269VB_FIXUP_AMIC] = {
6470 .type = ALC_FIXUP_PINS,
6471 .v.pins = (const struct alc_pincfg[]) {
6472 { 0x14, 0x99130110 }, /* speaker */
6473 { 0x18, 0x01a19c20 }, /* mic */
6474 { 0x19, 0x99a3092f }, /* int-mic */
6475 { 0x21, 0x0121401f }, /* HP out */
6476 { }
6477 },
6478 },
David Henningsson2267ea92012-01-03 08:45:56 +01006479 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006480 .type = ALC_FIXUP_PINS,
6481 .v.pins = (const struct alc_pincfg[]) {
6482 { 0x12, 0x99a3092f }, /* int-mic */
6483 { 0x14, 0x99130110 }, /* speaker */
6484 { 0x18, 0x01a19c20 }, /* mic */
6485 { 0x21, 0x0121401f }, /* HP out */
6486 { }
6487 },
6488 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006489 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6490 .type = ALC_FIXUP_FUNC,
6491 .v.func = alc269_fixup_mic1_mute,
6492 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006493 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6494 .type = ALC_FIXUP_FUNC,
6495 .v.func = alc269_fixup_mic2_mute,
6496 },
David Henningsson693b6132012-06-22 19:12:10 +02006497 [ALC269_FIXUP_INV_DMIC] = {
6498 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006499 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006500 },
David Henningsson108cc102012-07-20 10:37:25 +02006501 [ALC269_FIXUP_LENOVO_DOCK] = {
6502 .type = ALC_FIXUP_PINS,
6503 .v.pins = (const struct alc_pincfg[]) {
6504 { 0x19, 0x23a11040 }, /* dock mic */
6505 { 0x1b, 0x2121103f }, /* dock headphone */
6506 { }
6507 },
6508 .chained = true,
6509 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6510 },
6511 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6512 .type = ALC_FIXUP_FUNC,
6513 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6514 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006515 [ALC271_FIXUP_AMIC_MIC2] = {
6516 .type = ALC_FIXUP_PINS,
6517 .v.pins = (const struct alc_pincfg[]) {
6518 { 0x14, 0x99130110 }, /* speaker */
6519 { 0x19, 0x01a19c20 }, /* mic */
6520 { 0x1b, 0x99a7012f }, /* int-mic */
6521 { 0x21, 0x0121401f }, /* HP out */
6522 { }
6523 },
6524 },
6525 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6526 .type = ALC_FIXUP_FUNC,
6527 .v.func = alc271_hp_gate_mic_jack,
6528 .chained = true,
6529 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6530 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006531};
6532
6533static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006534 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6535 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006536 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006537 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006538 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006539 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006540 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006541 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006542 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6543 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6544 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6545 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6546 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006547 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6548 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6549 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6550 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6551 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006552 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006553 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006554 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006555 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6556 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6557 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6558 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6559 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006560 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006561 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006562 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006563 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006564 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006565 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006566 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006567
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006568#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006569 /* Below is a quirk table taken from the old code.
6570 * Basically the device should work as is without the fixup table.
6571 * If BIOS doesn't give a proper info, enable the corresponding
6572 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006573 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006574 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6575 ALC269_FIXUP_AMIC),
6576 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006577 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6578 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6579 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6580 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6581 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6582 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6583 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6584 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6585 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6586 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6587 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6588 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6589 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6590 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6591 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6592 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6593 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6594 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6595 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6596 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6597 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6598 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6599 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6600 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6601 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6602 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6603 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6604 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6605 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6606 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6607 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6608 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6609 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6610 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6611 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6612 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6613 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6614 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6615#endif
6616 {}
6617};
6618
6619static const struct alc_model_fixup alc269_fixup_models[] = {
6620 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6621 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006622 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6623 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6624 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006625 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006626 {}
6627};
6628
6629
Takashi Iwai546bb672012-03-07 08:37:19 +01006630static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006631{
Kailang Yang526af6e2012-03-07 08:25:20 +01006632 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006633 int val;
6634
Kailang Yang526af6e2012-03-07 08:25:20 +01006635 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006636 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006637
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006638 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006639 alc_write_coef_idx(codec, 0xf, 0x960b);
6640 alc_write_coef_idx(codec, 0xe, 0x8817);
6641 }
6642
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006643 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006644 alc_write_coef_idx(codec, 0xf, 0x960b);
6645 alc_write_coef_idx(codec, 0xe, 0x8814);
6646 }
6647
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006648 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006649 val = alc_read_coef_idx(codec, 0x04);
6650 /* Power up output pin */
6651 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6652 }
6653
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006654 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006655 val = alc_read_coef_idx(codec, 0xd);
6656 if ((val & 0x0c00) >> 10 != 0x1) {
6657 /* Capless ramp up clock control */
6658 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6659 }
6660 val = alc_read_coef_idx(codec, 0x17);
6661 if ((val & 0x01c0) >> 6 != 0x4) {
6662 /* Class D power on reset */
6663 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6664 }
6665 }
6666
6667 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6668 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6669
6670 val = alc_read_coef_idx(codec, 0x4); /* HP */
6671 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006672}
6673
6674/*
6675 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006676static int patch_alc269(struct hda_codec *codec)
6677{
6678 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006679 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006680
Takashi Iwai3de95172012-05-07 18:03:15 +02006681 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006682 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006683 return err;
6684
6685 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006686
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006687 alc_pick_fixup(codec, alc269_fixup_models,
6688 alc269_fixup_tbl, alc269_fixups);
6689 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6690
6691 alc_auto_parse_customize_define(codec);
6692
Kailang Yang065380f2013-01-10 10:25:48 +01006693 switch (codec->vendor_id) {
6694 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006695 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006696 switch (alc_get_coef0(codec) & 0x00f0) {
6697 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006698 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006699 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006700 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006701 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006702 break;
6703 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006704 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6705 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006706 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006707 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006708 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006709 case 0x0030:
6710 spec->codec_variant = ALC269_TYPE_ALC269VD;
6711 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006712 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006713 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006714 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006715 if (err < 0)
6716 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006717 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006718 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006719 break;
6720
6721 case 0x10ec0280:
6722 case 0x10ec0290:
6723 spec->codec_variant = ALC269_TYPE_ALC280;
6724 break;
6725 case 0x10ec0282:
6726 case 0x10ec0283:
6727 spec->codec_variant = ALC269_TYPE_ALC282;
6728 break;
6729 case 0x10ec0284:
6730 case 0x10ec0292:
6731 spec->codec_variant = ALC269_TYPE_ALC284;
6732 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006733 }
6734
Takashi Iwaia4297b52011-08-23 18:40:12 +02006735 /* automatic parse from the BIOS config */
6736 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006737 if (err < 0)
6738 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006739
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006740 if (!spec->no_analog && has_cdefine_beep(codec)) {
6741 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006742 if (err < 0)
6743 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006744 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006745 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006746
Takashi Iwai1d045db2011-07-07 18:23:21 +02006747 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006748#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006749 codec->patch_ops.resume = alc269_resume;
6750#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006751 spec->shutup = alc269_shutup;
6752
Takashi Iwai589876e2012-02-20 15:47:55 +01006753 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6754
Takashi Iwai1d045db2011-07-07 18:23:21 +02006755 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006756
6757 error:
6758 alc_free(codec);
6759 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006760}
6761
6762/*
6763 * ALC861
6764 */
6765
Takashi Iwai1d045db2011-07-07 18:23:21 +02006766static int alc861_parse_auto_config(struct hda_codec *codec)
6767{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006768 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006769 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6770 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006771}
6772
Takashi Iwai1d045db2011-07-07 18:23:21 +02006773/* Pin config fixes */
6774enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006775 ALC861_FIXUP_FSC_AMILO_PI1505,
6776 ALC861_FIXUP_AMP_VREF_0F,
6777 ALC861_FIXUP_NO_JACK_DETECT,
6778 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006779};
6780
Takashi Iwai31150f22012-01-30 10:54:08 +01006781/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6782static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6783 const struct alc_fixup *fix, int action)
6784{
6785 struct alc_spec *spec = codec->spec;
6786 unsigned int val;
6787
6788 if (action != ALC_FIXUP_ACT_INIT)
6789 return;
6790 val = snd_hda_codec_read(codec, 0x0f, 0,
6791 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6792 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6793 val |= AC_PINCTL_IN_EN;
6794 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006795 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006796 spec->keep_vref_in_automute = 1;
6797}
6798
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006799/* suppress the jack-detection */
6800static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6801 const struct alc_fixup *fix, int action)
6802{
6803 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6804 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006805}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006806
Takashi Iwai1d045db2011-07-07 18:23:21 +02006807static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006808 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006809 .type = ALC_FIXUP_PINS,
6810 .v.pins = (const struct alc_pincfg[]) {
6811 { 0x0b, 0x0221101f }, /* HP */
6812 { 0x0f, 0x90170310 }, /* speaker */
6813 { }
6814 }
6815 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006816 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006817 .type = ALC_FIXUP_FUNC,
6818 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006819 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006820 [ALC861_FIXUP_NO_JACK_DETECT] = {
6821 .type = ALC_FIXUP_FUNC,
6822 .v.func = alc_fixup_no_jack_detect,
6823 },
6824 [ALC861_FIXUP_ASUS_A6RP] = {
6825 .type = ALC_FIXUP_FUNC,
6826 .v.func = alc861_fixup_asus_amp_vref_0f,
6827 .chained = true,
6828 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6829 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006830};
6831
6832static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006833 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6834 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6835 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6836 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6837 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6838 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006839 {}
6840};
6841
6842/*
6843 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006844static int patch_alc861(struct hda_codec *codec)
6845{
6846 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006847 int err;
6848
Takashi Iwai3de95172012-05-07 18:03:15 +02006849 err = alc_alloc_spec(codec, 0x15);
6850 if (err < 0)
6851 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006852
Takashi Iwai3de95172012-05-07 18:03:15 +02006853 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006854
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006855 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6856 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006857
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006858 /* automatic parse from the BIOS config */
6859 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006860 if (err < 0)
6861 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006862
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006863 if (!spec->no_analog) {
6864 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006865 if (err < 0)
6866 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006867 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6868 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006869
Takashi Iwai1d045db2011-07-07 18:23:21 +02006870 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006871#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006872 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006873#endif
6874
Takashi Iwai589876e2012-02-20 15:47:55 +01006875 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6876
Takashi Iwai1d045db2011-07-07 18:23:21 +02006877 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006878
6879 error:
6880 alc_free(codec);
6881 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006882}
6883
6884/*
6885 * ALC861-VD support
6886 *
6887 * Based on ALC882
6888 *
6889 * In addition, an independent DAC
6890 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006891static int alc861vd_parse_auto_config(struct hda_codec *codec)
6892{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006893 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006894 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6895 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006896}
6897
Takashi Iwai1d045db2011-07-07 18:23:21 +02006898enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006899 ALC660VD_FIX_ASUS_GPIO1,
6900 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006901};
6902
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006903/* exclude VREF80 */
6904static void alc861vd_fixup_dallas(struct hda_codec *codec,
6905 const struct alc_fixup *fix, int action)
6906{
6907 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006908 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6909 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006910 }
6911}
6912
Takashi Iwai1d045db2011-07-07 18:23:21 +02006913static const struct alc_fixup alc861vd_fixups[] = {
6914 [ALC660VD_FIX_ASUS_GPIO1] = {
6915 .type = ALC_FIXUP_VERBS,
6916 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006917 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006918 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6919 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6920 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6921 { }
6922 }
6923 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006924 [ALC861VD_FIX_DALLAS] = {
6925 .type = ALC_FIXUP_FUNC,
6926 .v.func = alc861vd_fixup_dallas,
6927 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006928};
6929
6930static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006931 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006932 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006933 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006934 {}
6935};
6936
Takashi Iwai1d045db2011-07-07 18:23:21 +02006937/*
6938 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006939static int patch_alc861vd(struct hda_codec *codec)
6940{
6941 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006942 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006943
Takashi Iwai3de95172012-05-07 18:03:15 +02006944 err = alc_alloc_spec(codec, 0x0b);
6945 if (err < 0)
6946 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006947
Takashi Iwai3de95172012-05-07 18:03:15 +02006948 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006949
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006950 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6951 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006952
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006953 /* automatic parse from the BIOS config */
6954 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006955 if (err < 0)
6956 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006957
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006958 if (!spec->no_analog) {
6959 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006960 if (err < 0)
6961 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006962 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6963 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006964
Takashi Iwai1d045db2011-07-07 18:23:21 +02006965 codec->patch_ops = alc_patch_ops;
6966
Takashi Iwai1d045db2011-07-07 18:23:21 +02006967 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006968
Takashi Iwai589876e2012-02-20 15:47:55 +01006969 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6970
Takashi Iwai1d045db2011-07-07 18:23:21 +02006971 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006972
6973 error:
6974 alc_free(codec);
6975 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006976}
6977
6978/*
6979 * ALC662 support
6980 *
6981 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6982 * configuration. Each pin widget can choose any input DACs and a mixer.
6983 * Each ADC is connected from a mixer of all inputs. This makes possible
6984 * 6-channel independent captures.
6985 *
6986 * In addition, an independent DAC for the multi-playback (not used in this
6987 * driver yet).
6988 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006989
6990/*
6991 * BIOS auto configuration
6992 */
6993
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006994static int alc662_parse_auto_config(struct hda_codec *codec)
6995{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006996 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006997 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6998 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6999 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02007000
Kailang Yang6227cdc2010-02-25 08:36:52 +01007001 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
7002 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007003 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01007004 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007005 ssids = alc662_ssids;
7006 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007007}
7008
Todd Broch6be79482010-12-07 16:51:05 -08007009static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007010 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01007011{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007012 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01007013 return;
Todd Broch6be79482010-12-07 16:51:05 -08007014 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
7015 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
7016 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
7017 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
7018 (0 << AC_AMPCAP_MUTE_SHIFT)))
7019 printk(KERN_WARNING
7020 "hda_codec: failed to override amp caps for NID 0x2\n");
7021}
7022
David Henningsson6cb3b702010-09-09 08:51:44 +02007023enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04007024 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02007025 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08007026 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007027 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02007028 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007029 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02007030 ALC662_FIXUP_ASUS_MODE1,
7031 ALC662_FIXUP_ASUS_MODE2,
7032 ALC662_FIXUP_ASUS_MODE3,
7033 ALC662_FIXUP_ASUS_MODE4,
7034 ALC662_FIXUP_ASUS_MODE5,
7035 ALC662_FIXUP_ASUS_MODE6,
7036 ALC662_FIXUP_ASUS_MODE7,
7037 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01007038 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02007039 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02007040 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02007041};
7042
7043static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04007044 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007045 .type = ALC_FIXUP_PINS,
7046 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04007047 { 0x15, 0x99130112 }, /* subwoofer */
7048 { }
7049 }
7050 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007051 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007052 .type = ALC_FIXUP_PINS,
7053 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02007054 { 0x17, 0x99130112 }, /* subwoofer */
7055 { }
7056 }
7057 },
Todd Broch6be79482010-12-07 16:51:05 -08007058 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007059 .type = ALC_FIXUP_FUNC,
7060 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007061 },
7062 [ALC662_FIXUP_CZC_P10T] = {
7063 .type = ALC_FIXUP_VERBS,
7064 .v.verbs = (const struct hda_verb[]) {
7065 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7066 {}
7067 }
7068 },
David Henningsson94024cd2011-04-29 14:10:55 +02007069 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02007070 .type = ALC_FIXUP_FUNC,
7071 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02007072 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007073 [ALC662_FIXUP_HP_RP5800] = {
7074 .type = ALC_FIXUP_PINS,
7075 .v.pins = (const struct alc_pincfg[]) {
7076 { 0x14, 0x0221201f }, /* HP out */
7077 { }
7078 },
7079 .chained = true,
7080 .chain_id = ALC662_FIXUP_SKU_IGNORE
7081 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007082 [ALC662_FIXUP_ASUS_MODE1] = {
7083 .type = ALC_FIXUP_PINS,
7084 .v.pins = (const struct alc_pincfg[]) {
7085 { 0x14, 0x99130110 }, /* speaker */
7086 { 0x18, 0x01a19c20 }, /* mic */
7087 { 0x19, 0x99a3092f }, /* int-mic */
7088 { 0x21, 0x0121401f }, /* HP out */
7089 { }
7090 },
7091 .chained = true,
7092 .chain_id = ALC662_FIXUP_SKU_IGNORE
7093 },
7094 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007095 .type = ALC_FIXUP_PINS,
7096 .v.pins = (const struct alc_pincfg[]) {
7097 { 0x14, 0x99130110 }, /* speaker */
7098 { 0x18, 0x01a19820 }, /* mic */
7099 { 0x19, 0x99a3092f }, /* int-mic */
7100 { 0x1b, 0x0121401f }, /* HP out */
7101 { }
7102 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007103 .chained = true,
7104 .chain_id = ALC662_FIXUP_SKU_IGNORE
7105 },
7106 [ALC662_FIXUP_ASUS_MODE3] = {
7107 .type = ALC_FIXUP_PINS,
7108 .v.pins = (const struct alc_pincfg[]) {
7109 { 0x14, 0x99130110 }, /* speaker */
7110 { 0x15, 0x0121441f }, /* HP */
7111 { 0x18, 0x01a19840 }, /* mic */
7112 { 0x19, 0x99a3094f }, /* int-mic */
7113 { 0x21, 0x01211420 }, /* HP2 */
7114 { }
7115 },
7116 .chained = true,
7117 .chain_id = ALC662_FIXUP_SKU_IGNORE
7118 },
7119 [ALC662_FIXUP_ASUS_MODE4] = {
7120 .type = ALC_FIXUP_PINS,
7121 .v.pins = (const struct alc_pincfg[]) {
7122 { 0x14, 0x99130110 }, /* speaker */
7123 { 0x16, 0x99130111 }, /* speaker */
7124 { 0x18, 0x01a19840 }, /* mic */
7125 { 0x19, 0x99a3094f }, /* int-mic */
7126 { 0x21, 0x0121441f }, /* HP */
7127 { }
7128 },
7129 .chained = true,
7130 .chain_id = ALC662_FIXUP_SKU_IGNORE
7131 },
7132 [ALC662_FIXUP_ASUS_MODE5] = {
7133 .type = ALC_FIXUP_PINS,
7134 .v.pins = (const struct alc_pincfg[]) {
7135 { 0x14, 0x99130110 }, /* speaker */
7136 { 0x15, 0x0121441f }, /* HP */
7137 { 0x16, 0x99130111 }, /* speaker */
7138 { 0x18, 0x01a19840 }, /* mic */
7139 { 0x19, 0x99a3094f }, /* int-mic */
7140 { }
7141 },
7142 .chained = true,
7143 .chain_id = ALC662_FIXUP_SKU_IGNORE
7144 },
7145 [ALC662_FIXUP_ASUS_MODE6] = {
7146 .type = ALC_FIXUP_PINS,
7147 .v.pins = (const struct alc_pincfg[]) {
7148 { 0x14, 0x99130110 }, /* speaker */
7149 { 0x15, 0x01211420 }, /* HP2 */
7150 { 0x18, 0x01a19840 }, /* mic */
7151 { 0x19, 0x99a3094f }, /* int-mic */
7152 { 0x1b, 0x0121441f }, /* HP */
7153 { }
7154 },
7155 .chained = true,
7156 .chain_id = ALC662_FIXUP_SKU_IGNORE
7157 },
7158 [ALC662_FIXUP_ASUS_MODE7] = {
7159 .type = ALC_FIXUP_PINS,
7160 .v.pins = (const struct alc_pincfg[]) {
7161 { 0x14, 0x99130110 }, /* speaker */
7162 { 0x17, 0x99130111 }, /* speaker */
7163 { 0x18, 0x01a19840 }, /* mic */
7164 { 0x19, 0x99a3094f }, /* int-mic */
7165 { 0x1b, 0x01214020 }, /* HP */
7166 { 0x21, 0x0121401f }, /* HP */
7167 { }
7168 },
7169 .chained = true,
7170 .chain_id = ALC662_FIXUP_SKU_IGNORE
7171 },
7172 [ALC662_FIXUP_ASUS_MODE8] = {
7173 .type = ALC_FIXUP_PINS,
7174 .v.pins = (const struct alc_pincfg[]) {
7175 { 0x14, 0x99130110 }, /* speaker */
7176 { 0x12, 0x99a30970 }, /* int-mic */
7177 { 0x15, 0x01214020 }, /* HP */
7178 { 0x17, 0x99130111 }, /* speaker */
7179 { 0x18, 0x01a19840 }, /* mic */
7180 { 0x21, 0x0121401f }, /* HP */
7181 { }
7182 },
7183 .chained = true,
7184 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007185 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007186 [ALC662_FIXUP_NO_JACK_DETECT] = {
7187 .type = ALC_FIXUP_FUNC,
7188 .v.func = alc_fixup_no_jack_detect,
7189 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007190 [ALC662_FIXUP_ZOTAC_Z68] = {
7191 .type = ALC_FIXUP_PINS,
7192 .v.pins = (const struct alc_pincfg[]) {
7193 { 0x1b, 0x02214020 }, /* Front HP */
7194 { }
7195 }
7196 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007197 [ALC662_FIXUP_INV_DMIC] = {
7198 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007199 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007200 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007201};
7202
Takashi Iwaia9111322011-05-02 11:30:18 +02007203static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007204 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007205 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007206 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007207 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007208 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007209 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007210 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007211 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007212 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007213 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007214 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007215 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007216 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007217
7218#if 0
7219 /* Below is a quirk table taken from the old code.
7220 * Basically the device should work as is without the fixup table.
7221 * If BIOS doesn't give a proper info, enable the corresponding
7222 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007223 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007224 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7225 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7226 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7227 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7228 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7229 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7230 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7231 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7232 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7233 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7234 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7235 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7236 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7237 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7238 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7239 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7240 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7241 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7242 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7243 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7244 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7245 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7246 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7247 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7248 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7249 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7250 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7251 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7252 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7253 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7254 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7255 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7256 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7257 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7258 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7259 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7260 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7261 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7262 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7263 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7264 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7265 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7266 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7267 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7268 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7269 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7270 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7271 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7272 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7273 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7274#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007275 {}
7276};
7277
Todd Broch6be79482010-12-07 16:51:05 -08007278static const struct alc_model_fixup alc662_fixup_models[] = {
7279 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007280 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7281 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7282 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7283 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7284 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7285 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7286 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7287 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007288 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007289 {}
7290};
David Henningsson6cb3b702010-09-09 08:51:44 +02007291
Kailang Yang8663ff72012-06-29 09:35:52 +02007292static void alc662_fill_coef(struct hda_codec *codec)
7293{
7294 int val, coef;
7295
7296 coef = alc_get_coef0(codec);
7297
7298 switch (codec->vendor_id) {
7299 case 0x10ec0662:
7300 if ((coef & 0x00f0) == 0x0030) {
7301 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7302 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7303 }
7304 break;
7305 case 0x10ec0272:
7306 case 0x10ec0273:
7307 case 0x10ec0663:
7308 case 0x10ec0665:
7309 case 0x10ec0670:
7310 case 0x10ec0671:
7311 case 0x10ec0672:
7312 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7313 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7314 break;
7315 }
7316}
David Henningsson6cb3b702010-09-09 08:51:44 +02007317
Takashi Iwai1d045db2011-07-07 18:23:21 +02007318/*
7319 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007320static int patch_alc662(struct hda_codec *codec)
7321{
7322 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007323 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007324
Takashi Iwai3de95172012-05-07 18:03:15 +02007325 err = alc_alloc_spec(codec, 0x0b);
7326 if (err < 0)
7327 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007328
Takashi Iwai3de95172012-05-07 18:03:15 +02007329 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007330
Takashi Iwai53c334a2011-08-23 18:27:14 +02007331 /* handle multiple HPs as is */
7332 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7333
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007334 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7335
Kailang Yang8663ff72012-06-29 09:35:52 +02007336 spec->init_hook = alc662_fill_coef;
7337 alc662_fill_coef(codec);
7338
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007339 alc_pick_fixup(codec, alc662_fixup_models,
7340 alc662_fixup_tbl, alc662_fixups);
7341 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7342
7343 alc_auto_parse_customize_define(codec);
7344
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007345 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007346 codec->bus->pci->subsystem_vendor == 0x1025 &&
7347 spec->cdefine.platform_type == 1) {
7348 if (alc_codec_rename(codec, "ALC272X") < 0)
7349 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007350 }
Kailang Yang274693f2009-12-03 10:07:50 +01007351
Takashi Iwaib9c51062011-08-24 18:08:07 +02007352 /* automatic parse from the BIOS config */
7353 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007354 if (err < 0)
7355 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007356
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007357 if (!spec->no_analog && has_cdefine_beep(codec)) {
7358 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007359 if (err < 0)
7360 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007361 switch (codec->vendor_id) {
7362 case 0x10ec0662:
7363 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7364 break;
7365 case 0x10ec0272:
7366 case 0x10ec0663:
7367 case 0x10ec0665:
7368 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7369 break;
7370 case 0x10ec0273:
7371 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7372 break;
7373 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007374 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007375
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007376 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007377 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007378
Takashi Iwai589876e2012-02-20 15:47:55 +01007379 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7380
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007381 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007382
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007383 error:
7384 alc_free(codec);
7385 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007386}
7387
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007388/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007389 * ALC680 support
7390 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007391
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007392static int alc680_parse_auto_config(struct hda_codec *codec)
7393{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007394 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007395}
7396
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007397/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007398 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007399static int patch_alc680(struct hda_codec *codec)
7400{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007401 int err;
7402
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007403 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007404 err = alc_alloc_spec(codec, 0);
7405 if (err < 0)
7406 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007407
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007408 /* automatic parse from the BIOS config */
7409 err = alc680_parse_auto_config(codec);
7410 if (err < 0) {
7411 alc_free(codec);
7412 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007413 }
7414
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007415 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007416
7417 return 0;
7418}
7419
7420/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007421 * patch entries
7422 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007423static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007424 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007425 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007426 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007427 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007428 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007429 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007430 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007431 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007432 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007433 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007434 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007435 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007436 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007437 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007438 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007439 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007440 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007441 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007442 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7443 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7444 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007445 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007446 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007447 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7448 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007449 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7450 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007451 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007452 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007453 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007454 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007455 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007456 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007457 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007458 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007459 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007460 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007461 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007462 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007463 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007464 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007465 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007466 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007467 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007468 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007469 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007470 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007471 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007472 {} /* terminator */
7473};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007474
7475MODULE_ALIAS("snd-hda-codec-id:10ec*");
7476
7477MODULE_LICENSE("GPL");
7478MODULE_DESCRIPTION("Realtek HD-audio codec");
7479
7480static struct hda_codec_preset_list realtek_list = {
7481 .preset = snd_hda_preset_realtek,
7482 .owner = THIS_MODULE,
7483};
7484
7485static int __init patch_realtek_init(void)
7486{
7487 return snd_hda_add_codec_preset(&realtek_list);
7488}
7489
7490static void __exit patch_realtek_exit(void)
7491{
7492 snd_hda_delete_codec_preset(&realtek_list);
7493}
7494
7495module_init(patch_realtek_init)
7496module_exit(patch_realtek_exit)