blob: 6d57547aecac723329a8370ca234d8317fe4ee79 [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;
Hector Martin3b315d72009-06-02 10:54:19 +0200156 int const_channel_count;
157 int ext_channel_count;
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 Iwaiae6b8132006-03-03 16:47:17 +0100175 /* hooks */
176 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200177#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500178 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100179#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200180 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200181 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100182
Takashi Iwai834be882006-03-01 14:16:17 +0100183 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200184 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200185 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200186 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200187 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200188 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200189 unsigned int automute_speaker:1; /* automute speaker outputs */
190 unsigned int automute_lo:1; /* automute LO outputs */
191 unsigned int detect_hp:1; /* Headphone detection enabled */
192 unsigned int detect_lo:1; /* Line-out detection enabled */
193 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
194 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100195 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200196
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100197 /* other flags */
198 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200199 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100200 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200201 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200202 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100203 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200204 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
205 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200206 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200207
208 /* auto-mute control */
209 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200210 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200211
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200212 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200213 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100214
Takashi Iwai2134ea42008-01-10 16:53:55 +0100215 /* for virtual master */
216 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100217 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200218#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200219 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100220 int num_loopbacks;
221 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200222#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200223
224 /* for PLL fix */
225 hda_nid_t pll_nid;
226 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200227 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100228
Takashi Iwaice764ab2011-04-27 16:35:23 +0200229 /* multi-io */
230 int multi_ios;
231 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200232
233 /* bind volumes */
234 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100235};
236
Takashi Iwai44c02402011-07-08 15:14:19 +0200237static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
238 int dir, unsigned int bits)
239{
240 if (!nid)
241 return false;
242 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
243 if (query_amp_caps(codec, nid, dir) & bits)
244 return true;
245 return false;
246}
247
248#define nid_has_mute(codec, nid, dir) \
249 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
250#define nid_has_volume(codec, nid, dir) \
251 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253/*
254 * input MUX handling
255 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200256static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
260 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200261 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
262 if (mux_idx >= spec->num_mux_defs)
263 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100264 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
265 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200266 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200269static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
270 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
272 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
273 struct alc_spec *spec = codec->spec;
274 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
275
276 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
277 return 0;
278}
279
Takashi Iwai21268962011-07-07 15:01:13 +0200280static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Takashi Iwai21268962011-07-07 15:01:13 +0200282 struct alc_spec *spec = codec->spec;
283 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
284
285 if (spec->cur_adc && spec->cur_adc != new_adc) {
286 /* stream is running, let's swap the current ADC */
287 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
288 spec->cur_adc = new_adc;
289 snd_hda_codec_setup_stream(codec, new_adc,
290 spec->cur_adc_stream_tag, 0,
291 spec->cur_adc_format);
292 return true;
293 }
294 return false;
295}
296
Takashi Iwai61071592011-11-23 07:52:15 +0100297static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
298{
299 return spec->capsrc_nids ?
300 spec->capsrc_nids[idx] : spec->adc_nids[idx];
301}
302
Takashi Iwai24de1832011-11-07 17:13:39 +0100303static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200304static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100305
David Henningsson00227f12012-06-27 18:45:44 +0200306/* for shared I/O, change the pin-control accordingly */
307static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
308{
309 struct alc_spec *spec = codec->spec;
310 unsigned int val;
311 hda_nid_t pin = spec->autocfg.inputs[1].pin;
312 /* NOTE: this assumes that there are only two inputs, the
313 * first is the real internal mic and the second is HP/mic jack.
314 */
315
316 val = snd_hda_get_default_vref(codec, pin);
317
318 /* This pin does not have vref caps - let's enable vref on pin 0x18
319 instead, as suggested by Realtek */
320 if (val == AC_PINCTL_VREF_HIZ) {
321 const hda_nid_t vref_pin = 0x18;
322 /* Sanity check pin 0x18 */
323 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
324 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
325 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
326 if (vref_val != AC_PINCTL_VREF_HIZ)
327 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
328 }
329 }
330
331 val = set_as_mic ? val | PIN_IN : PIN_HP;
332 snd_hda_set_pin_ctl(codec, pin, val);
333
334 spec->automute_speaker = !set_as_mic;
335 call_update_outputs(codec);
336}
Takashi Iwai21268962011-07-07 15:01:13 +0200337
338/* select the given imux item; either unmute exclusively or select the route */
339static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
340 unsigned int idx, bool force)
341{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100343 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100344 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100345 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200346 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Takashi Iwai5803a322012-02-21 11:59:45 +0100348 if (!spec->input_mux)
349 return 0;
350
Takashi Iwaicd896c32008-11-18 12:36:33 +0100351 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
352 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100353 if (!imux->num_items && mux_idx > 0)
354 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100355 if (!imux->num_items)
356 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100357
Takashi Iwai21268962011-07-07 15:01:13 +0200358 if (idx >= imux->num_items)
359 idx = imux->num_items - 1;
360 if (spec->cur_mux[adc_idx] == idx && !force)
361 return 0;
362 spec->cur_mux[adc_idx] = idx;
363
David Henningsson00227f12012-06-27 18:45:44 +0200364 if (spec->shared_mic_hp)
365 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100366
Takashi Iwai21268962011-07-07 15:01:13 +0200367 if (spec->dyn_adc_switch) {
368 alc_dyn_adc_pcm_resetup(codec, idx);
369 adc_idx = spec->dyn_adc_idx[idx];
370 }
371
Takashi Iwai61071592011-11-23 07:52:15 +0100372 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200373
374 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200375 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100376 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200377 return 1;
378
Takashi Iwaia22d5432009-07-27 12:54:26 +0200379 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200380 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100381 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100382 int active = imux->items[idx].index;
383 for (i = 0; i < num_conns; i++) {
384 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
385 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100386 HDA_AMP_MUTE, v);
387 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100388 } else {
389 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200390 snd_hda_codec_write_cache(codec, nid, 0,
391 AC_VERB_SET_CONNECT_SEL,
392 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100393 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200394 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200395 return 1;
396}
397
398static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403 return alc_mux_select(codec, adc_idx,
404 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100405}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100408 * set up the input pin config (depending on the given auto-pin type)
409 */
410static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
411 int auto_pin_type)
412{
413 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200414 if (auto_pin_type == AUTO_PIN_MIC)
415 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200416 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100417}
418
419/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200420 * Append the given mixer and verb elements for the later use
421 * The mixer array is referred in build_controls(), and init_verbs are
422 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100423 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200424static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100425{
426 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
427 return;
428 spec->mixers[spec->num_mixers++] = mix;
429}
430
Takashi Iwaid88897e2008-10-31 15:01:37 +0100431/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200432 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100433 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200434/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200435static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200436 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
437 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
438 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
439 { }
440};
441
Takashi Iwaia9111322011-05-02 11:30:18 +0200442static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200443 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
444 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
445 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
446 { }
447};
448
Takashi Iwaia9111322011-05-02 11:30:18 +0200449static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200450 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
451 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
452 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
453 { }
454};
455
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200456/*
457 * Fix hardware PLL issue
458 * On some codecs, the analog PLL gating control must be off while
459 * the default value is 1.
460 */
461static void alc_fix_pll(struct hda_codec *codec)
462{
463 struct alc_spec *spec = codec->spec;
464 unsigned int val;
465
466 if (!spec->pll_nid)
467 return;
468 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
469 spec->pll_coef_idx);
470 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
471 AC_VERB_GET_PROC_COEF, 0);
472 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
473 spec->pll_coef_idx);
474 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
475 val & ~(1 << spec->pll_coef_bit));
476}
477
478static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
479 unsigned int coef_idx, unsigned int coef_bit)
480{
481 struct alc_spec *spec = codec->spec;
482 spec->pll_nid = nid;
483 spec->pll_coef_idx = coef_idx;
484 spec->pll_coef_bit = coef_bit;
485 alc_fix_pll(codec);
486}
487
Takashi Iwai1d045db2011-07-07 18:23:21 +0200488/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200489 * Jack detections for HP auto-mute and mic-switch
490 */
491
492/* check each pin in the given array; returns true if any of them is plugged */
493static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200494{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200496
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200499 if (!nid)
500 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200502 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200503 return present;
504}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200505
Takashi Iwai1d045db2011-07-07 18:23:21 +0200506/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200508 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200509{
510 struct alc_spec *spec = codec->spec;
511 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200512 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200513 int i;
514
515 for (i = 0; i < num_pins; i++) {
516 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100517 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200518 if (!nid)
519 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200520 switch (spec->automute_mode) {
521 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100522 /* don't reset VREF value in case it's controlling
523 * the amp (see alc861_fixup_asus_amp_vref_0f())
524 */
525 if (spec->keep_vref_in_automute) {
526 val = snd_hda_codec_read(codec, nid, 0,
527 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
528 val &= ~PIN_HP;
529 } else
530 val = 0;
531 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200532 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200533 break;
534 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200535 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200536 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200537 break;
538 case ALC_AUTOMUTE_MIXER:
539 nid = spec->automute_mixer_nid[i];
540 if (!nid)
541 break;
542 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200544 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200545 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200546 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200547 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200548 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200549}
550
David Henningsson42cf0d02011-09-20 12:04:56 +0200551/* Toggle outputs muting */
552static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200553{
554 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556
Takashi Iwaic0a20262011-06-10 15:28:15 +0200557 /* Control HP pins/amps depending on master_mute state;
558 * in general, HP pins/amps control should be enabled in all cases,
559 * but currently set only for master_mute, just to be safe
560 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100561 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
562 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200563 spec->autocfg.hp_pins, spec->master_mute, true);
564
David Henningsson42cf0d02011-09-20 12:04:56 +0200565 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 on = 0;
567 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200568 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200569 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200570 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200571 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200572
573 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200574 /* if LO is a copy of either HP or Speaker, don't need to handle it */
575 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
576 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200578 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200579 on = 0;
580 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200581 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200582 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200584 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200585}
586
David Henningsson42cf0d02011-09-20 12:04:56 +0200587static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200588{
589 struct alc_spec *spec = codec->spec;
590 if (spec->automute_hook)
591 spec->automute_hook(codec);
592 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200593 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200594}
595
Takashi Iwai1d045db2011-07-07 18:23:21 +0200596/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200597static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200598{
599 struct alc_spec *spec = codec->spec;
600
David Henningsson42cf0d02011-09-20 12:04:56 +0200601 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
603 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200604 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200605 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200606 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607}
608
Takashi Iwai1d045db2011-07-07 18:23:21 +0200609/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200610static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200611{
612 struct alc_spec *spec = codec->spec;
613
David Henningssonf7f4b2322012-10-10 16:32:09 +0200614 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
615 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200616 /* check LO jack only when it's different from HP */
617 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
618 return;
619
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200620 spec->line_jack_present =
621 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
622 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200623 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200624 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200625 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200626}
627
Takashi Iwai8d087c72011-06-28 12:45:47 +0200628#define get_connection_index(codec, mux, nid) \
629 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200630
Takashi Iwai1d045db2011-07-07 18:23:21 +0200631/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200632static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200633{
634 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200635 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200636
Takashi Iwai21268962011-07-07 15:01:13 +0200637 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200638 return;
639 if (snd_BUG_ON(!spec->adc_nids))
640 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200641 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200642 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200643
Takashi Iwai21268962011-07-07 15:01:13 +0200644 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
645 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
646 else if (spec->dock_mic_idx >= 0 &&
647 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
648 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
649 else
650 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200651}
652
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100653/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200654static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100655{
656 unsigned int val;
657 struct snd_kcontrol *kctl;
658 struct snd_ctl_elem_value *uctl;
659
660 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
661 if (!kctl)
662 return;
663 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
664 if (!uctl)
665 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200666 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100667 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
668 val &= HDA_AMP_VOLMASK;
669 uctl->value.integer.value[0] = val;
670 uctl->value.integer.value[1] = val;
671 kctl->put(kctl, uctl);
672 kfree(uctl);
673}
674
David Henningsson29adc4b2012-09-25 11:31:00 +0200675static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100676{
David Henningsson29adc4b2012-09-25 11:31:00 +0200677 /* For some reason, the res given from ALC880 is broken.
678 Here we adjust it properly. */
679 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100680}
681
Takashi Iwai1d045db2011-07-07 18:23:21 +0200682/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200683static void alc_inithook(struct hda_codec *codec)
684{
David Henningsson29adc4b2012-09-25 11:31:00 +0200685 alc_hp_automute(codec, NULL);
686 alc_line_automute(codec, NULL);
687 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200688}
689
Kailang Yangf9423e72008-05-27 12:32:25 +0200690/* additional initialization for ALC888 variants */
691static void alc888_coef_init(struct hda_codec *codec)
692{
693 unsigned int tmp;
694
695 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
696 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100698 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200699 /* alc888S-VC */
700 snd_hda_codec_read(codec, 0x20, 0,
701 AC_VERB_SET_PROC_COEF, 0x830);
702 else
703 /* alc888-VB */
704 snd_hda_codec_read(codec, 0x20, 0,
705 AC_VERB_SET_PROC_COEF, 0x3030);
706}
707
Takashi Iwai1d045db2011-07-07 18:23:21 +0200708/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200709static void alc889_coef_init(struct hda_codec *codec)
710{
711 unsigned int tmp;
712
713 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
714 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
715 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
716 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
717}
718
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100719/* turn on/off EAPD control (only if available) */
720static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
721{
722 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
723 return;
724 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
725 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
726 on ? 2 : 0);
727}
728
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200729/* turn on/off EAPD controls of the codec */
730static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
731{
732 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200733 static hda_nid_t pins[] = {
734 0x0f, 0x10, 0x14, 0x15, 0
735 };
736 hda_nid_t *p;
737 for (p = pins; *p; p++)
738 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200739}
740
Takashi Iwai1c7161532011-04-07 10:37:16 +0200741/* generic shutup callback;
742 * just turning off EPAD and a little pause for avoiding pop-noise
743 */
744static void alc_eapd_shutup(struct hda_codec *codec)
745{
746 alc_auto_setup_eapd(codec, false);
747 msleep(200);
748}
749
Takashi Iwai1d045db2011-07-07 18:23:21 +0200750/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200751static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200752{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200753 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200754
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200755 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200756 switch (type) {
757 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200758 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
759 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200760 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200761 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
762 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200763 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200764 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
765 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200766 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200767 switch (codec->vendor_id) {
768 case 0x10ec0260:
769 snd_hda_codec_write(codec, 0x1a, 0,
770 AC_VERB_SET_COEF_INDEX, 7);
771 tmp = snd_hda_codec_read(codec, 0x1a, 0,
772 AC_VERB_GET_PROC_COEF, 0);
773 snd_hda_codec_write(codec, 0x1a, 0,
774 AC_VERB_SET_COEF_INDEX, 7);
775 snd_hda_codec_write(codec, 0x1a, 0,
776 AC_VERB_SET_PROC_COEF,
777 tmp | 0x2010);
778 break;
779 case 0x10ec0262:
780 case 0x10ec0880:
781 case 0x10ec0882:
782 case 0x10ec0883:
783 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100784 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100785 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200786 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200787 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200788 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200789 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200790 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100791#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200792 case 0x10ec0267:
793 case 0x10ec0268:
794 snd_hda_codec_write(codec, 0x20, 0,
795 AC_VERB_SET_COEF_INDEX, 7);
796 tmp = snd_hda_codec_read(codec, 0x20, 0,
797 AC_VERB_GET_PROC_COEF, 0);
798 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200799 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200800 snd_hda_codec_write(codec, 0x20, 0,
801 AC_VERB_SET_PROC_COEF,
802 tmp | 0x3000);
803 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100804#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200805 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200806 break;
807 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200808}
Kailang Yangea1fb292008-08-26 12:58:38 +0200809
Takashi Iwai1d045db2011-07-07 18:23:21 +0200810/*
811 * Auto-Mute mode mixer enum support
812 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200813static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_info *uinfo)
815{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct alc_spec *spec = codec->spec;
818 static const char * const texts2[] = {
819 "Disabled", "Enabled"
820 };
821 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100822 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200823 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200824 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200825
826 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
827 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200828 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200829 uinfo->value.enumerated.items = 3;
830 texts = texts3;
831 } else {
832 uinfo->value.enumerated.items = 2;
833 texts = texts2;
834 }
835 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
836 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200837 strcpy(uinfo->value.enumerated.name,
838 texts[uinfo->value.enumerated.item]);
839 return 0;
840}
841
842static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
843 struct snd_ctl_elem_value *ucontrol)
844{
845 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
846 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200847 unsigned int val = 0;
848 if (spec->automute_speaker)
849 val++;
850 if (spec->automute_lo)
851 val++;
852
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200853 ucontrol->value.enumerated.item[0] = val;
854 return 0;
855}
856
857static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
858 struct snd_ctl_elem_value *ucontrol)
859{
860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
861 struct alc_spec *spec = codec->spec;
862
863 switch (ucontrol->value.enumerated.item[0]) {
864 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200865 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200866 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200867 spec->automute_speaker = 0;
868 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200869 break;
870 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200871 if (spec->automute_speaker_possible) {
872 if (!spec->automute_lo && spec->automute_speaker)
873 return 0;
874 spec->automute_speaker = 1;
875 spec->automute_lo = 0;
876 } else if (spec->automute_lo_possible) {
877 if (spec->automute_lo)
878 return 0;
879 spec->automute_lo = 1;
880 } else
881 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200882 break;
883 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200885 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200886 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200887 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200888 spec->automute_speaker = 1;
889 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200890 break;
891 default:
892 return -EINVAL;
893 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200894 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200895 return 1;
896}
897
Takashi Iwaia9111322011-05-02 11:30:18 +0200898static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
900 .name = "Auto-Mute Mode",
901 .info = alc_automute_mode_info,
902 .get = alc_automute_mode_get,
903 .put = alc_automute_mode_put,
904};
905
Takashi Iwai668d1e92012-11-29 14:10:17 +0100906static struct snd_kcontrol_new *
907alc_kcontrol_new(struct alc_spec *spec, const char *name,
908 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200909{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100910 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
911 if (!knew)
912 return NULL;
913 *knew = *temp;
914 knew->name = kstrdup(name, GFP_KERNEL);
915 if (!knew->name)
916 return NULL;
917 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200918}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200919
920static int alc_add_automute_mode_enum(struct hda_codec *codec)
921{
922 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200923
Takashi Iwai668d1e92012-11-29 14:10:17 +0100924 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200925 return -ENOMEM;
926 return 0;
927}
928
Takashi Iwai1d045db2011-07-07 18:23:21 +0200929/*
930 * Check the availability of HP/line-out auto-mute;
931 * Set up appropriately if really supported
932 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200933static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200934{
935 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200936 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200937 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200938 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200939
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200940 if (cfg->hp_pins[0])
941 present++;
942 if (cfg->line_out_pins[0])
943 present++;
944 if (cfg->speaker_pins[0])
945 present++;
946 if (present < 2) /* need two different output types */
947 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200948
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200949 if (!cfg->speaker_pins[0] &&
950 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200951 memcpy(cfg->speaker_pins, cfg->line_out_pins,
952 sizeof(cfg->speaker_pins));
953 cfg->speaker_outs = cfg->line_outs;
954 }
955
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200956 if (!cfg->hp_pins[0] &&
957 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200958 memcpy(cfg->hp_pins, cfg->line_out_pins,
959 sizeof(cfg->hp_pins));
960 cfg->hp_outs = cfg->line_outs;
961 }
962
David Henningsson42cf0d02011-09-20 12:04:56 +0200963 spec->automute_mode = ALC_AUTOMUTE_PIN;
964
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200965 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200966 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200967 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200968 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200969 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200970 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200971 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
972 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200973 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200974 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200975
David Henningsson42cf0d02011-09-20 12:04:56 +0200976 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
977 if (cfg->speaker_outs)
978 for (i = 0; i < cfg->line_outs; i++) {
979 hda_nid_t nid = cfg->line_out_pins[i];
980 if (!is_jack_detectable(codec, nid))
981 continue;
982 snd_printdd("realtek: Enable Line-Out "
983 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200984 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
985 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200986 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200987 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200988 spec->automute_lo_possible = spec->detect_hp;
989 }
990
991 spec->automute_speaker_possible = cfg->speaker_outs &&
992 (spec->detect_hp || spec->detect_lo);
993
994 spec->automute_lo = spec->automute_lo_possible;
995 spec->automute_speaker = spec->automute_speaker_possible;
996
David Henningssona7a0a642012-07-05 12:00:12 +0200997 if (spec->automute_speaker_possible || spec->automute_lo_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200998 /* create a control for automute mode */
999 alc_add_automute_mode_enum(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001000}
1001
Takashi Iwai1d045db2011-07-07 18:23:21 +02001002/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001003static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1004{
1005 int i;
1006 for (i = 0; i < nums; i++)
1007 if (list[i] == nid)
1008 return i;
1009 return -1;
1010}
1011
Takashi Iwai1d045db2011-07-07 18:23:21 +02001012/* check whether dynamic ADC-switching is available */
1013static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1014{
1015 struct alc_spec *spec = codec->spec;
1016 struct hda_input_mux *imux = &spec->private_imux[0];
1017 int i, n, idx;
1018 hda_nid_t cap, pin;
1019
1020 if (imux != spec->input_mux) /* no dynamic imux? */
1021 return false;
1022
1023 for (n = 0; n < spec->num_adc_nids; n++) {
1024 cap = spec->private_capsrc_nids[n];
1025 for (i = 0; i < imux->num_items; i++) {
1026 pin = spec->imux_pins[i];
1027 if (!pin)
1028 return false;
1029 if (get_connection_index(codec, cap, pin) < 0)
1030 break;
1031 }
1032 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001033 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001034 }
1035
1036 for (i = 0; i < imux->num_items; i++) {
1037 pin = spec->imux_pins[i];
1038 for (n = 0; n < spec->num_adc_nids; n++) {
1039 cap = spec->private_capsrc_nids[n];
1040 idx = get_connection_index(codec, cap, pin);
1041 if (idx >= 0) {
1042 imux->items[i].index = idx;
1043 spec->dyn_adc_idx[i] = n;
1044 break;
1045 }
1046 }
1047 }
1048
1049 snd_printdd("realtek: enabling ADC switching\n");
1050 spec->dyn_adc_switch = 1;
1051 return true;
1052}
Takashi Iwai21268962011-07-07 15:01:13 +02001053
Takashi Iwai21268962011-07-07 15:01:13 +02001054/* check whether all auto-mic pins are valid; setup indices if OK */
1055static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1056{
1057 struct alc_spec *spec = codec->spec;
1058 const struct hda_input_mux *imux;
1059
1060 if (!spec->auto_mic)
1061 return false;
1062 if (spec->auto_mic_valid_imux)
1063 return true; /* already checked */
1064
1065 /* fill up imux indices */
1066 if (!alc_check_dyn_adc_switch(codec)) {
1067 spec->auto_mic = 0;
1068 return false;
1069 }
1070
1071 imux = spec->input_mux;
1072 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1073 spec->imux_pins, imux->num_items);
1074 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1075 spec->imux_pins, imux->num_items);
1076 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1077 spec->imux_pins, imux->num_items);
1078 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1079 spec->auto_mic = 0;
1080 return false; /* no corresponding imux */
1081 }
1082
David Henningsson29adc4b2012-09-25 11:31:00 +02001083 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1084 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001085 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001086 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1087 ALC_MIC_EVENT,
1088 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001089
1090 spec->auto_mic_valid_imux = 1;
1091 spec->auto_mic = 1;
1092 return true;
1093}
1094
Takashi Iwai1d045db2011-07-07 18:23:21 +02001095/*
1096 * Check the availability of auto-mic switch;
1097 * Set up if really supported
1098 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001099static void alc_init_auto_mic(struct hda_codec *codec)
1100{
1101 struct alc_spec *spec = codec->spec;
1102 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001103 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001104 int i;
1105
Takashi Iwai24de1832011-11-07 17:13:39 +01001106 if (spec->shared_mic_hp)
1107 return; /* no auto-mic for the shared I/O */
1108
Takashi Iwai21268962011-07-07 15:01:13 +02001109 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1110
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001111 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001112 for (i = 0; i < cfg->num_inputs; i++) {
1113 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001114 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001115 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001116 switch (snd_hda_get_input_pin_attr(defcfg)) {
1117 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001118 if (fixed)
1119 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001120 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1121 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001122 fixed = nid;
1123 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001124 case INPUT_PIN_ATTR_UNUSED:
1125 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001126 case INPUT_PIN_ATTR_DOCK:
1127 if (dock)
1128 return; /* already occupied */
1129 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1130 return; /* invalid type */
1131 dock = nid;
1132 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001133 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001134 if (ext)
1135 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001136 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1137 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001138 ext = nid;
1139 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001140 }
1141 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001142 if (!ext && dock) {
1143 ext = dock;
1144 dock = 0;
1145 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001146 if (!ext || !fixed)
1147 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001148 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001149 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001150 if (dock && !is_jack_detectable(codec, dock))
1151 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001152
1153 /* check imux indices */
1154 spec->ext_mic_pin = ext;
1155 spec->int_mic_pin = fixed;
1156 spec->dock_mic_pin = dock;
1157
1158 spec->auto_mic = 1;
1159 if (!alc_auto_mic_check_imux(codec))
1160 return;
1161
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001162 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1163 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001164}
1165
Takashi Iwai1d045db2011-07-07 18:23:21 +02001166/* check the availabilities of auto-mute and auto-mic switches */
1167static void alc_auto_check_switches(struct hda_codec *codec)
1168{
David Henningsson42cf0d02011-09-20 12:04:56 +02001169 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001170 alc_init_auto_mic(codec);
1171}
1172
1173/*
1174 * Realtek SSID verification
1175 */
1176
David Henningsson90622912010-10-14 14:50:18 +02001177/* Could be any non-zero and even value. When used as fixup, tells
1178 * the driver to ignore any present sku defines.
1179 */
1180#define ALC_FIXUP_SKU_IGNORE (2)
1181
Takashi Iwai23d30f22012-05-07 17:17:32 +02001182static void alc_fixup_sku_ignore(struct hda_codec *codec,
1183 const struct hda_fixup *fix, int action)
1184{
1185 struct alc_spec *spec = codec->spec;
1186 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1187 spec->cdefine.fixup = 1;
1188 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1189 }
1190}
1191
Kailang Yangda00c242010-03-19 11:23:45 +01001192static int alc_auto_parse_customize_define(struct hda_codec *codec)
1193{
1194 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001195 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001196 struct alc_spec *spec = codec->spec;
1197
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001198 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1199
David Henningsson90622912010-10-14 14:50:18 +02001200 if (spec->cdefine.fixup) {
1201 ass = spec->cdefine.sku_cfg;
1202 if (ass == ALC_FIXUP_SKU_IGNORE)
1203 return -1;
1204 goto do_sku;
1205 }
1206
Kailang Yangda00c242010-03-19 11:23:45 +01001207 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001208 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001209 goto do_sku;
1210
1211 nid = 0x1d;
1212 if (codec->vendor_id == 0x10ec0260)
1213 nid = 0x17;
1214 ass = snd_hda_codec_get_pincfg(codec, nid);
1215
1216 if (!(ass & 1)) {
1217 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1218 codec->chip_name, ass);
1219 return -1;
1220 }
1221
1222 /* check sum */
1223 tmp = 0;
1224 for (i = 1; i < 16; i++) {
1225 if ((ass >> i) & 1)
1226 tmp++;
1227 }
1228 if (((ass >> 16) & 0xf) != tmp)
1229 return -1;
1230
1231 spec->cdefine.port_connectivity = ass >> 30;
1232 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1233 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1234 spec->cdefine.customization = ass >> 8;
1235do_sku:
1236 spec->cdefine.sku_cfg = ass;
1237 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1238 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1239 spec->cdefine.swap = (ass & 0x2) >> 1;
1240 spec->cdefine.override = ass & 0x1;
1241
1242 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1243 nid, spec->cdefine.sku_cfg);
1244 snd_printd("SKU: port_connectivity=0x%x\n",
1245 spec->cdefine.port_connectivity);
1246 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1247 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1248 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1249 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1250 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1251 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1252 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1253
1254 return 0;
1255}
1256
Takashi Iwai1d045db2011-07-07 18:23:21 +02001257/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001258static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1259{
Takashi Iwai21268962011-07-07 15:01:13 +02001260 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001261}
1262
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001263/* check subsystem ID and set up device-specific initialization;
1264 * return 1 if initialized, 0 if invalid SSID
1265 */
1266/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1267 * 31 ~ 16 : Manufacture ID
1268 * 15 ~ 8 : SKU ID
1269 * 7 ~ 0 : Assembly ID
1270 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1271 */
1272static int alc_subsystem_id(struct hda_codec *codec,
1273 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001274 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001275{
1276 unsigned int ass, tmp, i;
1277 unsigned nid;
1278 struct alc_spec *spec = codec->spec;
1279
David Henningsson90622912010-10-14 14:50:18 +02001280 if (spec->cdefine.fixup) {
1281 ass = spec->cdefine.sku_cfg;
1282 if (ass == ALC_FIXUP_SKU_IGNORE)
1283 return 0;
1284 goto do_sku;
1285 }
1286
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001287 ass = codec->subsystem_id & 0xffff;
1288 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1289 goto do_sku;
1290
1291 /* invalid SSID, check the special NID pin defcfg instead */
1292 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001293 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001294 * 29~21 : reserve
1295 * 20 : PCBEEP input
1296 * 19~16 : Check sum (15:1)
1297 * 15~1 : Custom
1298 * 0 : override
1299 */
1300 nid = 0x1d;
1301 if (codec->vendor_id == 0x10ec0260)
1302 nid = 0x17;
1303 ass = snd_hda_codec_get_pincfg(codec, nid);
1304 snd_printd("realtek: No valid SSID, "
1305 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001306 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001307 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001308 return 0;
1309 if ((ass >> 30) != 1) /* no physical connection */
1310 return 0;
1311
1312 /* check sum */
1313 tmp = 0;
1314 for (i = 1; i < 16; i++) {
1315 if ((ass >> i) & 1)
1316 tmp++;
1317 }
1318 if (((ass >> 16) & 0xf) != tmp)
1319 return 0;
1320do_sku:
1321 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1322 ass & 0xffff, codec->vendor_id);
1323 /*
1324 * 0 : override
1325 * 1 : Swap Jack
1326 * 2 : 0 --> Desktop, 1 --> Laptop
1327 * 3~5 : External Amplifier control
1328 * 7~6 : Reserved
1329 */
1330 tmp = (ass & 0x38) >> 3; /* external Amp control */
1331 switch (tmp) {
1332 case 1:
1333 spec->init_amp = ALC_INIT_GPIO1;
1334 break;
1335 case 3:
1336 spec->init_amp = ALC_INIT_GPIO2;
1337 break;
1338 case 7:
1339 spec->init_amp = ALC_INIT_GPIO3;
1340 break;
1341 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001342 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001343 spec->init_amp = ALC_INIT_DEFAULT;
1344 break;
1345 }
1346
1347 /* is laptop or Desktop and enable the function "Mute internal speaker
1348 * when the external headphone out jack is plugged"
1349 */
1350 if (!(ass & 0x8000))
1351 return 1;
1352 /*
1353 * 10~8 : Jack location
1354 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1355 * 14~13: Resvered
1356 * 15 : 1 --> enable the function "Mute internal speaker
1357 * when the external headphone out jack is plugged"
1358 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001359 if (!spec->autocfg.hp_pins[0] &&
1360 !(spec->autocfg.line_out_pins[0] &&
1361 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001362 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001363 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1364 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001365 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001366 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001367 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001368 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001369 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001370 else if (tmp == 3)
1371 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001372 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001373 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001374 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1375 spec->autocfg.line_outs))
1376 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001377 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001378 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001379 return 1;
1380}
Kailang Yangea1fb292008-08-26 12:58:38 +02001381
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001382/* Check the validity of ALC subsystem-id
1383 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1384static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001385{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001386 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001387 struct alc_spec *spec = codec->spec;
1388 snd_printd("realtek: "
1389 "Enable default setup for auto mode as fallback\n");
1390 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001391 }
Takashi Iwai21268962011-07-07 15:01:13 +02001392}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001393
Takashi Iwai41e41f12005-06-08 14:48:49 +02001394/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001395 * COEF access helper functions
1396 */
Kailang Yang274693f2009-12-03 10:07:50 +01001397static int alc_read_coef_idx(struct hda_codec *codec,
1398 unsigned int coef_idx)
1399{
1400 unsigned int val;
1401 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1402 coef_idx);
1403 val = snd_hda_codec_read(codec, 0x20, 0,
1404 AC_VERB_GET_PROC_COEF, 0);
1405 return val;
1406}
1407
Kailang Yang977ddd62010-09-15 10:02:29 +02001408static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1409 unsigned int coef_val)
1410{
1411 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1412 coef_idx);
1413 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1414 coef_val);
1415}
1416
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001417/* a special bypass for COEF 0; read the cached value at the second time */
1418static unsigned int alc_get_coef0(struct hda_codec *codec)
1419{
1420 struct alc_spec *spec = codec->spec;
1421 if (!spec->coef0)
1422 spec->coef0 = alc_read_coef_idx(codec, 0);
1423 return spec->coef0;
1424}
1425
Takashi Iwai1d045db2011-07-07 18:23:21 +02001426/*
1427 * Digital I/O handling
1428 */
1429
Takashi Iwai757899a2010-07-30 10:48:14 +02001430/* set right pin controls for digital I/O */
1431static void alc_auto_init_digital(struct hda_codec *codec)
1432{
1433 struct alc_spec *spec = codec->spec;
1434 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001435 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001436
1437 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1438 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001439 if (!pin)
1440 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001441 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001442 if (!i)
1443 dac = spec->multiout.dig_out_nid;
1444 else
1445 dac = spec->slave_dig_outs[i - 1];
1446 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1447 continue;
1448 snd_hda_codec_write(codec, dac, 0,
1449 AC_VERB_SET_AMP_GAIN_MUTE,
1450 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001451 }
1452 pin = spec->autocfg.dig_in_pin;
1453 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001454 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001455}
1456
1457/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1458static void alc_auto_parse_digital(struct hda_codec *codec)
1459{
1460 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001461 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001462 hda_nid_t dig_nid;
1463
1464 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001465 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001466 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001467 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001468 err = snd_hda_get_connections(codec,
1469 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001470 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001471 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001472 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001473 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001474 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001475 spec->multiout.dig_out_nid = dig_nid;
1476 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1477 } else {
1478 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001479 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001480 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001481 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001482 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001483 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001484 }
1485
1486 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001487 dig_nid = codec->start_nid;
1488 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1489 unsigned int wcaps = get_wcaps(codec, dig_nid);
1490 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1491 continue;
1492 if (!(wcaps & AC_WCAP_DIGITAL))
1493 continue;
1494 if (!(wcaps & AC_WCAP_CONN_LIST))
1495 continue;
1496 err = get_connection_index(codec, dig_nid,
1497 spec->autocfg.dig_in_pin);
1498 if (err >= 0) {
1499 spec->dig_in_nid = dig_nid;
1500 break;
1501 }
1502 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001503 }
1504}
1505
Takashi Iwaif95474e2007-07-10 00:47:43 +02001506/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001507 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001508 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001509static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1510 struct snd_ctl_elem_info *uinfo)
1511{
1512 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1513 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001514 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001515 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001516
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001517 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001518 if (spec->vol_in_capsrc)
1519 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1520 else
1521 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1522 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001523 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001524 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001525 return err;
1526}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001528static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1529 unsigned int size, unsigned int __user *tlv)
1530{
1531 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1532 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001533 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001534 int err;
1535
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001536 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001537 if (spec->vol_in_capsrc)
1538 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1539 else
1540 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1541 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001542 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001543 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001544 return err;
1545}
1546
1547typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1548 struct snd_ctl_elem_value *ucontrol);
1549
1550static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1551 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001552 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001553{
1554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1555 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001556 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001557
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001558 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001559 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001560 for (i = 0; i < spec->num_adc_nids; i++) {
1561 kcontrol->private_value =
1562 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1563 3, 0, HDA_INPUT);
1564 err = func(kcontrol, ucontrol);
1565 if (err < 0)
1566 goto error;
1567 }
1568 } else {
1569 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001570 if (spec->vol_in_capsrc)
1571 kcontrol->private_value =
1572 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1573 3, 0, HDA_OUTPUT);
1574 else
1575 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001576 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1577 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001578 err = func(kcontrol, ucontrol);
1579 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001580 if (err >= 0 && is_put)
1581 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001582 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001583 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001584 return err;
1585}
1586
1587static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1588 struct snd_ctl_elem_value *ucontrol)
1589{
1590 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001591 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001592}
1593
1594static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1595 struct snd_ctl_elem_value *ucontrol)
1596{
1597 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001598 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001599}
1600
1601/* capture mixer elements */
1602#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1603
1604static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1605 struct snd_ctl_elem_value *ucontrol)
1606{
1607 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001608 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001609}
1610
1611static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1612 struct snd_ctl_elem_value *ucontrol)
1613{
1614 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001615 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001616}
1617
Takashi Iwaia23b6882009-03-23 15:21:36 +01001618#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001619 { \
1620 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1621 .name = "Capture Switch", \
1622 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1623 .count = num, \
1624 .info = alc_cap_sw_info, \
1625 .get = alc_cap_sw_get, \
1626 .put = alc_cap_sw_put, \
1627 }, \
1628 { \
1629 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1630 .name = "Capture Volume", \
1631 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1632 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1633 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1634 .count = num, \
1635 .info = alc_cap_vol_info, \
1636 .get = alc_cap_vol_get, \
1637 .put = alc_cap_vol_put, \
1638 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001639 }
1640
1641#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001642 { \
1643 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1644 /* .name = "Capture Source", */ \
1645 .name = "Input Source", \
1646 .count = num, \
1647 .info = alc_mux_enum_info, \
1648 .get = alc_mux_enum_get, \
1649 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001650 }
1651
1652#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001653static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001654 _DEFINE_CAPMIX(num), \
1655 _DEFINE_CAPSRC(num), \
1656 { } /* end */ \
1657}
1658
1659#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001660static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001661 _DEFINE_CAPMIX(num), \
1662 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001663}
1664
1665/* up to three ADCs */
1666DEFINE_CAPMIX(1);
1667DEFINE_CAPMIX(2);
1668DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001669DEFINE_CAPMIX_NOSRC(1);
1670DEFINE_CAPMIX_NOSRC(2);
1671DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001672
1673/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001674 * Inverted digital-mic handling
1675 *
1676 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1677 * gives the additional mute only to the right channel of the digital mic
1678 * capture stream. This is a workaround for avoiding the almost silence
1679 * by summing the stereo stream from some (known to be ForteMedia)
1680 * digital mic unit.
1681 *
1682 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1683 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1684 * without caching so that the cache can still keep the original value.
1685 * The cached value is then restored when the flag is set off or any other
1686 * than d-mic is used as the current input source.
1687 */
1688static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1689{
1690 struct alc_spec *spec = codec->spec;
1691 int i;
1692
1693 if (!spec->inv_dmic_fixup)
1694 return;
1695 if (!spec->inv_dmic_muted && !force)
1696 return;
1697 for (i = 0; i < spec->num_adc_nids; i++) {
1698 int src = spec->dyn_adc_switch ? 0 : i;
1699 bool dmic_fixup = false;
1700 hda_nid_t nid;
1701 int parm, dir, v;
1702
1703 if (spec->inv_dmic_muted &&
1704 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1705 dmic_fixup = true;
1706 if (!dmic_fixup && !force)
1707 continue;
1708 if (spec->vol_in_capsrc) {
1709 nid = spec->capsrc_nids[i];
1710 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1711 dir = HDA_OUTPUT;
1712 } else {
1713 nid = spec->adc_nids[i];
1714 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1715 dir = HDA_INPUT;
1716 }
1717 /* we care only right channel */
1718 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1719 if (v & 0x80) /* if already muted, we don't need to touch */
1720 continue;
1721 if (dmic_fixup) /* add mute for d-mic */
1722 v |= 0x80;
1723 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1724 parm | v);
1725 }
1726}
1727
1728static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1729 struct snd_ctl_elem_value *ucontrol)
1730{
1731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1732 struct alc_spec *spec = codec->spec;
1733
1734 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1735 return 0;
1736}
1737
1738static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1739 struct snd_ctl_elem_value *ucontrol)
1740{
1741 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1742 struct alc_spec *spec = codec->spec;
1743 unsigned int val = !ucontrol->value.integer.value[0];
1744
1745 if (val == spec->inv_dmic_muted)
1746 return 0;
1747 spec->inv_dmic_muted = val;
1748 alc_inv_dmic_sync(codec, true);
1749 return 0;
1750}
1751
1752static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1753 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1754 .info = snd_ctl_boolean_mono_info,
1755 .get = alc_inv_dmic_sw_get,
1756 .put = alc_inv_dmic_sw_put,
1757};
1758
1759static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1760{
1761 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001762
1763 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1764 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001765 return -ENOMEM;
1766 spec->inv_dmic_fixup = 1;
1767 spec->inv_dmic_muted = 0;
1768 spec->inv_dmic_pin = nid;
1769 return 0;
1770}
1771
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001772/* typically the digital mic is put at node 0x12 */
1773static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1774 const struct alc_fixup *fix, int action)
1775{
1776 if (action == ALC_FIXUP_ACT_PROBE)
1777 alc_add_inv_dmic_mixer(codec, 0x12);
1778}
1779
Takashi Iwai125821a2012-06-22 14:30:29 +02001780/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001781 * virtual master controls
1782 */
1783
1784/*
1785 * slave controls for virtual master
1786 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001787static const char * const alc_slave_pfxs[] = {
1788 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001789 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001790 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001791 NULL,
1792};
1793
1794/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001795 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001797
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001798#define NID_MAPPING (-1)
1799
1800#define SUBDEV_SPEAKER_ (0 << 6)
1801#define SUBDEV_HP_ (1 << 6)
1802#define SUBDEV_LINE_ (2 << 6)
1803#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1804#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1805#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1806
Takashi Iwai603c4012008-07-30 15:01:44 +02001807static void alc_free_kctls(struct hda_codec *codec);
1808
Takashi Iwai67d634c2009-11-16 15:35:59 +01001809#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001810/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001811static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001812 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001813 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001814 { } /* end */
1815};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001816#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001817
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001818static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
1820 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001821 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001822 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001823 int i, j, err;
1824 unsigned int u;
1825 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
1827 for (i = 0; i < spec->num_mixers; i++) {
1828 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1829 if (err < 0)
1830 return err;
1831 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001832 if (spec->cap_mixer) {
1833 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1834 if (err < 0)
1835 return err;
1836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001838 err = snd_hda_create_dig_out_ctls(codec,
1839 spec->multiout.dig_out_nid,
1840 spec->multiout.dig_out_nid,
1841 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 if (err < 0)
1843 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001844 if (!spec->no_analog) {
1845 err = snd_hda_create_spdif_share_sw(codec,
1846 &spec->multiout);
1847 if (err < 0)
1848 return err;
1849 spec->multiout.share_spdif = 1;
1850 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 }
1852 if (spec->dig_in_nid) {
1853 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1854 if (err < 0)
1855 return err;
1856 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001857
Takashi Iwai67d634c2009-11-16 15:35:59 +01001858#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001859 /* create beep controls if needed */
1860 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001861 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001862 for (knew = alc_beep_mixer; knew->name; knew++) {
1863 struct snd_kcontrol *kctl;
1864 kctl = snd_ctl_new1(knew, codec);
1865 if (!kctl)
1866 return -ENOMEM;
1867 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001868 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001869 if (err < 0)
1870 return err;
1871 }
1872 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001873#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001874
Takashi Iwai2134ea42008-01-10 16:53:55 +01001875 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001876 if (!spec->no_analog &&
1877 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001878 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001879 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001880 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001881 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001882 vmaster_tlv, alc_slave_pfxs,
1883 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001884 if (err < 0)
1885 return err;
1886 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001887 if (!spec->no_analog &&
1888 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001889 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1890 NULL, alc_slave_pfxs,
1891 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001892 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001893 if (err < 0)
1894 return err;
1895 }
1896
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001897 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001898 if (spec->capsrc_nids || spec->adc_nids) {
1899 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1900 if (!kctl)
1901 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1902 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001903 err = snd_hda_add_nid(codec, kctl, i,
1904 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001905 if (err < 0)
1906 return err;
1907 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001908 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001909 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001910 const char *kname = kctl ? kctl->id.name : NULL;
1911 for (knew = spec->cap_mixer; knew->name; knew++) {
1912 if (kname && strcmp(knew->name, kname) == 0)
1913 continue;
1914 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1915 for (i = 0; kctl && i < kctl->count; i++) {
1916 err = snd_hda_add_nid(codec, kctl, i,
1917 spec->adc_nids[i]);
1918 if (err < 0)
1919 return err;
1920 }
1921 }
1922 }
1923
1924 /* other nid->control mapping */
1925 for (i = 0; i < spec->num_mixers; i++) {
1926 for (knew = spec->mixers[i]; knew->name; knew++) {
1927 if (knew->iface != NID_MAPPING)
1928 continue;
1929 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1930 if (kctl == NULL)
1931 continue;
1932 u = knew->subdevice;
1933 for (j = 0; j < 4; j++, u >>= 8) {
1934 nid = u & 0x3f;
1935 if (nid == 0)
1936 continue;
1937 switch (u & 0xc0) {
1938 case SUBDEV_SPEAKER_:
1939 nid = spec->autocfg.speaker_pins[nid];
1940 break;
1941 case SUBDEV_LINE_:
1942 nid = spec->autocfg.line_out_pins[nid];
1943 break;
1944 case SUBDEV_HP_:
1945 nid = spec->autocfg.hp_pins[nid];
1946 break;
1947 default:
1948 continue;
1949 }
1950 err = snd_hda_add_nid(codec, kctl, 0, nid);
1951 if (err < 0)
1952 return err;
1953 }
1954 u = knew->private_value;
1955 for (j = 0; j < 4; j++, u >>= 8) {
1956 nid = u & 0xff;
1957 if (nid == 0)
1958 continue;
1959 err = snd_hda_add_nid(codec, kctl, 0, nid);
1960 if (err < 0)
1961 return err;
1962 }
1963 }
1964 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001965
1966 alc_free_kctls(codec); /* no longer needed */
1967
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001968 return 0;
1969}
1970
David Henningsson5780b622012-06-27 18:45:45 +02001971static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001972{
1973 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001974
1975 if (spec->shared_mic_hp) {
1976 int err;
1977 int nid = spec->autocfg.inputs[1].pin;
1978 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1979 if (err < 0)
1980 return err;
1981 err = snd_hda_jack_detect_enable(codec, nid, 0);
1982 if (err < 0)
1983 return err;
1984 }
1985
1986 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1987}
1988
1989static int alc_build_controls(struct hda_codec *codec)
1990{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001991 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001992 if (err < 0)
1993 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001994
1995 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001996 if (err < 0)
1997 return err;
1998 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1999 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000}
2001
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002002
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002004 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002005 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002006
Takashi Iwai584c0c42011-03-10 12:51:11 +01002007static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002008static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002009
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010static int alc_init(struct hda_codec *codec)
2011{
2012 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002013
Takashi Iwai546bb672012-03-07 08:37:19 +01002014 if (spec->init_hook)
2015 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002016
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002017 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002018 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002019
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002020 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002021 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002022 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002023
Takashi Iwai58701122011-01-13 15:41:45 +01002024 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2025
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002026 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 return 0;
2028}
2029
Takashi Iwai83012a72012-08-24 18:38:08 +02002030#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002031static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2032{
2033 struct alc_spec *spec = codec->spec;
2034 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2035}
2036#endif
2037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038/*
2039 * Analog playback callbacks
2040 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002041static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002043 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044{
2045 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002046 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2047 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048}
2049
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002050static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 struct hda_codec *codec,
2052 unsigned int stream_tag,
2053 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002054 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055{
2056 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002057 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2058 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059}
2060
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002061static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002063 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064{
2065 struct alc_spec *spec = codec->spec;
2066 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2067}
2068
2069/*
2070 * Digital out
2071 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002072static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002074 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
2076 struct alc_spec *spec = codec->spec;
2077 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2078}
2079
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002080static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002081 struct hda_codec *codec,
2082 unsigned int stream_tag,
2083 unsigned int format,
2084 struct snd_pcm_substream *substream)
2085{
2086 struct alc_spec *spec = codec->spec;
2087 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2088 stream_tag, format, substream);
2089}
2090
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002091static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002092 struct hda_codec *codec,
2093 struct snd_pcm_substream *substream)
2094{
2095 struct alc_spec *spec = codec->spec;
2096 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2097}
2098
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002099static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002101 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
2103 struct alc_spec *spec = codec->spec;
2104 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2105}
2106
2107/*
2108 * Analog capture
2109 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002110static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 struct hda_codec *codec,
2112 unsigned int stream_tag,
2113 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002114 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115{
2116 struct alc_spec *spec = codec->spec;
2117
Takashi Iwai63300792008-01-24 15:31:36 +01002118 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 stream_tag, 0, format);
2120 return 0;
2121}
2122
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002123static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002125 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
2127 struct alc_spec *spec = codec->spec;
2128
Takashi Iwai888afa12008-03-18 09:57:50 +01002129 snd_hda_codec_cleanup_stream(codec,
2130 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 return 0;
2132}
2133
Takashi Iwai840b64c2010-07-13 22:49:01 +02002134/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002135static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002136 struct hda_codec *codec,
2137 unsigned int stream_tag,
2138 unsigned int format,
2139 struct snd_pcm_substream *substream)
2140{
2141 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002142 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002143 spec->cur_adc_stream_tag = stream_tag;
2144 spec->cur_adc_format = format;
2145 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2146 return 0;
2147}
2148
Takashi Iwai21268962011-07-07 15:01:13 +02002149static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002150 struct hda_codec *codec,
2151 struct snd_pcm_substream *substream)
2152{
2153 struct alc_spec *spec = codec->spec;
2154 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2155 spec->cur_adc = 0;
2156 return 0;
2157}
2158
Takashi Iwai21268962011-07-07 15:01:13 +02002159static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002160 .substreams = 1,
2161 .channels_min = 2,
2162 .channels_max = 2,
2163 .nid = 0, /* fill later */
2164 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002165 .prepare = dyn_adc_capture_pcm_prepare,
2166 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002167 },
2168};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170/*
2171 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002172static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 .substreams = 1,
2174 .channels_min = 2,
2175 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002176 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002178 .open = alc_playback_pcm_open,
2179 .prepare = alc_playback_pcm_prepare,
2180 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 },
2182};
2183
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002184static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002185 .substreams = 1,
2186 .channels_min = 2,
2187 .channels_max = 2,
2188 /* NID is set in alc_build_pcms */
2189};
2190
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002191static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002192 .substreams = 1,
2193 .channels_min = 2,
2194 .channels_max = 2,
2195 /* NID is set in alc_build_pcms */
2196};
2197
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002198static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002199 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 .channels_min = 2,
2201 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002202 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002204 .prepare = alc_alt_capture_pcm_prepare,
2205 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 },
2207};
2208
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002209static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 .substreams = 1,
2211 .channels_min = 2,
2212 .channels_max = 2,
2213 /* NID is set in alc_build_pcms */
2214 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002215 .open = alc_dig_playback_pcm_open,
2216 .close = alc_dig_playback_pcm_close,
2217 .prepare = alc_dig_playback_pcm_prepare,
2218 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 },
2220};
2221
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002222static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 .substreams = 1,
2224 .channels_min = 2,
2225 .channels_max = 2,
2226 /* NID is set in alc_build_pcms */
2227};
2228
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002229/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002230static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002231 .substreams = 0,
2232 .channels_min = 0,
2233 .channels_max = 0,
2234};
2235
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236static int alc_build_pcms(struct hda_codec *codec)
2237{
2238 struct alc_spec *spec = codec->spec;
2239 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002240 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002241 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 int i;
2243
2244 codec->num_pcms = 1;
2245 codec->pcm_info = info;
2246
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002247 if (spec->no_analog)
2248 goto skip_analog;
2249
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002250 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2251 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002253
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002254 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002255 p = spec->stream_analog_playback;
2256 if (!p)
2257 p = &alc_pcm_analog_playback;
2258 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002259 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002260 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2261 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002262 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2263 spec->autocfg.line_outs == 2)
2264 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2265 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002266 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002267 if (spec->adc_nids) {
2268 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002269 if (!p) {
2270 if (spec->dyn_adc_switch)
2271 p = &dyn_adc_pcm_analog_capture;
2272 else
2273 p = &alc_pcm_analog_capture;
2274 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002275 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002276 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
Takashi Iwai4a471b72005-12-07 13:56:29 +01002279 if (spec->channel_mode) {
2280 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2281 for (i = 0; i < spec->num_channel_mode; i++) {
2282 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2283 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 }
2286 }
2287
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002288 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002289 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002291 snprintf(spec->stream_name_digital,
2292 sizeof(spec->stream_name_digital),
2293 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002294 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002295 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002296 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002298 if (spec->dig_out_type)
2299 info->pcm_type = spec->dig_out_type;
2300 else
2301 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002302 if (spec->multiout.dig_out_nid) {
2303 p = spec->stream_digital_playback;
2304 if (!p)
2305 p = &alc_pcm_digital_playback;
2306 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2308 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002309 if (spec->dig_in_nid) {
2310 p = spec->stream_digital_capture;
2311 if (!p)
2312 p = &alc_pcm_digital_capture;
2313 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2315 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002316 /* FIXME: do we need this for all Realtek codec models? */
2317 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 }
2319
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002320 if (spec->no_analog)
2321 return 0;
2322
Takashi Iwaie08a0072006-09-07 17:52:14 +02002323 /* If the use of more than one ADC is requested for the current
2324 * model, configure a second analog capture-only PCM.
2325 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002326 have_multi_adcs = (spec->num_adc_nids > 1) &&
2327 !spec->dyn_adc_switch && !spec->auto_mic &&
2328 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002329 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002330 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002331 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002332 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002333 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002334 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002335 p = spec->stream_analog_alt_playback;
2336 if (!p)
2337 p = &alc_pcm_analog_alt_playback;
2338 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002339 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2340 spec->alt_dac_nid;
2341 } else {
2342 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2343 alc_pcm_null_stream;
2344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2345 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002346 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002347 p = spec->stream_analog_alt_capture;
2348 if (!p)
2349 p = &alc_pcm_analog_alt_capture;
2350 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002351 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2352 spec->adc_nids[1];
2353 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2354 spec->num_adc_nids - 1;
2355 } else {
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2357 alc_pcm_null_stream;
2358 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002359 }
2360 }
2361
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 return 0;
2363}
2364
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002365static inline void alc_shutup(struct hda_codec *codec)
2366{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002367 struct alc_spec *spec = codec->spec;
2368
2369 if (spec && spec->shutup)
2370 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002371 snd_hda_shutup_pins(codec);
2372}
2373
Takashi Iwai603c4012008-07-30 15:01:44 +02002374static void alc_free_kctls(struct hda_codec *codec)
2375{
2376 struct alc_spec *spec = codec->spec;
2377
2378 if (spec->kctls.list) {
2379 struct snd_kcontrol_new *kctl = spec->kctls.list;
2380 int i;
2381 for (i = 0; i < spec->kctls.used; i++)
2382 kfree(kctl[i].name);
2383 }
2384 snd_array_free(&spec->kctls);
2385}
2386
Takashi Iwai23c09b02011-08-19 09:05:35 +02002387static void alc_free_bind_ctls(struct hda_codec *codec)
2388{
2389 struct alc_spec *spec = codec->spec;
2390 if (spec->bind_ctls.list) {
2391 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2392 int i;
2393 for (i = 0; i < spec->bind_ctls.used; i++)
2394 kfree(ctl[i]);
2395 }
2396 snd_array_free(&spec->bind_ctls);
2397}
2398
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399static void alc_free(struct hda_codec *codec)
2400{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002401 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002402
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002403 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002404 return;
2405
Takashi Iwai603c4012008-07-30 15:01:44 +02002406 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002407 alc_free_bind_ctls(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002408 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002409 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002410 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
Takashi Iwai83012a72012-08-24 18:38:08 +02002413#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002414static void alc_power_eapd(struct hda_codec *codec)
2415{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002416 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002417}
2418
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002419static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002420{
2421 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002422 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002423 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002424 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002425 return 0;
2426}
2427#endif
2428
Takashi Iwai2a439522011-07-26 09:52:50 +02002429#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002430static int alc_resume(struct hda_codec *codec)
2431{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002432 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002433 codec->patch_ops.init(codec);
2434 snd_hda_codec_resume_amp(codec);
2435 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002436 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002437 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002438 return 0;
2439}
Takashi Iwaie044c392008-10-27 16:56:24 +01002440#endif
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442/*
2443 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002444static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 .build_controls = alc_build_controls,
2446 .build_pcms = alc_build_pcms,
2447 .init = alc_init,
2448 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002449 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002450#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002451 .resume = alc_resume,
2452#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002453#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002454 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002455 .check_power_status = alc_check_power_status,
2456#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002457 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458};
2459
David Henningsson29adc4b2012-09-25 11:31:00 +02002460
Kailang Yangc027ddc2010-03-19 11:33:06 +01002461/* replace the codec chip_name with the given string */
2462static int alc_codec_rename(struct hda_codec *codec, const char *name)
2463{
2464 kfree(codec->chip_name);
2465 codec->chip_name = kstrdup(name, GFP_KERNEL);
2466 if (!codec->chip_name) {
2467 alc_free(codec);
2468 return -ENOMEM;
2469 }
2470 return 0;
2471}
2472
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002473/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002474 * Rename codecs appropriately from COEF value
2475 */
2476struct alc_codec_rename_table {
2477 unsigned int vendor_id;
2478 unsigned short coef_mask;
2479 unsigned short coef_bits;
2480 const char *name;
2481};
2482
2483static struct alc_codec_rename_table rename_tbl[] = {
2484 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2485 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2486 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2487 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2488 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2489 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2490 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002491 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002492 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2493 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2494 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2495 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2496 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2497 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2498 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2499 { } /* terminator */
2500};
2501
2502static int alc_codec_rename_from_preset(struct hda_codec *codec)
2503{
2504 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002505
2506 for (p = rename_tbl; p->vendor_id; p++) {
2507 if (p->vendor_id != codec->vendor_id)
2508 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002509 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002510 return alc_codec_rename(codec, p->name);
2511 }
2512 return 0;
2513}
2514
2515/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002516 * Automatic parse of I/O pins from the BIOS configuration
2517 */
2518
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002519enum {
2520 ALC_CTL_WIDGET_VOL,
2521 ALC_CTL_WIDGET_MUTE,
2522 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002523 ALC_CTL_BIND_VOL,
2524 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002525};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002526static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002527 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2528 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002529 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002530 HDA_BIND_VOL(NULL, 0),
2531 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002532};
2533
2534/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002535static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002536 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002537{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002538 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002539
Takashi Iwai668d1e92012-11-29 14:10:17 +01002540 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002541 if (!knew)
2542 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002543 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002544 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002545 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002546 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002547 return 0;
2548}
2549
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002550static int add_control_with_pfx(struct alc_spec *spec, int type,
2551 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002552 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002553{
2554 char name[32];
2555 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002556 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002557}
2558
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002559#define add_pb_vol_ctrl(spec, type, pfx, val) \
2560 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2561#define add_pb_sw_ctrl(spec, type, pfx, val) \
2562 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2563#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2564 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2565#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2566 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002567
Takashi Iwai23c09b02011-08-19 09:05:35 +02002568static const char * const channel_name[4] = {
2569 "Front", "Surround", "CLFE", "Side"
2570};
2571
Takashi Iwai6843ca12011-06-24 11:03:58 +02002572static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2573 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002574{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002575 struct auto_pin_cfg *cfg = &spec->autocfg;
2576
Takashi Iwai6843ca12011-06-24 11:03:58 +02002577 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002578 if (cfg->line_outs == 1 && !spec->multi_ios &&
2579 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002580 return "Master";
2581
2582 switch (cfg->line_out_type) {
2583 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002584 if (cfg->line_outs == 1)
2585 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002586 if (cfg->line_outs == 2)
2587 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002588 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002589 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002590 /* for multi-io case, only the primary out */
2591 if (ch && spec->multi_ios)
2592 break;
2593 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002594 return "Headphone";
2595 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002596 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002597 return "PCM";
2598 break;
2599 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002600 if (ch >= ARRAY_SIZE(channel_name)) {
2601 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002602 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002603 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002604
2605 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002606}
2607
Takashi Iwai83012a72012-08-24 18:38:08 +02002608#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002609/* add the powersave loopback-list entry */
2610static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2611{
2612 struct hda_amp_list *list;
2613
2614 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2615 return;
2616 list = spec->loopback_list + spec->num_loopbacks;
2617 list->nid = mix;
2618 list->dir = HDA_INPUT;
2619 list->idx = idx;
2620 spec->num_loopbacks++;
2621 spec->loopback.amplist = spec->loopback_list;
2622}
2623#else
2624#define add_loopback_list(spec, mix, idx) /* NOP */
2625#endif
2626
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002627/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002628static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002629 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002630 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002631{
Kailang Yangdf694da2005-12-05 19:42:22 +01002632 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002633
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002634 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002635 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2636 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002637 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002638 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002639 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2640 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002641 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002642 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002643 return 0;
2644}
2645
Takashi Iwai05f5f472009-08-25 13:10:18 +02002646static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002647{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002648 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2649 return (pincap & AC_PINCAP_IN) != 0;
2650}
2651
Takashi Iwai1d045db2011-07-07 18:23:21 +02002652/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002653static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002654{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002655 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002656 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002657 hda_nid_t *adc_nids = spec->private_adc_nids;
2658 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2659 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002660 int i, nums = 0;
2661
2662 nid = codec->start_nid;
2663 for (i = 0; i < codec->num_nodes; i++, nid++) {
2664 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002665 unsigned int caps = get_wcaps(codec, nid);
2666 int type = get_wcaps_type(caps);
2667
2668 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2669 continue;
2670 adc_nids[nums] = nid;
2671 cap_nids[nums] = nid;
2672 src = nid;
2673 for (;;) {
2674 int n;
2675 type = get_wcaps_type(get_wcaps(codec, src));
2676 if (type == AC_WID_PIN)
2677 break;
2678 if (type == AC_WID_AUD_SEL) {
2679 cap_nids[nums] = src;
2680 break;
2681 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002682 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002683 if (n > 1) {
2684 cap_nids[nums] = src;
2685 break;
2686 } else if (n != 1)
2687 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002688 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2689 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002690 }
2691 if (++nums >= max_nums)
2692 break;
2693 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002694 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002695 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002696 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002697 return nums;
2698}
2699
Takashi Iwai05f5f472009-08-25 13:10:18 +02002700/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002701static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002702{
2703 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002704 const struct auto_pin_cfg *cfg = &spec->autocfg;
2705 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002706 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002707 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002708 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002709 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002710
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002711 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002712 if (num_adcs < 0)
2713 return 0;
2714
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002715 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002716 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002717 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002718
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002719 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002720 if (!alc_is_input_pin(codec, pin))
2721 continue;
2722
David Henningsson5322bf22011-01-05 11:03:56 +01002723 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002724 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2725 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002726 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002727 type_idx++;
2728 else
2729 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002730 prev_label = label;
2731
Takashi Iwai05f5f472009-08-25 13:10:18 +02002732 if (mixer) {
2733 idx = get_connection_index(codec, mixer, pin);
2734 if (idx >= 0) {
2735 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002736 label, type_idx,
2737 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002738 if (err < 0)
2739 return err;
2740 }
2741 }
2742
Takashi Iwaib7821702011-07-06 15:12:46 +02002743 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002744 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002745 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002746 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002747 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002748 snd_hda_add_imux_item(imux, label, idx, NULL);
2749 break;
2750 }
2751 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002752 }
Takashi Iwai21268962011-07-07 15:01:13 +02002753
2754 spec->num_mux_defs = 1;
2755 spec->input_mux = imux;
2756
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002757 return 0;
2758}
2759
Takashi Iwai24de1832011-11-07 17:13:39 +01002760/* create a shared input with the headphone out */
2761static int alc_auto_create_shared_input(struct hda_codec *codec)
2762{
2763 struct alc_spec *spec = codec->spec;
2764 struct auto_pin_cfg *cfg = &spec->autocfg;
2765 unsigned int defcfg;
2766 hda_nid_t nid;
2767
2768 /* only one internal input pin? */
2769 if (cfg->num_inputs != 1)
2770 return 0;
2771 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2772 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2773 return 0;
2774
2775 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2776 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2777 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2778 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2779 else
2780 return 0; /* both not available */
2781
2782 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2783 return 0; /* no input */
2784
2785 cfg->inputs[1].pin = nid;
2786 cfg->inputs[1].type = AUTO_PIN_MIC;
2787 cfg->num_inputs = 2;
2788 spec->shared_mic_hp = 1;
2789 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2790 return 0;
2791}
2792
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002793static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2794 unsigned int pin_type)
2795{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002796 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002797 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002798 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2799 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002800 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002801}
2802
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002803static int get_pin_type(int line_out_type)
2804{
2805 if (line_out_type == AUTO_PIN_HP_OUT)
2806 return PIN_HP;
2807 else
2808 return PIN_OUT;
2809}
2810
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002811static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002812{
2813 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002814 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002815 int i;
2816
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002817 for (i = 0; i < cfg->num_inputs; i++) {
2818 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002819 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002820 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002821 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002822 snd_hda_codec_write(codec, nid, 0,
2823 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002824 AMP_OUT_MUTE);
2825 }
2826 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002827
2828 /* mute all loopback inputs */
2829 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002830 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002831 for (i = 0; i < nums; i++)
2832 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2833 AC_VERB_SET_AMP_GAIN_MUTE,
2834 AMP_IN_MUTE(i));
2835 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002836}
2837
Takashi Iwai7085ec12009-10-02 09:03:58 +02002838/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002839static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002840{
Takashi Iwai604401a2011-04-27 15:14:23 +02002841 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002842 int i, num;
2843
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002844 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2845 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002846 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2847 for (i = 0; i < num; i++) {
2848 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2849 return list[i];
2850 }
2851 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002852}
2853
Takashi Iwai604401a2011-04-27 15:14:23 +02002854/* go down to the selector widget before the mixer */
2855static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2856{
2857 hda_nid_t srcs[5];
2858 int num = snd_hda_get_connections(codec, pin, srcs,
2859 ARRAY_SIZE(srcs));
2860 if (num != 1 ||
2861 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2862 return pin;
2863 return srcs[0];
2864}
2865
Takashi Iwai7085ec12009-10-02 09:03:58 +02002866/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002867static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002868 hda_nid_t dac)
2869{
David Henningssoncc1c4522010-11-24 14:17:47 +01002870 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002871 int i, num;
2872
Takashi Iwai604401a2011-04-27 15:14:23 +02002873 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002874 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2875 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002876 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002877 return mix[i];
2878 }
2879 return 0;
2880}
2881
Takashi Iwaice764ab2011-04-27 16:35:23 +02002882/* select the connection from pin to DAC if needed */
2883static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2884 hda_nid_t dac)
2885{
2886 hda_nid_t mix[5];
2887 int i, num;
2888
2889 pin = alc_go_down_to_selector(codec, pin);
2890 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2891 if (num < 2)
2892 return 0;
2893 for (i = 0; i < num; i++) {
2894 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2895 snd_hda_codec_update_cache(codec, pin, 0,
2896 AC_VERB_SET_CONNECT_SEL, i);
2897 return 0;
2898 }
2899 }
2900 return 0;
2901}
2902
Takashi Iwai185d99f2012-02-16 18:39:45 +01002903static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2904{
2905 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002906 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002907 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2908 ARRAY_SIZE(spec->private_dac_nids)) ||
2909 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2910 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2911 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2912 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2913 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002914 for (i = 0; i < spec->multi_ios; i++) {
2915 if (spec->multi_io[i].dac == nid)
2916 return true;
2917 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002918 return false;
2919}
2920
Takashi Iwai7085ec12009-10-02 09:03:58 +02002921/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002922static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002923{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002924 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002925 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002926
Takashi Iwai604401a2011-04-27 15:14:23 +02002927 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002928 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002929 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002930 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002931 if (!nid)
2932 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002933 if (!alc_is_dac_already_used(codec, nid))
2934 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002935 }
2936 return 0;
2937}
2938
Takashi Iwai07b18f62011-11-10 15:42:54 +01002939/* check whether the DAC is reachable from the pin */
2940static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2941 hda_nid_t pin, hda_nid_t dac)
2942{
2943 hda_nid_t srcs[5];
2944 int i, num;
2945
Takashi Iwaidc31b582012-02-17 17:27:53 +01002946 if (!pin || !dac)
2947 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002948 pin = alc_go_down_to_selector(codec, pin);
2949 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2950 for (i = 0; i < num; i++) {
2951 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2952 if (nid == dac)
2953 return true;
2954 }
2955 return false;
2956}
2957
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002958static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2959{
Takashi Iwai140547e2012-02-16 17:23:46 +01002960 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002961 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002962 hda_nid_t nid, nid_found, srcs[5];
2963 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01002964 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01002965 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002966 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002967 nid_found = 0;
2968 for (i = 0; i < num; i++) {
2969 if (srcs[i] == spec->mixer_nid)
2970 continue;
2971 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2972 if (nid && !alc_is_dac_already_used(codec, nid)) {
2973 if (nid_found)
2974 return 0;
2975 nid_found = nid;
2976 }
2977 }
2978 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002979}
2980
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002981/* mark up volume and mute control NIDs: used during badness parsing and
2982 * at creating actual controls
2983 */
2984static inline unsigned int get_ctl_pos(unsigned int data)
2985{
2986 hda_nid_t nid = get_amp_nid_(data);
2987 unsigned int dir;
2988 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
2989 return 0;
2990 dir = get_amp_direction_(data);
2991 return (nid << 1) | dir;
2992}
2993
2994#define is_ctl_used(bits, data) \
2995 test_bit(get_ctl_pos(data), bits)
2996#define mark_ctl_usage(bits, data) \
2997 set_bit(get_ctl_pos(data), bits)
2998
2999static void clear_vol_marks(struct hda_codec *codec)
3000{
3001 struct alc_spec *spec = codec->spec;
3002 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3003 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3004}
3005
3006/* badness definition */
3007enum {
3008 /* No primary DAC is found for the main output */
3009 BAD_NO_PRIMARY_DAC = 0x10000,
3010 /* No DAC is found for the extra output */
3011 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003012 /* No possible multi-ios */
3013 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003014 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003015 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003016 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003017 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003018 /* Primary DAC shared with main surrounds */
3019 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003020 /* Primary DAC shared with main CLFE */
3021 BAD_SHARED_CLFE = 0x10,
3022 /* Primary DAC shared with extra surrounds */
3023 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003024 /* Volume widget is shared */
3025 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003026};
3027
3028static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3029 hda_nid_t pin, hda_nid_t dac);
3030static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3031 hda_nid_t pin, hda_nid_t dac);
3032
3033static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3034 hda_nid_t dac)
3035{
3036 struct alc_spec *spec = codec->spec;
3037 hda_nid_t nid;
3038 unsigned int val;
3039 int badness = 0;
3040
3041 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3042 if (nid) {
3043 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3044 if (is_ctl_used(spec->vol_ctls, nid))
3045 badness += BAD_SHARED_VOL;
3046 else
3047 mark_ctl_usage(spec->vol_ctls, val);
3048 } else
3049 badness += BAD_SHARED_VOL;
3050 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3051 if (nid) {
3052 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3053 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3054 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3055 else
3056 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3057 if (is_ctl_used(spec->sw_ctls, val))
3058 badness += BAD_SHARED_VOL;
3059 else
3060 mark_ctl_usage(spec->sw_ctls, val);
3061 } else
3062 badness += BAD_SHARED_VOL;
3063 return badness;
3064}
3065
Takashi Iwaidc31b582012-02-17 17:27:53 +01003066struct badness_table {
3067 int no_primary_dac; /* no primary DAC */
3068 int no_dac; /* no secondary DACs */
3069 int shared_primary; /* primary DAC is shared with main output */
3070 int shared_surr; /* secondary DAC shared with main or primary */
3071 int shared_clfe; /* third DAC shared with main or primary */
3072 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3073};
3074
3075static struct badness_table main_out_badness = {
3076 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3077 .no_dac = BAD_NO_DAC,
3078 .shared_primary = BAD_NO_PRIMARY_DAC,
3079 .shared_surr = BAD_SHARED_SURROUND,
3080 .shared_clfe = BAD_SHARED_CLFE,
3081 .shared_surr_main = BAD_SHARED_SURROUND,
3082};
3083
3084static struct badness_table extra_out_badness = {
3085 .no_primary_dac = BAD_NO_DAC,
3086 .no_dac = BAD_NO_DAC,
3087 .shared_primary = BAD_NO_EXTRA_DAC,
3088 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3089 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3090 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3091};
3092
3093/* try to assign DACs to pins and return the resultant badness */
3094static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3095 const hda_nid_t *pins, hda_nid_t *dacs,
3096 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003097{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003098 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003099 struct auto_pin_cfg *cfg = &spec->autocfg;
3100 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003101 int badness = 0;
3102 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003103
Takashi Iwai185d99f2012-02-16 18:39:45 +01003104 if (!num_outs)
3105 return 0;
3106
Takashi Iwaidc31b582012-02-17 17:27:53 +01003107 for (i = 0; i < num_outs; i++) {
3108 hda_nid_t pin = pins[i];
3109 if (!dacs[i])
3110 dacs[i] = alc_auto_look_for_dac(codec, pin);
3111 if (!dacs[i] && !i) {
3112 for (j = 1; j < num_outs; j++) {
3113 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3114 dacs[0] = dacs[j];
3115 dacs[j] = 0;
3116 break;
3117 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003118 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003119 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003120 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003121 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003122 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003123 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003124 else if (cfg->line_outs > i &&
3125 alc_auto_is_dac_reachable(codec, pin,
3126 spec->private_dac_nids[i]))
3127 dac = spec->private_dac_nids[i];
3128 if (dac) {
3129 if (!i)
3130 badness += bad->shared_primary;
3131 else if (i == 1)
3132 badness += bad->shared_surr;
3133 else
3134 badness += bad->shared_clfe;
3135 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003136 spec->private_dac_nids[0])) {
3137 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003138 badness += bad->shared_surr_main;
3139 } else if (!i)
3140 badness += bad->no_primary_dac;
3141 else
3142 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003143 }
3144 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003145 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003146 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003147
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003148 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003149}
3150
3151static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003152 hda_nid_t reference_pin,
3153 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003154
Takashi Iwai185d99f2012-02-16 18:39:45 +01003155static bool alc_map_singles(struct hda_codec *codec, int outs,
3156 const hda_nid_t *pins, hda_nid_t *dacs)
3157{
3158 int i;
3159 bool found = false;
3160 for (i = 0; i < outs; i++) {
3161 if (dacs[i])
3162 continue;
3163 dacs[i] = get_dac_if_single(codec, pins[i]);
3164 if (dacs[i])
3165 found = true;
3166 }
3167 return found;
3168}
3169
Takashi Iwai7085ec12009-10-02 09:03:58 +02003170/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003171static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003172 bool fill_hardwired,
3173 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003174{
3175 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003176 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003177 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003178
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003179 /* set num_dacs once to full for alc_auto_look_for_dac() */
3180 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003181 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003182 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3183 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3184 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003185 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003186 clear_vol_marks(codec);
3187 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003188
3189 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003190 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003191 bool mapped;
3192 do {
3193 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003194 cfg->line_out_pins,
3195 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003196 mapped |= alc_map_singles(codec, cfg->hp_outs,
3197 cfg->hp_pins,
3198 spec->multiout.hp_out_nid);
3199 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3200 cfg->speaker_pins,
3201 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003202 if (fill_mio_first && cfg->line_outs == 1 &&
3203 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3204 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3205 if (!err)
3206 mapped = true;
3207 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003208 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003209 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003210
Takashi Iwaidc31b582012-02-17 17:27:53 +01003211 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3212 spec->private_dac_nids,
3213 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003214
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003215 /* re-count num_dacs and squash invalid entries */
3216 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003217 for (i = 0; i < cfg->line_outs; i++) {
3218 if (spec->private_dac_nids[i])
3219 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003220 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003221 memmove(spec->private_dac_nids + i,
3222 spec->private_dac_nids + i + 1,
3223 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003224 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3225 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003226 }
3227
Takashi Iwai276dd702012-02-17 16:17:03 +01003228 if (fill_mio_first &&
3229 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003230 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003231 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003232 if (err < 0)
3233 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003234 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003235 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003236
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003237 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003238 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3239 spec->multiout.hp_out_nid,
3240 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003241 if (err < 0)
3242 return err;
3243 badness += err;
3244 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003245 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003246 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3247 cfg->speaker_pins,
3248 spec->multiout.extra_out_nid,
3249 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003250 if (err < 0)
3251 return err;
3252 badness += err;
3253 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003254 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3255 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003256 if (err < 0)
3257 return err;
3258 badness += err;
3259 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003260 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3261 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003262 int offset = 0;
3263 if (cfg->line_outs >= 3)
3264 offset = 1;
3265 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3266 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003267 if (err < 0)
3268 return err;
3269 badness += err;
3270 }
3271
3272 if (spec->multi_ios == 2) {
3273 for (i = 0; i < 2; i++)
3274 spec->private_dac_nids[spec->multiout.num_dacs++] =
3275 spec->multi_io[i].dac;
3276 spec->ext_channel_count = 2;
3277 } else if (spec->multi_ios) {
3278 spec->multi_ios = 0;
3279 badness += BAD_MULTI_IO;
3280 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003281
3282 return badness;
3283}
3284
3285#define DEBUG_BADNESS
3286
3287#ifdef DEBUG_BADNESS
3288#define debug_badness snd_printdd
3289#else
3290#define debug_badness(...)
3291#endif
3292
3293static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3294{
3295 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3296 cfg->line_out_pins[0], cfg->line_out_pins[1],
3297 cfg->line_out_pins[2], cfg->line_out_pins[2],
3298 spec->multiout.dac_nids[0],
3299 spec->multiout.dac_nids[1],
3300 spec->multiout.dac_nids[2],
3301 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003302 if (spec->multi_ios > 0)
3303 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3304 spec->multi_ios,
3305 spec->multi_io[0].pin, spec->multi_io[1].pin,
3306 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003307 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3308 cfg->hp_pins[0], cfg->hp_pins[1],
3309 cfg->hp_pins[2], cfg->hp_pins[2],
3310 spec->multiout.hp_out_nid[0],
3311 spec->multiout.hp_out_nid[1],
3312 spec->multiout.hp_out_nid[2],
3313 spec->multiout.hp_out_nid[3]);
3314 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3315 cfg->speaker_pins[0], cfg->speaker_pins[1],
3316 cfg->speaker_pins[2], cfg->speaker_pins[3],
3317 spec->multiout.extra_out_nid[0],
3318 spec->multiout.extra_out_nid[1],
3319 spec->multiout.extra_out_nid[2],
3320 spec->multiout.extra_out_nid[3]);
3321}
3322
3323static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3324{
3325 struct alc_spec *spec = codec->spec;
3326 struct auto_pin_cfg *cfg = &spec->autocfg;
3327 struct auto_pin_cfg *best_cfg;
3328 int best_badness = INT_MAX;
3329 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003330 bool fill_hardwired = true, fill_mio_first = true;
3331 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003332 bool hp_spk_swapped = false;
3333
3334 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3335 if (!best_cfg)
3336 return -ENOMEM;
3337 *best_cfg = *cfg;
3338
3339 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003340 badness = fill_and_eval_dacs(codec, fill_hardwired,
3341 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003342 if (badness < 0) {
3343 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003344 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003345 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003346 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3347 cfg->line_out_type, fill_hardwired, fill_mio_first,
3348 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003349 debug_show_configs(spec, cfg);
3350 if (badness < best_badness) {
3351 best_badness = badness;
3352 *best_cfg = *cfg;
3353 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003354 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003355 }
3356 if (!badness)
3357 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003358 fill_mio_first = !fill_mio_first;
3359 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003360 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003361 fill_hardwired = !fill_hardwired;
3362 if (!fill_hardwired)
3363 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003364 if (hp_spk_swapped)
3365 break;
3366 hp_spk_swapped = true;
3367 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003368 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3369 cfg->hp_outs = cfg->line_outs;
3370 memcpy(cfg->hp_pins, cfg->line_out_pins,
3371 sizeof(cfg->hp_pins));
3372 cfg->line_outs = cfg->speaker_outs;
3373 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3374 sizeof(cfg->speaker_pins));
3375 cfg->speaker_outs = 0;
3376 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3377 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003378 fill_hardwired = true;
3379 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003380 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003381 if (cfg->hp_outs > 0 &&
3382 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3383 cfg->speaker_outs = cfg->line_outs;
3384 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3385 sizeof(cfg->speaker_pins));
3386 cfg->line_outs = cfg->hp_outs;
3387 memcpy(cfg->line_out_pins, cfg->hp_pins,
3388 sizeof(cfg->hp_pins));
3389 cfg->hp_outs = 0;
3390 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3391 cfg->line_out_type = AUTO_PIN_HP_OUT;
3392 fill_hardwired = true;
3393 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003394 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003395 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003396 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003397
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003398 if (badness) {
3399 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003400 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003401 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003402 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3403 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003404 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003405
David Henningssonfde48a12011-12-09 18:27:42 +08003406 if (cfg->line_out_pins[0])
3407 spec->vmaster_nid =
3408 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3409 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003410
3411 /* clear the bitmap flags for creating controls */
3412 clear_vol_marks(codec);
3413 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003414 return 0;
3415}
3416
Takashi Iwai343a04b2011-07-06 14:28:39 +02003417static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003418 const char *pfx, int cidx,
3419 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003420{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003421 struct alc_spec *spec = codec->spec;
3422 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003423 if (!nid)
3424 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003425 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3426 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3427 return 0;
3428 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003429 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003430 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003431}
3432
Takashi Iwaie29d3772011-11-14 17:13:23 +01003433static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3434 const char *pfx, int cidx,
3435 hda_nid_t nid)
3436{
3437 int chs = 1;
3438 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3439 chs = 3;
3440 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3441}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003442
3443/* create a mute-switch for the given mixer widget;
3444 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3445 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003446static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003447 const char *pfx, int cidx,
3448 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003449{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003450 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003451 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003452 int type;
3453 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003454 if (!nid)
3455 return 0;
3456 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3457 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3458 type = ALC_CTL_WIDGET_MUTE;
3459 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003460 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003461 type = ALC_CTL_WIDGET_MUTE;
3462 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3463 } else {
3464 type = ALC_CTL_BIND_MUTE;
3465 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3466 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003467 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3468 return 0;
3469 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003470 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003471}
3472
Takashi Iwaie29d3772011-11-14 17:13:23 +01003473static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3474 int cidx, hda_nid_t nid)
3475{
3476 int chs = 1;
3477 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3478 chs = 3;
3479 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3480}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003481
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003482static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3483 hda_nid_t pin, hda_nid_t dac)
3484{
3485 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3486 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3487 return pin;
3488 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3489 return mix;
3490 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3491 return dac;
3492 return 0;
3493}
3494
3495static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3496 hda_nid_t pin, hda_nid_t dac)
3497{
3498 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3499 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3500 return dac;
3501 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3502 return mix;
3503 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3504 return pin;
3505 return 0;
3506}
3507
Takashi Iwai7085ec12009-10-02 09:03:58 +02003508/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003509static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003510 const struct auto_pin_cfg *cfg)
3511{
3512 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003513 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003514
Takashi Iwaice764ab2011-04-27 16:35:23 +02003515 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003516 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003517 noutputs += spec->multi_ios;
3518
3519 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003520 const char *name;
3521 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003522 hda_nid_t dac, pin;
3523 hda_nid_t sw, vol;
3524
3525 dac = spec->multiout.dac_nids[i];
3526 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003527 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003528 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003529 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003530 index = 0;
3531 name = channel_name[i];
3532 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003533 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003534 name = alc_get_line_out_pfx(spec, i, true, &index);
3535 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003536
3537 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3538 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003539 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003540 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003541 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003542 if (err < 0)
3543 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003544 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003545 if (err < 0)
3546 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003547 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003548 if (err < 0)
3549 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003550 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003551 if (err < 0)
3552 return err;
3553 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003554 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003555 if (err < 0)
3556 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003557 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003558 if (err < 0)
3559 return err;
3560 }
3561 }
3562 return 0;
3563}
3564
Takashi Iwai343a04b2011-07-06 14:28:39 +02003565static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003566 hda_nid_t dac, const char *pfx,
3567 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003568{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003569 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003570 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003571 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003572
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003573 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003574 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003575 /* the corresponding DAC is already occupied */
3576 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3577 return 0; /* no way */
3578 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003579 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3580 if (is_ctl_used(spec->sw_ctls, val))
3581 return 0; /* already created */
3582 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003583 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003584 }
3585
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003586 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3587 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003588 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003589 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003590 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003591 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003592 if (err < 0)
3593 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003594 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003595}
3596
Takashi Iwai23c09b02011-08-19 09:05:35 +02003597static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3598 unsigned int nums,
3599 struct hda_ctl_ops *ops)
3600{
3601 struct alc_spec *spec = codec->spec;
3602 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003603 ctlp = snd_array_new(&spec->bind_ctls);
3604 if (!ctlp)
3605 return NULL;
3606 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3607 *ctlp = ctl;
3608 if (ctl)
3609 ctl->ops = ops;
3610 return ctl;
3611}
3612
3613/* add playback controls for speaker and HP outputs */
3614static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3615 const hda_nid_t *pins,
3616 const hda_nid_t *dacs,
3617 const char *pfx)
3618{
3619 struct alc_spec *spec = codec->spec;
3620 struct hda_bind_ctls *ctl;
3621 char name[32];
3622 int i, n, err;
3623
3624 if (!num_pins || !pins[0])
3625 return 0;
3626
Takashi Iwai527e4d72011-10-27 16:33:27 +02003627 if (num_pins == 1) {
3628 hda_nid_t dac = *dacs;
3629 if (!dac)
3630 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003631 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003632 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003633
Takashi Iwai23c09b02011-08-19 09:05:35 +02003634 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003635 hda_nid_t dac;
3636 if (dacs[num_pins - 1])
3637 dac = dacs[i]; /* with individual volumes */
3638 else
3639 dac = 0;
3640 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3641 err = alc_auto_create_extra_out(codec, pins[i], dac,
3642 "Bass Speaker", 0);
3643 } else if (num_pins >= 3) {
3644 snprintf(name, sizeof(name), "%s %s",
3645 pfx, channel_name[i]);
3646 err = alc_auto_create_extra_out(codec, pins[i], dac,
3647 name, 0);
3648 } else {
3649 err = alc_auto_create_extra_out(codec, pins[i], dac,
3650 pfx, i);
3651 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003652 if (err < 0)
3653 return err;
3654 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003655 if (dacs[num_pins - 1])
3656 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003657
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003658 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003659 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3660 if (!ctl)
3661 return -ENOMEM;
3662 n = 0;
3663 for (i = 0; i < num_pins; i++) {
3664 hda_nid_t vol;
3665 if (!pins[i] || !dacs[i])
3666 continue;
3667 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3668 if (vol)
3669 ctl->values[n++] =
3670 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3671 }
3672 if (n) {
3673 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3674 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3675 if (err < 0)
3676 return err;
3677 }
3678 return 0;
3679}
3680
Takashi Iwai343a04b2011-07-06 14:28:39 +02003681static int alc_auto_create_hp_out(struct hda_codec *codec)
3682{
3683 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003684 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3685 spec->autocfg.hp_pins,
3686 spec->multiout.hp_out_nid,
3687 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003688}
3689
3690static int alc_auto_create_speaker_out(struct hda_codec *codec)
3691{
3692 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003693 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3694 spec->autocfg.speaker_pins,
3695 spec->multiout.extra_out_nid,
3696 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003697}
3698
Takashi Iwai343a04b2011-07-06 14:28:39 +02003699static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003700 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003701 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003702{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003703 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003704 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003705 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003706
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003707 alc_set_pin_output(codec, pin, pin_type);
3708 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003709 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003710 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003711 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003712 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003713 mix = srcs[i];
3714 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003715 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003716 if (!mix)
3717 return;
3718
3719 /* need the manual connection? */
3720 if (num > 1)
3721 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3722 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003723 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3724 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003725 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003726 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003727 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003728 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003729 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003730 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3731 if (nid)
3732 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3733 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003734
3735 /* unmute DAC if it's not assigned to a mixer */
3736 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3737 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3738 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3739 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003740}
3741
Takashi Iwai343a04b2011-07-06 14:28:39 +02003742static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003743{
3744 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003745 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003746 int i;
3747
3748 for (i = 0; i <= HDA_SIDE; i++) {
3749 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3750 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003751 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003752 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003753 }
3754}
3755
Takashi Iwai343a04b2011-07-06 14:28:39 +02003756static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003757{
3758 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003759 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003760 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003761
David Henningsson636030e2011-10-12 19:26:03 +02003762 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003763 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3764 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003765 pin = spec->autocfg.hp_pins[i];
3766 if (!pin)
3767 break;
3768 dac = spec->multiout.hp_out_nid[i];
3769 if (!dac) {
3770 if (i > 0 && spec->multiout.hp_out_nid[0])
3771 dac = spec->multiout.hp_out_nid[0];
3772 else
3773 dac = spec->multiout.dac_nids[0];
3774 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003775 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3776 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003777 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003778 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3779 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003780 pin = spec->autocfg.speaker_pins[i];
3781 if (!pin)
3782 break;
3783 dac = spec->multiout.extra_out_nid[i];
3784 if (!dac) {
3785 if (i > 0 && spec->multiout.extra_out_nid[0])
3786 dac = spec->multiout.extra_out_nid[0];
3787 else
3788 dac = spec->multiout.dac_nids[0];
3789 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003790 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3791 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003792}
3793
Takashi Iwai276dd702012-02-17 16:17:03 +01003794/* check whether the given pin can be a multi-io pin */
3795static bool can_be_multiio_pin(struct hda_codec *codec,
3796 unsigned int location, hda_nid_t nid)
3797{
3798 unsigned int defcfg, caps;
3799
3800 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3801 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3802 return false;
3803 if (location && get_defcfg_location(defcfg) != location)
3804 return false;
3805 caps = snd_hda_query_pin_caps(codec, nid);
3806 if (!(caps & AC_PINCAP_OUT))
3807 return false;
3808 return true;
3809}
3810
Takashi Iwaice764ab2011-04-27 16:35:23 +02003811/*
3812 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003813 *
3814 * When hardwired is set, try to fill ony hardwired pins, and returns
3815 * zero if any pins are filled, non-zero if nothing found.
3816 * When hardwired is off, try to fill possible input pins, and returns
3817 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003818 */
3819static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003820 hda_nid_t reference_pin,
3821 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003822{
3823 struct alc_spec *spec = codec->spec;
3824 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003825 int type, i, j, dacs, num_pins, old_pins;
3826 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3827 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003828 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003829
Takashi Iwai276dd702012-02-17 16:17:03 +01003830 old_pins = spec->multi_ios;
3831 if (old_pins >= 2)
3832 goto end_fill;
3833
3834 num_pins = 0;
3835 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3836 for (i = 0; i < cfg->num_inputs; i++) {
3837 if (cfg->inputs[i].type != type)
3838 continue;
3839 if (can_be_multiio_pin(codec, location,
3840 cfg->inputs[i].pin))
3841 num_pins++;
3842 }
3843 }
3844 if (num_pins < 2)
3845 goto end_fill;
3846
Takashi Iwai07b18f62011-11-10 15:42:54 +01003847 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003848 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3849 for (i = 0; i < cfg->num_inputs; i++) {
3850 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003851 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003852
Takashi Iwaice764ab2011-04-27 16:35:23 +02003853 if (cfg->inputs[i].type != type)
3854 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003855 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003856 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003857 for (j = 0; j < spec->multi_ios; j++) {
3858 if (nid == spec->multi_io[j].pin)
3859 break;
3860 }
3861 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003862 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003863
3864 if (offset && offset + spec->multi_ios < dacs) {
3865 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003866 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3867 dac = 0;
3868 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003869 if (hardwired)
3870 dac = get_dac_if_single(codec, nid);
3871 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003872 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003873 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003874 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003875 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003876 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003877 spec->multi_io[spec->multi_ios].pin = nid;
3878 spec->multi_io[spec->multi_ios].dac = dac;
3879 spec->multi_ios++;
3880 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003881 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003882 }
3883 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003884 end_fill:
3885 if (badness)
3886 badness = BAD_MULTI_IO;
3887 if (old_pins == spec->multi_ios) {
3888 if (hardwired)
3889 return 1; /* nothing found */
3890 else
3891 return badness; /* no badness if nothing found */
3892 }
3893 if (!hardwired && spec->multi_ios < 2) {
3894 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003895 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003896 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003897
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003898 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003899}
3900
3901static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3902 struct snd_ctl_elem_info *uinfo)
3903{
3904 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3905 struct alc_spec *spec = codec->spec;
3906
3907 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3908 uinfo->count = 1;
3909 uinfo->value.enumerated.items = spec->multi_ios + 1;
3910 if (uinfo->value.enumerated.item > spec->multi_ios)
3911 uinfo->value.enumerated.item = spec->multi_ios;
3912 sprintf(uinfo->value.enumerated.name, "%dch",
3913 (uinfo->value.enumerated.item + 1) * 2);
3914 return 0;
3915}
3916
3917static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3918 struct snd_ctl_elem_value *ucontrol)
3919{
3920 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3921 struct alc_spec *spec = codec->spec;
3922 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3923 return 0;
3924}
3925
3926static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3927{
3928 struct alc_spec *spec = codec->spec;
3929 hda_nid_t nid = spec->multi_io[idx].pin;
3930
3931 if (!spec->multi_io[idx].ctl_in)
3932 spec->multi_io[idx].ctl_in =
3933 snd_hda_codec_read(codec, nid, 0,
3934 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3935 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003936 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003937 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3938 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3939 HDA_AMP_MUTE, 0);
3940 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3941 } else {
3942 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3943 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3944 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003945 snd_hda_set_pin_ctl_cache(codec, nid,
3946 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003947 }
3948 return 0;
3949}
3950
3951static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3952 struct snd_ctl_elem_value *ucontrol)
3953{
3954 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3955 struct alc_spec *spec = codec->spec;
3956 int i, ch;
3957
3958 ch = ucontrol->value.enumerated.item[0];
3959 if (ch < 0 || ch > spec->multi_ios)
3960 return -EINVAL;
3961 if (ch == (spec->ext_channel_count - 1) / 2)
3962 return 0;
3963 spec->ext_channel_count = (ch + 1) * 2;
3964 for (i = 0; i < spec->multi_ios; i++)
3965 alc_set_multi_io(codec, i, i < ch);
3966 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003967 if (spec->need_dac_fix && !spec->const_channel_count)
3968 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003969 return 1;
3970}
3971
Takashi Iwaia9111322011-05-02 11:30:18 +02003972static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003973 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3974 .name = "Channel Mode",
3975 .info = alc_auto_ch_mode_info,
3976 .get = alc_auto_ch_mode_get,
3977 .put = alc_auto_ch_mode_put,
3978};
3979
Takashi Iwai23c09b02011-08-19 09:05:35 +02003980static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003981{
3982 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003983
Takashi Iwaic2674682011-08-24 17:57:44 +02003984 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01003985 if (!alc_kcontrol_new(spec, "Channel Mode",
3986 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003987 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003988 }
3989 return 0;
3990}
3991
Takashi Iwai1d045db2011-07-07 18:23:21 +02003992/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3993 * active input pins
3994 */
3995static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3996{
3997 struct alc_spec *spec = codec->spec;
3998 const struct hda_input_mux *imux;
3999 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4000 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4001 int i, n, nums;
4002
4003 imux = spec->input_mux;
4004 if (!imux)
4005 return;
4006 if (spec->dyn_adc_switch)
4007 return;
4008
Takashi Iwai26acaf02012-03-22 14:36:50 +01004009 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004010 nums = 0;
4011 for (n = 0; n < spec->num_adc_nids; n++) {
4012 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004013 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004014 for (i = 0; i < imux->num_items; i++) {
4015 hda_nid_t pin = spec->imux_pins[i];
4016 if (pin) {
4017 if (get_connection_index(codec, cap, pin) < 0)
4018 break;
4019 } else if (num_conns <= imux->items[i].index)
4020 break;
4021 }
4022 if (i >= imux->num_items) {
4023 adc_nids[nums] = spec->private_adc_nids[n];
4024 capsrc_nids[nums++] = cap;
4025 }
4026 }
4027 if (!nums) {
4028 /* check whether ADC-switch is possible */
4029 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004030 if (spec->shared_mic_hp) {
4031 spec->shared_mic_hp = 0;
4032 spec->private_imux[0].num_items = 1;
4033 goto again;
4034 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004035 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4036 " using fallback 0x%x\n",
4037 codec->chip_name, spec->private_adc_nids[0]);
4038 spec->num_adc_nids = 1;
4039 spec->auto_mic = 0;
4040 return;
4041 }
4042 } else if (nums != spec->num_adc_nids) {
4043 memcpy(spec->private_adc_nids, adc_nids,
4044 nums * sizeof(hda_nid_t));
4045 memcpy(spec->private_capsrc_nids, capsrc_nids,
4046 nums * sizeof(hda_nid_t));
4047 spec->num_adc_nids = nums;
4048 }
4049
4050 if (spec->auto_mic)
4051 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004052 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004053 spec->num_adc_nids = 1; /* reduce to a single ADC */
4054}
4055
4056/*
4057 * initialize ADC paths
4058 */
4059static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4060{
4061 struct alc_spec *spec = codec->spec;
4062 hda_nid_t nid;
4063
4064 nid = spec->adc_nids[adc_idx];
4065 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004066 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004067 snd_hda_codec_write(codec, nid, 0,
4068 AC_VERB_SET_AMP_GAIN_MUTE,
4069 AMP_IN_MUTE(0));
4070 return;
4071 }
4072 if (!spec->capsrc_nids)
4073 return;
4074 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004075 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004076 snd_hda_codec_write(codec, nid, 0,
4077 AC_VERB_SET_AMP_GAIN_MUTE,
4078 AMP_OUT_MUTE);
4079}
4080
4081static void alc_auto_init_input_src(struct hda_codec *codec)
4082{
4083 struct alc_spec *spec = codec->spec;
4084 int c, nums;
4085
4086 for (c = 0; c < spec->num_adc_nids; c++)
4087 alc_auto_init_adc(codec, c);
4088 if (spec->dyn_adc_switch)
4089 nums = 1;
4090 else
4091 nums = spec->num_adc_nids;
4092 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004093 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004094}
4095
4096/* add mic boosts if needed */
4097static int alc_auto_add_mic_boost(struct hda_codec *codec)
4098{
4099 struct alc_spec *spec = codec->spec;
4100 struct auto_pin_cfg *cfg = &spec->autocfg;
4101 int i, err;
4102 int type_idx = 0;
4103 hda_nid_t nid;
4104 const char *prev_label = NULL;
4105
4106 for (i = 0; i < cfg->num_inputs; i++) {
4107 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4108 break;
4109 nid = cfg->inputs[i].pin;
4110 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4111 const char *label;
4112 char boost_label[32];
4113
4114 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004115 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4116 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004117 if (prev_label && !strcmp(label, prev_label))
4118 type_idx++;
4119 else
4120 type_idx = 0;
4121 prev_label = label;
4122
4123 snprintf(boost_label, sizeof(boost_label),
4124 "%s Boost Volume", label);
4125 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4126 boost_label, type_idx,
4127 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4128 if (err < 0)
4129 return err;
4130 }
4131 }
4132 return 0;
4133}
4134
4135/* select or unmute the given capsrc route */
4136static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4137 int idx)
4138{
4139 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4140 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4141 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004142 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004143 snd_hda_codec_write_cache(codec, cap, 0,
4144 AC_VERB_SET_CONNECT_SEL, idx);
4145 }
4146}
4147
4148/* set the default connection to that pin */
4149static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4150{
4151 struct alc_spec *spec = codec->spec;
4152 int i;
4153
4154 if (!pin)
4155 return 0;
4156 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004157 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004158 int idx;
4159
4160 idx = get_connection_index(codec, cap, pin);
4161 if (idx < 0)
4162 continue;
4163 select_or_unmute_capsrc(codec, cap, idx);
4164 return i; /* return the found index */
4165 }
4166 return -1; /* not found */
4167}
4168
4169/* initialize some special cases for input sources */
4170static void alc_init_special_input_src(struct hda_codec *codec)
4171{
4172 struct alc_spec *spec = codec->spec;
4173 int i;
4174
4175 for (i = 0; i < spec->autocfg.num_inputs; i++)
4176 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4177}
4178
4179/* assign appropriate capture mixers */
4180static void set_capture_mixer(struct hda_codec *codec)
4181{
4182 struct alc_spec *spec = codec->spec;
4183 static const struct snd_kcontrol_new *caps[2][3] = {
4184 { alc_capture_mixer_nosrc1,
4185 alc_capture_mixer_nosrc2,
4186 alc_capture_mixer_nosrc3 },
4187 { alc_capture_mixer1,
4188 alc_capture_mixer2,
4189 alc_capture_mixer3 },
4190 };
4191
4192 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004193 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004194 if (!spec->capsrc_nids)
4195 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004196 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004197 return; /* no volume in capsrc, too */
4198 spec->vol_in_capsrc = 1;
4199 }
4200
4201 if (spec->num_adc_nids > 0) {
4202 int mux = 0;
4203 int num_adcs = 0;
4204
4205 if (spec->input_mux && spec->input_mux->num_items > 1)
4206 mux = 1;
4207 if (spec->auto_mic) {
4208 num_adcs = 1;
4209 mux = 0;
4210 } else if (spec->dyn_adc_switch)
4211 num_adcs = 1;
4212 if (!num_adcs) {
4213 if (spec->num_adc_nids > 3)
4214 spec->num_adc_nids = 3;
4215 else if (!spec->num_adc_nids)
4216 return;
4217 num_adcs = spec->num_adc_nids;
4218 }
4219 spec->cap_mixer = caps[mux][num_adcs - 1];
4220 }
4221}
4222
4223/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004224 * standard auto-parser initializations
4225 */
4226static void alc_auto_init_std(struct hda_codec *codec)
4227{
Takashi Iwaie4770622011-07-08 11:11:35 +02004228 alc_auto_init_multi_out(codec);
4229 alc_auto_init_extra_out(codec);
4230 alc_auto_init_analog_input(codec);
4231 alc_auto_init_input_src(codec);
4232 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004233 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004234}
4235
4236/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004237 * Digital-beep handlers
4238 */
4239#ifdef CONFIG_SND_HDA_INPUT_BEEP
4240#define set_beep_amp(spec, nid, idx, dir) \
4241 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4242
4243static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004244 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004245 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4246 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4247 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4248 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004249 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004250 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4251 {}
4252};
4253
4254static inline int has_cdefine_beep(struct hda_codec *codec)
4255{
4256 struct alc_spec *spec = codec->spec;
4257 const struct snd_pci_quirk *q;
4258 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4259 if (q)
4260 return q->value;
4261 return spec->cdefine.enable_pcbeep;
4262}
4263#else
4264#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4265#define has_cdefine_beep(codec) 0
4266#endif
4267
4268/* parse the BIOS configuration and set up the alc_spec */
4269/* return 1 if successful, 0 if the proper config is not found,
4270 * or a negative error code
4271 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004272static int alc_parse_auto_config(struct hda_codec *codec,
4273 const hda_nid_t *ignore_nids,
4274 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004275{
4276 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004277 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004278 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004279
Takashi Iwai53c334a2011-08-23 18:27:14 +02004280 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4281 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004282 if (err < 0)
4283 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004284 if (!cfg->line_outs) {
4285 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004286 spec->multiout.max_channels = 2;
4287 spec->no_analog = 1;
4288 goto dig_only;
4289 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004290 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004291 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004292
Takashi Iwaie427c232012-07-29 10:04:08 +02004293 if (!spec->no_primary_hp &&
4294 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004295 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004296 /* use HP as primary out */
4297 cfg->speaker_outs = cfg->line_outs;
4298 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4299 sizeof(cfg->speaker_pins));
4300 cfg->line_outs = cfg->hp_outs;
4301 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4302 cfg->hp_outs = 0;
4303 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4304 cfg->line_out_type = AUTO_PIN_HP_OUT;
4305 }
4306
Takashi Iwai1d045db2011-07-07 18:23:21 +02004307 err = alc_auto_fill_dac_nids(codec);
4308 if (err < 0)
4309 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004310 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004311 if (err < 0)
4312 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004313 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004314 if (err < 0)
4315 return err;
4316 err = alc_auto_create_hp_out(codec);
4317 if (err < 0)
4318 return err;
4319 err = alc_auto_create_speaker_out(codec);
4320 if (err < 0)
4321 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004322 err = alc_auto_create_shared_input(codec);
4323 if (err < 0)
4324 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004325 err = alc_auto_create_input_ctls(codec);
4326 if (err < 0)
4327 return err;
4328
4329 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4330
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004331 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004332 alc_auto_parse_digital(codec);
4333
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004334 if (!spec->no_analog)
4335 alc_remove_invalid_adc_nids(codec);
4336
4337 if (ssid_nids)
4338 alc_ssid_check(codec, ssid_nids);
4339
4340 if (!spec->no_analog) {
4341 alc_auto_check_switches(codec);
4342 err = alc_auto_add_mic_boost(codec);
4343 if (err < 0)
4344 return err;
4345 }
4346
Takashi Iwai1d045db2011-07-07 18:23:21 +02004347 if (spec->kctls.list)
4348 add_mixer(spec, spec->kctls.list);
4349
Takashi Iwai070cff42012-02-21 12:54:17 +01004350 if (!spec->no_analog && !spec->cap_mixer)
4351 set_capture_mixer(codec);
4352
Takashi Iwai1d045db2011-07-07 18:23:21 +02004353 return 1;
4354}
4355
Takashi Iwai3de95172012-05-07 18:03:15 +02004356/* common preparation job for alc_spec */
4357static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4358{
4359 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4360 int err;
4361
4362 if (!spec)
4363 return -ENOMEM;
4364 codec->spec = spec;
4365 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004366 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004367 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4368 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004369
4370 err = alc_codec_rename_from_preset(codec);
4371 if (err < 0) {
4372 kfree(spec);
4373 return err;
4374 }
4375 return 0;
4376}
4377
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004378static int alc880_parse_auto_config(struct hda_codec *codec)
4379{
4380 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004381 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004382 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4383}
4384
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004386 * ALC880 fix-ups
4387 */
4388enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004389 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004390 ALC880_FIXUP_GPIO2,
4391 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004392 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004393 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004394 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004395 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004396 ALC880_FIXUP_VOL_KNOB,
4397 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004398 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004399 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004400 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004401 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004402 ALC880_FIXUP_3ST_BASE,
4403 ALC880_FIXUP_3ST,
4404 ALC880_FIXUP_3ST_DIG,
4405 ALC880_FIXUP_5ST_BASE,
4406 ALC880_FIXUP_5ST,
4407 ALC880_FIXUP_5ST_DIG,
4408 ALC880_FIXUP_6ST_BASE,
4409 ALC880_FIXUP_6ST,
4410 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004411};
4412
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004413/* enable the volume-knob widget support on NID 0x21 */
4414static void alc880_fixup_vol_knob(struct hda_codec *codec,
4415 const struct alc_fixup *fix, int action)
4416{
4417 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004418 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004419}
4420
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004421static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004422 [ALC880_FIXUP_GPIO1] = {
4423 .type = ALC_FIXUP_VERBS,
4424 .v.verbs = alc_gpio1_init_verbs,
4425 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004426 [ALC880_FIXUP_GPIO2] = {
4427 .type = ALC_FIXUP_VERBS,
4428 .v.verbs = alc_gpio2_init_verbs,
4429 },
4430 [ALC880_FIXUP_MEDION_RIM] = {
4431 .type = ALC_FIXUP_VERBS,
4432 .v.verbs = (const struct hda_verb[]) {
4433 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4434 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4435 { }
4436 },
4437 .chained = true,
4438 .chain_id = ALC880_FIXUP_GPIO2,
4439 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004440 [ALC880_FIXUP_LG] = {
4441 .type = ALC_FIXUP_PINS,
4442 .v.pins = (const struct alc_pincfg[]) {
4443 /* disable bogus unused pins */
4444 { 0x16, 0x411111f0 },
4445 { 0x18, 0x411111f0 },
4446 { 0x1a, 0x411111f0 },
4447 { }
4448 }
4449 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004450 [ALC880_FIXUP_W810] = {
4451 .type = ALC_FIXUP_PINS,
4452 .v.pins = (const struct alc_pincfg[]) {
4453 /* disable bogus unused pins */
4454 { 0x17, 0x411111f0 },
4455 { }
4456 },
4457 .chained = true,
4458 .chain_id = ALC880_FIXUP_GPIO2,
4459 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004460 [ALC880_FIXUP_EAPD_COEF] = {
4461 .type = ALC_FIXUP_VERBS,
4462 .v.verbs = (const struct hda_verb[]) {
4463 /* change to EAPD mode */
4464 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4465 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4466 {}
4467 },
4468 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004469 [ALC880_FIXUP_TCL_S700] = {
4470 .type = ALC_FIXUP_VERBS,
4471 .v.verbs = (const struct hda_verb[]) {
4472 /* change to EAPD mode */
4473 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4474 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4475 {}
4476 },
4477 .chained = true,
4478 .chain_id = ALC880_FIXUP_GPIO2,
4479 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004480 [ALC880_FIXUP_VOL_KNOB] = {
4481 .type = ALC_FIXUP_FUNC,
4482 .v.func = alc880_fixup_vol_knob,
4483 },
4484 [ALC880_FIXUP_FUJITSU] = {
4485 /* override all pins as BIOS on old Amilo is broken */
4486 .type = ALC_FIXUP_PINS,
4487 .v.pins = (const struct alc_pincfg[]) {
4488 { 0x14, 0x0121411f }, /* HP */
4489 { 0x15, 0x99030120 }, /* speaker */
4490 { 0x16, 0x99030130 }, /* bass speaker */
4491 { 0x17, 0x411111f0 }, /* N/A */
4492 { 0x18, 0x411111f0 }, /* N/A */
4493 { 0x19, 0x01a19950 }, /* mic-in */
4494 { 0x1a, 0x411111f0 }, /* N/A */
4495 { 0x1b, 0x411111f0 }, /* N/A */
4496 { 0x1c, 0x411111f0 }, /* N/A */
4497 { 0x1d, 0x411111f0 }, /* N/A */
4498 { 0x1e, 0x01454140 }, /* SPDIF out */
4499 { }
4500 },
4501 .chained = true,
4502 .chain_id = ALC880_FIXUP_VOL_KNOB,
4503 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004504 [ALC880_FIXUP_F1734] = {
4505 /* almost compatible with FUJITSU, but no bass and SPDIF */
4506 .type = ALC_FIXUP_PINS,
4507 .v.pins = (const struct alc_pincfg[]) {
4508 { 0x14, 0x0121411f }, /* HP */
4509 { 0x15, 0x99030120 }, /* speaker */
4510 { 0x16, 0x411111f0 }, /* N/A */
4511 { 0x17, 0x411111f0 }, /* N/A */
4512 { 0x18, 0x411111f0 }, /* N/A */
4513 { 0x19, 0x01a19950 }, /* mic-in */
4514 { 0x1a, 0x411111f0 }, /* N/A */
4515 { 0x1b, 0x411111f0 }, /* N/A */
4516 { 0x1c, 0x411111f0 }, /* N/A */
4517 { 0x1d, 0x411111f0 }, /* N/A */
4518 { 0x1e, 0x411111f0 }, /* N/A */
4519 { }
4520 },
4521 .chained = true,
4522 .chain_id = ALC880_FIXUP_VOL_KNOB,
4523 },
Takashi Iwai817de922012-02-20 17:20:48 +01004524 [ALC880_FIXUP_UNIWILL] = {
4525 /* need to fix HP and speaker pins to be parsed correctly */
4526 .type = ALC_FIXUP_PINS,
4527 .v.pins = (const struct alc_pincfg[]) {
4528 { 0x14, 0x0121411f }, /* HP */
4529 { 0x15, 0x99030120 }, /* speaker */
4530 { 0x16, 0x99030130 }, /* bass speaker */
4531 { }
4532 },
4533 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004534 [ALC880_FIXUP_UNIWILL_DIG] = {
4535 .type = ALC_FIXUP_PINS,
4536 .v.pins = (const struct alc_pincfg[]) {
4537 /* disable bogus unused pins */
4538 { 0x17, 0x411111f0 },
4539 { 0x19, 0x411111f0 },
4540 { 0x1b, 0x411111f0 },
4541 { 0x1f, 0x411111f0 },
4542 { }
4543 }
4544 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004545 [ALC880_FIXUP_Z71V] = {
4546 .type = ALC_FIXUP_PINS,
4547 .v.pins = (const struct alc_pincfg[]) {
4548 /* set up the whole pins as BIOS is utterly broken */
4549 { 0x14, 0x99030120 }, /* speaker */
4550 { 0x15, 0x0121411f }, /* HP */
4551 { 0x16, 0x411111f0 }, /* N/A */
4552 { 0x17, 0x411111f0 }, /* N/A */
4553 { 0x18, 0x01a19950 }, /* mic-in */
4554 { 0x19, 0x411111f0 }, /* N/A */
4555 { 0x1a, 0x01813031 }, /* line-in */
4556 { 0x1b, 0x411111f0 }, /* N/A */
4557 { 0x1c, 0x411111f0 }, /* N/A */
4558 { 0x1d, 0x411111f0 }, /* N/A */
4559 { 0x1e, 0x0144111e }, /* SPDIF */
4560 { }
4561 }
4562 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004563 [ALC880_FIXUP_3ST_BASE] = {
4564 .type = ALC_FIXUP_PINS,
4565 .v.pins = (const struct alc_pincfg[]) {
4566 { 0x14, 0x01014010 }, /* line-out */
4567 { 0x15, 0x411111f0 }, /* N/A */
4568 { 0x16, 0x411111f0 }, /* N/A */
4569 { 0x17, 0x411111f0 }, /* N/A */
4570 { 0x18, 0x01a19c30 }, /* mic-in */
4571 { 0x19, 0x0121411f }, /* HP */
4572 { 0x1a, 0x01813031 }, /* line-in */
4573 { 0x1b, 0x02a19c40 }, /* front-mic */
4574 { 0x1c, 0x411111f0 }, /* N/A */
4575 { 0x1d, 0x411111f0 }, /* N/A */
4576 /* 0x1e is filled in below */
4577 { 0x1f, 0x411111f0 }, /* N/A */
4578 { }
4579 }
4580 },
4581 [ALC880_FIXUP_3ST] = {
4582 .type = ALC_FIXUP_PINS,
4583 .v.pins = (const struct alc_pincfg[]) {
4584 { 0x1e, 0x411111f0 }, /* N/A */
4585 { }
4586 },
4587 .chained = true,
4588 .chain_id = ALC880_FIXUP_3ST_BASE,
4589 },
4590 [ALC880_FIXUP_3ST_DIG] = {
4591 .type = ALC_FIXUP_PINS,
4592 .v.pins = (const struct alc_pincfg[]) {
4593 { 0x1e, 0x0144111e }, /* SPDIF */
4594 { }
4595 },
4596 .chained = true,
4597 .chain_id = ALC880_FIXUP_3ST_BASE,
4598 },
4599 [ALC880_FIXUP_5ST_BASE] = {
4600 .type = ALC_FIXUP_PINS,
4601 .v.pins = (const struct alc_pincfg[]) {
4602 { 0x14, 0x01014010 }, /* front */
4603 { 0x15, 0x411111f0 }, /* N/A */
4604 { 0x16, 0x01011411 }, /* CLFE */
4605 { 0x17, 0x01016412 }, /* surr */
4606 { 0x18, 0x01a19c30 }, /* mic-in */
4607 { 0x19, 0x0121411f }, /* HP */
4608 { 0x1a, 0x01813031 }, /* line-in */
4609 { 0x1b, 0x02a19c40 }, /* front-mic */
4610 { 0x1c, 0x411111f0 }, /* N/A */
4611 { 0x1d, 0x411111f0 }, /* N/A */
4612 /* 0x1e is filled in below */
4613 { 0x1f, 0x411111f0 }, /* N/A */
4614 { }
4615 }
4616 },
4617 [ALC880_FIXUP_5ST] = {
4618 .type = ALC_FIXUP_PINS,
4619 .v.pins = (const struct alc_pincfg[]) {
4620 { 0x1e, 0x411111f0 }, /* N/A */
4621 { }
4622 },
4623 .chained = true,
4624 .chain_id = ALC880_FIXUP_5ST_BASE,
4625 },
4626 [ALC880_FIXUP_5ST_DIG] = {
4627 .type = ALC_FIXUP_PINS,
4628 .v.pins = (const struct alc_pincfg[]) {
4629 { 0x1e, 0x0144111e }, /* SPDIF */
4630 { }
4631 },
4632 .chained = true,
4633 .chain_id = ALC880_FIXUP_5ST_BASE,
4634 },
4635 [ALC880_FIXUP_6ST_BASE] = {
4636 .type = ALC_FIXUP_PINS,
4637 .v.pins = (const struct alc_pincfg[]) {
4638 { 0x14, 0x01014010 }, /* front */
4639 { 0x15, 0x01016412 }, /* surr */
4640 { 0x16, 0x01011411 }, /* CLFE */
4641 { 0x17, 0x01012414 }, /* side */
4642 { 0x18, 0x01a19c30 }, /* mic-in */
4643 { 0x19, 0x02a19c40 }, /* front-mic */
4644 { 0x1a, 0x01813031 }, /* line-in */
4645 { 0x1b, 0x0121411f }, /* HP */
4646 { 0x1c, 0x411111f0 }, /* N/A */
4647 { 0x1d, 0x411111f0 }, /* N/A */
4648 /* 0x1e is filled in below */
4649 { 0x1f, 0x411111f0 }, /* N/A */
4650 { }
4651 }
4652 },
4653 [ALC880_FIXUP_6ST] = {
4654 .type = ALC_FIXUP_PINS,
4655 .v.pins = (const struct alc_pincfg[]) {
4656 { 0x1e, 0x411111f0 }, /* N/A */
4657 { }
4658 },
4659 .chained = true,
4660 .chain_id = ALC880_FIXUP_6ST_BASE,
4661 },
4662 [ALC880_FIXUP_6ST_DIG] = {
4663 .type = ALC_FIXUP_PINS,
4664 .v.pins = (const struct alc_pincfg[]) {
4665 { 0x1e, 0x0144111e }, /* SPDIF */
4666 { }
4667 },
4668 .chained = true,
4669 .chain_id = ALC880_FIXUP_6ST_BASE,
4670 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004671};
4672
4673static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004674 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004675 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004676 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4677 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004678 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004679 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004680 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004681 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004682 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004683 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004684 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004685 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004686 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004687 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004688 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004689 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4690 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4691 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004692 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004693
4694 /* Below is the copied entries from alc880_quirks.c.
4695 * It's not quite sure whether BIOS sets the correct pin-config table
4696 * on these machines, thus they are kept to be compatible with
4697 * the old static quirks. Once when it's confirmed to work without
4698 * these overrides, it'd be better to remove.
4699 */
4700 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4701 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4702 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4703 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4704 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4705 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4706 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4707 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4708 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4709 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4710 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4711 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4712 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4713 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4714 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4715 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4716 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4717 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4718 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4719 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4720 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4721 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4722 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4723 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4724 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4725 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4726 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4727 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4728 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4729 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4730 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4731 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4732 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4733 /* default Intel */
4734 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4735 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4736 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4737 {}
4738};
4739
4740static const struct alc_model_fixup alc880_fixup_models[] = {
4741 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4742 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4743 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4744 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4745 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4746 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004747 {}
4748};
4749
4750
4751/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004752 * OK, here we have finally the patch for ALC880
4753 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004754static int patch_alc880(struct hda_codec *codec)
4755{
4756 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004757 int err;
4758
Takashi Iwai3de95172012-05-07 18:03:15 +02004759 err = alc_alloc_spec(codec, 0x0b);
4760 if (err < 0)
4761 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004762
Takashi Iwai3de95172012-05-07 18:03:15 +02004763 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004764 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004765
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004766 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4767 alc880_fixups);
4768 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004769
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004770 /* automatic parse from the BIOS config */
4771 err = alc880_parse_auto_config(codec);
4772 if (err < 0)
4773 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004774
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004775 if (!spec->no_analog) {
4776 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004777 if (err < 0)
4778 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004779 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4780 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004781
Takashi Iwai1d045db2011-07-07 18:23:21 +02004782 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004783 codec->patch_ops.unsol_event = alc880_unsol_event;
4784
Takashi Iwai1d045db2011-07-07 18:23:21 +02004785
Takashi Iwai589876e2012-02-20 15:47:55 +01004786 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4787
Takashi Iwai1d045db2011-07-07 18:23:21 +02004788 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004789
4790 error:
4791 alc_free(codec);
4792 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004793}
4794
4795
4796/*
4797 * ALC260 support
4798 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004799static int alc260_parse_auto_config(struct hda_codec *codec)
4800{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004801 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004802 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4803 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004804}
4805
Takashi Iwai1d045db2011-07-07 18:23:21 +02004806/*
4807 * Pin config fixes
4808 */
4809enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004810 ALC260_FIXUP_HP_DC5750,
4811 ALC260_FIXUP_HP_PIN_0F,
4812 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004813 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004814 ALC260_FIXUP_GPIO1_TOGGLE,
4815 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004816 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004817 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004818};
4819
Takashi Iwai20f7d922012-02-16 12:35:16 +01004820static void alc260_gpio1_automute(struct hda_codec *codec)
4821{
4822 struct alc_spec *spec = codec->spec;
4823 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4824 spec->hp_jack_present);
4825}
4826
4827static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4828 const struct alc_fixup *fix, int action)
4829{
4830 struct alc_spec *spec = codec->spec;
4831 if (action == ALC_FIXUP_ACT_PROBE) {
4832 /* although the machine has only one output pin, we need to
4833 * toggle GPIO1 according to the jack state
4834 */
4835 spec->automute_hook = alc260_gpio1_automute;
4836 spec->detect_hp = 1;
4837 spec->automute_speaker = 1;
4838 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004839 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4840 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004841 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004842 }
4843}
4844
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004845static void alc260_fixup_kn1(struct hda_codec *codec,
4846 const struct alc_fixup *fix, int action)
4847{
4848 struct alc_spec *spec = codec->spec;
4849 static const struct alc_pincfg pincfgs[] = {
4850 { 0x0f, 0x02214000 }, /* HP/speaker */
4851 { 0x12, 0x90a60160 }, /* int mic */
4852 { 0x13, 0x02a19000 }, /* ext mic */
4853 { 0x18, 0x01446000 }, /* SPDIF out */
4854 /* disable bogus I/O pins */
4855 { 0x10, 0x411111f0 },
4856 { 0x11, 0x411111f0 },
4857 { 0x14, 0x411111f0 },
4858 { 0x15, 0x411111f0 },
4859 { 0x16, 0x411111f0 },
4860 { 0x17, 0x411111f0 },
4861 { 0x19, 0x411111f0 },
4862 { }
4863 };
4864
4865 switch (action) {
4866 case ALC_FIXUP_ACT_PRE_PROBE:
4867 alc_apply_pincfgs(codec, pincfgs);
4868 break;
4869 case ALC_FIXUP_ACT_PROBE:
4870 spec->init_amp = ALC_INIT_NONE;
4871 break;
4872 }
4873}
4874
Takashi Iwai1d045db2011-07-07 18:23:21 +02004875static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004876 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004877 .type = ALC_FIXUP_PINS,
4878 .v.pins = (const struct alc_pincfg[]) {
4879 { 0x11, 0x90130110 }, /* speaker */
4880 { }
4881 }
4882 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004883 [ALC260_FIXUP_HP_PIN_0F] = {
4884 .type = ALC_FIXUP_PINS,
4885 .v.pins = (const struct alc_pincfg[]) {
4886 { 0x0f, 0x01214000 }, /* HP */
4887 { }
4888 }
4889 },
4890 [ALC260_FIXUP_COEF] = {
4891 .type = ALC_FIXUP_VERBS,
4892 .v.verbs = (const struct hda_verb[]) {
4893 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4894 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4895 { }
4896 },
4897 .chained = true,
4898 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4899 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004900 [ALC260_FIXUP_GPIO1] = {
4901 .type = ALC_FIXUP_VERBS,
4902 .v.verbs = alc_gpio1_init_verbs,
4903 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004904 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4905 .type = ALC_FIXUP_FUNC,
4906 .v.func = alc260_fixup_gpio1_toggle,
4907 .chained = true,
4908 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4909 },
4910 [ALC260_FIXUP_REPLACER] = {
4911 .type = ALC_FIXUP_VERBS,
4912 .v.verbs = (const struct hda_verb[]) {
4913 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4914 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4915 { }
4916 },
4917 .chained = true,
4918 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4919 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004920 [ALC260_FIXUP_HP_B1900] = {
4921 .type = ALC_FIXUP_FUNC,
4922 .v.func = alc260_fixup_gpio1_toggle,
4923 .chained = true,
4924 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004925 },
4926 [ALC260_FIXUP_KN1] = {
4927 .type = ALC_FIXUP_FUNC,
4928 .v.func = alc260_fixup_kn1,
4929 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004930};
4931
4932static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004933 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004934 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004935 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004936 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004937 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004938 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004939 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004940 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004941 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004942 {}
4943};
4944
4945/*
4946 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004947static int patch_alc260(struct hda_codec *codec)
4948{
4949 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004950 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004951
Takashi Iwai3de95172012-05-07 18:03:15 +02004952 err = alc_alloc_spec(codec, 0x07);
4953 if (err < 0)
4954 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004955
Takashi Iwai3de95172012-05-07 18:03:15 +02004956 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004957
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004958 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4959 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004960
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004961 /* automatic parse from the BIOS config */
4962 err = alc260_parse_auto_config(codec);
4963 if (err < 0)
4964 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004965
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004966 if (!spec->no_analog) {
4967 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004968 if (err < 0)
4969 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004970 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4971 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004972
Takashi Iwai1d045db2011-07-07 18:23:21 +02004973 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004974 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004975
Takashi Iwai589876e2012-02-20 15:47:55 +01004976 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4977
Takashi Iwai1d045db2011-07-07 18:23:21 +02004978 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004979
4980 error:
4981 alc_free(codec);
4982 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004983}
4984
4985
4986/*
4987 * ALC882/883/885/888/889 support
4988 *
4989 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4990 * configuration. Each pin widget can choose any input DACs and a mixer.
4991 * Each ADC is connected from a mixer of all inputs. This makes possible
4992 * 6-channel independent captures.
4993 *
4994 * In addition, an independent DAC for the multi-playback (not used in this
4995 * driver yet).
4996 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004997
4998/*
4999 * Pin config fixes
5000 */
5001enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005002 ALC882_FIXUP_ABIT_AW9D_MAX,
5003 ALC882_FIXUP_LENOVO_Y530,
5004 ALC882_FIXUP_PB_M5210,
5005 ALC882_FIXUP_ACER_ASPIRE_7736,
5006 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005007 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005008 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005009 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005010 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005011 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005012 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005013 ALC882_FIXUP_GPIO1,
5014 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005015 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005016 ALC889_FIXUP_COEF,
5017 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005018 ALC882_FIXUP_ACER_ASPIRE_4930G,
5019 ALC882_FIXUP_ACER_ASPIRE_8930G,
5020 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005021 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005022 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005023 ALC889_FIXUP_MBP_VREF,
5024 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005025 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005026 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005027};
5028
Takashi Iwai68ef0562011-11-09 18:24:44 +01005029static void alc889_fixup_coef(struct hda_codec *codec,
5030 const struct alc_fixup *fix, int action)
5031{
5032 if (action != ALC_FIXUP_ACT_INIT)
5033 return;
5034 alc889_coef_init(codec);
5035}
5036
Takashi Iwai56710872011-11-14 17:42:11 +01005037/* toggle speaker-output according to the hp-jack state */
5038static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5039{
5040 unsigned int gpiostate, gpiomask, gpiodir;
5041
5042 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5043 AC_VERB_GET_GPIO_DATA, 0);
5044
5045 if (!muted)
5046 gpiostate |= (1 << pin);
5047 else
5048 gpiostate &= ~(1 << pin);
5049
5050 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5051 AC_VERB_GET_GPIO_MASK, 0);
5052 gpiomask |= (1 << pin);
5053
5054 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5055 AC_VERB_GET_GPIO_DIRECTION, 0);
5056 gpiodir |= (1 << pin);
5057
5058
5059 snd_hda_codec_write(codec, codec->afg, 0,
5060 AC_VERB_SET_GPIO_MASK, gpiomask);
5061 snd_hda_codec_write(codec, codec->afg, 0,
5062 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5063
5064 msleep(1);
5065
5066 snd_hda_codec_write(codec, codec->afg, 0,
5067 AC_VERB_SET_GPIO_DATA, gpiostate);
5068}
5069
5070/* set up GPIO at initialization */
5071static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5072 const struct alc_fixup *fix, int action)
5073{
5074 if (action != ALC_FIXUP_ACT_INIT)
5075 return;
5076 alc882_gpio_mute(codec, 0, 0);
5077 alc882_gpio_mute(codec, 1, 0);
5078}
5079
Takashi Iwai02a237b2012-02-13 15:25:07 +01005080/* Fix the connection of some pins for ALC889:
5081 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5082 * work correctly (bko#42740)
5083 */
5084static void alc889_fixup_dac_route(struct hda_codec *codec,
5085 const struct alc_fixup *fix, int action)
5086{
5087 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005088 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005089 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5090 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5091 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5092 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5093 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5094 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005095 } else if (action == ALC_FIXUP_ACT_PROBE) {
5096 /* restore the connections */
5097 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5098 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5099 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5100 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5101 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005102 }
5103}
5104
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005105/* Set VREF on HP pin */
5106static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5107 const struct alc_fixup *fix, int action)
5108{
5109 struct alc_spec *spec = codec->spec;
5110 static hda_nid_t nids[2] = { 0x14, 0x15 };
5111 int i;
5112
5113 if (action != ALC_FIXUP_ACT_INIT)
5114 return;
5115 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5116 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5117 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5118 continue;
5119 val = snd_hda_codec_read(codec, nids[i], 0,
5120 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5121 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005122 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005123 spec->keep_vref_in_automute = 1;
5124 break;
5125 }
5126}
5127
5128/* Set VREF on speaker pins on imac91 */
5129static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5130 const struct alc_fixup *fix, int action)
5131{
5132 struct alc_spec *spec = codec->spec;
5133 static hda_nid_t nids[2] = { 0x18, 0x1a };
5134 int i;
5135
5136 if (action != ALC_FIXUP_ACT_INIT)
5137 return;
5138 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5139 unsigned int val;
5140 val = snd_hda_codec_read(codec, nids[i], 0,
5141 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5142 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005143 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005144 }
5145 spec->keep_vref_in_automute = 1;
5146}
5147
Takashi Iwaie427c232012-07-29 10:04:08 +02005148/* Don't take HP output as primary
5149 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5150 */
5151static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5152 const struct alc_fixup *fix, int action)
5153{
5154 struct alc_spec *spec = codec->spec;
5155 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5156 spec->no_primary_hp = 1;
5157}
5158
Takashi Iwai1d045db2011-07-07 18:23:21 +02005159static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005160 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005161 .type = ALC_FIXUP_PINS,
5162 .v.pins = (const struct alc_pincfg[]) {
5163 { 0x15, 0x01080104 }, /* side */
5164 { 0x16, 0x01011012 }, /* rear */
5165 { 0x17, 0x01016011 }, /* clfe */
5166 { }
5167 }
5168 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005169 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005170 .type = ALC_FIXUP_PINS,
5171 .v.pins = (const struct alc_pincfg[]) {
5172 { 0x15, 0x99130112 }, /* rear int speakers */
5173 { 0x16, 0x99130111 }, /* subwoofer */
5174 { }
5175 }
5176 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005177 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005178 .type = ALC_FIXUP_VERBS,
5179 .v.verbs = (const struct hda_verb[]) {
5180 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5181 {}
5182 }
5183 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005184 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005185 .type = ALC_FIXUP_FUNC,
5186 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005187 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005188 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005189 .type = ALC_FIXUP_PINS,
5190 .v.pins = (const struct alc_pincfg[]) {
5191 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5192 { }
5193 }
5194 },
Marton Balint8f239212012-03-05 21:33:23 +01005195 [ALC889_FIXUP_CD] = {
5196 .type = ALC_FIXUP_PINS,
5197 .v.pins = (const struct alc_pincfg[]) {
5198 { 0x1c, 0x993301f0 }, /* CD */
5199 { }
5200 }
5201 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005202 [ALC889_FIXUP_VAIO_TT] = {
5203 .type = ALC_FIXUP_PINS,
5204 .v.pins = (const struct alc_pincfg[]) {
5205 { 0x17, 0x90170111 }, /* hidden surround speaker */
5206 { }
5207 }
5208 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005209 [ALC888_FIXUP_EEE1601] = {
5210 .type = ALC_FIXUP_VERBS,
5211 .v.verbs = (const struct hda_verb[]) {
5212 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5213 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5214 { }
5215 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005216 },
5217 [ALC882_FIXUP_EAPD] = {
5218 .type = ALC_FIXUP_VERBS,
5219 .v.verbs = (const struct hda_verb[]) {
5220 /* change to EAPD mode */
5221 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5222 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5223 { }
5224 }
5225 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005226 [ALC883_FIXUP_EAPD] = {
5227 .type = ALC_FIXUP_VERBS,
5228 .v.verbs = (const struct hda_verb[]) {
5229 /* change to EAPD mode */
5230 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5231 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5232 { }
5233 }
5234 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005235 [ALC883_FIXUP_ACER_EAPD] = {
5236 .type = ALC_FIXUP_VERBS,
5237 .v.verbs = (const struct hda_verb[]) {
5238 /* eanable EAPD on Acer laptops */
5239 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5240 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5241 { }
5242 }
5243 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005244 [ALC882_FIXUP_GPIO1] = {
5245 .type = ALC_FIXUP_VERBS,
5246 .v.verbs = alc_gpio1_init_verbs,
5247 },
5248 [ALC882_FIXUP_GPIO2] = {
5249 .type = ALC_FIXUP_VERBS,
5250 .v.verbs = alc_gpio2_init_verbs,
5251 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005252 [ALC882_FIXUP_GPIO3] = {
5253 .type = ALC_FIXUP_VERBS,
5254 .v.verbs = alc_gpio3_init_verbs,
5255 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005256 [ALC882_FIXUP_ASUS_W2JC] = {
5257 .type = ALC_FIXUP_VERBS,
5258 .v.verbs = alc_gpio1_init_verbs,
5259 .chained = true,
5260 .chain_id = ALC882_FIXUP_EAPD,
5261 },
5262 [ALC889_FIXUP_COEF] = {
5263 .type = ALC_FIXUP_FUNC,
5264 .v.func = alc889_fixup_coef,
5265 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005266 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5267 .type = ALC_FIXUP_PINS,
5268 .v.pins = (const struct alc_pincfg[]) {
5269 { 0x16, 0x99130111 }, /* CLFE speaker */
5270 { 0x17, 0x99130112 }, /* surround speaker */
5271 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005272 },
5273 .chained = true,
5274 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005275 },
5276 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5277 .type = ALC_FIXUP_PINS,
5278 .v.pins = (const struct alc_pincfg[]) {
5279 { 0x16, 0x99130111 }, /* CLFE speaker */
5280 { 0x1b, 0x99130112 }, /* surround speaker */
5281 { }
5282 },
5283 .chained = true,
5284 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5285 },
5286 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5287 /* additional init verbs for Acer Aspire 8930G */
5288 .type = ALC_FIXUP_VERBS,
5289 .v.verbs = (const struct hda_verb[]) {
5290 /* Enable all DACs */
5291 /* DAC DISABLE/MUTE 1? */
5292 /* setting bits 1-5 disables DAC nids 0x02-0x06
5293 * apparently. Init=0x38 */
5294 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5295 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5296 /* DAC DISABLE/MUTE 2? */
5297 /* some bit here disables the other DACs.
5298 * Init=0x4900 */
5299 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5300 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5301 /* DMIC fix
5302 * This laptop has a stereo digital microphone.
5303 * The mics are only 1cm apart which makes the stereo
5304 * useless. However, either the mic or the ALC889
5305 * makes the signal become a difference/sum signal
5306 * instead of standard stereo, which is annoying.
5307 * So instead we flip this bit which makes the
5308 * codec replicate the sum signal to both channels,
5309 * turning it into a normal mono mic.
5310 */
5311 /* DMIC_CONTROL? Init value = 0x0001 */
5312 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5313 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5314 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5315 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5316 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005317 },
5318 .chained = true,
5319 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005320 },
Takashi Iwai56710872011-11-14 17:42:11 +01005321 [ALC885_FIXUP_MACPRO_GPIO] = {
5322 .type = ALC_FIXUP_FUNC,
5323 .v.func = alc885_fixup_macpro_gpio,
5324 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005325 [ALC889_FIXUP_DAC_ROUTE] = {
5326 .type = ALC_FIXUP_FUNC,
5327 .v.func = alc889_fixup_dac_route,
5328 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005329 [ALC889_FIXUP_MBP_VREF] = {
5330 .type = ALC_FIXUP_FUNC,
5331 .v.func = alc889_fixup_mbp_vref,
5332 .chained = true,
5333 .chain_id = ALC882_FIXUP_GPIO1,
5334 },
5335 [ALC889_FIXUP_IMAC91_VREF] = {
5336 .type = ALC_FIXUP_FUNC,
5337 .v.func = alc889_fixup_imac91_vref,
5338 .chained = true,
5339 .chain_id = ALC882_FIXUP_GPIO1,
5340 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005341 [ALC882_FIXUP_INV_DMIC] = {
5342 .type = ALC_FIXUP_FUNC,
5343 .v.func = alc_fixup_inv_dmic_0x12,
5344 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005345 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5346 .type = ALC_FIXUP_FUNC,
5347 .v.func = alc882_fixup_no_primary_hp,
5348 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005349};
5350
5351static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005352 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5353 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5354 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5355 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5356 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5357 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005358 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5359 ALC882_FIXUP_ACER_ASPIRE_4930G),
5360 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5361 ALC882_FIXUP_ACER_ASPIRE_4930G),
5362 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5363 ALC882_FIXUP_ACER_ASPIRE_8930G),
5364 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5365 ALC882_FIXUP_ACER_ASPIRE_8930G),
5366 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5367 ALC882_FIXUP_ACER_ASPIRE_4930G),
5368 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5369 ALC882_FIXUP_ACER_ASPIRE_4930G),
5370 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5371 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005372 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005373 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5374 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005375 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005376 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005377 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005378 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005379 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005380 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005381 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005382 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005383 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005384
5385 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005386 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5387 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5388 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005389 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5390 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5391 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005392 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5393 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005394 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005395 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5396 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5397 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5398 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005399 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005400 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5401 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5402 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005403 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005404 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005405 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5406 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5407 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005408
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005409 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005410 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005411 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005412 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005413 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005414 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5415 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005416 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005417 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005418 {}
5419};
5420
Takashi Iwai912093b2012-04-11 14:03:41 +02005421static const struct alc_model_fixup alc882_fixup_models[] = {
5422 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5423 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5424 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005425 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005426 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005427 {}
5428};
5429
Takashi Iwai1d045db2011-07-07 18:23:21 +02005430/*
5431 * BIOS auto configuration
5432 */
5433/* almost identical with ALC880 parser... */
5434static int alc882_parse_auto_config(struct hda_codec *codec)
5435{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005436 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005437 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5438 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005439}
5440
Takashi Iwai1d045db2011-07-07 18:23:21 +02005441/*
5442 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005443static int patch_alc882(struct hda_codec *codec)
5444{
5445 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005446 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005447
Takashi Iwai3de95172012-05-07 18:03:15 +02005448 err = alc_alloc_spec(codec, 0x0b);
5449 if (err < 0)
5450 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451
Takashi Iwai3de95172012-05-07 18:03:15 +02005452 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005453
5454 switch (codec->vendor_id) {
5455 case 0x10ec0882:
5456 case 0x10ec0885:
5457 break;
5458 default:
5459 /* ALC883 and variants */
5460 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5461 break;
5462 }
5463
Takashi Iwai912093b2012-04-11 14:03:41 +02005464 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5465 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005466 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005467
5468 alc_auto_parse_customize_define(codec);
5469
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005470 /* automatic parse from the BIOS config */
5471 err = alc882_parse_auto_config(codec);
5472 if (err < 0)
5473 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005474
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005475 if (!spec->no_analog && has_cdefine_beep(codec)) {
5476 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005477 if (err < 0)
5478 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005479 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005480 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481
Takashi Iwai1d045db2011-07-07 18:23:21 +02005482 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005483
Takashi Iwai589876e2012-02-20 15:47:55 +01005484 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5485
Takashi Iwai1d045db2011-07-07 18:23:21 +02005486 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005487
5488 error:
5489 alc_free(codec);
5490 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005491}
5492
5493
5494/*
5495 * ALC262 support
5496 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005497static int alc262_parse_auto_config(struct hda_codec *codec)
5498{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005500 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5501 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005502}
5503
5504/*
5505 * Pin config fixes
5506 */
5507enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005508 ALC262_FIXUP_FSC_H270,
5509 ALC262_FIXUP_HP_Z200,
5510 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005511 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005512 ALC262_FIXUP_BENQ,
5513 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005514 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005515};
5516
5517static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005518 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005519 .type = ALC_FIXUP_PINS,
5520 .v.pins = (const struct alc_pincfg[]) {
5521 { 0x14, 0x99130110 }, /* speaker */
5522 { 0x15, 0x0221142f }, /* front HP */
5523 { 0x1b, 0x0121141f }, /* rear HP */
5524 { }
5525 }
5526 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005527 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005528 .type = ALC_FIXUP_PINS,
5529 .v.pins = (const struct alc_pincfg[]) {
5530 { 0x16, 0x99130120 }, /* internal speaker */
5531 { }
5532 }
5533 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005534 [ALC262_FIXUP_TYAN] = {
5535 .type = ALC_FIXUP_PINS,
5536 .v.pins = (const struct alc_pincfg[]) {
5537 { 0x14, 0x1993e1f0 }, /* int AUX */
5538 { }
5539 }
5540 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005541 [ALC262_FIXUP_LENOVO_3000] = {
5542 .type = ALC_FIXUP_VERBS,
5543 .v.verbs = (const struct hda_verb[]) {
5544 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005545 {}
5546 },
5547 .chained = true,
5548 .chain_id = ALC262_FIXUP_BENQ,
5549 },
5550 [ALC262_FIXUP_BENQ] = {
5551 .type = ALC_FIXUP_VERBS,
5552 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005553 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5554 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5555 {}
5556 }
5557 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005558 [ALC262_FIXUP_BENQ_T31] = {
5559 .type = ALC_FIXUP_VERBS,
5560 .v.verbs = (const struct hda_verb[]) {
5561 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5562 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5563 {}
5564 }
5565 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005566 [ALC262_FIXUP_INV_DMIC] = {
5567 .type = ALC_FIXUP_FUNC,
5568 .v.func = alc_fixup_inv_dmic_0x12,
5569 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005570};
5571
5572static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005573 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005574 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5575 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005576 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5577 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005578 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005579 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5580 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005581 {}
5582};
5583
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005584static const struct alc_model_fixup alc262_fixup_models[] = {
5585 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5586 {}
5587};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005588
Takashi Iwai1d045db2011-07-07 18:23:21 +02005589/*
5590 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005591static int patch_alc262(struct hda_codec *codec)
5592{
5593 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005594 int err;
5595
Takashi Iwai3de95172012-05-07 18:03:15 +02005596 err = alc_alloc_spec(codec, 0x0b);
5597 if (err < 0)
5598 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005599
Takashi Iwai3de95172012-05-07 18:03:15 +02005600 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005601
5602#if 0
5603 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5604 * under-run
5605 */
5606 {
5607 int tmp;
5608 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5609 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5610 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5611 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5612 }
5613#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005614 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5615
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005616 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5617 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005618 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005619
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005620 alc_auto_parse_customize_define(codec);
5621
Takashi Iwai42399f72011-11-07 17:18:44 +01005622 /* automatic parse from the BIOS config */
5623 err = alc262_parse_auto_config(codec);
5624 if (err < 0)
5625 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005626
Takashi Iwai1d045db2011-07-07 18:23:21 +02005627 if (!spec->no_analog && has_cdefine_beep(codec)) {
5628 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005629 if (err < 0)
5630 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005631 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005632 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005633
Takashi Iwai1d045db2011-07-07 18:23:21 +02005634 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005635 spec->shutup = alc_eapd_shutup;
5636
Takashi Iwai589876e2012-02-20 15:47:55 +01005637 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5638
Takashi Iwai1d045db2011-07-07 18:23:21 +02005639 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005640
5641 error:
5642 alc_free(codec);
5643 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005644}
5645
5646/*
5647 * ALC268
5648 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649/* bind Beep switches of both NID 0x0f and 0x10 */
5650static const struct hda_bind_ctls alc268_bind_beep_sw = {
5651 .ops = &snd_hda_bind_sw,
5652 .values = {
5653 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5654 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5655 0
5656 },
5657};
5658
5659static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5660 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5661 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5662 { }
5663};
5664
5665/* set PCBEEP vol = 0, mute connections */
5666static const struct hda_verb alc268_beep_init_verbs[] = {
5667 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5668 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5669 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5670 { }
5671};
5672
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005673enum {
5674 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005675 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005676};
5677
5678static const struct alc_fixup alc268_fixups[] = {
5679 [ALC268_FIXUP_INV_DMIC] = {
5680 .type = ALC_FIXUP_FUNC,
5681 .v.func = alc_fixup_inv_dmic_0x12,
5682 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005683 [ALC268_FIXUP_HP_EAPD] = {
5684 .type = ALC_FIXUP_VERBS,
5685 .v.verbs = (const struct hda_verb[]) {
5686 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5687 {}
5688 }
5689 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005690};
5691
5692static const struct alc_model_fixup alc268_fixup_models[] = {
5693 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005694 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5695 {}
5696};
5697
5698static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5699 /* below is codec SSID since multiple Toshiba laptops have the
5700 * same PCI SSID 1179:ff00
5701 */
5702 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005703 {}
5704};
5705
Takashi Iwai1d045db2011-07-07 18:23:21 +02005706/*
5707 * BIOS auto configuration
5708 */
5709static int alc268_parse_auto_config(struct hda_codec *codec)
5710{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005711 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005713 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5714 if (err > 0) {
5715 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5716 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005717 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005718 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005719 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005720 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721}
5722
Takashi Iwai1d045db2011-07-07 18:23:21 +02005723/*
5724 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005725static int patch_alc268(struct hda_codec *codec)
5726{
5727 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005728 int i, has_beep, err;
5729
Takashi Iwai1d045db2011-07-07 18:23:21 +02005730 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005731 err = alc_alloc_spec(codec, 0);
5732 if (err < 0)
5733 return err;
5734
5735 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005736
Takashi Iwaicb766402012-10-20 10:55:21 +02005737 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005738 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5739
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005740 /* automatic parse from the BIOS config */
5741 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005742 if (err < 0)
5743 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005744
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745 has_beep = 0;
5746 for (i = 0; i < spec->num_mixers; i++) {
5747 if (spec->mixers[i] == alc268_beep_mixer) {
5748 has_beep = 1;
5749 break;
5750 }
5751 }
5752
5753 if (has_beep) {
5754 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005755 if (err < 0)
5756 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5758 /* override the amp caps for beep generator */
5759 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5760 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5761 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5762 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5763 (0 << AC_AMPCAP_MUTE_SHIFT));
5764 }
5765
Takashi Iwai1d045db2011-07-07 18:23:21 +02005766 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767 spec->shutup = alc_eapd_shutup;
5768
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005769 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5770
Takashi Iwai1d045db2011-07-07 18:23:21 +02005771 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005772
5773 error:
5774 alc_free(codec);
5775 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005776}
5777
5778/*
5779 * ALC269
5780 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005781static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5782 .substreams = 1,
5783 .channels_min = 2,
5784 .channels_max = 8,
5785 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5786 /* NID is set in alc_build_pcms */
5787 .ops = {
5788 .open = alc_playback_pcm_open,
5789 .prepare = alc_playback_pcm_prepare,
5790 .cleanup = alc_playback_pcm_cleanup
5791 },
5792};
5793
5794static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5795 .substreams = 1,
5796 .channels_min = 2,
5797 .channels_max = 2,
5798 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5799 /* NID is set in alc_build_pcms */
5800};
5801
Takashi Iwai1d045db2011-07-07 18:23:21 +02005802/* different alc269-variants */
5803enum {
5804 ALC269_TYPE_ALC269VA,
5805 ALC269_TYPE_ALC269VB,
5806 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005807 ALC269_TYPE_ALC269VD,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005808};
5809
5810/*
5811 * BIOS auto configuration
5812 */
5813static int alc269_parse_auto_config(struct hda_codec *codec)
5814{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005815 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005816 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5817 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5818 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005819 const hda_nid_t *ssids;
5820
5821 switch (spec->codec_variant) {
5822 case ALC269_TYPE_ALC269VA:
5823 case ALC269_TYPE_ALC269VC:
5824 ssids = alc269va_ssids;
5825 break;
5826 case ALC269_TYPE_ALC269VB:
5827 case ALC269_TYPE_ALC269VD:
5828 ssids = alc269_ssids;
5829 break;
5830 default:
5831 ssids = alc269_ssids;
5832 break;
5833 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005834
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005835 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005836}
5837
Kailang Yang1387e2d2012-11-08 10:23:18 +01005838static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005839{
5840 int val = alc_read_coef_idx(codec, 0x04);
5841 if (power_up)
5842 val |= 1 << 11;
5843 else
5844 val &= ~(1 << 11);
5845 alc_write_coef_idx(codec, 0x04, val);
5846}
5847
5848static void alc269_shutup(struct hda_codec *codec)
5849{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005850 struct alc_spec *spec = codec->spec;
5851
5852 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5853 return;
5854
Kailang Yang1387e2d2012-11-08 10:23:18 +01005855 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5856 alc269vb_toggle_power_output(codec, 0);
5857 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5858 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005859 msleep(150);
5860 }
5861}
5862
Takashi Iwai2a439522011-07-26 09:52:50 +02005863#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005864static int alc269_resume(struct hda_codec *codec)
5865{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005866 struct alc_spec *spec = codec->spec;
5867
Kailang Yang1387e2d2012-11-08 10:23:18 +01005868 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5869 alc269vb_toggle_power_output(codec, 0);
5870 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005871 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005872 msleep(150);
5873 }
5874
5875 codec->patch_ops.init(codec);
5876
Kailang Yang1387e2d2012-11-08 10:23:18 +01005877 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5878 alc269vb_toggle_power_output(codec, 1);
5879 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005880 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005881 msleep(200);
5882 }
5883
Takashi Iwai1d045db2011-07-07 18:23:21 +02005884 snd_hda_codec_resume_amp(codec);
5885 snd_hda_codec_resume_cache(codec);
5886 hda_call_check_power_status(codec, 0x01);
5887 return 0;
5888}
Takashi Iwai2a439522011-07-26 09:52:50 +02005889#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005890
David Henningsson108cc102012-07-20 10:37:25 +02005891static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5892 const struct alc_fixup *fix, int action)
5893{
5894 struct alc_spec *spec = codec->spec;
5895
5896 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5897 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5898}
5899
Takashi Iwai1d045db2011-07-07 18:23:21 +02005900static void alc269_fixup_hweq(struct hda_codec *codec,
5901 const struct alc_fixup *fix, int action)
5902{
5903 int coef;
5904
5905 if (action != ALC_FIXUP_ACT_INIT)
5906 return;
5907 coef = alc_read_coef_idx(codec, 0x1e);
5908 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5909}
5910
5911static void alc271_fixup_dmic(struct hda_codec *codec,
5912 const struct alc_fixup *fix, int action)
5913{
5914 static const struct hda_verb verbs[] = {
5915 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5916 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5917 {}
5918 };
5919 unsigned int cfg;
5920
5921 if (strcmp(codec->chip_name, "ALC271X"))
5922 return;
5923 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5924 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5925 snd_hda_sequence_write(codec, verbs);
5926}
5927
Takashi Iwai017f2a12011-07-09 14:42:25 +02005928static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5929 const struct alc_fixup *fix, int action)
5930{
5931 struct alc_spec *spec = codec->spec;
5932
5933 if (action != ALC_FIXUP_ACT_PROBE)
5934 return;
5935
5936 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5937 * fix the sample rate of analog I/O to 44.1kHz
5938 */
5939 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5940 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5941}
5942
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005943static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5944 const struct alc_fixup *fix, int action)
5945{
5946 int coef;
5947
5948 if (action != ALC_FIXUP_ACT_INIT)
5949 return;
5950 /* The digital-mic unit sends PDM (differential signal) instead of
5951 * the standard PCM, thus you can't record a valid mono stream as is.
5952 * Below is a workaround specific to ALC269 to control the dmic
5953 * signal source as mono.
5954 */
5955 coef = alc_read_coef_idx(codec, 0x07);
5956 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5957}
5958
Takashi Iwai24519912011-08-16 15:08:49 +02005959static void alc269_quanta_automute(struct hda_codec *codec)
5960{
David Henningsson42cf0d02011-09-20 12:04:56 +02005961 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005962
5963 snd_hda_codec_write(codec, 0x20, 0,
5964 AC_VERB_SET_COEF_INDEX, 0x0c);
5965 snd_hda_codec_write(codec, 0x20, 0,
5966 AC_VERB_SET_PROC_COEF, 0x680);
5967
5968 snd_hda_codec_write(codec, 0x20, 0,
5969 AC_VERB_SET_COEF_INDEX, 0x0c);
5970 snd_hda_codec_write(codec, 0x20, 0,
5971 AC_VERB_SET_PROC_COEF, 0x480);
5972}
5973
5974static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5975 const struct alc_fixup *fix, int action)
5976{
5977 struct alc_spec *spec = codec->spec;
5978 if (action != ALC_FIXUP_ACT_PROBE)
5979 return;
5980 spec->automute_hook = alc269_quanta_automute;
5981}
5982
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005983/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5984static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5985{
5986 struct hda_codec *codec = private_data;
5987 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005988 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005989}
5990
5991static void alc269_fixup_mic2_mute(struct hda_codec *codec,
5992 const struct alc_fixup *fix, int action)
5993{
5994 struct alc_spec *spec = codec->spec;
5995 switch (action) {
5996 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005997 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735cb2012-03-13 07:55:10 +01005998 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005999 /* fallthru */
6000 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006001 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006002 break;
6003 }
6004}
6005
Dylan Reid08a978d2012-11-18 22:56:40 -08006006static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6007 const struct alc_fixup *fix,
6008 int action)
6009{
6010 struct alc_spec *spec = codec->spec;
6011
6012 if (action == ALC_FIXUP_ACT_PROBE)
6013 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6014 spec->autocfg.hp_pins[0]);
6015}
David Henningsson693b6132012-06-22 19:12:10 +02006016
Takashi Iwai1d045db2011-07-07 18:23:21 +02006017enum {
6018 ALC269_FIXUP_SONY_VAIO,
6019 ALC275_FIXUP_SONY_VAIO_GPIO2,
6020 ALC269_FIXUP_DELL_M101Z,
6021 ALC269_FIXUP_SKU_IGNORE,
6022 ALC269_FIXUP_ASUS_G73JW,
6023 ALC269_FIXUP_LENOVO_EAPD,
6024 ALC275_FIXUP_SONY_HWEQ,
6025 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006026 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006027 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006028 ALC269_FIXUP_QUANTA_MUTE,
6029 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006030 ALC269_FIXUP_AMIC,
6031 ALC269_FIXUP_DMIC,
6032 ALC269VB_FIXUP_AMIC,
6033 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006034 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006035 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006036 ALC269_FIXUP_LENOVO_DOCK,
6037 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006038 ALC271_FIXUP_AMIC_MIC2,
6039 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006040};
6041
6042static const struct alc_fixup alc269_fixups[] = {
6043 [ALC269_FIXUP_SONY_VAIO] = {
6044 .type = ALC_FIXUP_VERBS,
6045 .v.verbs = (const struct hda_verb[]) {
6046 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6047 {}
6048 }
6049 },
6050 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6051 .type = ALC_FIXUP_VERBS,
6052 .v.verbs = (const struct hda_verb[]) {
6053 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6054 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6055 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6056 { }
6057 },
6058 .chained = true,
6059 .chain_id = ALC269_FIXUP_SONY_VAIO
6060 },
6061 [ALC269_FIXUP_DELL_M101Z] = {
6062 .type = ALC_FIXUP_VERBS,
6063 .v.verbs = (const struct hda_verb[]) {
6064 /* Enables internal speaker */
6065 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6066 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6067 {}
6068 }
6069 },
6070 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006071 .type = ALC_FIXUP_FUNC,
6072 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006073 },
6074 [ALC269_FIXUP_ASUS_G73JW] = {
6075 .type = ALC_FIXUP_PINS,
6076 .v.pins = (const struct alc_pincfg[]) {
6077 { 0x17, 0x99130111 }, /* subwoofer */
6078 { }
6079 }
6080 },
6081 [ALC269_FIXUP_LENOVO_EAPD] = {
6082 .type = ALC_FIXUP_VERBS,
6083 .v.verbs = (const struct hda_verb[]) {
6084 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6085 {}
6086 }
6087 },
6088 [ALC275_FIXUP_SONY_HWEQ] = {
6089 .type = ALC_FIXUP_FUNC,
6090 .v.func = alc269_fixup_hweq,
6091 .chained = true,
6092 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6093 },
6094 [ALC271_FIXUP_DMIC] = {
6095 .type = ALC_FIXUP_FUNC,
6096 .v.func = alc271_fixup_dmic,
6097 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006098 [ALC269_FIXUP_PCM_44K] = {
6099 .type = ALC_FIXUP_FUNC,
6100 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006101 .chained = true,
6102 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006103 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006104 [ALC269_FIXUP_STEREO_DMIC] = {
6105 .type = ALC_FIXUP_FUNC,
6106 .v.func = alc269_fixup_stereo_dmic,
6107 },
Takashi Iwai24519912011-08-16 15:08:49 +02006108 [ALC269_FIXUP_QUANTA_MUTE] = {
6109 .type = ALC_FIXUP_FUNC,
6110 .v.func = alc269_fixup_quanta_mute,
6111 },
6112 [ALC269_FIXUP_LIFEBOOK] = {
6113 .type = ALC_FIXUP_PINS,
6114 .v.pins = (const struct alc_pincfg[]) {
6115 { 0x1a, 0x2101103f }, /* dock line-out */
6116 { 0x1b, 0x23a11040 }, /* dock mic-in */
6117 { }
6118 },
6119 .chained = true,
6120 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6121 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006122 [ALC269_FIXUP_AMIC] = {
6123 .type = ALC_FIXUP_PINS,
6124 .v.pins = (const struct alc_pincfg[]) {
6125 { 0x14, 0x99130110 }, /* speaker */
6126 { 0x15, 0x0121401f }, /* HP out */
6127 { 0x18, 0x01a19c20 }, /* mic */
6128 { 0x19, 0x99a3092f }, /* int-mic */
6129 { }
6130 },
6131 },
6132 [ALC269_FIXUP_DMIC] = {
6133 .type = ALC_FIXUP_PINS,
6134 .v.pins = (const struct alc_pincfg[]) {
6135 { 0x12, 0x99a3092f }, /* int-mic */
6136 { 0x14, 0x99130110 }, /* speaker */
6137 { 0x15, 0x0121401f }, /* HP out */
6138 { 0x18, 0x01a19c20 }, /* mic */
6139 { }
6140 },
6141 },
6142 [ALC269VB_FIXUP_AMIC] = {
6143 .type = ALC_FIXUP_PINS,
6144 .v.pins = (const struct alc_pincfg[]) {
6145 { 0x14, 0x99130110 }, /* speaker */
6146 { 0x18, 0x01a19c20 }, /* mic */
6147 { 0x19, 0x99a3092f }, /* int-mic */
6148 { 0x21, 0x0121401f }, /* HP out */
6149 { }
6150 },
6151 },
David Henningsson2267ea92012-01-03 08:45:56 +01006152 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006153 .type = ALC_FIXUP_PINS,
6154 .v.pins = (const struct alc_pincfg[]) {
6155 { 0x12, 0x99a3092f }, /* int-mic */
6156 { 0x14, 0x99130110 }, /* speaker */
6157 { 0x18, 0x01a19c20 }, /* mic */
6158 { 0x21, 0x0121401f }, /* HP out */
6159 { }
6160 },
6161 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006162 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6163 .type = ALC_FIXUP_FUNC,
6164 .v.func = alc269_fixup_mic2_mute,
6165 },
David Henningsson693b6132012-06-22 19:12:10 +02006166 [ALC269_FIXUP_INV_DMIC] = {
6167 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006168 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006169 },
David Henningsson108cc102012-07-20 10:37:25 +02006170 [ALC269_FIXUP_LENOVO_DOCK] = {
6171 .type = ALC_FIXUP_PINS,
6172 .v.pins = (const struct alc_pincfg[]) {
6173 { 0x19, 0x23a11040 }, /* dock mic */
6174 { 0x1b, 0x2121103f }, /* dock headphone */
6175 { }
6176 },
6177 .chained = true,
6178 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6179 },
6180 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6181 .type = ALC_FIXUP_FUNC,
6182 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6183 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006184 [ALC271_FIXUP_AMIC_MIC2] = {
6185 .type = ALC_FIXUP_PINS,
6186 .v.pins = (const struct alc_pincfg[]) {
6187 { 0x14, 0x99130110 }, /* speaker */
6188 { 0x19, 0x01a19c20 }, /* mic */
6189 { 0x1b, 0x99a7012f }, /* int-mic */
6190 { 0x21, 0x0121401f }, /* HP out */
6191 { }
6192 },
6193 },
6194 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6195 .type = ALC_FIXUP_FUNC,
6196 .v.func = alc271_hp_gate_mic_jack,
6197 .chained = true,
6198 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6199 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006200};
6201
6202static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006203 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6204 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006205 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006206 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006207 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006208 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006209 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006210 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6211 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6212 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6213 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6214 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006215 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6216 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6217 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6218 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6219 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006220 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006221 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006222 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006223 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6224 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6225 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6226 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6227 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006228 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006229 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006230 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006231 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006232 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006233 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006234 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006235
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006236#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006237 /* Below is a quirk table taken from the old code.
6238 * Basically the device should work as is without the fixup table.
6239 * If BIOS doesn't give a proper info, enable the corresponding
6240 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006241 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006242 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6243 ALC269_FIXUP_AMIC),
6244 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006245 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6246 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6247 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6248 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6249 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6250 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6251 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6252 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6253 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6254 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6255 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6256 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6257 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6258 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6259 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6260 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6261 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6262 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6263 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6264 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6265 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6266 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6267 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6268 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6269 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6270 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6271 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6272 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6273 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6274 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6275 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6276 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6277 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6278 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6279 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6280 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6281 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6282 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6283#endif
6284 {}
6285};
6286
6287static const struct alc_model_fixup alc269_fixup_models[] = {
6288 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6289 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006290 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6291 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6292 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006293 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006294 {}
6295};
6296
6297
Takashi Iwai546bb672012-03-07 08:37:19 +01006298static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299{
Kailang Yang526af6e2012-03-07 08:25:20 +01006300 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006301 int val;
6302
Kailang Yang526af6e2012-03-07 08:25:20 +01006303 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006304 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006305
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006306 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006307 alc_write_coef_idx(codec, 0xf, 0x960b);
6308 alc_write_coef_idx(codec, 0xe, 0x8817);
6309 }
6310
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006311 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006312 alc_write_coef_idx(codec, 0xf, 0x960b);
6313 alc_write_coef_idx(codec, 0xe, 0x8814);
6314 }
6315
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006316 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006317 val = alc_read_coef_idx(codec, 0x04);
6318 /* Power up output pin */
6319 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6320 }
6321
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006322 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006323 val = alc_read_coef_idx(codec, 0xd);
6324 if ((val & 0x0c00) >> 10 != 0x1) {
6325 /* Capless ramp up clock control */
6326 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6327 }
6328 val = alc_read_coef_idx(codec, 0x17);
6329 if ((val & 0x01c0) >> 6 != 0x4) {
6330 /* Class D power on reset */
6331 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6332 }
6333 }
6334
6335 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6336 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6337
6338 val = alc_read_coef_idx(codec, 0x4); /* HP */
6339 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006340}
6341
6342/*
6343 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006344static int patch_alc269(struct hda_codec *codec)
6345{
6346 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006347 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006348
Takashi Iwai3de95172012-05-07 18:03:15 +02006349 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006350 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006351 return err;
6352
6353 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006354
Herton Ronaldo Krzesinski9f720bb92012-09-27 10:38:14 -03006355 alc_pick_fixup(codec, alc269_fixup_models,
6356 alc269_fixup_tbl, alc269_fixups);
6357 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6358
6359 alc_auto_parse_customize_define(codec);
6360
Takashi Iwai1d045db2011-07-07 18:23:21 +02006361 if (codec->vendor_id == 0x10ec0269) {
6362 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006363 switch (alc_get_coef0(codec) & 0x00f0) {
6364 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006365 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006366 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006367 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006368 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006369 break;
6370 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006371 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6372 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006373 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006374 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006375 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006376 case 0x0030:
6377 spec->codec_variant = ALC269_TYPE_ALC269VD;
6378 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006379 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006380 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006381 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006382 if (err < 0)
6383 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006384 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006385 alc269_fill_coef(codec);
6386 }
6387
Takashi Iwaia4297b52011-08-23 18:40:12 +02006388 /* automatic parse from the BIOS config */
6389 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006390 if (err < 0)
6391 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006392
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006393 if (!spec->no_analog && has_cdefine_beep(codec)) {
6394 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006395 if (err < 0)
6396 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006397 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006398 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006399
Takashi Iwai1d045db2011-07-07 18:23:21 +02006400 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006401#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006402 codec->patch_ops.resume = alc269_resume;
6403#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006404 spec->shutup = alc269_shutup;
6405
Takashi Iwai589876e2012-02-20 15:47:55 +01006406 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6407
Takashi Iwai1d045db2011-07-07 18:23:21 +02006408 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006409
6410 error:
6411 alc_free(codec);
6412 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006413}
6414
6415/*
6416 * ALC861
6417 */
6418
Takashi Iwai1d045db2011-07-07 18:23:21 +02006419static int alc861_parse_auto_config(struct hda_codec *codec)
6420{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006421 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006422 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6423 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006424}
6425
Takashi Iwai1d045db2011-07-07 18:23:21 +02006426/* Pin config fixes */
6427enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006428 ALC861_FIXUP_FSC_AMILO_PI1505,
6429 ALC861_FIXUP_AMP_VREF_0F,
6430 ALC861_FIXUP_NO_JACK_DETECT,
6431 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006432};
6433
Takashi Iwai31150f22012-01-30 10:54:08 +01006434/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6435static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6436 const struct alc_fixup *fix, int action)
6437{
6438 struct alc_spec *spec = codec->spec;
6439 unsigned int val;
6440
6441 if (action != ALC_FIXUP_ACT_INIT)
6442 return;
6443 val = snd_hda_codec_read(codec, 0x0f, 0,
6444 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6445 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6446 val |= AC_PINCTL_IN_EN;
6447 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006448 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006449 spec->keep_vref_in_automute = 1;
6450}
6451
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006452/* suppress the jack-detection */
6453static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6454 const struct alc_fixup *fix, int action)
6455{
6456 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6457 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006458}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006459
Takashi Iwai1d045db2011-07-07 18:23:21 +02006460static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006461 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006462 .type = ALC_FIXUP_PINS,
6463 .v.pins = (const struct alc_pincfg[]) {
6464 { 0x0b, 0x0221101f }, /* HP */
6465 { 0x0f, 0x90170310 }, /* speaker */
6466 { }
6467 }
6468 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006469 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006470 .type = ALC_FIXUP_FUNC,
6471 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006472 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006473 [ALC861_FIXUP_NO_JACK_DETECT] = {
6474 .type = ALC_FIXUP_FUNC,
6475 .v.func = alc_fixup_no_jack_detect,
6476 },
6477 [ALC861_FIXUP_ASUS_A6RP] = {
6478 .type = ALC_FIXUP_FUNC,
6479 .v.func = alc861_fixup_asus_amp_vref_0f,
6480 .chained = true,
6481 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6482 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006483};
6484
6485static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006486 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6487 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6488 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6489 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6490 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6491 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006492 {}
6493};
6494
6495/*
6496 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006497static int patch_alc861(struct hda_codec *codec)
6498{
6499 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006500 int err;
6501
Takashi Iwai3de95172012-05-07 18:03:15 +02006502 err = alc_alloc_spec(codec, 0x15);
6503 if (err < 0)
6504 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006505
Takashi Iwai3de95172012-05-07 18:03:15 +02006506 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006507
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006508 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6509 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006510
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006511 /* automatic parse from the BIOS config */
6512 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006513 if (err < 0)
6514 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006515
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006516 if (!spec->no_analog) {
6517 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006518 if (err < 0)
6519 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006520 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6521 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006522
Takashi Iwai1d045db2011-07-07 18:23:21 +02006523 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006524#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006525 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006526#endif
6527
Takashi Iwai589876e2012-02-20 15:47:55 +01006528 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6529
Takashi Iwai1d045db2011-07-07 18:23:21 +02006530 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006531
6532 error:
6533 alc_free(codec);
6534 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006535}
6536
6537/*
6538 * ALC861-VD support
6539 *
6540 * Based on ALC882
6541 *
6542 * In addition, an independent DAC
6543 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006544static int alc861vd_parse_auto_config(struct hda_codec *codec)
6545{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006546 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006547 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6548 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006549}
6550
Takashi Iwai1d045db2011-07-07 18:23:21 +02006551enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006552 ALC660VD_FIX_ASUS_GPIO1,
6553 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006554};
6555
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006556/* exclude VREF80 */
6557static void alc861vd_fixup_dallas(struct hda_codec *codec,
6558 const struct alc_fixup *fix, int action)
6559{
6560 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6561 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6562 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6563 }
6564}
6565
Takashi Iwai1d045db2011-07-07 18:23:21 +02006566static const struct alc_fixup alc861vd_fixups[] = {
6567 [ALC660VD_FIX_ASUS_GPIO1] = {
6568 .type = ALC_FIXUP_VERBS,
6569 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006570 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006571 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6572 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6573 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6574 { }
6575 }
6576 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006577 [ALC861VD_FIX_DALLAS] = {
6578 .type = ALC_FIXUP_FUNC,
6579 .v.func = alc861vd_fixup_dallas,
6580 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006581};
6582
6583static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006584 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006585 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006586 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006587 {}
6588};
6589
Takashi Iwai1d045db2011-07-07 18:23:21 +02006590/*
6591 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006592static int patch_alc861vd(struct hda_codec *codec)
6593{
6594 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006595 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006596
Takashi Iwai3de95172012-05-07 18:03:15 +02006597 err = alc_alloc_spec(codec, 0x0b);
6598 if (err < 0)
6599 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006600
Takashi Iwai3de95172012-05-07 18:03:15 +02006601 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006602
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006603 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6604 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006605
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006606 /* automatic parse from the BIOS config */
6607 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006608 if (err < 0)
6609 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006610
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006611 if (!spec->no_analog) {
6612 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006613 if (err < 0)
6614 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006615 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6616 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006617
Takashi Iwai1d045db2011-07-07 18:23:21 +02006618 codec->patch_ops = alc_patch_ops;
6619
Takashi Iwai1d045db2011-07-07 18:23:21 +02006620 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006621
Takashi Iwai589876e2012-02-20 15:47:55 +01006622 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6623
Takashi Iwai1d045db2011-07-07 18:23:21 +02006624 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006625
6626 error:
6627 alc_free(codec);
6628 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006629}
6630
6631/*
6632 * ALC662 support
6633 *
6634 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6635 * configuration. Each pin widget can choose any input DACs and a mixer.
6636 * Each ADC is connected from a mixer of all inputs. This makes possible
6637 * 6-channel independent captures.
6638 *
6639 * In addition, an independent DAC for the multi-playback (not used in this
6640 * driver yet).
6641 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006642
6643/*
6644 * BIOS auto configuration
6645 */
6646
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006647static int alc662_parse_auto_config(struct hda_codec *codec)
6648{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006649 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006650 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6651 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6652 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006653
Kailang Yang6227cdc2010-02-25 08:36:52 +01006654 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6655 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006656 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006657 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006658 ssids = alc662_ssids;
6659 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006660}
6661
Todd Broch6be79482010-12-07 16:51:05 -08006662static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006663 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006664{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006665 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006666 return;
Todd Broch6be79482010-12-07 16:51:05 -08006667 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6668 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6669 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6670 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6671 (0 << AC_AMPCAP_MUTE_SHIFT)))
6672 printk(KERN_WARNING
6673 "hda_codec: failed to override amp caps for NID 0x2\n");
6674}
6675
David Henningsson6cb3b702010-09-09 08:51:44 +02006676enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006677 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006678 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006679 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006680 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006681 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006682 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006683 ALC662_FIXUP_ASUS_MODE1,
6684 ALC662_FIXUP_ASUS_MODE2,
6685 ALC662_FIXUP_ASUS_MODE3,
6686 ALC662_FIXUP_ASUS_MODE4,
6687 ALC662_FIXUP_ASUS_MODE5,
6688 ALC662_FIXUP_ASUS_MODE6,
6689 ALC662_FIXUP_ASUS_MODE7,
6690 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006691 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006692 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006693 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006694};
6695
6696static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006697 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006698 .type = ALC_FIXUP_PINS,
6699 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006700 { 0x15, 0x99130112 }, /* subwoofer */
6701 { }
6702 }
6703 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006704 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006705 .type = ALC_FIXUP_PINS,
6706 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006707 { 0x17, 0x99130112 }, /* subwoofer */
6708 { }
6709 }
6710 },
Todd Broch6be79482010-12-07 16:51:05 -08006711 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006712 .type = ALC_FIXUP_FUNC,
6713 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006714 },
6715 [ALC662_FIXUP_CZC_P10T] = {
6716 .type = ALC_FIXUP_VERBS,
6717 .v.verbs = (const struct hda_verb[]) {
6718 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6719 {}
6720 }
6721 },
David Henningsson94024cd2011-04-29 14:10:55 +02006722 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006723 .type = ALC_FIXUP_FUNC,
6724 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006725 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006726 [ALC662_FIXUP_HP_RP5800] = {
6727 .type = ALC_FIXUP_PINS,
6728 .v.pins = (const struct alc_pincfg[]) {
6729 { 0x14, 0x0221201f }, /* HP out */
6730 { }
6731 },
6732 .chained = true,
6733 .chain_id = ALC662_FIXUP_SKU_IGNORE
6734 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006735 [ALC662_FIXUP_ASUS_MODE1] = {
6736 .type = ALC_FIXUP_PINS,
6737 .v.pins = (const struct alc_pincfg[]) {
6738 { 0x14, 0x99130110 }, /* speaker */
6739 { 0x18, 0x01a19c20 }, /* mic */
6740 { 0x19, 0x99a3092f }, /* int-mic */
6741 { 0x21, 0x0121401f }, /* HP out */
6742 { }
6743 },
6744 .chained = true,
6745 .chain_id = ALC662_FIXUP_SKU_IGNORE
6746 },
6747 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006748 .type = ALC_FIXUP_PINS,
6749 .v.pins = (const struct alc_pincfg[]) {
6750 { 0x14, 0x99130110 }, /* speaker */
6751 { 0x18, 0x01a19820 }, /* mic */
6752 { 0x19, 0x99a3092f }, /* int-mic */
6753 { 0x1b, 0x0121401f }, /* HP out */
6754 { }
6755 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006756 .chained = true,
6757 .chain_id = ALC662_FIXUP_SKU_IGNORE
6758 },
6759 [ALC662_FIXUP_ASUS_MODE3] = {
6760 .type = ALC_FIXUP_PINS,
6761 .v.pins = (const struct alc_pincfg[]) {
6762 { 0x14, 0x99130110 }, /* speaker */
6763 { 0x15, 0x0121441f }, /* HP */
6764 { 0x18, 0x01a19840 }, /* mic */
6765 { 0x19, 0x99a3094f }, /* int-mic */
6766 { 0x21, 0x01211420 }, /* HP2 */
6767 { }
6768 },
6769 .chained = true,
6770 .chain_id = ALC662_FIXUP_SKU_IGNORE
6771 },
6772 [ALC662_FIXUP_ASUS_MODE4] = {
6773 .type = ALC_FIXUP_PINS,
6774 .v.pins = (const struct alc_pincfg[]) {
6775 { 0x14, 0x99130110 }, /* speaker */
6776 { 0x16, 0x99130111 }, /* speaker */
6777 { 0x18, 0x01a19840 }, /* mic */
6778 { 0x19, 0x99a3094f }, /* int-mic */
6779 { 0x21, 0x0121441f }, /* HP */
6780 { }
6781 },
6782 .chained = true,
6783 .chain_id = ALC662_FIXUP_SKU_IGNORE
6784 },
6785 [ALC662_FIXUP_ASUS_MODE5] = {
6786 .type = ALC_FIXUP_PINS,
6787 .v.pins = (const struct alc_pincfg[]) {
6788 { 0x14, 0x99130110 }, /* speaker */
6789 { 0x15, 0x0121441f }, /* HP */
6790 { 0x16, 0x99130111 }, /* speaker */
6791 { 0x18, 0x01a19840 }, /* mic */
6792 { 0x19, 0x99a3094f }, /* int-mic */
6793 { }
6794 },
6795 .chained = true,
6796 .chain_id = ALC662_FIXUP_SKU_IGNORE
6797 },
6798 [ALC662_FIXUP_ASUS_MODE6] = {
6799 .type = ALC_FIXUP_PINS,
6800 .v.pins = (const struct alc_pincfg[]) {
6801 { 0x14, 0x99130110 }, /* speaker */
6802 { 0x15, 0x01211420 }, /* HP2 */
6803 { 0x18, 0x01a19840 }, /* mic */
6804 { 0x19, 0x99a3094f }, /* int-mic */
6805 { 0x1b, 0x0121441f }, /* HP */
6806 { }
6807 },
6808 .chained = true,
6809 .chain_id = ALC662_FIXUP_SKU_IGNORE
6810 },
6811 [ALC662_FIXUP_ASUS_MODE7] = {
6812 .type = ALC_FIXUP_PINS,
6813 .v.pins = (const struct alc_pincfg[]) {
6814 { 0x14, 0x99130110 }, /* speaker */
6815 { 0x17, 0x99130111 }, /* speaker */
6816 { 0x18, 0x01a19840 }, /* mic */
6817 { 0x19, 0x99a3094f }, /* int-mic */
6818 { 0x1b, 0x01214020 }, /* HP */
6819 { 0x21, 0x0121401f }, /* HP */
6820 { }
6821 },
6822 .chained = true,
6823 .chain_id = ALC662_FIXUP_SKU_IGNORE
6824 },
6825 [ALC662_FIXUP_ASUS_MODE8] = {
6826 .type = ALC_FIXUP_PINS,
6827 .v.pins = (const struct alc_pincfg[]) {
6828 { 0x14, 0x99130110 }, /* speaker */
6829 { 0x12, 0x99a30970 }, /* int-mic */
6830 { 0x15, 0x01214020 }, /* HP */
6831 { 0x17, 0x99130111 }, /* speaker */
6832 { 0x18, 0x01a19840 }, /* mic */
6833 { 0x21, 0x0121401f }, /* HP */
6834 { }
6835 },
6836 .chained = true,
6837 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006838 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006839 [ALC662_FIXUP_NO_JACK_DETECT] = {
6840 .type = ALC_FIXUP_FUNC,
6841 .v.func = alc_fixup_no_jack_detect,
6842 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006843 [ALC662_FIXUP_ZOTAC_Z68] = {
6844 .type = ALC_FIXUP_PINS,
6845 .v.pins = (const struct alc_pincfg[]) {
6846 { 0x1b, 0x02214020 }, /* Front HP */
6847 { }
6848 }
6849 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006850 [ALC662_FIXUP_INV_DMIC] = {
6851 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006852 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006853 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006854};
6855
Takashi Iwaia9111322011-05-02 11:30:18 +02006856static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006857 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006858 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006859 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006860 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006861 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006862 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006863 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006864 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006865 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006866 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006867 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006868 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006869 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006870
6871#if 0
6872 /* Below is a quirk table taken from the old code.
6873 * Basically the device should work as is without the fixup table.
6874 * If BIOS doesn't give a proper info, enable the corresponding
6875 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006876 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006877 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6878 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6879 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6880 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6881 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6882 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6883 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6884 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6885 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6886 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6887 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6888 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6889 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6890 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6891 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6892 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6893 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6894 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6895 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6896 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6897 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6898 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6899 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6900 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6901 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6902 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6903 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6904 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6905 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6906 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6907 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6908 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6909 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6910 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6911 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6912 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6913 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6914 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6915 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6916 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6917 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6918 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6919 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6920 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6921 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6922 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6923 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6924 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6925 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6926 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6927#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006928 {}
6929};
6930
Todd Broch6be79482010-12-07 16:51:05 -08006931static const struct alc_model_fixup alc662_fixup_models[] = {
6932 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006933 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6934 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6935 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6936 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6937 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6938 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6939 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6940 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006941 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08006942 {}
6943};
David Henningsson6cb3b702010-09-09 08:51:44 +02006944
Kailang Yang8663ff72012-06-29 09:35:52 +02006945static void alc662_fill_coef(struct hda_codec *codec)
6946{
6947 int val, coef;
6948
6949 coef = alc_get_coef0(codec);
6950
6951 switch (codec->vendor_id) {
6952 case 0x10ec0662:
6953 if ((coef & 0x00f0) == 0x0030) {
6954 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
6955 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
6956 }
6957 break;
6958 case 0x10ec0272:
6959 case 0x10ec0273:
6960 case 0x10ec0663:
6961 case 0x10ec0665:
6962 case 0x10ec0670:
6963 case 0x10ec0671:
6964 case 0x10ec0672:
6965 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
6966 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6967 break;
6968 }
6969}
David Henningsson6cb3b702010-09-09 08:51:44 +02006970
Takashi Iwai1d045db2011-07-07 18:23:21 +02006971/*
6972 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006973static int patch_alc662(struct hda_codec *codec)
6974{
6975 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006976 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006977
Takashi Iwai3de95172012-05-07 18:03:15 +02006978 err = alc_alloc_spec(codec, 0x0b);
6979 if (err < 0)
6980 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006981
Takashi Iwai3de95172012-05-07 18:03:15 +02006982 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006983
Takashi Iwai53c334a2011-08-23 18:27:14 +02006984 /* handle multiple HPs as is */
6985 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6986
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006987 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6988
Kailang Yang8663ff72012-06-29 09:35:52 +02006989 spec->init_hook = alc662_fill_coef;
6990 alc662_fill_coef(codec);
6991
Takashi Iwai8e5a0502012-06-21 15:49:33 +02006992 alc_pick_fixup(codec, alc662_fixup_models,
6993 alc662_fixup_tbl, alc662_fixups);
6994 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6995
6996 alc_auto_parse_customize_define(codec);
6997
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006998 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006999 codec->bus->pci->subsystem_vendor == 0x1025 &&
7000 spec->cdefine.platform_type == 1) {
7001 if (alc_codec_rename(codec, "ALC272X") < 0)
7002 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007003 }
Kailang Yang274693f2009-12-03 10:07:50 +01007004
Takashi Iwaib9c51062011-08-24 18:08:07 +02007005 /* automatic parse from the BIOS config */
7006 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007007 if (err < 0)
7008 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007009
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007010 if (!spec->no_analog && has_cdefine_beep(codec)) {
7011 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007012 if (err < 0)
7013 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007014 switch (codec->vendor_id) {
7015 case 0x10ec0662:
7016 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7017 break;
7018 case 0x10ec0272:
7019 case 0x10ec0663:
7020 case 0x10ec0665:
7021 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7022 break;
7023 case 0x10ec0273:
7024 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7025 break;
7026 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007027 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007028
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007029 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02007030 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007031
Takashi Iwai589876e2012-02-20 15:47:55 +01007032 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7033
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007034 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007035
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007036 error:
7037 alc_free(codec);
7038 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007039}
7040
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007041/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007042 * ALC680 support
7043 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007044
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007045static int alc680_parse_auto_config(struct hda_codec *codec)
7046{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007047 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007048}
7049
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007050/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007051 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007052static int patch_alc680(struct hda_codec *codec)
7053{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007054 int err;
7055
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007056 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007057 err = alc_alloc_spec(codec, 0);
7058 if (err < 0)
7059 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007060
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007061 /* automatic parse from the BIOS config */
7062 err = alc680_parse_auto_config(codec);
7063 if (err < 0) {
7064 alc_free(codec);
7065 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007066 }
7067
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007068 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007069
7070 return 0;
7071}
7072
7073/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007074 * patch entries
7075 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007076static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007077 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007078 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007079 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007080 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007081 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007082 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007083 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007084 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007085 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007086 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007087 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007088 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007089 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
7090 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007091 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007092 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007093 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007094 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7095 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7096 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007097 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007098 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007099 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7100 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007101 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7102 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007103 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007104 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007105 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007106 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007107 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007108 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007109 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007110 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007111 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007112 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007113 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007114 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007115 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007116 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007117 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007118 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007119 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007120 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007121 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007122 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007123 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007124 {} /* terminator */
7125};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007126
7127MODULE_ALIAS("snd-hda-codec-id:10ec*");
7128
7129MODULE_LICENSE("GPL");
7130MODULE_DESCRIPTION("Realtek HD-audio codec");
7131
7132static struct hda_codec_preset_list realtek_list = {
7133 .preset = snd_hda_preset_realtek,
7134 .owner = THIS_MODULE,
7135};
7136
7137static int __init patch_realtek_init(void)
7138{
7139 return snd_hda_add_codec_preset(&realtek_list);
7140}
7141
7142static void __exit patch_realtek_exit(void)
7143{
7144 snd_hda_delete_codec_preset(&realtek_list);
7145}
7146
7147module_init(patch_realtek_init)
7148module_exit(patch_realtek_exit)