blob: 8b768a566be0d2b09ce81bda441a30c2e5ef0545 [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 Iwaid922b512011-04-28 12:18:53 +020076enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020077 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020080};
81
Takashi Iwaic14c95f2012-02-16 16:38:07 +010082#define MAX_VOL_NIDS 0x40
83
Takashi Iwai23d30f22012-05-07 17:17:32 +020084/* make compatible with old code */
85#define alc_apply_pincfgs snd_hda_apply_pincfgs
86#define alc_apply_fixup snd_hda_apply_fixup
87#define alc_pick_fixup snd_hda_pick_fixup
88#define alc_fixup hda_fixup
89#define alc_pincfg hda_pintbl
90#define alc_model_fixup hda_model_fixup
91
92#define ALC_FIXUP_PINS HDA_FIXUP_PINS
93#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
95
96#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
100
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200103 struct hda_gen_spec gen;
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200106 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +0200108 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100109 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200111 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200112 const struct hda_pcm_stream *stream_analog_playback;
113 const struct hda_pcm_stream *stream_analog_capture;
114 const struct hda_pcm_stream *stream_analog_alt_playback;
115 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200117 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200118 const struct hda_pcm_stream *stream_digital_playback;
119 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200122 struct hda_multi_out multiout; /* playback set-up
123 * max_channels, dacs must be set
124 * dig_out_nid and hp_nid are optional
125 */
Takashi Iwai63300792008-01-24 15:31:36 +0100126 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100127 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100128 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 /* capture */
131 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200132 const hda_nid_t *adc_nids;
133 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200134 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200135 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwaic14c95f2012-02-16 16:38:07 +0100136 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
137 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Takashi Iwai840b64c2010-07-13 22:49:01 +0200139 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200140 hda_nid_t cur_adc;
141 unsigned int cur_adc_stream_tag;
142 unsigned int cur_adc_format;
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200145 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 const struct hda_input_mux *input_mux;
147 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200148 hda_nid_t ext_mic_pin;
149 hda_nid_t dock_mic_pin;
150 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100153 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200155 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100156 int const_channel_count; /* min. channel count (for speakers) */
157 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100160 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200161
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200162 /* dynamic controls, init_verbs and input_mux */
163 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100164 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200165 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200166 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200167 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200168 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
169 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200170 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
171 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
172 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200173 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100174
Takashi Iwai463419d2012-12-05 14:17:37 +0100175 /* DAC list */
176 int num_all_dacs;
177 hda_nid_t all_dacs[16];
178
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100179 /* hooks */
180 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200181#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500182 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100183#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200184 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200185 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100186
Takashi Iwai834be882006-03-01 14:16:17 +0100187 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200188 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200189 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200190 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200191 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200192 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200193 unsigned int automute_speaker:1; /* automute speaker outputs */
194 unsigned int automute_lo:1; /* automute LO outputs */
195 unsigned int detect_hp:1; /* Headphone detection enabled */
196 unsigned int detect_lo:1; /* Line-out detection enabled */
197 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
198 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100199 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200200
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100201 /* other flags */
202 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200203 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100204 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200205 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200206 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100207 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200208 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
209 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200210 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200211
212 /* auto-mute control */
213 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200214 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200215
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200216 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200217 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100218
Takashi Iwai2134ea42008-01-10 16:53:55 +0100219 /* for virtual master */
220 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100221 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200222#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200223 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100224 int num_loopbacks;
225 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200226#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200227
228 /* for PLL fix */
229 hda_nid_t pll_nid;
230 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200231 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100232
Takashi Iwaice764ab2011-04-27 16:35:23 +0200233 /* multi-io */
234 int multi_ios;
235 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200236
237 /* bind volumes */
238 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100239};
240
Takashi Iwai44c02402011-07-08 15:14:19 +0200241static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
242 int dir, unsigned int bits)
243{
244 if (!nid)
245 return false;
246 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
247 if (query_amp_caps(codec, nid, dir) & bits)
248 return true;
249 return false;
250}
251
252#define nid_has_mute(codec, nid, dir) \
253 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
254#define nid_has_volume(codec, nid, dir) \
255 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257/*
258 * input MUX handling
259 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200260static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
261 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
263 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
264 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200265 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
266 if (mux_idx >= spec->num_mux_defs)
267 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100268 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
269 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200270 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
272
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200273static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
274 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
276 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
277 struct alc_spec *spec = codec->spec;
278 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
279
280 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
281 return 0;
282}
283
Takashi Iwai21268962011-07-07 15:01:13 +0200284static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
Takashi Iwai21268962011-07-07 15:01:13 +0200286 struct alc_spec *spec = codec->spec;
287 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
288
289 if (spec->cur_adc && spec->cur_adc != new_adc) {
290 /* stream is running, let's swap the current ADC */
291 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
292 spec->cur_adc = new_adc;
293 snd_hda_codec_setup_stream(codec, new_adc,
294 spec->cur_adc_stream_tag, 0,
295 spec->cur_adc_format);
296 return true;
297 }
298 return false;
299}
300
Takashi Iwai61071592011-11-23 07:52:15 +0100301static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
302{
303 return spec->capsrc_nids ?
304 spec->capsrc_nids[idx] : spec->adc_nids[idx];
305}
306
Takashi Iwai24de1832011-11-07 17:13:39 +0100307static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200308static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100309
David Henningsson00227f12012-06-27 18:45:44 +0200310/* for shared I/O, change the pin-control accordingly */
311static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
312{
313 struct alc_spec *spec = codec->spec;
314 unsigned int val;
315 hda_nid_t pin = spec->autocfg.inputs[1].pin;
316 /* NOTE: this assumes that there are only two inputs, the
317 * first is the real internal mic and the second is HP/mic jack.
318 */
319
320 val = snd_hda_get_default_vref(codec, pin);
321
322 /* This pin does not have vref caps - let's enable vref on pin 0x18
323 instead, as suggested by Realtek */
324 if (val == AC_PINCTL_VREF_HIZ) {
325 const hda_nid_t vref_pin = 0x18;
326 /* Sanity check pin 0x18 */
327 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
328 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
329 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
330 if (vref_val != AC_PINCTL_VREF_HIZ)
331 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
332 }
333 }
334
335 val = set_as_mic ? val | PIN_IN : PIN_HP;
336 snd_hda_set_pin_ctl(codec, pin, val);
337
338 spec->automute_speaker = !set_as_mic;
339 call_update_outputs(codec);
340}
Takashi Iwai21268962011-07-07 15:01:13 +0200341
342/* select the given imux item; either unmute exclusively or select the route */
343static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
344 unsigned int idx, bool force)
345{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100347 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100348 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100349 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200350 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Takashi Iwai5803a322012-02-21 11:59:45 +0100352 if (!spec->input_mux)
353 return 0;
354
Takashi Iwaicd896c32008-11-18 12:36:33 +0100355 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
356 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100357 if (!imux->num_items && mux_idx > 0)
358 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100359 if (!imux->num_items)
360 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100361
Takashi Iwai21268962011-07-07 15:01:13 +0200362 if (idx >= imux->num_items)
363 idx = imux->num_items - 1;
364 if (spec->cur_mux[adc_idx] == idx && !force)
365 return 0;
366 spec->cur_mux[adc_idx] = idx;
367
David Henningsson00227f12012-06-27 18:45:44 +0200368 if (spec->shared_mic_hp)
369 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100370
Takashi Iwai21268962011-07-07 15:01:13 +0200371 if (spec->dyn_adc_switch) {
372 alc_dyn_adc_pcm_resetup(codec, idx);
373 adc_idx = spec->dyn_adc_idx[idx];
374 }
375
Takashi Iwai61071592011-11-23 07:52:15 +0100376 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200377
378 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200379 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100380 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200381 return 1;
382
Takashi Iwaia22d5432009-07-27 12:54:26 +0200383 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200384 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100385 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100386 int active = imux->items[idx].index;
387 for (i = 0; i < num_conns; i++) {
388 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
389 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100390 HDA_AMP_MUTE, v);
391 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100392 } else {
393 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200394 snd_hda_codec_write_cache(codec, nid, 0,
395 AC_VERB_SET_CONNECT_SEL,
396 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100397 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200398 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200399 return 1;
400}
401
402static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
403 struct snd_ctl_elem_value *ucontrol)
404{
405 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
406 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
407 return alc_mux_select(codec, adc_idx,
408 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100409}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100412 * set up the input pin config (depending on the given auto-pin type)
413 */
414static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
415 int auto_pin_type)
416{
417 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200418 if (auto_pin_type == AUTO_PIN_MIC)
419 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200420 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100421}
422
423/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200424 * Append the given mixer and verb elements for the later use
425 * The mixer array is referred in build_controls(), and init_verbs are
426 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100427 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200428static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100429{
430 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
431 return;
432 spec->mixers[spec->num_mixers++] = mix;
433}
434
Takashi Iwaid88897e2008-10-31 15:01:37 +0100435/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200436 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100437 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200438/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200439static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200440 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
441 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
442 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
443 { }
444};
445
Takashi Iwaia9111322011-05-02 11:30:18 +0200446static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200447 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
448 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
449 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
450 { }
451};
452
Takashi Iwaia9111322011-05-02 11:30:18 +0200453static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200454 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
455 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
456 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
457 { }
458};
459
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200460/*
461 * Fix hardware PLL issue
462 * On some codecs, the analog PLL gating control must be off while
463 * the default value is 1.
464 */
465static void alc_fix_pll(struct hda_codec *codec)
466{
467 struct alc_spec *spec = codec->spec;
468 unsigned int val;
469
470 if (!spec->pll_nid)
471 return;
472 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
473 spec->pll_coef_idx);
474 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
475 AC_VERB_GET_PROC_COEF, 0);
476 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
477 spec->pll_coef_idx);
478 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
479 val & ~(1 << spec->pll_coef_bit));
480}
481
482static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
483 unsigned int coef_idx, unsigned int coef_bit)
484{
485 struct alc_spec *spec = codec->spec;
486 spec->pll_nid = nid;
487 spec->pll_coef_idx = coef_idx;
488 spec->pll_coef_bit = coef_bit;
489 alc_fix_pll(codec);
490}
491
Takashi Iwai1d045db2011-07-07 18:23:21 +0200492/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200493 * Jack detections for HP auto-mute and mic-switch
494 */
495
496/* check each pin in the given array; returns true if any of them is plugged */
497static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200498{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200499 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200500
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 for (i = 0; i < num_pins; i++) {
502 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200503 if (!nid)
504 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200505 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200506 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507 return present;
508}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200509
Takashi Iwai1d045db2011-07-07 18:23:21 +0200510/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200511static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200512 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200513{
514 struct alc_spec *spec = codec->spec;
515 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200516 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 int i;
518
519 for (i = 0; i < num_pins; i++) {
520 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100521 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200522 if (!nid)
523 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200524 switch (spec->automute_mode) {
525 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100526 /* don't reset VREF value in case it's controlling
527 * the amp (see alc861_fixup_asus_amp_vref_0f())
528 */
529 if (spec->keep_vref_in_automute) {
530 val = snd_hda_codec_read(codec, nid, 0,
531 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
532 val &= ~PIN_HP;
533 } else
534 val = 0;
535 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200536 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200537 break;
538 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200539 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200540 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200541 break;
542 case ALC_AUTOMUTE_MIXER:
543 nid = spec->automute_mixer_nid[i];
544 if (!nid)
545 break;
546 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200547 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200548 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200549 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200550 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200551 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200552 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200553}
554
David Henningsson42cf0d02011-09-20 12:04:56 +0200555/* Toggle outputs muting */
556static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200557{
558 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200559 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200560
Takashi Iwaic0a20262011-06-10 15:28:15 +0200561 /* Control HP pins/amps depending on master_mute state;
562 * in general, HP pins/amps control should be enabled in all cases,
563 * but currently set only for master_mute, just to be safe
564 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100565 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
566 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200567 spec->autocfg.hp_pins, spec->master_mute, true);
568
David Henningsson42cf0d02011-09-20 12:04:56 +0200569 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 on = 0;
571 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200572 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200573 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200574 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200575 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200576
577 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200578 /* if LO is a copy of either HP or Speaker, don't need to handle it */
579 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
580 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200581 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200582 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200583 on = 0;
584 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200585 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200586 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200587 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200588 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200589}
590
David Henningsson42cf0d02011-09-20 12:04:56 +0200591static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200592{
593 struct alc_spec *spec = codec->spec;
594 if (spec->automute_hook)
595 spec->automute_hook(codec);
596 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200597 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200598}
599
Takashi Iwai1d045db2011-07-07 18:23:21 +0200600/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200601static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602{
603 struct alc_spec *spec = codec->spec;
604
David Henningsson42cf0d02011-09-20 12:04:56 +0200605 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200606 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
607 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200608 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200609 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200610 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200611}
612
Takashi Iwai1d045db2011-07-07 18:23:21 +0200613/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200614static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200615{
616 struct alc_spec *spec = codec->spec;
617
David Henningssonf7f4b2322012-10-10 16:32:09 +0200618 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
619 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200620 /* check LO jack only when it's different from HP */
621 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
622 return;
623
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200624 spec->line_jack_present =
625 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
626 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200627 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200628 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200629 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200630}
631
Takashi Iwai8d087c72011-06-28 12:45:47 +0200632#define get_connection_index(codec, mux, nid) \
633 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200634
Takashi Iwai1d045db2011-07-07 18:23:21 +0200635/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200636static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200637{
638 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200639 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200640
Takashi Iwai21268962011-07-07 15:01:13 +0200641 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200642 return;
643 if (snd_BUG_ON(!spec->adc_nids))
644 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200645 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200646 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200647
Takashi Iwai21268962011-07-07 15:01:13 +0200648 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
649 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
650 else if (spec->dock_mic_idx >= 0 &&
651 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
652 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
653 else
654 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200655}
656
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100657/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200658static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100659{
660 unsigned int val;
661 struct snd_kcontrol *kctl;
662 struct snd_ctl_elem_value *uctl;
663
664 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
665 if (!kctl)
666 return;
667 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
668 if (!uctl)
669 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200670 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100671 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
672 val &= HDA_AMP_VOLMASK;
673 uctl->value.integer.value[0] = val;
674 uctl->value.integer.value[1] = val;
675 kctl->put(kctl, uctl);
676 kfree(uctl);
677}
678
David Henningsson29adc4b2012-09-25 11:31:00 +0200679static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100680{
David Henningsson29adc4b2012-09-25 11:31:00 +0200681 /* For some reason, the res given from ALC880 is broken.
682 Here we adjust it properly. */
683 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100684}
685
Takashi Iwai1d045db2011-07-07 18:23:21 +0200686/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200687static void alc_inithook(struct hda_codec *codec)
688{
David Henningsson29adc4b2012-09-25 11:31:00 +0200689 alc_hp_automute(codec, NULL);
690 alc_line_automute(codec, NULL);
691 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200692}
693
Kailang Yangf9423e72008-05-27 12:32:25 +0200694/* additional initialization for ALC888 variants */
695static void alc888_coef_init(struct hda_codec *codec)
696{
697 unsigned int tmp;
698
699 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
700 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
701 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100702 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200703 /* alc888S-VC */
704 snd_hda_codec_read(codec, 0x20, 0,
705 AC_VERB_SET_PROC_COEF, 0x830);
706 else
707 /* alc888-VB */
708 snd_hda_codec_read(codec, 0x20, 0,
709 AC_VERB_SET_PROC_COEF, 0x3030);
710}
711
Takashi Iwai1d045db2011-07-07 18:23:21 +0200712/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200713static void alc889_coef_init(struct hda_codec *codec)
714{
715 unsigned int tmp;
716
717 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
718 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
719 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
720 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
721}
722
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100723/* turn on/off EAPD control (only if available) */
724static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
725{
726 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
727 return;
728 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
729 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
730 on ? 2 : 0);
731}
732
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200733/* turn on/off EAPD controls of the codec */
734static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
735{
736 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200737 static hda_nid_t pins[] = {
738 0x0f, 0x10, 0x14, 0x15, 0
739 };
740 hda_nid_t *p;
741 for (p = pins; *p; p++)
742 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200743}
744
Takashi Iwai1c716152011-04-07 10:37:16 +0200745/* generic shutup callback;
746 * just turning off EPAD and a little pause for avoiding pop-noise
747 */
748static void alc_eapd_shutup(struct hda_codec *codec)
749{
750 alc_auto_setup_eapd(codec, false);
751 msleep(200);
752}
753
Takashi Iwai1d045db2011-07-07 18:23:21 +0200754/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200755static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200756{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200757 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200758
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200759 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200760 switch (type) {
761 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200762 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
763 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200764 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200765 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
766 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200767 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200768 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
769 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200771 switch (codec->vendor_id) {
772 case 0x10ec0260:
773 snd_hda_codec_write(codec, 0x1a, 0,
774 AC_VERB_SET_COEF_INDEX, 7);
775 tmp = snd_hda_codec_read(codec, 0x1a, 0,
776 AC_VERB_GET_PROC_COEF, 0);
777 snd_hda_codec_write(codec, 0x1a, 0,
778 AC_VERB_SET_COEF_INDEX, 7);
779 snd_hda_codec_write(codec, 0x1a, 0,
780 AC_VERB_SET_PROC_COEF,
781 tmp | 0x2010);
782 break;
783 case 0x10ec0262:
784 case 0x10ec0880:
785 case 0x10ec0882:
786 case 0x10ec0883:
787 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100788 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100789 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200790 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200791 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200792 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200793 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200794 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100795#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200796 case 0x10ec0267:
797 case 0x10ec0268:
798 snd_hda_codec_write(codec, 0x20, 0,
799 AC_VERB_SET_COEF_INDEX, 7);
800 tmp = snd_hda_codec_read(codec, 0x20, 0,
801 AC_VERB_GET_PROC_COEF, 0);
802 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200803 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200804 snd_hda_codec_write(codec, 0x20, 0,
805 AC_VERB_SET_PROC_COEF,
806 tmp | 0x3000);
807 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100808#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200809 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200810 break;
811 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200812}
Kailang Yangea1fb292008-08-26 12:58:38 +0200813
Takashi Iwai1d045db2011-07-07 18:23:21 +0200814/*
815 * Auto-Mute mode mixer enum support
816 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200817static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
818 struct snd_ctl_elem_info *uinfo)
819{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200820 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
821 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200822 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100823 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200824 };
825
Takashi Iwaidda415d2012-11-30 18:34:38 +0100826 if (spec->automute_speaker_possible && spec->automute_lo_possible)
827 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
828 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200829}
830
831static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
832 struct snd_ctl_elem_value *ucontrol)
833{
834 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
835 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200836 unsigned int val = 0;
837 if (spec->automute_speaker)
838 val++;
839 if (spec->automute_lo)
840 val++;
841
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200842 ucontrol->value.enumerated.item[0] = val;
843 return 0;
844}
845
846static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
847 struct snd_ctl_elem_value *ucontrol)
848{
849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
850 struct alc_spec *spec = codec->spec;
851
852 switch (ucontrol->value.enumerated.item[0]) {
853 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200854 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200855 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200856 spec->automute_speaker = 0;
857 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200858 break;
859 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200860 if (spec->automute_speaker_possible) {
861 if (!spec->automute_lo && spec->automute_speaker)
862 return 0;
863 spec->automute_speaker = 1;
864 spec->automute_lo = 0;
865 } else if (spec->automute_lo_possible) {
866 if (spec->automute_lo)
867 return 0;
868 spec->automute_lo = 1;
869 } else
870 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200871 break;
872 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200873 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200874 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200875 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200876 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200877 spec->automute_speaker = 1;
878 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200879 break;
880 default:
881 return -EINVAL;
882 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200883 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200884 return 1;
885}
886
Takashi Iwaia9111322011-05-02 11:30:18 +0200887static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200888 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
889 .name = "Auto-Mute Mode",
890 .info = alc_automute_mode_info,
891 .get = alc_automute_mode_get,
892 .put = alc_automute_mode_put,
893};
894
Takashi Iwai668d1e92012-11-29 14:10:17 +0100895static struct snd_kcontrol_new *
896alc_kcontrol_new(struct alc_spec *spec, const char *name,
897 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200898{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100899 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
900 if (!knew)
901 return NULL;
902 *knew = *temp;
903 knew->name = kstrdup(name, GFP_KERNEL);
904 if (!knew->name)
905 return NULL;
906 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200907}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200908
909static int alc_add_automute_mode_enum(struct hda_codec *codec)
910{
911 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200912
Takashi Iwai668d1e92012-11-29 14:10:17 +0100913 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200914 return -ENOMEM;
915 return 0;
916}
917
Takashi Iwai1d045db2011-07-07 18:23:21 +0200918/*
919 * Check the availability of HP/line-out auto-mute;
920 * Set up appropriately if really supported
921 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100922static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200923{
924 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200925 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200926 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100927 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200928
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200929 if (cfg->hp_pins[0])
930 present++;
931 if (cfg->line_out_pins[0])
932 present++;
933 if (cfg->speaker_pins[0])
934 present++;
935 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100936 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200937
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200938 if (!cfg->speaker_pins[0] &&
939 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200940 memcpy(cfg->speaker_pins, cfg->line_out_pins,
941 sizeof(cfg->speaker_pins));
942 cfg->speaker_outs = cfg->line_outs;
943 }
944
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200945 if (!cfg->hp_pins[0] &&
946 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200947 memcpy(cfg->hp_pins, cfg->line_out_pins,
948 sizeof(cfg->hp_pins));
949 cfg->hp_outs = cfg->line_outs;
950 }
951
David Henningsson42cf0d02011-09-20 12:04:56 +0200952 spec->automute_mode = ALC_AUTOMUTE_PIN;
953
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200954 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200955 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200956 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200957 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200958 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200959 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200960 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
961 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200962 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200963 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200964
David Henningsson42cf0d02011-09-20 12:04:56 +0200965 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
966 if (cfg->speaker_outs)
967 for (i = 0; i < cfg->line_outs; i++) {
968 hda_nid_t nid = cfg->line_out_pins[i];
969 if (!is_jack_detectable(codec, nid))
970 continue;
971 snd_printdd("realtek: Enable Line-Out "
972 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200973 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
974 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200975 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200976 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200977 spec->automute_lo_possible = spec->detect_hp;
978 }
979
980 spec->automute_speaker_possible = cfg->speaker_outs &&
981 (spec->detect_hp || spec->detect_lo);
982
983 spec->automute_lo = spec->automute_lo_possible;
984 spec->automute_speaker = spec->automute_speaker_possible;
985
Takashi Iwai475c3d22012-11-30 08:31:30 +0100986 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200987 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100988 err = alc_add_automute_mode_enum(codec);
989 if (err < 0)
990 return err;
991 }
992 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200993}
994
Takashi Iwai1d045db2011-07-07 18:23:21 +0200995/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200996static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
997{
998 int i;
999 for (i = 0; i < nums; i++)
1000 if (list[i] == nid)
1001 return i;
1002 return -1;
1003}
1004
Takashi Iwai1d045db2011-07-07 18:23:21 +02001005/* check whether dynamic ADC-switching is available */
1006static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1007{
1008 struct alc_spec *spec = codec->spec;
1009 struct hda_input_mux *imux = &spec->private_imux[0];
1010 int i, n, idx;
1011 hda_nid_t cap, pin;
1012
1013 if (imux != spec->input_mux) /* no dynamic imux? */
1014 return false;
1015
1016 for (n = 0; n < spec->num_adc_nids; n++) {
1017 cap = spec->private_capsrc_nids[n];
1018 for (i = 0; i < imux->num_items; i++) {
1019 pin = spec->imux_pins[i];
1020 if (!pin)
1021 return false;
1022 if (get_connection_index(codec, cap, pin) < 0)
1023 break;
1024 }
1025 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001026 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001027 }
1028
1029 for (i = 0; i < imux->num_items; i++) {
1030 pin = spec->imux_pins[i];
1031 for (n = 0; n < spec->num_adc_nids; n++) {
1032 cap = spec->private_capsrc_nids[n];
1033 idx = get_connection_index(codec, cap, pin);
1034 if (idx >= 0) {
1035 imux->items[i].index = idx;
1036 spec->dyn_adc_idx[i] = n;
1037 break;
1038 }
1039 }
1040 }
1041
1042 snd_printdd("realtek: enabling ADC switching\n");
1043 spec->dyn_adc_switch = 1;
1044 return true;
1045}
Takashi Iwai21268962011-07-07 15:01:13 +02001046
Takashi Iwai21268962011-07-07 15:01:13 +02001047/* check whether all auto-mic pins are valid; setup indices if OK */
1048static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1049{
1050 struct alc_spec *spec = codec->spec;
1051 const struct hda_input_mux *imux;
1052
1053 if (!spec->auto_mic)
1054 return false;
1055 if (spec->auto_mic_valid_imux)
1056 return true; /* already checked */
1057
1058 /* fill up imux indices */
1059 if (!alc_check_dyn_adc_switch(codec)) {
1060 spec->auto_mic = 0;
1061 return false;
1062 }
1063
1064 imux = spec->input_mux;
1065 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1066 spec->imux_pins, imux->num_items);
1067 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1068 spec->imux_pins, imux->num_items);
1069 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1070 spec->imux_pins, imux->num_items);
1071 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1072 spec->auto_mic = 0;
1073 return false; /* no corresponding imux */
1074 }
1075
David Henningsson29adc4b2012-09-25 11:31:00 +02001076 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1077 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001078 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001079 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1080 ALC_MIC_EVENT,
1081 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001082
1083 spec->auto_mic_valid_imux = 1;
1084 spec->auto_mic = 1;
1085 return true;
1086}
1087
Takashi Iwai1d045db2011-07-07 18:23:21 +02001088/*
1089 * Check the availability of auto-mic switch;
1090 * Set up if really supported
1091 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001092static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001093{
1094 struct alc_spec *spec = codec->spec;
1095 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001096 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001097 int i;
1098
Takashi Iwai24de1832011-11-07 17:13:39 +01001099 if (spec->shared_mic_hp)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001100 return 0; /* no auto-mic for the shared I/O */
Takashi Iwai24de1832011-11-07 17:13:39 +01001101
Takashi Iwai21268962011-07-07 15:01:13 +02001102 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1103
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001104 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001105 for (i = 0; i < cfg->num_inputs; i++) {
1106 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001107 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001108 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001109 switch (snd_hda_get_input_pin_attr(defcfg)) {
1110 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001111 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001112 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001113 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001114 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001115 fixed = nid;
1116 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001117 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001118 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001119 case INPUT_PIN_ATTR_DOCK:
1120 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001121 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001122 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001123 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001124 dock = nid;
1125 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001126 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001127 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001128 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001129 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001130 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001131 ext = nid;
1132 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001133 }
1134 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001135 if (!ext && dock) {
1136 ext = dock;
1137 dock = 0;
1138 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001139 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001140 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001141 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001142 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001143 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001144 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001145
1146 /* check imux indices */
1147 spec->ext_mic_pin = ext;
1148 spec->int_mic_pin = fixed;
1149 spec->dock_mic_pin = dock;
1150
1151 spec->auto_mic = 1;
1152 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001153 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001154
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001155 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1156 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001157
1158 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001159}
1160
Takashi Iwai1d045db2011-07-07 18:23:21 +02001161/* check the availabilities of auto-mute and auto-mic switches */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001162static int alc_auto_check_switches(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02001163{
Takashi Iwai475c3d22012-11-30 08:31:30 +01001164 int err;
1165
1166 err = alc_init_automute(codec);
1167 if (err < 0)
1168 return err;
1169 err = alc_init_auto_mic(codec);
1170 if (err < 0)
1171 return err;
1172 return 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02001173}
1174
1175/*
1176 * Realtek SSID verification
1177 */
1178
David Henningsson90622912010-10-14 14:50:18 +02001179/* Could be any non-zero and even value. When used as fixup, tells
1180 * the driver to ignore any present sku defines.
1181 */
1182#define ALC_FIXUP_SKU_IGNORE (2)
1183
Takashi Iwai23d30f22012-05-07 17:17:32 +02001184static void alc_fixup_sku_ignore(struct hda_codec *codec,
1185 const struct hda_fixup *fix, int action)
1186{
1187 struct alc_spec *spec = codec->spec;
1188 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1189 spec->cdefine.fixup = 1;
1190 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1191 }
1192}
1193
Kailang Yangda00c242010-03-19 11:23:45 +01001194static int alc_auto_parse_customize_define(struct hda_codec *codec)
1195{
1196 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001197 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001198 struct alc_spec *spec = codec->spec;
1199
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001200 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1201
David Henningsson90622912010-10-14 14:50:18 +02001202 if (spec->cdefine.fixup) {
1203 ass = spec->cdefine.sku_cfg;
1204 if (ass == ALC_FIXUP_SKU_IGNORE)
1205 return -1;
1206 goto do_sku;
1207 }
1208
Kailang Yangda00c242010-03-19 11:23:45 +01001209 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001210 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001211 goto do_sku;
1212
1213 nid = 0x1d;
1214 if (codec->vendor_id == 0x10ec0260)
1215 nid = 0x17;
1216 ass = snd_hda_codec_get_pincfg(codec, nid);
1217
1218 if (!(ass & 1)) {
1219 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1220 codec->chip_name, ass);
1221 return -1;
1222 }
1223
1224 /* check sum */
1225 tmp = 0;
1226 for (i = 1; i < 16; i++) {
1227 if ((ass >> i) & 1)
1228 tmp++;
1229 }
1230 if (((ass >> 16) & 0xf) != tmp)
1231 return -1;
1232
1233 spec->cdefine.port_connectivity = ass >> 30;
1234 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1235 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1236 spec->cdefine.customization = ass >> 8;
1237do_sku:
1238 spec->cdefine.sku_cfg = ass;
1239 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1240 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1241 spec->cdefine.swap = (ass & 0x2) >> 1;
1242 spec->cdefine.override = ass & 0x1;
1243
1244 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1245 nid, spec->cdefine.sku_cfg);
1246 snd_printd("SKU: port_connectivity=0x%x\n",
1247 spec->cdefine.port_connectivity);
1248 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1249 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1250 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1251 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1252 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1253 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1254 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1255
1256 return 0;
1257}
1258
Takashi Iwai1d045db2011-07-07 18:23:21 +02001259/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001260static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1261{
Takashi Iwai21268962011-07-07 15:01:13 +02001262 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001263}
1264
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001265/* check subsystem ID and set up device-specific initialization;
1266 * return 1 if initialized, 0 if invalid SSID
1267 */
1268/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1269 * 31 ~ 16 : Manufacture ID
1270 * 15 ~ 8 : SKU ID
1271 * 7 ~ 0 : Assembly ID
1272 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1273 */
1274static int alc_subsystem_id(struct hda_codec *codec,
1275 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001276 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001277{
1278 unsigned int ass, tmp, i;
1279 unsigned nid;
1280 struct alc_spec *spec = codec->spec;
1281
David Henningsson90622912010-10-14 14:50:18 +02001282 if (spec->cdefine.fixup) {
1283 ass = spec->cdefine.sku_cfg;
1284 if (ass == ALC_FIXUP_SKU_IGNORE)
1285 return 0;
1286 goto do_sku;
1287 }
1288
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001289 ass = codec->subsystem_id & 0xffff;
1290 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1291 goto do_sku;
1292
1293 /* invalid SSID, check the special NID pin defcfg instead */
1294 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001295 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001296 * 29~21 : reserve
1297 * 20 : PCBEEP input
1298 * 19~16 : Check sum (15:1)
1299 * 15~1 : Custom
1300 * 0 : override
1301 */
1302 nid = 0x1d;
1303 if (codec->vendor_id == 0x10ec0260)
1304 nid = 0x17;
1305 ass = snd_hda_codec_get_pincfg(codec, nid);
1306 snd_printd("realtek: No valid SSID, "
1307 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001308 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001309 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001310 return 0;
1311 if ((ass >> 30) != 1) /* no physical connection */
1312 return 0;
1313
1314 /* check sum */
1315 tmp = 0;
1316 for (i = 1; i < 16; i++) {
1317 if ((ass >> i) & 1)
1318 tmp++;
1319 }
1320 if (((ass >> 16) & 0xf) != tmp)
1321 return 0;
1322do_sku:
1323 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1324 ass & 0xffff, codec->vendor_id);
1325 /*
1326 * 0 : override
1327 * 1 : Swap Jack
1328 * 2 : 0 --> Desktop, 1 --> Laptop
1329 * 3~5 : External Amplifier control
1330 * 7~6 : Reserved
1331 */
1332 tmp = (ass & 0x38) >> 3; /* external Amp control */
1333 switch (tmp) {
1334 case 1:
1335 spec->init_amp = ALC_INIT_GPIO1;
1336 break;
1337 case 3:
1338 spec->init_amp = ALC_INIT_GPIO2;
1339 break;
1340 case 7:
1341 spec->init_amp = ALC_INIT_GPIO3;
1342 break;
1343 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001344 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001345 spec->init_amp = ALC_INIT_DEFAULT;
1346 break;
1347 }
1348
1349 /* is laptop or Desktop and enable the function "Mute internal speaker
1350 * when the external headphone out jack is plugged"
1351 */
1352 if (!(ass & 0x8000))
1353 return 1;
1354 /*
1355 * 10~8 : Jack location
1356 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1357 * 14~13: Resvered
1358 * 15 : 1 --> enable the function "Mute internal speaker
1359 * when the external headphone out jack is plugged"
1360 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001361 if (!spec->autocfg.hp_pins[0] &&
1362 !(spec->autocfg.line_out_pins[0] &&
1363 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001364 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001365 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1366 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001367 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001368 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001369 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001370 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001371 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001372 else if (tmp == 3)
1373 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001374 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001375 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001376 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1377 spec->autocfg.line_outs))
1378 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001379 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001380 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001381 return 1;
1382}
Kailang Yangea1fb292008-08-26 12:58:38 +02001383
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001384/* Check the validity of ALC subsystem-id
1385 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1386static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001387{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001388 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001389 struct alc_spec *spec = codec->spec;
1390 snd_printd("realtek: "
1391 "Enable default setup for auto mode as fallback\n");
1392 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001393 }
Takashi Iwai21268962011-07-07 15:01:13 +02001394}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001395
Takashi Iwai41e41f12005-06-08 14:48:49 +02001396/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001397 * COEF access helper functions
1398 */
Kailang Yang274693f2009-12-03 10:07:50 +01001399static int alc_read_coef_idx(struct hda_codec *codec,
1400 unsigned int coef_idx)
1401{
1402 unsigned int val;
1403 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1404 coef_idx);
1405 val = snd_hda_codec_read(codec, 0x20, 0,
1406 AC_VERB_GET_PROC_COEF, 0);
1407 return val;
1408}
1409
Kailang Yang977ddd62010-09-15 10:02:29 +02001410static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1411 unsigned int coef_val)
1412{
1413 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1414 coef_idx);
1415 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1416 coef_val);
1417}
1418
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001419/* a special bypass for COEF 0; read the cached value at the second time */
1420static unsigned int alc_get_coef0(struct hda_codec *codec)
1421{
1422 struct alc_spec *spec = codec->spec;
1423 if (!spec->coef0)
1424 spec->coef0 = alc_read_coef_idx(codec, 0);
1425 return spec->coef0;
1426}
1427
Takashi Iwai1d045db2011-07-07 18:23:21 +02001428/*
1429 * Digital I/O handling
1430 */
1431
Takashi Iwai757899a2010-07-30 10:48:14 +02001432/* set right pin controls for digital I/O */
1433static void alc_auto_init_digital(struct hda_codec *codec)
1434{
1435 struct alc_spec *spec = codec->spec;
1436 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001437 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001438
1439 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1440 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001441 if (!pin)
1442 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001443 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001444 if (!i)
1445 dac = spec->multiout.dig_out_nid;
1446 else
1447 dac = spec->slave_dig_outs[i - 1];
1448 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1449 continue;
1450 snd_hda_codec_write(codec, dac, 0,
1451 AC_VERB_SET_AMP_GAIN_MUTE,
1452 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001453 }
1454 pin = spec->autocfg.dig_in_pin;
1455 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001456 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001457}
1458
1459/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1460static void alc_auto_parse_digital(struct hda_codec *codec)
1461{
1462 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001463 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001464 hda_nid_t dig_nid;
1465
1466 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001467 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001468 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001469 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001470 err = snd_hda_get_connections(codec,
1471 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001472 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001473 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001474 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001475 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001476 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001477 spec->multiout.dig_out_nid = dig_nid;
1478 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1479 } else {
1480 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001481 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001482 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001483 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001484 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001485 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001486 }
1487
1488 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001489 dig_nid = codec->start_nid;
1490 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1491 unsigned int wcaps = get_wcaps(codec, dig_nid);
1492 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1493 continue;
1494 if (!(wcaps & AC_WCAP_DIGITAL))
1495 continue;
1496 if (!(wcaps & AC_WCAP_CONN_LIST))
1497 continue;
1498 err = get_connection_index(codec, dig_nid,
1499 spec->autocfg.dig_in_pin);
1500 if (err >= 0) {
1501 spec->dig_in_nid = dig_nid;
1502 break;
1503 }
1504 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001505 }
1506}
1507
Takashi Iwaif95474e2007-07-10 00:47:43 +02001508/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001509 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001510 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001511static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1512 struct snd_ctl_elem_info *uinfo)
1513{
1514 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1515 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001516 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001517 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001518
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001519 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001520 if (spec->vol_in_capsrc)
1521 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1522 else
1523 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1524 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001525 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001526 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001527 return err;
1528}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001530static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1531 unsigned int size, unsigned int __user *tlv)
1532{
1533 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1534 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001535 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001536 int err;
1537
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001538 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001539 if (spec->vol_in_capsrc)
1540 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1541 else
1542 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1543 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001544 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001545 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001546 return err;
1547}
1548
1549typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1550 struct snd_ctl_elem_value *ucontrol);
1551
1552static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1553 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001554 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001555{
1556 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1557 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001558 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001559
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001560 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001561 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001562 for (i = 0; i < spec->num_adc_nids; i++) {
1563 kcontrol->private_value =
1564 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1565 3, 0, HDA_INPUT);
1566 err = func(kcontrol, ucontrol);
1567 if (err < 0)
1568 goto error;
1569 }
1570 } else {
1571 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001572 if (spec->vol_in_capsrc)
1573 kcontrol->private_value =
1574 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1575 3, 0, HDA_OUTPUT);
1576 else
1577 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001578 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1579 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001580 err = func(kcontrol, ucontrol);
1581 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001582 if (err >= 0 && is_put)
1583 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001584 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001585 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001586 return err;
1587}
1588
1589static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1590 struct snd_ctl_elem_value *ucontrol)
1591{
1592 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001593 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001594}
1595
1596static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1597 struct snd_ctl_elem_value *ucontrol)
1598{
1599 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001600 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001601}
1602
1603/* capture mixer elements */
1604#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1605
1606static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1607 struct snd_ctl_elem_value *ucontrol)
1608{
1609 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001610 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001611}
1612
1613static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1614 struct snd_ctl_elem_value *ucontrol)
1615{
1616 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001617 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001618}
1619
Takashi Iwaia23b6882009-03-23 15:21:36 +01001620#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001621 { \
1622 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1623 .name = "Capture Switch", \
1624 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1625 .count = num, \
1626 .info = alc_cap_sw_info, \
1627 .get = alc_cap_sw_get, \
1628 .put = alc_cap_sw_put, \
1629 }, \
1630 { \
1631 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1632 .name = "Capture Volume", \
1633 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1634 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1635 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1636 .count = num, \
1637 .info = alc_cap_vol_info, \
1638 .get = alc_cap_vol_get, \
1639 .put = alc_cap_vol_put, \
1640 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001641 }
1642
1643#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001644 { \
1645 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1646 /* .name = "Capture Source", */ \
1647 .name = "Input Source", \
1648 .count = num, \
1649 .info = alc_mux_enum_info, \
1650 .get = alc_mux_enum_get, \
1651 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001652 }
1653
1654#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001655static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001656 _DEFINE_CAPMIX(num), \
1657 _DEFINE_CAPSRC(num), \
1658 { } /* end */ \
1659}
1660
1661#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001662static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001663 _DEFINE_CAPMIX(num), \
1664 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001665}
1666
1667/* up to three ADCs */
1668DEFINE_CAPMIX(1);
1669DEFINE_CAPMIX(2);
1670DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001671DEFINE_CAPMIX_NOSRC(1);
1672DEFINE_CAPMIX_NOSRC(2);
1673DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001674
1675/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001676 * Inverted digital-mic handling
1677 *
1678 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1679 * gives the additional mute only to the right channel of the digital mic
1680 * capture stream. This is a workaround for avoiding the almost silence
1681 * by summing the stereo stream from some (known to be ForteMedia)
1682 * digital mic unit.
1683 *
1684 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1685 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1686 * without caching so that the cache can still keep the original value.
1687 * The cached value is then restored when the flag is set off or any other
1688 * than d-mic is used as the current input source.
1689 */
1690static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1691{
1692 struct alc_spec *spec = codec->spec;
1693 int i;
1694
1695 if (!spec->inv_dmic_fixup)
1696 return;
1697 if (!spec->inv_dmic_muted && !force)
1698 return;
1699 for (i = 0; i < spec->num_adc_nids; i++) {
1700 int src = spec->dyn_adc_switch ? 0 : i;
1701 bool dmic_fixup = false;
1702 hda_nid_t nid;
1703 int parm, dir, v;
1704
1705 if (spec->inv_dmic_muted &&
1706 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1707 dmic_fixup = true;
1708 if (!dmic_fixup && !force)
1709 continue;
1710 if (spec->vol_in_capsrc) {
1711 nid = spec->capsrc_nids[i];
1712 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1713 dir = HDA_OUTPUT;
1714 } else {
1715 nid = spec->adc_nids[i];
1716 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1717 dir = HDA_INPUT;
1718 }
1719 /* we care only right channel */
1720 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1721 if (v & 0x80) /* if already muted, we don't need to touch */
1722 continue;
1723 if (dmic_fixup) /* add mute for d-mic */
1724 v |= 0x80;
1725 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1726 parm | v);
1727 }
1728}
1729
1730static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1731 struct snd_ctl_elem_value *ucontrol)
1732{
1733 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1734 struct alc_spec *spec = codec->spec;
1735
1736 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1737 return 0;
1738}
1739
1740static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1741 struct snd_ctl_elem_value *ucontrol)
1742{
1743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1744 struct alc_spec *spec = codec->spec;
1745 unsigned int val = !ucontrol->value.integer.value[0];
1746
1747 if (val == spec->inv_dmic_muted)
1748 return 0;
1749 spec->inv_dmic_muted = val;
1750 alc_inv_dmic_sync(codec, true);
1751 return 0;
1752}
1753
1754static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1756 .info = snd_ctl_boolean_mono_info,
1757 .get = alc_inv_dmic_sw_get,
1758 .put = alc_inv_dmic_sw_put,
1759};
1760
1761static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1762{
1763 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001764
1765 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1766 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001767 return -ENOMEM;
1768 spec->inv_dmic_fixup = 1;
1769 spec->inv_dmic_muted = 0;
1770 spec->inv_dmic_pin = nid;
1771 return 0;
1772}
1773
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001774/* typically the digital mic is put at node 0x12 */
1775static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1776 const struct alc_fixup *fix, int action)
1777{
1778 if (action == ALC_FIXUP_ACT_PROBE)
1779 alc_add_inv_dmic_mixer(codec, 0x12);
1780}
1781
Takashi Iwai125821a2012-06-22 14:30:29 +02001782/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001783 * virtual master controls
1784 */
1785
1786/*
1787 * slave controls for virtual master
1788 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001789static const char * const alc_slave_pfxs[] = {
1790 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001791 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001792 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001793 NULL,
1794};
1795
1796/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001797 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001799
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001800#define NID_MAPPING (-1)
1801
1802#define SUBDEV_SPEAKER_ (0 << 6)
1803#define SUBDEV_HP_ (1 << 6)
1804#define SUBDEV_LINE_ (2 << 6)
1805#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1806#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1807#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1808
Takashi Iwai603c4012008-07-30 15:01:44 +02001809static void alc_free_kctls(struct hda_codec *codec);
1810
Takashi Iwai67d634c2009-11-16 15:35:59 +01001811#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001812/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001813static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001814 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001815 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001816 { } /* end */
1817};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001818#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001819
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001820static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821{
1822 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001823 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001824 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001825 int i, j, err;
1826 unsigned int u;
1827 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 for (i = 0; i < spec->num_mixers; i++) {
1830 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1831 if (err < 0)
1832 return err;
1833 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001834 if (spec->cap_mixer) {
1835 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1836 if (err < 0)
1837 return err;
1838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001840 err = snd_hda_create_dig_out_ctls(codec,
1841 spec->multiout.dig_out_nid,
1842 spec->multiout.dig_out_nid,
1843 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 if (err < 0)
1845 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001846 if (!spec->no_analog) {
1847 err = snd_hda_create_spdif_share_sw(codec,
1848 &spec->multiout);
1849 if (err < 0)
1850 return err;
1851 spec->multiout.share_spdif = 1;
1852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 }
1854 if (spec->dig_in_nid) {
1855 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1856 if (err < 0)
1857 return err;
1858 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001859
Takashi Iwai67d634c2009-11-16 15:35:59 +01001860#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001861 /* create beep controls if needed */
1862 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001863 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001864 for (knew = alc_beep_mixer; knew->name; knew++) {
1865 struct snd_kcontrol *kctl;
1866 kctl = snd_ctl_new1(knew, codec);
1867 if (!kctl)
1868 return -ENOMEM;
1869 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001870 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001871 if (err < 0)
1872 return err;
1873 }
1874 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001875#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001876
Takashi Iwai2134ea42008-01-10 16:53:55 +01001877 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001878 if (!spec->no_analog &&
1879 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001880 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001881 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001882 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001883 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001884 vmaster_tlv, alc_slave_pfxs,
1885 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001886 if (err < 0)
1887 return err;
1888 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001889 if (!spec->no_analog &&
1890 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001891 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1892 NULL, alc_slave_pfxs,
1893 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001894 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001895 if (err < 0)
1896 return err;
1897 }
1898
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001899 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001900 if (spec->capsrc_nids || spec->adc_nids) {
1901 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1902 if (!kctl)
1903 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1904 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001905 err = snd_hda_add_nid(codec, kctl, i,
1906 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001907 if (err < 0)
1908 return err;
1909 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001910 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001911 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001912 const char *kname = kctl ? kctl->id.name : NULL;
1913 for (knew = spec->cap_mixer; knew->name; knew++) {
1914 if (kname && strcmp(knew->name, kname) == 0)
1915 continue;
1916 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1917 for (i = 0; kctl && i < kctl->count; i++) {
1918 err = snd_hda_add_nid(codec, kctl, i,
1919 spec->adc_nids[i]);
1920 if (err < 0)
1921 return err;
1922 }
1923 }
1924 }
1925
1926 /* other nid->control mapping */
1927 for (i = 0; i < spec->num_mixers; i++) {
1928 for (knew = spec->mixers[i]; knew->name; knew++) {
1929 if (knew->iface != NID_MAPPING)
1930 continue;
1931 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1932 if (kctl == NULL)
1933 continue;
1934 u = knew->subdevice;
1935 for (j = 0; j < 4; j++, u >>= 8) {
1936 nid = u & 0x3f;
1937 if (nid == 0)
1938 continue;
1939 switch (u & 0xc0) {
1940 case SUBDEV_SPEAKER_:
1941 nid = spec->autocfg.speaker_pins[nid];
1942 break;
1943 case SUBDEV_LINE_:
1944 nid = spec->autocfg.line_out_pins[nid];
1945 break;
1946 case SUBDEV_HP_:
1947 nid = spec->autocfg.hp_pins[nid];
1948 break;
1949 default:
1950 continue;
1951 }
1952 err = snd_hda_add_nid(codec, kctl, 0, nid);
1953 if (err < 0)
1954 return err;
1955 }
1956 u = knew->private_value;
1957 for (j = 0; j < 4; j++, u >>= 8) {
1958 nid = u & 0xff;
1959 if (nid == 0)
1960 continue;
1961 err = snd_hda_add_nid(codec, kctl, 0, nid);
1962 if (err < 0)
1963 return err;
1964 }
1965 }
1966 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001967
1968 alc_free_kctls(codec); /* no longer needed */
1969
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001970 return 0;
1971}
1972
David Henningsson5780b622012-06-27 18:45:45 +02001973static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001974{
1975 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001976
1977 if (spec->shared_mic_hp) {
1978 int err;
1979 int nid = spec->autocfg.inputs[1].pin;
1980 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1981 if (err < 0)
1982 return err;
1983 err = snd_hda_jack_detect_enable(codec, nid, 0);
1984 if (err < 0)
1985 return err;
1986 }
1987
1988 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1989}
1990
1991static int alc_build_controls(struct hda_codec *codec)
1992{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001993 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001994 if (err < 0)
1995 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001996
1997 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001998 if (err < 0)
1999 return err;
2000 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2001 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002}
2003
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002004
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002006 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002007 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002008
Takashi Iwai584c0c42011-03-10 12:51:11 +01002009static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002010static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002011
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012static int alc_init(struct hda_codec *codec)
2013{
2014 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002015
Takashi Iwai546bb672012-03-07 08:37:19 +01002016 if (spec->init_hook)
2017 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002018
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002019 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002020 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002021
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002022 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002023 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002024 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002025
Takashi Iwai58701122011-01-13 15:41:45 +01002026 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2027
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002028 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 return 0;
2030}
2031
Takashi Iwai83012a72012-08-24 18:38:08 +02002032#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002033static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2034{
2035 struct alc_spec *spec = codec->spec;
2036 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2037}
2038#endif
2039
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040/*
2041 * Analog playback callbacks
2042 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002043static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002045 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046{
2047 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002048 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2049 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050}
2051
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002052static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 struct hda_codec *codec,
2054 unsigned int stream_tag,
2055 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002056 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057{
2058 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002059 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2060 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061}
2062
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002063static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002065 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
2067 struct alc_spec *spec = codec->spec;
2068 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2069}
2070
2071/*
2072 * Digital out
2073 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002074static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002076 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
2078 struct alc_spec *spec = codec->spec;
2079 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2080}
2081
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002082static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002083 struct hda_codec *codec,
2084 unsigned int stream_tag,
2085 unsigned int format,
2086 struct snd_pcm_substream *substream)
2087{
2088 struct alc_spec *spec = codec->spec;
2089 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2090 stream_tag, format, substream);
2091}
2092
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002093static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002094 struct hda_codec *codec,
2095 struct snd_pcm_substream *substream)
2096{
2097 struct alc_spec *spec = codec->spec;
2098 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2099}
2100
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002101static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002103 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
2105 struct alc_spec *spec = codec->spec;
2106 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2107}
2108
2109/*
2110 * Analog capture
2111 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002112static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 struct hda_codec *codec,
2114 unsigned int stream_tag,
2115 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002116 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
2118 struct alc_spec *spec = codec->spec;
2119
Takashi Iwai63300792008-01-24 15:31:36 +01002120 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 stream_tag, 0, format);
2122 return 0;
2123}
2124
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002125static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002127 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128{
2129 struct alc_spec *spec = codec->spec;
2130
Takashi Iwai888afa12008-03-18 09:57:50 +01002131 snd_hda_codec_cleanup_stream(codec,
2132 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 return 0;
2134}
2135
Takashi Iwai840b64c2010-07-13 22:49:01 +02002136/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002137static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002138 struct hda_codec *codec,
2139 unsigned int stream_tag,
2140 unsigned int format,
2141 struct snd_pcm_substream *substream)
2142{
2143 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002144 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002145 spec->cur_adc_stream_tag = stream_tag;
2146 spec->cur_adc_format = format;
2147 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2148 return 0;
2149}
2150
Takashi Iwai21268962011-07-07 15:01:13 +02002151static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002152 struct hda_codec *codec,
2153 struct snd_pcm_substream *substream)
2154{
2155 struct alc_spec *spec = codec->spec;
2156 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2157 spec->cur_adc = 0;
2158 return 0;
2159}
2160
Takashi Iwai21268962011-07-07 15:01:13 +02002161static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002162 .substreams = 1,
2163 .channels_min = 2,
2164 .channels_max = 2,
2165 .nid = 0, /* fill later */
2166 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002167 .prepare = dyn_adc_capture_pcm_prepare,
2168 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002169 },
2170};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
2172/*
2173 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002174static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 .substreams = 1,
2176 .channels_min = 2,
2177 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002178 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002180 .open = alc_playback_pcm_open,
2181 .prepare = alc_playback_pcm_prepare,
2182 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 },
2184};
2185
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002186static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002187 .substreams = 1,
2188 .channels_min = 2,
2189 .channels_max = 2,
2190 /* NID is set in alc_build_pcms */
2191};
2192
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002193static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002194 .substreams = 1,
2195 .channels_min = 2,
2196 .channels_max = 2,
2197 /* NID is set in alc_build_pcms */
2198};
2199
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002200static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002201 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 .channels_min = 2,
2203 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002204 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002206 .prepare = alc_alt_capture_pcm_prepare,
2207 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 },
2209};
2210
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002211static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 .substreams = 1,
2213 .channels_min = 2,
2214 .channels_max = 2,
2215 /* NID is set in alc_build_pcms */
2216 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002217 .open = alc_dig_playback_pcm_open,
2218 .close = alc_dig_playback_pcm_close,
2219 .prepare = alc_dig_playback_pcm_prepare,
2220 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 },
2222};
2223
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002224static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 .substreams = 1,
2226 .channels_min = 2,
2227 .channels_max = 2,
2228 /* NID is set in alc_build_pcms */
2229};
2230
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002231/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002232static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002233 .substreams = 0,
2234 .channels_min = 0,
2235 .channels_max = 0,
2236};
2237
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238static int alc_build_pcms(struct hda_codec *codec)
2239{
2240 struct alc_spec *spec = codec->spec;
2241 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002242 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002243 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 int i;
2245
2246 codec->num_pcms = 1;
2247 codec->pcm_info = info;
2248
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002249 if (spec->no_analog)
2250 goto skip_analog;
2251
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002252 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2253 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002255
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002256 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002257 p = spec->stream_analog_playback;
2258 if (!p)
2259 p = &alc_pcm_analog_playback;
2260 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002261 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002262 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2263 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002264 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2265 spec->autocfg.line_outs == 2)
2266 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2267 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002268 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002269 if (spec->adc_nids) {
2270 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002271 if (!p) {
2272 if (spec->dyn_adc_switch)
2273 p = &dyn_adc_pcm_analog_capture;
2274 else
2275 p = &alc_pcm_analog_capture;
2276 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002277 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002278 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Takashi Iwai4a471b72005-12-07 13:56:29 +01002281 if (spec->channel_mode) {
2282 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2283 for (i = 0; i < spec->num_channel_mode; i++) {
2284 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2285 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2286 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 }
2288 }
2289
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002290 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002291 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002293 snprintf(spec->stream_name_digital,
2294 sizeof(spec->stream_name_digital),
2295 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002296 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002297 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002298 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002300 if (spec->dig_out_type)
2301 info->pcm_type = spec->dig_out_type;
2302 else
2303 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002304 if (spec->multiout.dig_out_nid) {
2305 p = spec->stream_digital_playback;
2306 if (!p)
2307 p = &alc_pcm_digital_playback;
2308 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2310 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002311 if (spec->dig_in_nid) {
2312 p = spec->stream_digital_capture;
2313 if (!p)
2314 p = &alc_pcm_digital_capture;
2315 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2317 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002318 /* FIXME: do we need this for all Realtek codec models? */
2319 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 }
2321
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002322 if (spec->no_analog)
2323 return 0;
2324
Takashi Iwaie08a0072006-09-07 17:52:14 +02002325 /* If the use of more than one ADC is requested for the current
2326 * model, configure a second analog capture-only PCM.
2327 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002328 have_multi_adcs = (spec->num_adc_nids > 1) &&
2329 !spec->dyn_adc_switch && !spec->auto_mic &&
2330 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002331 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002332 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002333 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002334 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002335 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002336 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002337 p = spec->stream_analog_alt_playback;
2338 if (!p)
2339 p = &alc_pcm_analog_alt_playback;
2340 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002341 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2342 spec->alt_dac_nid;
2343 } else {
2344 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2345 alc_pcm_null_stream;
2346 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2347 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002348 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002349 p = spec->stream_analog_alt_capture;
2350 if (!p)
2351 p = &alc_pcm_analog_alt_capture;
2352 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002353 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2354 spec->adc_nids[1];
2355 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2356 spec->num_adc_nids - 1;
2357 } else {
2358 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2359 alc_pcm_null_stream;
2360 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002361 }
2362 }
2363
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 return 0;
2365}
2366
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002367static inline void alc_shutup(struct hda_codec *codec)
2368{
Takashi Iwai1c716152011-04-07 10:37:16 +02002369 struct alc_spec *spec = codec->spec;
2370
2371 if (spec && spec->shutup)
2372 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002373 snd_hda_shutup_pins(codec);
2374}
2375
Takashi Iwai603c4012008-07-30 15:01:44 +02002376static void alc_free_kctls(struct hda_codec *codec)
2377{
2378 struct alc_spec *spec = codec->spec;
2379
2380 if (spec->kctls.list) {
2381 struct snd_kcontrol_new *kctl = spec->kctls.list;
2382 int i;
2383 for (i = 0; i < spec->kctls.used; i++)
2384 kfree(kctl[i].name);
2385 }
2386 snd_array_free(&spec->kctls);
2387}
2388
Takashi Iwai23c09b02011-08-19 09:05:35 +02002389static void alc_free_bind_ctls(struct hda_codec *codec)
2390{
2391 struct alc_spec *spec = codec->spec;
2392 if (spec->bind_ctls.list) {
2393 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2394 int i;
2395 for (i = 0; i < spec->bind_ctls.used; i++)
2396 kfree(ctl[i]);
2397 }
2398 snd_array_free(&spec->bind_ctls);
2399}
2400
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401static void alc_free(struct hda_codec *codec)
2402{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002403 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002404
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002405 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002406 return;
2407
Takashi Iwai603c4012008-07-30 15:01:44 +02002408 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002409 alc_free_bind_ctls(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002410 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002411 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002412 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413}
2414
Takashi Iwai83012a72012-08-24 18:38:08 +02002415#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002416static void alc_power_eapd(struct hda_codec *codec)
2417{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002418 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002419}
2420
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002421static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002422{
2423 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002424 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002425 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002426 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002427 return 0;
2428}
2429#endif
2430
Takashi Iwai2a439522011-07-26 09:52:50 +02002431#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002432static int alc_resume(struct hda_codec *codec)
2433{
Takashi Iwai1c716152011-04-07 10:37:16 +02002434 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002435 codec->patch_ops.init(codec);
2436 snd_hda_codec_resume_amp(codec);
2437 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002438 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002439 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002440 return 0;
2441}
Takashi Iwaie044c392008-10-27 16:56:24 +01002442#endif
2443
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444/*
2445 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002446static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 .build_controls = alc_build_controls,
2448 .build_pcms = alc_build_pcms,
2449 .init = alc_init,
2450 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002451 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002452#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002453 .resume = alc_resume,
2454#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002455#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002456 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002457 .check_power_status = alc_check_power_status,
2458#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002459 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460};
2461
David Henningsson29adc4b2012-09-25 11:31:00 +02002462
Kailang Yangc027ddc2010-03-19 11:33:06 +01002463/* replace the codec chip_name with the given string */
2464static int alc_codec_rename(struct hda_codec *codec, const char *name)
2465{
2466 kfree(codec->chip_name);
2467 codec->chip_name = kstrdup(name, GFP_KERNEL);
2468 if (!codec->chip_name) {
2469 alc_free(codec);
2470 return -ENOMEM;
2471 }
2472 return 0;
2473}
2474
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002475/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002476 * Rename codecs appropriately from COEF value
2477 */
2478struct alc_codec_rename_table {
2479 unsigned int vendor_id;
2480 unsigned short coef_mask;
2481 unsigned short coef_bits;
2482 const char *name;
2483};
2484
2485static struct alc_codec_rename_table rename_tbl[] = {
2486 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2487 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2488 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2489 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2490 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2491 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2492 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002493 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002494 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2495 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2496 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2497 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2498 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2499 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2500 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2501 { } /* terminator */
2502};
2503
2504static int alc_codec_rename_from_preset(struct hda_codec *codec)
2505{
2506 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002507
2508 for (p = rename_tbl; p->vendor_id; p++) {
2509 if (p->vendor_id != codec->vendor_id)
2510 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002511 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002512 return alc_codec_rename(codec, p->name);
2513 }
2514 return 0;
2515}
2516
2517/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002518 * Automatic parse of I/O pins from the BIOS configuration
2519 */
2520
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002521enum {
2522 ALC_CTL_WIDGET_VOL,
2523 ALC_CTL_WIDGET_MUTE,
2524 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002525 ALC_CTL_BIND_VOL,
2526 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002527};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002528static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002529 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2530 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002531 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002532 HDA_BIND_VOL(NULL, 0),
2533 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002534};
2535
2536/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002537static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002538 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002539{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002540 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002541
Takashi Iwai668d1e92012-11-29 14:10:17 +01002542 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002543 if (!knew)
2544 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002545 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002546 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002547 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002548 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002549 return 0;
2550}
2551
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002552static int add_control_with_pfx(struct alc_spec *spec, int type,
2553 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002554 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002555{
2556 char name[32];
2557 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002558 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002559}
2560
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002561#define add_pb_vol_ctrl(spec, type, pfx, val) \
2562 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2563#define add_pb_sw_ctrl(spec, type, pfx, val) \
2564 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2565#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2566 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2567#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2568 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002569
Takashi Iwai23c09b02011-08-19 09:05:35 +02002570static const char * const channel_name[4] = {
2571 "Front", "Surround", "CLFE", "Side"
2572};
2573
Takashi Iwai6843ca12011-06-24 11:03:58 +02002574static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2575 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002576{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002577 struct auto_pin_cfg *cfg = &spec->autocfg;
2578
Takashi Iwai6843ca12011-06-24 11:03:58 +02002579 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002580 if (cfg->line_outs == 1 && !spec->multi_ios &&
2581 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002582 return "Master";
2583
2584 switch (cfg->line_out_type) {
2585 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002586 if (cfg->line_outs == 1)
2587 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002588 if (cfg->line_outs == 2)
2589 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002590 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002591 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002592 /* for multi-io case, only the primary out */
2593 if (ch && spec->multi_ios)
2594 break;
2595 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002596 return "Headphone";
2597 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002598 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002599 return "PCM";
2600 break;
2601 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002602 if (ch >= ARRAY_SIZE(channel_name)) {
2603 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002604 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002605 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002606
2607 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002608}
2609
Takashi Iwai83012a72012-08-24 18:38:08 +02002610#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002611/* add the powersave loopback-list entry */
2612static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2613{
2614 struct hda_amp_list *list;
2615
2616 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2617 return;
2618 list = spec->loopback_list + spec->num_loopbacks;
2619 list->nid = mix;
2620 list->dir = HDA_INPUT;
2621 list->idx = idx;
2622 spec->num_loopbacks++;
2623 spec->loopback.amplist = spec->loopback_list;
2624}
2625#else
2626#define add_loopback_list(spec, mix, idx) /* NOP */
2627#endif
2628
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002629/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002630static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002631 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002632 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002633{
Kailang Yangdf694da2005-12-05 19:42:22 +01002634 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002635
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002636 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002637 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2638 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002639 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002640 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002641 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2642 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002643 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002644 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002645 return 0;
2646}
2647
Takashi Iwai05f5f472009-08-25 13:10:18 +02002648static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002649{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002650 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2651 return (pincap & AC_PINCAP_IN) != 0;
2652}
2653
Takashi Iwai1d045db2011-07-07 18:23:21 +02002654/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002655static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002656{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002657 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002658 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002659 hda_nid_t *adc_nids = spec->private_adc_nids;
2660 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2661 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002662 int i, nums = 0;
2663
2664 nid = codec->start_nid;
2665 for (i = 0; i < codec->num_nodes; i++, nid++) {
2666 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002667 unsigned int caps = get_wcaps(codec, nid);
2668 int type = get_wcaps_type(caps);
2669
2670 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2671 continue;
2672 adc_nids[nums] = nid;
2673 cap_nids[nums] = nid;
2674 src = nid;
2675 for (;;) {
2676 int n;
2677 type = get_wcaps_type(get_wcaps(codec, src));
2678 if (type == AC_WID_PIN)
2679 break;
2680 if (type == AC_WID_AUD_SEL) {
2681 cap_nids[nums] = src;
2682 break;
2683 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002684 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002685 if (n > 1) {
2686 cap_nids[nums] = src;
2687 break;
2688 } else if (n != 1)
2689 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002690 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2691 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002692 }
2693 if (++nums >= max_nums)
2694 break;
2695 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002696 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002697 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002698 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002699 return nums;
2700}
2701
Takashi Iwai05f5f472009-08-25 13:10:18 +02002702/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002703static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002704{
2705 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002706 const struct auto_pin_cfg *cfg = &spec->autocfg;
2707 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002708 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002709 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002710 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002711 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002712
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002713 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002714 if (num_adcs < 0)
2715 return 0;
2716
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002717 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002718 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002719 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002720
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002721 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002722 if (!alc_is_input_pin(codec, pin))
2723 continue;
2724
David Henningsson5322bf22011-01-05 11:03:56 +01002725 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002726 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2727 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002728 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002729 type_idx++;
2730 else
2731 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002732 prev_label = label;
2733
Takashi Iwai05f5f472009-08-25 13:10:18 +02002734 if (mixer) {
2735 idx = get_connection_index(codec, mixer, pin);
2736 if (idx >= 0) {
2737 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002738 label, type_idx,
2739 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002740 if (err < 0)
2741 return err;
2742 }
2743 }
2744
Takashi Iwaib7821702011-07-06 15:12:46 +02002745 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002746 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002747 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002748 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002749 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002750 snd_hda_add_imux_item(imux, label, idx, NULL);
2751 break;
2752 }
2753 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002754 }
Takashi Iwai21268962011-07-07 15:01:13 +02002755
2756 spec->num_mux_defs = 1;
2757 spec->input_mux = imux;
2758
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002759 return 0;
2760}
2761
Takashi Iwai24de1832011-11-07 17:13:39 +01002762/* create a shared input with the headphone out */
2763static int alc_auto_create_shared_input(struct hda_codec *codec)
2764{
2765 struct alc_spec *spec = codec->spec;
2766 struct auto_pin_cfg *cfg = &spec->autocfg;
2767 unsigned int defcfg;
2768 hda_nid_t nid;
2769
2770 /* only one internal input pin? */
2771 if (cfg->num_inputs != 1)
2772 return 0;
2773 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2774 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2775 return 0;
2776
2777 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2778 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2779 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2780 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2781 else
2782 return 0; /* both not available */
2783
2784 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2785 return 0; /* no input */
2786
2787 cfg->inputs[1].pin = nid;
2788 cfg->inputs[1].type = AUTO_PIN_MIC;
2789 cfg->num_inputs = 2;
2790 spec->shared_mic_hp = 1;
2791 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2792 return 0;
2793}
2794
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002795static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2796 unsigned int pin_type)
2797{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002798 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002799 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002800 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2801 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002802 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002803}
2804
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002805static int get_pin_type(int line_out_type)
2806{
2807 if (line_out_type == AUTO_PIN_HP_OUT)
2808 return PIN_HP;
2809 else
2810 return PIN_OUT;
2811}
2812
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002813static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002814{
2815 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002816 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002817 int i;
2818
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002819 for (i = 0; i < cfg->num_inputs; i++) {
2820 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002821 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002822 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002823 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002824 snd_hda_codec_write(codec, nid, 0,
2825 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002826 AMP_OUT_MUTE);
2827 }
2828 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002829
2830 /* mute all loopback inputs */
2831 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002832 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002833 for (i = 0; i < nums; i++)
2834 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2835 AC_VERB_SET_AMP_GAIN_MUTE,
2836 AMP_IN_MUTE(i));
2837 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002838}
2839
Takashi Iwai7085ec12009-10-02 09:03:58 +02002840/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002841static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002842{
Takashi Iwai604401a2011-04-27 15:14:23 +02002843 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002844 int i, num;
2845
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002846 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2847 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002848 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2849 for (i = 0; i < num; i++) {
2850 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2851 return list[i];
2852 }
2853 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002854}
2855
Takashi Iwai604401a2011-04-27 15:14:23 +02002856/* go down to the selector widget before the mixer */
2857static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2858{
2859 hda_nid_t srcs[5];
2860 int num = snd_hda_get_connections(codec, pin, srcs,
2861 ARRAY_SIZE(srcs));
2862 if (num != 1 ||
2863 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2864 return pin;
2865 return srcs[0];
2866}
2867
Takashi Iwai7085ec12009-10-02 09:03:58 +02002868/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002869static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002870 hda_nid_t dac)
2871{
David Henningssoncc1c4522010-11-24 14:17:47 +01002872 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002873 int i, num;
2874
Takashi Iwai604401a2011-04-27 15:14:23 +02002875 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002876 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2877 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002878 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002879 return mix[i];
2880 }
2881 return 0;
2882}
2883
Takashi Iwaice764ab2011-04-27 16:35:23 +02002884/* select the connection from pin to DAC if needed */
2885static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2886 hda_nid_t dac)
2887{
2888 hda_nid_t mix[5];
2889 int i, num;
2890
2891 pin = alc_go_down_to_selector(codec, pin);
2892 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2893 if (num < 2)
2894 return 0;
2895 for (i = 0; i < num; i++) {
2896 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2897 snd_hda_codec_update_cache(codec, pin, 0,
2898 AC_VERB_SET_CONNECT_SEL, i);
2899 return 0;
2900 }
2901 }
2902 return 0;
2903}
2904
Takashi Iwai185d99f2012-02-16 18:39:45 +01002905static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2906{
2907 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002908 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002909 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2910 ARRAY_SIZE(spec->private_dac_nids)) ||
2911 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2912 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2913 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2914 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2915 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002916 for (i = 0; i < spec->multi_ios; i++) {
2917 if (spec->multi_io[i].dac == nid)
2918 return true;
2919 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002920 return false;
2921}
2922
Takashi Iwai07b18f62011-11-10 15:42:54 +01002923/* check whether the DAC is reachable from the pin */
2924static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2925 hda_nid_t pin, hda_nid_t dac)
2926{
Takashi Iwaidc31b582012-02-17 17:27:53 +01002927 if (!pin || !dac)
2928 return false;
Takashi Iwai6a84c302012-12-05 14:08:45 +01002929 return snd_hda_get_conn_index(codec, pin, dac, true) >= 0;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002930}
2931
Takashi Iwai463419d2012-12-05 14:17:37 +01002932/* look for an empty DAC slot */
2933static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2934{
2935 struct alc_spec *spec = codec->spec;
2936 int i;
2937
2938 for (i = 0; i < spec->num_all_dacs; i++) {
2939 hda_nid_t nid = spec->all_dacs[i];
2940 if (!nid || alc_is_dac_already_used(codec, nid))
2941 continue;
2942 if (alc_auto_is_dac_reachable(codec, pin, nid))
2943 return nid;
2944 }
2945 return 0;
2946}
2947
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002948static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2949{
Takashi Iwai140547e2012-02-16 17:23:46 +01002950 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002951 int i;
2952 hda_nid_t nid_found = 0;
2953
2954 for (i = 0; i < spec->num_all_dacs; i++) {
2955 hda_nid_t nid = spec->all_dacs[i];
2956 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002957 continue;
Takashi Iwai463419d2012-12-05 14:17:37 +01002958 if (alc_auto_is_dac_reachable(codec, pin, nid)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01002959 if (nid_found)
2960 return 0;
2961 nid_found = nid;
2962 }
2963 }
2964 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002965}
2966
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002967/* mark up volume and mute control NIDs: used during badness parsing and
2968 * at creating actual controls
2969 */
2970static inline unsigned int get_ctl_pos(unsigned int data)
2971{
2972 hda_nid_t nid = get_amp_nid_(data);
2973 unsigned int dir;
2974 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
2975 return 0;
2976 dir = get_amp_direction_(data);
2977 return (nid << 1) | dir;
2978}
2979
2980#define is_ctl_used(bits, data) \
2981 test_bit(get_ctl_pos(data), bits)
2982#define mark_ctl_usage(bits, data) \
2983 set_bit(get_ctl_pos(data), bits)
2984
2985static void clear_vol_marks(struct hda_codec *codec)
2986{
2987 struct alc_spec *spec = codec->spec;
2988 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
2989 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
2990}
2991
2992/* badness definition */
2993enum {
2994 /* No primary DAC is found for the main output */
2995 BAD_NO_PRIMARY_DAC = 0x10000,
2996 /* No DAC is found for the extra output */
2997 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01002998 /* No possible multi-ios */
2999 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003000 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003001 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003002 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003003 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003004 /* Primary DAC shared with main surrounds */
3005 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003006 /* Primary DAC shared with main CLFE */
3007 BAD_SHARED_CLFE = 0x10,
3008 /* Primary DAC shared with extra surrounds */
3009 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003010 /* Volume widget is shared */
3011 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003012};
3013
3014static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3015 hda_nid_t pin, hda_nid_t dac);
3016static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3017 hda_nid_t pin, hda_nid_t dac);
3018
3019static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3020 hda_nid_t dac)
3021{
3022 struct alc_spec *spec = codec->spec;
3023 hda_nid_t nid;
3024 unsigned int val;
3025 int badness = 0;
3026
3027 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3028 if (nid) {
3029 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3030 if (is_ctl_used(spec->vol_ctls, nid))
3031 badness += BAD_SHARED_VOL;
3032 else
3033 mark_ctl_usage(spec->vol_ctls, val);
3034 } else
3035 badness += BAD_SHARED_VOL;
3036 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3037 if (nid) {
3038 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3039 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3040 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3041 else
3042 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3043 if (is_ctl_used(spec->sw_ctls, val))
3044 badness += BAD_SHARED_VOL;
3045 else
3046 mark_ctl_usage(spec->sw_ctls, val);
3047 } else
3048 badness += BAD_SHARED_VOL;
3049 return badness;
3050}
3051
Takashi Iwaidc31b582012-02-17 17:27:53 +01003052struct badness_table {
3053 int no_primary_dac; /* no primary DAC */
3054 int no_dac; /* no secondary DACs */
3055 int shared_primary; /* primary DAC is shared with main output */
3056 int shared_surr; /* secondary DAC shared with main or primary */
3057 int shared_clfe; /* third DAC shared with main or primary */
3058 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3059};
3060
3061static struct badness_table main_out_badness = {
3062 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3063 .no_dac = BAD_NO_DAC,
3064 .shared_primary = BAD_NO_PRIMARY_DAC,
3065 .shared_surr = BAD_SHARED_SURROUND,
3066 .shared_clfe = BAD_SHARED_CLFE,
3067 .shared_surr_main = BAD_SHARED_SURROUND,
3068};
3069
3070static struct badness_table extra_out_badness = {
3071 .no_primary_dac = BAD_NO_DAC,
3072 .no_dac = BAD_NO_DAC,
3073 .shared_primary = BAD_NO_EXTRA_DAC,
3074 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3075 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3076 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3077};
3078
3079/* try to assign DACs to pins and return the resultant badness */
3080static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3081 const hda_nid_t *pins, hda_nid_t *dacs,
3082 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003083{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003084 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003085 struct auto_pin_cfg *cfg = &spec->autocfg;
3086 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003087 int badness = 0;
3088 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003089
Takashi Iwai185d99f2012-02-16 18:39:45 +01003090 if (!num_outs)
3091 return 0;
3092
Takashi Iwaidc31b582012-02-17 17:27:53 +01003093 for (i = 0; i < num_outs; i++) {
3094 hda_nid_t pin = pins[i];
3095 if (!dacs[i])
3096 dacs[i] = alc_auto_look_for_dac(codec, pin);
3097 if (!dacs[i] && !i) {
3098 for (j = 1; j < num_outs; j++) {
3099 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3100 dacs[0] = dacs[j];
3101 dacs[j] = 0;
3102 break;
3103 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003104 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003105 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003106 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003107 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003108 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003109 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003110 else if (cfg->line_outs > i &&
3111 alc_auto_is_dac_reachable(codec, pin,
3112 spec->private_dac_nids[i]))
3113 dac = spec->private_dac_nids[i];
3114 if (dac) {
3115 if (!i)
3116 badness += bad->shared_primary;
3117 else if (i == 1)
3118 badness += bad->shared_surr;
3119 else
3120 badness += bad->shared_clfe;
3121 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003122 spec->private_dac_nids[0])) {
3123 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003124 badness += bad->shared_surr_main;
3125 } else if (!i)
3126 badness += bad->no_primary_dac;
3127 else
3128 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003129 }
3130 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003131 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003132 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003133
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003134 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003135}
3136
3137static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003138 hda_nid_t reference_pin,
3139 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003140
Takashi Iwai185d99f2012-02-16 18:39:45 +01003141static bool alc_map_singles(struct hda_codec *codec, int outs,
3142 const hda_nid_t *pins, hda_nid_t *dacs)
3143{
3144 int i;
3145 bool found = false;
3146 for (i = 0; i < outs; i++) {
3147 if (dacs[i])
3148 continue;
3149 dacs[i] = get_dac_if_single(codec, pins[i]);
3150 if (dacs[i])
3151 found = true;
3152 }
3153 return found;
3154}
3155
Takashi Iwai7085ec12009-10-02 09:03:58 +02003156/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003157static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003158 bool fill_hardwired,
3159 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003160{
3161 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003162 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003163 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003164
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003165 /* set num_dacs once to full for alc_auto_look_for_dac() */
3166 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003167 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003168 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3169 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3170 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003171 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003172 clear_vol_marks(codec);
3173 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003174
3175 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003176 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003177 bool mapped;
3178 do {
3179 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003180 cfg->line_out_pins,
3181 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003182 mapped |= alc_map_singles(codec, cfg->hp_outs,
3183 cfg->hp_pins,
3184 spec->multiout.hp_out_nid);
3185 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3186 cfg->speaker_pins,
3187 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003188 if (fill_mio_first && cfg->line_outs == 1 &&
3189 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3190 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3191 if (!err)
3192 mapped = true;
3193 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003194 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003195 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003196
Takashi Iwaidc31b582012-02-17 17:27:53 +01003197 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3198 spec->private_dac_nids,
3199 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003200
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003201 /* re-count num_dacs and squash invalid entries */
3202 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003203 for (i = 0; i < cfg->line_outs; i++) {
3204 if (spec->private_dac_nids[i])
3205 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003206 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003207 memmove(spec->private_dac_nids + i,
3208 spec->private_dac_nids + i + 1,
3209 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003210 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3211 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003212 }
3213
Takashi Iwai276dd702012-02-17 16:17:03 +01003214 if (fill_mio_first &&
3215 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003216 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003217 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003218 if (err < 0)
3219 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003220 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003221 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003222
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003223 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003224 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3225 spec->multiout.hp_out_nid,
3226 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003227 if (err < 0)
3228 return err;
3229 badness += err;
3230 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003231 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003232 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3233 cfg->speaker_pins,
3234 spec->multiout.extra_out_nid,
3235 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003236 if (err < 0)
3237 return err;
3238 badness += err;
3239 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003240 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3241 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003242 if (err < 0)
3243 return err;
3244 badness += err;
3245 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003246 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3247 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003248 int offset = 0;
3249 if (cfg->line_outs >= 3)
3250 offset = 1;
3251 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3252 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003253 if (err < 0)
3254 return err;
3255 badness += err;
3256 }
3257
3258 if (spec->multi_ios == 2) {
3259 for (i = 0; i < 2; i++)
3260 spec->private_dac_nids[spec->multiout.num_dacs++] =
3261 spec->multi_io[i].dac;
3262 spec->ext_channel_count = 2;
3263 } else if (spec->multi_ios) {
3264 spec->multi_ios = 0;
3265 badness += BAD_MULTI_IO;
3266 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003267
3268 return badness;
3269}
3270
3271#define DEBUG_BADNESS
3272
3273#ifdef DEBUG_BADNESS
3274#define debug_badness snd_printdd
3275#else
3276#define debug_badness(...)
3277#endif
3278
3279static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3280{
3281 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3282 cfg->line_out_pins[0], cfg->line_out_pins[1],
3283 cfg->line_out_pins[2], cfg->line_out_pins[2],
3284 spec->multiout.dac_nids[0],
3285 spec->multiout.dac_nids[1],
3286 spec->multiout.dac_nids[2],
3287 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003288 if (spec->multi_ios > 0)
3289 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3290 spec->multi_ios,
3291 spec->multi_io[0].pin, spec->multi_io[1].pin,
3292 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003293 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3294 cfg->hp_pins[0], cfg->hp_pins[1],
3295 cfg->hp_pins[2], cfg->hp_pins[2],
3296 spec->multiout.hp_out_nid[0],
3297 spec->multiout.hp_out_nid[1],
3298 spec->multiout.hp_out_nid[2],
3299 spec->multiout.hp_out_nid[3]);
3300 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3301 cfg->speaker_pins[0], cfg->speaker_pins[1],
3302 cfg->speaker_pins[2], cfg->speaker_pins[3],
3303 spec->multiout.extra_out_nid[0],
3304 spec->multiout.extra_out_nid[1],
3305 spec->multiout.extra_out_nid[2],
3306 spec->multiout.extra_out_nid[3]);
3307}
3308
Takashi Iwai463419d2012-12-05 14:17:37 +01003309/* find all available DACs of the codec */
3310static void alc_fill_all_nids(struct hda_codec *codec)
3311{
3312 struct alc_spec *spec = codec->spec;
3313 int i;
3314 hda_nid_t nid = codec->start_nid;
3315
3316 spec->num_all_dacs = 0;
3317 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3318 for (i = 0; i < codec->num_nodes; i++, nid++) {
3319 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3320 continue;
3321 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3322 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3323 break;
3324 }
3325 spec->all_dacs[spec->num_all_dacs++] = nid;
3326 }
3327}
3328
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003329static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3330{
3331 struct alc_spec *spec = codec->spec;
3332 struct auto_pin_cfg *cfg = &spec->autocfg;
3333 struct auto_pin_cfg *best_cfg;
3334 int best_badness = INT_MAX;
3335 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003336 bool fill_hardwired = true, fill_mio_first = true;
3337 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003338 bool hp_spk_swapped = false;
3339
Takashi Iwai463419d2012-12-05 14:17:37 +01003340 alc_fill_all_nids(codec);
3341
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003342 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3343 if (!best_cfg)
3344 return -ENOMEM;
3345 *best_cfg = *cfg;
3346
3347 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003348 badness = fill_and_eval_dacs(codec, fill_hardwired,
3349 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003350 if (badness < 0) {
3351 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003352 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003353 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003354 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3355 cfg->line_out_type, fill_hardwired, fill_mio_first,
3356 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003357 debug_show_configs(spec, cfg);
3358 if (badness < best_badness) {
3359 best_badness = badness;
3360 *best_cfg = *cfg;
3361 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003362 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003363 }
3364 if (!badness)
3365 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003366 fill_mio_first = !fill_mio_first;
3367 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003368 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003369 fill_hardwired = !fill_hardwired;
3370 if (!fill_hardwired)
3371 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003372 if (hp_spk_swapped)
3373 break;
3374 hp_spk_swapped = true;
3375 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003376 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3377 cfg->hp_outs = cfg->line_outs;
3378 memcpy(cfg->hp_pins, cfg->line_out_pins,
3379 sizeof(cfg->hp_pins));
3380 cfg->line_outs = cfg->speaker_outs;
3381 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3382 sizeof(cfg->speaker_pins));
3383 cfg->speaker_outs = 0;
3384 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3385 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003386 fill_hardwired = true;
3387 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003388 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003389 if (cfg->hp_outs > 0 &&
3390 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3391 cfg->speaker_outs = cfg->line_outs;
3392 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3393 sizeof(cfg->speaker_pins));
3394 cfg->line_outs = cfg->hp_outs;
3395 memcpy(cfg->line_out_pins, cfg->hp_pins,
3396 sizeof(cfg->hp_pins));
3397 cfg->hp_outs = 0;
3398 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3399 cfg->line_out_type = AUTO_PIN_HP_OUT;
3400 fill_hardwired = true;
3401 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003402 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003403 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003404 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003405
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003406 if (badness) {
3407 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003408 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003409 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003410 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3411 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003412 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003413
David Henningssonfde48a12011-12-09 18:27:42 +08003414 if (cfg->line_out_pins[0])
3415 spec->vmaster_nid =
3416 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3417 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003418
3419 /* clear the bitmap flags for creating controls */
3420 clear_vol_marks(codec);
3421 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003422 return 0;
3423}
3424
Takashi Iwai343a04b2011-07-06 14:28:39 +02003425static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003426 const char *pfx, int cidx,
3427 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003428{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003429 struct alc_spec *spec = codec->spec;
3430 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003431 if (!nid)
3432 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003433 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3434 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3435 return 0;
3436 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003437 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003438 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003439}
3440
Takashi Iwaie29d3772011-11-14 17:13:23 +01003441static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3442 const char *pfx, int cidx,
3443 hda_nid_t nid)
3444{
3445 int chs = 1;
3446 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3447 chs = 3;
3448 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3449}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003450
3451/* create a mute-switch for the given mixer widget;
3452 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3453 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003454static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003455 const char *pfx, int cidx,
3456 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003457{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003458 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003459 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003460 int type;
3461 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003462 if (!nid)
3463 return 0;
3464 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3465 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3466 type = ALC_CTL_WIDGET_MUTE;
3467 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003468 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003469 type = ALC_CTL_WIDGET_MUTE;
3470 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3471 } else {
3472 type = ALC_CTL_BIND_MUTE;
3473 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3474 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003475 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3476 return 0;
3477 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003478 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003479}
3480
Takashi Iwaie29d3772011-11-14 17:13:23 +01003481static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3482 int cidx, hda_nid_t nid)
3483{
3484 int chs = 1;
3485 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3486 chs = 3;
3487 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3488}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003489
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003490static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3491 hda_nid_t pin, hda_nid_t dac)
3492{
3493 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3494 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3495 return pin;
3496 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3497 return mix;
3498 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3499 return dac;
3500 return 0;
3501}
3502
3503static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3504 hda_nid_t pin, hda_nid_t dac)
3505{
3506 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3507 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3508 return dac;
3509 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3510 return mix;
3511 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3512 return pin;
3513 return 0;
3514}
3515
Takashi Iwai7085ec12009-10-02 09:03:58 +02003516/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003517static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003518 const struct auto_pin_cfg *cfg)
3519{
3520 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003521 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003522
Takashi Iwaice764ab2011-04-27 16:35:23 +02003523 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003524 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003525 noutputs += spec->multi_ios;
3526
3527 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003528 const char *name;
3529 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003530 hda_nid_t dac, pin;
3531 hda_nid_t sw, vol;
3532
3533 dac = spec->multiout.dac_nids[i];
3534 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003535 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003536 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003537 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003538 index = 0;
3539 name = channel_name[i];
3540 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003541 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003542 name = alc_get_line_out_pfx(spec, i, true, &index);
3543 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003544
3545 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3546 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003547 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003548 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003549 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003550 if (err < 0)
3551 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003552 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003553 if (err < 0)
3554 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003555 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003556 if (err < 0)
3557 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003558 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003559 if (err < 0)
3560 return err;
3561 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003562 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003563 if (err < 0)
3564 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003565 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003566 if (err < 0)
3567 return err;
3568 }
3569 }
3570 return 0;
3571}
3572
Takashi Iwai343a04b2011-07-06 14:28:39 +02003573static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003574 hda_nid_t dac, const char *pfx,
3575 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003576{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003577 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003578 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003579 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003580
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003581 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003582 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003583 /* the corresponding DAC is already occupied */
3584 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3585 return 0; /* no way */
3586 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003587 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3588 if (is_ctl_used(spec->sw_ctls, val))
3589 return 0; /* already created */
3590 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003591 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003592 }
3593
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003594 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3595 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003596 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003597 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003598 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003599 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003600 if (err < 0)
3601 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003602 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003603}
3604
Takashi Iwai23c09b02011-08-19 09:05:35 +02003605static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3606 unsigned int nums,
3607 struct hda_ctl_ops *ops)
3608{
3609 struct alc_spec *spec = codec->spec;
3610 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003611 ctlp = snd_array_new(&spec->bind_ctls);
3612 if (!ctlp)
3613 return NULL;
3614 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3615 *ctlp = ctl;
3616 if (ctl)
3617 ctl->ops = ops;
3618 return ctl;
3619}
3620
3621/* add playback controls for speaker and HP outputs */
3622static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3623 const hda_nid_t *pins,
3624 const hda_nid_t *dacs,
3625 const char *pfx)
3626{
3627 struct alc_spec *spec = codec->spec;
3628 struct hda_bind_ctls *ctl;
3629 char name[32];
3630 int i, n, err;
3631
3632 if (!num_pins || !pins[0])
3633 return 0;
3634
Takashi Iwai527e4d72011-10-27 16:33:27 +02003635 if (num_pins == 1) {
3636 hda_nid_t dac = *dacs;
3637 if (!dac)
3638 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003639 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003640 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003641
Takashi Iwai23c09b02011-08-19 09:05:35 +02003642 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003643 hda_nid_t dac;
3644 if (dacs[num_pins - 1])
3645 dac = dacs[i]; /* with individual volumes */
3646 else
3647 dac = 0;
3648 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3649 err = alc_auto_create_extra_out(codec, pins[i], dac,
3650 "Bass Speaker", 0);
3651 } else if (num_pins >= 3) {
3652 snprintf(name, sizeof(name), "%s %s",
3653 pfx, channel_name[i]);
3654 err = alc_auto_create_extra_out(codec, pins[i], dac,
3655 name, 0);
3656 } else {
3657 err = alc_auto_create_extra_out(codec, pins[i], dac,
3658 pfx, i);
3659 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003660 if (err < 0)
3661 return err;
3662 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003663 if (dacs[num_pins - 1])
3664 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003665
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003666 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003667 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3668 if (!ctl)
3669 return -ENOMEM;
3670 n = 0;
3671 for (i = 0; i < num_pins; i++) {
3672 hda_nid_t vol;
3673 if (!pins[i] || !dacs[i])
3674 continue;
3675 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3676 if (vol)
3677 ctl->values[n++] =
3678 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3679 }
3680 if (n) {
3681 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3682 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3683 if (err < 0)
3684 return err;
3685 }
3686 return 0;
3687}
3688
Takashi Iwai343a04b2011-07-06 14:28:39 +02003689static int alc_auto_create_hp_out(struct hda_codec *codec)
3690{
3691 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003692 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3693 spec->autocfg.hp_pins,
3694 spec->multiout.hp_out_nid,
3695 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003696}
3697
3698static int alc_auto_create_speaker_out(struct hda_codec *codec)
3699{
3700 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003701 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3702 spec->autocfg.speaker_pins,
3703 spec->multiout.extra_out_nid,
3704 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003705}
3706
Takashi Iwai343a04b2011-07-06 14:28:39 +02003707static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003708 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003709 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003710{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003711 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003712 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003713 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003714
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003715 alc_set_pin_output(codec, pin, pin_type);
3716 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003717 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003718 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003719 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003720 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003721 mix = srcs[i];
3722 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003723 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003724 if (!mix)
3725 return;
3726
3727 /* need the manual connection? */
3728 if (num > 1)
3729 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3730 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003731 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3732 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003733 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003734 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003735 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003736 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003737 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003738 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3739 if (nid)
3740 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3741 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003742
3743 /* unmute DAC if it's not assigned to a mixer */
3744 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3745 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3746 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3747 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003748}
3749
Takashi Iwai343a04b2011-07-06 14:28:39 +02003750static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003751{
3752 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003753 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003754 int i;
3755
3756 for (i = 0; i <= HDA_SIDE; i++) {
3757 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3758 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003759 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003760 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003761 }
3762}
3763
Takashi Iwai343a04b2011-07-06 14:28:39 +02003764static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003765{
3766 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003767 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003768 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003769
David Henningsson636030e2011-10-12 19:26:03 +02003770 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003771 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3772 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003773 pin = spec->autocfg.hp_pins[i];
3774 if (!pin)
3775 break;
3776 dac = spec->multiout.hp_out_nid[i];
3777 if (!dac) {
3778 if (i > 0 && spec->multiout.hp_out_nid[0])
3779 dac = spec->multiout.hp_out_nid[0];
3780 else
3781 dac = spec->multiout.dac_nids[0];
3782 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003783 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3784 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003785 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003786 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3787 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003788 pin = spec->autocfg.speaker_pins[i];
3789 if (!pin)
3790 break;
3791 dac = spec->multiout.extra_out_nid[i];
3792 if (!dac) {
3793 if (i > 0 && spec->multiout.extra_out_nid[0])
3794 dac = spec->multiout.extra_out_nid[0];
3795 else
3796 dac = spec->multiout.dac_nids[0];
3797 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003798 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3799 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003800}
3801
Takashi Iwai276dd702012-02-17 16:17:03 +01003802/* check whether the given pin can be a multi-io pin */
3803static bool can_be_multiio_pin(struct hda_codec *codec,
3804 unsigned int location, hda_nid_t nid)
3805{
3806 unsigned int defcfg, caps;
3807
3808 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3809 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3810 return false;
3811 if (location && get_defcfg_location(defcfg) != location)
3812 return false;
3813 caps = snd_hda_query_pin_caps(codec, nid);
3814 if (!(caps & AC_PINCAP_OUT))
3815 return false;
3816 return true;
3817}
3818
Takashi Iwaice764ab2011-04-27 16:35:23 +02003819/*
3820 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003821 *
3822 * When hardwired is set, try to fill ony hardwired pins, and returns
3823 * zero if any pins are filled, non-zero if nothing found.
3824 * When hardwired is off, try to fill possible input pins, and returns
3825 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003826 */
3827static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003828 hda_nid_t reference_pin,
3829 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003830{
3831 struct alc_spec *spec = codec->spec;
3832 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003833 int type, i, j, dacs, num_pins, old_pins;
3834 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3835 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003836 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003837
Takashi Iwai276dd702012-02-17 16:17:03 +01003838 old_pins = spec->multi_ios;
3839 if (old_pins >= 2)
3840 goto end_fill;
3841
3842 num_pins = 0;
3843 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3844 for (i = 0; i < cfg->num_inputs; i++) {
3845 if (cfg->inputs[i].type != type)
3846 continue;
3847 if (can_be_multiio_pin(codec, location,
3848 cfg->inputs[i].pin))
3849 num_pins++;
3850 }
3851 }
3852 if (num_pins < 2)
3853 goto end_fill;
3854
Takashi Iwai07b18f62011-11-10 15:42:54 +01003855 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003856 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3857 for (i = 0; i < cfg->num_inputs; i++) {
3858 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003859 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003860
Takashi Iwaice764ab2011-04-27 16:35:23 +02003861 if (cfg->inputs[i].type != type)
3862 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003863 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003864 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003865 for (j = 0; j < spec->multi_ios; j++) {
3866 if (nid == spec->multi_io[j].pin)
3867 break;
3868 }
3869 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003870 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003871
3872 if (offset && offset + spec->multi_ios < dacs) {
3873 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003874 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3875 dac = 0;
3876 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003877 if (hardwired)
3878 dac = get_dac_if_single(codec, nid);
3879 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003880 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003881 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003882 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003883 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003884 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003885 spec->multi_io[spec->multi_ios].pin = nid;
3886 spec->multi_io[spec->multi_ios].dac = dac;
3887 spec->multi_ios++;
3888 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003889 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003890 }
3891 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003892 end_fill:
3893 if (badness)
3894 badness = BAD_MULTI_IO;
3895 if (old_pins == spec->multi_ios) {
3896 if (hardwired)
3897 return 1; /* nothing found */
3898 else
3899 return badness; /* no badness if nothing found */
3900 }
3901 if (!hardwired && spec->multi_ios < 2) {
3902 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003903 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003904 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003905
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003906 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003907}
3908
3909static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3910 struct snd_ctl_elem_info *uinfo)
3911{
3912 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3913 struct alc_spec *spec = codec->spec;
3914
3915 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3916 uinfo->count = 1;
3917 uinfo->value.enumerated.items = spec->multi_ios + 1;
3918 if (uinfo->value.enumerated.item > spec->multi_ios)
3919 uinfo->value.enumerated.item = spec->multi_ios;
3920 sprintf(uinfo->value.enumerated.name, "%dch",
3921 (uinfo->value.enumerated.item + 1) * 2);
3922 return 0;
3923}
3924
3925static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3926 struct snd_ctl_elem_value *ucontrol)
3927{
3928 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3929 struct alc_spec *spec = codec->spec;
3930 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3931 return 0;
3932}
3933
3934static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3935{
3936 struct alc_spec *spec = codec->spec;
3937 hda_nid_t nid = spec->multi_io[idx].pin;
3938
3939 if (!spec->multi_io[idx].ctl_in)
3940 spec->multi_io[idx].ctl_in =
3941 snd_hda_codec_read(codec, nid, 0,
3942 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3943 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003944 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003945 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3946 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3947 HDA_AMP_MUTE, 0);
3948 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3949 } else {
3950 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3951 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3952 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003953 snd_hda_set_pin_ctl_cache(codec, nid,
3954 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003955 }
3956 return 0;
3957}
3958
3959static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3960 struct snd_ctl_elem_value *ucontrol)
3961{
3962 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3963 struct alc_spec *spec = codec->spec;
3964 int i, ch;
3965
3966 ch = ucontrol->value.enumerated.item[0];
3967 if (ch < 0 || ch > spec->multi_ios)
3968 return -EINVAL;
3969 if (ch == (spec->ext_channel_count - 1) / 2)
3970 return 0;
3971 spec->ext_channel_count = (ch + 1) * 2;
3972 for (i = 0; i < spec->multi_ios; i++)
3973 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01003974 spec->multiout.max_channels = max(spec->ext_channel_count,
3975 spec->const_channel_count);
3976 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003977 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003978 return 1;
3979}
3980
Takashi Iwaia9111322011-05-02 11:30:18 +02003981static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003982 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3983 .name = "Channel Mode",
3984 .info = alc_auto_ch_mode_info,
3985 .get = alc_auto_ch_mode_get,
3986 .put = alc_auto_ch_mode_put,
3987};
3988
Takashi Iwai23c09b02011-08-19 09:05:35 +02003989static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003990{
3991 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003992
Takashi Iwaic2674682011-08-24 17:57:44 +02003993 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01003994 if (!alc_kcontrol_new(spec, "Channel Mode",
3995 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003996 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003997 }
3998 return 0;
3999}
4000
Takashi Iwai1d045db2011-07-07 18:23:21 +02004001/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4002 * active input pins
4003 */
4004static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4005{
4006 struct alc_spec *spec = codec->spec;
4007 const struct hda_input_mux *imux;
4008 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4009 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4010 int i, n, nums;
4011
4012 imux = spec->input_mux;
4013 if (!imux)
4014 return;
4015 if (spec->dyn_adc_switch)
4016 return;
4017
Takashi Iwai26acaf02012-03-22 14:36:50 +01004018 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004019 nums = 0;
4020 for (n = 0; n < spec->num_adc_nids; n++) {
4021 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004022 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004023 for (i = 0; i < imux->num_items; i++) {
4024 hda_nid_t pin = spec->imux_pins[i];
4025 if (pin) {
4026 if (get_connection_index(codec, cap, pin) < 0)
4027 break;
4028 } else if (num_conns <= imux->items[i].index)
4029 break;
4030 }
4031 if (i >= imux->num_items) {
4032 adc_nids[nums] = spec->private_adc_nids[n];
4033 capsrc_nids[nums++] = cap;
4034 }
4035 }
4036 if (!nums) {
4037 /* check whether ADC-switch is possible */
4038 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004039 if (spec->shared_mic_hp) {
4040 spec->shared_mic_hp = 0;
4041 spec->private_imux[0].num_items = 1;
4042 goto again;
4043 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004044 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4045 " using fallback 0x%x\n",
4046 codec->chip_name, spec->private_adc_nids[0]);
4047 spec->num_adc_nids = 1;
4048 spec->auto_mic = 0;
4049 return;
4050 }
4051 } else if (nums != spec->num_adc_nids) {
4052 memcpy(spec->private_adc_nids, adc_nids,
4053 nums * sizeof(hda_nid_t));
4054 memcpy(spec->private_capsrc_nids, capsrc_nids,
4055 nums * sizeof(hda_nid_t));
4056 spec->num_adc_nids = nums;
4057 }
4058
4059 if (spec->auto_mic)
4060 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004061 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004062 spec->num_adc_nids = 1; /* reduce to a single ADC */
4063}
4064
4065/*
4066 * initialize ADC paths
4067 */
4068static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4069{
4070 struct alc_spec *spec = codec->spec;
4071 hda_nid_t nid;
4072
4073 nid = spec->adc_nids[adc_idx];
4074 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004075 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004076 snd_hda_codec_write(codec, nid, 0,
4077 AC_VERB_SET_AMP_GAIN_MUTE,
4078 AMP_IN_MUTE(0));
4079 return;
4080 }
4081 if (!spec->capsrc_nids)
4082 return;
4083 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004084 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004085 snd_hda_codec_write(codec, nid, 0,
4086 AC_VERB_SET_AMP_GAIN_MUTE,
4087 AMP_OUT_MUTE);
4088}
4089
4090static void alc_auto_init_input_src(struct hda_codec *codec)
4091{
4092 struct alc_spec *spec = codec->spec;
4093 int c, nums;
4094
4095 for (c = 0; c < spec->num_adc_nids; c++)
4096 alc_auto_init_adc(codec, c);
4097 if (spec->dyn_adc_switch)
4098 nums = 1;
4099 else
4100 nums = spec->num_adc_nids;
4101 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004102 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004103}
4104
4105/* add mic boosts if needed */
4106static int alc_auto_add_mic_boost(struct hda_codec *codec)
4107{
4108 struct alc_spec *spec = codec->spec;
4109 struct auto_pin_cfg *cfg = &spec->autocfg;
4110 int i, err;
4111 int type_idx = 0;
4112 hda_nid_t nid;
4113 const char *prev_label = NULL;
4114
4115 for (i = 0; i < cfg->num_inputs; i++) {
4116 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4117 break;
4118 nid = cfg->inputs[i].pin;
4119 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4120 const char *label;
4121 char boost_label[32];
4122
4123 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004124 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4125 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004126 if (prev_label && !strcmp(label, prev_label))
4127 type_idx++;
4128 else
4129 type_idx = 0;
4130 prev_label = label;
4131
4132 snprintf(boost_label, sizeof(boost_label),
4133 "%s Boost Volume", label);
4134 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4135 boost_label, type_idx,
4136 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4137 if (err < 0)
4138 return err;
4139 }
4140 }
4141 return 0;
4142}
4143
4144/* select or unmute the given capsrc route */
4145static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4146 int idx)
4147{
4148 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4149 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4150 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004151 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004152 snd_hda_codec_write_cache(codec, cap, 0,
4153 AC_VERB_SET_CONNECT_SEL, idx);
4154 }
4155}
4156
4157/* set the default connection to that pin */
4158static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4159{
4160 struct alc_spec *spec = codec->spec;
4161 int i;
4162
4163 if (!pin)
4164 return 0;
4165 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004166 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004167 int idx;
4168
4169 idx = get_connection_index(codec, cap, pin);
4170 if (idx < 0)
4171 continue;
4172 select_or_unmute_capsrc(codec, cap, idx);
4173 return i; /* return the found index */
4174 }
4175 return -1; /* not found */
4176}
4177
4178/* initialize some special cases for input sources */
4179static void alc_init_special_input_src(struct hda_codec *codec)
4180{
4181 struct alc_spec *spec = codec->spec;
4182 int i;
4183
4184 for (i = 0; i < spec->autocfg.num_inputs; i++)
4185 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4186}
4187
4188/* assign appropriate capture mixers */
4189static void set_capture_mixer(struct hda_codec *codec)
4190{
4191 struct alc_spec *spec = codec->spec;
4192 static const struct snd_kcontrol_new *caps[2][3] = {
4193 { alc_capture_mixer_nosrc1,
4194 alc_capture_mixer_nosrc2,
4195 alc_capture_mixer_nosrc3 },
4196 { alc_capture_mixer1,
4197 alc_capture_mixer2,
4198 alc_capture_mixer3 },
4199 };
4200
4201 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004202 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004203 if (!spec->capsrc_nids)
4204 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004205 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004206 return; /* no volume in capsrc, too */
4207 spec->vol_in_capsrc = 1;
4208 }
4209
4210 if (spec->num_adc_nids > 0) {
4211 int mux = 0;
4212 int num_adcs = 0;
4213
4214 if (spec->input_mux && spec->input_mux->num_items > 1)
4215 mux = 1;
4216 if (spec->auto_mic) {
4217 num_adcs = 1;
4218 mux = 0;
4219 } else if (spec->dyn_adc_switch)
4220 num_adcs = 1;
4221 if (!num_adcs) {
4222 if (spec->num_adc_nids > 3)
4223 spec->num_adc_nids = 3;
4224 else if (!spec->num_adc_nids)
4225 return;
4226 num_adcs = spec->num_adc_nids;
4227 }
4228 spec->cap_mixer = caps[mux][num_adcs - 1];
4229 }
4230}
4231
4232/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004233 * standard auto-parser initializations
4234 */
4235static void alc_auto_init_std(struct hda_codec *codec)
4236{
Takashi Iwaie4770622011-07-08 11:11:35 +02004237 alc_auto_init_multi_out(codec);
4238 alc_auto_init_extra_out(codec);
4239 alc_auto_init_analog_input(codec);
4240 alc_auto_init_input_src(codec);
4241 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004242 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004243}
4244
4245/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004246 * Digital-beep handlers
4247 */
4248#ifdef CONFIG_SND_HDA_INPUT_BEEP
4249#define set_beep_amp(spec, nid, idx, dir) \
4250 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4251
4252static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004253 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004254 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4255 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4256 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4257 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004258 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004259 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4260 {}
4261};
4262
4263static inline int has_cdefine_beep(struct hda_codec *codec)
4264{
4265 struct alc_spec *spec = codec->spec;
4266 const struct snd_pci_quirk *q;
4267 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4268 if (q)
4269 return q->value;
4270 return spec->cdefine.enable_pcbeep;
4271}
4272#else
4273#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4274#define has_cdefine_beep(codec) 0
4275#endif
4276
4277/* parse the BIOS configuration and set up the alc_spec */
4278/* return 1 if successful, 0 if the proper config is not found,
4279 * or a negative error code
4280 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004281static int alc_parse_auto_config(struct hda_codec *codec,
4282 const hda_nid_t *ignore_nids,
4283 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004284{
4285 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004286 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004287 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004288
Takashi Iwai53c334a2011-08-23 18:27:14 +02004289 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4290 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004291 if (err < 0)
4292 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004293 if (!cfg->line_outs) {
4294 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004295 spec->multiout.max_channels = 2;
4296 spec->no_analog = 1;
4297 goto dig_only;
4298 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004299 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004300 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004301
Takashi Iwaie427c232012-07-29 10:04:08 +02004302 if (!spec->no_primary_hp &&
4303 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004304 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004305 /* use HP as primary out */
4306 cfg->speaker_outs = cfg->line_outs;
4307 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4308 sizeof(cfg->speaker_pins));
4309 cfg->line_outs = cfg->hp_outs;
4310 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4311 cfg->hp_outs = 0;
4312 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4313 cfg->line_out_type = AUTO_PIN_HP_OUT;
4314 }
4315
Takashi Iwai1d045db2011-07-07 18:23:21 +02004316 err = alc_auto_fill_dac_nids(codec);
4317 if (err < 0)
4318 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004319 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004320 if (err < 0)
4321 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004322 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004323 if (err < 0)
4324 return err;
4325 err = alc_auto_create_hp_out(codec);
4326 if (err < 0)
4327 return err;
4328 err = alc_auto_create_speaker_out(codec);
4329 if (err < 0)
4330 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004331 err = alc_auto_create_shared_input(codec);
4332 if (err < 0)
4333 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004334 err = alc_auto_create_input_ctls(codec);
4335 if (err < 0)
4336 return err;
4337
Takashi Iwaib6adb572012-12-03 10:30:58 +01004338 /* check the multiple speaker pins */
4339 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4340 spec->const_channel_count = cfg->line_outs * 2;
4341 else
4342 spec->const_channel_count = cfg->speaker_outs * 2;
4343
4344 if (spec->multi_ios > 0)
4345 spec->multiout.max_channels = max(spec->ext_channel_count,
4346 spec->const_channel_count);
4347 else
4348 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004349
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004350 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004351 alc_auto_parse_digital(codec);
4352
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004353 if (!spec->no_analog)
4354 alc_remove_invalid_adc_nids(codec);
4355
4356 if (ssid_nids)
4357 alc_ssid_check(codec, ssid_nids);
4358
4359 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004360 err = alc_auto_check_switches(codec);
4361 if (err < 0)
4362 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004363 err = alc_auto_add_mic_boost(codec);
4364 if (err < 0)
4365 return err;
4366 }
4367
Takashi Iwai1d045db2011-07-07 18:23:21 +02004368 if (spec->kctls.list)
4369 add_mixer(spec, spec->kctls.list);
4370
Takashi Iwai070cff42012-02-21 12:54:17 +01004371 if (!spec->no_analog && !spec->cap_mixer)
4372 set_capture_mixer(codec);
4373
Takashi Iwai1d045db2011-07-07 18:23:21 +02004374 return 1;
4375}
4376
Takashi Iwai3de95172012-05-07 18:03:15 +02004377/* common preparation job for alc_spec */
4378static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4379{
4380 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4381 int err;
4382
4383 if (!spec)
4384 return -ENOMEM;
4385 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004386 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004387 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004388 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004389 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4390 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004391
4392 err = alc_codec_rename_from_preset(codec);
4393 if (err < 0) {
4394 kfree(spec);
4395 return err;
4396 }
4397 return 0;
4398}
4399
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004400static int alc880_parse_auto_config(struct hda_codec *codec)
4401{
4402 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004403 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004404 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4405}
4406
Takashi Iwai1d045db2011-07-07 18:23:21 +02004407/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004408 * ALC880 fix-ups
4409 */
4410enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004411 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004412 ALC880_FIXUP_GPIO2,
4413 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004414 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004415 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004416 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004417 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004418 ALC880_FIXUP_VOL_KNOB,
4419 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004420 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004421 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004422 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004423 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004424 ALC880_FIXUP_3ST_BASE,
4425 ALC880_FIXUP_3ST,
4426 ALC880_FIXUP_3ST_DIG,
4427 ALC880_FIXUP_5ST_BASE,
4428 ALC880_FIXUP_5ST,
4429 ALC880_FIXUP_5ST_DIG,
4430 ALC880_FIXUP_6ST_BASE,
4431 ALC880_FIXUP_6ST,
4432 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004433};
4434
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004435/* enable the volume-knob widget support on NID 0x21 */
4436static void alc880_fixup_vol_knob(struct hda_codec *codec,
4437 const struct alc_fixup *fix, int action)
4438{
4439 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004440 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004441}
4442
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004443static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004444 [ALC880_FIXUP_GPIO1] = {
4445 .type = ALC_FIXUP_VERBS,
4446 .v.verbs = alc_gpio1_init_verbs,
4447 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004448 [ALC880_FIXUP_GPIO2] = {
4449 .type = ALC_FIXUP_VERBS,
4450 .v.verbs = alc_gpio2_init_verbs,
4451 },
4452 [ALC880_FIXUP_MEDION_RIM] = {
4453 .type = ALC_FIXUP_VERBS,
4454 .v.verbs = (const struct hda_verb[]) {
4455 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4456 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4457 { }
4458 },
4459 .chained = true,
4460 .chain_id = ALC880_FIXUP_GPIO2,
4461 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004462 [ALC880_FIXUP_LG] = {
4463 .type = ALC_FIXUP_PINS,
4464 .v.pins = (const struct alc_pincfg[]) {
4465 /* disable bogus unused pins */
4466 { 0x16, 0x411111f0 },
4467 { 0x18, 0x411111f0 },
4468 { 0x1a, 0x411111f0 },
4469 { }
4470 }
4471 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004472 [ALC880_FIXUP_W810] = {
4473 .type = ALC_FIXUP_PINS,
4474 .v.pins = (const struct alc_pincfg[]) {
4475 /* disable bogus unused pins */
4476 { 0x17, 0x411111f0 },
4477 { }
4478 },
4479 .chained = true,
4480 .chain_id = ALC880_FIXUP_GPIO2,
4481 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004482 [ALC880_FIXUP_EAPD_COEF] = {
4483 .type = ALC_FIXUP_VERBS,
4484 .v.verbs = (const struct hda_verb[]) {
4485 /* change to EAPD mode */
4486 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4487 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4488 {}
4489 },
4490 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004491 [ALC880_FIXUP_TCL_S700] = {
4492 .type = ALC_FIXUP_VERBS,
4493 .v.verbs = (const struct hda_verb[]) {
4494 /* change to EAPD mode */
4495 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4496 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4497 {}
4498 },
4499 .chained = true,
4500 .chain_id = ALC880_FIXUP_GPIO2,
4501 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004502 [ALC880_FIXUP_VOL_KNOB] = {
4503 .type = ALC_FIXUP_FUNC,
4504 .v.func = alc880_fixup_vol_knob,
4505 },
4506 [ALC880_FIXUP_FUJITSU] = {
4507 /* override all pins as BIOS on old Amilo is broken */
4508 .type = ALC_FIXUP_PINS,
4509 .v.pins = (const struct alc_pincfg[]) {
4510 { 0x14, 0x0121411f }, /* HP */
4511 { 0x15, 0x99030120 }, /* speaker */
4512 { 0x16, 0x99030130 }, /* bass speaker */
4513 { 0x17, 0x411111f0 }, /* N/A */
4514 { 0x18, 0x411111f0 }, /* N/A */
4515 { 0x19, 0x01a19950 }, /* mic-in */
4516 { 0x1a, 0x411111f0 }, /* N/A */
4517 { 0x1b, 0x411111f0 }, /* N/A */
4518 { 0x1c, 0x411111f0 }, /* N/A */
4519 { 0x1d, 0x411111f0 }, /* N/A */
4520 { 0x1e, 0x01454140 }, /* SPDIF out */
4521 { }
4522 },
4523 .chained = true,
4524 .chain_id = ALC880_FIXUP_VOL_KNOB,
4525 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004526 [ALC880_FIXUP_F1734] = {
4527 /* almost compatible with FUJITSU, but no bass and SPDIF */
4528 .type = ALC_FIXUP_PINS,
4529 .v.pins = (const struct alc_pincfg[]) {
4530 { 0x14, 0x0121411f }, /* HP */
4531 { 0x15, 0x99030120 }, /* speaker */
4532 { 0x16, 0x411111f0 }, /* N/A */
4533 { 0x17, 0x411111f0 }, /* N/A */
4534 { 0x18, 0x411111f0 }, /* N/A */
4535 { 0x19, 0x01a19950 }, /* mic-in */
4536 { 0x1a, 0x411111f0 }, /* N/A */
4537 { 0x1b, 0x411111f0 }, /* N/A */
4538 { 0x1c, 0x411111f0 }, /* N/A */
4539 { 0x1d, 0x411111f0 }, /* N/A */
4540 { 0x1e, 0x411111f0 }, /* N/A */
4541 { }
4542 },
4543 .chained = true,
4544 .chain_id = ALC880_FIXUP_VOL_KNOB,
4545 },
Takashi Iwai817de922012-02-20 17:20:48 +01004546 [ALC880_FIXUP_UNIWILL] = {
4547 /* need to fix HP and speaker pins to be parsed correctly */
4548 .type = ALC_FIXUP_PINS,
4549 .v.pins = (const struct alc_pincfg[]) {
4550 { 0x14, 0x0121411f }, /* HP */
4551 { 0x15, 0x99030120 }, /* speaker */
4552 { 0x16, 0x99030130 }, /* bass speaker */
4553 { }
4554 },
4555 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004556 [ALC880_FIXUP_UNIWILL_DIG] = {
4557 .type = ALC_FIXUP_PINS,
4558 .v.pins = (const struct alc_pincfg[]) {
4559 /* disable bogus unused pins */
4560 { 0x17, 0x411111f0 },
4561 { 0x19, 0x411111f0 },
4562 { 0x1b, 0x411111f0 },
4563 { 0x1f, 0x411111f0 },
4564 { }
4565 }
4566 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004567 [ALC880_FIXUP_Z71V] = {
4568 .type = ALC_FIXUP_PINS,
4569 .v.pins = (const struct alc_pincfg[]) {
4570 /* set up the whole pins as BIOS is utterly broken */
4571 { 0x14, 0x99030120 }, /* speaker */
4572 { 0x15, 0x0121411f }, /* HP */
4573 { 0x16, 0x411111f0 }, /* N/A */
4574 { 0x17, 0x411111f0 }, /* N/A */
4575 { 0x18, 0x01a19950 }, /* mic-in */
4576 { 0x19, 0x411111f0 }, /* N/A */
4577 { 0x1a, 0x01813031 }, /* line-in */
4578 { 0x1b, 0x411111f0 }, /* N/A */
4579 { 0x1c, 0x411111f0 }, /* N/A */
4580 { 0x1d, 0x411111f0 }, /* N/A */
4581 { 0x1e, 0x0144111e }, /* SPDIF */
4582 { }
4583 }
4584 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004585 [ALC880_FIXUP_3ST_BASE] = {
4586 .type = ALC_FIXUP_PINS,
4587 .v.pins = (const struct alc_pincfg[]) {
4588 { 0x14, 0x01014010 }, /* line-out */
4589 { 0x15, 0x411111f0 }, /* N/A */
4590 { 0x16, 0x411111f0 }, /* N/A */
4591 { 0x17, 0x411111f0 }, /* N/A */
4592 { 0x18, 0x01a19c30 }, /* mic-in */
4593 { 0x19, 0x0121411f }, /* HP */
4594 { 0x1a, 0x01813031 }, /* line-in */
4595 { 0x1b, 0x02a19c40 }, /* front-mic */
4596 { 0x1c, 0x411111f0 }, /* N/A */
4597 { 0x1d, 0x411111f0 }, /* N/A */
4598 /* 0x1e is filled in below */
4599 { 0x1f, 0x411111f0 }, /* N/A */
4600 { }
4601 }
4602 },
4603 [ALC880_FIXUP_3ST] = {
4604 .type = ALC_FIXUP_PINS,
4605 .v.pins = (const struct alc_pincfg[]) {
4606 { 0x1e, 0x411111f0 }, /* N/A */
4607 { }
4608 },
4609 .chained = true,
4610 .chain_id = ALC880_FIXUP_3ST_BASE,
4611 },
4612 [ALC880_FIXUP_3ST_DIG] = {
4613 .type = ALC_FIXUP_PINS,
4614 .v.pins = (const struct alc_pincfg[]) {
4615 { 0x1e, 0x0144111e }, /* SPDIF */
4616 { }
4617 },
4618 .chained = true,
4619 .chain_id = ALC880_FIXUP_3ST_BASE,
4620 },
4621 [ALC880_FIXUP_5ST_BASE] = {
4622 .type = ALC_FIXUP_PINS,
4623 .v.pins = (const struct alc_pincfg[]) {
4624 { 0x14, 0x01014010 }, /* front */
4625 { 0x15, 0x411111f0 }, /* N/A */
4626 { 0x16, 0x01011411 }, /* CLFE */
4627 { 0x17, 0x01016412 }, /* surr */
4628 { 0x18, 0x01a19c30 }, /* mic-in */
4629 { 0x19, 0x0121411f }, /* HP */
4630 { 0x1a, 0x01813031 }, /* line-in */
4631 { 0x1b, 0x02a19c40 }, /* front-mic */
4632 { 0x1c, 0x411111f0 }, /* N/A */
4633 { 0x1d, 0x411111f0 }, /* N/A */
4634 /* 0x1e is filled in below */
4635 { 0x1f, 0x411111f0 }, /* N/A */
4636 { }
4637 }
4638 },
4639 [ALC880_FIXUP_5ST] = {
4640 .type = ALC_FIXUP_PINS,
4641 .v.pins = (const struct alc_pincfg[]) {
4642 { 0x1e, 0x411111f0 }, /* N/A */
4643 { }
4644 },
4645 .chained = true,
4646 .chain_id = ALC880_FIXUP_5ST_BASE,
4647 },
4648 [ALC880_FIXUP_5ST_DIG] = {
4649 .type = ALC_FIXUP_PINS,
4650 .v.pins = (const struct alc_pincfg[]) {
4651 { 0x1e, 0x0144111e }, /* SPDIF */
4652 { }
4653 },
4654 .chained = true,
4655 .chain_id = ALC880_FIXUP_5ST_BASE,
4656 },
4657 [ALC880_FIXUP_6ST_BASE] = {
4658 .type = ALC_FIXUP_PINS,
4659 .v.pins = (const struct alc_pincfg[]) {
4660 { 0x14, 0x01014010 }, /* front */
4661 { 0x15, 0x01016412 }, /* surr */
4662 { 0x16, 0x01011411 }, /* CLFE */
4663 { 0x17, 0x01012414 }, /* side */
4664 { 0x18, 0x01a19c30 }, /* mic-in */
4665 { 0x19, 0x02a19c40 }, /* front-mic */
4666 { 0x1a, 0x01813031 }, /* line-in */
4667 { 0x1b, 0x0121411f }, /* HP */
4668 { 0x1c, 0x411111f0 }, /* N/A */
4669 { 0x1d, 0x411111f0 }, /* N/A */
4670 /* 0x1e is filled in below */
4671 { 0x1f, 0x411111f0 }, /* N/A */
4672 { }
4673 }
4674 },
4675 [ALC880_FIXUP_6ST] = {
4676 .type = ALC_FIXUP_PINS,
4677 .v.pins = (const struct alc_pincfg[]) {
4678 { 0x1e, 0x411111f0 }, /* N/A */
4679 { }
4680 },
4681 .chained = true,
4682 .chain_id = ALC880_FIXUP_6ST_BASE,
4683 },
4684 [ALC880_FIXUP_6ST_DIG] = {
4685 .type = ALC_FIXUP_PINS,
4686 .v.pins = (const struct alc_pincfg[]) {
4687 { 0x1e, 0x0144111e }, /* SPDIF */
4688 { }
4689 },
4690 .chained = true,
4691 .chain_id = ALC880_FIXUP_6ST_BASE,
4692 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004693};
4694
4695static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004696 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004697 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004698 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4699 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004700 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004701 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004702 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004703 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004704 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004705 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004706 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004707 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004708 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004709 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004710 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004711 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4712 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4713 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004714 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004715
4716 /* Below is the copied entries from alc880_quirks.c.
4717 * It's not quite sure whether BIOS sets the correct pin-config table
4718 * on these machines, thus they are kept to be compatible with
4719 * the old static quirks. Once when it's confirmed to work without
4720 * these overrides, it'd be better to remove.
4721 */
4722 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4723 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4724 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4725 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4726 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4727 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4728 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4729 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4730 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4731 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4732 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4733 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4734 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4735 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4736 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4737 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4738 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4739 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4740 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4741 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4742 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4743 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4744 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4745 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4746 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4747 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4748 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4749 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4750 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4751 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4752 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4753 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4754 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4755 /* default Intel */
4756 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4757 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4758 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4759 {}
4760};
4761
4762static const struct alc_model_fixup alc880_fixup_models[] = {
4763 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4764 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4765 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4766 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4767 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4768 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004769 {}
4770};
4771
4772
4773/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004774 * OK, here we have finally the patch for ALC880
4775 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004776static int patch_alc880(struct hda_codec *codec)
4777{
4778 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004779 int err;
4780
Takashi Iwai3de95172012-05-07 18:03:15 +02004781 err = alc_alloc_spec(codec, 0x0b);
4782 if (err < 0)
4783 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004784
Takashi Iwai3de95172012-05-07 18:03:15 +02004785 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004786 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004787
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004788 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4789 alc880_fixups);
4790 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004791
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004792 /* automatic parse from the BIOS config */
4793 err = alc880_parse_auto_config(codec);
4794 if (err < 0)
4795 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004796
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004797 if (!spec->no_analog) {
4798 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004799 if (err < 0)
4800 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004801 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4802 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004803
Takashi Iwai1d045db2011-07-07 18:23:21 +02004804 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004805 codec->patch_ops.unsol_event = alc880_unsol_event;
4806
Takashi Iwai1d045db2011-07-07 18:23:21 +02004807
Takashi Iwai589876e2012-02-20 15:47:55 +01004808 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4809
Takashi Iwai1d045db2011-07-07 18:23:21 +02004810 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004811
4812 error:
4813 alc_free(codec);
4814 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004815}
4816
4817
4818/*
4819 * ALC260 support
4820 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004821static int alc260_parse_auto_config(struct hda_codec *codec)
4822{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004823 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004824 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4825 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004826}
4827
Takashi Iwai1d045db2011-07-07 18:23:21 +02004828/*
4829 * Pin config fixes
4830 */
4831enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004832 ALC260_FIXUP_HP_DC5750,
4833 ALC260_FIXUP_HP_PIN_0F,
4834 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004835 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004836 ALC260_FIXUP_GPIO1_TOGGLE,
4837 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004838 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004839 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004840};
4841
Takashi Iwai20f7d922012-02-16 12:35:16 +01004842static void alc260_gpio1_automute(struct hda_codec *codec)
4843{
4844 struct alc_spec *spec = codec->spec;
4845 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4846 spec->hp_jack_present);
4847}
4848
4849static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4850 const struct alc_fixup *fix, int action)
4851{
4852 struct alc_spec *spec = codec->spec;
4853 if (action == ALC_FIXUP_ACT_PROBE) {
4854 /* although the machine has only one output pin, we need to
4855 * toggle GPIO1 according to the jack state
4856 */
4857 spec->automute_hook = alc260_gpio1_automute;
4858 spec->detect_hp = 1;
4859 spec->automute_speaker = 1;
4860 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004861 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4862 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004863 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004864 }
4865}
4866
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004867static void alc260_fixup_kn1(struct hda_codec *codec,
4868 const struct alc_fixup *fix, int action)
4869{
4870 struct alc_spec *spec = codec->spec;
4871 static const struct alc_pincfg pincfgs[] = {
4872 { 0x0f, 0x02214000 }, /* HP/speaker */
4873 { 0x12, 0x90a60160 }, /* int mic */
4874 { 0x13, 0x02a19000 }, /* ext mic */
4875 { 0x18, 0x01446000 }, /* SPDIF out */
4876 /* disable bogus I/O pins */
4877 { 0x10, 0x411111f0 },
4878 { 0x11, 0x411111f0 },
4879 { 0x14, 0x411111f0 },
4880 { 0x15, 0x411111f0 },
4881 { 0x16, 0x411111f0 },
4882 { 0x17, 0x411111f0 },
4883 { 0x19, 0x411111f0 },
4884 { }
4885 };
4886
4887 switch (action) {
4888 case ALC_FIXUP_ACT_PRE_PROBE:
4889 alc_apply_pincfgs(codec, pincfgs);
4890 break;
4891 case ALC_FIXUP_ACT_PROBE:
4892 spec->init_amp = ALC_INIT_NONE;
4893 break;
4894 }
4895}
4896
Takashi Iwai1d045db2011-07-07 18:23:21 +02004897static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004898 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004899 .type = ALC_FIXUP_PINS,
4900 .v.pins = (const struct alc_pincfg[]) {
4901 { 0x11, 0x90130110 }, /* speaker */
4902 { }
4903 }
4904 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004905 [ALC260_FIXUP_HP_PIN_0F] = {
4906 .type = ALC_FIXUP_PINS,
4907 .v.pins = (const struct alc_pincfg[]) {
4908 { 0x0f, 0x01214000 }, /* HP */
4909 { }
4910 }
4911 },
4912 [ALC260_FIXUP_COEF] = {
4913 .type = ALC_FIXUP_VERBS,
4914 .v.verbs = (const struct hda_verb[]) {
4915 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4916 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4917 { }
4918 },
4919 .chained = true,
4920 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4921 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004922 [ALC260_FIXUP_GPIO1] = {
4923 .type = ALC_FIXUP_VERBS,
4924 .v.verbs = alc_gpio1_init_verbs,
4925 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004926 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4927 .type = ALC_FIXUP_FUNC,
4928 .v.func = alc260_fixup_gpio1_toggle,
4929 .chained = true,
4930 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4931 },
4932 [ALC260_FIXUP_REPLACER] = {
4933 .type = ALC_FIXUP_VERBS,
4934 .v.verbs = (const struct hda_verb[]) {
4935 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4936 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4937 { }
4938 },
4939 .chained = true,
4940 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4941 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004942 [ALC260_FIXUP_HP_B1900] = {
4943 .type = ALC_FIXUP_FUNC,
4944 .v.func = alc260_fixup_gpio1_toggle,
4945 .chained = true,
4946 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004947 },
4948 [ALC260_FIXUP_KN1] = {
4949 .type = ALC_FIXUP_FUNC,
4950 .v.func = alc260_fixup_kn1,
4951 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004952};
4953
4954static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004955 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004956 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004957 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004958 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004959 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004960 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004961 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004962 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004963 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004964 {}
4965};
4966
4967/*
4968 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004969static int patch_alc260(struct hda_codec *codec)
4970{
4971 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004972 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004973
Takashi Iwai3de95172012-05-07 18:03:15 +02004974 err = alc_alloc_spec(codec, 0x07);
4975 if (err < 0)
4976 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004977
Takashi Iwai3de95172012-05-07 18:03:15 +02004978 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004979
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004980 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4981 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004982
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004983 /* automatic parse from the BIOS config */
4984 err = alc260_parse_auto_config(codec);
4985 if (err < 0)
4986 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004987
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004988 if (!spec->no_analog) {
4989 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004990 if (err < 0)
4991 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004992 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4993 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004994
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004996 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004997
Takashi Iwai589876e2012-02-20 15:47:55 +01004998 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4999
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005001
5002 error:
5003 alc_free(codec);
5004 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005}
5006
5007
5008/*
5009 * ALC882/883/885/888/889 support
5010 *
5011 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5012 * configuration. Each pin widget can choose any input DACs and a mixer.
5013 * Each ADC is connected from a mixer of all inputs. This makes possible
5014 * 6-channel independent captures.
5015 *
5016 * In addition, an independent DAC for the multi-playback (not used in this
5017 * driver yet).
5018 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005019
5020/*
5021 * Pin config fixes
5022 */
5023enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005024 ALC882_FIXUP_ABIT_AW9D_MAX,
5025 ALC882_FIXUP_LENOVO_Y530,
5026 ALC882_FIXUP_PB_M5210,
5027 ALC882_FIXUP_ACER_ASPIRE_7736,
5028 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005029 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005030 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005031 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005032 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005033 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005034 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005035 ALC882_FIXUP_GPIO1,
5036 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005037 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005038 ALC889_FIXUP_COEF,
5039 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005040 ALC882_FIXUP_ACER_ASPIRE_4930G,
5041 ALC882_FIXUP_ACER_ASPIRE_8930G,
5042 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005043 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005044 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005045 ALC889_FIXUP_MBP_VREF,
5046 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005047 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005048 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005049};
5050
Takashi Iwai68ef0562011-11-09 18:24:44 +01005051static void alc889_fixup_coef(struct hda_codec *codec,
5052 const struct alc_fixup *fix, int action)
5053{
5054 if (action != ALC_FIXUP_ACT_INIT)
5055 return;
5056 alc889_coef_init(codec);
5057}
5058
Takashi Iwai56710872011-11-14 17:42:11 +01005059/* toggle speaker-output according to the hp-jack state */
5060static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5061{
5062 unsigned int gpiostate, gpiomask, gpiodir;
5063
5064 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5065 AC_VERB_GET_GPIO_DATA, 0);
5066
5067 if (!muted)
5068 gpiostate |= (1 << pin);
5069 else
5070 gpiostate &= ~(1 << pin);
5071
5072 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5073 AC_VERB_GET_GPIO_MASK, 0);
5074 gpiomask |= (1 << pin);
5075
5076 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5077 AC_VERB_GET_GPIO_DIRECTION, 0);
5078 gpiodir |= (1 << pin);
5079
5080
5081 snd_hda_codec_write(codec, codec->afg, 0,
5082 AC_VERB_SET_GPIO_MASK, gpiomask);
5083 snd_hda_codec_write(codec, codec->afg, 0,
5084 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5085
5086 msleep(1);
5087
5088 snd_hda_codec_write(codec, codec->afg, 0,
5089 AC_VERB_SET_GPIO_DATA, gpiostate);
5090}
5091
5092/* set up GPIO at initialization */
5093static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5094 const struct alc_fixup *fix, int action)
5095{
5096 if (action != ALC_FIXUP_ACT_INIT)
5097 return;
5098 alc882_gpio_mute(codec, 0, 0);
5099 alc882_gpio_mute(codec, 1, 0);
5100}
5101
Takashi Iwai02a237b2012-02-13 15:25:07 +01005102/* Fix the connection of some pins for ALC889:
5103 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5104 * work correctly (bko#42740)
5105 */
5106static void alc889_fixup_dac_route(struct hda_codec *codec,
5107 const struct alc_fixup *fix, int action)
5108{
5109 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005110 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005111 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5112 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5113 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5114 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5115 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5116 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005117 } else if (action == ALC_FIXUP_ACT_PROBE) {
5118 /* restore the connections */
5119 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5120 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5121 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5122 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5123 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005124 }
5125}
5126
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005127/* Set VREF on HP pin */
5128static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5129 const struct alc_fixup *fix, int action)
5130{
5131 struct alc_spec *spec = codec->spec;
5132 static hda_nid_t nids[2] = { 0x14, 0x15 };
5133 int i;
5134
5135 if (action != ALC_FIXUP_ACT_INIT)
5136 return;
5137 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5138 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5139 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5140 continue;
5141 val = snd_hda_codec_read(codec, nids[i], 0,
5142 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5143 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005144 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005145 spec->keep_vref_in_automute = 1;
5146 break;
5147 }
5148}
5149
5150/* Set VREF on speaker pins on imac91 */
5151static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5152 const struct alc_fixup *fix, int action)
5153{
5154 struct alc_spec *spec = codec->spec;
5155 static hda_nid_t nids[2] = { 0x18, 0x1a };
5156 int i;
5157
5158 if (action != ALC_FIXUP_ACT_INIT)
5159 return;
5160 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5161 unsigned int val;
5162 val = snd_hda_codec_read(codec, nids[i], 0,
5163 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5164 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005165 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005166 }
5167 spec->keep_vref_in_automute = 1;
5168}
5169
Takashi Iwaie427c232012-07-29 10:04:08 +02005170/* Don't take HP output as primary
5171 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5172 */
5173static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5174 const struct alc_fixup *fix, int action)
5175{
5176 struct alc_spec *spec = codec->spec;
5177 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5178 spec->no_primary_hp = 1;
5179}
5180
Takashi Iwai1d045db2011-07-07 18:23:21 +02005181static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005182 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005183 .type = ALC_FIXUP_PINS,
5184 .v.pins = (const struct alc_pincfg[]) {
5185 { 0x15, 0x01080104 }, /* side */
5186 { 0x16, 0x01011012 }, /* rear */
5187 { 0x17, 0x01016011 }, /* clfe */
5188 { }
5189 }
5190 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005191 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005192 .type = ALC_FIXUP_PINS,
5193 .v.pins = (const struct alc_pincfg[]) {
5194 { 0x15, 0x99130112 }, /* rear int speakers */
5195 { 0x16, 0x99130111 }, /* subwoofer */
5196 { }
5197 }
5198 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005199 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005200 .type = ALC_FIXUP_VERBS,
5201 .v.verbs = (const struct hda_verb[]) {
5202 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5203 {}
5204 }
5205 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005206 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005207 .type = ALC_FIXUP_FUNC,
5208 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005209 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005210 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005211 .type = ALC_FIXUP_PINS,
5212 .v.pins = (const struct alc_pincfg[]) {
5213 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5214 { }
5215 }
5216 },
Marton Balint8f239212012-03-05 21:33:23 +01005217 [ALC889_FIXUP_CD] = {
5218 .type = ALC_FIXUP_PINS,
5219 .v.pins = (const struct alc_pincfg[]) {
5220 { 0x1c, 0x993301f0 }, /* CD */
5221 { }
5222 }
5223 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005224 [ALC889_FIXUP_VAIO_TT] = {
5225 .type = ALC_FIXUP_PINS,
5226 .v.pins = (const struct alc_pincfg[]) {
5227 { 0x17, 0x90170111 }, /* hidden surround speaker */
5228 { }
5229 }
5230 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005231 [ALC888_FIXUP_EEE1601] = {
5232 .type = ALC_FIXUP_VERBS,
5233 .v.verbs = (const struct hda_verb[]) {
5234 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5235 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5236 { }
5237 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005238 },
5239 [ALC882_FIXUP_EAPD] = {
5240 .type = ALC_FIXUP_VERBS,
5241 .v.verbs = (const struct hda_verb[]) {
5242 /* change to EAPD mode */
5243 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5244 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5245 { }
5246 }
5247 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005248 [ALC883_FIXUP_EAPD] = {
5249 .type = ALC_FIXUP_VERBS,
5250 .v.verbs = (const struct hda_verb[]) {
5251 /* change to EAPD mode */
5252 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5253 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5254 { }
5255 }
5256 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005257 [ALC883_FIXUP_ACER_EAPD] = {
5258 .type = ALC_FIXUP_VERBS,
5259 .v.verbs = (const struct hda_verb[]) {
5260 /* eanable EAPD on Acer laptops */
5261 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5262 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5263 { }
5264 }
5265 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005266 [ALC882_FIXUP_GPIO1] = {
5267 .type = ALC_FIXUP_VERBS,
5268 .v.verbs = alc_gpio1_init_verbs,
5269 },
5270 [ALC882_FIXUP_GPIO2] = {
5271 .type = ALC_FIXUP_VERBS,
5272 .v.verbs = alc_gpio2_init_verbs,
5273 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005274 [ALC882_FIXUP_GPIO3] = {
5275 .type = ALC_FIXUP_VERBS,
5276 .v.verbs = alc_gpio3_init_verbs,
5277 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005278 [ALC882_FIXUP_ASUS_W2JC] = {
5279 .type = ALC_FIXUP_VERBS,
5280 .v.verbs = alc_gpio1_init_verbs,
5281 .chained = true,
5282 .chain_id = ALC882_FIXUP_EAPD,
5283 },
5284 [ALC889_FIXUP_COEF] = {
5285 .type = ALC_FIXUP_FUNC,
5286 .v.func = alc889_fixup_coef,
5287 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005288 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5289 .type = ALC_FIXUP_PINS,
5290 .v.pins = (const struct alc_pincfg[]) {
5291 { 0x16, 0x99130111 }, /* CLFE speaker */
5292 { 0x17, 0x99130112 }, /* surround speaker */
5293 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005294 },
5295 .chained = true,
5296 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005297 },
5298 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5299 .type = ALC_FIXUP_PINS,
5300 .v.pins = (const struct alc_pincfg[]) {
5301 { 0x16, 0x99130111 }, /* CLFE speaker */
5302 { 0x1b, 0x99130112 }, /* surround speaker */
5303 { }
5304 },
5305 .chained = true,
5306 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5307 },
5308 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5309 /* additional init verbs for Acer Aspire 8930G */
5310 .type = ALC_FIXUP_VERBS,
5311 .v.verbs = (const struct hda_verb[]) {
5312 /* Enable all DACs */
5313 /* DAC DISABLE/MUTE 1? */
5314 /* setting bits 1-5 disables DAC nids 0x02-0x06
5315 * apparently. Init=0x38 */
5316 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5317 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5318 /* DAC DISABLE/MUTE 2? */
5319 /* some bit here disables the other DACs.
5320 * Init=0x4900 */
5321 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5322 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5323 /* DMIC fix
5324 * This laptop has a stereo digital microphone.
5325 * The mics are only 1cm apart which makes the stereo
5326 * useless. However, either the mic or the ALC889
5327 * makes the signal become a difference/sum signal
5328 * instead of standard stereo, which is annoying.
5329 * So instead we flip this bit which makes the
5330 * codec replicate the sum signal to both channels,
5331 * turning it into a normal mono mic.
5332 */
5333 /* DMIC_CONTROL? Init value = 0x0001 */
5334 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5335 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5336 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5337 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5338 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005339 },
5340 .chained = true,
5341 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005342 },
Takashi Iwai56710872011-11-14 17:42:11 +01005343 [ALC885_FIXUP_MACPRO_GPIO] = {
5344 .type = ALC_FIXUP_FUNC,
5345 .v.func = alc885_fixup_macpro_gpio,
5346 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005347 [ALC889_FIXUP_DAC_ROUTE] = {
5348 .type = ALC_FIXUP_FUNC,
5349 .v.func = alc889_fixup_dac_route,
5350 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005351 [ALC889_FIXUP_MBP_VREF] = {
5352 .type = ALC_FIXUP_FUNC,
5353 .v.func = alc889_fixup_mbp_vref,
5354 .chained = true,
5355 .chain_id = ALC882_FIXUP_GPIO1,
5356 },
5357 [ALC889_FIXUP_IMAC91_VREF] = {
5358 .type = ALC_FIXUP_FUNC,
5359 .v.func = alc889_fixup_imac91_vref,
5360 .chained = true,
5361 .chain_id = ALC882_FIXUP_GPIO1,
5362 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005363 [ALC882_FIXUP_INV_DMIC] = {
5364 .type = ALC_FIXUP_FUNC,
5365 .v.func = alc_fixup_inv_dmic_0x12,
5366 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005367 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5368 .type = ALC_FIXUP_FUNC,
5369 .v.func = alc882_fixup_no_primary_hp,
5370 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005371};
5372
5373static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005374 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5375 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5376 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5377 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5378 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5379 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005380 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5381 ALC882_FIXUP_ACER_ASPIRE_4930G),
5382 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5383 ALC882_FIXUP_ACER_ASPIRE_4930G),
5384 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5385 ALC882_FIXUP_ACER_ASPIRE_8930G),
5386 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5387 ALC882_FIXUP_ACER_ASPIRE_8930G),
5388 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5389 ALC882_FIXUP_ACER_ASPIRE_4930G),
5390 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5391 ALC882_FIXUP_ACER_ASPIRE_4930G),
5392 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5393 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005394 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005395 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5396 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005397 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005398 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005399 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005400 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005401 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005402 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005403 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005404 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005405 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005406
5407 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005408 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5409 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5410 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005411 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5412 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5413 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005414 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5415 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005416 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005417 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5418 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5419 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5420 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005421 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005422 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5423 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5424 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005425 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005426 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005427 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5428 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5429 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005430
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005431 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005432 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005433 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005434 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005435 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005436 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5437 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005438 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005439 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005440 {}
5441};
5442
Takashi Iwai912093b2012-04-11 14:03:41 +02005443static const struct alc_model_fixup alc882_fixup_models[] = {
5444 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5445 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5446 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005447 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005448 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005449 {}
5450};
5451
Takashi Iwai1d045db2011-07-07 18:23:21 +02005452/*
5453 * BIOS auto configuration
5454 */
5455/* almost identical with ALC880 parser... */
5456static int alc882_parse_auto_config(struct hda_codec *codec)
5457{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005458 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005459 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5460 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005461}
5462
Takashi Iwai1d045db2011-07-07 18:23:21 +02005463/*
5464 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005465static int patch_alc882(struct hda_codec *codec)
5466{
5467 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005468 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005469
Takashi Iwai3de95172012-05-07 18:03:15 +02005470 err = alc_alloc_spec(codec, 0x0b);
5471 if (err < 0)
5472 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005473
Takashi Iwai3de95172012-05-07 18:03:15 +02005474 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005475
5476 switch (codec->vendor_id) {
5477 case 0x10ec0882:
5478 case 0x10ec0885:
5479 break;
5480 default:
5481 /* ALC883 and variants */
5482 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5483 break;
5484 }
5485
Takashi Iwai912093b2012-04-11 14:03:41 +02005486 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5487 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005488 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489
5490 alc_auto_parse_customize_define(codec);
5491
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005492 /* automatic parse from the BIOS config */
5493 err = alc882_parse_auto_config(codec);
5494 if (err < 0)
5495 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005496
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005497 if (!spec->no_analog && has_cdefine_beep(codec)) {
5498 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005499 if (err < 0)
5500 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005501 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005502 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005503
Takashi Iwai1d045db2011-07-07 18:23:21 +02005504 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505
Takashi Iwai589876e2012-02-20 15:47:55 +01005506 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5507
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005509
5510 error:
5511 alc_free(codec);
5512 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005513}
5514
5515
5516/*
5517 * ALC262 support
5518 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005519static int alc262_parse_auto_config(struct hda_codec *codec)
5520{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005521 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005522 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5523 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005524}
5525
5526/*
5527 * Pin config fixes
5528 */
5529enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005530 ALC262_FIXUP_FSC_H270,
5531 ALC262_FIXUP_HP_Z200,
5532 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005533 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005534 ALC262_FIXUP_BENQ,
5535 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005536 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005537};
5538
5539static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005540 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005541 .type = ALC_FIXUP_PINS,
5542 .v.pins = (const struct alc_pincfg[]) {
5543 { 0x14, 0x99130110 }, /* speaker */
5544 { 0x15, 0x0221142f }, /* front HP */
5545 { 0x1b, 0x0121141f }, /* rear HP */
5546 { }
5547 }
5548 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005549 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005550 .type = ALC_FIXUP_PINS,
5551 .v.pins = (const struct alc_pincfg[]) {
5552 { 0x16, 0x99130120 }, /* internal speaker */
5553 { }
5554 }
5555 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005556 [ALC262_FIXUP_TYAN] = {
5557 .type = ALC_FIXUP_PINS,
5558 .v.pins = (const struct alc_pincfg[]) {
5559 { 0x14, 0x1993e1f0 }, /* int AUX */
5560 { }
5561 }
5562 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005563 [ALC262_FIXUP_LENOVO_3000] = {
5564 .type = ALC_FIXUP_VERBS,
5565 .v.verbs = (const struct hda_verb[]) {
5566 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005567 {}
5568 },
5569 .chained = true,
5570 .chain_id = ALC262_FIXUP_BENQ,
5571 },
5572 [ALC262_FIXUP_BENQ] = {
5573 .type = ALC_FIXUP_VERBS,
5574 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005575 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5576 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5577 {}
5578 }
5579 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005580 [ALC262_FIXUP_BENQ_T31] = {
5581 .type = ALC_FIXUP_VERBS,
5582 .v.verbs = (const struct hda_verb[]) {
5583 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5584 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5585 {}
5586 }
5587 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005588 [ALC262_FIXUP_INV_DMIC] = {
5589 .type = ALC_FIXUP_FUNC,
5590 .v.func = alc_fixup_inv_dmic_0x12,
5591 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005592};
5593
5594static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005595 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005596 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5597 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005598 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5599 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005600 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005601 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5602 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005603 {}
5604};
5605
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005606static const struct alc_model_fixup alc262_fixup_models[] = {
5607 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5608 {}
5609};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005610
Takashi Iwai1d045db2011-07-07 18:23:21 +02005611/*
5612 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005613static int patch_alc262(struct hda_codec *codec)
5614{
5615 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005616 int err;
5617
Takashi Iwai3de95172012-05-07 18:03:15 +02005618 err = alc_alloc_spec(codec, 0x0b);
5619 if (err < 0)
5620 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005621
Takashi Iwai3de95172012-05-07 18:03:15 +02005622 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005623
5624#if 0
5625 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5626 * under-run
5627 */
5628 {
5629 int tmp;
5630 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5631 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5632 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5633 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5634 }
5635#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005636 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5637
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005638 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5639 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005640 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005641
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005642 alc_auto_parse_customize_define(codec);
5643
Takashi Iwai42399f72011-11-07 17:18:44 +01005644 /* automatic parse from the BIOS config */
5645 err = alc262_parse_auto_config(codec);
5646 if (err < 0)
5647 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005648
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649 if (!spec->no_analog && has_cdefine_beep(codec)) {
5650 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005651 if (err < 0)
5652 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005653 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005654 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005655
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657 spec->shutup = alc_eapd_shutup;
5658
Takashi Iwai589876e2012-02-20 15:47:55 +01005659 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5660
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005662
5663 error:
5664 alc_free(codec);
5665 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005666}
5667
5668/*
5669 * ALC268
5670 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005671/* bind Beep switches of both NID 0x0f and 0x10 */
5672static const struct hda_bind_ctls alc268_bind_beep_sw = {
5673 .ops = &snd_hda_bind_sw,
5674 .values = {
5675 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5676 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5677 0
5678 },
5679};
5680
5681static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5682 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5683 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5684 { }
5685};
5686
5687/* set PCBEEP vol = 0, mute connections */
5688static const struct hda_verb alc268_beep_init_verbs[] = {
5689 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5690 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5691 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5692 { }
5693};
5694
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005695enum {
5696 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005697 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005698};
5699
5700static const struct alc_fixup alc268_fixups[] = {
5701 [ALC268_FIXUP_INV_DMIC] = {
5702 .type = ALC_FIXUP_FUNC,
5703 .v.func = alc_fixup_inv_dmic_0x12,
5704 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005705 [ALC268_FIXUP_HP_EAPD] = {
5706 .type = ALC_FIXUP_VERBS,
5707 .v.verbs = (const struct hda_verb[]) {
5708 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5709 {}
5710 }
5711 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005712};
5713
5714static const struct alc_model_fixup alc268_fixup_models[] = {
5715 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005716 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5717 {}
5718};
5719
5720static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5721 /* below is codec SSID since multiple Toshiba laptops have the
5722 * same PCI SSID 1179:ff00
5723 */
5724 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005725 {}
5726};
5727
Takashi Iwai1d045db2011-07-07 18:23:21 +02005728/*
5729 * BIOS auto configuration
5730 */
5731static int alc268_parse_auto_config(struct hda_codec *codec)
5732{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005733 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005734 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005735 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5736 if (err > 0) {
5737 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5738 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005739 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005740 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005741 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005742 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743}
5744
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745/*
5746 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005747static int patch_alc268(struct hda_codec *codec)
5748{
5749 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750 int i, has_beep, err;
5751
Takashi Iwai1d045db2011-07-07 18:23:21 +02005752 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005753 err = alc_alloc_spec(codec, 0);
5754 if (err < 0)
5755 return err;
5756
5757 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005758
Takashi Iwaicb766402012-10-20 10:55:21 +02005759 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005760 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5761
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005762 /* automatic parse from the BIOS config */
5763 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005764 if (err < 0)
5765 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005766
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767 has_beep = 0;
5768 for (i = 0; i < spec->num_mixers; i++) {
5769 if (spec->mixers[i] == alc268_beep_mixer) {
5770 has_beep = 1;
5771 break;
5772 }
5773 }
5774
5775 if (has_beep) {
5776 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005777 if (err < 0)
5778 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005779 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5780 /* override the amp caps for beep generator */
5781 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5782 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5783 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5784 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5785 (0 << AC_AMPCAP_MUTE_SHIFT));
5786 }
5787
Takashi Iwai1d045db2011-07-07 18:23:21 +02005788 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005789 spec->shutup = alc_eapd_shutup;
5790
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005791 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5792
Takashi Iwai1d045db2011-07-07 18:23:21 +02005793 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005794
5795 error:
5796 alc_free(codec);
5797 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005798}
5799
5800/*
5801 * ALC269
5802 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005803static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5804 .substreams = 1,
5805 .channels_min = 2,
5806 .channels_max = 8,
5807 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5808 /* NID is set in alc_build_pcms */
5809 .ops = {
5810 .open = alc_playback_pcm_open,
5811 .prepare = alc_playback_pcm_prepare,
5812 .cleanup = alc_playback_pcm_cleanup
5813 },
5814};
5815
5816static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5817 .substreams = 1,
5818 .channels_min = 2,
5819 .channels_max = 2,
5820 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5821 /* NID is set in alc_build_pcms */
5822};
5823
Takashi Iwai1d045db2011-07-07 18:23:21 +02005824/* different alc269-variants */
5825enum {
5826 ALC269_TYPE_ALC269VA,
5827 ALC269_TYPE_ALC269VB,
5828 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005829 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005830 ALC269_TYPE_ALC280,
5831 ALC269_TYPE_ALC282,
5832 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005833};
5834
5835/*
5836 * BIOS auto configuration
5837 */
5838static int alc269_parse_auto_config(struct hda_codec *codec)
5839{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005840 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005841 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5842 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5843 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005844 const hda_nid_t *ssids;
5845
5846 switch (spec->codec_variant) {
5847 case ALC269_TYPE_ALC269VA:
5848 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005849 case ALC269_TYPE_ALC280:
5850 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005851 ssids = alc269va_ssids;
5852 break;
5853 case ALC269_TYPE_ALC269VB:
5854 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005855 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005856 ssids = alc269_ssids;
5857 break;
5858 default:
5859 ssids = alc269_ssids;
5860 break;
5861 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005862
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005863 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005864}
5865
Kailang Yang1387e2d2012-11-08 10:23:18 +01005866static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005867{
5868 int val = alc_read_coef_idx(codec, 0x04);
5869 if (power_up)
5870 val |= 1 << 11;
5871 else
5872 val &= ~(1 << 11);
5873 alc_write_coef_idx(codec, 0x04, val);
5874}
5875
5876static void alc269_shutup(struct hda_codec *codec)
5877{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005878 struct alc_spec *spec = codec->spec;
5879
5880 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5881 return;
5882
Kailang Yang1387e2d2012-11-08 10:23:18 +01005883 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5884 alc269vb_toggle_power_output(codec, 0);
5885 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5886 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887 msleep(150);
5888 }
5889}
5890
Takashi Iwai2a439522011-07-26 09:52:50 +02005891#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005892static int alc269_resume(struct hda_codec *codec)
5893{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005894 struct alc_spec *spec = codec->spec;
5895
Kailang Yang1387e2d2012-11-08 10:23:18 +01005896 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5897 alc269vb_toggle_power_output(codec, 0);
5898 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005899 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005900 msleep(150);
5901 }
5902
5903 codec->patch_ops.init(codec);
5904
Kailang Yang1387e2d2012-11-08 10:23:18 +01005905 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5906 alc269vb_toggle_power_output(codec, 1);
5907 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005908 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005909 msleep(200);
5910 }
5911
Takashi Iwai1d045db2011-07-07 18:23:21 +02005912 snd_hda_codec_resume_amp(codec);
5913 snd_hda_codec_resume_cache(codec);
5914 hda_call_check_power_status(codec, 0x01);
5915 return 0;
5916}
Takashi Iwai2a439522011-07-26 09:52:50 +02005917#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005918
David Henningsson108cc102012-07-20 10:37:25 +02005919static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5920 const struct alc_fixup *fix, int action)
5921{
5922 struct alc_spec *spec = codec->spec;
5923
5924 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5925 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5926}
5927
Takashi Iwai1d045db2011-07-07 18:23:21 +02005928static void alc269_fixup_hweq(struct hda_codec *codec,
5929 const struct alc_fixup *fix, int action)
5930{
5931 int coef;
5932
5933 if (action != ALC_FIXUP_ACT_INIT)
5934 return;
5935 coef = alc_read_coef_idx(codec, 0x1e);
5936 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5937}
5938
5939static void alc271_fixup_dmic(struct hda_codec *codec,
5940 const struct alc_fixup *fix, int action)
5941{
5942 static const struct hda_verb verbs[] = {
5943 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5944 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5945 {}
5946 };
5947 unsigned int cfg;
5948
5949 if (strcmp(codec->chip_name, "ALC271X"))
5950 return;
5951 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5952 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5953 snd_hda_sequence_write(codec, verbs);
5954}
5955
Takashi Iwai017f2a12011-07-09 14:42:25 +02005956static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5957 const struct alc_fixup *fix, int action)
5958{
5959 struct alc_spec *spec = codec->spec;
5960
5961 if (action != ALC_FIXUP_ACT_PROBE)
5962 return;
5963
5964 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5965 * fix the sample rate of analog I/O to 44.1kHz
5966 */
5967 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5968 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5969}
5970
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005971static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5972 const struct alc_fixup *fix, int action)
5973{
5974 int coef;
5975
5976 if (action != ALC_FIXUP_ACT_INIT)
5977 return;
5978 /* The digital-mic unit sends PDM (differential signal) instead of
5979 * the standard PCM, thus you can't record a valid mono stream as is.
5980 * Below is a workaround specific to ALC269 to control the dmic
5981 * signal source as mono.
5982 */
5983 coef = alc_read_coef_idx(codec, 0x07);
5984 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5985}
5986
Takashi Iwai24519912011-08-16 15:08:49 +02005987static void alc269_quanta_automute(struct hda_codec *codec)
5988{
David Henningsson42cf0d02011-09-20 12:04:56 +02005989 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005990
5991 snd_hda_codec_write(codec, 0x20, 0,
5992 AC_VERB_SET_COEF_INDEX, 0x0c);
5993 snd_hda_codec_write(codec, 0x20, 0,
5994 AC_VERB_SET_PROC_COEF, 0x680);
5995
5996 snd_hda_codec_write(codec, 0x20, 0,
5997 AC_VERB_SET_COEF_INDEX, 0x0c);
5998 snd_hda_codec_write(codec, 0x20, 0,
5999 AC_VERB_SET_PROC_COEF, 0x480);
6000}
6001
6002static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6003 const struct alc_fixup *fix, int action)
6004{
6005 struct alc_spec *spec = codec->spec;
6006 if (action != ALC_FIXUP_ACT_PROBE)
6007 return;
6008 spec->automute_hook = alc269_quanta_automute;
6009}
6010
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006011/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6012static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6013{
6014 struct hda_codec *codec = private_data;
6015 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6016 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6017 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6018}
6019
6020static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6021 const struct alc_fixup *fix, int action)
6022{
6023 struct alc_spec *spec = codec->spec;
6024 switch (action) {
6025 case ALC_FIXUP_ACT_BUILD:
6026 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6027 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6028 /* fallthru */
6029 case ALC_FIXUP_ACT_INIT:
6030 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6031 break;
6032 }
6033}
6034
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006035/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6036static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6037{
6038 struct hda_codec *codec = private_data;
6039 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006040 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006041}
6042
6043static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6044 const struct alc_fixup *fix, int action)
6045{
6046 struct alc_spec *spec = codec->spec;
6047 switch (action) {
6048 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006049 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006050 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006051 /* fallthru */
6052 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006053 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006054 break;
6055 }
6056}
6057
Dylan Reid08a978d2012-11-18 22:56:40 -08006058static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6059 const struct alc_fixup *fix,
6060 int action)
6061{
6062 struct alc_spec *spec = codec->spec;
6063
6064 if (action == ALC_FIXUP_ACT_PROBE)
6065 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6066 spec->autocfg.hp_pins[0]);
6067}
David Henningsson693b6132012-06-22 19:12:10 +02006068
Takashi Iwai1d045db2011-07-07 18:23:21 +02006069enum {
6070 ALC269_FIXUP_SONY_VAIO,
6071 ALC275_FIXUP_SONY_VAIO_GPIO2,
6072 ALC269_FIXUP_DELL_M101Z,
6073 ALC269_FIXUP_SKU_IGNORE,
6074 ALC269_FIXUP_ASUS_G73JW,
6075 ALC269_FIXUP_LENOVO_EAPD,
6076 ALC275_FIXUP_SONY_HWEQ,
6077 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006078 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006079 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006080 ALC269_FIXUP_QUANTA_MUTE,
6081 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006082 ALC269_FIXUP_AMIC,
6083 ALC269_FIXUP_DMIC,
6084 ALC269VB_FIXUP_AMIC,
6085 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006086 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006087 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006088 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006089 ALC269_FIXUP_LENOVO_DOCK,
6090 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006091 ALC271_FIXUP_AMIC_MIC2,
6092 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006093};
6094
6095static const struct alc_fixup alc269_fixups[] = {
6096 [ALC269_FIXUP_SONY_VAIO] = {
6097 .type = ALC_FIXUP_VERBS,
6098 .v.verbs = (const struct hda_verb[]) {
6099 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6100 {}
6101 }
6102 },
6103 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6104 .type = ALC_FIXUP_VERBS,
6105 .v.verbs = (const struct hda_verb[]) {
6106 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6107 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6108 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6109 { }
6110 },
6111 .chained = true,
6112 .chain_id = ALC269_FIXUP_SONY_VAIO
6113 },
6114 [ALC269_FIXUP_DELL_M101Z] = {
6115 .type = ALC_FIXUP_VERBS,
6116 .v.verbs = (const struct hda_verb[]) {
6117 /* Enables internal speaker */
6118 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6119 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6120 {}
6121 }
6122 },
6123 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006124 .type = ALC_FIXUP_FUNC,
6125 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006126 },
6127 [ALC269_FIXUP_ASUS_G73JW] = {
6128 .type = ALC_FIXUP_PINS,
6129 .v.pins = (const struct alc_pincfg[]) {
6130 { 0x17, 0x99130111 }, /* subwoofer */
6131 { }
6132 }
6133 },
6134 [ALC269_FIXUP_LENOVO_EAPD] = {
6135 .type = ALC_FIXUP_VERBS,
6136 .v.verbs = (const struct hda_verb[]) {
6137 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6138 {}
6139 }
6140 },
6141 [ALC275_FIXUP_SONY_HWEQ] = {
6142 .type = ALC_FIXUP_FUNC,
6143 .v.func = alc269_fixup_hweq,
6144 .chained = true,
6145 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6146 },
6147 [ALC271_FIXUP_DMIC] = {
6148 .type = ALC_FIXUP_FUNC,
6149 .v.func = alc271_fixup_dmic,
6150 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006151 [ALC269_FIXUP_PCM_44K] = {
6152 .type = ALC_FIXUP_FUNC,
6153 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006154 .chained = true,
6155 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006156 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006157 [ALC269_FIXUP_STEREO_DMIC] = {
6158 .type = ALC_FIXUP_FUNC,
6159 .v.func = alc269_fixup_stereo_dmic,
6160 },
Takashi Iwai24519912011-08-16 15:08:49 +02006161 [ALC269_FIXUP_QUANTA_MUTE] = {
6162 .type = ALC_FIXUP_FUNC,
6163 .v.func = alc269_fixup_quanta_mute,
6164 },
6165 [ALC269_FIXUP_LIFEBOOK] = {
6166 .type = ALC_FIXUP_PINS,
6167 .v.pins = (const struct alc_pincfg[]) {
6168 { 0x1a, 0x2101103f }, /* dock line-out */
6169 { 0x1b, 0x23a11040 }, /* dock mic-in */
6170 { }
6171 },
6172 .chained = true,
6173 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6174 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006175 [ALC269_FIXUP_AMIC] = {
6176 .type = ALC_FIXUP_PINS,
6177 .v.pins = (const struct alc_pincfg[]) {
6178 { 0x14, 0x99130110 }, /* speaker */
6179 { 0x15, 0x0121401f }, /* HP out */
6180 { 0x18, 0x01a19c20 }, /* mic */
6181 { 0x19, 0x99a3092f }, /* int-mic */
6182 { }
6183 },
6184 },
6185 [ALC269_FIXUP_DMIC] = {
6186 .type = ALC_FIXUP_PINS,
6187 .v.pins = (const struct alc_pincfg[]) {
6188 { 0x12, 0x99a3092f }, /* int-mic */
6189 { 0x14, 0x99130110 }, /* speaker */
6190 { 0x15, 0x0121401f }, /* HP out */
6191 { 0x18, 0x01a19c20 }, /* mic */
6192 { }
6193 },
6194 },
6195 [ALC269VB_FIXUP_AMIC] = {
6196 .type = ALC_FIXUP_PINS,
6197 .v.pins = (const struct alc_pincfg[]) {
6198 { 0x14, 0x99130110 }, /* speaker */
6199 { 0x18, 0x01a19c20 }, /* mic */
6200 { 0x19, 0x99a3092f }, /* int-mic */
6201 { 0x21, 0x0121401f }, /* HP out */
6202 { }
6203 },
6204 },
David Henningsson2267ea92012-01-03 08:45:56 +01006205 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006206 .type = ALC_FIXUP_PINS,
6207 .v.pins = (const struct alc_pincfg[]) {
6208 { 0x12, 0x99a3092f }, /* int-mic */
6209 { 0x14, 0x99130110 }, /* speaker */
6210 { 0x18, 0x01a19c20 }, /* mic */
6211 { 0x21, 0x0121401f }, /* HP out */
6212 { }
6213 },
6214 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006215 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6216 .type = ALC_FIXUP_FUNC,
6217 .v.func = alc269_fixup_mic1_mute,
6218 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006219 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6220 .type = ALC_FIXUP_FUNC,
6221 .v.func = alc269_fixup_mic2_mute,
6222 },
David Henningsson693b6132012-06-22 19:12:10 +02006223 [ALC269_FIXUP_INV_DMIC] = {
6224 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006225 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006226 },
David Henningsson108cc102012-07-20 10:37:25 +02006227 [ALC269_FIXUP_LENOVO_DOCK] = {
6228 .type = ALC_FIXUP_PINS,
6229 .v.pins = (const struct alc_pincfg[]) {
6230 { 0x19, 0x23a11040 }, /* dock mic */
6231 { 0x1b, 0x2121103f }, /* dock headphone */
6232 { }
6233 },
6234 .chained = true,
6235 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6236 },
6237 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6238 .type = ALC_FIXUP_FUNC,
6239 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6240 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006241 [ALC271_FIXUP_AMIC_MIC2] = {
6242 .type = ALC_FIXUP_PINS,
6243 .v.pins = (const struct alc_pincfg[]) {
6244 { 0x14, 0x99130110 }, /* speaker */
6245 { 0x19, 0x01a19c20 }, /* mic */
6246 { 0x1b, 0x99a7012f }, /* int-mic */
6247 { 0x21, 0x0121401f }, /* HP out */
6248 { }
6249 },
6250 },
6251 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6252 .type = ALC_FIXUP_FUNC,
6253 .v.func = alc271_hp_gate_mic_jack,
6254 .chained = true,
6255 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6256 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006257};
6258
6259static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006260 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6261 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006262 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006263 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006264 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006265 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006266 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006267 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006268 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6269 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6270 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6271 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6272 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006273 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6274 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6275 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6276 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6277 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006278 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006279 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006280 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006281 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6282 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6283 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6284 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6285 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006286 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006287 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006288 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006289 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006290 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006291 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006292 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006293
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006294#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006295 /* Below is a quirk table taken from the old code.
6296 * Basically the device should work as is without the fixup table.
6297 * If BIOS doesn't give a proper info, enable the corresponding
6298 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006299 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006300 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6301 ALC269_FIXUP_AMIC),
6302 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006303 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6304 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6305 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6306 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6307 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6308 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6309 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6310 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6311 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6312 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6313 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6314 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6315 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6316 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6317 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6318 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6319 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6320 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6321 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6322 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6323 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6324 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6325 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6326 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6327 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6328 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6329 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6330 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6331 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6332 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6333 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6334 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6335 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6336 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6337 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6338 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6339 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6340 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6341#endif
6342 {}
6343};
6344
6345static const struct alc_model_fixup alc269_fixup_models[] = {
6346 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6347 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006348 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6349 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6350 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006351 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006352 {}
6353};
6354
6355
Takashi Iwai546bb672012-03-07 08:37:19 +01006356static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006357{
Kailang Yang526af6e2012-03-07 08:25:20 +01006358 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006359 int val;
6360
Kailang Yang526af6e2012-03-07 08:25:20 +01006361 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006362 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006363
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006364 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006365 alc_write_coef_idx(codec, 0xf, 0x960b);
6366 alc_write_coef_idx(codec, 0xe, 0x8817);
6367 }
6368
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006369 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006370 alc_write_coef_idx(codec, 0xf, 0x960b);
6371 alc_write_coef_idx(codec, 0xe, 0x8814);
6372 }
6373
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006374 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006375 val = alc_read_coef_idx(codec, 0x04);
6376 /* Power up output pin */
6377 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6378 }
6379
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006380 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006381 val = alc_read_coef_idx(codec, 0xd);
6382 if ((val & 0x0c00) >> 10 != 0x1) {
6383 /* Capless ramp up clock control */
6384 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6385 }
6386 val = alc_read_coef_idx(codec, 0x17);
6387 if ((val & 0x01c0) >> 6 != 0x4) {
6388 /* Class D power on reset */
6389 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6390 }
6391 }
6392
6393 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6394 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6395
6396 val = alc_read_coef_idx(codec, 0x4); /* HP */
6397 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006398}
6399
6400/*
6401 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006402static int patch_alc269(struct hda_codec *codec)
6403{
6404 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006405 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006406
Takashi Iwai3de95172012-05-07 18:03:15 +02006407 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006408 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006409 return err;
6410
6411 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006412
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006413 alc_pick_fixup(codec, alc269_fixup_models,
6414 alc269_fixup_tbl, alc269_fixups);
6415 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6416
6417 alc_auto_parse_customize_define(codec);
6418
Kailang Yang065380f2013-01-10 10:25:48 +01006419 switch (codec->vendor_id) {
6420 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006421 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006422 switch (alc_get_coef0(codec) & 0x00f0) {
6423 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006424 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006425 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006426 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006427 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006428 break;
6429 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006430 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6431 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006432 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006433 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006434 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006435 case 0x0030:
6436 spec->codec_variant = ALC269_TYPE_ALC269VD;
6437 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006438 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006439 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006440 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006441 if (err < 0)
6442 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006443 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006444 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006445 break;
6446
6447 case 0x10ec0280:
6448 case 0x10ec0290:
6449 spec->codec_variant = ALC269_TYPE_ALC280;
6450 break;
6451 case 0x10ec0282:
6452 case 0x10ec0283:
6453 spec->codec_variant = ALC269_TYPE_ALC282;
6454 break;
6455 case 0x10ec0284:
6456 case 0x10ec0292:
6457 spec->codec_variant = ALC269_TYPE_ALC284;
6458 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006459 }
6460
Takashi Iwaia4297b52011-08-23 18:40:12 +02006461 /* automatic parse from the BIOS config */
6462 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006463 if (err < 0)
6464 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006465
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006466 if (!spec->no_analog && has_cdefine_beep(codec)) {
6467 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006468 if (err < 0)
6469 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006470 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006471 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006472
Takashi Iwai1d045db2011-07-07 18:23:21 +02006473 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006474#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006475 codec->patch_ops.resume = alc269_resume;
6476#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006477 spec->shutup = alc269_shutup;
6478
Takashi Iwai589876e2012-02-20 15:47:55 +01006479 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6480
Takashi Iwai1d045db2011-07-07 18:23:21 +02006481 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006482
6483 error:
6484 alc_free(codec);
6485 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006486}
6487
6488/*
6489 * ALC861
6490 */
6491
Takashi Iwai1d045db2011-07-07 18:23:21 +02006492static int alc861_parse_auto_config(struct hda_codec *codec)
6493{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006494 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006495 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6496 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006497}
6498
Takashi Iwai1d045db2011-07-07 18:23:21 +02006499/* Pin config fixes */
6500enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006501 ALC861_FIXUP_FSC_AMILO_PI1505,
6502 ALC861_FIXUP_AMP_VREF_0F,
6503 ALC861_FIXUP_NO_JACK_DETECT,
6504 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006505};
6506
Takashi Iwai31150f22012-01-30 10:54:08 +01006507/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6508static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6509 const struct alc_fixup *fix, int action)
6510{
6511 struct alc_spec *spec = codec->spec;
6512 unsigned int val;
6513
6514 if (action != ALC_FIXUP_ACT_INIT)
6515 return;
6516 val = snd_hda_codec_read(codec, 0x0f, 0,
6517 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6518 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6519 val |= AC_PINCTL_IN_EN;
6520 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006521 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006522 spec->keep_vref_in_automute = 1;
6523}
6524
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006525/* suppress the jack-detection */
6526static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6527 const struct alc_fixup *fix, int action)
6528{
6529 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6530 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006531}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006532
Takashi Iwai1d045db2011-07-07 18:23:21 +02006533static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006534 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006535 .type = ALC_FIXUP_PINS,
6536 .v.pins = (const struct alc_pincfg[]) {
6537 { 0x0b, 0x0221101f }, /* HP */
6538 { 0x0f, 0x90170310 }, /* speaker */
6539 { }
6540 }
6541 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006542 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006543 .type = ALC_FIXUP_FUNC,
6544 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006545 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006546 [ALC861_FIXUP_NO_JACK_DETECT] = {
6547 .type = ALC_FIXUP_FUNC,
6548 .v.func = alc_fixup_no_jack_detect,
6549 },
6550 [ALC861_FIXUP_ASUS_A6RP] = {
6551 .type = ALC_FIXUP_FUNC,
6552 .v.func = alc861_fixup_asus_amp_vref_0f,
6553 .chained = true,
6554 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6555 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006556};
6557
6558static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006559 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6560 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6561 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6562 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6563 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6564 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006565 {}
6566};
6567
6568/*
6569 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006570static int patch_alc861(struct hda_codec *codec)
6571{
6572 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006573 int err;
6574
Takashi Iwai3de95172012-05-07 18:03:15 +02006575 err = alc_alloc_spec(codec, 0x15);
6576 if (err < 0)
6577 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006578
Takashi Iwai3de95172012-05-07 18:03:15 +02006579 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006580
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006581 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6582 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006583
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006584 /* automatic parse from the BIOS config */
6585 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006586 if (err < 0)
6587 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006588
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006589 if (!spec->no_analog) {
6590 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006591 if (err < 0)
6592 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006593 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6594 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006595
Takashi Iwai1d045db2011-07-07 18:23:21 +02006596 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006597#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006598 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006599#endif
6600
Takashi Iwai589876e2012-02-20 15:47:55 +01006601 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6602
Takashi Iwai1d045db2011-07-07 18:23:21 +02006603 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006604
6605 error:
6606 alc_free(codec);
6607 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006608}
6609
6610/*
6611 * ALC861-VD support
6612 *
6613 * Based on ALC882
6614 *
6615 * In addition, an independent DAC
6616 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006617static int alc861vd_parse_auto_config(struct hda_codec *codec)
6618{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006619 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006620 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6621 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006622}
6623
Takashi Iwai1d045db2011-07-07 18:23:21 +02006624enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006625 ALC660VD_FIX_ASUS_GPIO1,
6626 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006627};
6628
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006629/* exclude VREF80 */
6630static void alc861vd_fixup_dallas(struct hda_codec *codec,
6631 const struct alc_fixup *fix, int action)
6632{
6633 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006634 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6635 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006636 }
6637}
6638
Takashi Iwai1d045db2011-07-07 18:23:21 +02006639static const struct alc_fixup alc861vd_fixups[] = {
6640 [ALC660VD_FIX_ASUS_GPIO1] = {
6641 .type = ALC_FIXUP_VERBS,
6642 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006643 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006644 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6645 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6646 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6647 { }
6648 }
6649 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006650 [ALC861VD_FIX_DALLAS] = {
6651 .type = ALC_FIXUP_FUNC,
6652 .v.func = alc861vd_fixup_dallas,
6653 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006654};
6655
6656static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006657 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006658 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006659 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006660 {}
6661};
6662
Takashi Iwai1d045db2011-07-07 18:23:21 +02006663/*
6664 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006665static int patch_alc861vd(struct hda_codec *codec)
6666{
6667 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006668 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006669
Takashi Iwai3de95172012-05-07 18:03:15 +02006670 err = alc_alloc_spec(codec, 0x0b);
6671 if (err < 0)
6672 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006673
Takashi Iwai3de95172012-05-07 18:03:15 +02006674 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006675
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006676 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6677 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006678
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006679 /* automatic parse from the BIOS config */
6680 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006681 if (err < 0)
6682 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006683
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006684 if (!spec->no_analog) {
6685 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006686 if (err < 0)
6687 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006688 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6689 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006690
Takashi Iwai1d045db2011-07-07 18:23:21 +02006691 codec->patch_ops = alc_patch_ops;
6692
Takashi Iwai1d045db2011-07-07 18:23:21 +02006693 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006694
Takashi Iwai589876e2012-02-20 15:47:55 +01006695 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6696
Takashi Iwai1d045db2011-07-07 18:23:21 +02006697 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006698
6699 error:
6700 alc_free(codec);
6701 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006702}
6703
6704/*
6705 * ALC662 support
6706 *
6707 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6708 * configuration. Each pin widget can choose any input DACs and a mixer.
6709 * Each ADC is connected from a mixer of all inputs. This makes possible
6710 * 6-channel independent captures.
6711 *
6712 * In addition, an independent DAC for the multi-playback (not used in this
6713 * driver yet).
6714 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006715
6716/*
6717 * BIOS auto configuration
6718 */
6719
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006720static int alc662_parse_auto_config(struct hda_codec *codec)
6721{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006722 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006723 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6724 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6725 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006726
Kailang Yang6227cdc2010-02-25 08:36:52 +01006727 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6728 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006729 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006730 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006731 ssids = alc662_ssids;
6732 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006733}
6734
Todd Broch6be79482010-12-07 16:51:05 -08006735static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006736 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006737{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006738 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006739 return;
Todd Broch6be79482010-12-07 16:51:05 -08006740 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6741 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6742 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6743 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6744 (0 << AC_AMPCAP_MUTE_SHIFT)))
6745 printk(KERN_WARNING
6746 "hda_codec: failed to override amp caps for NID 0x2\n");
6747}
6748
David Henningsson6cb3b702010-09-09 08:51:44 +02006749enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006750 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006751 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006752 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006753 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006754 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006755 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006756 ALC662_FIXUP_ASUS_MODE1,
6757 ALC662_FIXUP_ASUS_MODE2,
6758 ALC662_FIXUP_ASUS_MODE3,
6759 ALC662_FIXUP_ASUS_MODE4,
6760 ALC662_FIXUP_ASUS_MODE5,
6761 ALC662_FIXUP_ASUS_MODE6,
6762 ALC662_FIXUP_ASUS_MODE7,
6763 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006764 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006765 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006766 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006767};
6768
6769static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006770 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006771 .type = ALC_FIXUP_PINS,
6772 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006773 { 0x15, 0x99130112 }, /* subwoofer */
6774 { }
6775 }
6776 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006777 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006778 .type = ALC_FIXUP_PINS,
6779 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006780 { 0x17, 0x99130112 }, /* subwoofer */
6781 { }
6782 }
6783 },
Todd Broch6be79482010-12-07 16:51:05 -08006784 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006785 .type = ALC_FIXUP_FUNC,
6786 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006787 },
6788 [ALC662_FIXUP_CZC_P10T] = {
6789 .type = ALC_FIXUP_VERBS,
6790 .v.verbs = (const struct hda_verb[]) {
6791 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6792 {}
6793 }
6794 },
David Henningsson94024cd2011-04-29 14:10:55 +02006795 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006796 .type = ALC_FIXUP_FUNC,
6797 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006798 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006799 [ALC662_FIXUP_HP_RP5800] = {
6800 .type = ALC_FIXUP_PINS,
6801 .v.pins = (const struct alc_pincfg[]) {
6802 { 0x14, 0x0221201f }, /* HP out */
6803 { }
6804 },
6805 .chained = true,
6806 .chain_id = ALC662_FIXUP_SKU_IGNORE
6807 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006808 [ALC662_FIXUP_ASUS_MODE1] = {
6809 .type = ALC_FIXUP_PINS,
6810 .v.pins = (const struct alc_pincfg[]) {
6811 { 0x14, 0x99130110 }, /* speaker */
6812 { 0x18, 0x01a19c20 }, /* mic */
6813 { 0x19, 0x99a3092f }, /* int-mic */
6814 { 0x21, 0x0121401f }, /* HP out */
6815 { }
6816 },
6817 .chained = true,
6818 .chain_id = ALC662_FIXUP_SKU_IGNORE
6819 },
6820 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006821 .type = ALC_FIXUP_PINS,
6822 .v.pins = (const struct alc_pincfg[]) {
6823 { 0x14, 0x99130110 }, /* speaker */
6824 { 0x18, 0x01a19820 }, /* mic */
6825 { 0x19, 0x99a3092f }, /* int-mic */
6826 { 0x1b, 0x0121401f }, /* HP out */
6827 { }
6828 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006829 .chained = true,
6830 .chain_id = ALC662_FIXUP_SKU_IGNORE
6831 },
6832 [ALC662_FIXUP_ASUS_MODE3] = {
6833 .type = ALC_FIXUP_PINS,
6834 .v.pins = (const struct alc_pincfg[]) {
6835 { 0x14, 0x99130110 }, /* speaker */
6836 { 0x15, 0x0121441f }, /* HP */
6837 { 0x18, 0x01a19840 }, /* mic */
6838 { 0x19, 0x99a3094f }, /* int-mic */
6839 { 0x21, 0x01211420 }, /* HP2 */
6840 { }
6841 },
6842 .chained = true,
6843 .chain_id = ALC662_FIXUP_SKU_IGNORE
6844 },
6845 [ALC662_FIXUP_ASUS_MODE4] = {
6846 .type = ALC_FIXUP_PINS,
6847 .v.pins = (const struct alc_pincfg[]) {
6848 { 0x14, 0x99130110 }, /* speaker */
6849 { 0x16, 0x99130111 }, /* speaker */
6850 { 0x18, 0x01a19840 }, /* mic */
6851 { 0x19, 0x99a3094f }, /* int-mic */
6852 { 0x21, 0x0121441f }, /* HP */
6853 { }
6854 },
6855 .chained = true,
6856 .chain_id = ALC662_FIXUP_SKU_IGNORE
6857 },
6858 [ALC662_FIXUP_ASUS_MODE5] = {
6859 .type = ALC_FIXUP_PINS,
6860 .v.pins = (const struct alc_pincfg[]) {
6861 { 0x14, 0x99130110 }, /* speaker */
6862 { 0x15, 0x0121441f }, /* HP */
6863 { 0x16, 0x99130111 }, /* speaker */
6864 { 0x18, 0x01a19840 }, /* mic */
6865 { 0x19, 0x99a3094f }, /* int-mic */
6866 { }
6867 },
6868 .chained = true,
6869 .chain_id = ALC662_FIXUP_SKU_IGNORE
6870 },
6871 [ALC662_FIXUP_ASUS_MODE6] = {
6872 .type = ALC_FIXUP_PINS,
6873 .v.pins = (const struct alc_pincfg[]) {
6874 { 0x14, 0x99130110 }, /* speaker */
6875 { 0x15, 0x01211420 }, /* HP2 */
6876 { 0x18, 0x01a19840 }, /* mic */
6877 { 0x19, 0x99a3094f }, /* int-mic */
6878 { 0x1b, 0x0121441f }, /* HP */
6879 { }
6880 },
6881 .chained = true,
6882 .chain_id = ALC662_FIXUP_SKU_IGNORE
6883 },
6884 [ALC662_FIXUP_ASUS_MODE7] = {
6885 .type = ALC_FIXUP_PINS,
6886 .v.pins = (const struct alc_pincfg[]) {
6887 { 0x14, 0x99130110 }, /* speaker */
6888 { 0x17, 0x99130111 }, /* speaker */
6889 { 0x18, 0x01a19840 }, /* mic */
6890 { 0x19, 0x99a3094f }, /* int-mic */
6891 { 0x1b, 0x01214020 }, /* HP */
6892 { 0x21, 0x0121401f }, /* HP */
6893 { }
6894 },
6895 .chained = true,
6896 .chain_id = ALC662_FIXUP_SKU_IGNORE
6897 },
6898 [ALC662_FIXUP_ASUS_MODE8] = {
6899 .type = ALC_FIXUP_PINS,
6900 .v.pins = (const struct alc_pincfg[]) {
6901 { 0x14, 0x99130110 }, /* speaker */
6902 { 0x12, 0x99a30970 }, /* int-mic */
6903 { 0x15, 0x01214020 }, /* HP */
6904 { 0x17, 0x99130111 }, /* speaker */
6905 { 0x18, 0x01a19840 }, /* mic */
6906 { 0x21, 0x0121401f }, /* HP */
6907 { }
6908 },
6909 .chained = true,
6910 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006911 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006912 [ALC662_FIXUP_NO_JACK_DETECT] = {
6913 .type = ALC_FIXUP_FUNC,
6914 .v.func = alc_fixup_no_jack_detect,
6915 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006916 [ALC662_FIXUP_ZOTAC_Z68] = {
6917 .type = ALC_FIXUP_PINS,
6918 .v.pins = (const struct alc_pincfg[]) {
6919 { 0x1b, 0x02214020 }, /* Front HP */
6920 { }
6921 }
6922 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006923 [ALC662_FIXUP_INV_DMIC] = {
6924 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006925 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006926 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006927};
6928
Takashi Iwaia9111322011-05-02 11:30:18 +02006929static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006930 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006931 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006932 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006933 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006934 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006935 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006936 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006937 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006938 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006939 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006940 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006941 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006942 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006943
6944#if 0
6945 /* Below is a quirk table taken from the old code.
6946 * Basically the device should work as is without the fixup table.
6947 * If BIOS doesn't give a proper info, enable the corresponding
6948 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006949 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006950 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6951 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6952 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6953 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6954 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6955 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6956 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6957 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6958 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6959 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6960 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6961 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6962 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6963 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6964 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6965 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6966 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6967 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6968 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6969 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6970 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6971 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6972 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6973 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6974 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6975 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6976 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6977 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6978 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6979 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6980 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6981 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6982 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6983 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6984 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6985 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6986 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6987 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6988 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6989 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6990 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6991 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6992 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6993 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6994 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6995 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6996 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6997 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6998 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6999 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7000#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007001 {}
7002};
7003
Todd Broch6be79482010-12-07 16:51:05 -08007004static const struct alc_model_fixup alc662_fixup_models[] = {
7005 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007006 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7007 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7008 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7009 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7010 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7011 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7012 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7013 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007014 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007015 {}
7016};
David Henningsson6cb3b702010-09-09 08:51:44 +02007017
Kailang Yang8663ff72012-06-29 09:35:52 +02007018static void alc662_fill_coef(struct hda_codec *codec)
7019{
7020 int val, coef;
7021
7022 coef = alc_get_coef0(codec);
7023
7024 switch (codec->vendor_id) {
7025 case 0x10ec0662:
7026 if ((coef & 0x00f0) == 0x0030) {
7027 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7028 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7029 }
7030 break;
7031 case 0x10ec0272:
7032 case 0x10ec0273:
7033 case 0x10ec0663:
7034 case 0x10ec0665:
7035 case 0x10ec0670:
7036 case 0x10ec0671:
7037 case 0x10ec0672:
7038 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7039 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7040 break;
7041 }
7042}
David Henningsson6cb3b702010-09-09 08:51:44 +02007043
Takashi Iwai1d045db2011-07-07 18:23:21 +02007044/*
7045 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007046static int patch_alc662(struct hda_codec *codec)
7047{
7048 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007049 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007050
Takashi Iwai3de95172012-05-07 18:03:15 +02007051 err = alc_alloc_spec(codec, 0x0b);
7052 if (err < 0)
7053 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007054
Takashi Iwai3de95172012-05-07 18:03:15 +02007055 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007056
Takashi Iwai53c334a2011-08-23 18:27:14 +02007057 /* handle multiple HPs as is */
7058 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7059
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007060 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7061
Kailang Yang8663ff72012-06-29 09:35:52 +02007062 spec->init_hook = alc662_fill_coef;
7063 alc662_fill_coef(codec);
7064
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007065 alc_pick_fixup(codec, alc662_fixup_models,
7066 alc662_fixup_tbl, alc662_fixups);
7067 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7068
7069 alc_auto_parse_customize_define(codec);
7070
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007071 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007072 codec->bus->pci->subsystem_vendor == 0x1025 &&
7073 spec->cdefine.platform_type == 1) {
7074 if (alc_codec_rename(codec, "ALC272X") < 0)
7075 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007076 }
Kailang Yang274693f2009-12-03 10:07:50 +01007077
Takashi Iwaib9c51062011-08-24 18:08:07 +02007078 /* automatic parse from the BIOS config */
7079 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007080 if (err < 0)
7081 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007082
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007083 if (!spec->no_analog && has_cdefine_beep(codec)) {
7084 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007085 if (err < 0)
7086 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007087 switch (codec->vendor_id) {
7088 case 0x10ec0662:
7089 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7090 break;
7091 case 0x10ec0272:
7092 case 0x10ec0663:
7093 case 0x10ec0665:
7094 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7095 break;
7096 case 0x10ec0273:
7097 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7098 break;
7099 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007100 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007101
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007102 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007103 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007104
Takashi Iwai589876e2012-02-20 15:47:55 +01007105 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7106
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007107 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007108
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007109 error:
7110 alc_free(codec);
7111 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007112}
7113
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007114/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007115 * ALC680 support
7116 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007117
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007118static int alc680_parse_auto_config(struct hda_codec *codec)
7119{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007120 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007121}
7122
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007123/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007124 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007125static int patch_alc680(struct hda_codec *codec)
7126{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007127 int err;
7128
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007129 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007130 err = alc_alloc_spec(codec, 0);
7131 if (err < 0)
7132 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007133
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007134 /* automatic parse from the BIOS config */
7135 err = alc680_parse_auto_config(codec);
7136 if (err < 0) {
7137 alc_free(codec);
7138 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007139 }
7140
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007141 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007142
7143 return 0;
7144}
7145
7146/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007147 * patch entries
7148 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007149static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007150 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007151 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007152 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007153 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007154 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007155 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007156 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007157 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007158 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007159 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007160 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007161 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007162 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007163 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007164 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007165 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007166 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007167 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007168 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7169 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7170 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007171 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007172 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007173 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7174 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007175 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7176 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007177 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007178 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007179 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007180 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007181 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007182 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007183 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007184 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007185 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007186 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007187 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007188 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007189 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007190 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007191 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007192 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007193 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007194 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007195 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007196 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007197 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007198 {} /* terminator */
7199};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007200
7201MODULE_ALIAS("snd-hda-codec-id:10ec*");
7202
7203MODULE_LICENSE("GPL");
7204MODULE_DESCRIPTION("Realtek HD-audio codec");
7205
7206static struct hda_codec_preset_list realtek_list = {
7207 .preset = snd_hda_preset_realtek,
7208 .owner = THIS_MODULE,
7209};
7210
7211static int __init patch_realtek_init(void)
7212{
7213 return snd_hda_add_codec_preset(&realtek_list);
7214}
7215
7216static void __exit patch_realtek_exit(void)
7217{
7218 snd_hda_delete_codec_preset(&realtek_list);
7219}
7220
7221module_init(patch_realtek_init)
7222module_exit(patch_realtek_exit)