blob: 76c67407996c4457b0b19408a1ba5028b2f85ada [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 Iwaic9967f12012-12-14 16:39:22 +0100195 /* path list */
196 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100197
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100198 /* hooks */
199 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200200#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500201 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100202#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200203 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200204 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100205
Takashi Iwai834be882006-03-01 14:16:17 +0100206 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200207 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200208 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200209 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200210 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200211 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200212 unsigned int automute_speaker:1; /* automute speaker outputs */
213 unsigned int automute_lo:1; /* automute LO outputs */
214 unsigned int detect_hp:1; /* Headphone detection enabled */
215 unsigned int detect_lo:1; /* Line-out detection enabled */
216 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
217 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100218 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200219
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100220 /* other flags */
221 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200222 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100223 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200224 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200225 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100226 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200227 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
228 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200229 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200230
231 /* auto-mute control */
232 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200233 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200234
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200235 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200236 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100237
Takashi Iwai2134ea42008-01-10 16:53:55 +0100238 /* for virtual master */
239 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100240 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200241#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200242 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100243 int num_loopbacks;
244 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200245#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200246
247 /* for PLL fix */
248 hda_nid_t pll_nid;
249 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200250 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100251
Takashi Iwaice764ab2011-04-27 16:35:23 +0200252 /* multi-io */
253 int multi_ios;
254 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200255
256 /* bind volumes */
257 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100258};
259
Takashi Iwai44c02402011-07-08 15:14:19 +0200260static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
261 int dir, unsigned int bits)
262{
263 if (!nid)
264 return false;
265 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
266 if (query_amp_caps(codec, nid, dir) & bits)
267 return true;
268 return false;
269}
270
271#define nid_has_mute(codec, nid, dir) \
272 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
273#define nid_has_volume(codec, nid, dir) \
274 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276/*
277 * input MUX handling
278 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200279static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
282 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
283 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200284 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
285 if (mux_idx >= spec->num_mux_defs)
286 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100287 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
288 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200289 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200292static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
296 struct alc_spec *spec = codec->spec;
297 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
298
299 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
300 return 0;
301}
302
Takashi Iwai21268962011-07-07 15:01:13 +0200303static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Takashi Iwai21268962011-07-07 15:01:13 +0200305 struct alc_spec *spec = codec->spec;
306 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
307
308 if (spec->cur_adc && spec->cur_adc != new_adc) {
309 /* stream is running, let's swap the current ADC */
310 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
311 spec->cur_adc = new_adc;
312 snd_hda_codec_setup_stream(codec, new_adc,
313 spec->cur_adc_stream_tag, 0,
314 spec->cur_adc_format);
315 return true;
316 }
317 return false;
318}
319
Takashi Iwai61071592011-11-23 07:52:15 +0100320static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
321{
322 return spec->capsrc_nids ?
323 spec->capsrc_nids[idx] : spec->adc_nids[idx];
324}
325
Takashi Iwai24de1832011-11-07 17:13:39 +0100326static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200327static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100328
David Henningsson00227f12012-06-27 18:45:44 +0200329/* for shared I/O, change the pin-control accordingly */
330static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
331{
332 struct alc_spec *spec = codec->spec;
333 unsigned int val;
334 hda_nid_t pin = spec->autocfg.inputs[1].pin;
335 /* NOTE: this assumes that there are only two inputs, the
336 * first is the real internal mic and the second is HP/mic jack.
337 */
338
339 val = snd_hda_get_default_vref(codec, pin);
340
341 /* This pin does not have vref caps - let's enable vref on pin 0x18
342 instead, as suggested by Realtek */
343 if (val == AC_PINCTL_VREF_HIZ) {
344 const hda_nid_t vref_pin = 0x18;
345 /* Sanity check pin 0x18 */
346 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
347 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
348 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
349 if (vref_val != AC_PINCTL_VREF_HIZ)
350 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
351 }
352 }
353
354 val = set_as_mic ? val | PIN_IN : PIN_HP;
355 snd_hda_set_pin_ctl(codec, pin, val);
356
357 spec->automute_speaker = !set_as_mic;
358 call_update_outputs(codec);
359}
Takashi Iwai21268962011-07-07 15:01:13 +0200360
361/* select the given imux item; either unmute exclusively or select the route */
362static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
363 unsigned int idx, bool force)
364{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100366 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100367 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100368 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200369 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Takashi Iwai5803a322012-02-21 11:59:45 +0100371 if (!spec->input_mux)
372 return 0;
373
Takashi Iwaicd896c32008-11-18 12:36:33 +0100374 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
375 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100376 if (!imux->num_items && mux_idx > 0)
377 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100378 if (!imux->num_items)
379 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100380
Takashi Iwai21268962011-07-07 15:01:13 +0200381 if (idx >= imux->num_items)
382 idx = imux->num_items - 1;
383 if (spec->cur_mux[adc_idx] == idx && !force)
384 return 0;
385 spec->cur_mux[adc_idx] = idx;
386
David Henningsson00227f12012-06-27 18:45:44 +0200387 if (spec->shared_mic_hp)
388 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100389
Takashi Iwai21268962011-07-07 15:01:13 +0200390 if (spec->dyn_adc_switch) {
391 alc_dyn_adc_pcm_resetup(codec, idx);
392 adc_idx = spec->dyn_adc_idx[idx];
393 }
394
Takashi Iwai61071592011-11-23 07:52:15 +0100395 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200396
397 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200398 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100399 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200400 return 1;
401
Takashi Iwaia22d5432009-07-27 12:54:26 +0200402 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200403 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100404 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100405 int active = imux->items[idx].index;
406 for (i = 0; i < num_conns; i++) {
407 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
408 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100409 HDA_AMP_MUTE, v);
410 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100411 } else {
412 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200413 snd_hda_codec_write_cache(codec, nid, 0,
414 AC_VERB_SET_CONNECT_SEL,
415 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100416 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200417 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200418 return 1;
419}
420
421static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
422 struct snd_ctl_elem_value *ucontrol)
423{
424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
425 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
426 return alc_mux_select(codec, adc_idx,
427 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100428}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100431 * set up the input pin config (depending on the given auto-pin type)
432 */
433static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
434 int auto_pin_type)
435{
436 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200437 if (auto_pin_type == AUTO_PIN_MIC)
438 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200439 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100440}
441
442/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200443 * Append the given mixer and verb elements for the later use
444 * The mixer array is referred in build_controls(), and init_verbs are
445 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100446 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200447static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100448{
449 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
450 return;
451 spec->mixers[spec->num_mixers++] = mix;
452}
453
Takashi Iwaid88897e2008-10-31 15:01:37 +0100454/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200455 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100456 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200457/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200458static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200459 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
460 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
461 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
462 { }
463};
464
Takashi Iwaia9111322011-05-02 11:30:18 +0200465static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200466 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
467 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
468 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
469 { }
470};
471
Takashi Iwaia9111322011-05-02 11:30:18 +0200472static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200473 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
474 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
475 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
476 { }
477};
478
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200479/*
480 * Fix hardware PLL issue
481 * On some codecs, the analog PLL gating control must be off while
482 * the default value is 1.
483 */
484static void alc_fix_pll(struct hda_codec *codec)
485{
486 struct alc_spec *spec = codec->spec;
487 unsigned int val;
488
489 if (!spec->pll_nid)
490 return;
491 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
492 spec->pll_coef_idx);
493 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
494 AC_VERB_GET_PROC_COEF, 0);
495 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
496 spec->pll_coef_idx);
497 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
498 val & ~(1 << spec->pll_coef_bit));
499}
500
501static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
502 unsigned int coef_idx, unsigned int coef_bit)
503{
504 struct alc_spec *spec = codec->spec;
505 spec->pll_nid = nid;
506 spec->pll_coef_idx = coef_idx;
507 spec->pll_coef_bit = coef_bit;
508 alc_fix_pll(codec);
509}
510
Takashi Iwai1d045db2011-07-07 18:23:21 +0200511/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200512 * Jack detections for HP auto-mute and mic-switch
513 */
514
515/* check each pin in the given array; returns true if any of them is plugged */
516static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200517{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200518 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200519
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200520 for (i = 0; i < num_pins; i++) {
521 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200522 if (!nid)
523 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200524 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200525 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526 return present;
527}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200528
Takashi Iwai1d045db2011-07-07 18:23:21 +0200529/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200530static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200531 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532{
533 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200534 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200535 int i;
536
537 for (i = 0; i < num_pins; i++) {
538 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100539 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200540 if (!nid)
541 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100542 /* don't reset VREF value in case it's controlling
543 * the amp (see alc861_fixup_asus_amp_vref_0f())
544 */
545 if (spec->keep_vref_in_automute) {
546 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100547 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100548 val &= ~PIN_HP;
549 } else
550 val = 0;
551 val |= pin_bits;
552 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200553 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200554}
555
David Henningsson42cf0d02011-09-20 12:04:56 +0200556/* Toggle outputs muting */
557static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558{
559 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561
Takashi Iwaic0a20262011-06-10 15:28:15 +0200562 /* Control HP pins/amps depending on master_mute state;
563 * in general, HP pins/amps control should be enabled in all cases,
564 * but currently set only for master_mute, just to be safe
565 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100566 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
567 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200568 spec->autocfg.hp_pins, spec->master_mute, true);
569
David Henningsson42cf0d02011-09-20 12:04:56 +0200570 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200571 on = 0;
572 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200573 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200574 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200575 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200576 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577
578 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200579 /* if LO is a copy of either HP or Speaker, don't need to handle it */
580 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
581 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200583 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200584 on = 0;
585 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200586 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200587 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200589 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590}
591
David Henningsson42cf0d02011-09-20 12:04:56 +0200592static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200593{
594 struct alc_spec *spec = codec->spec;
595 if (spec->automute_hook)
596 spec->automute_hook(codec);
597 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200598 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200599}
600
Takashi Iwai1d045db2011-07-07 18:23:21 +0200601/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200602static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200603{
604 struct alc_spec *spec = codec->spec;
605
David Henningsson42cf0d02011-09-20 12:04:56 +0200606 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
608 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200609 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200610 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200611 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200612}
613
Takashi Iwai1d045db2011-07-07 18:23:21 +0200614/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200615static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200616{
617 struct alc_spec *spec = codec->spec;
618
David Henningssonf7f4b2322012-10-10 16:32:09 +0200619 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
620 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200621 /* check LO jack only when it's different from HP */
622 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
623 return;
624
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200625 spec->line_jack_present =
626 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
627 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200628 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200629 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200630 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200631}
632
Takashi Iwai8d087c72011-06-28 12:45:47 +0200633#define get_connection_index(codec, mux, nid) \
634 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200635
Takashi Iwai1d045db2011-07-07 18:23:21 +0200636/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200637static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200638{
639 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200640 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200641
Takashi Iwai21268962011-07-07 15:01:13 +0200642 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200643 return;
644 if (snd_BUG_ON(!spec->adc_nids))
645 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200646 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200647 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200648
Takashi Iwai21268962011-07-07 15:01:13 +0200649 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
650 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
651 else if (spec->dock_mic_idx >= 0 &&
652 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
653 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
654 else
655 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200656}
657
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100658/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200659static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100660{
661 unsigned int val;
662 struct snd_kcontrol *kctl;
663 struct snd_ctl_elem_value *uctl;
664
665 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
666 if (!kctl)
667 return;
668 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
669 if (!uctl)
670 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200671 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100672 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
673 val &= HDA_AMP_VOLMASK;
674 uctl->value.integer.value[0] = val;
675 uctl->value.integer.value[1] = val;
676 kctl->put(kctl, uctl);
677 kfree(uctl);
678}
679
David Henningsson29adc4b2012-09-25 11:31:00 +0200680static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100681{
David Henningsson29adc4b2012-09-25 11:31:00 +0200682 /* For some reason, the res given from ALC880 is broken.
683 Here we adjust it properly. */
684 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100685}
686
Takashi Iwai1d045db2011-07-07 18:23:21 +0200687/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200688static void alc_inithook(struct hda_codec *codec)
689{
David Henningsson29adc4b2012-09-25 11:31:00 +0200690 alc_hp_automute(codec, NULL);
691 alc_line_automute(codec, NULL);
692 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200693}
694
Kailang Yangf9423e72008-05-27 12:32:25 +0200695/* additional initialization for ALC888 variants */
696static void alc888_coef_init(struct hda_codec *codec)
697{
698 unsigned int tmp;
699
700 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
701 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
702 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100703 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200704 /* alc888S-VC */
705 snd_hda_codec_read(codec, 0x20, 0,
706 AC_VERB_SET_PROC_COEF, 0x830);
707 else
708 /* alc888-VB */
709 snd_hda_codec_read(codec, 0x20, 0,
710 AC_VERB_SET_PROC_COEF, 0x3030);
711}
712
Takashi Iwai1d045db2011-07-07 18:23:21 +0200713/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200714static void alc889_coef_init(struct hda_codec *codec)
715{
716 unsigned int tmp;
717
718 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
719 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
720 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
722}
723
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100724/* turn on/off EAPD control (only if available) */
725static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
726{
727 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
728 return;
729 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
731 on ? 2 : 0);
732}
733
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200734/* turn on/off EAPD controls of the codec */
735static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
736{
737 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200738 static hda_nid_t pins[] = {
739 0x0f, 0x10, 0x14, 0x15, 0
740 };
741 hda_nid_t *p;
742 for (p = pins; *p; p++)
743 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200744}
745
Takashi Iwai1c7161532011-04-07 10:37:16 +0200746/* generic shutup callback;
747 * just turning off EPAD and a little pause for avoiding pop-noise
748 */
749static void alc_eapd_shutup(struct hda_codec *codec)
750{
751 alc_auto_setup_eapd(codec, false);
752 msleep(200);
753}
754
Takashi Iwai1d045db2011-07-07 18:23:21 +0200755/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200756static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200757{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200758 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200759
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200760 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200761 switch (type) {
762 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200763 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
764 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200765 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200766 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
767 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200768 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200769 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
770 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200771 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200772 switch (codec->vendor_id) {
773 case 0x10ec0260:
774 snd_hda_codec_write(codec, 0x1a, 0,
775 AC_VERB_SET_COEF_INDEX, 7);
776 tmp = snd_hda_codec_read(codec, 0x1a, 0,
777 AC_VERB_GET_PROC_COEF, 0);
778 snd_hda_codec_write(codec, 0x1a, 0,
779 AC_VERB_SET_COEF_INDEX, 7);
780 snd_hda_codec_write(codec, 0x1a, 0,
781 AC_VERB_SET_PROC_COEF,
782 tmp | 0x2010);
783 break;
784 case 0x10ec0262:
785 case 0x10ec0880:
786 case 0x10ec0882:
787 case 0x10ec0883:
788 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100789 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100790 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200791 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200792 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200793 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200794 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200795 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100796#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200797 case 0x10ec0267:
798 case 0x10ec0268:
799 snd_hda_codec_write(codec, 0x20, 0,
800 AC_VERB_SET_COEF_INDEX, 7);
801 tmp = snd_hda_codec_read(codec, 0x20, 0,
802 AC_VERB_GET_PROC_COEF, 0);
803 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200804 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200805 snd_hda_codec_write(codec, 0x20, 0,
806 AC_VERB_SET_PROC_COEF,
807 tmp | 0x3000);
808 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100809#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200810 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200811 break;
812 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200813}
Kailang Yangea1fb292008-08-26 12:58:38 +0200814
Takashi Iwai1d045db2011-07-07 18:23:21 +0200815/*
816 * Auto-Mute mode mixer enum support
817 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200818static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
819 struct snd_ctl_elem_info *uinfo)
820{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200821 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
822 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200823 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100824 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200825 };
826
Takashi Iwaidda415d2012-11-30 18:34:38 +0100827 if (spec->automute_speaker_possible && spec->automute_lo_possible)
828 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
829 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200830}
831
832static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
833 struct snd_ctl_elem_value *ucontrol)
834{
835 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
836 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200837 unsigned int val = 0;
838 if (spec->automute_speaker)
839 val++;
840 if (spec->automute_lo)
841 val++;
842
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200843 ucontrol->value.enumerated.item[0] = val;
844 return 0;
845}
846
847static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
848 struct snd_ctl_elem_value *ucontrol)
849{
850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
851 struct alc_spec *spec = codec->spec;
852
853 switch (ucontrol->value.enumerated.item[0]) {
854 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200855 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200856 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200857 spec->automute_speaker = 0;
858 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200859 break;
860 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200861 if (spec->automute_speaker_possible) {
862 if (!spec->automute_lo && spec->automute_speaker)
863 return 0;
864 spec->automute_speaker = 1;
865 spec->automute_lo = 0;
866 } else if (spec->automute_lo_possible) {
867 if (spec->automute_lo)
868 return 0;
869 spec->automute_lo = 1;
870 } else
871 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200872 break;
873 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200874 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200875 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200876 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200877 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200878 spec->automute_speaker = 1;
879 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 break;
881 default:
882 return -EINVAL;
883 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 return 1;
886}
887
Takashi Iwaia9111322011-05-02 11:30:18 +0200888static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200889 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
890 .name = "Auto-Mute Mode",
891 .info = alc_automute_mode_info,
892 .get = alc_automute_mode_get,
893 .put = alc_automute_mode_put,
894};
895
Takashi Iwai668d1e92012-11-29 14:10:17 +0100896static struct snd_kcontrol_new *
897alc_kcontrol_new(struct alc_spec *spec, const char *name,
898 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200899{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100900 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
901 if (!knew)
902 return NULL;
903 *knew = *temp;
904 knew->name = kstrdup(name, GFP_KERNEL);
905 if (!knew->name)
906 return NULL;
907 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200908}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909
910static int alc_add_automute_mode_enum(struct hda_codec *codec)
911{
912 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200913
Takashi Iwai668d1e92012-11-29 14:10:17 +0100914 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200915 return -ENOMEM;
916 return 0;
917}
918
Takashi Iwai1d045db2011-07-07 18:23:21 +0200919/*
920 * Check the availability of HP/line-out auto-mute;
921 * Set up appropriately if really supported
922 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100923static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200924{
925 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200926 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200927 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100928 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200929
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200930 if (cfg->hp_pins[0])
931 present++;
932 if (cfg->line_out_pins[0])
933 present++;
934 if (cfg->speaker_pins[0])
935 present++;
936 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100937 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200938
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200939 if (!cfg->speaker_pins[0] &&
940 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200941 memcpy(cfg->speaker_pins, cfg->line_out_pins,
942 sizeof(cfg->speaker_pins));
943 cfg->speaker_outs = cfg->line_outs;
944 }
945
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200946 if (!cfg->hp_pins[0] &&
947 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200948 memcpy(cfg->hp_pins, cfg->line_out_pins,
949 sizeof(cfg->hp_pins));
950 cfg->hp_outs = cfg->line_outs;
951 }
952
953 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200954 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200955 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200956 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200957 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200958 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200959 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
960 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200961 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200962 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200963
David Henningsson42cf0d02011-09-20 12:04:56 +0200964 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
965 if (cfg->speaker_outs)
966 for (i = 0; i < cfg->line_outs; i++) {
967 hda_nid_t nid = cfg->line_out_pins[i];
968 if (!is_jack_detectable(codec, nid))
969 continue;
970 snd_printdd("realtek: Enable Line-Out "
971 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200972 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
973 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200974 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200975 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200976 spec->automute_lo_possible = spec->detect_hp;
977 }
978
979 spec->automute_speaker_possible = cfg->speaker_outs &&
980 (spec->detect_hp || spec->detect_lo);
981
982 spec->automute_lo = spec->automute_lo_possible;
983 spec->automute_speaker = spec->automute_speaker_possible;
984
Takashi Iwai475c3d22012-11-30 08:31:30 +0100985 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200986 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100987 err = alc_add_automute_mode_enum(codec);
988 if (err < 0)
989 return err;
990 }
991 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200992}
993
Takashi Iwai1d045db2011-07-07 18:23:21 +0200994/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200995static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
996{
997 int i;
998 for (i = 0; i < nums; i++)
999 if (list[i] == nid)
1000 return i;
1001 return -1;
1002}
1003
Takashi Iwai1d045db2011-07-07 18:23:21 +02001004/* check whether dynamic ADC-switching is available */
1005static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1006{
1007 struct alc_spec *spec = codec->spec;
1008 struct hda_input_mux *imux = &spec->private_imux[0];
1009 int i, n, idx;
1010 hda_nid_t cap, pin;
1011
1012 if (imux != spec->input_mux) /* no dynamic imux? */
1013 return false;
1014
1015 for (n = 0; n < spec->num_adc_nids; n++) {
1016 cap = spec->private_capsrc_nids[n];
1017 for (i = 0; i < imux->num_items; i++) {
1018 pin = spec->imux_pins[i];
1019 if (!pin)
1020 return false;
1021 if (get_connection_index(codec, cap, pin) < 0)
1022 break;
1023 }
1024 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001025 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001026 }
1027
1028 for (i = 0; i < imux->num_items; i++) {
1029 pin = spec->imux_pins[i];
1030 for (n = 0; n < spec->num_adc_nids; n++) {
1031 cap = spec->private_capsrc_nids[n];
1032 idx = get_connection_index(codec, cap, pin);
1033 if (idx >= 0) {
1034 imux->items[i].index = idx;
1035 spec->dyn_adc_idx[i] = n;
1036 break;
1037 }
1038 }
1039 }
1040
1041 snd_printdd("realtek: enabling ADC switching\n");
1042 spec->dyn_adc_switch = 1;
1043 return true;
1044}
Takashi Iwai21268962011-07-07 15:01:13 +02001045
Takashi Iwai21268962011-07-07 15:01:13 +02001046/* check whether all auto-mic pins are valid; setup indices if OK */
1047static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1048{
1049 struct alc_spec *spec = codec->spec;
1050 const struct hda_input_mux *imux;
1051
1052 if (!spec->auto_mic)
1053 return false;
1054 if (spec->auto_mic_valid_imux)
1055 return true; /* already checked */
1056
1057 /* fill up imux indices */
1058 if (!alc_check_dyn_adc_switch(codec)) {
1059 spec->auto_mic = 0;
1060 return false;
1061 }
1062
1063 imux = spec->input_mux;
1064 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1065 spec->imux_pins, imux->num_items);
1066 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1067 spec->imux_pins, imux->num_items);
1068 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1069 spec->imux_pins, imux->num_items);
1070 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1071 spec->auto_mic = 0;
1072 return false; /* no corresponding imux */
1073 }
1074
David Henningsson29adc4b2012-09-25 11:31:00 +02001075 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1076 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001077 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001078 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1079 ALC_MIC_EVENT,
1080 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001081
1082 spec->auto_mic_valid_imux = 1;
1083 spec->auto_mic = 1;
1084 return true;
1085}
1086
Takashi Iwai1d045db2011-07-07 18:23:21 +02001087/*
1088 * Check the availability of auto-mic switch;
1089 * Set up if really supported
1090 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001091static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001092{
1093 struct alc_spec *spec = codec->spec;
1094 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001095 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001096 int i;
1097
Takashi Iwai24de1832011-11-07 17:13:39 +01001098 if (spec->shared_mic_hp)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001099 return 0; /* no auto-mic for the shared I/O */
Takashi Iwai24de1832011-11-07 17:13:39 +01001100
Takashi Iwai21268962011-07-07 15:01:13 +02001101 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1102
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001103 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001104 for (i = 0; i < cfg->num_inputs; i++) {
1105 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001106 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001107 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001108 switch (snd_hda_get_input_pin_attr(defcfg)) {
1109 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001110 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001111 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001112 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001113 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001114 fixed = nid;
1115 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001116 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001117 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001118 case INPUT_PIN_ATTR_DOCK:
1119 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001120 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001121 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001122 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001123 dock = nid;
1124 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001125 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001126 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001127 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001128 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001129 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001130 ext = nid;
1131 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001132 }
1133 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001134 if (!ext && dock) {
1135 ext = dock;
1136 dock = 0;
1137 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001138 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001139 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001140 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001141 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001142 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001143 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001144
1145 /* check imux indices */
1146 spec->ext_mic_pin = ext;
1147 spec->int_mic_pin = fixed;
1148 spec->dock_mic_pin = dock;
1149
1150 spec->auto_mic = 1;
1151 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001152 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001153
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001154 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1155 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001156
1157 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001158}
1159
Takashi Iwai1d045db2011-07-07 18:23:21 +02001160/* check the availabilities of auto-mute and auto-mic switches */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001161static int alc_auto_check_switches(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02001162{
Takashi Iwai475c3d22012-11-30 08:31:30 +01001163 int err;
1164
1165 err = alc_init_automute(codec);
1166 if (err < 0)
1167 return err;
1168 err = alc_init_auto_mic(codec);
1169 if (err < 0)
1170 return err;
1171 return 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02001172}
1173
1174/*
1175 * Realtek SSID verification
1176 */
1177
David Henningsson90622912010-10-14 14:50:18 +02001178/* Could be any non-zero and even value. When used as fixup, tells
1179 * the driver to ignore any present sku defines.
1180 */
1181#define ALC_FIXUP_SKU_IGNORE (2)
1182
Takashi Iwai23d30f22012-05-07 17:17:32 +02001183static void alc_fixup_sku_ignore(struct hda_codec *codec,
1184 const struct hda_fixup *fix, int action)
1185{
1186 struct alc_spec *spec = codec->spec;
1187 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1188 spec->cdefine.fixup = 1;
1189 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1190 }
1191}
1192
Kailang Yangda00c242010-03-19 11:23:45 +01001193static int alc_auto_parse_customize_define(struct hda_codec *codec)
1194{
1195 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001196 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001197 struct alc_spec *spec = codec->spec;
1198
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001199 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1200
David Henningsson90622912010-10-14 14:50:18 +02001201 if (spec->cdefine.fixup) {
1202 ass = spec->cdefine.sku_cfg;
1203 if (ass == ALC_FIXUP_SKU_IGNORE)
1204 return -1;
1205 goto do_sku;
1206 }
1207
Kailang Yangda00c242010-03-19 11:23:45 +01001208 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001209 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001210 goto do_sku;
1211
1212 nid = 0x1d;
1213 if (codec->vendor_id == 0x10ec0260)
1214 nid = 0x17;
1215 ass = snd_hda_codec_get_pincfg(codec, nid);
1216
1217 if (!(ass & 1)) {
1218 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1219 codec->chip_name, ass);
1220 return -1;
1221 }
1222
1223 /* check sum */
1224 tmp = 0;
1225 for (i = 1; i < 16; i++) {
1226 if ((ass >> i) & 1)
1227 tmp++;
1228 }
1229 if (((ass >> 16) & 0xf) != tmp)
1230 return -1;
1231
1232 spec->cdefine.port_connectivity = ass >> 30;
1233 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1234 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1235 spec->cdefine.customization = ass >> 8;
1236do_sku:
1237 spec->cdefine.sku_cfg = ass;
1238 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1239 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1240 spec->cdefine.swap = (ass & 0x2) >> 1;
1241 spec->cdefine.override = ass & 0x1;
1242
1243 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1244 nid, spec->cdefine.sku_cfg);
1245 snd_printd("SKU: port_connectivity=0x%x\n",
1246 spec->cdefine.port_connectivity);
1247 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1248 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1249 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1250 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1251 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1252 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1253 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1254
1255 return 0;
1256}
1257
Takashi Iwai1d045db2011-07-07 18:23:21 +02001258/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001259static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1260{
Takashi Iwai21268962011-07-07 15:01:13 +02001261 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001262}
1263
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001264/* check subsystem ID and set up device-specific initialization;
1265 * return 1 if initialized, 0 if invalid SSID
1266 */
1267/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1268 * 31 ~ 16 : Manufacture ID
1269 * 15 ~ 8 : SKU ID
1270 * 7 ~ 0 : Assembly ID
1271 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1272 */
1273static int alc_subsystem_id(struct hda_codec *codec,
1274 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001275 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001276{
1277 unsigned int ass, tmp, i;
1278 unsigned nid;
1279 struct alc_spec *spec = codec->spec;
1280
David Henningsson90622912010-10-14 14:50:18 +02001281 if (spec->cdefine.fixup) {
1282 ass = spec->cdefine.sku_cfg;
1283 if (ass == ALC_FIXUP_SKU_IGNORE)
1284 return 0;
1285 goto do_sku;
1286 }
1287
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001288 ass = codec->subsystem_id & 0xffff;
1289 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1290 goto do_sku;
1291
1292 /* invalid SSID, check the special NID pin defcfg instead */
1293 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001294 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001295 * 29~21 : reserve
1296 * 20 : PCBEEP input
1297 * 19~16 : Check sum (15:1)
1298 * 15~1 : Custom
1299 * 0 : override
1300 */
1301 nid = 0x1d;
1302 if (codec->vendor_id == 0x10ec0260)
1303 nid = 0x17;
1304 ass = snd_hda_codec_get_pincfg(codec, nid);
1305 snd_printd("realtek: No valid SSID, "
1306 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001307 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001308 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001309 return 0;
1310 if ((ass >> 30) != 1) /* no physical connection */
1311 return 0;
1312
1313 /* check sum */
1314 tmp = 0;
1315 for (i = 1; i < 16; i++) {
1316 if ((ass >> i) & 1)
1317 tmp++;
1318 }
1319 if (((ass >> 16) & 0xf) != tmp)
1320 return 0;
1321do_sku:
1322 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1323 ass & 0xffff, codec->vendor_id);
1324 /*
1325 * 0 : override
1326 * 1 : Swap Jack
1327 * 2 : 0 --> Desktop, 1 --> Laptop
1328 * 3~5 : External Amplifier control
1329 * 7~6 : Reserved
1330 */
1331 tmp = (ass & 0x38) >> 3; /* external Amp control */
1332 switch (tmp) {
1333 case 1:
1334 spec->init_amp = ALC_INIT_GPIO1;
1335 break;
1336 case 3:
1337 spec->init_amp = ALC_INIT_GPIO2;
1338 break;
1339 case 7:
1340 spec->init_amp = ALC_INIT_GPIO3;
1341 break;
1342 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001343 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001344 spec->init_amp = ALC_INIT_DEFAULT;
1345 break;
1346 }
1347
1348 /* is laptop or Desktop and enable the function "Mute internal speaker
1349 * when the external headphone out jack is plugged"
1350 */
1351 if (!(ass & 0x8000))
1352 return 1;
1353 /*
1354 * 10~8 : Jack location
1355 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1356 * 14~13: Resvered
1357 * 15 : 1 --> enable the function "Mute internal speaker
1358 * when the external headphone out jack is plugged"
1359 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001360 if (!spec->autocfg.hp_pins[0] &&
1361 !(spec->autocfg.line_out_pins[0] &&
1362 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001363 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001364 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1365 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001366 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001367 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001368 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001369 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001370 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001371 else if (tmp == 3)
1372 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001373 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001374 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001375 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1376 spec->autocfg.line_outs))
1377 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001378 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001379 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001380 return 1;
1381}
Kailang Yangea1fb292008-08-26 12:58:38 +02001382
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001383/* Check the validity of ALC subsystem-id
1384 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1385static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001386{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001387 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001388 struct alc_spec *spec = codec->spec;
1389 snd_printd("realtek: "
1390 "Enable default setup for auto mode as fallback\n");
1391 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001392 }
Takashi Iwai21268962011-07-07 15:01:13 +02001393}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001394
Takashi Iwai41e41f12005-06-08 14:48:49 +02001395/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001396 * COEF access helper functions
1397 */
Kailang Yang274693f2009-12-03 10:07:50 +01001398static int alc_read_coef_idx(struct hda_codec *codec,
1399 unsigned int coef_idx)
1400{
1401 unsigned int val;
1402 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1403 coef_idx);
1404 val = snd_hda_codec_read(codec, 0x20, 0,
1405 AC_VERB_GET_PROC_COEF, 0);
1406 return val;
1407}
1408
Kailang Yang977ddd62010-09-15 10:02:29 +02001409static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1410 unsigned int coef_val)
1411{
1412 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1413 coef_idx);
1414 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1415 coef_val);
1416}
1417
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001418/* a special bypass for COEF 0; read the cached value at the second time */
1419static unsigned int alc_get_coef0(struct hda_codec *codec)
1420{
1421 struct alc_spec *spec = codec->spec;
1422 if (!spec->coef0)
1423 spec->coef0 = alc_read_coef_idx(codec, 0);
1424 return spec->coef0;
1425}
1426
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001427static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1428 hda_nid_t pin, int pin_type,
1429 hda_nid_t dac);
1430static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1431 bool is_digital);
1432static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
1433 hda_nid_t dac);
1434
Takashi Iwai1d045db2011-07-07 18:23:21 +02001435/*
1436 * Digital I/O handling
1437 */
1438
Takashi Iwai757899a2010-07-30 10:48:14 +02001439/* set right pin controls for digital I/O */
1440static void alc_auto_init_digital(struct hda_codec *codec)
1441{
1442 struct alc_spec *spec = codec->spec;
1443 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001444 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001445
1446 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1447 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001448 if (!pin)
1449 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001450 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001451 }
1452 pin = spec->autocfg.dig_in_pin;
1453 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001454 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001455}
1456
1457/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1458static void alc_auto_parse_digital(struct hda_codec *codec)
1459{
1460 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001461 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001462 hda_nid_t dig_nid;
1463
1464 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001465 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001466 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001467 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1468 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1469 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001470 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001471 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001472 spec->multiout.dig_out_nid = dig_nid;
1473 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1474 } else {
1475 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001476 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001477 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001478 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001479 }
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001480 add_new_out_path(codec, pin, dig_nid);
Takashi Iwai51e41522011-11-03 16:54:06 +01001481 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001482 }
1483
1484 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001485 dig_nid = codec->start_nid;
1486 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1487 unsigned int wcaps = get_wcaps(codec, dig_nid);
1488 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1489 continue;
1490 if (!(wcaps & AC_WCAP_DIGITAL))
1491 continue;
1492 if (!(wcaps & AC_WCAP_CONN_LIST))
1493 continue;
1494 err = get_connection_index(codec, dig_nid,
1495 spec->autocfg.dig_in_pin);
1496 if (err >= 0) {
1497 spec->dig_in_nid = dig_nid;
1498 break;
1499 }
1500 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001501 }
1502}
1503
Takashi Iwaif95474e2007-07-10 00:47:43 +02001504/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001505 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001506 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001507static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1508 struct snd_ctl_elem_info *uinfo)
1509{
1510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1511 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001512 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001513 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001514
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001515 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001516 if (spec->vol_in_capsrc)
1517 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1518 else
1519 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1520 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001521 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001522 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001523 return err;
1524}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001526static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1527 unsigned int size, unsigned int __user *tlv)
1528{
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001531 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001532 int err;
1533
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001534 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001535 if (spec->vol_in_capsrc)
1536 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1537 else
1538 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1539 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001540 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001541 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001542 return err;
1543}
1544
1545typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1546 struct snd_ctl_elem_value *ucontrol);
1547
1548static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1549 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001550 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001551{
1552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1553 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001554 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001555
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001556 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001557 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001558 for (i = 0; i < spec->num_adc_nids; i++) {
1559 kcontrol->private_value =
1560 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1561 3, 0, HDA_INPUT);
1562 err = func(kcontrol, ucontrol);
1563 if (err < 0)
1564 goto error;
1565 }
1566 } else {
1567 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001568 if (spec->vol_in_capsrc)
1569 kcontrol->private_value =
1570 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1571 3, 0, HDA_OUTPUT);
1572 else
1573 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001574 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1575 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001576 err = func(kcontrol, ucontrol);
1577 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001578 if (err >= 0 && is_put)
1579 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001580 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001581 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001582 return err;
1583}
1584
1585static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1586 struct snd_ctl_elem_value *ucontrol)
1587{
1588 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001589 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001590}
1591
1592static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1594{
1595 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001596 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001597}
1598
1599/* capture mixer elements */
1600#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1601
1602static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1603 struct snd_ctl_elem_value *ucontrol)
1604{
1605 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001606 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001607}
1608
1609static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1611{
1612 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001613 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001614}
1615
Takashi Iwaia23b6882009-03-23 15:21:36 +01001616#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001617 { \
1618 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1619 .name = "Capture Switch", \
1620 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1621 .count = num, \
1622 .info = alc_cap_sw_info, \
1623 .get = alc_cap_sw_get, \
1624 .put = alc_cap_sw_put, \
1625 }, \
1626 { \
1627 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1628 .name = "Capture Volume", \
1629 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1630 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1631 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1632 .count = num, \
1633 .info = alc_cap_vol_info, \
1634 .get = alc_cap_vol_get, \
1635 .put = alc_cap_vol_put, \
1636 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001637 }
1638
1639#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001640 { \
1641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1642 /* .name = "Capture Source", */ \
1643 .name = "Input Source", \
1644 .count = num, \
1645 .info = alc_mux_enum_info, \
1646 .get = alc_mux_enum_get, \
1647 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001648 }
1649
1650#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001651static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001652 _DEFINE_CAPMIX(num), \
1653 _DEFINE_CAPSRC(num), \
1654 { } /* end */ \
1655}
1656
1657#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001658static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001659 _DEFINE_CAPMIX(num), \
1660 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001661}
1662
1663/* up to three ADCs */
1664DEFINE_CAPMIX(1);
1665DEFINE_CAPMIX(2);
1666DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001667DEFINE_CAPMIX_NOSRC(1);
1668DEFINE_CAPMIX_NOSRC(2);
1669DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001670
1671/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001672 * Inverted digital-mic handling
1673 *
1674 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1675 * gives the additional mute only to the right channel of the digital mic
1676 * capture stream. This is a workaround for avoiding the almost silence
1677 * by summing the stereo stream from some (known to be ForteMedia)
1678 * digital mic unit.
1679 *
1680 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1681 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1682 * without caching so that the cache can still keep the original value.
1683 * The cached value is then restored when the flag is set off or any other
1684 * than d-mic is used as the current input source.
1685 */
1686static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1687{
1688 struct alc_spec *spec = codec->spec;
1689 int i;
1690
1691 if (!spec->inv_dmic_fixup)
1692 return;
1693 if (!spec->inv_dmic_muted && !force)
1694 return;
1695 for (i = 0; i < spec->num_adc_nids; i++) {
1696 int src = spec->dyn_adc_switch ? 0 : i;
1697 bool dmic_fixup = false;
1698 hda_nid_t nid;
1699 int parm, dir, v;
1700
1701 if (spec->inv_dmic_muted &&
1702 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1703 dmic_fixup = true;
1704 if (!dmic_fixup && !force)
1705 continue;
1706 if (spec->vol_in_capsrc) {
1707 nid = spec->capsrc_nids[i];
1708 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1709 dir = HDA_OUTPUT;
1710 } else {
1711 nid = spec->adc_nids[i];
1712 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1713 dir = HDA_INPUT;
1714 }
1715 /* we care only right channel */
1716 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1717 if (v & 0x80) /* if already muted, we don't need to touch */
1718 continue;
1719 if (dmic_fixup) /* add mute for d-mic */
1720 v |= 0x80;
1721 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1722 parm | v);
1723 }
1724}
1725
1726static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol)
1728{
1729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1730 struct alc_spec *spec = codec->spec;
1731
1732 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1733 return 0;
1734}
1735
1736static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_value *ucontrol)
1738{
1739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1740 struct alc_spec *spec = codec->spec;
1741 unsigned int val = !ucontrol->value.integer.value[0];
1742
1743 if (val == spec->inv_dmic_muted)
1744 return 0;
1745 spec->inv_dmic_muted = val;
1746 alc_inv_dmic_sync(codec, true);
1747 return 0;
1748}
1749
1750static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1752 .info = snd_ctl_boolean_mono_info,
1753 .get = alc_inv_dmic_sw_get,
1754 .put = alc_inv_dmic_sw_put,
1755};
1756
1757static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1758{
1759 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001760
1761 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1762 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001763 return -ENOMEM;
1764 spec->inv_dmic_fixup = 1;
1765 spec->inv_dmic_muted = 0;
1766 spec->inv_dmic_pin = nid;
1767 return 0;
1768}
1769
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001770/* typically the digital mic is put at node 0x12 */
1771static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1772 const struct alc_fixup *fix, int action)
1773{
1774 if (action == ALC_FIXUP_ACT_PROBE)
1775 alc_add_inv_dmic_mixer(codec, 0x12);
1776}
1777
Takashi Iwai125821a2012-06-22 14:30:29 +02001778/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001779 * virtual master controls
1780 */
1781
1782/*
1783 * slave controls for virtual master
1784 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001785static const char * const alc_slave_pfxs[] = {
1786 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001787 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001788 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001789 NULL,
1790};
1791
1792/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001793 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001795
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001796#define NID_MAPPING (-1)
1797
1798#define SUBDEV_SPEAKER_ (0 << 6)
1799#define SUBDEV_HP_ (1 << 6)
1800#define SUBDEV_LINE_ (2 << 6)
1801#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1802#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1803#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1804
Takashi Iwai603c4012008-07-30 15:01:44 +02001805static void alc_free_kctls(struct hda_codec *codec);
1806
Takashi Iwai67d634c2009-11-16 15:35:59 +01001807#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001808/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001809static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001810 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001811 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001812 { } /* end */
1813};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001814#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001815
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001816static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817{
1818 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001819 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001820 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001821 int i, j, err;
1822 unsigned int u;
1823 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
1825 for (i = 0; i < spec->num_mixers; i++) {
1826 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1827 if (err < 0)
1828 return err;
1829 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001830 if (spec->cap_mixer) {
1831 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1832 if (err < 0)
1833 return err;
1834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001836 err = snd_hda_create_dig_out_ctls(codec,
1837 spec->multiout.dig_out_nid,
1838 spec->multiout.dig_out_nid,
1839 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 if (err < 0)
1841 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001842 if (!spec->no_analog) {
1843 err = snd_hda_create_spdif_share_sw(codec,
1844 &spec->multiout);
1845 if (err < 0)
1846 return err;
1847 spec->multiout.share_spdif = 1;
1848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 }
1850 if (spec->dig_in_nid) {
1851 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1852 if (err < 0)
1853 return err;
1854 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001855
Takashi Iwai67d634c2009-11-16 15:35:59 +01001856#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001857 /* create beep controls if needed */
1858 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001859 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001860 for (knew = alc_beep_mixer; knew->name; knew++) {
1861 struct snd_kcontrol *kctl;
1862 kctl = snd_ctl_new1(knew, codec);
1863 if (!kctl)
1864 return -ENOMEM;
1865 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001866 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001867 if (err < 0)
1868 return err;
1869 }
1870 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001871#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001872
Takashi Iwai2134ea42008-01-10 16:53:55 +01001873 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001874 if (!spec->no_analog &&
1875 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001876 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001877 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001878 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001879 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001880 vmaster_tlv, alc_slave_pfxs,
1881 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001882 if (err < 0)
1883 return err;
1884 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001885 if (!spec->no_analog &&
1886 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001887 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1888 NULL, alc_slave_pfxs,
1889 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001890 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001891 if (err < 0)
1892 return err;
1893 }
1894
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001895 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001896 if (spec->capsrc_nids || spec->adc_nids) {
1897 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1898 if (!kctl)
1899 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1900 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001901 err = snd_hda_add_nid(codec, kctl, i,
1902 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001903 if (err < 0)
1904 return err;
1905 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001906 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001907 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001908 const char *kname = kctl ? kctl->id.name : NULL;
1909 for (knew = spec->cap_mixer; knew->name; knew++) {
1910 if (kname && strcmp(knew->name, kname) == 0)
1911 continue;
1912 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1913 for (i = 0; kctl && i < kctl->count; i++) {
1914 err = snd_hda_add_nid(codec, kctl, i,
1915 spec->adc_nids[i]);
1916 if (err < 0)
1917 return err;
1918 }
1919 }
1920 }
1921
1922 /* other nid->control mapping */
1923 for (i = 0; i < spec->num_mixers; i++) {
1924 for (knew = spec->mixers[i]; knew->name; knew++) {
1925 if (knew->iface != NID_MAPPING)
1926 continue;
1927 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1928 if (kctl == NULL)
1929 continue;
1930 u = knew->subdevice;
1931 for (j = 0; j < 4; j++, u >>= 8) {
1932 nid = u & 0x3f;
1933 if (nid == 0)
1934 continue;
1935 switch (u & 0xc0) {
1936 case SUBDEV_SPEAKER_:
1937 nid = spec->autocfg.speaker_pins[nid];
1938 break;
1939 case SUBDEV_LINE_:
1940 nid = spec->autocfg.line_out_pins[nid];
1941 break;
1942 case SUBDEV_HP_:
1943 nid = spec->autocfg.hp_pins[nid];
1944 break;
1945 default:
1946 continue;
1947 }
1948 err = snd_hda_add_nid(codec, kctl, 0, nid);
1949 if (err < 0)
1950 return err;
1951 }
1952 u = knew->private_value;
1953 for (j = 0; j < 4; j++, u >>= 8) {
1954 nid = u & 0xff;
1955 if (nid == 0)
1956 continue;
1957 err = snd_hda_add_nid(codec, kctl, 0, nid);
1958 if (err < 0)
1959 return err;
1960 }
1961 }
1962 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001963
1964 alc_free_kctls(codec); /* no longer needed */
1965
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001966 return 0;
1967}
1968
David Henningsson5780b622012-06-27 18:45:45 +02001969static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001970{
1971 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001972
1973 if (spec->shared_mic_hp) {
1974 int err;
1975 int nid = spec->autocfg.inputs[1].pin;
1976 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1977 if (err < 0)
1978 return err;
1979 err = snd_hda_jack_detect_enable(codec, nid, 0);
1980 if (err < 0)
1981 return err;
1982 }
1983
1984 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1985}
1986
1987static int alc_build_controls(struct hda_codec *codec)
1988{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001989 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001990 if (err < 0)
1991 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001992
1993 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001994 if (err < 0)
1995 return err;
1996 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1997 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998}
1999
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002000
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002002 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002003 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002004
Takashi Iwai584c0c42011-03-10 12:51:11 +01002005static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002006static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002007
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008static int alc_init(struct hda_codec *codec)
2009{
2010 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002011
Takashi Iwai546bb672012-03-07 08:37:19 +01002012 if (spec->init_hook)
2013 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002014
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002015 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002016 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002017
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002018 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002019 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002020 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002021
Takashi Iwai58701122011-01-13 15:41:45 +01002022 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2023
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002024 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 return 0;
2026}
2027
Takashi Iwai83012a72012-08-24 18:38:08 +02002028#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002029static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2030{
2031 struct alc_spec *spec = codec->spec;
2032 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2033}
2034#endif
2035
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036/*
2037 * Analog playback callbacks
2038 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002039static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002041 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042{
2043 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002044 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2045 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002048static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 struct hda_codec *codec,
2050 unsigned int stream_tag,
2051 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002052 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053{
2054 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002055 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2056 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002059static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 struct hda_codec *codec,
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;
2064 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2065}
2066
2067/*
2068 * Digital out
2069 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002070static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002072 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
2074 struct alc_spec *spec = codec->spec;
2075 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2076}
2077
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002078static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002079 struct hda_codec *codec,
2080 unsigned int stream_tag,
2081 unsigned int format,
2082 struct snd_pcm_substream *substream)
2083{
2084 struct alc_spec *spec = codec->spec;
2085 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2086 stream_tag, format, substream);
2087}
2088
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002089static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002090 struct hda_codec *codec,
2091 struct snd_pcm_substream *substream)
2092{
2093 struct alc_spec *spec = codec->spec;
2094 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2095}
2096
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002097static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002099 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100{
2101 struct alc_spec *spec = codec->spec;
2102 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2103}
2104
2105/*
2106 * Analog capture
2107 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002108static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct hda_codec *codec,
2110 unsigned int stream_tag,
2111 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002112 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
2114 struct alc_spec *spec = codec->spec;
2115
Takashi Iwai63300792008-01-24 15:31:36 +01002116 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 stream_tag, 0, format);
2118 return 0;
2119}
2120
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002121static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002123 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
2125 struct alc_spec *spec = codec->spec;
2126
Takashi Iwai888afa12008-03-18 09:57:50 +01002127 snd_hda_codec_cleanup_stream(codec,
2128 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 return 0;
2130}
2131
Takashi Iwai840b64c2010-07-13 22:49:01 +02002132/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002133static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002134 struct hda_codec *codec,
2135 unsigned int stream_tag,
2136 unsigned int format,
2137 struct snd_pcm_substream *substream)
2138{
2139 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002140 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002141 spec->cur_adc_stream_tag = stream_tag;
2142 spec->cur_adc_format = format;
2143 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2144 return 0;
2145}
2146
Takashi Iwai21268962011-07-07 15:01:13 +02002147static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002148 struct hda_codec *codec,
2149 struct snd_pcm_substream *substream)
2150{
2151 struct alc_spec *spec = codec->spec;
2152 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2153 spec->cur_adc = 0;
2154 return 0;
2155}
2156
Takashi Iwai21268962011-07-07 15:01:13 +02002157static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002158 .substreams = 1,
2159 .channels_min = 2,
2160 .channels_max = 2,
2161 .nid = 0, /* fill later */
2162 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002163 .prepare = dyn_adc_capture_pcm_prepare,
2164 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002165 },
2166};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
2168/*
2169 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002170static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 .substreams = 1,
2172 .channels_min = 2,
2173 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002174 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002176 .open = alc_playback_pcm_open,
2177 .prepare = alc_playback_pcm_prepare,
2178 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 },
2180};
2181
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002182static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002183 .substreams = 1,
2184 .channels_min = 2,
2185 .channels_max = 2,
2186 /* NID is set in alc_build_pcms */
2187};
2188
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002189static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002190 .substreams = 1,
2191 .channels_min = 2,
2192 .channels_max = 2,
2193 /* NID is set in alc_build_pcms */
2194};
2195
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002196static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002197 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 .channels_min = 2,
2199 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002200 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002202 .prepare = alc_alt_capture_pcm_prepare,
2203 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 },
2205};
2206
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002207static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 .substreams = 1,
2209 .channels_min = 2,
2210 .channels_max = 2,
2211 /* NID is set in alc_build_pcms */
2212 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002213 .open = alc_dig_playback_pcm_open,
2214 .close = alc_dig_playback_pcm_close,
2215 .prepare = alc_dig_playback_pcm_prepare,
2216 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 },
2218};
2219
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002220static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 .substreams = 1,
2222 .channels_min = 2,
2223 .channels_max = 2,
2224 /* NID is set in alc_build_pcms */
2225};
2226
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002227/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002228static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002229 .substreams = 0,
2230 .channels_min = 0,
2231 .channels_max = 0,
2232};
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234static int alc_build_pcms(struct hda_codec *codec)
2235{
2236 struct alc_spec *spec = codec->spec;
2237 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002238 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002239 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 int i;
2241
2242 codec->num_pcms = 1;
2243 codec->pcm_info = info;
2244
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002245 if (spec->no_analog)
2246 goto skip_analog;
2247
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002248 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2249 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002251
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002252 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002253 p = spec->stream_analog_playback;
2254 if (!p)
2255 p = &alc_pcm_analog_playback;
2256 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002257 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002258 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2259 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002260 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2261 spec->autocfg.line_outs == 2)
2262 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2263 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002264 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002265 if (spec->adc_nids) {
2266 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002267 if (!p) {
2268 if (spec->dyn_adc_switch)
2269 p = &dyn_adc_pcm_analog_capture;
2270 else
2271 p = &alc_pcm_analog_capture;
2272 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002273 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002274 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Takashi Iwai4a471b72005-12-07 13:56:29 +01002277 if (spec->channel_mode) {
2278 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2279 for (i = 0; i < spec->num_channel_mode; i++) {
2280 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 }
2284 }
2285
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002286 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002287 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002289 snprintf(spec->stream_name_digital,
2290 sizeof(spec->stream_name_digital),
2291 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002292 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002293 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002294 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002296 if (spec->dig_out_type)
2297 info->pcm_type = spec->dig_out_type;
2298 else
2299 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002300 if (spec->multiout.dig_out_nid) {
2301 p = spec->stream_digital_playback;
2302 if (!p)
2303 p = &alc_pcm_digital_playback;
2304 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2306 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002307 if (spec->dig_in_nid) {
2308 p = spec->stream_digital_capture;
2309 if (!p)
2310 p = &alc_pcm_digital_capture;
2311 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2313 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002314 /* FIXME: do we need this for all Realtek codec models? */
2315 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 }
2317
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002318 if (spec->no_analog)
2319 return 0;
2320
Takashi Iwaie08a0072006-09-07 17:52:14 +02002321 /* If the use of more than one ADC is requested for the current
2322 * model, configure a second analog capture-only PCM.
2323 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002324 have_multi_adcs = (spec->num_adc_nids > 1) &&
2325 !spec->dyn_adc_switch && !spec->auto_mic &&
2326 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002327 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002328 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002329 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002330 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002331 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002332 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002333 p = spec->stream_analog_alt_playback;
2334 if (!p)
2335 p = &alc_pcm_analog_alt_playback;
2336 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002337 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2338 spec->alt_dac_nid;
2339 } else {
2340 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2341 alc_pcm_null_stream;
2342 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2343 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002344 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002345 p = spec->stream_analog_alt_capture;
2346 if (!p)
2347 p = &alc_pcm_analog_alt_capture;
2348 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002349 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2350 spec->adc_nids[1];
2351 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2352 spec->num_adc_nids - 1;
2353 } else {
2354 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2355 alc_pcm_null_stream;
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002357 }
2358 }
2359
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 return 0;
2361}
2362
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002363static inline void alc_shutup(struct hda_codec *codec)
2364{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002365 struct alc_spec *spec = codec->spec;
2366
2367 if (spec && spec->shutup)
2368 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002369 snd_hda_shutup_pins(codec);
2370}
2371
Takashi Iwai603c4012008-07-30 15:01:44 +02002372static void alc_free_kctls(struct hda_codec *codec)
2373{
2374 struct alc_spec *spec = codec->spec;
2375
2376 if (spec->kctls.list) {
2377 struct snd_kcontrol_new *kctl = spec->kctls.list;
2378 int i;
2379 for (i = 0; i < spec->kctls.used; i++)
2380 kfree(kctl[i].name);
2381 }
2382 snd_array_free(&spec->kctls);
2383}
2384
Takashi Iwai23c09b02011-08-19 09:05:35 +02002385static void alc_free_bind_ctls(struct hda_codec *codec)
2386{
2387 struct alc_spec *spec = codec->spec;
2388 if (spec->bind_ctls.list) {
2389 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2390 int i;
2391 for (i = 0; i < spec->bind_ctls.used; i++)
2392 kfree(ctl[i]);
2393 }
2394 snd_array_free(&spec->bind_ctls);
2395}
2396
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397static void alc_free(struct hda_codec *codec)
2398{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002399 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002400
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002401 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002402 return;
2403
Takashi Iwai603c4012008-07-30 15:01:44 +02002404 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002405 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002406 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002407 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002408 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002409 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410}
2411
Takashi Iwai83012a72012-08-24 18:38:08 +02002412#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002413static void alc_power_eapd(struct hda_codec *codec)
2414{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002415 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002416}
2417
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002418static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002419{
2420 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002421 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002422 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002423 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002424 return 0;
2425}
2426#endif
2427
Takashi Iwai2a439522011-07-26 09:52:50 +02002428#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002429static int alc_resume(struct hda_codec *codec)
2430{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002431 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002432 codec->patch_ops.init(codec);
2433 snd_hda_codec_resume_amp(codec);
2434 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002435 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002436 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002437 return 0;
2438}
Takashi Iwaie044c392008-10-27 16:56:24 +01002439#endif
2440
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441/*
2442 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002443static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 .build_controls = alc_build_controls,
2445 .build_pcms = alc_build_pcms,
2446 .init = alc_init,
2447 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002448 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002449#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002450 .resume = alc_resume,
2451#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002452#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002453 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002454 .check_power_status = alc_check_power_status,
2455#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002456 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457};
2458
David Henningsson29adc4b2012-09-25 11:31:00 +02002459
Kailang Yangc027ddc2010-03-19 11:33:06 +01002460/* replace the codec chip_name with the given string */
2461static int alc_codec_rename(struct hda_codec *codec, const char *name)
2462{
2463 kfree(codec->chip_name);
2464 codec->chip_name = kstrdup(name, GFP_KERNEL);
2465 if (!codec->chip_name) {
2466 alc_free(codec);
2467 return -ENOMEM;
2468 }
2469 return 0;
2470}
2471
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002472/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002473 * Rename codecs appropriately from COEF value
2474 */
2475struct alc_codec_rename_table {
2476 unsigned int vendor_id;
2477 unsigned short coef_mask;
2478 unsigned short coef_bits;
2479 const char *name;
2480};
2481
2482static struct alc_codec_rename_table rename_tbl[] = {
2483 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2484 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2485 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2486 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2487 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2488 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2489 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002490 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002491 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2492 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2493 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2494 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2495 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2496 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2497 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2498 { } /* terminator */
2499};
2500
2501static int alc_codec_rename_from_preset(struct hda_codec *codec)
2502{
2503 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002504
2505 for (p = rename_tbl; p->vendor_id; p++) {
2506 if (p->vendor_id != codec->vendor_id)
2507 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002508 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002509 return alc_codec_rename(codec, p->name);
2510 }
2511 return 0;
2512}
2513
2514/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002515 * Automatic parse of I/O pins from the BIOS configuration
2516 */
2517
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002518enum {
2519 ALC_CTL_WIDGET_VOL,
2520 ALC_CTL_WIDGET_MUTE,
2521 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002522 ALC_CTL_BIND_VOL,
2523 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002524};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002525static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002526 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2527 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002528 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002529 HDA_BIND_VOL(NULL, 0),
2530 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002531};
2532
2533/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002534static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002535 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002536{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002537 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002538
Takashi Iwai668d1e92012-11-29 14:10:17 +01002539 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002540 if (!knew)
2541 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002542 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002543 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002544 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002545 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002546 return 0;
2547}
2548
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002549static int add_control_with_pfx(struct alc_spec *spec, int type,
2550 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002551 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002552{
2553 char name[32];
2554 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002555 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002556}
2557
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002558#define add_pb_vol_ctrl(spec, type, pfx, val) \
2559 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2560#define add_pb_sw_ctrl(spec, type, pfx, val) \
2561 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2562#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2563 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2564#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2565 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002566
Takashi Iwai23c09b02011-08-19 09:05:35 +02002567static const char * const channel_name[4] = {
2568 "Front", "Surround", "CLFE", "Side"
2569};
2570
Takashi Iwai6843ca12011-06-24 11:03:58 +02002571static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2572 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002573{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002574 struct auto_pin_cfg *cfg = &spec->autocfg;
2575
Takashi Iwai6843ca12011-06-24 11:03:58 +02002576 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002577 if (cfg->line_outs == 1 && !spec->multi_ios &&
2578 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002579 return "Master";
2580
2581 switch (cfg->line_out_type) {
2582 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002583 if (cfg->line_outs == 1)
2584 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002585 if (cfg->line_outs == 2)
2586 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002587 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002588 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002589 /* for multi-io case, only the primary out */
2590 if (ch && spec->multi_ios)
2591 break;
2592 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002593 return "Headphone";
2594 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002595 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002596 return "PCM";
2597 break;
2598 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002599 if (ch >= ARRAY_SIZE(channel_name)) {
2600 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002601 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002602 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002603
2604 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002605}
2606
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002607static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2608 hda_nid_t to_nid, int with_aa_mix,
2609 struct nid_path *path);
2610
Takashi Iwai83012a72012-08-24 18:38:08 +02002611#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002612/* add the powersave loopback-list entry */
2613static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2614{
2615 struct hda_amp_list *list;
2616
2617 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2618 return;
2619 list = spec->loopback_list + spec->num_loopbacks;
2620 list->nid = mix;
2621 list->dir = HDA_INPUT;
2622 list->idx = idx;
2623 spec->num_loopbacks++;
2624 spec->loopback.amplist = spec->loopback_list;
2625}
2626#else
2627#define add_loopback_list(spec, mix, idx) /* NOP */
2628#endif
2629
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002630/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002631static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002632 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002633 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002634{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002635 struct alc_spec *spec = codec->spec;
2636 struct nid_path *path;
2637 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002638
Takashi Iwaibd32f782012-12-12 18:08:52 +01002639 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2640 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2641 return 0; /* no need for analog loopback */
2642
Takashi Iwaic9967f12012-12-14 16:39:22 +01002643 path = snd_array_new(&spec->paths);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002644 if (!path)
2645 return -ENOMEM;
2646 memset(path, 0, sizeof(*path));
2647 if (!parse_nid_path(codec, pin, mix_nid, 2, path))
2648 return -EINVAL;
2649
2650 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002651 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
2652 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002653 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002654 if (err < 0)
2655 return err;
2656 }
2657
2658 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
2659 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002660 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002661 if (err < 0)
2662 return err;
2663 }
2664
Takashi Iwai164f73e2012-02-21 11:27:09 +01002665 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002666 return 0;
2667}
2668
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002669static int new_capture_source(struct hda_codec *codec, int adc_idx,
2670 hda_nid_t pin, int idx, const char *label)
2671{
2672 struct alc_spec *spec = codec->spec;
2673 struct hda_input_mux *imux = &spec->private_imux[0];
2674 struct nid_path *path;
2675
Takashi Iwaic9967f12012-12-14 16:39:22 +01002676 path = snd_array_new(&spec->paths);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002677 if (!path)
2678 return -ENOMEM;
2679 memset(path, 0, sizeof(*path));
2680 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2681 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2682 pin, spec->adc_nids[adc_idx]);
2683 return -EINVAL;
2684 }
2685
2686 spec->imux_pins[imux->num_items] = pin;
2687 snd_hda_add_imux_item(imux, label, idx, NULL);
2688 return 0;
2689}
2690
Takashi Iwai05f5f472009-08-25 13:10:18 +02002691static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002692{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002693 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2694 return (pincap & AC_PINCAP_IN) != 0;
2695}
2696
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002697/* check whether the given two widgets can be connected */
2698static bool is_reachable_path(struct hda_codec *codec,
2699 hda_nid_t from_nid, hda_nid_t to_nid)
2700{
2701 if (!from_nid || !to_nid)
2702 return false;
2703 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2704}
2705
Takashi Iwai1d045db2011-07-07 18:23:21 +02002706/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002707static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002708{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002709 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002710 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002711 hda_nid_t *adc_nids = spec->private_adc_nids;
2712 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2713 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002714 int i, nums = 0;
2715
2716 nid = codec->start_nid;
2717 for (i = 0; i < codec->num_nodes; i++, nid++) {
2718 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002719 unsigned int caps = get_wcaps(codec, nid);
2720 int type = get_wcaps_type(caps);
2721
2722 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2723 continue;
2724 adc_nids[nums] = nid;
2725 cap_nids[nums] = nid;
2726 src = nid;
2727 for (;;) {
2728 int n;
2729 type = get_wcaps_type(get_wcaps(codec, src));
2730 if (type == AC_WID_PIN)
2731 break;
2732 if (type == AC_WID_AUD_SEL) {
2733 cap_nids[nums] = src;
2734 break;
2735 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002736 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002737 if (n > 1) {
2738 cap_nids[nums] = src;
2739 break;
2740 } else if (n != 1)
2741 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002742 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2743 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002744 }
2745 if (++nums >= max_nums)
2746 break;
2747 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002748 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002749 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002750 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002751 return nums;
2752}
2753
Takashi Iwai05f5f472009-08-25 13:10:18 +02002754/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002755static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002756{
2757 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002758 const struct auto_pin_cfg *cfg = &spec->autocfg;
2759 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002760 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002761 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002762 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002763 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002764
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002765 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002766 if (num_adcs < 0)
2767 return 0;
2768
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002769 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002770 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002771 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002772
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002773 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002774 if (!alc_is_input_pin(codec, pin))
2775 continue;
2776
David Henningsson5322bf22011-01-05 11:03:56 +01002777 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002778 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2779 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002780 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002781 type_idx++;
2782 else
2783 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002784 prev_label = label;
2785
Takashi Iwai05f5f472009-08-25 13:10:18 +02002786 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002787 if (is_reachable_path(codec, pin, mixer)) {
2788 err = new_analog_input(codec, pin,
2789 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002790 if (err < 0)
2791 return err;
2792 }
2793 }
2794
Takashi Iwaib7821702011-07-06 15:12:46 +02002795 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002796 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002797 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002798 if (idx >= 0) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002799 err = new_capture_source(codec, c, pin, idx, label);
2800 if (err < 0)
2801 return err;
Takashi Iwaib7821702011-07-06 15:12:46 +02002802 break;
2803 }
2804 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002805 }
Takashi Iwai21268962011-07-07 15:01:13 +02002806
2807 spec->num_mux_defs = 1;
2808 spec->input_mux = imux;
2809
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002810 return 0;
2811}
2812
Takashi Iwai24de1832011-11-07 17:13:39 +01002813/* create a shared input with the headphone out */
2814static int alc_auto_create_shared_input(struct hda_codec *codec)
2815{
2816 struct alc_spec *spec = codec->spec;
2817 struct auto_pin_cfg *cfg = &spec->autocfg;
2818 unsigned int defcfg;
2819 hda_nid_t nid;
2820
2821 /* only one internal input pin? */
2822 if (cfg->num_inputs != 1)
2823 return 0;
2824 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2825 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2826 return 0;
2827
2828 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2829 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2830 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2831 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2832 else
2833 return 0; /* both not available */
2834
2835 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2836 return 0; /* no input */
2837
2838 cfg->inputs[1].pin = nid;
2839 cfg->inputs[1].type = AUTO_PIN_MIC;
2840 cfg->num_inputs = 2;
2841 spec->shared_mic_hp = 1;
2842 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2843 return 0;
2844}
2845
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002846static int get_pin_type(int line_out_type)
2847{
2848 if (line_out_type == AUTO_PIN_HP_OUT)
2849 return PIN_HP;
2850 else
2851 return PIN_OUT;
2852}
2853
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002854static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002855{
2856 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002857 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002858 int i;
2859
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002860 for (i = 0; i < cfg->num_inputs; i++) {
2861 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002862 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002863 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002864 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002865 snd_hda_codec_write(codec, nid, 0,
2866 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002867 AMP_OUT_MUTE);
2868 }
2869 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002870
2871 /* mute all loopback inputs */
2872 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002873 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002874 for (i = 0; i < nums; i++)
2875 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2876 AC_VERB_SET_AMP_GAIN_MUTE,
2877 AMP_IN_MUTE(i));
2878 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002879}
2880
Takashi Iwai185d99f2012-02-16 18:39:45 +01002881static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2882{
2883 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002884 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002885
Takashi Iwaic9967f12012-12-14 16:39:22 +01002886 for (i = 0; i < spec->paths.used; i++) {
2887 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002888 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002889 return true;
2890 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002891 return false;
2892}
2893
Takashi Iwai463419d2012-12-05 14:17:37 +01002894/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002895static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2896 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002897{
2898 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002899 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002900 int i;
2901
2902 for (i = 0; i < spec->num_all_dacs; i++) {
2903 hda_nid_t nid = spec->all_dacs[i];
2904 if (!nid || alc_is_dac_already_used(codec, nid))
2905 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002906 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2907 if (is_digital != cap_digital)
2908 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002909 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002910 return nid;
2911 }
2912 return 0;
2913}
2914
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002915/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002916static bool __parse_nid_path(struct hda_codec *codec,
2917 hda_nid_t from_nid, hda_nid_t to_nid,
2918 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002919{
2920 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002921 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002922 int i, nums;
2923
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002924 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002925 if (!with_aa_mix)
2926 return false;
2927 with_aa_mix = 2; /* mark aa-mix is included */
2928 }
2929
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002930 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002931 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002932 if (conn[i] != from_nid) {
2933 /* special case: when from_nid is 0,
2934 * try to find an empty DAC
2935 */
2936 if (from_nid ||
2937 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2938 alc_is_dac_already_used(codec, conn[i]))
2939 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002940 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002941 /* aa-mix is requested but not included? */
2942 if (!(spec->mixer_nid && with_aa_mix == 1))
2943 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002944 }
2945 if (depth >= MAX_NID_PATH_DEPTH)
2946 return false;
2947 for (i = 0; i < nums; i++) {
2948 unsigned int type;
2949 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002950 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2951 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002952 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002953 if (__parse_nid_path(codec, from_nid, conn[i],
2954 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002955 goto found;
2956 }
2957 return false;
2958
2959 found:
2960 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002961 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002962 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002963 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002964 path->depth++;
2965 return true;
2966}
2967
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002968/* parse the widget path from the given nid to the target nid;
2969 * when @from_nid is 0, try to find an empty DAC;
2970 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2971 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2972 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002973 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002974static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2975 hda_nid_t to_nid, int with_aa_mix,
2976 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002977{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002978 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2979 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002980 path->depth++;
2981#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002982 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002983 path->depth, path->path[0], path->path[1],
2984 path->path[2], path->path[3], path->path[4]);
2985#endif
2986 return true;
2987 }
2988 return false;
2989}
2990
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002991static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2992{
Takashi Iwai140547e2012-02-16 17:23:46 +01002993 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002994 int i;
2995 hda_nid_t nid_found = 0;
2996
2997 for (i = 0; i < spec->num_all_dacs; i++) {
2998 hda_nid_t nid = spec->all_dacs[i];
2999 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003000 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01003001 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003002 if (nid_found)
3003 return 0;
3004 nid_found = nid;
3005 }
3006 }
3007 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003008}
3009
Takashi Iwaiba8111272012-12-06 18:06:23 +01003010static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003011{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003012 struct alc_spec *spec = codec->spec;
3013 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003014
Takashi Iwaic9967f12012-12-14 16:39:22 +01003015 for (i = 0; i < spec->paths.used; i++) {
3016 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003017 if (path->ctls[type] == val)
3018 return true;
3019 }
3020 return false;
3021}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003022
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003023/* badness definition */
3024enum {
3025 /* No primary DAC is found for the main output */
3026 BAD_NO_PRIMARY_DAC = 0x10000,
3027 /* No DAC is found for the extra output */
3028 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003029 /* No possible multi-ios */
3030 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003031 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003032 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003033 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003034 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003035 /* Primary DAC shared with main surrounds */
3036 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003037 /* Primary DAC shared with main CLFE */
3038 BAD_SHARED_CLFE = 0x10,
3039 /* Primary DAC shared with extra surrounds */
3040 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003041 /* Volume widget is shared */
3042 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003043};
3044
3045static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003046 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003047static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003048 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003049
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003050static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3051 hda_nid_t dac)
3052{
3053 struct alc_spec *spec = codec->spec;
3054 struct nid_path *path;
3055
Takashi Iwaic9967f12012-12-14 16:39:22 +01003056 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003057 if (!path)
3058 return false;
3059 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003060 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003061 return true;
3062 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01003063 spec->paths.used--;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003064 return false;
3065}
3066
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003067/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003068 * passing 0 to either @pin or @dac behaves as a wildcard
3069 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003070static struct nid_path *
3071get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01003072{
3073 struct alc_spec *spec = codec->spec;
3074 int i;
3075
Takashi Iwaic9967f12012-12-14 16:39:22 +01003076 for (i = 0; i < spec->paths.used; i++) {
3077 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003078 if (path->depth <= 0)
3079 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003080 if ((!from_nid || path->path[0] == from_nid) &&
3081 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01003082 return path;
3083 }
3084 return NULL;
3085}
3086
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003087/* look for widgets in the path between the given NIDs appropriate for
3088 * volume and mute controls, and assign the values to ctls[].
3089 *
3090 * When no appropriate widget is found in the path, the badness value
3091 * is incremented depending on the situation. The function returns the
3092 * total badness for both volume and mute controls.
3093 */
3094static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3095 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003096{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003097 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003098 hda_nid_t nid;
3099 unsigned int val;
3100 int badness = 0;
3101
Takashi Iwaiba8111272012-12-06 18:06:23 +01003102 if (!path)
3103 return BAD_SHARED_VOL * 2;
3104 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003105 if (nid) {
3106 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003107 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003108 badness += BAD_SHARED_VOL;
3109 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003110 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003111 } else
3112 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003113 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003114 if (nid) {
3115 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003116 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3117 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003118 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3119 else
3120 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003121 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003122 badness += BAD_SHARED_VOL;
3123 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003124 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003125 } else
3126 badness += BAD_SHARED_VOL;
3127 return badness;
3128}
3129
Takashi Iwaidc31b582012-02-17 17:27:53 +01003130struct badness_table {
3131 int no_primary_dac; /* no primary DAC */
3132 int no_dac; /* no secondary DACs */
3133 int shared_primary; /* primary DAC is shared with main output */
3134 int shared_surr; /* secondary DAC shared with main or primary */
3135 int shared_clfe; /* third DAC shared with main or primary */
3136 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3137};
3138
3139static struct badness_table main_out_badness = {
3140 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3141 .no_dac = BAD_NO_DAC,
3142 .shared_primary = BAD_NO_PRIMARY_DAC,
3143 .shared_surr = BAD_SHARED_SURROUND,
3144 .shared_clfe = BAD_SHARED_CLFE,
3145 .shared_surr_main = BAD_SHARED_SURROUND,
3146};
3147
3148static struct badness_table extra_out_badness = {
3149 .no_primary_dac = BAD_NO_DAC,
3150 .no_dac = BAD_NO_DAC,
3151 .shared_primary = BAD_NO_EXTRA_DAC,
3152 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3153 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3154 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3155};
3156
3157/* try to assign DACs to pins and return the resultant badness */
3158static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3159 const hda_nid_t *pins, hda_nid_t *dacs,
3160 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003161{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003162 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003163 struct auto_pin_cfg *cfg = &spec->autocfg;
3164 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003165 int badness = 0;
3166 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003167
Takashi Iwai185d99f2012-02-16 18:39:45 +01003168 if (!num_outs)
3169 return 0;
3170
Takashi Iwaidc31b582012-02-17 17:27:53 +01003171 for (i = 0; i < num_outs; i++) {
3172 hda_nid_t pin = pins[i];
3173 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003174 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003175 if (!dacs[i] && !i) {
3176 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003177 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003178 dacs[0] = dacs[j];
3179 dacs[j] = 0;
3180 break;
3181 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003182 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003183 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003184 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003185 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003186 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003187 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003188 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003189 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003190 dac = spec->private_dac_nids[i];
3191 if (dac) {
3192 if (!i)
3193 badness += bad->shared_primary;
3194 else if (i == 1)
3195 badness += bad->shared_surr;
3196 else
3197 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003198 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003199 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003200 badness += bad->shared_surr_main;
3201 } else if (!i)
3202 badness += bad->no_primary_dac;
3203 else
3204 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003205 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003206 if (!add_new_out_path(codec, pin, dac))
3207 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003208 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003209 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003210 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003211
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003212 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003213}
3214
3215static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003216 hda_nid_t reference_pin,
3217 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003218
Takashi Iwai185d99f2012-02-16 18:39:45 +01003219static bool alc_map_singles(struct hda_codec *codec, int outs,
3220 const hda_nid_t *pins, hda_nid_t *dacs)
3221{
3222 int i;
3223 bool found = false;
3224 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003225 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003226 if (dacs[i])
3227 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003228 dac = get_dac_if_single(codec, pins[i]);
3229 if (!dac)
3230 continue;
3231 if (add_new_out_path(codec, pins[i], dac)) {
3232 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003233 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003234 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003235 }
3236 return found;
3237}
3238
Takashi Iwai7085ec12009-10-02 09:03:58 +02003239/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003240static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003241 bool fill_hardwired,
3242 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003243{
3244 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003245 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003246 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003247
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003248 /* set num_dacs once to full for alc_auto_look_for_dac() */
3249 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003250 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003251 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3252 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3253 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003254 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003255 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003256 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003257
3258 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003259 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003260 bool mapped;
3261 do {
3262 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003263 cfg->line_out_pins,
3264 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003265 mapped |= alc_map_singles(codec, cfg->hp_outs,
3266 cfg->hp_pins,
3267 spec->multiout.hp_out_nid);
3268 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3269 cfg->speaker_pins,
3270 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003271 if (fill_mio_first && cfg->line_outs == 1 &&
3272 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3273 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3274 if (!err)
3275 mapped = true;
3276 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003277 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003278 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003279
Takashi Iwaidc31b582012-02-17 17:27:53 +01003280 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3281 spec->private_dac_nids,
3282 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003283
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003284 /* re-count num_dacs and squash invalid entries */
3285 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003286 for (i = 0; i < cfg->line_outs; i++) {
3287 if (spec->private_dac_nids[i])
3288 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003289 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003290 memmove(spec->private_dac_nids + i,
3291 spec->private_dac_nids + i + 1,
3292 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003293 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3294 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003295 }
3296
Takashi Iwai276dd702012-02-17 16:17:03 +01003297 if (fill_mio_first &&
3298 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003299 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003300 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003301 if (err < 0)
3302 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003303 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003304 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003305
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003306 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003307 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3308 spec->multiout.hp_out_nid,
3309 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003310 if (err < 0)
3311 return err;
3312 badness += err;
3313 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003314 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003315 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3316 cfg->speaker_pins,
3317 spec->multiout.extra_out_nid,
3318 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003319 if (err < 0)
3320 return err;
3321 badness += err;
3322 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003323 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3324 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
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->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3330 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003331 int offset = 0;
3332 if (cfg->line_outs >= 3)
3333 offset = 1;
3334 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3335 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003336 if (err < 0)
3337 return err;
3338 badness += err;
3339 }
3340
3341 if (spec->multi_ios == 2) {
3342 for (i = 0; i < 2; i++)
3343 spec->private_dac_nids[spec->multiout.num_dacs++] =
3344 spec->multi_io[i].dac;
3345 spec->ext_channel_count = 2;
3346 } else if (spec->multi_ios) {
3347 spec->multi_ios = 0;
3348 badness += BAD_MULTI_IO;
3349 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003350
3351 return badness;
3352}
3353
3354#define DEBUG_BADNESS
3355
3356#ifdef DEBUG_BADNESS
3357#define debug_badness snd_printdd
3358#else
3359#define debug_badness(...)
3360#endif
3361
3362static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3363{
3364 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3365 cfg->line_out_pins[0], cfg->line_out_pins[1],
3366 cfg->line_out_pins[2], cfg->line_out_pins[2],
3367 spec->multiout.dac_nids[0],
3368 spec->multiout.dac_nids[1],
3369 spec->multiout.dac_nids[2],
3370 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003371 if (spec->multi_ios > 0)
3372 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3373 spec->multi_ios,
3374 spec->multi_io[0].pin, spec->multi_io[1].pin,
3375 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003376 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3377 cfg->hp_pins[0], cfg->hp_pins[1],
3378 cfg->hp_pins[2], cfg->hp_pins[2],
3379 spec->multiout.hp_out_nid[0],
3380 spec->multiout.hp_out_nid[1],
3381 spec->multiout.hp_out_nid[2],
3382 spec->multiout.hp_out_nid[3]);
3383 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3384 cfg->speaker_pins[0], cfg->speaker_pins[1],
3385 cfg->speaker_pins[2], cfg->speaker_pins[3],
3386 spec->multiout.extra_out_nid[0],
3387 spec->multiout.extra_out_nid[1],
3388 spec->multiout.extra_out_nid[2],
3389 spec->multiout.extra_out_nid[3]);
3390}
3391
Takashi Iwai463419d2012-12-05 14:17:37 +01003392/* find all available DACs of the codec */
3393static void alc_fill_all_nids(struct hda_codec *codec)
3394{
3395 struct alc_spec *spec = codec->spec;
3396 int i;
3397 hda_nid_t nid = codec->start_nid;
3398
3399 spec->num_all_dacs = 0;
3400 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3401 for (i = 0; i < codec->num_nodes; i++, nid++) {
3402 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3403 continue;
3404 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3405 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3406 break;
3407 }
3408 spec->all_dacs[spec->num_all_dacs++] = nid;
3409 }
3410}
3411
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003412static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3413{
3414 struct alc_spec *spec = codec->spec;
3415 struct auto_pin_cfg *cfg = &spec->autocfg;
3416 struct auto_pin_cfg *best_cfg;
3417 int best_badness = INT_MAX;
3418 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003419 bool fill_hardwired = true, fill_mio_first = true;
3420 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003421 bool hp_spk_swapped = false;
3422
Takashi Iwai463419d2012-12-05 14:17:37 +01003423 alc_fill_all_nids(codec);
3424
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003425 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3426 if (!best_cfg)
3427 return -ENOMEM;
3428 *best_cfg = *cfg;
3429
3430 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003431 badness = fill_and_eval_dacs(codec, fill_hardwired,
3432 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003433 if (badness < 0) {
3434 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003435 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003436 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003437 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3438 cfg->line_out_type, fill_hardwired, fill_mio_first,
3439 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003440 debug_show_configs(spec, cfg);
3441 if (badness < best_badness) {
3442 best_badness = badness;
3443 *best_cfg = *cfg;
3444 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003445 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003446 }
3447 if (!badness)
3448 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003449 fill_mio_first = !fill_mio_first;
3450 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003451 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003452 fill_hardwired = !fill_hardwired;
3453 if (!fill_hardwired)
3454 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003455 if (hp_spk_swapped)
3456 break;
3457 hp_spk_swapped = true;
3458 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003459 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3460 cfg->hp_outs = cfg->line_outs;
3461 memcpy(cfg->hp_pins, cfg->line_out_pins,
3462 sizeof(cfg->hp_pins));
3463 cfg->line_outs = cfg->speaker_outs;
3464 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3465 sizeof(cfg->speaker_pins));
3466 cfg->speaker_outs = 0;
3467 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3468 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003469 fill_hardwired = true;
3470 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003471 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003472 if (cfg->hp_outs > 0 &&
3473 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3474 cfg->speaker_outs = cfg->line_outs;
3475 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3476 sizeof(cfg->speaker_pins));
3477 cfg->line_outs = cfg->hp_outs;
3478 memcpy(cfg->line_out_pins, cfg->hp_pins,
3479 sizeof(cfg->hp_pins));
3480 cfg->hp_outs = 0;
3481 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3482 cfg->line_out_type = AUTO_PIN_HP_OUT;
3483 fill_hardwired = true;
3484 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003485 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003486 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003487 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003488
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003489 if (badness) {
3490 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003491 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003492 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003493 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3494 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003495 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003496
Takashi Iwaiba8111272012-12-06 18:06:23 +01003497 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003498 struct nid_path *path = get_nid_path(codec,
3499 spec->multiout.dac_nids[0],
3500 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003501 if (path)
3502 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3503 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003504
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003505 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003506 return 0;
3507}
3508
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003509/* replace the channels in the composed amp value with the given number */
3510static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3511{
3512 val &= ~(0x3U << 16);
3513 val |= chs << 16;
3514 return val;
3515}
3516
Takashi Iwai343a04b2011-07-06 14:28:39 +02003517static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003518 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003519 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003520 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003521{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003522 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003523 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003524 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003525 val = path->ctls[NID_PATH_VOL_CTL];
3526 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003527 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003528 val = amp_val_replace_channels(val, chs);
3529 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3530}
3531
3532/* return the channel bits suitable for the given path->ctls[] */
3533static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3534 int type)
3535{
3536 int chs = 1; /* mono (left only) */
3537 if (path) {
3538 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3539 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3540 chs = 3; /* stereo */
3541 }
3542 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003543}
3544
Takashi Iwaie29d3772011-11-14 17:13:23 +01003545static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3546 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003547 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003548{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003549 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3550 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003551}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003552
3553/* create a mute-switch for the given mixer widget;
3554 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3555 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003556static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003557 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003558 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003559 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003560{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003561 unsigned int val;
3562 int type = ALC_CTL_WIDGET_MUTE;
3563
3564 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003565 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003566 val = path->ctls[NID_PATH_MUTE_CTL];
3567 if (!val)
3568 return 0;
3569 val = amp_val_replace_channels(val, chs);
3570 if (get_amp_direction_(val) == HDA_INPUT) {
3571 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003572 int nums = snd_hda_get_num_conns(codec, nid);
3573 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003574 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003575 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003576 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003577 }
3578 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003579}
3580
Takashi Iwaie29d3772011-11-14 17:13:23 +01003581static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003582 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003583{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003584 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3585 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003586}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003587
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003588static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003589 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003590{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003591 int i;
3592
3593 for (i = path->depth - 1; i >= 0; i--) {
3594 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3595 return path->path[i];
3596 if (i != path->depth - 1 && i != 0 &&
3597 nid_has_mute(codec, path->path[i], HDA_INPUT))
3598 return path->path[i];
3599 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003600 return 0;
3601}
3602
3603static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003604 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003605{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003606 int i;
3607
3608 for (i = path->depth - 1; i >= 0; i--) {
3609 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3610 return path->path[i];
3611 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003612 return 0;
3613}
3614
Takashi Iwai7085ec12009-10-02 09:03:58 +02003615/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003616static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003617 const struct auto_pin_cfg *cfg)
3618{
3619 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003620 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003621
Takashi Iwaice764ab2011-04-27 16:35:23 +02003622 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003623 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003624 noutputs += spec->multi_ios;
3625
3626 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003627 const char *name;
3628 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003629 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003630 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003631
3632 dac = spec->multiout.dac_nids[i];
3633 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003634 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003635 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003636 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003637 index = 0;
3638 name = channel_name[i];
3639 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003640 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003641 name = alc_get_line_out_pfx(spec, i, true, &index);
3642 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003643
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003644 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003645 if (!path)
3646 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003647 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003648 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003649 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003650 if (err < 0)
3651 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003652 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003653 if (err < 0)
3654 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003655 err = alc_auto_add_sw_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_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003659 if (err < 0)
3660 return err;
3661 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003662 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003663 if (err < 0)
3664 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003665 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003666 if (err < 0)
3667 return err;
3668 }
3669 }
3670 return 0;
3671}
3672
Takashi Iwai343a04b2011-07-06 14:28:39 +02003673static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003674 hda_nid_t dac, const char *pfx,
3675 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003676{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003677 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003678 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003679
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003680 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003681 if (!path)
3682 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003683 /* bind volume control will be created in the case of dac = 0 */
3684 if (dac) {
3685 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3686 if (err < 0)
3687 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003688 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003689 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003690 if (err < 0)
3691 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003692 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003693}
3694
Takashi Iwai23c09b02011-08-19 09:05:35 +02003695static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3696 unsigned int nums,
3697 struct hda_ctl_ops *ops)
3698{
3699 struct alc_spec *spec = codec->spec;
3700 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003701 ctlp = snd_array_new(&spec->bind_ctls);
3702 if (!ctlp)
3703 return NULL;
3704 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3705 *ctlp = ctl;
3706 if (ctl)
3707 ctl->ops = ops;
3708 return ctl;
3709}
3710
3711/* add playback controls for speaker and HP outputs */
3712static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3713 const hda_nid_t *pins,
3714 const hda_nid_t *dacs,
3715 const char *pfx)
3716{
3717 struct alc_spec *spec = codec->spec;
3718 struct hda_bind_ctls *ctl;
3719 char name[32];
3720 int i, n, err;
3721
3722 if (!num_pins || !pins[0])
3723 return 0;
3724
Takashi Iwai527e4d72011-10-27 16:33:27 +02003725 if (num_pins == 1) {
3726 hda_nid_t dac = *dacs;
3727 if (!dac)
3728 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003729 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003730 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003731
Takashi Iwai23c09b02011-08-19 09:05:35 +02003732 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003733 hda_nid_t dac;
3734 if (dacs[num_pins - 1])
3735 dac = dacs[i]; /* with individual volumes */
3736 else
3737 dac = 0;
3738 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3739 err = alc_auto_create_extra_out(codec, pins[i], dac,
3740 "Bass Speaker", 0);
3741 } else if (num_pins >= 3) {
3742 snprintf(name, sizeof(name), "%s %s",
3743 pfx, channel_name[i]);
3744 err = alc_auto_create_extra_out(codec, pins[i], dac,
3745 name, 0);
3746 } else {
3747 err = alc_auto_create_extra_out(codec, pins[i], dac,
3748 pfx, i);
3749 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003750 if (err < 0)
3751 return err;
3752 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003753 if (dacs[num_pins - 1])
3754 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003755
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003756 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003757 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3758 if (!ctl)
3759 return -ENOMEM;
3760 n = 0;
3761 for (i = 0; i < num_pins; i++) {
3762 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003763 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003764 if (!pins[i] || !dacs[i])
3765 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003766 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003767 if (!path)
3768 continue;
3769 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003770 if (vol)
3771 ctl->values[n++] =
3772 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3773 }
3774 if (n) {
3775 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3776 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3777 if (err < 0)
3778 return err;
3779 }
3780 return 0;
3781}
3782
Takashi Iwai343a04b2011-07-06 14:28:39 +02003783static int alc_auto_create_hp_out(struct hda_codec *codec)
3784{
3785 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003786 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3787 spec->autocfg.hp_pins,
3788 spec->multiout.hp_out_nid,
3789 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003790}
3791
3792static int alc_auto_create_speaker_out(struct hda_codec *codec)
3793{
3794 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003795 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3796 spec->autocfg.speaker_pins,
3797 spec->multiout.extra_out_nid,
3798 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003799}
3800
Takashi Iwai130e5f02012-12-14 16:09:29 +01003801/* check whether a control with the given (nid, dir, idx) was assigned */
3802static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3803 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003804{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003805 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003806 int i, type;
3807
3808 for (i = 0; i < spec->paths.used; i++) {
3809 struct nid_path *p = snd_array_elem(&spec->paths, i);
3810 if (p->depth <= 0)
3811 continue;
3812 for (type = 0; type < 2; type++) {
3813 unsigned int val = p->ctls[type];
3814 if (get_amp_nid_(val) == nid &&
3815 get_amp_direction_(val) == dir &&
3816 get_amp_index_(val) == idx)
3817 return true;
3818 }
3819 }
3820 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003821}
3822
3823/* can have the amp-in capability? */
3824static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3825{
3826 hda_nid_t nid = path->path[idx];
3827 unsigned int caps = get_wcaps(codec, nid);
3828 unsigned int type = get_wcaps_type(caps);
3829
3830 if (!(caps & AC_WCAP_IN_AMP))
3831 return false;
3832 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3833 return false;
3834 return true;
3835}
3836
3837/* can have the amp-out capability? */
3838static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3839{
3840 hda_nid_t nid = path->path[idx];
3841 unsigned int caps = get_wcaps(codec, nid);
3842 unsigned int type = get_wcaps_type(caps);
3843
3844 if (!(caps & AC_WCAP_OUT_AMP))
3845 return false;
3846 if (type == AC_WID_PIN && !idx) /* only for output pins */
3847 return false;
3848 return true;
3849}
3850
Takashi Iwaic9967f12012-12-14 16:39:22 +01003851/* check whether the given (nid,dir,idx) is active */
3852static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3853 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003854{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003855 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003856 int i, n;
3857
Takashi Iwaic9967f12012-12-14 16:39:22 +01003858 for (n = 0; n < spec->paths.used; n++) {
3859 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003860 if (!path->active)
3861 continue;
3862 for (i = 0; i < path->depth; i++) {
3863 if (path->path[i] == nid) {
3864 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3865 return true;
3866 break;
3867 }
3868 }
3869 }
3870 return false;
3871}
3872
Takashi Iwai130e5f02012-12-14 16:09:29 +01003873/* get the default amp value for the target state */
3874static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3875 int dir, bool enable)
3876{
3877 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003878 unsigned int val = 0;
3879
3880 caps = query_amp_caps(codec, nid, dir);
3881 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003882 /* set to 0dB */
3883 if (enable)
3884 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003885 }
3886 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003887 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003888 val |= HDA_AMP_MUTE;
3889 }
3890 return val;
3891}
3892
Takashi Iwai130e5f02012-12-14 16:09:29 +01003893/* initialize the amp value (only at the first time) */
3894static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3895{
3896 int val = get_amp_val_to_activate(codec, nid, dir, false);
3897 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3898}
3899
3900static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3901 int idx, bool enable)
3902{
3903 int val;
3904 if (is_ctl_associated(codec, nid, dir, idx) ||
3905 is_active_nid(codec, nid, dir, idx))
3906 return;
3907 val = get_amp_val_to_activate(codec, nid, dir, enable);
3908 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3909}
3910
3911static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3912 int i, bool enable)
3913{
3914 hda_nid_t nid = path->path[i];
3915 init_amp(codec, nid, HDA_OUTPUT, 0);
3916 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3917}
3918
3919static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
3920 int i, bool enable)
3921{
3922 struct alc_spec *spec = codec->spec;
3923 hda_nid_t conn[16];
3924 int n, nums;
3925 hda_nid_t nid = path->path[i];
3926
3927 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
3928 for (n = 0; n < nums; n++)
3929 init_amp(codec, nid, HDA_INPUT, n);
3930
3931 if (is_ctl_associated(codec, nid, HDA_INPUT, path->idx[i]))
3932 return;
3933
3934 /* here is a little bit tricky in comparison with activate_amp_out();
3935 * when aa-mixer is available, we need to enable the path as well
3936 */
3937 for (n = 0; n < nums; n++) {
3938 if (n != path->idx[i] && conn[n] != spec->mixer_nid)
3939 continue;
3940 activate_amp(codec, nid, HDA_INPUT, n, enable);
3941 }
3942}
3943
3944static void activate_path(struct hda_codec *codec, struct nid_path *path,
3945 bool enable)
3946{
3947 int i;
3948
3949 if (path->active == enable)
3950 return;
3951
3952 if (!enable)
3953 path->active = false;
3954
3955 for (i = path->depth - 1; i >= 0; i--) {
3956 if (path->multi[i])
3957 snd_hda_codec_write_cache(codec, path->path[i], 0,
3958 AC_VERB_SET_CONNECT_SEL,
3959 path->idx[i]);
3960 if (has_amp_in(codec, path, i))
3961 activate_amp_in(codec, path, i, enable);
3962 if (has_amp_out(codec, path, i))
3963 activate_amp_out(codec, path, i, enable);
3964 }
3965
3966 if (enable)
3967 path->active = true;
3968}
3969
Takashi Iwai78e635c2012-12-10 17:07:16 +01003970/* configure the path from the given dac to the pin as the proper output */
3971static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3972 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003973 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003974{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003975 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003976
Takashi Iwai130e5f02012-12-14 16:09:29 +01003977 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003978 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003979 if (!path)
3980 return;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003981 activate_path(codec, path, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003982}
3983
Takashi Iwai343a04b2011-07-06 14:28:39 +02003984static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003985{
3986 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003987 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003988 int i;
3989
3990 for (i = 0; i <= HDA_SIDE; i++) {
3991 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3992 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003993 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003994 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003995
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003996 }
3997}
3998
Takashi Iwai343a04b2011-07-06 14:28:39 +02003999static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004000{
4001 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004002 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004003 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004004
David Henningsson636030e2011-10-12 19:26:03 +02004005 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004006 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4007 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02004008 pin = spec->autocfg.hp_pins[i];
4009 if (!pin)
4010 break;
4011 dac = spec->multiout.hp_out_nid[i];
4012 if (!dac) {
4013 if (i > 0 && spec->multiout.hp_out_nid[0])
4014 dac = spec->multiout.hp_out_nid[0];
4015 else
4016 dac = spec->multiout.dac_nids[0];
4017 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004018 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004019 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02004020 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004021 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4022 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004023 pin = spec->autocfg.speaker_pins[i];
4024 if (!pin)
4025 break;
4026 dac = spec->multiout.extra_out_nid[i];
4027 if (!dac) {
4028 if (i > 0 && spec->multiout.extra_out_nid[0])
4029 dac = spec->multiout.extra_out_nid[0];
4030 else
4031 dac = spec->multiout.dac_nids[0];
4032 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004033 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004034 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004035}
4036
Takashi Iwai276dd702012-02-17 16:17:03 +01004037/* check whether the given pin can be a multi-io pin */
4038static bool can_be_multiio_pin(struct hda_codec *codec,
4039 unsigned int location, hda_nid_t nid)
4040{
4041 unsigned int defcfg, caps;
4042
4043 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4044 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4045 return false;
4046 if (location && get_defcfg_location(defcfg) != location)
4047 return false;
4048 caps = snd_hda_query_pin_caps(codec, nid);
4049 if (!(caps & AC_PINCAP_OUT))
4050 return false;
4051 return true;
4052}
4053
Takashi Iwaice764ab2011-04-27 16:35:23 +02004054/*
4055 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004056 *
4057 * When hardwired is set, try to fill ony hardwired pins, and returns
4058 * zero if any pins are filled, non-zero if nothing found.
4059 * When hardwired is off, try to fill possible input pins, and returns
4060 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004061 */
4062static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004063 hda_nid_t reference_pin,
4064 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004065{
4066 struct alc_spec *spec = codec->spec;
4067 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004068 int type, i, j, dacs, num_pins, old_pins;
4069 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4070 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004071 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004072
Takashi Iwai276dd702012-02-17 16:17:03 +01004073 old_pins = spec->multi_ios;
4074 if (old_pins >= 2)
4075 goto end_fill;
4076
4077 num_pins = 0;
4078 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4079 for (i = 0; i < cfg->num_inputs; i++) {
4080 if (cfg->inputs[i].type != type)
4081 continue;
4082 if (can_be_multiio_pin(codec, location,
4083 cfg->inputs[i].pin))
4084 num_pins++;
4085 }
4086 }
4087 if (num_pins < 2)
4088 goto end_fill;
4089
Takashi Iwai07b18f62011-11-10 15:42:54 +01004090 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004091 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4092 for (i = 0; i < cfg->num_inputs; i++) {
4093 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004094 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004095
Takashi Iwaice764ab2011-04-27 16:35:23 +02004096 if (cfg->inputs[i].type != type)
4097 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004098 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004099 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004100 for (j = 0; j < spec->multi_ios; j++) {
4101 if (nid == spec->multi_io[j].pin)
4102 break;
4103 }
4104 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004105 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004106
4107 if (offset && offset + spec->multi_ios < dacs) {
4108 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004109 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004110 dac = 0;
4111 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004112 if (hardwired)
4113 dac = get_dac_if_single(codec, nid);
4114 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004115 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004116 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004117 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004118 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004119 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004120 if (!add_new_out_path(codec, nid, dac)) {
4121 badness++;
4122 continue;
4123 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004124 spec->multi_io[spec->multi_ios].pin = nid;
4125 spec->multi_io[spec->multi_ios].dac = dac;
4126 spec->multi_ios++;
4127 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004128 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004129 }
4130 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004131 end_fill:
4132 if (badness)
4133 badness = BAD_MULTI_IO;
4134 if (old_pins == spec->multi_ios) {
4135 if (hardwired)
4136 return 1; /* nothing found */
4137 else
4138 return badness; /* no badness if nothing found */
4139 }
4140 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004141 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004142 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004143 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004144 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004145 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004146
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004147 /* assign volume and mute controls */
4148 for (i = old_pins; i < spec->multi_ios; i++)
4149 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4150 spec->multi_io[i].dac);
4151
4152 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004153}
4154
4155static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4156 struct snd_ctl_elem_info *uinfo)
4157{
4158 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4159 struct alc_spec *spec = codec->spec;
4160
4161 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4162 uinfo->count = 1;
4163 uinfo->value.enumerated.items = spec->multi_ios + 1;
4164 if (uinfo->value.enumerated.item > spec->multi_ios)
4165 uinfo->value.enumerated.item = spec->multi_ios;
4166 sprintf(uinfo->value.enumerated.name, "%dch",
4167 (uinfo->value.enumerated.item + 1) * 2);
4168 return 0;
4169}
4170
4171static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4172 struct snd_ctl_elem_value *ucontrol)
4173{
4174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4175 struct alc_spec *spec = codec->spec;
4176 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4177 return 0;
4178}
4179
4180static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4181{
4182 struct alc_spec *spec = codec->spec;
4183 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004184 struct nid_path *path;
4185
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004186 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004187 if (!path)
4188 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004189
4190 if (!spec->multi_io[idx].ctl_in)
4191 spec->multi_io[idx].ctl_in =
Takashi Iwai130e5f02012-12-14 16:09:29 +01004192 snd_hda_codec_update_cache(codec, nid, 0,
Takashi Iwaice764ab2011-04-27 16:35:23 +02004193 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004194
Takashi Iwaice764ab2011-04-27 16:35:23 +02004195 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004196 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004197 activate_path(codec, path, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004198 } else {
Takashi Iwai130e5f02012-12-14 16:09:29 +01004199 activate_path(codec, path, false);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004200 snd_hda_set_pin_ctl_cache(codec, nid,
4201 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004202 }
4203 return 0;
4204}
4205
4206static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4207 struct snd_ctl_elem_value *ucontrol)
4208{
4209 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4210 struct alc_spec *spec = codec->spec;
4211 int i, ch;
4212
4213 ch = ucontrol->value.enumerated.item[0];
4214 if (ch < 0 || ch > spec->multi_ios)
4215 return -EINVAL;
4216 if (ch == (spec->ext_channel_count - 1) / 2)
4217 return 0;
4218 spec->ext_channel_count = (ch + 1) * 2;
4219 for (i = 0; i < spec->multi_ios; i++)
4220 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004221 spec->multiout.max_channels = max(spec->ext_channel_count,
4222 spec->const_channel_count);
4223 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004224 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004225 return 1;
4226}
4227
Takashi Iwaia9111322011-05-02 11:30:18 +02004228static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004229 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4230 .name = "Channel Mode",
4231 .info = alc_auto_ch_mode_info,
4232 .get = alc_auto_ch_mode_get,
4233 .put = alc_auto_ch_mode_put,
4234};
4235
Takashi Iwai23c09b02011-08-19 09:05:35 +02004236static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004237{
4238 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004239
Takashi Iwaic2674682011-08-24 17:57:44 +02004240 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004241 if (!alc_kcontrol_new(spec, "Channel Mode",
4242 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004243 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004244 }
4245 return 0;
4246}
4247
Takashi Iwai1d045db2011-07-07 18:23:21 +02004248/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4249 * active input pins
4250 */
4251static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4252{
4253 struct alc_spec *spec = codec->spec;
4254 const struct hda_input_mux *imux;
4255 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4256 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4257 int i, n, nums;
4258
4259 imux = spec->input_mux;
4260 if (!imux)
4261 return;
4262 if (spec->dyn_adc_switch)
4263 return;
4264
Takashi Iwai26acaf02012-03-22 14:36:50 +01004265 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004266 nums = 0;
4267 for (n = 0; n < spec->num_adc_nids; n++) {
4268 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004269 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004270 for (i = 0; i < imux->num_items; i++) {
4271 hda_nid_t pin = spec->imux_pins[i];
4272 if (pin) {
4273 if (get_connection_index(codec, cap, pin) < 0)
4274 break;
4275 } else if (num_conns <= imux->items[i].index)
4276 break;
4277 }
4278 if (i >= imux->num_items) {
4279 adc_nids[nums] = spec->private_adc_nids[n];
4280 capsrc_nids[nums++] = cap;
4281 }
4282 }
4283 if (!nums) {
4284 /* check whether ADC-switch is possible */
4285 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004286 if (spec->shared_mic_hp) {
4287 spec->shared_mic_hp = 0;
4288 spec->private_imux[0].num_items = 1;
4289 goto again;
4290 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004291 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4292 " using fallback 0x%x\n",
4293 codec->chip_name, spec->private_adc_nids[0]);
4294 spec->num_adc_nids = 1;
4295 spec->auto_mic = 0;
4296 return;
4297 }
4298 } else if (nums != spec->num_adc_nids) {
4299 memcpy(spec->private_adc_nids, adc_nids,
4300 nums * sizeof(hda_nid_t));
4301 memcpy(spec->private_capsrc_nids, capsrc_nids,
4302 nums * sizeof(hda_nid_t));
4303 spec->num_adc_nids = nums;
4304 }
4305
4306 if (spec->auto_mic)
4307 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004308 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004309 spec->num_adc_nids = 1; /* reduce to a single ADC */
4310}
4311
4312/*
4313 * initialize ADC paths
4314 */
4315static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4316{
4317 struct alc_spec *spec = codec->spec;
4318 hda_nid_t nid;
4319
4320 nid = spec->adc_nids[adc_idx];
4321 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004322 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004323 snd_hda_codec_write(codec, nid, 0,
4324 AC_VERB_SET_AMP_GAIN_MUTE,
4325 AMP_IN_MUTE(0));
4326 return;
4327 }
4328 if (!spec->capsrc_nids)
4329 return;
4330 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004331 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004332 snd_hda_codec_write(codec, nid, 0,
4333 AC_VERB_SET_AMP_GAIN_MUTE,
4334 AMP_OUT_MUTE);
4335}
4336
4337static void alc_auto_init_input_src(struct hda_codec *codec)
4338{
4339 struct alc_spec *spec = codec->spec;
4340 int c, nums;
4341
4342 for (c = 0; c < spec->num_adc_nids; c++)
4343 alc_auto_init_adc(codec, c);
4344 if (spec->dyn_adc_switch)
4345 nums = 1;
4346 else
4347 nums = spec->num_adc_nids;
4348 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004349 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004350}
4351
4352/* add mic boosts if needed */
4353static int alc_auto_add_mic_boost(struct hda_codec *codec)
4354{
4355 struct alc_spec *spec = codec->spec;
4356 struct auto_pin_cfg *cfg = &spec->autocfg;
4357 int i, err;
4358 int type_idx = 0;
4359 hda_nid_t nid;
4360 const char *prev_label = NULL;
4361
4362 for (i = 0; i < cfg->num_inputs; i++) {
4363 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4364 break;
4365 nid = cfg->inputs[i].pin;
4366 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4367 const char *label;
4368 char boost_label[32];
4369
4370 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004371 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4372 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004373 if (prev_label && !strcmp(label, prev_label))
4374 type_idx++;
4375 else
4376 type_idx = 0;
4377 prev_label = label;
4378
4379 snprintf(boost_label, sizeof(boost_label),
4380 "%s Boost Volume", label);
4381 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4382 boost_label, type_idx,
4383 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4384 if (err < 0)
4385 return err;
4386 }
4387 }
4388 return 0;
4389}
4390
4391/* select or unmute the given capsrc route */
4392static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4393 int idx)
4394{
4395 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4396 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4397 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004398 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004399 snd_hda_codec_write_cache(codec, cap, 0,
4400 AC_VERB_SET_CONNECT_SEL, idx);
4401 }
4402}
4403
4404/* set the default connection to that pin */
4405static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4406{
4407 struct alc_spec *spec = codec->spec;
4408 int i;
4409
4410 if (!pin)
4411 return 0;
4412 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004413 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004414 int idx;
4415
4416 idx = get_connection_index(codec, cap, pin);
4417 if (idx < 0)
4418 continue;
4419 select_or_unmute_capsrc(codec, cap, idx);
4420 return i; /* return the found index */
4421 }
4422 return -1; /* not found */
4423}
4424
4425/* initialize some special cases for input sources */
4426static void alc_init_special_input_src(struct hda_codec *codec)
4427{
4428 struct alc_spec *spec = codec->spec;
4429 int i;
4430
4431 for (i = 0; i < spec->autocfg.num_inputs; i++)
4432 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4433}
4434
4435/* assign appropriate capture mixers */
4436static void set_capture_mixer(struct hda_codec *codec)
4437{
4438 struct alc_spec *spec = codec->spec;
4439 static const struct snd_kcontrol_new *caps[2][3] = {
4440 { alc_capture_mixer_nosrc1,
4441 alc_capture_mixer_nosrc2,
4442 alc_capture_mixer_nosrc3 },
4443 { alc_capture_mixer1,
4444 alc_capture_mixer2,
4445 alc_capture_mixer3 },
4446 };
4447
4448 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004449 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004450 if (!spec->capsrc_nids)
4451 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004452 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004453 return; /* no volume in capsrc, too */
4454 spec->vol_in_capsrc = 1;
4455 }
4456
4457 if (spec->num_adc_nids > 0) {
4458 int mux = 0;
4459 int num_adcs = 0;
4460
4461 if (spec->input_mux && spec->input_mux->num_items > 1)
4462 mux = 1;
4463 if (spec->auto_mic) {
4464 num_adcs = 1;
4465 mux = 0;
4466 } else if (spec->dyn_adc_switch)
4467 num_adcs = 1;
4468 if (!num_adcs) {
4469 if (spec->num_adc_nids > 3)
4470 spec->num_adc_nids = 3;
4471 else if (!spec->num_adc_nids)
4472 return;
4473 num_adcs = spec->num_adc_nids;
4474 }
4475 spec->cap_mixer = caps[mux][num_adcs - 1];
4476 }
4477}
4478
4479/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004480 * standard auto-parser initializations
4481 */
4482static void alc_auto_init_std(struct hda_codec *codec)
4483{
Takashi Iwaie4770622011-07-08 11:11:35 +02004484 alc_auto_init_multi_out(codec);
4485 alc_auto_init_extra_out(codec);
4486 alc_auto_init_analog_input(codec);
4487 alc_auto_init_input_src(codec);
4488 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004489 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004490}
4491
4492/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004493 * Digital-beep handlers
4494 */
4495#ifdef CONFIG_SND_HDA_INPUT_BEEP
4496#define set_beep_amp(spec, nid, idx, dir) \
4497 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4498
4499static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004500 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004501 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4502 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4503 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4504 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004505 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004506 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4507 {}
4508};
4509
4510static inline int has_cdefine_beep(struct hda_codec *codec)
4511{
4512 struct alc_spec *spec = codec->spec;
4513 const struct snd_pci_quirk *q;
4514 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4515 if (q)
4516 return q->value;
4517 return spec->cdefine.enable_pcbeep;
4518}
4519#else
4520#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4521#define has_cdefine_beep(codec) 0
4522#endif
4523
4524/* parse the BIOS configuration and set up the alc_spec */
4525/* return 1 if successful, 0 if the proper config is not found,
4526 * or a negative error code
4527 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004528static int alc_parse_auto_config(struct hda_codec *codec,
4529 const hda_nid_t *ignore_nids,
4530 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004531{
4532 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004533 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004534 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004535
Takashi Iwai53c334a2011-08-23 18:27:14 +02004536 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4537 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004538 if (err < 0)
4539 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004540 if (!cfg->line_outs) {
4541 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004542 spec->multiout.max_channels = 2;
4543 spec->no_analog = 1;
4544 goto dig_only;
4545 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004546 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004547 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004548
Takashi Iwaie427c232012-07-29 10:04:08 +02004549 if (!spec->no_primary_hp &&
4550 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004551 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004552 /* use HP as primary out */
4553 cfg->speaker_outs = cfg->line_outs;
4554 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4555 sizeof(cfg->speaker_pins));
4556 cfg->line_outs = cfg->hp_outs;
4557 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4558 cfg->hp_outs = 0;
4559 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4560 cfg->line_out_type = AUTO_PIN_HP_OUT;
4561 }
4562
Takashi Iwai1d045db2011-07-07 18:23:21 +02004563 err = alc_auto_fill_dac_nids(codec);
4564 if (err < 0)
4565 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004566 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004567 if (err < 0)
4568 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004569 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004570 if (err < 0)
4571 return err;
4572 err = alc_auto_create_hp_out(codec);
4573 if (err < 0)
4574 return err;
4575 err = alc_auto_create_speaker_out(codec);
4576 if (err < 0)
4577 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004578 err = alc_auto_create_shared_input(codec);
4579 if (err < 0)
4580 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004581 err = alc_auto_create_input_ctls(codec);
4582 if (err < 0)
4583 return err;
4584
Takashi Iwaib6adb572012-12-03 10:30:58 +01004585 /* check the multiple speaker pins */
4586 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4587 spec->const_channel_count = cfg->line_outs * 2;
4588 else
4589 spec->const_channel_count = cfg->speaker_outs * 2;
4590
4591 if (spec->multi_ios > 0)
4592 spec->multiout.max_channels = max(spec->ext_channel_count,
4593 spec->const_channel_count);
4594 else
4595 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004596
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004597 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004598 alc_auto_parse_digital(codec);
4599
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004600 if (!spec->no_analog)
4601 alc_remove_invalid_adc_nids(codec);
4602
4603 if (ssid_nids)
4604 alc_ssid_check(codec, ssid_nids);
4605
4606 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004607 err = alc_auto_check_switches(codec);
4608 if (err < 0)
4609 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004610 err = alc_auto_add_mic_boost(codec);
4611 if (err < 0)
4612 return err;
4613 }
4614
Takashi Iwai1d045db2011-07-07 18:23:21 +02004615 if (spec->kctls.list)
4616 add_mixer(spec, spec->kctls.list);
4617
Takashi Iwai070cff42012-02-21 12:54:17 +01004618 if (!spec->no_analog && !spec->cap_mixer)
4619 set_capture_mixer(codec);
4620
Takashi Iwai1d045db2011-07-07 18:23:21 +02004621 return 1;
4622}
4623
Takashi Iwai3de95172012-05-07 18:03:15 +02004624/* common preparation job for alc_spec */
4625static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4626{
4627 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4628 int err;
4629
4630 if (!spec)
4631 return -ENOMEM;
4632 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004633 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004634 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004635 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004636 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4637 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004638 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004639
4640 err = alc_codec_rename_from_preset(codec);
4641 if (err < 0) {
4642 kfree(spec);
4643 return err;
4644 }
4645 return 0;
4646}
4647
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004648static int alc880_parse_auto_config(struct hda_codec *codec)
4649{
4650 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004651 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004652 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4653}
4654
Takashi Iwai1d045db2011-07-07 18:23:21 +02004655/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004656 * ALC880 fix-ups
4657 */
4658enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004659 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004660 ALC880_FIXUP_GPIO2,
4661 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004662 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004663 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004664 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004665 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004666 ALC880_FIXUP_VOL_KNOB,
4667 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004668 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004669 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004670 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004671 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004672 ALC880_FIXUP_3ST_BASE,
4673 ALC880_FIXUP_3ST,
4674 ALC880_FIXUP_3ST_DIG,
4675 ALC880_FIXUP_5ST_BASE,
4676 ALC880_FIXUP_5ST,
4677 ALC880_FIXUP_5ST_DIG,
4678 ALC880_FIXUP_6ST_BASE,
4679 ALC880_FIXUP_6ST,
4680 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004681};
4682
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004683/* enable the volume-knob widget support on NID 0x21 */
4684static void alc880_fixup_vol_knob(struct hda_codec *codec,
4685 const struct alc_fixup *fix, int action)
4686{
4687 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004688 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004689}
4690
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004691static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004692 [ALC880_FIXUP_GPIO1] = {
4693 .type = ALC_FIXUP_VERBS,
4694 .v.verbs = alc_gpio1_init_verbs,
4695 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004696 [ALC880_FIXUP_GPIO2] = {
4697 .type = ALC_FIXUP_VERBS,
4698 .v.verbs = alc_gpio2_init_verbs,
4699 },
4700 [ALC880_FIXUP_MEDION_RIM] = {
4701 .type = ALC_FIXUP_VERBS,
4702 .v.verbs = (const struct hda_verb[]) {
4703 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4704 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4705 { }
4706 },
4707 .chained = true,
4708 .chain_id = ALC880_FIXUP_GPIO2,
4709 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004710 [ALC880_FIXUP_LG] = {
4711 .type = ALC_FIXUP_PINS,
4712 .v.pins = (const struct alc_pincfg[]) {
4713 /* disable bogus unused pins */
4714 { 0x16, 0x411111f0 },
4715 { 0x18, 0x411111f0 },
4716 { 0x1a, 0x411111f0 },
4717 { }
4718 }
4719 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004720 [ALC880_FIXUP_W810] = {
4721 .type = ALC_FIXUP_PINS,
4722 .v.pins = (const struct alc_pincfg[]) {
4723 /* disable bogus unused pins */
4724 { 0x17, 0x411111f0 },
4725 { }
4726 },
4727 .chained = true,
4728 .chain_id = ALC880_FIXUP_GPIO2,
4729 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004730 [ALC880_FIXUP_EAPD_COEF] = {
4731 .type = ALC_FIXUP_VERBS,
4732 .v.verbs = (const struct hda_verb[]) {
4733 /* change to EAPD mode */
4734 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4735 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4736 {}
4737 },
4738 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004739 [ALC880_FIXUP_TCL_S700] = {
4740 .type = ALC_FIXUP_VERBS,
4741 .v.verbs = (const struct hda_verb[]) {
4742 /* change to EAPD mode */
4743 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4744 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4745 {}
4746 },
4747 .chained = true,
4748 .chain_id = ALC880_FIXUP_GPIO2,
4749 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004750 [ALC880_FIXUP_VOL_KNOB] = {
4751 .type = ALC_FIXUP_FUNC,
4752 .v.func = alc880_fixup_vol_knob,
4753 },
4754 [ALC880_FIXUP_FUJITSU] = {
4755 /* override all pins as BIOS on old Amilo is broken */
4756 .type = ALC_FIXUP_PINS,
4757 .v.pins = (const struct alc_pincfg[]) {
4758 { 0x14, 0x0121411f }, /* HP */
4759 { 0x15, 0x99030120 }, /* speaker */
4760 { 0x16, 0x99030130 }, /* bass speaker */
4761 { 0x17, 0x411111f0 }, /* N/A */
4762 { 0x18, 0x411111f0 }, /* N/A */
4763 { 0x19, 0x01a19950 }, /* mic-in */
4764 { 0x1a, 0x411111f0 }, /* N/A */
4765 { 0x1b, 0x411111f0 }, /* N/A */
4766 { 0x1c, 0x411111f0 }, /* N/A */
4767 { 0x1d, 0x411111f0 }, /* N/A */
4768 { 0x1e, 0x01454140 }, /* SPDIF out */
4769 { }
4770 },
4771 .chained = true,
4772 .chain_id = ALC880_FIXUP_VOL_KNOB,
4773 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004774 [ALC880_FIXUP_F1734] = {
4775 /* almost compatible with FUJITSU, but no bass and SPDIF */
4776 .type = ALC_FIXUP_PINS,
4777 .v.pins = (const struct alc_pincfg[]) {
4778 { 0x14, 0x0121411f }, /* HP */
4779 { 0x15, 0x99030120 }, /* speaker */
4780 { 0x16, 0x411111f0 }, /* N/A */
4781 { 0x17, 0x411111f0 }, /* N/A */
4782 { 0x18, 0x411111f0 }, /* N/A */
4783 { 0x19, 0x01a19950 }, /* mic-in */
4784 { 0x1a, 0x411111f0 }, /* N/A */
4785 { 0x1b, 0x411111f0 }, /* N/A */
4786 { 0x1c, 0x411111f0 }, /* N/A */
4787 { 0x1d, 0x411111f0 }, /* N/A */
4788 { 0x1e, 0x411111f0 }, /* N/A */
4789 { }
4790 },
4791 .chained = true,
4792 .chain_id = ALC880_FIXUP_VOL_KNOB,
4793 },
Takashi Iwai817de922012-02-20 17:20:48 +01004794 [ALC880_FIXUP_UNIWILL] = {
4795 /* need to fix HP and speaker pins to be parsed correctly */
4796 .type = ALC_FIXUP_PINS,
4797 .v.pins = (const struct alc_pincfg[]) {
4798 { 0x14, 0x0121411f }, /* HP */
4799 { 0x15, 0x99030120 }, /* speaker */
4800 { 0x16, 0x99030130 }, /* bass speaker */
4801 { }
4802 },
4803 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004804 [ALC880_FIXUP_UNIWILL_DIG] = {
4805 .type = ALC_FIXUP_PINS,
4806 .v.pins = (const struct alc_pincfg[]) {
4807 /* disable bogus unused pins */
4808 { 0x17, 0x411111f0 },
4809 { 0x19, 0x411111f0 },
4810 { 0x1b, 0x411111f0 },
4811 { 0x1f, 0x411111f0 },
4812 { }
4813 }
4814 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004815 [ALC880_FIXUP_Z71V] = {
4816 .type = ALC_FIXUP_PINS,
4817 .v.pins = (const struct alc_pincfg[]) {
4818 /* set up the whole pins as BIOS is utterly broken */
4819 { 0x14, 0x99030120 }, /* speaker */
4820 { 0x15, 0x0121411f }, /* HP */
4821 { 0x16, 0x411111f0 }, /* N/A */
4822 { 0x17, 0x411111f0 }, /* N/A */
4823 { 0x18, 0x01a19950 }, /* mic-in */
4824 { 0x19, 0x411111f0 }, /* N/A */
4825 { 0x1a, 0x01813031 }, /* line-in */
4826 { 0x1b, 0x411111f0 }, /* N/A */
4827 { 0x1c, 0x411111f0 }, /* N/A */
4828 { 0x1d, 0x411111f0 }, /* N/A */
4829 { 0x1e, 0x0144111e }, /* SPDIF */
4830 { }
4831 }
4832 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004833 [ALC880_FIXUP_3ST_BASE] = {
4834 .type = ALC_FIXUP_PINS,
4835 .v.pins = (const struct alc_pincfg[]) {
4836 { 0x14, 0x01014010 }, /* line-out */
4837 { 0x15, 0x411111f0 }, /* N/A */
4838 { 0x16, 0x411111f0 }, /* N/A */
4839 { 0x17, 0x411111f0 }, /* N/A */
4840 { 0x18, 0x01a19c30 }, /* mic-in */
4841 { 0x19, 0x0121411f }, /* HP */
4842 { 0x1a, 0x01813031 }, /* line-in */
4843 { 0x1b, 0x02a19c40 }, /* front-mic */
4844 { 0x1c, 0x411111f0 }, /* N/A */
4845 { 0x1d, 0x411111f0 }, /* N/A */
4846 /* 0x1e is filled in below */
4847 { 0x1f, 0x411111f0 }, /* N/A */
4848 { }
4849 }
4850 },
4851 [ALC880_FIXUP_3ST] = {
4852 .type = ALC_FIXUP_PINS,
4853 .v.pins = (const struct alc_pincfg[]) {
4854 { 0x1e, 0x411111f0 }, /* N/A */
4855 { }
4856 },
4857 .chained = true,
4858 .chain_id = ALC880_FIXUP_3ST_BASE,
4859 },
4860 [ALC880_FIXUP_3ST_DIG] = {
4861 .type = ALC_FIXUP_PINS,
4862 .v.pins = (const struct alc_pincfg[]) {
4863 { 0x1e, 0x0144111e }, /* SPDIF */
4864 { }
4865 },
4866 .chained = true,
4867 .chain_id = ALC880_FIXUP_3ST_BASE,
4868 },
4869 [ALC880_FIXUP_5ST_BASE] = {
4870 .type = ALC_FIXUP_PINS,
4871 .v.pins = (const struct alc_pincfg[]) {
4872 { 0x14, 0x01014010 }, /* front */
4873 { 0x15, 0x411111f0 }, /* N/A */
4874 { 0x16, 0x01011411 }, /* CLFE */
4875 { 0x17, 0x01016412 }, /* surr */
4876 { 0x18, 0x01a19c30 }, /* mic-in */
4877 { 0x19, 0x0121411f }, /* HP */
4878 { 0x1a, 0x01813031 }, /* line-in */
4879 { 0x1b, 0x02a19c40 }, /* front-mic */
4880 { 0x1c, 0x411111f0 }, /* N/A */
4881 { 0x1d, 0x411111f0 }, /* N/A */
4882 /* 0x1e is filled in below */
4883 { 0x1f, 0x411111f0 }, /* N/A */
4884 { }
4885 }
4886 },
4887 [ALC880_FIXUP_5ST] = {
4888 .type = ALC_FIXUP_PINS,
4889 .v.pins = (const struct alc_pincfg[]) {
4890 { 0x1e, 0x411111f0 }, /* N/A */
4891 { }
4892 },
4893 .chained = true,
4894 .chain_id = ALC880_FIXUP_5ST_BASE,
4895 },
4896 [ALC880_FIXUP_5ST_DIG] = {
4897 .type = ALC_FIXUP_PINS,
4898 .v.pins = (const struct alc_pincfg[]) {
4899 { 0x1e, 0x0144111e }, /* SPDIF */
4900 { }
4901 },
4902 .chained = true,
4903 .chain_id = ALC880_FIXUP_5ST_BASE,
4904 },
4905 [ALC880_FIXUP_6ST_BASE] = {
4906 .type = ALC_FIXUP_PINS,
4907 .v.pins = (const struct alc_pincfg[]) {
4908 { 0x14, 0x01014010 }, /* front */
4909 { 0x15, 0x01016412 }, /* surr */
4910 { 0x16, 0x01011411 }, /* CLFE */
4911 { 0x17, 0x01012414 }, /* side */
4912 { 0x18, 0x01a19c30 }, /* mic-in */
4913 { 0x19, 0x02a19c40 }, /* front-mic */
4914 { 0x1a, 0x01813031 }, /* line-in */
4915 { 0x1b, 0x0121411f }, /* HP */
4916 { 0x1c, 0x411111f0 }, /* N/A */
4917 { 0x1d, 0x411111f0 }, /* N/A */
4918 /* 0x1e is filled in below */
4919 { 0x1f, 0x411111f0 }, /* N/A */
4920 { }
4921 }
4922 },
4923 [ALC880_FIXUP_6ST] = {
4924 .type = ALC_FIXUP_PINS,
4925 .v.pins = (const struct alc_pincfg[]) {
4926 { 0x1e, 0x411111f0 }, /* N/A */
4927 { }
4928 },
4929 .chained = true,
4930 .chain_id = ALC880_FIXUP_6ST_BASE,
4931 },
4932 [ALC880_FIXUP_6ST_DIG] = {
4933 .type = ALC_FIXUP_PINS,
4934 .v.pins = (const struct alc_pincfg[]) {
4935 { 0x1e, 0x0144111e }, /* SPDIF */
4936 { }
4937 },
4938 .chained = true,
4939 .chain_id = ALC880_FIXUP_6ST_BASE,
4940 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004941};
4942
4943static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004944 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004945 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004946 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4947 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004948 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004949 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004950 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004951 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004952 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004953 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004954 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004955 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004956 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004957 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004958 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004959 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4960 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4961 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004962 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004963
4964 /* Below is the copied entries from alc880_quirks.c.
4965 * It's not quite sure whether BIOS sets the correct pin-config table
4966 * on these machines, thus they are kept to be compatible with
4967 * the old static quirks. Once when it's confirmed to work without
4968 * these overrides, it'd be better to remove.
4969 */
4970 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4971 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4972 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4973 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4974 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4975 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4976 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4977 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4978 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4979 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4980 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4981 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4982 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4983 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4984 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4985 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4986 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4987 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4988 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4989 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4990 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4991 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4992 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4993 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4994 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4995 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4996 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4997 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4998 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4999 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5000 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5001 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5002 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5003 /* default Intel */
5004 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
5005 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
5006 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
5007 {}
5008};
5009
5010static const struct alc_model_fixup alc880_fixup_models[] = {
5011 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
5012 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
5013 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
5014 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
5015 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
5016 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01005017 {}
5018};
5019
5020
5021/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02005022 * OK, here we have finally the patch for ALC880
5023 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005024static int patch_alc880(struct hda_codec *codec)
5025{
5026 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005027 int err;
5028
Takashi Iwai3de95172012-05-07 18:03:15 +02005029 err = alc_alloc_spec(codec, 0x0b);
5030 if (err < 0)
5031 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005032
Takashi Iwai3de95172012-05-07 18:03:15 +02005033 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02005034 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005035
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005036 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
5037 alc880_fixups);
5038 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005039
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005040 /* automatic parse from the BIOS config */
5041 err = alc880_parse_auto_config(codec);
5042 if (err < 0)
5043 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005044
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005045 if (!spec->no_analog) {
5046 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005047 if (err < 0)
5048 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005049 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5050 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005051
Takashi Iwai1d045db2011-07-07 18:23:21 +02005052 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02005053 codec->patch_ops.unsol_event = alc880_unsol_event;
5054
Takashi Iwai1d045db2011-07-07 18:23:21 +02005055
Takashi Iwai589876e2012-02-20 15:47:55 +01005056 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5057
Takashi Iwai1d045db2011-07-07 18:23:21 +02005058 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005059
5060 error:
5061 alc_free(codec);
5062 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005063}
5064
5065
5066/*
5067 * ALC260 support
5068 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005069static int alc260_parse_auto_config(struct hda_codec *codec)
5070{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005071 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005072 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5073 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005074}
5075
Takashi Iwai1d045db2011-07-07 18:23:21 +02005076/*
5077 * Pin config fixes
5078 */
5079enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005080 ALC260_FIXUP_HP_DC5750,
5081 ALC260_FIXUP_HP_PIN_0F,
5082 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005083 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005084 ALC260_FIXUP_GPIO1_TOGGLE,
5085 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005086 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005087 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005088};
5089
Takashi Iwai20f7d922012-02-16 12:35:16 +01005090static void alc260_gpio1_automute(struct hda_codec *codec)
5091{
5092 struct alc_spec *spec = codec->spec;
5093 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5094 spec->hp_jack_present);
5095}
5096
5097static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5098 const struct alc_fixup *fix, int action)
5099{
5100 struct alc_spec *spec = codec->spec;
5101 if (action == ALC_FIXUP_ACT_PROBE) {
5102 /* although the machine has only one output pin, we need to
5103 * toggle GPIO1 according to the jack state
5104 */
5105 spec->automute_hook = alc260_gpio1_automute;
5106 spec->detect_hp = 1;
5107 spec->automute_speaker = 1;
5108 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005109 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5110 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005111 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005112 }
5113}
5114
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005115static void alc260_fixup_kn1(struct hda_codec *codec,
5116 const struct alc_fixup *fix, int action)
5117{
5118 struct alc_spec *spec = codec->spec;
5119 static const struct alc_pincfg pincfgs[] = {
5120 { 0x0f, 0x02214000 }, /* HP/speaker */
5121 { 0x12, 0x90a60160 }, /* int mic */
5122 { 0x13, 0x02a19000 }, /* ext mic */
5123 { 0x18, 0x01446000 }, /* SPDIF out */
5124 /* disable bogus I/O pins */
5125 { 0x10, 0x411111f0 },
5126 { 0x11, 0x411111f0 },
5127 { 0x14, 0x411111f0 },
5128 { 0x15, 0x411111f0 },
5129 { 0x16, 0x411111f0 },
5130 { 0x17, 0x411111f0 },
5131 { 0x19, 0x411111f0 },
5132 { }
5133 };
5134
5135 switch (action) {
5136 case ALC_FIXUP_ACT_PRE_PROBE:
5137 alc_apply_pincfgs(codec, pincfgs);
5138 break;
5139 case ALC_FIXUP_ACT_PROBE:
5140 spec->init_amp = ALC_INIT_NONE;
5141 break;
5142 }
5143}
5144
Takashi Iwai1d045db2011-07-07 18:23:21 +02005145static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005146 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005147 .type = ALC_FIXUP_PINS,
5148 .v.pins = (const struct alc_pincfg[]) {
5149 { 0x11, 0x90130110 }, /* speaker */
5150 { }
5151 }
5152 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005153 [ALC260_FIXUP_HP_PIN_0F] = {
5154 .type = ALC_FIXUP_PINS,
5155 .v.pins = (const struct alc_pincfg[]) {
5156 { 0x0f, 0x01214000 }, /* HP */
5157 { }
5158 }
5159 },
5160 [ALC260_FIXUP_COEF] = {
5161 .type = ALC_FIXUP_VERBS,
5162 .v.verbs = (const struct hda_verb[]) {
5163 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5164 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5165 { }
5166 },
5167 .chained = true,
5168 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5169 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005170 [ALC260_FIXUP_GPIO1] = {
5171 .type = ALC_FIXUP_VERBS,
5172 .v.verbs = alc_gpio1_init_verbs,
5173 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005174 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5175 .type = ALC_FIXUP_FUNC,
5176 .v.func = alc260_fixup_gpio1_toggle,
5177 .chained = true,
5178 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5179 },
5180 [ALC260_FIXUP_REPLACER] = {
5181 .type = ALC_FIXUP_VERBS,
5182 .v.verbs = (const struct hda_verb[]) {
5183 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5184 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5185 { }
5186 },
5187 .chained = true,
5188 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5189 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005190 [ALC260_FIXUP_HP_B1900] = {
5191 .type = ALC_FIXUP_FUNC,
5192 .v.func = alc260_fixup_gpio1_toggle,
5193 .chained = true,
5194 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005195 },
5196 [ALC260_FIXUP_KN1] = {
5197 .type = ALC_FIXUP_FUNC,
5198 .v.func = alc260_fixup_kn1,
5199 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005200};
5201
5202static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005203 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005204 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005205 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005206 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005207 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005208 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005209 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005210 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005211 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005212 {}
5213};
5214
5215/*
5216 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005217static int patch_alc260(struct hda_codec *codec)
5218{
5219 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005220 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005221
Takashi Iwai3de95172012-05-07 18:03:15 +02005222 err = alc_alloc_spec(codec, 0x07);
5223 if (err < 0)
5224 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005225
Takashi Iwai3de95172012-05-07 18:03:15 +02005226 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005227
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005228 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5229 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005230
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005231 /* automatic parse from the BIOS config */
5232 err = alc260_parse_auto_config(codec);
5233 if (err < 0)
5234 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005235
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005236 if (!spec->no_analog) {
5237 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005238 if (err < 0)
5239 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005240 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5241 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005242
Takashi Iwai1d045db2011-07-07 18:23:21 +02005243 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005244 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005245
Takashi Iwai589876e2012-02-20 15:47:55 +01005246 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5247
Takashi Iwai1d045db2011-07-07 18:23:21 +02005248 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005249
5250 error:
5251 alc_free(codec);
5252 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005253}
5254
5255
5256/*
5257 * ALC882/883/885/888/889 support
5258 *
5259 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5260 * configuration. Each pin widget can choose any input DACs and a mixer.
5261 * Each ADC is connected from a mixer of all inputs. This makes possible
5262 * 6-channel independent captures.
5263 *
5264 * In addition, an independent DAC for the multi-playback (not used in this
5265 * driver yet).
5266 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005267
5268/*
5269 * Pin config fixes
5270 */
5271enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005272 ALC882_FIXUP_ABIT_AW9D_MAX,
5273 ALC882_FIXUP_LENOVO_Y530,
5274 ALC882_FIXUP_PB_M5210,
5275 ALC882_FIXUP_ACER_ASPIRE_7736,
5276 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005277 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005278 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005279 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005280 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005281 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005282 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005283 ALC882_FIXUP_GPIO1,
5284 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005285 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005286 ALC889_FIXUP_COEF,
5287 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005288 ALC882_FIXUP_ACER_ASPIRE_4930G,
5289 ALC882_FIXUP_ACER_ASPIRE_8930G,
5290 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005291 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005292 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005293 ALC889_FIXUP_MBP_VREF,
5294 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005295 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005296 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005297};
5298
Takashi Iwai68ef0562011-11-09 18:24:44 +01005299static void alc889_fixup_coef(struct hda_codec *codec,
5300 const struct alc_fixup *fix, int action)
5301{
5302 if (action != ALC_FIXUP_ACT_INIT)
5303 return;
5304 alc889_coef_init(codec);
5305}
5306
Takashi Iwai56710872011-11-14 17:42:11 +01005307/* toggle speaker-output according to the hp-jack state */
5308static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5309{
5310 unsigned int gpiostate, gpiomask, gpiodir;
5311
5312 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5313 AC_VERB_GET_GPIO_DATA, 0);
5314
5315 if (!muted)
5316 gpiostate |= (1 << pin);
5317 else
5318 gpiostate &= ~(1 << pin);
5319
5320 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5321 AC_VERB_GET_GPIO_MASK, 0);
5322 gpiomask |= (1 << pin);
5323
5324 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5325 AC_VERB_GET_GPIO_DIRECTION, 0);
5326 gpiodir |= (1 << pin);
5327
5328
5329 snd_hda_codec_write(codec, codec->afg, 0,
5330 AC_VERB_SET_GPIO_MASK, gpiomask);
5331 snd_hda_codec_write(codec, codec->afg, 0,
5332 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5333
5334 msleep(1);
5335
5336 snd_hda_codec_write(codec, codec->afg, 0,
5337 AC_VERB_SET_GPIO_DATA, gpiostate);
5338}
5339
5340/* set up GPIO at initialization */
5341static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5342 const struct alc_fixup *fix, int action)
5343{
5344 if (action != ALC_FIXUP_ACT_INIT)
5345 return;
5346 alc882_gpio_mute(codec, 0, 0);
5347 alc882_gpio_mute(codec, 1, 0);
5348}
5349
Takashi Iwai02a237b2012-02-13 15:25:07 +01005350/* Fix the connection of some pins for ALC889:
5351 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5352 * work correctly (bko#42740)
5353 */
5354static void alc889_fixup_dac_route(struct hda_codec *codec,
5355 const struct alc_fixup *fix, int action)
5356{
5357 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005358 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005359 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5360 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5361 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5362 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5363 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5364 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005365 } else if (action == ALC_FIXUP_ACT_PROBE) {
5366 /* restore the connections */
5367 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5368 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5369 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5370 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5371 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005372 }
5373}
5374
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005375/* Set VREF on HP pin */
5376static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5377 const struct alc_fixup *fix, int action)
5378{
5379 struct alc_spec *spec = codec->spec;
5380 static hda_nid_t nids[2] = { 0x14, 0x15 };
5381 int i;
5382
5383 if (action != ALC_FIXUP_ACT_INIT)
5384 return;
5385 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5386 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5387 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5388 continue;
5389 val = snd_hda_codec_read(codec, nids[i], 0,
5390 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5391 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005392 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005393 spec->keep_vref_in_automute = 1;
5394 break;
5395 }
5396}
5397
5398/* Set VREF on speaker pins on imac91 */
5399static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5400 const struct alc_fixup *fix, int action)
5401{
5402 struct alc_spec *spec = codec->spec;
5403 static hda_nid_t nids[2] = { 0x18, 0x1a };
5404 int i;
5405
5406 if (action != ALC_FIXUP_ACT_INIT)
5407 return;
5408 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5409 unsigned int val;
5410 val = snd_hda_codec_read(codec, nids[i], 0,
5411 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5412 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005413 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005414 }
5415 spec->keep_vref_in_automute = 1;
5416}
5417
Takashi Iwaie427c232012-07-29 10:04:08 +02005418/* Don't take HP output as primary
5419 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5420 */
5421static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5422 const struct alc_fixup *fix, int action)
5423{
5424 struct alc_spec *spec = codec->spec;
5425 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5426 spec->no_primary_hp = 1;
5427}
5428
Takashi Iwai1d045db2011-07-07 18:23:21 +02005429static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005430 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005431 .type = ALC_FIXUP_PINS,
5432 .v.pins = (const struct alc_pincfg[]) {
5433 { 0x15, 0x01080104 }, /* side */
5434 { 0x16, 0x01011012 }, /* rear */
5435 { 0x17, 0x01016011 }, /* clfe */
5436 { }
5437 }
5438 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005439 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005440 .type = ALC_FIXUP_PINS,
5441 .v.pins = (const struct alc_pincfg[]) {
5442 { 0x15, 0x99130112 }, /* rear int speakers */
5443 { 0x16, 0x99130111 }, /* subwoofer */
5444 { }
5445 }
5446 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005447 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005448 .type = ALC_FIXUP_VERBS,
5449 .v.verbs = (const struct hda_verb[]) {
5450 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5451 {}
5452 }
5453 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005454 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005455 .type = ALC_FIXUP_FUNC,
5456 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005457 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005458 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005459 .type = ALC_FIXUP_PINS,
5460 .v.pins = (const struct alc_pincfg[]) {
5461 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5462 { }
5463 }
5464 },
Marton Balint8f239212012-03-05 21:33:23 +01005465 [ALC889_FIXUP_CD] = {
5466 .type = ALC_FIXUP_PINS,
5467 .v.pins = (const struct alc_pincfg[]) {
5468 { 0x1c, 0x993301f0 }, /* CD */
5469 { }
5470 }
5471 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005472 [ALC889_FIXUP_VAIO_TT] = {
5473 .type = ALC_FIXUP_PINS,
5474 .v.pins = (const struct alc_pincfg[]) {
5475 { 0x17, 0x90170111 }, /* hidden surround speaker */
5476 { }
5477 }
5478 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005479 [ALC888_FIXUP_EEE1601] = {
5480 .type = ALC_FIXUP_VERBS,
5481 .v.verbs = (const struct hda_verb[]) {
5482 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5483 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5484 { }
5485 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005486 },
5487 [ALC882_FIXUP_EAPD] = {
5488 .type = ALC_FIXUP_VERBS,
5489 .v.verbs = (const struct hda_verb[]) {
5490 /* change to EAPD mode */
5491 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5492 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5493 { }
5494 }
5495 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005496 [ALC883_FIXUP_EAPD] = {
5497 .type = ALC_FIXUP_VERBS,
5498 .v.verbs = (const struct hda_verb[]) {
5499 /* change to EAPD mode */
5500 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5501 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5502 { }
5503 }
5504 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005505 [ALC883_FIXUP_ACER_EAPD] = {
5506 .type = ALC_FIXUP_VERBS,
5507 .v.verbs = (const struct hda_verb[]) {
5508 /* eanable EAPD on Acer laptops */
5509 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5510 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5511 { }
5512 }
5513 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005514 [ALC882_FIXUP_GPIO1] = {
5515 .type = ALC_FIXUP_VERBS,
5516 .v.verbs = alc_gpio1_init_verbs,
5517 },
5518 [ALC882_FIXUP_GPIO2] = {
5519 .type = ALC_FIXUP_VERBS,
5520 .v.verbs = alc_gpio2_init_verbs,
5521 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005522 [ALC882_FIXUP_GPIO3] = {
5523 .type = ALC_FIXUP_VERBS,
5524 .v.verbs = alc_gpio3_init_verbs,
5525 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005526 [ALC882_FIXUP_ASUS_W2JC] = {
5527 .type = ALC_FIXUP_VERBS,
5528 .v.verbs = alc_gpio1_init_verbs,
5529 .chained = true,
5530 .chain_id = ALC882_FIXUP_EAPD,
5531 },
5532 [ALC889_FIXUP_COEF] = {
5533 .type = ALC_FIXUP_FUNC,
5534 .v.func = alc889_fixup_coef,
5535 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005536 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5537 .type = ALC_FIXUP_PINS,
5538 .v.pins = (const struct alc_pincfg[]) {
5539 { 0x16, 0x99130111 }, /* CLFE speaker */
5540 { 0x17, 0x99130112 }, /* surround speaker */
5541 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005542 },
5543 .chained = true,
5544 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005545 },
5546 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5547 .type = ALC_FIXUP_PINS,
5548 .v.pins = (const struct alc_pincfg[]) {
5549 { 0x16, 0x99130111 }, /* CLFE speaker */
5550 { 0x1b, 0x99130112 }, /* surround speaker */
5551 { }
5552 },
5553 .chained = true,
5554 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5555 },
5556 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5557 /* additional init verbs for Acer Aspire 8930G */
5558 .type = ALC_FIXUP_VERBS,
5559 .v.verbs = (const struct hda_verb[]) {
5560 /* Enable all DACs */
5561 /* DAC DISABLE/MUTE 1? */
5562 /* setting bits 1-5 disables DAC nids 0x02-0x06
5563 * apparently. Init=0x38 */
5564 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5565 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5566 /* DAC DISABLE/MUTE 2? */
5567 /* some bit here disables the other DACs.
5568 * Init=0x4900 */
5569 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5570 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5571 /* DMIC fix
5572 * This laptop has a stereo digital microphone.
5573 * The mics are only 1cm apart which makes the stereo
5574 * useless. However, either the mic or the ALC889
5575 * makes the signal become a difference/sum signal
5576 * instead of standard stereo, which is annoying.
5577 * So instead we flip this bit which makes the
5578 * codec replicate the sum signal to both channels,
5579 * turning it into a normal mono mic.
5580 */
5581 /* DMIC_CONTROL? Init value = 0x0001 */
5582 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5583 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5584 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5585 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5586 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005587 },
5588 .chained = true,
5589 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005590 },
Takashi Iwai56710872011-11-14 17:42:11 +01005591 [ALC885_FIXUP_MACPRO_GPIO] = {
5592 .type = ALC_FIXUP_FUNC,
5593 .v.func = alc885_fixup_macpro_gpio,
5594 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005595 [ALC889_FIXUP_DAC_ROUTE] = {
5596 .type = ALC_FIXUP_FUNC,
5597 .v.func = alc889_fixup_dac_route,
5598 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005599 [ALC889_FIXUP_MBP_VREF] = {
5600 .type = ALC_FIXUP_FUNC,
5601 .v.func = alc889_fixup_mbp_vref,
5602 .chained = true,
5603 .chain_id = ALC882_FIXUP_GPIO1,
5604 },
5605 [ALC889_FIXUP_IMAC91_VREF] = {
5606 .type = ALC_FIXUP_FUNC,
5607 .v.func = alc889_fixup_imac91_vref,
5608 .chained = true,
5609 .chain_id = ALC882_FIXUP_GPIO1,
5610 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005611 [ALC882_FIXUP_INV_DMIC] = {
5612 .type = ALC_FIXUP_FUNC,
5613 .v.func = alc_fixup_inv_dmic_0x12,
5614 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005615 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5616 .type = ALC_FIXUP_FUNC,
5617 .v.func = alc882_fixup_no_primary_hp,
5618 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005619};
5620
5621static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005622 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5623 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5624 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5625 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5626 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5627 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005628 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5629 ALC882_FIXUP_ACER_ASPIRE_4930G),
5630 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5631 ALC882_FIXUP_ACER_ASPIRE_4930G),
5632 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5633 ALC882_FIXUP_ACER_ASPIRE_8930G),
5634 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5635 ALC882_FIXUP_ACER_ASPIRE_8930G),
5636 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5637 ALC882_FIXUP_ACER_ASPIRE_4930G),
5638 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5639 ALC882_FIXUP_ACER_ASPIRE_4930G),
5640 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5641 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005642 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005643 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5644 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005645 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005646 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005647 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005648 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005649 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005650 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005651 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005652 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005653 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005654
5655 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005656 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5657 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5658 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005659 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5660 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5661 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005662 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5663 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005664 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005665 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5666 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5667 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5668 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005669 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005670 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5671 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5672 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005673 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005674 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005675 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5676 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5677 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005678
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005679 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005680 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005681 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005682 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005683 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005684 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5685 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005686 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005687 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005688 {}
5689};
5690
Takashi Iwai912093b2012-04-11 14:03:41 +02005691static const struct alc_model_fixup alc882_fixup_models[] = {
5692 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5693 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5694 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005695 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005696 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005697 {}
5698};
5699
Takashi Iwai1d045db2011-07-07 18:23:21 +02005700/*
5701 * BIOS auto configuration
5702 */
5703/* almost identical with ALC880 parser... */
5704static int alc882_parse_auto_config(struct hda_codec *codec)
5705{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005706 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005707 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5708 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005709}
5710
Takashi Iwai1d045db2011-07-07 18:23:21 +02005711/*
5712 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005713static int patch_alc882(struct hda_codec *codec)
5714{
5715 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005716 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005717
Takashi Iwai3de95172012-05-07 18:03:15 +02005718 err = alc_alloc_spec(codec, 0x0b);
5719 if (err < 0)
5720 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721
Takashi Iwai3de95172012-05-07 18:03:15 +02005722 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005723
5724 switch (codec->vendor_id) {
5725 case 0x10ec0882:
5726 case 0x10ec0885:
5727 break;
5728 default:
5729 /* ALC883 and variants */
5730 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5731 break;
5732 }
5733
Takashi Iwai912093b2012-04-11 14:03:41 +02005734 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5735 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005736 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005737
5738 alc_auto_parse_customize_define(codec);
5739
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005740 /* automatic parse from the BIOS config */
5741 err = alc882_parse_auto_config(codec);
5742 if (err < 0)
5743 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005744
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005745 if (!spec->no_analog && has_cdefine_beep(codec)) {
5746 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005747 if (err < 0)
5748 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005749 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005750 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005751
Takashi Iwai1d045db2011-07-07 18:23:21 +02005752 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753
Takashi Iwai589876e2012-02-20 15:47:55 +01005754 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5755
Takashi Iwai1d045db2011-07-07 18:23:21 +02005756 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005757
5758 error:
5759 alc_free(codec);
5760 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005761}
5762
5763
5764/*
5765 * ALC262 support
5766 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767static int alc262_parse_auto_config(struct hda_codec *codec)
5768{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005769 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005770 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5771 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005772}
5773
5774/*
5775 * Pin config fixes
5776 */
5777enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005778 ALC262_FIXUP_FSC_H270,
5779 ALC262_FIXUP_HP_Z200,
5780 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005781 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005782 ALC262_FIXUP_BENQ,
5783 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005784 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005785};
5786
5787static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005788 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005789 .type = ALC_FIXUP_PINS,
5790 .v.pins = (const struct alc_pincfg[]) {
5791 { 0x14, 0x99130110 }, /* speaker */
5792 { 0x15, 0x0221142f }, /* front HP */
5793 { 0x1b, 0x0121141f }, /* rear HP */
5794 { }
5795 }
5796 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005797 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005798 .type = ALC_FIXUP_PINS,
5799 .v.pins = (const struct alc_pincfg[]) {
5800 { 0x16, 0x99130120 }, /* internal speaker */
5801 { }
5802 }
5803 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005804 [ALC262_FIXUP_TYAN] = {
5805 .type = ALC_FIXUP_PINS,
5806 .v.pins = (const struct alc_pincfg[]) {
5807 { 0x14, 0x1993e1f0 }, /* int AUX */
5808 { }
5809 }
5810 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005811 [ALC262_FIXUP_LENOVO_3000] = {
5812 .type = ALC_FIXUP_VERBS,
5813 .v.verbs = (const struct hda_verb[]) {
5814 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005815 {}
5816 },
5817 .chained = true,
5818 .chain_id = ALC262_FIXUP_BENQ,
5819 },
5820 [ALC262_FIXUP_BENQ] = {
5821 .type = ALC_FIXUP_VERBS,
5822 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005823 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5824 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5825 {}
5826 }
5827 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005828 [ALC262_FIXUP_BENQ_T31] = {
5829 .type = ALC_FIXUP_VERBS,
5830 .v.verbs = (const struct hda_verb[]) {
5831 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5832 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5833 {}
5834 }
5835 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005836 [ALC262_FIXUP_INV_DMIC] = {
5837 .type = ALC_FIXUP_FUNC,
5838 .v.func = alc_fixup_inv_dmic_0x12,
5839 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005840};
5841
5842static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005843 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005844 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5845 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005846 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5847 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005848 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005849 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5850 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005851 {}
5852};
5853
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005854static const struct alc_model_fixup alc262_fixup_models[] = {
5855 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5856 {}
5857};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005858
Takashi Iwai1d045db2011-07-07 18:23:21 +02005859/*
5860 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005861static int patch_alc262(struct hda_codec *codec)
5862{
5863 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005864 int err;
5865
Takashi Iwai3de95172012-05-07 18:03:15 +02005866 err = alc_alloc_spec(codec, 0x0b);
5867 if (err < 0)
5868 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005869
Takashi Iwai3de95172012-05-07 18:03:15 +02005870 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005871
5872#if 0
5873 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5874 * under-run
5875 */
5876 {
5877 int tmp;
5878 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5879 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5880 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5881 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5882 }
5883#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005884 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5885
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005886 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5887 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005888 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005889
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005890 alc_auto_parse_customize_define(codec);
5891
Takashi Iwai42399f72011-11-07 17:18:44 +01005892 /* automatic parse from the BIOS config */
5893 err = alc262_parse_auto_config(codec);
5894 if (err < 0)
5895 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005896
Takashi Iwai1d045db2011-07-07 18:23:21 +02005897 if (!spec->no_analog && has_cdefine_beep(codec)) {
5898 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005899 if (err < 0)
5900 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005901 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005902 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005903
Takashi Iwai1d045db2011-07-07 18:23:21 +02005904 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005905 spec->shutup = alc_eapd_shutup;
5906
Takashi Iwai589876e2012-02-20 15:47:55 +01005907 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5908
Takashi Iwai1d045db2011-07-07 18:23:21 +02005909 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005910
5911 error:
5912 alc_free(codec);
5913 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005914}
5915
5916/*
5917 * ALC268
5918 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005919/* bind Beep switches of both NID 0x0f and 0x10 */
5920static const struct hda_bind_ctls alc268_bind_beep_sw = {
5921 .ops = &snd_hda_bind_sw,
5922 .values = {
5923 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5924 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5925 0
5926 },
5927};
5928
5929static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5930 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5931 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5932 { }
5933};
5934
5935/* set PCBEEP vol = 0, mute connections */
5936static const struct hda_verb alc268_beep_init_verbs[] = {
5937 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5938 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5939 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5940 { }
5941};
5942
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005943enum {
5944 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005945 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005946};
5947
5948static const struct alc_fixup alc268_fixups[] = {
5949 [ALC268_FIXUP_INV_DMIC] = {
5950 .type = ALC_FIXUP_FUNC,
5951 .v.func = alc_fixup_inv_dmic_0x12,
5952 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005953 [ALC268_FIXUP_HP_EAPD] = {
5954 .type = ALC_FIXUP_VERBS,
5955 .v.verbs = (const struct hda_verb[]) {
5956 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5957 {}
5958 }
5959 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005960};
5961
5962static const struct alc_model_fixup alc268_fixup_models[] = {
5963 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005964 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5965 {}
5966};
5967
5968static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5969 /* below is codec SSID since multiple Toshiba laptops have the
5970 * same PCI SSID 1179:ff00
5971 */
5972 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005973 {}
5974};
5975
Takashi Iwai1d045db2011-07-07 18:23:21 +02005976/*
5977 * BIOS auto configuration
5978 */
5979static int alc268_parse_auto_config(struct hda_codec *codec)
5980{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005981 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005982 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005983 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5984 if (err > 0) {
5985 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5986 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005987 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005988 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005989 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005990 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005991}
5992
Takashi Iwai1d045db2011-07-07 18:23:21 +02005993/*
5994 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005995static int patch_alc268(struct hda_codec *codec)
5996{
5997 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005998 int i, has_beep, err;
5999
Takashi Iwai1d045db2011-07-07 18:23:21 +02006000 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006001 err = alc_alloc_spec(codec, 0);
6002 if (err < 0)
6003 return err;
6004
6005 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006006
Takashi Iwaicb766402012-10-20 10:55:21 +02006007 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006008 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6009
Takashi Iwai6ebb8052011-08-16 15:15:40 +02006010 /* automatic parse from the BIOS config */
6011 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006012 if (err < 0)
6013 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006014
Takashi Iwai1d045db2011-07-07 18:23:21 +02006015 has_beep = 0;
6016 for (i = 0; i < spec->num_mixers; i++) {
6017 if (spec->mixers[i] == alc268_beep_mixer) {
6018 has_beep = 1;
6019 break;
6020 }
6021 }
6022
6023 if (has_beep) {
6024 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006025 if (err < 0)
6026 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006027 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
6028 /* override the amp caps for beep generator */
6029 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
6030 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
6031 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
6032 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6033 (0 << AC_AMPCAP_MUTE_SHIFT));
6034 }
6035
Takashi Iwai1d045db2011-07-07 18:23:21 +02006036 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006037 spec->shutup = alc_eapd_shutup;
6038
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006039 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6040
Takashi Iwai1d045db2011-07-07 18:23:21 +02006041 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006042
6043 error:
6044 alc_free(codec);
6045 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006046}
6047
6048/*
6049 * ALC269
6050 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006051static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6052 .substreams = 1,
6053 .channels_min = 2,
6054 .channels_max = 8,
6055 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6056 /* NID is set in alc_build_pcms */
6057 .ops = {
6058 .open = alc_playback_pcm_open,
6059 .prepare = alc_playback_pcm_prepare,
6060 .cleanup = alc_playback_pcm_cleanup
6061 },
6062};
6063
6064static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6065 .substreams = 1,
6066 .channels_min = 2,
6067 .channels_max = 2,
6068 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6069 /* NID is set in alc_build_pcms */
6070};
6071
Takashi Iwai1d045db2011-07-07 18:23:21 +02006072/* different alc269-variants */
6073enum {
6074 ALC269_TYPE_ALC269VA,
6075 ALC269_TYPE_ALC269VB,
6076 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006077 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006078 ALC269_TYPE_ALC280,
6079 ALC269_TYPE_ALC282,
6080 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006081};
6082
6083/*
6084 * BIOS auto configuration
6085 */
6086static int alc269_parse_auto_config(struct hda_codec *codec)
6087{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006088 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006089 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6090 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6091 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006092 const hda_nid_t *ssids;
6093
6094 switch (spec->codec_variant) {
6095 case ALC269_TYPE_ALC269VA:
6096 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006097 case ALC269_TYPE_ALC280:
6098 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006099 ssids = alc269va_ssids;
6100 break;
6101 case ALC269_TYPE_ALC269VB:
6102 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006103 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006104 ssids = alc269_ssids;
6105 break;
6106 default:
6107 ssids = alc269_ssids;
6108 break;
6109 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006110
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006111 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006112}
6113
Kailang Yang1387e2d2012-11-08 10:23:18 +01006114static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006115{
6116 int val = alc_read_coef_idx(codec, 0x04);
6117 if (power_up)
6118 val |= 1 << 11;
6119 else
6120 val &= ~(1 << 11);
6121 alc_write_coef_idx(codec, 0x04, val);
6122}
6123
6124static void alc269_shutup(struct hda_codec *codec)
6125{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006126 struct alc_spec *spec = codec->spec;
6127
6128 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6129 return;
6130
Kailang Yang1387e2d2012-11-08 10:23:18 +01006131 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6132 alc269vb_toggle_power_output(codec, 0);
6133 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6134 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006135 msleep(150);
6136 }
6137}
6138
Takashi Iwai2a439522011-07-26 09:52:50 +02006139#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006140static int alc269_resume(struct hda_codec *codec)
6141{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006142 struct alc_spec *spec = codec->spec;
6143
Kailang Yang1387e2d2012-11-08 10:23:18 +01006144 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6145 alc269vb_toggle_power_output(codec, 0);
6146 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006147 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006148 msleep(150);
6149 }
6150
6151 codec->patch_ops.init(codec);
6152
Kailang Yang1387e2d2012-11-08 10:23:18 +01006153 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6154 alc269vb_toggle_power_output(codec, 1);
6155 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006156 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006157 msleep(200);
6158 }
6159
Takashi Iwai1d045db2011-07-07 18:23:21 +02006160 snd_hda_codec_resume_amp(codec);
6161 snd_hda_codec_resume_cache(codec);
6162 hda_call_check_power_status(codec, 0x01);
6163 return 0;
6164}
Takashi Iwai2a439522011-07-26 09:52:50 +02006165#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006166
David Henningsson108cc102012-07-20 10:37:25 +02006167static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6168 const struct alc_fixup *fix, int action)
6169{
6170 struct alc_spec *spec = codec->spec;
6171
6172 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6173 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6174}
6175
Takashi Iwai1d045db2011-07-07 18:23:21 +02006176static void alc269_fixup_hweq(struct hda_codec *codec,
6177 const struct alc_fixup *fix, int action)
6178{
6179 int coef;
6180
6181 if (action != ALC_FIXUP_ACT_INIT)
6182 return;
6183 coef = alc_read_coef_idx(codec, 0x1e);
6184 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6185}
6186
6187static void alc271_fixup_dmic(struct hda_codec *codec,
6188 const struct alc_fixup *fix, int action)
6189{
6190 static const struct hda_verb verbs[] = {
6191 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6192 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6193 {}
6194 };
6195 unsigned int cfg;
6196
6197 if (strcmp(codec->chip_name, "ALC271X"))
6198 return;
6199 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6200 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6201 snd_hda_sequence_write(codec, verbs);
6202}
6203
Takashi Iwai017f2a12011-07-09 14:42:25 +02006204static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6205 const struct alc_fixup *fix, int action)
6206{
6207 struct alc_spec *spec = codec->spec;
6208
6209 if (action != ALC_FIXUP_ACT_PROBE)
6210 return;
6211
6212 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6213 * fix the sample rate of analog I/O to 44.1kHz
6214 */
6215 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6216 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6217}
6218
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006219static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6220 const struct alc_fixup *fix, int action)
6221{
6222 int coef;
6223
6224 if (action != ALC_FIXUP_ACT_INIT)
6225 return;
6226 /* The digital-mic unit sends PDM (differential signal) instead of
6227 * the standard PCM, thus you can't record a valid mono stream as is.
6228 * Below is a workaround specific to ALC269 to control the dmic
6229 * signal source as mono.
6230 */
6231 coef = alc_read_coef_idx(codec, 0x07);
6232 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6233}
6234
Takashi Iwai24519912011-08-16 15:08:49 +02006235static void alc269_quanta_automute(struct hda_codec *codec)
6236{
David Henningsson42cf0d02011-09-20 12:04:56 +02006237 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006238
6239 snd_hda_codec_write(codec, 0x20, 0,
6240 AC_VERB_SET_COEF_INDEX, 0x0c);
6241 snd_hda_codec_write(codec, 0x20, 0,
6242 AC_VERB_SET_PROC_COEF, 0x680);
6243
6244 snd_hda_codec_write(codec, 0x20, 0,
6245 AC_VERB_SET_COEF_INDEX, 0x0c);
6246 snd_hda_codec_write(codec, 0x20, 0,
6247 AC_VERB_SET_PROC_COEF, 0x480);
6248}
6249
6250static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6251 const struct alc_fixup *fix, int action)
6252{
6253 struct alc_spec *spec = codec->spec;
6254 if (action != ALC_FIXUP_ACT_PROBE)
6255 return;
6256 spec->automute_hook = alc269_quanta_automute;
6257}
6258
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006259/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6260static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6261{
6262 struct hda_codec *codec = private_data;
6263 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6264 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6265 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6266}
6267
6268static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6269 const struct alc_fixup *fix, int action)
6270{
6271 struct alc_spec *spec = codec->spec;
6272 switch (action) {
6273 case ALC_FIXUP_ACT_BUILD:
6274 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6275 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6276 /* fallthru */
6277 case ALC_FIXUP_ACT_INIT:
6278 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6279 break;
6280 }
6281}
6282
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006283/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6284static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6285{
6286 struct hda_codec *codec = private_data;
6287 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006288 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006289}
6290
6291static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6292 const struct alc_fixup *fix, int action)
6293{
6294 struct alc_spec *spec = codec->spec;
6295 switch (action) {
6296 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006297 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735cb2012-03-13 07:55:10 +01006298 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006299 /* fallthru */
6300 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006301 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006302 break;
6303 }
6304}
6305
Dylan Reid08a978d2012-11-18 22:56:40 -08006306static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6307 const struct alc_fixup *fix,
6308 int action)
6309{
6310 struct alc_spec *spec = codec->spec;
6311
6312 if (action == ALC_FIXUP_ACT_PROBE)
6313 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6314 spec->autocfg.hp_pins[0]);
6315}
David Henningsson693b6132012-06-22 19:12:10 +02006316
Takashi Iwai1d045db2011-07-07 18:23:21 +02006317enum {
6318 ALC269_FIXUP_SONY_VAIO,
6319 ALC275_FIXUP_SONY_VAIO_GPIO2,
6320 ALC269_FIXUP_DELL_M101Z,
6321 ALC269_FIXUP_SKU_IGNORE,
6322 ALC269_FIXUP_ASUS_G73JW,
6323 ALC269_FIXUP_LENOVO_EAPD,
6324 ALC275_FIXUP_SONY_HWEQ,
6325 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006326 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006327 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006328 ALC269_FIXUP_QUANTA_MUTE,
6329 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006330 ALC269_FIXUP_AMIC,
6331 ALC269_FIXUP_DMIC,
6332 ALC269VB_FIXUP_AMIC,
6333 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006334 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006335 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006336 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006337 ALC269_FIXUP_LENOVO_DOCK,
6338 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006339 ALC271_FIXUP_AMIC_MIC2,
6340 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006341};
6342
6343static const struct alc_fixup alc269_fixups[] = {
6344 [ALC269_FIXUP_SONY_VAIO] = {
6345 .type = ALC_FIXUP_VERBS,
6346 .v.verbs = (const struct hda_verb[]) {
6347 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6348 {}
6349 }
6350 },
6351 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6352 .type = ALC_FIXUP_VERBS,
6353 .v.verbs = (const struct hda_verb[]) {
6354 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6355 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6356 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6357 { }
6358 },
6359 .chained = true,
6360 .chain_id = ALC269_FIXUP_SONY_VAIO
6361 },
6362 [ALC269_FIXUP_DELL_M101Z] = {
6363 .type = ALC_FIXUP_VERBS,
6364 .v.verbs = (const struct hda_verb[]) {
6365 /* Enables internal speaker */
6366 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6367 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6368 {}
6369 }
6370 },
6371 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006372 .type = ALC_FIXUP_FUNC,
6373 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006374 },
6375 [ALC269_FIXUP_ASUS_G73JW] = {
6376 .type = ALC_FIXUP_PINS,
6377 .v.pins = (const struct alc_pincfg[]) {
6378 { 0x17, 0x99130111 }, /* subwoofer */
6379 { }
6380 }
6381 },
6382 [ALC269_FIXUP_LENOVO_EAPD] = {
6383 .type = ALC_FIXUP_VERBS,
6384 .v.verbs = (const struct hda_verb[]) {
6385 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6386 {}
6387 }
6388 },
6389 [ALC275_FIXUP_SONY_HWEQ] = {
6390 .type = ALC_FIXUP_FUNC,
6391 .v.func = alc269_fixup_hweq,
6392 .chained = true,
6393 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6394 },
6395 [ALC271_FIXUP_DMIC] = {
6396 .type = ALC_FIXUP_FUNC,
6397 .v.func = alc271_fixup_dmic,
6398 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006399 [ALC269_FIXUP_PCM_44K] = {
6400 .type = ALC_FIXUP_FUNC,
6401 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006402 .chained = true,
6403 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006404 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006405 [ALC269_FIXUP_STEREO_DMIC] = {
6406 .type = ALC_FIXUP_FUNC,
6407 .v.func = alc269_fixup_stereo_dmic,
6408 },
Takashi Iwai24519912011-08-16 15:08:49 +02006409 [ALC269_FIXUP_QUANTA_MUTE] = {
6410 .type = ALC_FIXUP_FUNC,
6411 .v.func = alc269_fixup_quanta_mute,
6412 },
6413 [ALC269_FIXUP_LIFEBOOK] = {
6414 .type = ALC_FIXUP_PINS,
6415 .v.pins = (const struct alc_pincfg[]) {
6416 { 0x1a, 0x2101103f }, /* dock line-out */
6417 { 0x1b, 0x23a11040 }, /* dock mic-in */
6418 { }
6419 },
6420 .chained = true,
6421 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6422 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006423 [ALC269_FIXUP_AMIC] = {
6424 .type = ALC_FIXUP_PINS,
6425 .v.pins = (const struct alc_pincfg[]) {
6426 { 0x14, 0x99130110 }, /* speaker */
6427 { 0x15, 0x0121401f }, /* HP out */
6428 { 0x18, 0x01a19c20 }, /* mic */
6429 { 0x19, 0x99a3092f }, /* int-mic */
6430 { }
6431 },
6432 },
6433 [ALC269_FIXUP_DMIC] = {
6434 .type = ALC_FIXUP_PINS,
6435 .v.pins = (const struct alc_pincfg[]) {
6436 { 0x12, 0x99a3092f }, /* int-mic */
6437 { 0x14, 0x99130110 }, /* speaker */
6438 { 0x15, 0x0121401f }, /* HP out */
6439 { 0x18, 0x01a19c20 }, /* mic */
6440 { }
6441 },
6442 },
6443 [ALC269VB_FIXUP_AMIC] = {
6444 .type = ALC_FIXUP_PINS,
6445 .v.pins = (const struct alc_pincfg[]) {
6446 { 0x14, 0x99130110 }, /* speaker */
6447 { 0x18, 0x01a19c20 }, /* mic */
6448 { 0x19, 0x99a3092f }, /* int-mic */
6449 { 0x21, 0x0121401f }, /* HP out */
6450 { }
6451 },
6452 },
David Henningsson2267ea92012-01-03 08:45:56 +01006453 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006454 .type = ALC_FIXUP_PINS,
6455 .v.pins = (const struct alc_pincfg[]) {
6456 { 0x12, 0x99a3092f }, /* int-mic */
6457 { 0x14, 0x99130110 }, /* speaker */
6458 { 0x18, 0x01a19c20 }, /* mic */
6459 { 0x21, 0x0121401f }, /* HP out */
6460 { }
6461 },
6462 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006463 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6464 .type = ALC_FIXUP_FUNC,
6465 .v.func = alc269_fixup_mic1_mute,
6466 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006467 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6468 .type = ALC_FIXUP_FUNC,
6469 .v.func = alc269_fixup_mic2_mute,
6470 },
David Henningsson693b6132012-06-22 19:12:10 +02006471 [ALC269_FIXUP_INV_DMIC] = {
6472 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006473 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006474 },
David Henningsson108cc102012-07-20 10:37:25 +02006475 [ALC269_FIXUP_LENOVO_DOCK] = {
6476 .type = ALC_FIXUP_PINS,
6477 .v.pins = (const struct alc_pincfg[]) {
6478 { 0x19, 0x23a11040 }, /* dock mic */
6479 { 0x1b, 0x2121103f }, /* dock headphone */
6480 { }
6481 },
6482 .chained = true,
6483 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6484 },
6485 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6486 .type = ALC_FIXUP_FUNC,
6487 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6488 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006489 [ALC271_FIXUP_AMIC_MIC2] = {
6490 .type = ALC_FIXUP_PINS,
6491 .v.pins = (const struct alc_pincfg[]) {
6492 { 0x14, 0x99130110 }, /* speaker */
6493 { 0x19, 0x01a19c20 }, /* mic */
6494 { 0x1b, 0x99a7012f }, /* int-mic */
6495 { 0x21, 0x0121401f }, /* HP out */
6496 { }
6497 },
6498 },
6499 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6500 .type = ALC_FIXUP_FUNC,
6501 .v.func = alc271_hp_gate_mic_jack,
6502 .chained = true,
6503 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6504 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006505};
6506
6507static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006508 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6509 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006510 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006511 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006512 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006513 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006514 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006515 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006516 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6517 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6518 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6519 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6520 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006521 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6522 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6523 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6524 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6525 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006526 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006527 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006528 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006529 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6530 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6531 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6532 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6533 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006534 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006535 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006536 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006537 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006538 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006539 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006540 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006541
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006542#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006543 /* Below is a quirk table taken from the old code.
6544 * Basically the device should work as is without the fixup table.
6545 * If BIOS doesn't give a proper info, enable the corresponding
6546 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006547 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006548 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6549 ALC269_FIXUP_AMIC),
6550 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006551 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6552 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6553 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6554 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6555 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6556 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6557 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6558 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6559 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6560 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6561 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6562 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6563 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6564 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6565 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6566 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6567 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6568 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6569 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6570 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6571 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6572 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6573 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6574 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6575 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6576 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6577 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6578 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6579 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6580 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6581 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6582 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6583 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6584 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6585 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6586 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6587 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6588 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6589#endif
6590 {}
6591};
6592
6593static const struct alc_model_fixup alc269_fixup_models[] = {
6594 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6595 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006596 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6597 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6598 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006599 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006600 {}
6601};
6602
6603
Takashi Iwai546bb672012-03-07 08:37:19 +01006604static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006605{
Kailang Yang526af6e2012-03-07 08:25:20 +01006606 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006607 int val;
6608
Kailang Yang526af6e2012-03-07 08:25:20 +01006609 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006610 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006611
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006612 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006613 alc_write_coef_idx(codec, 0xf, 0x960b);
6614 alc_write_coef_idx(codec, 0xe, 0x8817);
6615 }
6616
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006617 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006618 alc_write_coef_idx(codec, 0xf, 0x960b);
6619 alc_write_coef_idx(codec, 0xe, 0x8814);
6620 }
6621
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006622 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006623 val = alc_read_coef_idx(codec, 0x04);
6624 /* Power up output pin */
6625 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6626 }
6627
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006628 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006629 val = alc_read_coef_idx(codec, 0xd);
6630 if ((val & 0x0c00) >> 10 != 0x1) {
6631 /* Capless ramp up clock control */
6632 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6633 }
6634 val = alc_read_coef_idx(codec, 0x17);
6635 if ((val & 0x01c0) >> 6 != 0x4) {
6636 /* Class D power on reset */
6637 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6638 }
6639 }
6640
6641 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6642 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6643
6644 val = alc_read_coef_idx(codec, 0x4); /* HP */
6645 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006646}
6647
6648/*
6649 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006650static int patch_alc269(struct hda_codec *codec)
6651{
6652 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006653 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006654
Takashi Iwai3de95172012-05-07 18:03:15 +02006655 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006656 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006657 return err;
6658
6659 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006660
Herton Ronaldo Krzesinski9f720bb92012-09-27 10:38:14 -03006661 alc_pick_fixup(codec, alc269_fixup_models,
6662 alc269_fixup_tbl, alc269_fixups);
6663 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6664
6665 alc_auto_parse_customize_define(codec);
6666
Kailang Yang065380f2013-01-10 10:25:48 +01006667 switch (codec->vendor_id) {
6668 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006669 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006670 switch (alc_get_coef0(codec) & 0x00f0) {
6671 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006672 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006673 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006674 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006675 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006676 break;
6677 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006678 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6679 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006680 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006681 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006682 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006683 case 0x0030:
6684 spec->codec_variant = ALC269_TYPE_ALC269VD;
6685 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006686 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006687 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006688 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006689 if (err < 0)
6690 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006691 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006692 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006693 break;
6694
6695 case 0x10ec0280:
6696 case 0x10ec0290:
6697 spec->codec_variant = ALC269_TYPE_ALC280;
6698 break;
6699 case 0x10ec0282:
6700 case 0x10ec0283:
6701 spec->codec_variant = ALC269_TYPE_ALC282;
6702 break;
6703 case 0x10ec0284:
6704 case 0x10ec0292:
6705 spec->codec_variant = ALC269_TYPE_ALC284;
6706 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006707 }
6708
Takashi Iwaia4297b52011-08-23 18:40:12 +02006709 /* automatic parse from the BIOS config */
6710 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006711 if (err < 0)
6712 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006713
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006714 if (!spec->no_analog && has_cdefine_beep(codec)) {
6715 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006716 if (err < 0)
6717 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006718 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006719 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006720
Takashi Iwai1d045db2011-07-07 18:23:21 +02006721 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006722#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006723 codec->patch_ops.resume = alc269_resume;
6724#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006725 spec->shutup = alc269_shutup;
6726
Takashi Iwai589876e2012-02-20 15:47:55 +01006727 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6728
Takashi Iwai1d045db2011-07-07 18:23:21 +02006729 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006730
6731 error:
6732 alc_free(codec);
6733 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006734}
6735
6736/*
6737 * ALC861
6738 */
6739
Takashi Iwai1d045db2011-07-07 18:23:21 +02006740static int alc861_parse_auto_config(struct hda_codec *codec)
6741{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006742 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006743 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6744 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006745}
6746
Takashi Iwai1d045db2011-07-07 18:23:21 +02006747/* Pin config fixes */
6748enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006749 ALC861_FIXUP_FSC_AMILO_PI1505,
6750 ALC861_FIXUP_AMP_VREF_0F,
6751 ALC861_FIXUP_NO_JACK_DETECT,
6752 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006753};
6754
Takashi Iwai31150f22012-01-30 10:54:08 +01006755/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6756static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6757 const struct alc_fixup *fix, int action)
6758{
6759 struct alc_spec *spec = codec->spec;
6760 unsigned int val;
6761
6762 if (action != ALC_FIXUP_ACT_INIT)
6763 return;
6764 val = snd_hda_codec_read(codec, 0x0f, 0,
6765 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6766 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6767 val |= AC_PINCTL_IN_EN;
6768 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006769 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006770 spec->keep_vref_in_automute = 1;
6771}
6772
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006773/* suppress the jack-detection */
6774static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6775 const struct alc_fixup *fix, int action)
6776{
6777 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6778 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006779}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006780
Takashi Iwai1d045db2011-07-07 18:23:21 +02006781static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006782 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006783 .type = ALC_FIXUP_PINS,
6784 .v.pins = (const struct alc_pincfg[]) {
6785 { 0x0b, 0x0221101f }, /* HP */
6786 { 0x0f, 0x90170310 }, /* speaker */
6787 { }
6788 }
6789 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006790 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006791 .type = ALC_FIXUP_FUNC,
6792 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006793 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006794 [ALC861_FIXUP_NO_JACK_DETECT] = {
6795 .type = ALC_FIXUP_FUNC,
6796 .v.func = alc_fixup_no_jack_detect,
6797 },
6798 [ALC861_FIXUP_ASUS_A6RP] = {
6799 .type = ALC_FIXUP_FUNC,
6800 .v.func = alc861_fixup_asus_amp_vref_0f,
6801 .chained = true,
6802 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6803 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006804};
6805
6806static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006807 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6808 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6809 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6810 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6811 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6812 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006813 {}
6814};
6815
6816/*
6817 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006818static int patch_alc861(struct hda_codec *codec)
6819{
6820 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006821 int err;
6822
Takashi Iwai3de95172012-05-07 18:03:15 +02006823 err = alc_alloc_spec(codec, 0x15);
6824 if (err < 0)
6825 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006826
Takashi Iwai3de95172012-05-07 18:03:15 +02006827 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006828
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006829 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6830 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006831
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006832 /* automatic parse from the BIOS config */
6833 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006834 if (err < 0)
6835 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006836
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006837 if (!spec->no_analog) {
6838 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006839 if (err < 0)
6840 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006841 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6842 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006843
Takashi Iwai1d045db2011-07-07 18:23:21 +02006844 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006845#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006846 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006847#endif
6848
Takashi Iwai589876e2012-02-20 15:47:55 +01006849 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6850
Takashi Iwai1d045db2011-07-07 18:23:21 +02006851 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006852
6853 error:
6854 alc_free(codec);
6855 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006856}
6857
6858/*
6859 * ALC861-VD support
6860 *
6861 * Based on ALC882
6862 *
6863 * In addition, an independent DAC
6864 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006865static int alc861vd_parse_auto_config(struct hda_codec *codec)
6866{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006867 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006868 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6869 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006870}
6871
Takashi Iwai1d045db2011-07-07 18:23:21 +02006872enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006873 ALC660VD_FIX_ASUS_GPIO1,
6874 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006875};
6876
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006877/* exclude VREF80 */
6878static void alc861vd_fixup_dallas(struct hda_codec *codec,
6879 const struct alc_fixup *fix, int action)
6880{
6881 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006882 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6883 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006884 }
6885}
6886
Takashi Iwai1d045db2011-07-07 18:23:21 +02006887static const struct alc_fixup alc861vd_fixups[] = {
6888 [ALC660VD_FIX_ASUS_GPIO1] = {
6889 .type = ALC_FIXUP_VERBS,
6890 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006891 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006892 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6893 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6894 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6895 { }
6896 }
6897 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006898 [ALC861VD_FIX_DALLAS] = {
6899 .type = ALC_FIXUP_FUNC,
6900 .v.func = alc861vd_fixup_dallas,
6901 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006902};
6903
6904static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006905 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006906 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006907 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006908 {}
6909};
6910
Takashi Iwai1d045db2011-07-07 18:23:21 +02006911/*
6912 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006913static int patch_alc861vd(struct hda_codec *codec)
6914{
6915 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006916 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006917
Takashi Iwai3de95172012-05-07 18:03:15 +02006918 err = alc_alloc_spec(codec, 0x0b);
6919 if (err < 0)
6920 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006921
Takashi Iwai3de95172012-05-07 18:03:15 +02006922 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006923
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006924 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6925 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006926
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006927 /* automatic parse from the BIOS config */
6928 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006929 if (err < 0)
6930 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006931
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006932 if (!spec->no_analog) {
6933 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006934 if (err < 0)
6935 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006936 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6937 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006938
Takashi Iwai1d045db2011-07-07 18:23:21 +02006939 codec->patch_ops = alc_patch_ops;
6940
Takashi Iwai1d045db2011-07-07 18:23:21 +02006941 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006942
Takashi Iwai589876e2012-02-20 15:47:55 +01006943 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6944
Takashi Iwai1d045db2011-07-07 18:23:21 +02006945 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006946
6947 error:
6948 alc_free(codec);
6949 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006950}
6951
6952/*
6953 * ALC662 support
6954 *
6955 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6956 * configuration. Each pin widget can choose any input DACs and a mixer.
6957 * Each ADC is connected from a mixer of all inputs. This makes possible
6958 * 6-channel independent captures.
6959 *
6960 * In addition, an independent DAC for the multi-playback (not used in this
6961 * driver yet).
6962 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006963
6964/*
6965 * BIOS auto configuration
6966 */
6967
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006968static int alc662_parse_auto_config(struct hda_codec *codec)
6969{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006970 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006971 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6972 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6973 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006974
Kailang Yang6227cdc2010-02-25 08:36:52 +01006975 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6976 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006977 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006978 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006979 ssids = alc662_ssids;
6980 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006981}
6982
Todd Broch6be79482010-12-07 16:51:05 -08006983static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006984 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006985{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006986 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006987 return;
Todd Broch6be79482010-12-07 16:51:05 -08006988 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6989 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6990 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6991 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6992 (0 << AC_AMPCAP_MUTE_SHIFT)))
6993 printk(KERN_WARNING
6994 "hda_codec: failed to override amp caps for NID 0x2\n");
6995}
6996
David Henningsson6cb3b702010-09-09 08:51:44 +02006997enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006998 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006999 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08007000 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007001 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02007002 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007003 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02007004 ALC662_FIXUP_ASUS_MODE1,
7005 ALC662_FIXUP_ASUS_MODE2,
7006 ALC662_FIXUP_ASUS_MODE3,
7007 ALC662_FIXUP_ASUS_MODE4,
7008 ALC662_FIXUP_ASUS_MODE5,
7009 ALC662_FIXUP_ASUS_MODE6,
7010 ALC662_FIXUP_ASUS_MODE7,
7011 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01007012 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02007013 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02007014 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02007015};
7016
7017static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04007018 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007019 .type = ALC_FIXUP_PINS,
7020 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04007021 { 0x15, 0x99130112 }, /* subwoofer */
7022 { }
7023 }
7024 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007025 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007026 .type = ALC_FIXUP_PINS,
7027 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02007028 { 0x17, 0x99130112 }, /* subwoofer */
7029 { }
7030 }
7031 },
Todd Broch6be79482010-12-07 16:51:05 -08007032 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007033 .type = ALC_FIXUP_FUNC,
7034 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007035 },
7036 [ALC662_FIXUP_CZC_P10T] = {
7037 .type = ALC_FIXUP_VERBS,
7038 .v.verbs = (const struct hda_verb[]) {
7039 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7040 {}
7041 }
7042 },
David Henningsson94024cd2011-04-29 14:10:55 +02007043 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02007044 .type = ALC_FIXUP_FUNC,
7045 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02007046 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007047 [ALC662_FIXUP_HP_RP5800] = {
7048 .type = ALC_FIXUP_PINS,
7049 .v.pins = (const struct alc_pincfg[]) {
7050 { 0x14, 0x0221201f }, /* HP out */
7051 { }
7052 },
7053 .chained = true,
7054 .chain_id = ALC662_FIXUP_SKU_IGNORE
7055 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007056 [ALC662_FIXUP_ASUS_MODE1] = {
7057 .type = ALC_FIXUP_PINS,
7058 .v.pins = (const struct alc_pincfg[]) {
7059 { 0x14, 0x99130110 }, /* speaker */
7060 { 0x18, 0x01a19c20 }, /* mic */
7061 { 0x19, 0x99a3092f }, /* int-mic */
7062 { 0x21, 0x0121401f }, /* HP out */
7063 { }
7064 },
7065 .chained = true,
7066 .chain_id = ALC662_FIXUP_SKU_IGNORE
7067 },
7068 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007069 .type = ALC_FIXUP_PINS,
7070 .v.pins = (const struct alc_pincfg[]) {
7071 { 0x14, 0x99130110 }, /* speaker */
7072 { 0x18, 0x01a19820 }, /* mic */
7073 { 0x19, 0x99a3092f }, /* int-mic */
7074 { 0x1b, 0x0121401f }, /* HP out */
7075 { }
7076 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007077 .chained = true,
7078 .chain_id = ALC662_FIXUP_SKU_IGNORE
7079 },
7080 [ALC662_FIXUP_ASUS_MODE3] = {
7081 .type = ALC_FIXUP_PINS,
7082 .v.pins = (const struct alc_pincfg[]) {
7083 { 0x14, 0x99130110 }, /* speaker */
7084 { 0x15, 0x0121441f }, /* HP */
7085 { 0x18, 0x01a19840 }, /* mic */
7086 { 0x19, 0x99a3094f }, /* int-mic */
7087 { 0x21, 0x01211420 }, /* HP2 */
7088 { }
7089 },
7090 .chained = true,
7091 .chain_id = ALC662_FIXUP_SKU_IGNORE
7092 },
7093 [ALC662_FIXUP_ASUS_MODE4] = {
7094 .type = ALC_FIXUP_PINS,
7095 .v.pins = (const struct alc_pincfg[]) {
7096 { 0x14, 0x99130110 }, /* speaker */
7097 { 0x16, 0x99130111 }, /* speaker */
7098 { 0x18, 0x01a19840 }, /* mic */
7099 { 0x19, 0x99a3094f }, /* int-mic */
7100 { 0x21, 0x0121441f }, /* HP */
7101 { }
7102 },
7103 .chained = true,
7104 .chain_id = ALC662_FIXUP_SKU_IGNORE
7105 },
7106 [ALC662_FIXUP_ASUS_MODE5] = {
7107 .type = ALC_FIXUP_PINS,
7108 .v.pins = (const struct alc_pincfg[]) {
7109 { 0x14, 0x99130110 }, /* speaker */
7110 { 0x15, 0x0121441f }, /* HP */
7111 { 0x16, 0x99130111 }, /* speaker */
7112 { 0x18, 0x01a19840 }, /* mic */
7113 { 0x19, 0x99a3094f }, /* int-mic */
7114 { }
7115 },
7116 .chained = true,
7117 .chain_id = ALC662_FIXUP_SKU_IGNORE
7118 },
7119 [ALC662_FIXUP_ASUS_MODE6] = {
7120 .type = ALC_FIXUP_PINS,
7121 .v.pins = (const struct alc_pincfg[]) {
7122 { 0x14, 0x99130110 }, /* speaker */
7123 { 0x15, 0x01211420 }, /* HP2 */
7124 { 0x18, 0x01a19840 }, /* mic */
7125 { 0x19, 0x99a3094f }, /* int-mic */
7126 { 0x1b, 0x0121441f }, /* HP */
7127 { }
7128 },
7129 .chained = true,
7130 .chain_id = ALC662_FIXUP_SKU_IGNORE
7131 },
7132 [ALC662_FIXUP_ASUS_MODE7] = {
7133 .type = ALC_FIXUP_PINS,
7134 .v.pins = (const struct alc_pincfg[]) {
7135 { 0x14, 0x99130110 }, /* speaker */
7136 { 0x17, 0x99130111 }, /* speaker */
7137 { 0x18, 0x01a19840 }, /* mic */
7138 { 0x19, 0x99a3094f }, /* int-mic */
7139 { 0x1b, 0x01214020 }, /* HP */
7140 { 0x21, 0x0121401f }, /* HP */
7141 { }
7142 },
7143 .chained = true,
7144 .chain_id = ALC662_FIXUP_SKU_IGNORE
7145 },
7146 [ALC662_FIXUP_ASUS_MODE8] = {
7147 .type = ALC_FIXUP_PINS,
7148 .v.pins = (const struct alc_pincfg[]) {
7149 { 0x14, 0x99130110 }, /* speaker */
7150 { 0x12, 0x99a30970 }, /* int-mic */
7151 { 0x15, 0x01214020 }, /* HP */
7152 { 0x17, 0x99130111 }, /* speaker */
7153 { 0x18, 0x01a19840 }, /* mic */
7154 { 0x21, 0x0121401f }, /* HP */
7155 { }
7156 },
7157 .chained = true,
7158 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007159 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007160 [ALC662_FIXUP_NO_JACK_DETECT] = {
7161 .type = ALC_FIXUP_FUNC,
7162 .v.func = alc_fixup_no_jack_detect,
7163 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007164 [ALC662_FIXUP_ZOTAC_Z68] = {
7165 .type = ALC_FIXUP_PINS,
7166 .v.pins = (const struct alc_pincfg[]) {
7167 { 0x1b, 0x02214020 }, /* Front HP */
7168 { }
7169 }
7170 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007171 [ALC662_FIXUP_INV_DMIC] = {
7172 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007173 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007174 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007175};
7176
Takashi Iwaia9111322011-05-02 11:30:18 +02007177static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007178 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007179 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007180 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007181 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007182 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007183 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007184 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007185 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007186 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007187 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007188 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007189 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007190 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007191
7192#if 0
7193 /* Below is a quirk table taken from the old code.
7194 * Basically the device should work as is without the fixup table.
7195 * If BIOS doesn't give a proper info, enable the corresponding
7196 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007197 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007198 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7199 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7200 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7201 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7202 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7203 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7204 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7205 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7206 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7207 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7208 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7209 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7210 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7211 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7212 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7213 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7214 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7215 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7216 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7217 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7218 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7219 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7220 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7221 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7222 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7223 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7224 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7225 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7226 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7227 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7228 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7229 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7230 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7231 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7232 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7233 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7234 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7235 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7236 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7237 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7238 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7239 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7240 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7241 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7242 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7243 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7244 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7245 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7246 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7247 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7248#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007249 {}
7250};
7251
Todd Broch6be79482010-12-07 16:51:05 -08007252static const struct alc_model_fixup alc662_fixup_models[] = {
7253 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007254 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7255 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7256 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7257 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7258 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7259 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7260 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7261 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007262 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007263 {}
7264};
David Henningsson6cb3b702010-09-09 08:51:44 +02007265
Kailang Yang8663ff72012-06-29 09:35:52 +02007266static void alc662_fill_coef(struct hda_codec *codec)
7267{
7268 int val, coef;
7269
7270 coef = alc_get_coef0(codec);
7271
7272 switch (codec->vendor_id) {
7273 case 0x10ec0662:
7274 if ((coef & 0x00f0) == 0x0030) {
7275 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7276 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7277 }
7278 break;
7279 case 0x10ec0272:
7280 case 0x10ec0273:
7281 case 0x10ec0663:
7282 case 0x10ec0665:
7283 case 0x10ec0670:
7284 case 0x10ec0671:
7285 case 0x10ec0672:
7286 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7287 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7288 break;
7289 }
7290}
David Henningsson6cb3b702010-09-09 08:51:44 +02007291
Takashi Iwai1d045db2011-07-07 18:23:21 +02007292/*
7293 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007294static int patch_alc662(struct hda_codec *codec)
7295{
7296 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007297 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007298
Takashi Iwai3de95172012-05-07 18:03:15 +02007299 err = alc_alloc_spec(codec, 0x0b);
7300 if (err < 0)
7301 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007302
Takashi Iwai3de95172012-05-07 18:03:15 +02007303 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007304
Takashi Iwai53c334a2011-08-23 18:27:14 +02007305 /* handle multiple HPs as is */
7306 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7307
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007308 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7309
Kailang Yang8663ff72012-06-29 09:35:52 +02007310 spec->init_hook = alc662_fill_coef;
7311 alc662_fill_coef(codec);
7312
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007313 alc_pick_fixup(codec, alc662_fixup_models,
7314 alc662_fixup_tbl, alc662_fixups);
7315 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7316
7317 alc_auto_parse_customize_define(codec);
7318
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007319 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007320 codec->bus->pci->subsystem_vendor == 0x1025 &&
7321 spec->cdefine.platform_type == 1) {
7322 if (alc_codec_rename(codec, "ALC272X") < 0)
7323 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007324 }
Kailang Yang274693f2009-12-03 10:07:50 +01007325
Takashi Iwaib9c51062011-08-24 18:08:07 +02007326 /* automatic parse from the BIOS config */
7327 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007328 if (err < 0)
7329 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007330
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007331 if (!spec->no_analog && has_cdefine_beep(codec)) {
7332 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007333 if (err < 0)
7334 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007335 switch (codec->vendor_id) {
7336 case 0x10ec0662:
7337 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7338 break;
7339 case 0x10ec0272:
7340 case 0x10ec0663:
7341 case 0x10ec0665:
7342 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7343 break;
7344 case 0x10ec0273:
7345 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7346 break;
7347 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007348 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007349
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007350 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02007351 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007352
Takashi Iwai589876e2012-02-20 15:47:55 +01007353 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7354
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007355 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007356
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007357 error:
7358 alc_free(codec);
7359 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007360}
7361
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007362/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007363 * ALC680 support
7364 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007365
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007366static int alc680_parse_auto_config(struct hda_codec *codec)
7367{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007368 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007369}
7370
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007371/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007372 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007373static int patch_alc680(struct hda_codec *codec)
7374{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007375 int err;
7376
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007377 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007378 err = alc_alloc_spec(codec, 0);
7379 if (err < 0)
7380 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007381
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007382 /* automatic parse from the BIOS config */
7383 err = alc680_parse_auto_config(codec);
7384 if (err < 0) {
7385 alc_free(codec);
7386 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007387 }
7388
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007389 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007390
7391 return 0;
7392}
7393
7394/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007395 * patch entries
7396 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007397static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007398 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007399 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007400 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007401 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007402 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007403 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007404 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007405 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007406 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007407 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007408 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007409 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007410 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007411 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007412 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007413 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007414 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007415 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007416 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7417 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7418 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007419 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007420 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007421 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7422 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007423 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7424 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007425 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007426 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007427 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007428 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007429 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007430 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007431 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007432 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007433 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007434 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007435 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007436 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007437 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007438 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007439 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007440 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007441 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007442 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007443 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007444 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007445 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007446 {} /* terminator */
7447};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007448
7449MODULE_ALIAS("snd-hda-codec-id:10ec*");
7450
7451MODULE_LICENSE("GPL");
7452MODULE_DESCRIPTION("Realtek HD-audio codec");
7453
7454static struct hda_codec_preset_list realtek_list = {
7455 .preset = snd_hda_preset_realtek,
7456 .owner = THIS_MODULE,
7457};
7458
7459static int __init patch_realtek_init(void)
7460{
7461 return snd_hda_add_codec_preset(&realtek_list);
7462}
7463
7464static void __exit patch_realtek_exit(void)
7465{
7466 snd_hda_delete_codec_preset(&realtek_list);
7467}
7468
7469module_init(patch_realtek_init)
7470module_exit(patch_realtek_exit)