blob: 613499932b2ba3f565a8834312baf3712d51b772 [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 */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200597static void alc_hp_automute(struct hda_codec *codec)
598{
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 */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200610static void alc_line_automute(struct hda_codec *codec)
611{
612 struct alc_spec *spec = codec->spec;
613
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200614 /* check LO jack only when it's different from HP */
615 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
616 return;
617
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200618 spec->line_jack_present =
619 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
620 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200621 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200622 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200623 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200624}
625
Takashi Iwai8d087c72011-06-28 12:45:47 +0200626#define get_connection_index(codec, mux, nid) \
627 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200628
Takashi Iwai1d045db2011-07-07 18:23:21 +0200629/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200630static void alc_mic_automute(struct hda_codec *codec)
631{
632 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200633 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200634
Takashi Iwai21268962011-07-07 15:01:13 +0200635 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200636 return;
637 if (snd_BUG_ON(!spec->adc_nids))
638 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200639 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200640 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200641
Takashi Iwai21268962011-07-07 15:01:13 +0200642 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
643 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
644 else if (spec->dock_mic_idx >= 0 &&
645 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
646 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
647 else
648 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200649}
650
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100651/* handle the specified unsol action (ALC_XXX_EVENT) */
652static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200653{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100654 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200655 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200656 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200657 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200658 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200659 alc_line_automute(codec);
660 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200661 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200662 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200663 break;
664 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200665 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200666}
667
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100668/* update the master volume per volume-knob's unsol event */
669static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
670{
671 unsigned int val;
672 struct snd_kcontrol *kctl;
673 struct snd_ctl_elem_value *uctl;
674
675 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
676 if (!kctl)
677 return;
678 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
679 if (!uctl)
680 return;
681 val = snd_hda_codec_read(codec, nid, 0,
682 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
683 val &= HDA_AMP_VOLMASK;
684 uctl->value.integer.value[0] = val;
685 uctl->value.integer.value[1] = val;
686 kctl->put(kctl, uctl);
687 kfree(uctl);
688}
689
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100690/* unsolicited event for HP jack sensing */
David Henningssona7a0a642012-07-05 12:00:12 +0200691static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100692{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100693 int action;
694
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100695 if (codec->vendor_id == 0x10ec0880)
696 res >>= 28;
697 else
698 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100699 action = snd_hda_jack_get_action(codec, res);
David Henningssone21af482012-03-05 11:38:46 +0100700 if (action == ALC_DCVOL_EVENT) {
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100701 /* Execute the dc-vol event here as it requires the NID
702 * but we don't pass NID to alc_exec_unsol_event().
703 * Once when we convert all static quirks to the auto-parser,
704 * this can be integerated into there.
705 */
706 struct hda_jack_tbl *jack;
707 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
708 if (jack)
709 alc_update_knob_master(codec, jack->nid);
710 return;
711 }
712 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100713}
714
Takashi Iwai1d045db2011-07-07 18:23:21 +0200715/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200716static void alc_inithook(struct hda_codec *codec)
717{
Takashi Iwaid922b512011-04-28 12:18:53 +0200718 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200719 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200720 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200721}
722
Kailang Yangf9423e72008-05-27 12:32:25 +0200723/* additional initialization for ALC888 variants */
724static void alc888_coef_init(struct hda_codec *codec)
725{
726 unsigned int tmp;
727
728 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
729 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
730 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100731 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200732 /* alc888S-VC */
733 snd_hda_codec_read(codec, 0x20, 0,
734 AC_VERB_SET_PROC_COEF, 0x830);
735 else
736 /* alc888-VB */
737 snd_hda_codec_read(codec, 0x20, 0,
738 AC_VERB_SET_PROC_COEF, 0x3030);
739}
740
Takashi Iwai1d045db2011-07-07 18:23:21 +0200741/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200742static void alc889_coef_init(struct hda_codec *codec)
743{
744 unsigned int tmp;
745
746 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
747 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
748 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
749 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
750}
751
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100752/* turn on/off EAPD control (only if available) */
753static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
754{
755 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
756 return;
757 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
758 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
759 on ? 2 : 0);
760}
761
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200762/* turn on/off EAPD controls of the codec */
763static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
764{
765 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200766 static hda_nid_t pins[] = {
767 0x0f, 0x10, 0x14, 0x15, 0
768 };
769 hda_nid_t *p;
770 for (p = pins; *p; p++)
771 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200772}
773
Takashi Iwai1c7161532011-04-07 10:37:16 +0200774/* generic shutup callback;
775 * just turning off EPAD and a little pause for avoiding pop-noise
776 */
777static void alc_eapd_shutup(struct hda_codec *codec)
778{
779 alc_auto_setup_eapd(codec, false);
780 msleep(200);
781}
782
Takashi Iwai1d045db2011-07-07 18:23:21 +0200783/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200784static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200785{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200786 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200787
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200788 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200789 switch (type) {
790 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200791 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
792 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200793 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200794 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
795 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200796 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200797 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
798 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200799 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200800 switch (codec->vendor_id) {
801 case 0x10ec0260:
802 snd_hda_codec_write(codec, 0x1a, 0,
803 AC_VERB_SET_COEF_INDEX, 7);
804 tmp = snd_hda_codec_read(codec, 0x1a, 0,
805 AC_VERB_GET_PROC_COEF, 0);
806 snd_hda_codec_write(codec, 0x1a, 0,
807 AC_VERB_SET_COEF_INDEX, 7);
808 snd_hda_codec_write(codec, 0x1a, 0,
809 AC_VERB_SET_PROC_COEF,
810 tmp | 0x2010);
811 break;
812 case 0x10ec0262:
813 case 0x10ec0880:
814 case 0x10ec0882:
815 case 0x10ec0883:
816 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100817 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100818 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200819 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200820 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200821 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200822 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200823 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100824#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200825 case 0x10ec0267:
826 case 0x10ec0268:
827 snd_hda_codec_write(codec, 0x20, 0,
828 AC_VERB_SET_COEF_INDEX, 7);
829 tmp = snd_hda_codec_read(codec, 0x20, 0,
830 AC_VERB_GET_PROC_COEF, 0);
831 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200832 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200833 snd_hda_codec_write(codec, 0x20, 0,
834 AC_VERB_SET_PROC_COEF,
835 tmp | 0x3000);
836 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100837#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200838 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200839 break;
840 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200841}
Kailang Yangea1fb292008-08-26 12:58:38 +0200842
Takashi Iwai1d045db2011-07-07 18:23:21 +0200843/*
844 * Auto-Mute mode mixer enum support
845 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200846static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
847 struct snd_ctl_elem_info *uinfo)
848{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
850 struct alc_spec *spec = codec->spec;
851 static const char * const texts2[] = {
852 "Disabled", "Enabled"
853 };
854 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100855 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200856 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200857 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200858
859 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
860 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200861 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200862 uinfo->value.enumerated.items = 3;
863 texts = texts3;
864 } else {
865 uinfo->value.enumerated.items = 2;
866 texts = texts2;
867 }
868 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
869 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200870 strcpy(uinfo->value.enumerated.name,
871 texts[uinfo->value.enumerated.item]);
872 return 0;
873}
874
875static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
876 struct snd_ctl_elem_value *ucontrol)
877{
878 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
879 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200880 unsigned int val = 0;
881 if (spec->automute_speaker)
882 val++;
883 if (spec->automute_lo)
884 val++;
885
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200886 ucontrol->value.enumerated.item[0] = val;
887 return 0;
888}
889
890static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
891 struct snd_ctl_elem_value *ucontrol)
892{
893 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
894 struct alc_spec *spec = codec->spec;
895
896 switch (ucontrol->value.enumerated.item[0]) {
897 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200898 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200900 spec->automute_speaker = 0;
901 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200902 break;
903 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200904 if (spec->automute_speaker_possible) {
905 if (!spec->automute_lo && spec->automute_speaker)
906 return 0;
907 spec->automute_speaker = 1;
908 spec->automute_lo = 0;
909 } else if (spec->automute_lo_possible) {
910 if (spec->automute_lo)
911 return 0;
912 spec->automute_lo = 1;
913 } else
914 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200915 break;
916 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200917 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200918 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200919 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200920 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200921 spec->automute_speaker = 1;
922 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200923 break;
924 default:
925 return -EINVAL;
926 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200927 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200928 return 1;
929}
930
Takashi Iwaia9111322011-05-02 11:30:18 +0200931static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200932 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
933 .name = "Auto-Mute Mode",
934 .info = alc_automute_mode_info,
935 .get = alc_automute_mode_get,
936 .put = alc_automute_mode_put,
937};
938
Takashi Iwai1d045db2011-07-07 18:23:21 +0200939static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
940{
941 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
942 return snd_array_new(&spec->kctls);
943}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200944
945static int alc_add_automute_mode_enum(struct hda_codec *codec)
946{
947 struct alc_spec *spec = codec->spec;
948 struct snd_kcontrol_new *knew;
949
950 knew = alc_kcontrol_new(spec);
951 if (!knew)
952 return -ENOMEM;
953 *knew = alc_automute_mode_enum;
954 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
955 if (!knew->name)
956 return -ENOMEM;
957 return 0;
958}
959
Takashi Iwai1d045db2011-07-07 18:23:21 +0200960/*
961 * Check the availability of HP/line-out auto-mute;
962 * Set up appropriately if really supported
963 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200964static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200965{
966 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200967 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200968 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200969 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200970
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200971 if (cfg->hp_pins[0])
972 present++;
973 if (cfg->line_out_pins[0])
974 present++;
975 if (cfg->speaker_pins[0])
976 present++;
977 if (present < 2) /* need two different output types */
978 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200979
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200980 if (!cfg->speaker_pins[0] &&
981 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200982 memcpy(cfg->speaker_pins, cfg->line_out_pins,
983 sizeof(cfg->speaker_pins));
984 cfg->speaker_outs = cfg->line_outs;
985 }
986
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200987 if (!cfg->hp_pins[0] &&
988 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200989 memcpy(cfg->hp_pins, cfg->line_out_pins,
990 sizeof(cfg->hp_pins));
991 cfg->hp_outs = cfg->line_outs;
992 }
993
David Henningsson42cf0d02011-09-20 12:04:56 +0200994 spec->automute_mode = ALC_AUTOMUTE_PIN;
995
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200996 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200997 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200998 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200999 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +02001000 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001001 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001002 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001003 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001004 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001005
David Henningsson42cf0d02011-09-20 12:04:56 +02001006 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
1007 if (cfg->speaker_outs)
1008 for (i = 0; i < cfg->line_outs; i++) {
1009 hda_nid_t nid = cfg->line_out_pins[i];
1010 if (!is_jack_detectable(codec, nid))
1011 continue;
1012 snd_printdd("realtek: Enable Line-Out "
1013 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001014 snd_hda_jack_detect_enable(codec, nid,
1015 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001016 spec->detect_lo = 1;
1017 }
1018 spec->automute_lo_possible = spec->detect_hp;
1019 }
1020
1021 spec->automute_speaker_possible = cfg->speaker_outs &&
1022 (spec->detect_hp || spec->detect_lo);
1023
1024 spec->automute_lo = spec->automute_lo_possible;
1025 spec->automute_speaker = spec->automute_speaker_possible;
1026
David Henningssona7a0a642012-07-05 12:00:12 +02001027 if (spec->automute_speaker_possible || spec->automute_lo_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001028 /* create a control for automute mode */
1029 alc_add_automute_mode_enum(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001030}
1031
Takashi Iwai1d045db2011-07-07 18:23:21 +02001032/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001033static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1034{
1035 int i;
1036 for (i = 0; i < nums; i++)
1037 if (list[i] == nid)
1038 return i;
1039 return -1;
1040}
1041
Takashi Iwai1d045db2011-07-07 18:23:21 +02001042/* check whether dynamic ADC-switching is available */
1043static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1044{
1045 struct alc_spec *spec = codec->spec;
1046 struct hda_input_mux *imux = &spec->private_imux[0];
1047 int i, n, idx;
1048 hda_nid_t cap, pin;
1049
1050 if (imux != spec->input_mux) /* no dynamic imux? */
1051 return false;
1052
1053 for (n = 0; n < spec->num_adc_nids; n++) {
1054 cap = spec->private_capsrc_nids[n];
1055 for (i = 0; i < imux->num_items; i++) {
1056 pin = spec->imux_pins[i];
1057 if (!pin)
1058 return false;
1059 if (get_connection_index(codec, cap, pin) < 0)
1060 break;
1061 }
1062 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001063 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001064 }
1065
1066 for (i = 0; i < imux->num_items; i++) {
1067 pin = spec->imux_pins[i];
1068 for (n = 0; n < spec->num_adc_nids; n++) {
1069 cap = spec->private_capsrc_nids[n];
1070 idx = get_connection_index(codec, cap, pin);
1071 if (idx >= 0) {
1072 imux->items[i].index = idx;
1073 spec->dyn_adc_idx[i] = n;
1074 break;
1075 }
1076 }
1077 }
1078
1079 snd_printdd("realtek: enabling ADC switching\n");
1080 spec->dyn_adc_switch = 1;
1081 return true;
1082}
Takashi Iwai21268962011-07-07 15:01:13 +02001083
Takashi Iwai21268962011-07-07 15:01:13 +02001084/* check whether all auto-mic pins are valid; setup indices if OK */
1085static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1086{
1087 struct alc_spec *spec = codec->spec;
1088 const struct hda_input_mux *imux;
1089
1090 if (!spec->auto_mic)
1091 return false;
1092 if (spec->auto_mic_valid_imux)
1093 return true; /* already checked */
1094
1095 /* fill up imux indices */
1096 if (!alc_check_dyn_adc_switch(codec)) {
1097 spec->auto_mic = 0;
1098 return false;
1099 }
1100
1101 imux = spec->input_mux;
1102 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1103 spec->imux_pins, imux->num_items);
1104 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1105 spec->imux_pins, imux->num_items);
1106 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1107 spec->imux_pins, imux->num_items);
1108 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1109 spec->auto_mic = 0;
1110 return false; /* no corresponding imux */
1111 }
1112
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001113 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001114 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001115 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1116 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001117
1118 spec->auto_mic_valid_imux = 1;
1119 spec->auto_mic = 1;
1120 return true;
1121}
1122
Takashi Iwai1d045db2011-07-07 18:23:21 +02001123/*
1124 * Check the availability of auto-mic switch;
1125 * Set up if really supported
1126 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001127static void alc_init_auto_mic(struct hda_codec *codec)
1128{
1129 struct alc_spec *spec = codec->spec;
1130 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001131 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001132 int i;
1133
Takashi Iwai24de1832011-11-07 17:13:39 +01001134 if (spec->shared_mic_hp)
1135 return; /* no auto-mic for the shared I/O */
1136
Takashi Iwai21268962011-07-07 15:01:13 +02001137 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1138
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001139 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001140 for (i = 0; i < cfg->num_inputs; i++) {
1141 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001142 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001143 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001144 switch (snd_hda_get_input_pin_attr(defcfg)) {
1145 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001146 if (fixed)
1147 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001148 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1149 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001150 fixed = nid;
1151 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001152 case INPUT_PIN_ATTR_UNUSED:
1153 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001154 case INPUT_PIN_ATTR_DOCK:
1155 if (dock)
1156 return; /* already occupied */
1157 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1158 return; /* invalid type */
1159 dock = nid;
1160 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001161 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001162 if (ext)
1163 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001164 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1165 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001166 ext = nid;
1167 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001168 }
1169 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001170 if (!ext && dock) {
1171 ext = dock;
1172 dock = 0;
1173 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001174 if (!ext || !fixed)
1175 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001176 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001177 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001178 if (dock && !is_jack_detectable(codec, dock))
1179 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001180
1181 /* check imux indices */
1182 spec->ext_mic_pin = ext;
1183 spec->int_mic_pin = fixed;
1184 spec->dock_mic_pin = dock;
1185
1186 spec->auto_mic = 1;
1187 if (!alc_auto_mic_check_imux(codec))
1188 return;
1189
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001190 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1191 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001192}
1193
Takashi Iwai1d045db2011-07-07 18:23:21 +02001194/* check the availabilities of auto-mute and auto-mic switches */
1195static void alc_auto_check_switches(struct hda_codec *codec)
1196{
David Henningsson42cf0d02011-09-20 12:04:56 +02001197 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001198 alc_init_auto_mic(codec);
1199}
1200
1201/*
1202 * Realtek SSID verification
1203 */
1204
David Henningsson90622912010-10-14 14:50:18 +02001205/* Could be any non-zero and even value. When used as fixup, tells
1206 * the driver to ignore any present sku defines.
1207 */
1208#define ALC_FIXUP_SKU_IGNORE (2)
1209
Takashi Iwai23d30f22012-05-07 17:17:32 +02001210static void alc_fixup_sku_ignore(struct hda_codec *codec,
1211 const struct hda_fixup *fix, int action)
1212{
1213 struct alc_spec *spec = codec->spec;
1214 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1215 spec->cdefine.fixup = 1;
1216 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1217 }
1218}
1219
Kailang Yangda00c242010-03-19 11:23:45 +01001220static int alc_auto_parse_customize_define(struct hda_codec *codec)
1221{
1222 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001223 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001224 struct alc_spec *spec = codec->spec;
1225
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001226 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1227
David Henningsson90622912010-10-14 14:50:18 +02001228 if (spec->cdefine.fixup) {
1229 ass = spec->cdefine.sku_cfg;
1230 if (ass == ALC_FIXUP_SKU_IGNORE)
1231 return -1;
1232 goto do_sku;
1233 }
1234
Kailang Yangda00c242010-03-19 11:23:45 +01001235 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001236 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001237 goto do_sku;
1238
1239 nid = 0x1d;
1240 if (codec->vendor_id == 0x10ec0260)
1241 nid = 0x17;
1242 ass = snd_hda_codec_get_pincfg(codec, nid);
1243
1244 if (!(ass & 1)) {
1245 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1246 codec->chip_name, ass);
1247 return -1;
1248 }
1249
1250 /* check sum */
1251 tmp = 0;
1252 for (i = 1; i < 16; i++) {
1253 if ((ass >> i) & 1)
1254 tmp++;
1255 }
1256 if (((ass >> 16) & 0xf) != tmp)
1257 return -1;
1258
1259 spec->cdefine.port_connectivity = ass >> 30;
1260 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1261 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1262 spec->cdefine.customization = ass >> 8;
1263do_sku:
1264 spec->cdefine.sku_cfg = ass;
1265 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1266 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1267 spec->cdefine.swap = (ass & 0x2) >> 1;
1268 spec->cdefine.override = ass & 0x1;
1269
1270 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1271 nid, spec->cdefine.sku_cfg);
1272 snd_printd("SKU: port_connectivity=0x%x\n",
1273 spec->cdefine.port_connectivity);
1274 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1275 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1276 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1277 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1278 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1279 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1280 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1281
1282 return 0;
1283}
1284
Takashi Iwai1d045db2011-07-07 18:23:21 +02001285/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001286static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1287{
Takashi Iwai21268962011-07-07 15:01:13 +02001288 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001289}
1290
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001291/* check subsystem ID and set up device-specific initialization;
1292 * return 1 if initialized, 0 if invalid SSID
1293 */
1294/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1295 * 31 ~ 16 : Manufacture ID
1296 * 15 ~ 8 : SKU ID
1297 * 7 ~ 0 : Assembly ID
1298 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1299 */
1300static int alc_subsystem_id(struct hda_codec *codec,
1301 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001302 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001303{
1304 unsigned int ass, tmp, i;
1305 unsigned nid;
1306 struct alc_spec *spec = codec->spec;
1307
David Henningsson90622912010-10-14 14:50:18 +02001308 if (spec->cdefine.fixup) {
1309 ass = spec->cdefine.sku_cfg;
1310 if (ass == ALC_FIXUP_SKU_IGNORE)
1311 return 0;
1312 goto do_sku;
1313 }
1314
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001315 ass = codec->subsystem_id & 0xffff;
1316 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1317 goto do_sku;
1318
1319 /* invalid SSID, check the special NID pin defcfg instead */
1320 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001321 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001322 * 29~21 : reserve
1323 * 20 : PCBEEP input
1324 * 19~16 : Check sum (15:1)
1325 * 15~1 : Custom
1326 * 0 : override
1327 */
1328 nid = 0x1d;
1329 if (codec->vendor_id == 0x10ec0260)
1330 nid = 0x17;
1331 ass = snd_hda_codec_get_pincfg(codec, nid);
1332 snd_printd("realtek: No valid SSID, "
1333 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001334 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001335 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001336 return 0;
1337 if ((ass >> 30) != 1) /* no physical connection */
1338 return 0;
1339
1340 /* check sum */
1341 tmp = 0;
1342 for (i = 1; i < 16; i++) {
1343 if ((ass >> i) & 1)
1344 tmp++;
1345 }
1346 if (((ass >> 16) & 0xf) != tmp)
1347 return 0;
1348do_sku:
1349 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1350 ass & 0xffff, codec->vendor_id);
1351 /*
1352 * 0 : override
1353 * 1 : Swap Jack
1354 * 2 : 0 --> Desktop, 1 --> Laptop
1355 * 3~5 : External Amplifier control
1356 * 7~6 : Reserved
1357 */
1358 tmp = (ass & 0x38) >> 3; /* external Amp control */
1359 switch (tmp) {
1360 case 1:
1361 spec->init_amp = ALC_INIT_GPIO1;
1362 break;
1363 case 3:
1364 spec->init_amp = ALC_INIT_GPIO2;
1365 break;
1366 case 7:
1367 spec->init_amp = ALC_INIT_GPIO3;
1368 break;
1369 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001370 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001371 spec->init_amp = ALC_INIT_DEFAULT;
1372 break;
1373 }
1374
1375 /* is laptop or Desktop and enable the function "Mute internal speaker
1376 * when the external headphone out jack is plugged"
1377 */
1378 if (!(ass & 0x8000))
1379 return 1;
1380 /*
1381 * 10~8 : Jack location
1382 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1383 * 14~13: Resvered
1384 * 15 : 1 --> enable the function "Mute internal speaker
1385 * when the external headphone out jack is plugged"
1386 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001387 if (!spec->autocfg.hp_pins[0] &&
1388 !(spec->autocfg.line_out_pins[0] &&
1389 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001390 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001391 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1392 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001393 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001394 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001395 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001396 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001397 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001398 else if (tmp == 3)
1399 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001400 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001401 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001402 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1403 spec->autocfg.line_outs))
1404 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001405 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001406 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001407 return 1;
1408}
Kailang Yangea1fb292008-08-26 12:58:38 +02001409
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001410/* Check the validity of ALC subsystem-id
1411 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1412static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001413{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001414 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001415 struct alc_spec *spec = codec->spec;
1416 snd_printd("realtek: "
1417 "Enable default setup for auto mode as fallback\n");
1418 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001419 }
Takashi Iwai21268962011-07-07 15:01:13 +02001420}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001421
Takashi Iwai41e41f12005-06-08 14:48:49 +02001422/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001423 * COEF access helper functions
1424 */
Kailang Yang274693f2009-12-03 10:07:50 +01001425static int alc_read_coef_idx(struct hda_codec *codec,
1426 unsigned int coef_idx)
1427{
1428 unsigned int val;
1429 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1430 coef_idx);
1431 val = snd_hda_codec_read(codec, 0x20, 0,
1432 AC_VERB_GET_PROC_COEF, 0);
1433 return val;
1434}
1435
Kailang Yang977ddd62010-09-15 10:02:29 +02001436static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1437 unsigned int coef_val)
1438{
1439 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1440 coef_idx);
1441 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1442 coef_val);
1443}
1444
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001445/* a special bypass for COEF 0; read the cached value at the second time */
1446static unsigned int alc_get_coef0(struct hda_codec *codec)
1447{
1448 struct alc_spec *spec = codec->spec;
1449 if (!spec->coef0)
1450 spec->coef0 = alc_read_coef_idx(codec, 0);
1451 return spec->coef0;
1452}
1453
Takashi Iwai1d045db2011-07-07 18:23:21 +02001454/*
1455 * Digital I/O handling
1456 */
1457
Takashi Iwai757899a2010-07-30 10:48:14 +02001458/* set right pin controls for digital I/O */
1459static void alc_auto_init_digital(struct hda_codec *codec)
1460{
1461 struct alc_spec *spec = codec->spec;
1462 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001463 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001464
1465 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1466 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001467 if (!pin)
1468 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001469 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001470 if (!i)
1471 dac = spec->multiout.dig_out_nid;
1472 else
1473 dac = spec->slave_dig_outs[i - 1];
1474 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1475 continue;
1476 snd_hda_codec_write(codec, dac, 0,
1477 AC_VERB_SET_AMP_GAIN_MUTE,
1478 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001479 }
1480 pin = spec->autocfg.dig_in_pin;
1481 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001482 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001483}
1484
1485/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1486static void alc_auto_parse_digital(struct hda_codec *codec)
1487{
1488 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001489 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001490 hda_nid_t dig_nid;
1491
1492 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001493 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001494 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001495 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001496 err = snd_hda_get_connections(codec,
1497 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001498 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001499 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001500 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001501 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001502 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001503 spec->multiout.dig_out_nid = dig_nid;
1504 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1505 } else {
1506 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001507 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001508 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001509 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001510 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001511 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001512 }
1513
1514 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001515 dig_nid = codec->start_nid;
1516 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1517 unsigned int wcaps = get_wcaps(codec, dig_nid);
1518 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1519 continue;
1520 if (!(wcaps & AC_WCAP_DIGITAL))
1521 continue;
1522 if (!(wcaps & AC_WCAP_CONN_LIST))
1523 continue;
1524 err = get_connection_index(codec, dig_nid,
1525 spec->autocfg.dig_in_pin);
1526 if (err >= 0) {
1527 spec->dig_in_nid = dig_nid;
1528 break;
1529 }
1530 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001531 }
1532}
1533
Takashi Iwaif95474e2007-07-10 00:47:43 +02001534/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001535 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001536 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001537static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1538 struct snd_ctl_elem_info *uinfo)
1539{
1540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1541 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001542 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001543 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001544
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001545 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001546 if (spec->vol_in_capsrc)
1547 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1548 else
1549 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1550 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001551 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001552 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001553 return err;
1554}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001556static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1557 unsigned int size, unsigned int __user *tlv)
1558{
1559 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1560 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001561 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001562 int err;
1563
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001564 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001565 if (spec->vol_in_capsrc)
1566 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1567 else
1568 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1569 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001570 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001571 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001572 return err;
1573}
1574
1575typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1576 struct snd_ctl_elem_value *ucontrol);
1577
1578static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1579 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001580 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001581{
1582 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1583 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001584 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001585
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001586 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001587 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001588 for (i = 0; i < spec->num_adc_nids; i++) {
1589 kcontrol->private_value =
1590 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1591 3, 0, HDA_INPUT);
1592 err = func(kcontrol, ucontrol);
1593 if (err < 0)
1594 goto error;
1595 }
1596 } else {
1597 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001598 if (spec->vol_in_capsrc)
1599 kcontrol->private_value =
1600 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1601 3, 0, HDA_OUTPUT);
1602 else
1603 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001604 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1605 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001606 err = func(kcontrol, ucontrol);
1607 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001608 if (err >= 0 && is_put)
1609 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001610 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001611 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001612 return err;
1613}
1614
1615static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1616 struct snd_ctl_elem_value *ucontrol)
1617{
1618 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001619 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001620}
1621
1622static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1623 struct snd_ctl_elem_value *ucontrol)
1624{
1625 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001626 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001627}
1628
1629/* capture mixer elements */
1630#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1631
1632static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1633 struct snd_ctl_elem_value *ucontrol)
1634{
1635 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001636 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001637}
1638
1639static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1640 struct snd_ctl_elem_value *ucontrol)
1641{
1642 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001643 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001644}
1645
Takashi Iwaia23b6882009-03-23 15:21:36 +01001646#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001647 { \
1648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1649 .name = "Capture Switch", \
1650 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1651 .count = num, \
1652 .info = alc_cap_sw_info, \
1653 .get = alc_cap_sw_get, \
1654 .put = alc_cap_sw_put, \
1655 }, \
1656 { \
1657 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1658 .name = "Capture Volume", \
1659 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1660 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1661 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1662 .count = num, \
1663 .info = alc_cap_vol_info, \
1664 .get = alc_cap_vol_get, \
1665 .put = alc_cap_vol_put, \
1666 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001667 }
1668
1669#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001670 { \
1671 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1672 /* .name = "Capture Source", */ \
1673 .name = "Input Source", \
1674 .count = num, \
1675 .info = alc_mux_enum_info, \
1676 .get = alc_mux_enum_get, \
1677 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001678 }
1679
1680#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001681static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001682 _DEFINE_CAPMIX(num), \
1683 _DEFINE_CAPSRC(num), \
1684 { } /* end */ \
1685}
1686
1687#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001688static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001689 _DEFINE_CAPMIX(num), \
1690 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001691}
1692
1693/* up to three ADCs */
1694DEFINE_CAPMIX(1);
1695DEFINE_CAPMIX(2);
1696DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001697DEFINE_CAPMIX_NOSRC(1);
1698DEFINE_CAPMIX_NOSRC(2);
1699DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001700
1701/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001702 * Inverted digital-mic handling
1703 *
1704 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1705 * gives the additional mute only to the right channel of the digital mic
1706 * capture stream. This is a workaround for avoiding the almost silence
1707 * by summing the stereo stream from some (known to be ForteMedia)
1708 * digital mic unit.
1709 *
1710 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1711 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1712 * without caching so that the cache can still keep the original value.
1713 * The cached value is then restored when the flag is set off or any other
1714 * than d-mic is used as the current input source.
1715 */
1716static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1717{
1718 struct alc_spec *spec = codec->spec;
1719 int i;
1720
1721 if (!spec->inv_dmic_fixup)
1722 return;
1723 if (!spec->inv_dmic_muted && !force)
1724 return;
1725 for (i = 0; i < spec->num_adc_nids; i++) {
1726 int src = spec->dyn_adc_switch ? 0 : i;
1727 bool dmic_fixup = false;
1728 hda_nid_t nid;
1729 int parm, dir, v;
1730
1731 if (spec->inv_dmic_muted &&
1732 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1733 dmic_fixup = true;
1734 if (!dmic_fixup && !force)
1735 continue;
1736 if (spec->vol_in_capsrc) {
1737 nid = spec->capsrc_nids[i];
1738 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1739 dir = HDA_OUTPUT;
1740 } else {
1741 nid = spec->adc_nids[i];
1742 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1743 dir = HDA_INPUT;
1744 }
1745 /* we care only right channel */
1746 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1747 if (v & 0x80) /* if already muted, we don't need to touch */
1748 continue;
1749 if (dmic_fixup) /* add mute for d-mic */
1750 v |= 0x80;
1751 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1752 parm | v);
1753 }
1754}
1755
1756static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1757 struct snd_ctl_elem_value *ucontrol)
1758{
1759 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1760 struct alc_spec *spec = codec->spec;
1761
1762 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1763 return 0;
1764}
1765
1766static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1767 struct snd_ctl_elem_value *ucontrol)
1768{
1769 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1770 struct alc_spec *spec = codec->spec;
1771 unsigned int val = !ucontrol->value.integer.value[0];
1772
1773 if (val == spec->inv_dmic_muted)
1774 return 0;
1775 spec->inv_dmic_muted = val;
1776 alc_inv_dmic_sync(codec, true);
1777 return 0;
1778}
1779
1780static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1782 .info = snd_ctl_boolean_mono_info,
1783 .get = alc_inv_dmic_sw_get,
1784 .put = alc_inv_dmic_sw_put,
1785};
1786
1787static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1788{
1789 struct alc_spec *spec = codec->spec;
1790 struct snd_kcontrol_new *knew = alc_kcontrol_new(spec);
1791 if (!knew)
1792 return -ENOMEM;
1793 *knew = alc_inv_dmic_sw;
1794 knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL);
1795 if (!knew->name)
1796 return -ENOMEM;
1797 spec->inv_dmic_fixup = 1;
1798 spec->inv_dmic_muted = 0;
1799 spec->inv_dmic_pin = nid;
1800 return 0;
1801}
1802
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001803/* typically the digital mic is put at node 0x12 */
1804static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1805 const struct alc_fixup *fix, int action)
1806{
1807 if (action == ALC_FIXUP_ACT_PROBE)
1808 alc_add_inv_dmic_mixer(codec, 0x12);
1809}
1810
Takashi Iwai125821a2012-06-22 14:30:29 +02001811/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001812 * virtual master controls
1813 */
1814
1815/*
1816 * slave controls for virtual master
1817 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001818static const char * const alc_slave_pfxs[] = {
1819 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001820 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001821 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001822 NULL,
1823};
1824
1825/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001826 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001828
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001829#define NID_MAPPING (-1)
1830
1831#define SUBDEV_SPEAKER_ (0 << 6)
1832#define SUBDEV_HP_ (1 << 6)
1833#define SUBDEV_LINE_ (2 << 6)
1834#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1835#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1836#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1837
Takashi Iwai603c4012008-07-30 15:01:44 +02001838static void alc_free_kctls(struct hda_codec *codec);
1839
Takashi Iwai67d634c2009-11-16 15:35:59 +01001840#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001841/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001842static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001843 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001844 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001845 { } /* end */
1846};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001847#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001848
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001849static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850{
1851 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001852 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001853 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001854 int i, j, err;
1855 unsigned int u;
1856 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
1858 for (i = 0; i < spec->num_mixers; i++) {
1859 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1860 if (err < 0)
1861 return err;
1862 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001863 if (spec->cap_mixer) {
1864 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1865 if (err < 0)
1866 return err;
1867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001869 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001870 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001871 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 if (err < 0)
1873 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001874 if (!spec->no_analog) {
1875 err = snd_hda_create_spdif_share_sw(codec,
1876 &spec->multiout);
1877 if (err < 0)
1878 return err;
1879 spec->multiout.share_spdif = 1;
1880 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 }
1882 if (spec->dig_in_nid) {
1883 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1884 if (err < 0)
1885 return err;
1886 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001887
Takashi Iwai67d634c2009-11-16 15:35:59 +01001888#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001889 /* create beep controls if needed */
1890 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001891 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001892 for (knew = alc_beep_mixer; knew->name; knew++) {
1893 struct snd_kcontrol *kctl;
1894 kctl = snd_ctl_new1(knew, codec);
1895 if (!kctl)
1896 return -ENOMEM;
1897 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001898 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001899 if (err < 0)
1900 return err;
1901 }
1902 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001903#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001904
Takashi Iwai2134ea42008-01-10 16:53:55 +01001905 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001906 if (!spec->no_analog &&
1907 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001908 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001909 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001910 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001911 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001912 vmaster_tlv, alc_slave_pfxs,
1913 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001914 if (err < 0)
1915 return err;
1916 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001917 if (!spec->no_analog &&
1918 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001919 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1920 NULL, alc_slave_pfxs,
1921 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001922 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001923 if (err < 0)
1924 return err;
1925 }
1926
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001927 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001928 if (spec->capsrc_nids || spec->adc_nids) {
1929 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1930 if (!kctl)
1931 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1932 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001933 err = snd_hda_add_nid(codec, kctl, i,
1934 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001935 if (err < 0)
1936 return err;
1937 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001938 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001939 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001940 const char *kname = kctl ? kctl->id.name : NULL;
1941 for (knew = spec->cap_mixer; knew->name; knew++) {
1942 if (kname && strcmp(knew->name, kname) == 0)
1943 continue;
1944 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1945 for (i = 0; kctl && i < kctl->count; i++) {
1946 err = snd_hda_add_nid(codec, kctl, i,
1947 spec->adc_nids[i]);
1948 if (err < 0)
1949 return err;
1950 }
1951 }
1952 }
1953
1954 /* other nid->control mapping */
1955 for (i = 0; i < spec->num_mixers; i++) {
1956 for (knew = spec->mixers[i]; knew->name; knew++) {
1957 if (knew->iface != NID_MAPPING)
1958 continue;
1959 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1960 if (kctl == NULL)
1961 continue;
1962 u = knew->subdevice;
1963 for (j = 0; j < 4; j++, u >>= 8) {
1964 nid = u & 0x3f;
1965 if (nid == 0)
1966 continue;
1967 switch (u & 0xc0) {
1968 case SUBDEV_SPEAKER_:
1969 nid = spec->autocfg.speaker_pins[nid];
1970 break;
1971 case SUBDEV_LINE_:
1972 nid = spec->autocfg.line_out_pins[nid];
1973 break;
1974 case SUBDEV_HP_:
1975 nid = spec->autocfg.hp_pins[nid];
1976 break;
1977 default:
1978 continue;
1979 }
1980 err = snd_hda_add_nid(codec, kctl, 0, nid);
1981 if (err < 0)
1982 return err;
1983 }
1984 u = knew->private_value;
1985 for (j = 0; j < 4; j++, u >>= 8) {
1986 nid = u & 0xff;
1987 if (nid == 0)
1988 continue;
1989 err = snd_hda_add_nid(codec, kctl, 0, nid);
1990 if (err < 0)
1991 return err;
1992 }
1993 }
1994 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001995
1996 alc_free_kctls(codec); /* no longer needed */
1997
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001998 return 0;
1999}
2000
David Henningsson5780b622012-06-27 18:45:45 +02002001static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002002{
2003 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02002004
2005 if (spec->shared_mic_hp) {
2006 int err;
2007 int nid = spec->autocfg.inputs[1].pin;
2008 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
2009 if (err < 0)
2010 return err;
2011 err = snd_hda_jack_detect_enable(codec, nid, 0);
2012 if (err < 0)
2013 return err;
2014 }
2015
2016 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2017}
2018
2019static int alc_build_controls(struct hda_codec *codec)
2020{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002021 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002022 if (err < 0)
2023 return err;
David Henningsson5780b622012-06-27 18:45:45 +02002024
2025 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002026 if (err < 0)
2027 return err;
2028 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2029 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030}
2031
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002032
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002034 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002035 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002036
Takashi Iwai584c0c42011-03-10 12:51:11 +01002037static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002038static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002039
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040static int alc_init(struct hda_codec *codec)
2041{
2042 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002043
Takashi Iwai546bb672012-03-07 08:37:19 +01002044 if (spec->init_hook)
2045 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002046
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002047 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002048 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002049
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002050 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002051 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002052 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002053
Takashi Iwai58701122011-01-13 15:41:45 +01002054 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2055
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002056 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 return 0;
2058}
2059
Takashi Iwai83012a72012-08-24 18:38:08 +02002060#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002061static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2062{
2063 struct alc_spec *spec = codec->spec;
2064 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2065}
2066#endif
2067
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068/*
2069 * Analog playback callbacks
2070 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002071static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002073 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074{
2075 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002076 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2077 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078}
2079
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002080static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 struct hda_codec *codec,
2082 unsigned int stream_tag,
2083 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002084 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
2086 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002087 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2088 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002091static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002093 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094{
2095 struct alc_spec *spec = codec->spec;
2096 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2097}
2098
2099/*
2100 * Digital out
2101 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002102static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002104 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
2106 struct alc_spec *spec = codec->spec;
2107 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2108}
2109
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002110static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002111 struct hda_codec *codec,
2112 unsigned int stream_tag,
2113 unsigned int format,
2114 struct snd_pcm_substream *substream)
2115{
2116 struct alc_spec *spec = codec->spec;
2117 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2118 stream_tag, format, substream);
2119}
2120
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002121static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002122 struct hda_codec *codec,
2123 struct snd_pcm_substream *substream)
2124{
2125 struct alc_spec *spec = codec->spec;
2126 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2127}
2128
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002129static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002131 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
2133 struct alc_spec *spec = codec->spec;
2134 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2135}
2136
2137/*
2138 * Analog capture
2139 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002140static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 struct hda_codec *codec,
2142 unsigned int stream_tag,
2143 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002144 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
2146 struct alc_spec *spec = codec->spec;
2147
Takashi Iwai63300792008-01-24 15:31:36 +01002148 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 stream_tag, 0, format);
2150 return 0;
2151}
2152
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002153static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002155 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
2157 struct alc_spec *spec = codec->spec;
2158
Takashi Iwai888afa12008-03-18 09:57:50 +01002159 snd_hda_codec_cleanup_stream(codec,
2160 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 return 0;
2162}
2163
Takashi Iwai840b64c2010-07-13 22:49:01 +02002164/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002165static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002166 struct hda_codec *codec,
2167 unsigned int stream_tag,
2168 unsigned int format,
2169 struct snd_pcm_substream *substream)
2170{
2171 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002172 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002173 spec->cur_adc_stream_tag = stream_tag;
2174 spec->cur_adc_format = format;
2175 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2176 return 0;
2177}
2178
Takashi Iwai21268962011-07-07 15:01:13 +02002179static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002180 struct hda_codec *codec,
2181 struct snd_pcm_substream *substream)
2182{
2183 struct alc_spec *spec = codec->spec;
2184 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2185 spec->cur_adc = 0;
2186 return 0;
2187}
2188
Takashi Iwai21268962011-07-07 15:01:13 +02002189static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002190 .substreams = 1,
2191 .channels_min = 2,
2192 .channels_max = 2,
2193 .nid = 0, /* fill later */
2194 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002195 .prepare = dyn_adc_capture_pcm_prepare,
2196 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002197 },
2198};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
2200/*
2201 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002202static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 .substreams = 1,
2204 .channels_min = 2,
2205 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002206 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002208 .open = alc_playback_pcm_open,
2209 .prepare = alc_playback_pcm_prepare,
2210 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 },
2212};
2213
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002214static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002215 .substreams = 1,
2216 .channels_min = 2,
2217 .channels_max = 2,
2218 /* NID is set in alc_build_pcms */
2219};
2220
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002221static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002222 .substreams = 1,
2223 .channels_min = 2,
2224 .channels_max = 2,
2225 /* NID is set in alc_build_pcms */
2226};
2227
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002228static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002229 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 .channels_min = 2,
2231 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002232 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002234 .prepare = alc_alt_capture_pcm_prepare,
2235 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 },
2237};
2238
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002239static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 .substreams = 1,
2241 .channels_min = 2,
2242 .channels_max = 2,
2243 /* NID is set in alc_build_pcms */
2244 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002245 .open = alc_dig_playback_pcm_open,
2246 .close = alc_dig_playback_pcm_close,
2247 .prepare = alc_dig_playback_pcm_prepare,
2248 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 },
2250};
2251
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002252static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 .substreams = 1,
2254 .channels_min = 2,
2255 .channels_max = 2,
2256 /* NID is set in alc_build_pcms */
2257};
2258
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002259/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002260static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002261 .substreams = 0,
2262 .channels_min = 0,
2263 .channels_max = 0,
2264};
2265
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266static int alc_build_pcms(struct hda_codec *codec)
2267{
2268 struct alc_spec *spec = codec->spec;
2269 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002270 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002271 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 int i;
2273
2274 codec->num_pcms = 1;
2275 codec->pcm_info = info;
2276
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002277 if (spec->no_analog)
2278 goto skip_analog;
2279
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002280 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2281 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002283
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002284 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002285 p = spec->stream_analog_playback;
2286 if (!p)
2287 p = &alc_pcm_analog_playback;
2288 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2290 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002291 if (spec->adc_nids) {
2292 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002293 if (!p) {
2294 if (spec->dyn_adc_switch)
2295 p = &dyn_adc_pcm_analog_capture;
2296 else
2297 p = &alc_pcm_analog_capture;
2298 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002299 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002300 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
Takashi Iwai4a471b72005-12-07 13:56:29 +01002303 if (spec->channel_mode) {
2304 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2305 for (i = 0; i < spec->num_channel_mode; i++) {
2306 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2307 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 }
2310 }
2311
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002312 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002313 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002315 snprintf(spec->stream_name_digital,
2316 sizeof(spec->stream_name_digital),
2317 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002318 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002319 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002320 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002322 if (spec->dig_out_type)
2323 info->pcm_type = spec->dig_out_type;
2324 else
2325 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002326 if (spec->multiout.dig_out_nid) {
2327 p = spec->stream_digital_playback;
2328 if (!p)
2329 p = &alc_pcm_digital_playback;
2330 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2332 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002333 if (spec->dig_in_nid) {
2334 p = spec->stream_digital_capture;
2335 if (!p)
2336 p = &alc_pcm_digital_capture;
2337 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2339 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002340 /* FIXME: do we need this for all Realtek codec models? */
2341 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 }
2343
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002344 if (spec->no_analog)
2345 return 0;
2346
Takashi Iwaie08a0072006-09-07 17:52:14 +02002347 /* If the use of more than one ADC is requested for the current
2348 * model, configure a second analog capture-only PCM.
2349 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002350 have_multi_adcs = (spec->num_adc_nids > 1) &&
2351 !spec->dyn_adc_switch && !spec->auto_mic &&
2352 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002353 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002354 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002355 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002356 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002357 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002358 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002359 p = spec->stream_analog_alt_playback;
2360 if (!p)
2361 p = &alc_pcm_analog_alt_playback;
2362 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002363 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2364 spec->alt_dac_nid;
2365 } else {
2366 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2367 alc_pcm_null_stream;
2368 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2369 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002370 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002371 p = spec->stream_analog_alt_capture;
2372 if (!p)
2373 p = &alc_pcm_analog_alt_capture;
2374 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002375 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2376 spec->adc_nids[1];
2377 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2378 spec->num_adc_nids - 1;
2379 } else {
2380 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2381 alc_pcm_null_stream;
2382 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002383 }
2384 }
2385
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 return 0;
2387}
2388
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002389static inline void alc_shutup(struct hda_codec *codec)
2390{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002391 struct alc_spec *spec = codec->spec;
2392
2393 if (spec && spec->shutup)
2394 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002395 snd_hda_shutup_pins(codec);
2396}
2397
Takashi Iwai603c4012008-07-30 15:01:44 +02002398static void alc_free_kctls(struct hda_codec *codec)
2399{
2400 struct alc_spec *spec = codec->spec;
2401
2402 if (spec->kctls.list) {
2403 struct snd_kcontrol_new *kctl = spec->kctls.list;
2404 int i;
2405 for (i = 0; i < spec->kctls.used; i++)
2406 kfree(kctl[i].name);
2407 }
2408 snd_array_free(&spec->kctls);
2409}
2410
Takashi Iwai23c09b02011-08-19 09:05:35 +02002411static void alc_free_bind_ctls(struct hda_codec *codec)
2412{
2413 struct alc_spec *spec = codec->spec;
2414 if (spec->bind_ctls.list) {
2415 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2416 int i;
2417 for (i = 0; i < spec->bind_ctls.used; i++)
2418 kfree(ctl[i]);
2419 }
2420 snd_array_free(&spec->bind_ctls);
2421}
2422
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423static void alc_free(struct hda_codec *codec)
2424{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002425 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002426
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002427 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002428 return;
2429
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002430 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002431 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002432 alc_free_bind_ctls(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002433 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002434 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002435 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436}
2437
Takashi Iwai83012a72012-08-24 18:38:08 +02002438#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002439static void alc_power_eapd(struct hda_codec *codec)
2440{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002441 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002442}
2443
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002444static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002445{
2446 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002447 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002448 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002449 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002450 return 0;
2451}
2452#endif
2453
Takashi Iwai2a439522011-07-26 09:52:50 +02002454#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002455static int alc_resume(struct hda_codec *codec)
2456{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002457 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002458 codec->patch_ops.init(codec);
2459 snd_hda_codec_resume_amp(codec);
2460 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002461 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002462 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002463 return 0;
2464}
Takashi Iwaie044c392008-10-27 16:56:24 +01002465#endif
2466
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467/*
2468 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002469static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 .build_controls = alc_build_controls,
2471 .build_pcms = alc_build_pcms,
2472 .init = alc_init,
2473 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002474 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002475#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002476 .resume = alc_resume,
2477#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002478#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002479 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002480 .check_power_status = alc_check_power_status,
2481#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002482 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483};
2484
Kailang Yangc027ddc2010-03-19 11:33:06 +01002485/* replace the codec chip_name with the given string */
2486static int alc_codec_rename(struct hda_codec *codec, const char *name)
2487{
2488 kfree(codec->chip_name);
2489 codec->chip_name = kstrdup(name, GFP_KERNEL);
2490 if (!codec->chip_name) {
2491 alc_free(codec);
2492 return -ENOMEM;
2493 }
2494 return 0;
2495}
2496
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002497/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002498 * Rename codecs appropriately from COEF value
2499 */
2500struct alc_codec_rename_table {
2501 unsigned int vendor_id;
2502 unsigned short coef_mask;
2503 unsigned short coef_bits;
2504 const char *name;
2505};
2506
2507static struct alc_codec_rename_table rename_tbl[] = {
2508 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2509 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2510 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2511 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2512 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2513 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2514 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002515 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002516 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2517 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2518 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2519 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2520 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2521 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2522 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2523 { } /* terminator */
2524};
2525
2526static int alc_codec_rename_from_preset(struct hda_codec *codec)
2527{
2528 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002529
2530 for (p = rename_tbl; p->vendor_id; p++) {
2531 if (p->vendor_id != codec->vendor_id)
2532 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002533 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002534 return alc_codec_rename(codec, p->name);
2535 }
2536 return 0;
2537}
2538
2539/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002540 * Automatic parse of I/O pins from the BIOS configuration
2541 */
2542
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002543enum {
2544 ALC_CTL_WIDGET_VOL,
2545 ALC_CTL_WIDGET_MUTE,
2546 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002547 ALC_CTL_BIND_VOL,
2548 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002549};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002550static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002551 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2552 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002553 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002554 HDA_BIND_VOL(NULL, 0),
2555 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002556};
2557
2558/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002559static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002560 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002561{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002562 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002563
Takashi Iwaice764ab2011-04-27 16:35:23 +02002564 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002565 if (!knew)
2566 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002567 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002568 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002569 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002570 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002571 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002572 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002573 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002574 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002575 return 0;
2576}
2577
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002578static int add_control_with_pfx(struct alc_spec *spec, int type,
2579 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002580 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002581{
2582 char name[32];
2583 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002584 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002585}
2586
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002587#define add_pb_vol_ctrl(spec, type, pfx, val) \
2588 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2589#define add_pb_sw_ctrl(spec, type, pfx, val) \
2590 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2591#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2592 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2593#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2594 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002595
Takashi Iwai23c09b02011-08-19 09:05:35 +02002596static const char * const channel_name[4] = {
2597 "Front", "Surround", "CLFE", "Side"
2598};
2599
Takashi Iwai6843ca12011-06-24 11:03:58 +02002600static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2601 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002602{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002603 struct auto_pin_cfg *cfg = &spec->autocfg;
2604
Takashi Iwai6843ca12011-06-24 11:03:58 +02002605 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002606 if (cfg->line_outs == 1 && !spec->multi_ios &&
2607 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002608 return "Master";
2609
2610 switch (cfg->line_out_type) {
2611 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002612 if (cfg->line_outs == 1)
2613 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002614 if (cfg->line_outs == 2)
2615 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002616 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002617 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002618 /* for multi-io case, only the primary out */
2619 if (ch && spec->multi_ios)
2620 break;
2621 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002622 return "Headphone";
2623 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002624 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002625 return "PCM";
2626 break;
2627 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002628 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2629 return "PCM";
2630
2631 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002632}
2633
Takashi Iwai83012a72012-08-24 18:38:08 +02002634#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002635/* add the powersave loopback-list entry */
2636static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2637{
2638 struct hda_amp_list *list;
2639
2640 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2641 return;
2642 list = spec->loopback_list + spec->num_loopbacks;
2643 list->nid = mix;
2644 list->dir = HDA_INPUT;
2645 list->idx = idx;
2646 spec->num_loopbacks++;
2647 spec->loopback.amplist = spec->loopback_list;
2648}
2649#else
2650#define add_loopback_list(spec, mix, idx) /* NOP */
2651#endif
2652
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002653/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002654static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002655 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002656 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002657{
Kailang Yangdf694da2005-12-05 19:42:22 +01002658 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002659
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002660 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002661 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2662 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002663 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002664 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002665 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2666 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002667 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002668 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002669 return 0;
2670}
2671
Takashi Iwai05f5f472009-08-25 13:10:18 +02002672static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002673{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002674 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2675 return (pincap & AC_PINCAP_IN) != 0;
2676}
2677
Takashi Iwai1d045db2011-07-07 18:23:21 +02002678/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002679static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002680{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002681 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002682 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002683 hda_nid_t *adc_nids = spec->private_adc_nids;
2684 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2685 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002686 int i, nums = 0;
2687
2688 nid = codec->start_nid;
2689 for (i = 0; i < codec->num_nodes; i++, nid++) {
2690 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002691 unsigned int caps = get_wcaps(codec, nid);
2692 int type = get_wcaps_type(caps);
2693
2694 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2695 continue;
2696 adc_nids[nums] = nid;
2697 cap_nids[nums] = nid;
2698 src = nid;
2699 for (;;) {
2700 int n;
2701 type = get_wcaps_type(get_wcaps(codec, src));
2702 if (type == AC_WID_PIN)
2703 break;
2704 if (type == AC_WID_AUD_SEL) {
2705 cap_nids[nums] = src;
2706 break;
2707 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002708 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002709 if (n > 1) {
2710 cap_nids[nums] = src;
2711 break;
2712 } else if (n != 1)
2713 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002714 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2715 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002716 }
2717 if (++nums >= max_nums)
2718 break;
2719 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002720 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002721 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002722 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002723 return nums;
2724}
2725
Takashi Iwai05f5f472009-08-25 13:10:18 +02002726/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002727static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002728{
2729 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002730 const struct auto_pin_cfg *cfg = &spec->autocfg;
2731 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002732 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002733 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002734 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002735 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002736
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002737 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002738 if (num_adcs < 0)
2739 return 0;
2740
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002741 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002742 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002743 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002744
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002745 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002746 if (!alc_is_input_pin(codec, pin))
2747 continue;
2748
David Henningsson5322bf22011-01-05 11:03:56 +01002749 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002750 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2751 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002752 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002753 type_idx++;
2754 else
2755 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002756 prev_label = label;
2757
Takashi Iwai05f5f472009-08-25 13:10:18 +02002758 if (mixer) {
2759 idx = get_connection_index(codec, mixer, pin);
2760 if (idx >= 0) {
2761 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002762 label, type_idx,
2763 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002764 if (err < 0)
2765 return err;
2766 }
2767 }
2768
Takashi Iwaib7821702011-07-06 15:12:46 +02002769 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002770 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002771 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002772 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002773 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002774 snd_hda_add_imux_item(imux, label, idx, NULL);
2775 break;
2776 }
2777 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002778 }
Takashi Iwai21268962011-07-07 15:01:13 +02002779
2780 spec->num_mux_defs = 1;
2781 spec->input_mux = imux;
2782
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002783 return 0;
2784}
2785
Takashi Iwai24de1832011-11-07 17:13:39 +01002786/* create a shared input with the headphone out */
2787static int alc_auto_create_shared_input(struct hda_codec *codec)
2788{
2789 struct alc_spec *spec = codec->spec;
2790 struct auto_pin_cfg *cfg = &spec->autocfg;
2791 unsigned int defcfg;
2792 hda_nid_t nid;
2793
2794 /* only one internal input pin? */
2795 if (cfg->num_inputs != 1)
2796 return 0;
2797 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2798 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2799 return 0;
2800
2801 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2802 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2803 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2804 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2805 else
2806 return 0; /* both not available */
2807
2808 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2809 return 0; /* no input */
2810
2811 cfg->inputs[1].pin = nid;
2812 cfg->inputs[1].type = AUTO_PIN_MIC;
2813 cfg->num_inputs = 2;
2814 spec->shared_mic_hp = 1;
2815 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2816 return 0;
2817}
2818
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002819static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2820 unsigned int pin_type)
2821{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002822 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002823 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002824 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2825 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002826 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002827}
2828
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002829static int get_pin_type(int line_out_type)
2830{
2831 if (line_out_type == AUTO_PIN_HP_OUT)
2832 return PIN_HP;
2833 else
2834 return PIN_OUT;
2835}
2836
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002837static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002838{
2839 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002840 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002841 int i;
2842
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002843 for (i = 0; i < cfg->num_inputs; i++) {
2844 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002845 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002846 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002847 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002848 snd_hda_codec_write(codec, nid, 0,
2849 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002850 AMP_OUT_MUTE);
2851 }
2852 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002853
2854 /* mute all loopback inputs */
2855 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002856 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002857 for (i = 0; i < nums; i++)
2858 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2859 AC_VERB_SET_AMP_GAIN_MUTE,
2860 AMP_IN_MUTE(i));
2861 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002862}
2863
Takashi Iwai7085ec12009-10-02 09:03:58 +02002864/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002865static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002866{
Takashi Iwai604401a2011-04-27 15:14:23 +02002867 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002868 int i, num;
2869
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002870 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2871 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002872 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2873 for (i = 0; i < num; i++) {
2874 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2875 return list[i];
2876 }
2877 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002878}
2879
Takashi Iwai604401a2011-04-27 15:14:23 +02002880/* go down to the selector widget before the mixer */
2881static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2882{
2883 hda_nid_t srcs[5];
2884 int num = snd_hda_get_connections(codec, pin, srcs,
2885 ARRAY_SIZE(srcs));
2886 if (num != 1 ||
2887 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2888 return pin;
2889 return srcs[0];
2890}
2891
Takashi Iwai7085ec12009-10-02 09:03:58 +02002892/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002893static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002894 hda_nid_t dac)
2895{
David Henningssoncc1c4522010-11-24 14:17:47 +01002896 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002897 int i, num;
2898
Takashi Iwai604401a2011-04-27 15:14:23 +02002899 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002900 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2901 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002902 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002903 return mix[i];
2904 }
2905 return 0;
2906}
2907
Takashi Iwaice764ab2011-04-27 16:35:23 +02002908/* select the connection from pin to DAC if needed */
2909static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2910 hda_nid_t dac)
2911{
2912 hda_nid_t mix[5];
2913 int i, num;
2914
2915 pin = alc_go_down_to_selector(codec, pin);
2916 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2917 if (num < 2)
2918 return 0;
2919 for (i = 0; i < num; i++) {
2920 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2921 snd_hda_codec_update_cache(codec, pin, 0,
2922 AC_VERB_SET_CONNECT_SEL, i);
2923 return 0;
2924 }
2925 }
2926 return 0;
2927}
2928
Takashi Iwai185d99f2012-02-16 18:39:45 +01002929static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2930{
2931 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002932 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002933 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2934 ARRAY_SIZE(spec->private_dac_nids)) ||
2935 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2936 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2937 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2938 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2939 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002940 for (i = 0; i < spec->multi_ios; i++) {
2941 if (spec->multi_io[i].dac == nid)
2942 return true;
2943 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002944 return false;
2945}
2946
Takashi Iwai7085ec12009-10-02 09:03:58 +02002947/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002948static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002949{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002950 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002951 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002952
Takashi Iwai604401a2011-04-27 15:14:23 +02002953 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002954 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002955 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002956 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002957 if (!nid)
2958 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002959 if (!alc_is_dac_already_used(codec, nid))
2960 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002961 }
2962 return 0;
2963}
2964
Takashi Iwai07b18f62011-11-10 15:42:54 +01002965/* check whether the DAC is reachable from the pin */
2966static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2967 hda_nid_t pin, hda_nid_t dac)
2968{
2969 hda_nid_t srcs[5];
2970 int i, num;
2971
Takashi Iwaidc31b582012-02-17 17:27:53 +01002972 if (!pin || !dac)
2973 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002974 pin = alc_go_down_to_selector(codec, pin);
2975 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2976 for (i = 0; i < num; i++) {
2977 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2978 if (nid == dac)
2979 return true;
2980 }
2981 return false;
2982}
2983
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002984static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2985{
Takashi Iwai140547e2012-02-16 17:23:46 +01002986 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002987 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002988 hda_nid_t nid, nid_found, srcs[5];
2989 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01002990 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01002991 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002992 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002993 nid_found = 0;
2994 for (i = 0; i < num; i++) {
2995 if (srcs[i] == spec->mixer_nid)
2996 continue;
2997 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2998 if (nid && !alc_is_dac_already_used(codec, nid)) {
2999 if (nid_found)
3000 return 0;
3001 nid_found = nid;
3002 }
3003 }
3004 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003005}
3006
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003007/* mark up volume and mute control NIDs: used during badness parsing and
3008 * at creating actual controls
3009 */
3010static inline unsigned int get_ctl_pos(unsigned int data)
3011{
3012 hda_nid_t nid = get_amp_nid_(data);
3013 unsigned int dir;
3014 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3015 return 0;
3016 dir = get_amp_direction_(data);
3017 return (nid << 1) | dir;
3018}
3019
3020#define is_ctl_used(bits, data) \
3021 test_bit(get_ctl_pos(data), bits)
3022#define mark_ctl_usage(bits, data) \
3023 set_bit(get_ctl_pos(data), bits)
3024
3025static void clear_vol_marks(struct hda_codec *codec)
3026{
3027 struct alc_spec *spec = codec->spec;
3028 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3029 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3030}
3031
3032/* badness definition */
3033enum {
3034 /* No primary DAC is found for the main output */
3035 BAD_NO_PRIMARY_DAC = 0x10000,
3036 /* No DAC is found for the extra output */
3037 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003038 /* No possible multi-ios */
3039 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003040 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003041 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003042 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003043 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003044 /* Primary DAC shared with main surrounds */
3045 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003046 /* Primary DAC shared with main CLFE */
3047 BAD_SHARED_CLFE = 0x10,
3048 /* Primary DAC shared with extra surrounds */
3049 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003050 /* Volume widget is shared */
3051 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003052};
3053
3054static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3055 hda_nid_t pin, hda_nid_t dac);
3056static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3057 hda_nid_t pin, hda_nid_t dac);
3058
3059static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3060 hda_nid_t dac)
3061{
3062 struct alc_spec *spec = codec->spec;
3063 hda_nid_t nid;
3064 unsigned int val;
3065 int badness = 0;
3066
3067 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3068 if (nid) {
3069 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3070 if (is_ctl_used(spec->vol_ctls, nid))
3071 badness += BAD_SHARED_VOL;
3072 else
3073 mark_ctl_usage(spec->vol_ctls, val);
3074 } else
3075 badness += BAD_SHARED_VOL;
3076 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3077 if (nid) {
3078 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3079 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3080 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3081 else
3082 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3083 if (is_ctl_used(spec->sw_ctls, val))
3084 badness += BAD_SHARED_VOL;
3085 else
3086 mark_ctl_usage(spec->sw_ctls, val);
3087 } else
3088 badness += BAD_SHARED_VOL;
3089 return badness;
3090}
3091
Takashi Iwaidc31b582012-02-17 17:27:53 +01003092struct badness_table {
3093 int no_primary_dac; /* no primary DAC */
3094 int no_dac; /* no secondary DACs */
3095 int shared_primary; /* primary DAC is shared with main output */
3096 int shared_surr; /* secondary DAC shared with main or primary */
3097 int shared_clfe; /* third DAC shared with main or primary */
3098 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3099};
3100
3101static struct badness_table main_out_badness = {
3102 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3103 .no_dac = BAD_NO_DAC,
3104 .shared_primary = BAD_NO_PRIMARY_DAC,
3105 .shared_surr = BAD_SHARED_SURROUND,
3106 .shared_clfe = BAD_SHARED_CLFE,
3107 .shared_surr_main = BAD_SHARED_SURROUND,
3108};
3109
3110static struct badness_table extra_out_badness = {
3111 .no_primary_dac = BAD_NO_DAC,
3112 .no_dac = BAD_NO_DAC,
3113 .shared_primary = BAD_NO_EXTRA_DAC,
3114 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3115 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3116 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3117};
3118
3119/* try to assign DACs to pins and return the resultant badness */
3120static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3121 const hda_nid_t *pins, hda_nid_t *dacs,
3122 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003123{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003124 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003125 struct auto_pin_cfg *cfg = &spec->autocfg;
3126 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003127 int badness = 0;
3128 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003129
Takashi Iwai185d99f2012-02-16 18:39:45 +01003130 if (!num_outs)
3131 return 0;
3132
Takashi Iwaidc31b582012-02-17 17:27:53 +01003133 for (i = 0; i < num_outs; i++) {
3134 hda_nid_t pin = pins[i];
3135 if (!dacs[i])
3136 dacs[i] = alc_auto_look_for_dac(codec, pin);
3137 if (!dacs[i] && !i) {
3138 for (j = 1; j < num_outs; j++) {
3139 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3140 dacs[0] = dacs[j];
3141 dacs[j] = 0;
3142 break;
3143 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003144 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003145 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003146 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003147 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003148 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003149 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003150 else if (cfg->line_outs > i &&
3151 alc_auto_is_dac_reachable(codec, pin,
3152 spec->private_dac_nids[i]))
3153 dac = spec->private_dac_nids[i];
3154 if (dac) {
3155 if (!i)
3156 badness += bad->shared_primary;
3157 else if (i == 1)
3158 badness += bad->shared_surr;
3159 else
3160 badness += bad->shared_clfe;
3161 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003162 spec->private_dac_nids[0])) {
3163 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003164 badness += bad->shared_surr_main;
3165 } else if (!i)
3166 badness += bad->no_primary_dac;
3167 else
3168 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003169 }
3170 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003171 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003172 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003173
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003174 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003175}
3176
3177static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003178 hda_nid_t reference_pin,
3179 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003180
Takashi Iwai185d99f2012-02-16 18:39:45 +01003181static bool alc_map_singles(struct hda_codec *codec, int outs,
3182 const hda_nid_t *pins, hda_nid_t *dacs)
3183{
3184 int i;
3185 bool found = false;
3186 for (i = 0; i < outs; i++) {
3187 if (dacs[i])
3188 continue;
3189 dacs[i] = get_dac_if_single(codec, pins[i]);
3190 if (dacs[i])
3191 found = true;
3192 }
3193 return found;
3194}
3195
Takashi Iwai7085ec12009-10-02 09:03:58 +02003196/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003197static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003198 bool fill_hardwired,
3199 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003200{
3201 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003202 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003203 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003204
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003205 /* set num_dacs once to full for alc_auto_look_for_dac() */
3206 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003207 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003208 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3209 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3210 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003211 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003212 clear_vol_marks(codec);
3213 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003214
3215 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003216 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003217 bool mapped;
3218 do {
3219 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003220 cfg->line_out_pins,
3221 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003222 mapped |= alc_map_singles(codec, cfg->hp_outs,
3223 cfg->hp_pins,
3224 spec->multiout.hp_out_nid);
3225 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3226 cfg->speaker_pins,
3227 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003228 if (fill_mio_first && cfg->line_outs == 1 &&
3229 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3230 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3231 if (!err)
3232 mapped = true;
3233 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003234 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003235 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003236
Takashi Iwaidc31b582012-02-17 17:27:53 +01003237 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3238 spec->private_dac_nids,
3239 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003240
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003241 /* re-count num_dacs and squash invalid entries */
3242 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003243 for (i = 0; i < cfg->line_outs; i++) {
3244 if (spec->private_dac_nids[i])
3245 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003246 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003247 memmove(spec->private_dac_nids + i,
3248 spec->private_dac_nids + i + 1,
3249 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003250 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3251 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003252 }
3253
Takashi Iwai276dd702012-02-17 16:17:03 +01003254 if (fill_mio_first &&
3255 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003256 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003257 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003258 if (err < 0)
3259 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003260 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003261 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003262
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003263 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003264 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3265 spec->multiout.hp_out_nid,
3266 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003267 if (err < 0)
3268 return err;
3269 badness += err;
3270 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003271 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003272 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3273 cfg->speaker_pins,
3274 spec->multiout.extra_out_nid,
3275 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003276 if (err < 0)
3277 return err;
3278 badness += err;
3279 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003280 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3281 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003282 if (err < 0)
3283 return err;
3284 badness += err;
3285 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003286 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3287 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003288 int offset = 0;
3289 if (cfg->line_outs >= 3)
3290 offset = 1;
3291 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3292 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003293 if (err < 0)
3294 return err;
3295 badness += err;
3296 }
3297
3298 if (spec->multi_ios == 2) {
3299 for (i = 0; i < 2; i++)
3300 spec->private_dac_nids[spec->multiout.num_dacs++] =
3301 spec->multi_io[i].dac;
3302 spec->ext_channel_count = 2;
3303 } else if (spec->multi_ios) {
3304 spec->multi_ios = 0;
3305 badness += BAD_MULTI_IO;
3306 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003307
3308 return badness;
3309}
3310
3311#define DEBUG_BADNESS
3312
3313#ifdef DEBUG_BADNESS
3314#define debug_badness snd_printdd
3315#else
3316#define debug_badness(...)
3317#endif
3318
3319static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3320{
3321 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3322 cfg->line_out_pins[0], cfg->line_out_pins[1],
3323 cfg->line_out_pins[2], cfg->line_out_pins[2],
3324 spec->multiout.dac_nids[0],
3325 spec->multiout.dac_nids[1],
3326 spec->multiout.dac_nids[2],
3327 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003328 if (spec->multi_ios > 0)
3329 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3330 spec->multi_ios,
3331 spec->multi_io[0].pin, spec->multi_io[1].pin,
3332 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003333 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3334 cfg->hp_pins[0], cfg->hp_pins[1],
3335 cfg->hp_pins[2], cfg->hp_pins[2],
3336 spec->multiout.hp_out_nid[0],
3337 spec->multiout.hp_out_nid[1],
3338 spec->multiout.hp_out_nid[2],
3339 spec->multiout.hp_out_nid[3]);
3340 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3341 cfg->speaker_pins[0], cfg->speaker_pins[1],
3342 cfg->speaker_pins[2], cfg->speaker_pins[3],
3343 spec->multiout.extra_out_nid[0],
3344 spec->multiout.extra_out_nid[1],
3345 spec->multiout.extra_out_nid[2],
3346 spec->multiout.extra_out_nid[3]);
3347}
3348
3349static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3350{
3351 struct alc_spec *spec = codec->spec;
3352 struct auto_pin_cfg *cfg = &spec->autocfg;
3353 struct auto_pin_cfg *best_cfg;
3354 int best_badness = INT_MAX;
3355 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003356 bool fill_hardwired = true, fill_mio_first = true;
3357 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003358 bool hp_spk_swapped = false;
3359
3360 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3361 if (!best_cfg)
3362 return -ENOMEM;
3363 *best_cfg = *cfg;
3364
3365 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003366 badness = fill_and_eval_dacs(codec, fill_hardwired,
3367 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003368 if (badness < 0) {
3369 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003370 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003371 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003372 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3373 cfg->line_out_type, fill_hardwired, fill_mio_first,
3374 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003375 debug_show_configs(spec, cfg);
3376 if (badness < best_badness) {
3377 best_badness = badness;
3378 *best_cfg = *cfg;
3379 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003380 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003381 }
3382 if (!badness)
3383 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003384 fill_mio_first = !fill_mio_first;
3385 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003386 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003387 fill_hardwired = !fill_hardwired;
3388 if (!fill_hardwired)
3389 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003390 if (hp_spk_swapped)
3391 break;
3392 hp_spk_swapped = true;
3393 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003394 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3395 cfg->hp_outs = cfg->line_outs;
3396 memcpy(cfg->hp_pins, cfg->line_out_pins,
3397 sizeof(cfg->hp_pins));
3398 cfg->line_outs = cfg->speaker_outs;
3399 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3400 sizeof(cfg->speaker_pins));
3401 cfg->speaker_outs = 0;
3402 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3403 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003404 fill_hardwired = true;
3405 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003406 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003407 if (cfg->hp_outs > 0 &&
3408 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3409 cfg->speaker_outs = cfg->line_outs;
3410 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3411 sizeof(cfg->speaker_pins));
3412 cfg->line_outs = cfg->hp_outs;
3413 memcpy(cfg->line_out_pins, cfg->hp_pins,
3414 sizeof(cfg->hp_pins));
3415 cfg->hp_outs = 0;
3416 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3417 cfg->line_out_type = AUTO_PIN_HP_OUT;
3418 fill_hardwired = true;
3419 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003420 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003421 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003422 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003423
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003424 if (badness) {
3425 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003426 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003427 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003428 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3429 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003430 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003431
David Henningssonfde48a12011-12-09 18:27:42 +08003432 if (cfg->line_out_pins[0])
3433 spec->vmaster_nid =
3434 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3435 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003436
3437 /* clear the bitmap flags for creating controls */
3438 clear_vol_marks(codec);
3439 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003440 return 0;
3441}
3442
Takashi Iwai343a04b2011-07-06 14:28:39 +02003443static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003444 const char *pfx, int cidx,
3445 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003446{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003447 struct alc_spec *spec = codec->spec;
3448 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003449 if (!nid)
3450 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003451 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3452 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3453 return 0;
3454 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003455 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003456 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003457}
3458
Takashi Iwaie29d3772011-11-14 17:13:23 +01003459static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3460 const char *pfx, int cidx,
3461 hda_nid_t nid)
3462{
3463 int chs = 1;
3464 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3465 chs = 3;
3466 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3467}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003468
3469/* create a mute-switch for the given mixer widget;
3470 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3471 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003472static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003473 const char *pfx, int cidx,
3474 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003475{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003476 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003477 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003478 int type;
3479 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003480 if (!nid)
3481 return 0;
3482 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3483 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3484 type = ALC_CTL_WIDGET_MUTE;
3485 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003486 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003487 type = ALC_CTL_WIDGET_MUTE;
3488 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3489 } else {
3490 type = ALC_CTL_BIND_MUTE;
3491 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3492 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003493 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3494 return 0;
3495 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003496 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003497}
3498
Takashi Iwaie29d3772011-11-14 17:13:23 +01003499static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3500 int cidx, hda_nid_t nid)
3501{
3502 int chs = 1;
3503 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3504 chs = 3;
3505 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3506}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003507
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003508static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3509 hda_nid_t pin, hda_nid_t dac)
3510{
3511 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3512 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3513 return pin;
3514 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3515 return mix;
3516 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3517 return dac;
3518 return 0;
3519}
3520
3521static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3522 hda_nid_t pin, hda_nid_t dac)
3523{
3524 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3525 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3526 return dac;
3527 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3528 return mix;
3529 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3530 return pin;
3531 return 0;
3532}
3533
Takashi Iwai7085ec12009-10-02 09:03:58 +02003534/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003535static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003536 const struct auto_pin_cfg *cfg)
3537{
3538 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003539 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003540
Takashi Iwaice764ab2011-04-27 16:35:23 +02003541 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003542 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003543 noutputs += spec->multi_ios;
3544
3545 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003546 const char *name;
3547 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003548 hda_nid_t dac, pin;
3549 hda_nid_t sw, vol;
3550
3551 dac = spec->multiout.dac_nids[i];
3552 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003553 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003554 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003555 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003556 index = 0;
3557 name = channel_name[i];
3558 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003559 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003560 name = alc_get_line_out_pfx(spec, i, true, &index);
3561 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003562
3563 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3564 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003565 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003566 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003567 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003568 if (err < 0)
3569 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003570 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003571 if (err < 0)
3572 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003573 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003574 if (err < 0)
3575 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003576 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003577 if (err < 0)
3578 return err;
3579 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003580 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003581 if (err < 0)
3582 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003583 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003584 if (err < 0)
3585 return err;
3586 }
3587 }
3588 return 0;
3589}
3590
Takashi Iwai343a04b2011-07-06 14:28:39 +02003591static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003592 hda_nid_t dac, const char *pfx,
3593 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003594{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003595 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003596 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003597 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003598
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003599 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003600 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003601 /* the corresponding DAC is already occupied */
3602 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3603 return 0; /* no way */
3604 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003605 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3606 if (is_ctl_used(spec->sw_ctls, val))
3607 return 0; /* already created */
3608 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003609 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003610 }
3611
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003612 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3613 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003614 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003615 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003616 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003617 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003618 if (err < 0)
3619 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003620 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003621}
3622
Takashi Iwai23c09b02011-08-19 09:05:35 +02003623static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3624 unsigned int nums,
3625 struct hda_ctl_ops *ops)
3626{
3627 struct alc_spec *spec = codec->spec;
3628 struct hda_bind_ctls **ctlp, *ctl;
3629 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3630 ctlp = snd_array_new(&spec->bind_ctls);
3631 if (!ctlp)
3632 return NULL;
3633 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3634 *ctlp = ctl;
3635 if (ctl)
3636 ctl->ops = ops;
3637 return ctl;
3638}
3639
3640/* add playback controls for speaker and HP outputs */
3641static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3642 const hda_nid_t *pins,
3643 const hda_nid_t *dacs,
3644 const char *pfx)
3645{
3646 struct alc_spec *spec = codec->spec;
3647 struct hda_bind_ctls *ctl;
3648 char name[32];
3649 int i, n, err;
3650
3651 if (!num_pins || !pins[0])
3652 return 0;
3653
Takashi Iwai527e4d72011-10-27 16:33:27 +02003654 if (num_pins == 1) {
3655 hda_nid_t dac = *dacs;
3656 if (!dac)
3657 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003658 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003659 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003660
Takashi Iwai23c09b02011-08-19 09:05:35 +02003661 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003662 hda_nid_t dac;
3663 if (dacs[num_pins - 1])
3664 dac = dacs[i]; /* with individual volumes */
3665 else
3666 dac = 0;
3667 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3668 err = alc_auto_create_extra_out(codec, pins[i], dac,
3669 "Bass Speaker", 0);
3670 } else if (num_pins >= 3) {
3671 snprintf(name, sizeof(name), "%s %s",
3672 pfx, channel_name[i]);
3673 err = alc_auto_create_extra_out(codec, pins[i], dac,
3674 name, 0);
3675 } else {
3676 err = alc_auto_create_extra_out(codec, pins[i], dac,
3677 pfx, i);
3678 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003679 if (err < 0)
3680 return err;
3681 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003682 if (dacs[num_pins - 1])
3683 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003684
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003685 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003686 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3687 if (!ctl)
3688 return -ENOMEM;
3689 n = 0;
3690 for (i = 0; i < num_pins; i++) {
3691 hda_nid_t vol;
3692 if (!pins[i] || !dacs[i])
3693 continue;
3694 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3695 if (vol)
3696 ctl->values[n++] =
3697 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3698 }
3699 if (n) {
3700 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3701 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3702 if (err < 0)
3703 return err;
3704 }
3705 return 0;
3706}
3707
Takashi Iwai343a04b2011-07-06 14:28:39 +02003708static int alc_auto_create_hp_out(struct hda_codec *codec)
3709{
3710 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003711 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3712 spec->autocfg.hp_pins,
3713 spec->multiout.hp_out_nid,
3714 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003715}
3716
3717static int alc_auto_create_speaker_out(struct hda_codec *codec)
3718{
3719 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003720 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3721 spec->autocfg.speaker_pins,
3722 spec->multiout.extra_out_nid,
3723 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003724}
3725
Takashi Iwai343a04b2011-07-06 14:28:39 +02003726static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003727 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003728 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003729{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003730 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003731 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003732 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003733
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003734 alc_set_pin_output(codec, pin, pin_type);
3735 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003736 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003737 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003738 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003739 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003740 mix = srcs[i];
3741 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003742 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003743 if (!mix)
3744 return;
3745
3746 /* need the manual connection? */
3747 if (num > 1)
3748 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3749 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003750 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3751 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003752 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003753 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003754 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003755 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003756 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003757 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3758 if (nid)
3759 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3760 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003761
3762 /* unmute DAC if it's not assigned to a mixer */
3763 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3764 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3765 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3766 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003767}
3768
Takashi Iwai343a04b2011-07-06 14:28:39 +02003769static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003770{
3771 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003772 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003773 int i;
3774
3775 for (i = 0; i <= HDA_SIDE; i++) {
3776 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3777 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003778 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003779 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003780 }
3781}
3782
Takashi Iwai343a04b2011-07-06 14:28:39 +02003783static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003784{
3785 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003786 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003787 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003788
David Henningsson636030e2011-10-12 19:26:03 +02003789 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003790 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3791 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003792 pin = spec->autocfg.hp_pins[i];
3793 if (!pin)
3794 break;
3795 dac = spec->multiout.hp_out_nid[i];
3796 if (!dac) {
3797 if (i > 0 && spec->multiout.hp_out_nid[0])
3798 dac = spec->multiout.hp_out_nid[0];
3799 else
3800 dac = spec->multiout.dac_nids[0];
3801 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003802 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3803 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003804 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003805 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3806 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003807 pin = spec->autocfg.speaker_pins[i];
3808 if (!pin)
3809 break;
3810 dac = spec->multiout.extra_out_nid[i];
3811 if (!dac) {
3812 if (i > 0 && spec->multiout.extra_out_nid[0])
3813 dac = spec->multiout.extra_out_nid[0];
3814 else
3815 dac = spec->multiout.dac_nids[0];
3816 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003817 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3818 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003819}
3820
Takashi Iwai276dd702012-02-17 16:17:03 +01003821/* check whether the given pin can be a multi-io pin */
3822static bool can_be_multiio_pin(struct hda_codec *codec,
3823 unsigned int location, hda_nid_t nid)
3824{
3825 unsigned int defcfg, caps;
3826
3827 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3828 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3829 return false;
3830 if (location && get_defcfg_location(defcfg) != location)
3831 return false;
3832 caps = snd_hda_query_pin_caps(codec, nid);
3833 if (!(caps & AC_PINCAP_OUT))
3834 return false;
3835 return true;
3836}
3837
Takashi Iwaice764ab2011-04-27 16:35:23 +02003838/*
3839 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003840 *
3841 * When hardwired is set, try to fill ony hardwired pins, and returns
3842 * zero if any pins are filled, non-zero if nothing found.
3843 * When hardwired is off, try to fill possible input pins, and returns
3844 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003845 */
3846static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003847 hda_nid_t reference_pin,
3848 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003849{
3850 struct alc_spec *spec = codec->spec;
3851 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003852 int type, i, j, dacs, num_pins, old_pins;
3853 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3854 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003855 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003856
Takashi Iwai276dd702012-02-17 16:17:03 +01003857 old_pins = spec->multi_ios;
3858 if (old_pins >= 2)
3859 goto end_fill;
3860
3861 num_pins = 0;
3862 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3863 for (i = 0; i < cfg->num_inputs; i++) {
3864 if (cfg->inputs[i].type != type)
3865 continue;
3866 if (can_be_multiio_pin(codec, location,
3867 cfg->inputs[i].pin))
3868 num_pins++;
3869 }
3870 }
3871 if (num_pins < 2)
3872 goto end_fill;
3873
Takashi Iwai07b18f62011-11-10 15:42:54 +01003874 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003875 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3876 for (i = 0; i < cfg->num_inputs; i++) {
3877 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003878 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003879
Takashi Iwaice764ab2011-04-27 16:35:23 +02003880 if (cfg->inputs[i].type != type)
3881 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003882 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003883 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003884 for (j = 0; j < spec->multi_ios; j++) {
3885 if (nid == spec->multi_io[j].pin)
3886 break;
3887 }
3888 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003889 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003890
3891 if (offset && offset + spec->multi_ios < dacs) {
3892 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003893 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3894 dac = 0;
3895 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003896 if (hardwired)
3897 dac = get_dac_if_single(codec, nid);
3898 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003899 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003900 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003901 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003902 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003903 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003904 spec->multi_io[spec->multi_ios].pin = nid;
3905 spec->multi_io[spec->multi_ios].dac = dac;
3906 spec->multi_ios++;
3907 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003908 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003909 }
3910 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003911 end_fill:
3912 if (badness)
3913 badness = BAD_MULTI_IO;
3914 if (old_pins == spec->multi_ios) {
3915 if (hardwired)
3916 return 1; /* nothing found */
3917 else
3918 return badness; /* no badness if nothing found */
3919 }
3920 if (!hardwired && spec->multi_ios < 2) {
3921 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003922 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003923 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003924
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003925 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003926}
3927
3928static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3929 struct snd_ctl_elem_info *uinfo)
3930{
3931 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3932 struct alc_spec *spec = codec->spec;
3933
3934 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3935 uinfo->count = 1;
3936 uinfo->value.enumerated.items = spec->multi_ios + 1;
3937 if (uinfo->value.enumerated.item > spec->multi_ios)
3938 uinfo->value.enumerated.item = spec->multi_ios;
3939 sprintf(uinfo->value.enumerated.name, "%dch",
3940 (uinfo->value.enumerated.item + 1) * 2);
3941 return 0;
3942}
3943
3944static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3945 struct snd_ctl_elem_value *ucontrol)
3946{
3947 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3948 struct alc_spec *spec = codec->spec;
3949 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3950 return 0;
3951}
3952
3953static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3954{
3955 struct alc_spec *spec = codec->spec;
3956 hda_nid_t nid = spec->multi_io[idx].pin;
3957
3958 if (!spec->multi_io[idx].ctl_in)
3959 spec->multi_io[idx].ctl_in =
3960 snd_hda_codec_read(codec, nid, 0,
3961 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3962 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003963 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003964 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3965 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3966 HDA_AMP_MUTE, 0);
3967 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3968 } else {
3969 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3970 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3971 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003972 snd_hda_set_pin_ctl_cache(codec, nid,
3973 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003974 }
3975 return 0;
3976}
3977
3978static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3979 struct snd_ctl_elem_value *ucontrol)
3980{
3981 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3982 struct alc_spec *spec = codec->spec;
3983 int i, ch;
3984
3985 ch = ucontrol->value.enumerated.item[0];
3986 if (ch < 0 || ch > spec->multi_ios)
3987 return -EINVAL;
3988 if (ch == (spec->ext_channel_count - 1) / 2)
3989 return 0;
3990 spec->ext_channel_count = (ch + 1) * 2;
3991 for (i = 0; i < spec->multi_ios; i++)
3992 alc_set_multi_io(codec, i, i < ch);
3993 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003994 if (spec->need_dac_fix && !spec->const_channel_count)
3995 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003996 return 1;
3997}
3998
Takashi Iwaia9111322011-05-02 11:30:18 +02003999static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004000 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4001 .name = "Channel Mode",
4002 .info = alc_auto_ch_mode_info,
4003 .get = alc_auto_ch_mode_get,
4004 .put = alc_auto_ch_mode_put,
4005};
4006
Takashi Iwai23c09b02011-08-19 09:05:35 +02004007static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004008{
4009 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004010
Takashi Iwaic2674682011-08-24 17:57:44 +02004011 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004012 struct snd_kcontrol_new *knew;
4013
4014 knew = alc_kcontrol_new(spec);
4015 if (!knew)
4016 return -ENOMEM;
4017 *knew = alc_auto_channel_mode_enum;
4018 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4019 if (!knew->name)
4020 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004021 }
4022 return 0;
4023}
4024
Takashi Iwai1d045db2011-07-07 18:23:21 +02004025/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4026 * active input pins
4027 */
4028static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4029{
4030 struct alc_spec *spec = codec->spec;
4031 const struct hda_input_mux *imux;
4032 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4033 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4034 int i, n, nums;
4035
4036 imux = spec->input_mux;
4037 if (!imux)
4038 return;
4039 if (spec->dyn_adc_switch)
4040 return;
4041
Takashi Iwai26acaf02012-03-22 14:36:50 +01004042 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004043 nums = 0;
4044 for (n = 0; n < spec->num_adc_nids; n++) {
4045 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004046 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004047 for (i = 0; i < imux->num_items; i++) {
4048 hda_nid_t pin = spec->imux_pins[i];
4049 if (pin) {
4050 if (get_connection_index(codec, cap, pin) < 0)
4051 break;
4052 } else if (num_conns <= imux->items[i].index)
4053 break;
4054 }
4055 if (i >= imux->num_items) {
4056 adc_nids[nums] = spec->private_adc_nids[n];
4057 capsrc_nids[nums++] = cap;
4058 }
4059 }
4060 if (!nums) {
4061 /* check whether ADC-switch is possible */
4062 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004063 if (spec->shared_mic_hp) {
4064 spec->shared_mic_hp = 0;
4065 spec->private_imux[0].num_items = 1;
4066 goto again;
4067 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004068 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4069 " using fallback 0x%x\n",
4070 codec->chip_name, spec->private_adc_nids[0]);
4071 spec->num_adc_nids = 1;
4072 spec->auto_mic = 0;
4073 return;
4074 }
4075 } else if (nums != spec->num_adc_nids) {
4076 memcpy(spec->private_adc_nids, adc_nids,
4077 nums * sizeof(hda_nid_t));
4078 memcpy(spec->private_capsrc_nids, capsrc_nids,
4079 nums * sizeof(hda_nid_t));
4080 spec->num_adc_nids = nums;
4081 }
4082
4083 if (spec->auto_mic)
4084 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004085 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004086 spec->num_adc_nids = 1; /* reduce to a single ADC */
4087}
4088
4089/*
4090 * initialize ADC paths
4091 */
4092static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4093{
4094 struct alc_spec *spec = codec->spec;
4095 hda_nid_t nid;
4096
4097 nid = spec->adc_nids[adc_idx];
4098 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004099 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004100 snd_hda_codec_write(codec, nid, 0,
4101 AC_VERB_SET_AMP_GAIN_MUTE,
4102 AMP_IN_MUTE(0));
4103 return;
4104 }
4105 if (!spec->capsrc_nids)
4106 return;
4107 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004108 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004109 snd_hda_codec_write(codec, nid, 0,
4110 AC_VERB_SET_AMP_GAIN_MUTE,
4111 AMP_OUT_MUTE);
4112}
4113
4114static void alc_auto_init_input_src(struct hda_codec *codec)
4115{
4116 struct alc_spec *spec = codec->spec;
4117 int c, nums;
4118
4119 for (c = 0; c < spec->num_adc_nids; c++)
4120 alc_auto_init_adc(codec, c);
4121 if (spec->dyn_adc_switch)
4122 nums = 1;
4123 else
4124 nums = spec->num_adc_nids;
4125 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004126 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004127}
4128
4129/* add mic boosts if needed */
4130static int alc_auto_add_mic_boost(struct hda_codec *codec)
4131{
4132 struct alc_spec *spec = codec->spec;
4133 struct auto_pin_cfg *cfg = &spec->autocfg;
4134 int i, err;
4135 int type_idx = 0;
4136 hda_nid_t nid;
4137 const char *prev_label = NULL;
4138
4139 for (i = 0; i < cfg->num_inputs; i++) {
4140 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4141 break;
4142 nid = cfg->inputs[i].pin;
4143 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4144 const char *label;
4145 char boost_label[32];
4146
4147 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004148 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4149 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004150 if (prev_label && !strcmp(label, prev_label))
4151 type_idx++;
4152 else
4153 type_idx = 0;
4154 prev_label = label;
4155
4156 snprintf(boost_label, sizeof(boost_label),
4157 "%s Boost Volume", label);
4158 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4159 boost_label, type_idx,
4160 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4161 if (err < 0)
4162 return err;
4163 }
4164 }
4165 return 0;
4166}
4167
4168/* select or unmute the given capsrc route */
4169static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4170 int idx)
4171{
4172 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4173 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4174 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004175 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004176 snd_hda_codec_write_cache(codec, cap, 0,
4177 AC_VERB_SET_CONNECT_SEL, idx);
4178 }
4179}
4180
4181/* set the default connection to that pin */
4182static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4183{
4184 struct alc_spec *spec = codec->spec;
4185 int i;
4186
4187 if (!pin)
4188 return 0;
4189 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004190 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004191 int idx;
4192
4193 idx = get_connection_index(codec, cap, pin);
4194 if (idx < 0)
4195 continue;
4196 select_or_unmute_capsrc(codec, cap, idx);
4197 return i; /* return the found index */
4198 }
4199 return -1; /* not found */
4200}
4201
4202/* initialize some special cases for input sources */
4203static void alc_init_special_input_src(struct hda_codec *codec)
4204{
4205 struct alc_spec *spec = codec->spec;
4206 int i;
4207
4208 for (i = 0; i < spec->autocfg.num_inputs; i++)
4209 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4210}
4211
4212/* assign appropriate capture mixers */
4213static void set_capture_mixer(struct hda_codec *codec)
4214{
4215 struct alc_spec *spec = codec->spec;
4216 static const struct snd_kcontrol_new *caps[2][3] = {
4217 { alc_capture_mixer_nosrc1,
4218 alc_capture_mixer_nosrc2,
4219 alc_capture_mixer_nosrc3 },
4220 { alc_capture_mixer1,
4221 alc_capture_mixer2,
4222 alc_capture_mixer3 },
4223 };
4224
4225 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004226 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004227 if (!spec->capsrc_nids)
4228 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004229 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004230 return; /* no volume in capsrc, too */
4231 spec->vol_in_capsrc = 1;
4232 }
4233
4234 if (spec->num_adc_nids > 0) {
4235 int mux = 0;
4236 int num_adcs = 0;
4237
4238 if (spec->input_mux && spec->input_mux->num_items > 1)
4239 mux = 1;
4240 if (spec->auto_mic) {
4241 num_adcs = 1;
4242 mux = 0;
4243 } else if (spec->dyn_adc_switch)
4244 num_adcs = 1;
4245 if (!num_adcs) {
4246 if (spec->num_adc_nids > 3)
4247 spec->num_adc_nids = 3;
4248 else if (!spec->num_adc_nids)
4249 return;
4250 num_adcs = spec->num_adc_nids;
4251 }
4252 spec->cap_mixer = caps[mux][num_adcs - 1];
4253 }
4254}
4255
4256/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004257 * standard auto-parser initializations
4258 */
4259static void alc_auto_init_std(struct hda_codec *codec)
4260{
Takashi Iwaie4770622011-07-08 11:11:35 +02004261 alc_auto_init_multi_out(codec);
4262 alc_auto_init_extra_out(codec);
4263 alc_auto_init_analog_input(codec);
4264 alc_auto_init_input_src(codec);
4265 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004266 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004267}
4268
4269/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004270 * Digital-beep handlers
4271 */
4272#ifdef CONFIG_SND_HDA_INPUT_BEEP
4273#define set_beep_amp(spec, nid, idx, dir) \
4274 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4275
4276static const struct snd_pci_quirk beep_white_list[] = {
4277 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4278 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4279 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4280 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004281 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004282 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4283 {}
4284};
4285
4286static inline int has_cdefine_beep(struct hda_codec *codec)
4287{
4288 struct alc_spec *spec = codec->spec;
4289 const struct snd_pci_quirk *q;
4290 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4291 if (q)
4292 return q->value;
4293 return spec->cdefine.enable_pcbeep;
4294}
4295#else
4296#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4297#define has_cdefine_beep(codec) 0
4298#endif
4299
4300/* parse the BIOS configuration and set up the alc_spec */
4301/* return 1 if successful, 0 if the proper config is not found,
4302 * or a negative error code
4303 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004304static int alc_parse_auto_config(struct hda_codec *codec,
4305 const hda_nid_t *ignore_nids,
4306 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004307{
4308 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004309 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004310 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004311
Takashi Iwai53c334a2011-08-23 18:27:14 +02004312 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4313 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004314 if (err < 0)
4315 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004316 if (!cfg->line_outs) {
4317 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004318 spec->multiout.max_channels = 2;
4319 spec->no_analog = 1;
4320 goto dig_only;
4321 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004322 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004323 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004324
Takashi Iwaie427c232012-07-29 10:04:08 +02004325 if (!spec->no_primary_hp &&
4326 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004327 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004328 /* use HP as primary out */
4329 cfg->speaker_outs = cfg->line_outs;
4330 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4331 sizeof(cfg->speaker_pins));
4332 cfg->line_outs = cfg->hp_outs;
4333 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4334 cfg->hp_outs = 0;
4335 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4336 cfg->line_out_type = AUTO_PIN_HP_OUT;
4337 }
4338
Takashi Iwai1d045db2011-07-07 18:23:21 +02004339 err = alc_auto_fill_dac_nids(codec);
4340 if (err < 0)
4341 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004342 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004343 if (err < 0)
4344 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004345 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004346 if (err < 0)
4347 return err;
4348 err = alc_auto_create_hp_out(codec);
4349 if (err < 0)
4350 return err;
4351 err = alc_auto_create_speaker_out(codec);
4352 if (err < 0)
4353 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004354 err = alc_auto_create_shared_input(codec);
4355 if (err < 0)
4356 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004357 err = alc_auto_create_input_ctls(codec);
4358 if (err < 0)
4359 return err;
4360
4361 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4362
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004363 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004364 alc_auto_parse_digital(codec);
4365
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004366 if (!spec->no_analog)
4367 alc_remove_invalid_adc_nids(codec);
4368
4369 if (ssid_nids)
4370 alc_ssid_check(codec, ssid_nids);
4371
4372 if (!spec->no_analog) {
4373 alc_auto_check_switches(codec);
4374 err = alc_auto_add_mic_boost(codec);
4375 if (err < 0)
4376 return err;
4377 }
4378
Takashi Iwai1d045db2011-07-07 18:23:21 +02004379 if (spec->kctls.list)
4380 add_mixer(spec, spec->kctls.list);
4381
Takashi Iwai070cff42012-02-21 12:54:17 +01004382 if (!spec->no_analog && !spec->cap_mixer)
4383 set_capture_mixer(codec);
4384
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385 return 1;
4386}
4387
Takashi Iwai3de95172012-05-07 18:03:15 +02004388/* common preparation job for alc_spec */
4389static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4390{
4391 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4392 int err;
4393
4394 if (!spec)
4395 return -ENOMEM;
4396 codec->spec = spec;
4397 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004398 snd_hda_gen_init(&spec->gen);
Takashi Iwai3de95172012-05-07 18:03:15 +02004399
4400 err = alc_codec_rename_from_preset(codec);
4401 if (err < 0) {
4402 kfree(spec);
4403 return err;
4404 }
4405 return 0;
4406}
4407
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004408static int alc880_parse_auto_config(struct hda_codec *codec)
4409{
4410 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004411 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004412 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4413}
4414
Takashi Iwai1d045db2011-07-07 18:23:21 +02004415/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004416 * ALC880 fix-ups
4417 */
4418enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004419 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004420 ALC880_FIXUP_GPIO2,
4421 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004422 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004423 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004424 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004425 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004426 ALC880_FIXUP_VOL_KNOB,
4427 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004428 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004429 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004430 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004431 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004432 ALC880_FIXUP_3ST_BASE,
4433 ALC880_FIXUP_3ST,
4434 ALC880_FIXUP_3ST_DIG,
4435 ALC880_FIXUP_5ST_BASE,
4436 ALC880_FIXUP_5ST,
4437 ALC880_FIXUP_5ST_DIG,
4438 ALC880_FIXUP_6ST_BASE,
4439 ALC880_FIXUP_6ST,
4440 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004441};
4442
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004443/* enable the volume-knob widget support on NID 0x21 */
4444static void alc880_fixup_vol_knob(struct hda_codec *codec,
4445 const struct alc_fixup *fix, int action)
4446{
4447 if (action == ALC_FIXUP_ACT_PROBE)
4448 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4449}
4450
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004451static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004452 [ALC880_FIXUP_GPIO1] = {
4453 .type = ALC_FIXUP_VERBS,
4454 .v.verbs = alc_gpio1_init_verbs,
4455 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004456 [ALC880_FIXUP_GPIO2] = {
4457 .type = ALC_FIXUP_VERBS,
4458 .v.verbs = alc_gpio2_init_verbs,
4459 },
4460 [ALC880_FIXUP_MEDION_RIM] = {
4461 .type = ALC_FIXUP_VERBS,
4462 .v.verbs = (const struct hda_verb[]) {
4463 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4464 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4465 { }
4466 },
4467 .chained = true,
4468 .chain_id = ALC880_FIXUP_GPIO2,
4469 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004470 [ALC880_FIXUP_LG] = {
4471 .type = ALC_FIXUP_PINS,
4472 .v.pins = (const struct alc_pincfg[]) {
4473 /* disable bogus unused pins */
4474 { 0x16, 0x411111f0 },
4475 { 0x18, 0x411111f0 },
4476 { 0x1a, 0x411111f0 },
4477 { }
4478 }
4479 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004480 [ALC880_FIXUP_W810] = {
4481 .type = ALC_FIXUP_PINS,
4482 .v.pins = (const struct alc_pincfg[]) {
4483 /* disable bogus unused pins */
4484 { 0x17, 0x411111f0 },
4485 { }
4486 },
4487 .chained = true,
4488 .chain_id = ALC880_FIXUP_GPIO2,
4489 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004490 [ALC880_FIXUP_EAPD_COEF] = {
4491 .type = ALC_FIXUP_VERBS,
4492 .v.verbs = (const struct hda_verb[]) {
4493 /* change to EAPD mode */
4494 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4495 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4496 {}
4497 },
4498 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004499 [ALC880_FIXUP_TCL_S700] = {
4500 .type = ALC_FIXUP_VERBS,
4501 .v.verbs = (const struct hda_verb[]) {
4502 /* change to EAPD mode */
4503 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4504 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4505 {}
4506 },
4507 .chained = true,
4508 .chain_id = ALC880_FIXUP_GPIO2,
4509 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004510 [ALC880_FIXUP_VOL_KNOB] = {
4511 .type = ALC_FIXUP_FUNC,
4512 .v.func = alc880_fixup_vol_knob,
4513 },
4514 [ALC880_FIXUP_FUJITSU] = {
4515 /* override all pins as BIOS on old Amilo is broken */
4516 .type = ALC_FIXUP_PINS,
4517 .v.pins = (const struct alc_pincfg[]) {
4518 { 0x14, 0x0121411f }, /* HP */
4519 { 0x15, 0x99030120 }, /* speaker */
4520 { 0x16, 0x99030130 }, /* bass speaker */
4521 { 0x17, 0x411111f0 }, /* N/A */
4522 { 0x18, 0x411111f0 }, /* N/A */
4523 { 0x19, 0x01a19950 }, /* mic-in */
4524 { 0x1a, 0x411111f0 }, /* N/A */
4525 { 0x1b, 0x411111f0 }, /* N/A */
4526 { 0x1c, 0x411111f0 }, /* N/A */
4527 { 0x1d, 0x411111f0 }, /* N/A */
4528 { 0x1e, 0x01454140 }, /* SPDIF out */
4529 { }
4530 },
4531 .chained = true,
4532 .chain_id = ALC880_FIXUP_VOL_KNOB,
4533 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004534 [ALC880_FIXUP_F1734] = {
4535 /* almost compatible with FUJITSU, but no bass and SPDIF */
4536 .type = ALC_FIXUP_PINS,
4537 .v.pins = (const struct alc_pincfg[]) {
4538 { 0x14, 0x0121411f }, /* HP */
4539 { 0x15, 0x99030120 }, /* speaker */
4540 { 0x16, 0x411111f0 }, /* N/A */
4541 { 0x17, 0x411111f0 }, /* N/A */
4542 { 0x18, 0x411111f0 }, /* N/A */
4543 { 0x19, 0x01a19950 }, /* mic-in */
4544 { 0x1a, 0x411111f0 }, /* N/A */
4545 { 0x1b, 0x411111f0 }, /* N/A */
4546 { 0x1c, 0x411111f0 }, /* N/A */
4547 { 0x1d, 0x411111f0 }, /* N/A */
4548 { 0x1e, 0x411111f0 }, /* N/A */
4549 { }
4550 },
4551 .chained = true,
4552 .chain_id = ALC880_FIXUP_VOL_KNOB,
4553 },
Takashi Iwai817de922012-02-20 17:20:48 +01004554 [ALC880_FIXUP_UNIWILL] = {
4555 /* need to fix HP and speaker pins to be parsed correctly */
4556 .type = ALC_FIXUP_PINS,
4557 .v.pins = (const struct alc_pincfg[]) {
4558 { 0x14, 0x0121411f }, /* HP */
4559 { 0x15, 0x99030120 }, /* speaker */
4560 { 0x16, 0x99030130 }, /* bass speaker */
4561 { }
4562 },
4563 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004564 [ALC880_FIXUP_UNIWILL_DIG] = {
4565 .type = ALC_FIXUP_PINS,
4566 .v.pins = (const struct alc_pincfg[]) {
4567 /* disable bogus unused pins */
4568 { 0x17, 0x411111f0 },
4569 { 0x19, 0x411111f0 },
4570 { 0x1b, 0x411111f0 },
4571 { 0x1f, 0x411111f0 },
4572 { }
4573 }
4574 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004575 [ALC880_FIXUP_Z71V] = {
4576 .type = ALC_FIXUP_PINS,
4577 .v.pins = (const struct alc_pincfg[]) {
4578 /* set up the whole pins as BIOS is utterly broken */
4579 { 0x14, 0x99030120 }, /* speaker */
4580 { 0x15, 0x0121411f }, /* HP */
4581 { 0x16, 0x411111f0 }, /* N/A */
4582 { 0x17, 0x411111f0 }, /* N/A */
4583 { 0x18, 0x01a19950 }, /* mic-in */
4584 { 0x19, 0x411111f0 }, /* N/A */
4585 { 0x1a, 0x01813031 }, /* line-in */
4586 { 0x1b, 0x411111f0 }, /* N/A */
4587 { 0x1c, 0x411111f0 }, /* N/A */
4588 { 0x1d, 0x411111f0 }, /* N/A */
4589 { 0x1e, 0x0144111e }, /* SPDIF */
4590 { }
4591 }
4592 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004593 [ALC880_FIXUP_3ST_BASE] = {
4594 .type = ALC_FIXUP_PINS,
4595 .v.pins = (const struct alc_pincfg[]) {
4596 { 0x14, 0x01014010 }, /* line-out */
4597 { 0x15, 0x411111f0 }, /* N/A */
4598 { 0x16, 0x411111f0 }, /* N/A */
4599 { 0x17, 0x411111f0 }, /* N/A */
4600 { 0x18, 0x01a19c30 }, /* mic-in */
4601 { 0x19, 0x0121411f }, /* HP */
4602 { 0x1a, 0x01813031 }, /* line-in */
4603 { 0x1b, 0x02a19c40 }, /* front-mic */
4604 { 0x1c, 0x411111f0 }, /* N/A */
4605 { 0x1d, 0x411111f0 }, /* N/A */
4606 /* 0x1e is filled in below */
4607 { 0x1f, 0x411111f0 }, /* N/A */
4608 { }
4609 }
4610 },
4611 [ALC880_FIXUP_3ST] = {
4612 .type = ALC_FIXUP_PINS,
4613 .v.pins = (const struct alc_pincfg[]) {
4614 { 0x1e, 0x411111f0 }, /* N/A */
4615 { }
4616 },
4617 .chained = true,
4618 .chain_id = ALC880_FIXUP_3ST_BASE,
4619 },
4620 [ALC880_FIXUP_3ST_DIG] = {
4621 .type = ALC_FIXUP_PINS,
4622 .v.pins = (const struct alc_pincfg[]) {
4623 { 0x1e, 0x0144111e }, /* SPDIF */
4624 { }
4625 },
4626 .chained = true,
4627 .chain_id = ALC880_FIXUP_3ST_BASE,
4628 },
4629 [ALC880_FIXUP_5ST_BASE] = {
4630 .type = ALC_FIXUP_PINS,
4631 .v.pins = (const struct alc_pincfg[]) {
4632 { 0x14, 0x01014010 }, /* front */
4633 { 0x15, 0x411111f0 }, /* N/A */
4634 { 0x16, 0x01011411 }, /* CLFE */
4635 { 0x17, 0x01016412 }, /* surr */
4636 { 0x18, 0x01a19c30 }, /* mic-in */
4637 { 0x19, 0x0121411f }, /* HP */
4638 { 0x1a, 0x01813031 }, /* line-in */
4639 { 0x1b, 0x02a19c40 }, /* front-mic */
4640 { 0x1c, 0x411111f0 }, /* N/A */
4641 { 0x1d, 0x411111f0 }, /* N/A */
4642 /* 0x1e is filled in below */
4643 { 0x1f, 0x411111f0 }, /* N/A */
4644 { }
4645 }
4646 },
4647 [ALC880_FIXUP_5ST] = {
4648 .type = ALC_FIXUP_PINS,
4649 .v.pins = (const struct alc_pincfg[]) {
4650 { 0x1e, 0x411111f0 }, /* N/A */
4651 { }
4652 },
4653 .chained = true,
4654 .chain_id = ALC880_FIXUP_5ST_BASE,
4655 },
4656 [ALC880_FIXUP_5ST_DIG] = {
4657 .type = ALC_FIXUP_PINS,
4658 .v.pins = (const struct alc_pincfg[]) {
4659 { 0x1e, 0x0144111e }, /* SPDIF */
4660 { }
4661 },
4662 .chained = true,
4663 .chain_id = ALC880_FIXUP_5ST_BASE,
4664 },
4665 [ALC880_FIXUP_6ST_BASE] = {
4666 .type = ALC_FIXUP_PINS,
4667 .v.pins = (const struct alc_pincfg[]) {
4668 { 0x14, 0x01014010 }, /* front */
4669 { 0x15, 0x01016412 }, /* surr */
4670 { 0x16, 0x01011411 }, /* CLFE */
4671 { 0x17, 0x01012414 }, /* side */
4672 { 0x18, 0x01a19c30 }, /* mic-in */
4673 { 0x19, 0x02a19c40 }, /* front-mic */
4674 { 0x1a, 0x01813031 }, /* line-in */
4675 { 0x1b, 0x0121411f }, /* HP */
4676 { 0x1c, 0x411111f0 }, /* N/A */
4677 { 0x1d, 0x411111f0 }, /* N/A */
4678 /* 0x1e is filled in below */
4679 { 0x1f, 0x411111f0 }, /* N/A */
4680 { }
4681 }
4682 },
4683 [ALC880_FIXUP_6ST] = {
4684 .type = ALC_FIXUP_PINS,
4685 .v.pins = (const struct alc_pincfg[]) {
4686 { 0x1e, 0x411111f0 }, /* N/A */
4687 { }
4688 },
4689 .chained = true,
4690 .chain_id = ALC880_FIXUP_6ST_BASE,
4691 },
4692 [ALC880_FIXUP_6ST_DIG] = {
4693 .type = ALC_FIXUP_PINS,
4694 .v.pins = (const struct alc_pincfg[]) {
4695 { 0x1e, 0x0144111e }, /* SPDIF */
4696 { }
4697 },
4698 .chained = true,
4699 .chain_id = ALC880_FIXUP_6ST_BASE,
4700 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004701};
4702
4703static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004704 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004705 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004706 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4707 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004708 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004709 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004710 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004711 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004712 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004713 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004714 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004715 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004716 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004717 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004718 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004719 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4720 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4721 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004722 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004723
4724 /* Below is the copied entries from alc880_quirks.c.
4725 * It's not quite sure whether BIOS sets the correct pin-config table
4726 * on these machines, thus they are kept to be compatible with
4727 * the old static quirks. Once when it's confirmed to work without
4728 * these overrides, it'd be better to remove.
4729 */
4730 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4731 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4732 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4733 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4734 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4735 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4736 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4737 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4738 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4739 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4740 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4741 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4742 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4743 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4744 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4745 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4746 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4747 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4748 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4749 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4750 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4751 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4752 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4753 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4754 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4755 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4756 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4757 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4758 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4759 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4760 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4761 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4762 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4763 /* default Intel */
4764 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4765 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4766 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4767 {}
4768};
4769
4770static const struct alc_model_fixup alc880_fixup_models[] = {
4771 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4772 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4773 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4774 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4775 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4776 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004777 {}
4778};
4779
4780
4781/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004782 * OK, here we have finally the patch for ALC880
4783 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004784static int patch_alc880(struct hda_codec *codec)
4785{
4786 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004787 int err;
4788
Takashi Iwai3de95172012-05-07 18:03:15 +02004789 err = alc_alloc_spec(codec, 0x0b);
4790 if (err < 0)
4791 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004792
Takashi Iwai3de95172012-05-07 18:03:15 +02004793 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004794 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004795
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004796 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4797 alc880_fixups);
4798 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004799
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004800 /* automatic parse from the BIOS config */
4801 err = alc880_parse_auto_config(codec);
4802 if (err < 0)
4803 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004804
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004805 if (!spec->no_analog) {
4806 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004807 if (err < 0)
4808 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004809 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4810 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004811
Takashi Iwai1d045db2011-07-07 18:23:21 +02004812 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004813
Takashi Iwai589876e2012-02-20 15:47:55 +01004814 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4815
Takashi Iwai1d045db2011-07-07 18:23:21 +02004816 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004817
4818 error:
4819 alc_free(codec);
4820 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004821}
4822
4823
4824/*
4825 * ALC260 support
4826 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004827static int alc260_parse_auto_config(struct hda_codec *codec)
4828{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004829 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004830 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4831 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004832}
4833
Takashi Iwai1d045db2011-07-07 18:23:21 +02004834/*
4835 * Pin config fixes
4836 */
4837enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004838 ALC260_FIXUP_HP_DC5750,
4839 ALC260_FIXUP_HP_PIN_0F,
4840 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004841 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004842 ALC260_FIXUP_GPIO1_TOGGLE,
4843 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004844 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004845 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004846};
4847
Takashi Iwai20f7d922012-02-16 12:35:16 +01004848static void alc260_gpio1_automute(struct hda_codec *codec)
4849{
4850 struct alc_spec *spec = codec->spec;
4851 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4852 spec->hp_jack_present);
4853}
4854
4855static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4856 const struct alc_fixup *fix, int action)
4857{
4858 struct alc_spec *spec = codec->spec;
4859 if (action == ALC_FIXUP_ACT_PROBE) {
4860 /* although the machine has only one output pin, we need to
4861 * toggle GPIO1 according to the jack state
4862 */
4863 spec->automute_hook = alc260_gpio1_automute;
4864 spec->detect_hp = 1;
4865 spec->automute_speaker = 1;
4866 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4867 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004868 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004869 }
4870}
4871
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004872static void alc260_fixup_kn1(struct hda_codec *codec,
4873 const struct alc_fixup *fix, int action)
4874{
4875 struct alc_spec *spec = codec->spec;
4876 static const struct alc_pincfg pincfgs[] = {
4877 { 0x0f, 0x02214000 }, /* HP/speaker */
4878 { 0x12, 0x90a60160 }, /* int mic */
4879 { 0x13, 0x02a19000 }, /* ext mic */
4880 { 0x18, 0x01446000 }, /* SPDIF out */
4881 /* disable bogus I/O pins */
4882 { 0x10, 0x411111f0 },
4883 { 0x11, 0x411111f0 },
4884 { 0x14, 0x411111f0 },
4885 { 0x15, 0x411111f0 },
4886 { 0x16, 0x411111f0 },
4887 { 0x17, 0x411111f0 },
4888 { 0x19, 0x411111f0 },
4889 { }
4890 };
4891
4892 switch (action) {
4893 case ALC_FIXUP_ACT_PRE_PROBE:
4894 alc_apply_pincfgs(codec, pincfgs);
4895 break;
4896 case ALC_FIXUP_ACT_PROBE:
4897 spec->init_amp = ALC_INIT_NONE;
4898 break;
4899 }
4900}
4901
Takashi Iwai1d045db2011-07-07 18:23:21 +02004902static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004903 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004904 .type = ALC_FIXUP_PINS,
4905 .v.pins = (const struct alc_pincfg[]) {
4906 { 0x11, 0x90130110 }, /* speaker */
4907 { }
4908 }
4909 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004910 [ALC260_FIXUP_HP_PIN_0F] = {
4911 .type = ALC_FIXUP_PINS,
4912 .v.pins = (const struct alc_pincfg[]) {
4913 { 0x0f, 0x01214000 }, /* HP */
4914 { }
4915 }
4916 },
4917 [ALC260_FIXUP_COEF] = {
4918 .type = ALC_FIXUP_VERBS,
4919 .v.verbs = (const struct hda_verb[]) {
4920 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4921 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4922 { }
4923 },
4924 .chained = true,
4925 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4926 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004927 [ALC260_FIXUP_GPIO1] = {
4928 .type = ALC_FIXUP_VERBS,
4929 .v.verbs = alc_gpio1_init_verbs,
4930 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004931 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4932 .type = ALC_FIXUP_FUNC,
4933 .v.func = alc260_fixup_gpio1_toggle,
4934 .chained = true,
4935 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4936 },
4937 [ALC260_FIXUP_REPLACER] = {
4938 .type = ALC_FIXUP_VERBS,
4939 .v.verbs = (const struct hda_verb[]) {
4940 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4941 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4942 { }
4943 },
4944 .chained = true,
4945 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4946 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004947 [ALC260_FIXUP_HP_B1900] = {
4948 .type = ALC_FIXUP_FUNC,
4949 .v.func = alc260_fixup_gpio1_toggle,
4950 .chained = true,
4951 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004952 },
4953 [ALC260_FIXUP_KN1] = {
4954 .type = ALC_FIXUP_FUNC,
4955 .v.func = alc260_fixup_kn1,
4956 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004957};
4958
4959static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004960 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004961 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004962 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004963 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004964 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004965 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004966 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004967 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004968 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004969 {}
4970};
4971
4972/*
4973 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004974static int patch_alc260(struct hda_codec *codec)
4975{
4976 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004977 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004978
Takashi Iwai3de95172012-05-07 18:03:15 +02004979 err = alc_alloc_spec(codec, 0x07);
4980 if (err < 0)
4981 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004982
Takashi Iwai3de95172012-05-07 18:03:15 +02004983 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004984
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004985 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4986 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004987
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004988 /* automatic parse from the BIOS config */
4989 err = alc260_parse_auto_config(codec);
4990 if (err < 0)
4991 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004992
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004993 if (!spec->no_analog) {
4994 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004995 if (err < 0)
4996 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004997 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4998 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004999
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005001 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005002
Takashi Iwai589876e2012-02-20 15:47:55 +01005003 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5004
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005006
5007 error:
5008 alc_free(codec);
5009 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005010}
5011
5012
5013/*
5014 * ALC882/883/885/888/889 support
5015 *
5016 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5017 * configuration. Each pin widget can choose any input DACs and a mixer.
5018 * Each ADC is connected from a mixer of all inputs. This makes possible
5019 * 6-channel independent captures.
5020 *
5021 * In addition, an independent DAC for the multi-playback (not used in this
5022 * driver yet).
5023 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005024
5025/*
5026 * Pin config fixes
5027 */
5028enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005029 ALC882_FIXUP_ABIT_AW9D_MAX,
5030 ALC882_FIXUP_LENOVO_Y530,
5031 ALC882_FIXUP_PB_M5210,
5032 ALC882_FIXUP_ACER_ASPIRE_7736,
5033 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005034 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005035 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005036 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005037 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005038 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005039 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005040 ALC882_FIXUP_GPIO1,
5041 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005042 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005043 ALC889_FIXUP_COEF,
5044 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005045 ALC882_FIXUP_ACER_ASPIRE_4930G,
5046 ALC882_FIXUP_ACER_ASPIRE_8930G,
5047 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005048 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005049 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005050 ALC889_FIXUP_MBP_VREF,
5051 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005052 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005053 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005054};
5055
Takashi Iwai68ef0562011-11-09 18:24:44 +01005056static void alc889_fixup_coef(struct hda_codec *codec,
5057 const struct alc_fixup *fix, int action)
5058{
5059 if (action != ALC_FIXUP_ACT_INIT)
5060 return;
5061 alc889_coef_init(codec);
5062}
5063
Takashi Iwai56710872011-11-14 17:42:11 +01005064/* toggle speaker-output according to the hp-jack state */
5065static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5066{
5067 unsigned int gpiostate, gpiomask, gpiodir;
5068
5069 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5070 AC_VERB_GET_GPIO_DATA, 0);
5071
5072 if (!muted)
5073 gpiostate |= (1 << pin);
5074 else
5075 gpiostate &= ~(1 << pin);
5076
5077 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5078 AC_VERB_GET_GPIO_MASK, 0);
5079 gpiomask |= (1 << pin);
5080
5081 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5082 AC_VERB_GET_GPIO_DIRECTION, 0);
5083 gpiodir |= (1 << pin);
5084
5085
5086 snd_hda_codec_write(codec, codec->afg, 0,
5087 AC_VERB_SET_GPIO_MASK, gpiomask);
5088 snd_hda_codec_write(codec, codec->afg, 0,
5089 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5090
5091 msleep(1);
5092
5093 snd_hda_codec_write(codec, codec->afg, 0,
5094 AC_VERB_SET_GPIO_DATA, gpiostate);
5095}
5096
5097/* set up GPIO at initialization */
5098static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5099 const struct alc_fixup *fix, int action)
5100{
5101 if (action != ALC_FIXUP_ACT_INIT)
5102 return;
5103 alc882_gpio_mute(codec, 0, 0);
5104 alc882_gpio_mute(codec, 1, 0);
5105}
5106
Takashi Iwai02a237b2012-02-13 15:25:07 +01005107/* Fix the connection of some pins for ALC889:
5108 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5109 * work correctly (bko#42740)
5110 */
5111static void alc889_fixup_dac_route(struct hda_codec *codec,
5112 const struct alc_fixup *fix, int action)
5113{
5114 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005115 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005116 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5117 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5118 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5119 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5120 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5121 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005122 } else if (action == ALC_FIXUP_ACT_PROBE) {
5123 /* restore the connections */
5124 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5125 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5126 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5127 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5128 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005129 }
5130}
5131
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005132/* Set VREF on HP pin */
5133static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5134 const struct alc_fixup *fix, int action)
5135{
5136 struct alc_spec *spec = codec->spec;
5137 static hda_nid_t nids[2] = { 0x14, 0x15 };
5138 int i;
5139
5140 if (action != ALC_FIXUP_ACT_INIT)
5141 return;
5142 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5143 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5144 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5145 continue;
5146 val = snd_hda_codec_read(codec, nids[i], 0,
5147 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5148 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005149 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005150 spec->keep_vref_in_automute = 1;
5151 break;
5152 }
5153}
5154
5155/* Set VREF on speaker pins on imac91 */
5156static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5157 const struct alc_fixup *fix, int action)
5158{
5159 struct alc_spec *spec = codec->spec;
5160 static hda_nid_t nids[2] = { 0x18, 0x1a };
5161 int i;
5162
5163 if (action != ALC_FIXUP_ACT_INIT)
5164 return;
5165 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5166 unsigned int val;
5167 val = snd_hda_codec_read(codec, nids[i], 0,
5168 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5169 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005170 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005171 }
5172 spec->keep_vref_in_automute = 1;
5173}
5174
Takashi Iwaie427c232012-07-29 10:04:08 +02005175/* Don't take HP output as primary
5176 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5177 */
5178static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5179 const struct alc_fixup *fix, int action)
5180{
5181 struct alc_spec *spec = codec->spec;
5182 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5183 spec->no_primary_hp = 1;
5184}
5185
Takashi Iwai1d045db2011-07-07 18:23:21 +02005186static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005187 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005188 .type = ALC_FIXUP_PINS,
5189 .v.pins = (const struct alc_pincfg[]) {
5190 { 0x15, 0x01080104 }, /* side */
5191 { 0x16, 0x01011012 }, /* rear */
5192 { 0x17, 0x01016011 }, /* clfe */
5193 { }
5194 }
5195 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005196 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005197 .type = ALC_FIXUP_PINS,
5198 .v.pins = (const struct alc_pincfg[]) {
5199 { 0x15, 0x99130112 }, /* rear int speakers */
5200 { 0x16, 0x99130111 }, /* subwoofer */
5201 { }
5202 }
5203 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005204 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005205 .type = ALC_FIXUP_VERBS,
5206 .v.verbs = (const struct hda_verb[]) {
5207 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5208 {}
5209 }
5210 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005211 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005212 .type = ALC_FIXUP_FUNC,
5213 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005214 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005215 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005216 .type = ALC_FIXUP_PINS,
5217 .v.pins = (const struct alc_pincfg[]) {
5218 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5219 { }
5220 }
5221 },
Marton Balint8f239212012-03-05 21:33:23 +01005222 [ALC889_FIXUP_CD] = {
5223 .type = ALC_FIXUP_PINS,
5224 .v.pins = (const struct alc_pincfg[]) {
5225 { 0x1c, 0x993301f0 }, /* CD */
5226 { }
5227 }
5228 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005229 [ALC889_FIXUP_VAIO_TT] = {
5230 .type = ALC_FIXUP_PINS,
5231 .v.pins = (const struct alc_pincfg[]) {
5232 { 0x17, 0x90170111 }, /* hidden surround speaker */
5233 { }
5234 }
5235 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005236 [ALC888_FIXUP_EEE1601] = {
5237 .type = ALC_FIXUP_VERBS,
5238 .v.verbs = (const struct hda_verb[]) {
5239 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5240 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5241 { }
5242 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005243 },
5244 [ALC882_FIXUP_EAPD] = {
5245 .type = ALC_FIXUP_VERBS,
5246 .v.verbs = (const struct hda_verb[]) {
5247 /* change to EAPD mode */
5248 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5249 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5250 { }
5251 }
5252 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005253 [ALC883_FIXUP_EAPD] = {
5254 .type = ALC_FIXUP_VERBS,
5255 .v.verbs = (const struct hda_verb[]) {
5256 /* change to EAPD mode */
5257 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5258 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5259 { }
5260 }
5261 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005262 [ALC883_FIXUP_ACER_EAPD] = {
5263 .type = ALC_FIXUP_VERBS,
5264 .v.verbs = (const struct hda_verb[]) {
5265 /* eanable EAPD on Acer laptops */
5266 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5267 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5268 { }
5269 }
5270 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005271 [ALC882_FIXUP_GPIO1] = {
5272 .type = ALC_FIXUP_VERBS,
5273 .v.verbs = alc_gpio1_init_verbs,
5274 },
5275 [ALC882_FIXUP_GPIO2] = {
5276 .type = ALC_FIXUP_VERBS,
5277 .v.verbs = alc_gpio2_init_verbs,
5278 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005279 [ALC882_FIXUP_GPIO3] = {
5280 .type = ALC_FIXUP_VERBS,
5281 .v.verbs = alc_gpio3_init_verbs,
5282 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005283 [ALC882_FIXUP_ASUS_W2JC] = {
5284 .type = ALC_FIXUP_VERBS,
5285 .v.verbs = alc_gpio1_init_verbs,
5286 .chained = true,
5287 .chain_id = ALC882_FIXUP_EAPD,
5288 },
5289 [ALC889_FIXUP_COEF] = {
5290 .type = ALC_FIXUP_FUNC,
5291 .v.func = alc889_fixup_coef,
5292 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005293 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5294 .type = ALC_FIXUP_PINS,
5295 .v.pins = (const struct alc_pincfg[]) {
5296 { 0x16, 0x99130111 }, /* CLFE speaker */
5297 { 0x17, 0x99130112 }, /* surround speaker */
5298 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005299 },
5300 .chained = true,
5301 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005302 },
5303 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5304 .type = ALC_FIXUP_PINS,
5305 .v.pins = (const struct alc_pincfg[]) {
5306 { 0x16, 0x99130111 }, /* CLFE speaker */
5307 { 0x1b, 0x99130112 }, /* surround speaker */
5308 { }
5309 },
5310 .chained = true,
5311 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5312 },
5313 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5314 /* additional init verbs for Acer Aspire 8930G */
5315 .type = ALC_FIXUP_VERBS,
5316 .v.verbs = (const struct hda_verb[]) {
5317 /* Enable all DACs */
5318 /* DAC DISABLE/MUTE 1? */
5319 /* setting bits 1-5 disables DAC nids 0x02-0x06
5320 * apparently. Init=0x38 */
5321 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5322 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5323 /* DAC DISABLE/MUTE 2? */
5324 /* some bit here disables the other DACs.
5325 * Init=0x4900 */
5326 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5327 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5328 /* DMIC fix
5329 * This laptop has a stereo digital microphone.
5330 * The mics are only 1cm apart which makes the stereo
5331 * useless. However, either the mic or the ALC889
5332 * makes the signal become a difference/sum signal
5333 * instead of standard stereo, which is annoying.
5334 * So instead we flip this bit which makes the
5335 * codec replicate the sum signal to both channels,
5336 * turning it into a normal mono mic.
5337 */
5338 /* DMIC_CONTROL? Init value = 0x0001 */
5339 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5340 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5341 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5342 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5343 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005344 },
5345 .chained = true,
5346 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005347 },
Takashi Iwai56710872011-11-14 17:42:11 +01005348 [ALC885_FIXUP_MACPRO_GPIO] = {
5349 .type = ALC_FIXUP_FUNC,
5350 .v.func = alc885_fixup_macpro_gpio,
5351 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005352 [ALC889_FIXUP_DAC_ROUTE] = {
5353 .type = ALC_FIXUP_FUNC,
5354 .v.func = alc889_fixup_dac_route,
5355 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005356 [ALC889_FIXUP_MBP_VREF] = {
5357 .type = ALC_FIXUP_FUNC,
5358 .v.func = alc889_fixup_mbp_vref,
5359 .chained = true,
5360 .chain_id = ALC882_FIXUP_GPIO1,
5361 },
5362 [ALC889_FIXUP_IMAC91_VREF] = {
5363 .type = ALC_FIXUP_FUNC,
5364 .v.func = alc889_fixup_imac91_vref,
5365 .chained = true,
5366 .chain_id = ALC882_FIXUP_GPIO1,
5367 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005368 [ALC882_FIXUP_INV_DMIC] = {
5369 .type = ALC_FIXUP_FUNC,
5370 .v.func = alc_fixup_inv_dmic_0x12,
5371 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005372 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5373 .type = ALC_FIXUP_FUNC,
5374 .v.func = alc882_fixup_no_primary_hp,
5375 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005376};
5377
5378static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005379 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5380 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5381 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5382 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5383 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5384 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005385 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5386 ALC882_FIXUP_ACER_ASPIRE_4930G),
5387 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5388 ALC882_FIXUP_ACER_ASPIRE_4930G),
5389 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5390 ALC882_FIXUP_ACER_ASPIRE_8930G),
5391 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5392 ALC882_FIXUP_ACER_ASPIRE_8930G),
5393 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5394 ALC882_FIXUP_ACER_ASPIRE_4930G),
5395 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5396 ALC882_FIXUP_ACER_ASPIRE_4930G),
5397 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5398 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005399 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005400 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5401 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005402 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005403 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005404 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005405 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005406 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005407 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005408 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005409 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005410 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005411
5412 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005413 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5414 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5415 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005416 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5417 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5418 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005419 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5420 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005421 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005422 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5423 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5424 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5425 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005426 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005427 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5428 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5429 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005430 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005431 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5432 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5433 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005434
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005435 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005436 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005437 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005438 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005439 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005440 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5441 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005442 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005443 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005444 {}
5445};
5446
Takashi Iwai912093b2012-04-11 14:03:41 +02005447static const struct alc_model_fixup alc882_fixup_models[] = {
5448 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5449 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5450 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005451 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005452 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005453 {}
5454};
5455
Takashi Iwai1d045db2011-07-07 18:23:21 +02005456/*
5457 * BIOS auto configuration
5458 */
5459/* almost identical with ALC880 parser... */
5460static int alc882_parse_auto_config(struct hda_codec *codec)
5461{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005462 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005463 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5464 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005465}
5466
Takashi Iwai1d045db2011-07-07 18:23:21 +02005467/*
5468 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005469static int patch_alc882(struct hda_codec *codec)
5470{
5471 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005472 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005473
Takashi Iwai3de95172012-05-07 18:03:15 +02005474 err = alc_alloc_spec(codec, 0x0b);
5475 if (err < 0)
5476 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005477
Takashi Iwai3de95172012-05-07 18:03:15 +02005478 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005479
5480 switch (codec->vendor_id) {
5481 case 0x10ec0882:
5482 case 0x10ec0885:
5483 break;
5484 default:
5485 /* ALC883 and variants */
5486 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5487 break;
5488 }
5489
Takashi Iwai912093b2012-04-11 14:03:41 +02005490 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5491 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005492 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005493
5494 alc_auto_parse_customize_define(codec);
5495
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005496 /* automatic parse from the BIOS config */
5497 err = alc882_parse_auto_config(codec);
5498 if (err < 0)
5499 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005500
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005501 if (!spec->no_analog && has_cdefine_beep(codec)) {
5502 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005503 if (err < 0)
5504 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005506 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005507
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005509
Takashi Iwai589876e2012-02-20 15:47:55 +01005510 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5511
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005513
5514 error:
5515 alc_free(codec);
5516 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005517}
5518
5519
5520/*
5521 * ALC262 support
5522 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005523static int alc262_parse_auto_config(struct hda_codec *codec)
5524{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005525 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005526 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5527 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005528}
5529
5530/*
5531 * Pin config fixes
5532 */
5533enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005534 ALC262_FIXUP_FSC_H270,
5535 ALC262_FIXUP_HP_Z200,
5536 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005537 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005538 ALC262_FIXUP_BENQ,
5539 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005540 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005541};
5542
5543static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005544 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005545 .type = ALC_FIXUP_PINS,
5546 .v.pins = (const struct alc_pincfg[]) {
5547 { 0x14, 0x99130110 }, /* speaker */
5548 { 0x15, 0x0221142f }, /* front HP */
5549 { 0x1b, 0x0121141f }, /* rear HP */
5550 { }
5551 }
5552 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005553 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005554 .type = ALC_FIXUP_PINS,
5555 .v.pins = (const struct alc_pincfg[]) {
5556 { 0x16, 0x99130120 }, /* internal speaker */
5557 { }
5558 }
5559 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005560 [ALC262_FIXUP_TYAN] = {
5561 .type = ALC_FIXUP_PINS,
5562 .v.pins = (const struct alc_pincfg[]) {
5563 { 0x14, 0x1993e1f0 }, /* int AUX */
5564 { }
5565 }
5566 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005567 [ALC262_FIXUP_LENOVO_3000] = {
5568 .type = ALC_FIXUP_VERBS,
5569 .v.verbs = (const struct hda_verb[]) {
5570 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005571 {}
5572 },
5573 .chained = true,
5574 .chain_id = ALC262_FIXUP_BENQ,
5575 },
5576 [ALC262_FIXUP_BENQ] = {
5577 .type = ALC_FIXUP_VERBS,
5578 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005579 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5580 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5581 {}
5582 }
5583 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005584 [ALC262_FIXUP_BENQ_T31] = {
5585 .type = ALC_FIXUP_VERBS,
5586 .v.verbs = (const struct hda_verb[]) {
5587 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5588 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5589 {}
5590 }
5591 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005592 [ALC262_FIXUP_INV_DMIC] = {
5593 .type = ALC_FIXUP_FUNC,
5594 .v.func = alc_fixup_inv_dmic_0x12,
5595 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005596};
5597
5598static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005599 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005600 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5601 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005602 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5603 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005604 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005605 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5606 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005607 {}
5608};
5609
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005610static const struct alc_model_fixup alc262_fixup_models[] = {
5611 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5612 {}
5613};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005614
Takashi Iwai1d045db2011-07-07 18:23:21 +02005615/*
5616 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005617static int patch_alc262(struct hda_codec *codec)
5618{
5619 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005620 int err;
5621
Takashi Iwai3de95172012-05-07 18:03:15 +02005622 err = alc_alloc_spec(codec, 0x0b);
5623 if (err < 0)
5624 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005625
Takashi Iwai3de95172012-05-07 18:03:15 +02005626 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005627
5628#if 0
5629 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5630 * under-run
5631 */
5632 {
5633 int tmp;
5634 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5635 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5636 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5637 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5638 }
5639#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005640 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5641
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005642 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5643 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005644 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005646 alc_auto_parse_customize_define(codec);
5647
Takashi Iwai42399f72011-11-07 17:18:44 +01005648 /* automatic parse from the BIOS config */
5649 err = alc262_parse_auto_config(codec);
5650 if (err < 0)
5651 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005652
Takashi Iwai1d045db2011-07-07 18:23:21 +02005653 if (!spec->no_analog && has_cdefine_beep(codec)) {
5654 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005655 if (err < 0)
5656 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005658 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005659
Takashi Iwai1d045db2011-07-07 18:23:21 +02005660 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661 spec->shutup = alc_eapd_shutup;
5662
Takashi Iwai589876e2012-02-20 15:47:55 +01005663 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5664
Takashi Iwai1d045db2011-07-07 18:23:21 +02005665 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005666
5667 error:
5668 alc_free(codec);
5669 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005670}
5671
5672/*
5673 * ALC268
5674 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005675/* bind Beep switches of both NID 0x0f and 0x10 */
5676static const struct hda_bind_ctls alc268_bind_beep_sw = {
5677 .ops = &snd_hda_bind_sw,
5678 .values = {
5679 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5680 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5681 0
5682 },
5683};
5684
5685static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5686 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5687 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5688 { }
5689};
5690
5691/* set PCBEEP vol = 0, mute connections */
5692static const struct hda_verb alc268_beep_init_verbs[] = {
5693 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5694 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5695 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5696 { }
5697};
5698
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005699enum {
5700 ALC268_FIXUP_INV_DMIC,
5701};
5702
5703static const struct alc_fixup alc268_fixups[] = {
5704 [ALC268_FIXUP_INV_DMIC] = {
5705 .type = ALC_FIXUP_FUNC,
5706 .v.func = alc_fixup_inv_dmic_0x12,
5707 },
5708};
5709
5710static const struct alc_model_fixup alc268_fixup_models[] = {
5711 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5712 {}
5713};
5714
Takashi Iwai1d045db2011-07-07 18:23:21 +02005715/*
5716 * BIOS auto configuration
5717 */
5718static int alc268_parse_auto_config(struct hda_codec *codec)
5719{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005720 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005722 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5723 if (err > 0) {
5724 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5725 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005726 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005728 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005729 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005730}
5731
Takashi Iwai1d045db2011-07-07 18:23:21 +02005732/*
5733 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005734static int patch_alc268(struct hda_codec *codec)
5735{
5736 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005737 int i, has_beep, err;
5738
Takashi Iwai1d045db2011-07-07 18:23:21 +02005739 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005740 err = alc_alloc_spec(codec, 0);
5741 if (err < 0)
5742 return err;
5743
5744 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005746 alc_pick_fixup(codec, alc268_fixup_models, NULL, alc268_fixups);
5747 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5748
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005749 /* automatic parse from the BIOS config */
5750 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005751 if (err < 0)
5752 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754 has_beep = 0;
5755 for (i = 0; i < spec->num_mixers; i++) {
5756 if (spec->mixers[i] == alc268_beep_mixer) {
5757 has_beep = 1;
5758 break;
5759 }
5760 }
5761
5762 if (has_beep) {
5763 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005764 if (err < 0)
5765 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005766 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5767 /* override the amp caps for beep generator */
5768 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5769 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5770 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5771 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5772 (0 << AC_AMPCAP_MUTE_SHIFT));
5773 }
5774
Takashi Iwai1d045db2011-07-07 18:23:21 +02005775 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005776 spec->shutup = alc_eapd_shutup;
5777
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005778 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5779
Takashi Iwai1d045db2011-07-07 18:23:21 +02005780 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005781
5782 error:
5783 alc_free(codec);
5784 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005785}
5786
5787/*
5788 * ALC269
5789 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005790static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5791 .substreams = 1,
5792 .channels_min = 2,
5793 .channels_max = 8,
5794 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5795 /* NID is set in alc_build_pcms */
5796 .ops = {
5797 .open = alc_playback_pcm_open,
5798 .prepare = alc_playback_pcm_prepare,
5799 .cleanup = alc_playback_pcm_cleanup
5800 },
5801};
5802
5803static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5804 .substreams = 1,
5805 .channels_min = 2,
5806 .channels_max = 2,
5807 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5808 /* NID is set in alc_build_pcms */
5809};
5810
Takashi Iwai1d045db2011-07-07 18:23:21 +02005811/* different alc269-variants */
5812enum {
5813 ALC269_TYPE_ALC269VA,
5814 ALC269_TYPE_ALC269VB,
5815 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005816 ALC269_TYPE_ALC269VD,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005817};
5818
5819/*
5820 * BIOS auto configuration
5821 */
5822static int alc269_parse_auto_config(struct hda_codec *codec)
5823{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005824 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005825 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5826 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5827 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005828 const hda_nid_t *ssids;
5829
5830 switch (spec->codec_variant) {
5831 case ALC269_TYPE_ALC269VA:
5832 case ALC269_TYPE_ALC269VC:
5833 ssids = alc269va_ssids;
5834 break;
5835 case ALC269_TYPE_ALC269VB:
5836 case ALC269_TYPE_ALC269VD:
5837 ssids = alc269_ssids;
5838 break;
5839 default:
5840 ssids = alc269_ssids;
5841 break;
5842 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005843
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005844 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005845}
5846
Takashi Iwai1d045db2011-07-07 18:23:21 +02005847static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5848{
5849 int val = alc_read_coef_idx(codec, 0x04);
5850 if (power_up)
5851 val |= 1 << 11;
5852 else
5853 val &= ~(1 << 11);
5854 alc_write_coef_idx(codec, 0x04, val);
5855}
5856
5857static void alc269_shutup(struct hda_codec *codec)
5858{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005859 struct alc_spec *spec = codec->spec;
5860
5861 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5862 return;
5863
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005864 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005865 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005866 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005867 alc269_toggle_power_output(codec, 0);
5868 msleep(150);
5869 }
5870}
5871
Takashi Iwai2a439522011-07-26 09:52:50 +02005872#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005873static int alc269_resume(struct hda_codec *codec)
5874{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005875 struct alc_spec *spec = codec->spec;
5876
5877 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5878 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005879 alc269_toggle_power_output(codec, 0);
5880 msleep(150);
5881 }
5882
5883 codec->patch_ops.init(codec);
5884
Kailang Yangadcc70b2012-05-25 08:08:38 +02005885 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5886 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887 alc269_toggle_power_output(codec, 1);
5888 msleep(200);
5889 }
5890
Kailang Yangadcc70b2012-05-25 08:08:38 +02005891 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5892 (alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005893 alc269_toggle_power_output(codec, 1);
5894
5895 snd_hda_codec_resume_amp(codec);
5896 snd_hda_codec_resume_cache(codec);
5897 hda_call_check_power_status(codec, 0x01);
5898 return 0;
5899}
Takashi Iwai2a439522011-07-26 09:52:50 +02005900#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005901
David Henningsson108cc102012-07-20 10:37:25 +02005902static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5903 const struct alc_fixup *fix, int action)
5904{
5905 struct alc_spec *spec = codec->spec;
5906
5907 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5908 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5909}
5910
Takashi Iwai1d045db2011-07-07 18:23:21 +02005911static void alc269_fixup_hweq(struct hda_codec *codec,
5912 const struct alc_fixup *fix, int action)
5913{
5914 int coef;
5915
5916 if (action != ALC_FIXUP_ACT_INIT)
5917 return;
5918 coef = alc_read_coef_idx(codec, 0x1e);
5919 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5920}
5921
5922static void alc271_fixup_dmic(struct hda_codec *codec,
5923 const struct alc_fixup *fix, int action)
5924{
5925 static const struct hda_verb verbs[] = {
5926 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5927 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5928 {}
5929 };
5930 unsigned int cfg;
5931
5932 if (strcmp(codec->chip_name, "ALC271X"))
5933 return;
5934 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5935 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5936 snd_hda_sequence_write(codec, verbs);
5937}
5938
Takashi Iwai017f2a12011-07-09 14:42:25 +02005939static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5940 const struct alc_fixup *fix, int action)
5941{
5942 struct alc_spec *spec = codec->spec;
5943
5944 if (action != ALC_FIXUP_ACT_PROBE)
5945 return;
5946
5947 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5948 * fix the sample rate of analog I/O to 44.1kHz
5949 */
5950 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5951 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5952}
5953
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005954static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5955 const struct alc_fixup *fix, int action)
5956{
5957 int coef;
5958
5959 if (action != ALC_FIXUP_ACT_INIT)
5960 return;
5961 /* The digital-mic unit sends PDM (differential signal) instead of
5962 * the standard PCM, thus you can't record a valid mono stream as is.
5963 * Below is a workaround specific to ALC269 to control the dmic
5964 * signal source as mono.
5965 */
5966 coef = alc_read_coef_idx(codec, 0x07);
5967 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5968}
5969
Takashi Iwai24519912011-08-16 15:08:49 +02005970static void alc269_quanta_automute(struct hda_codec *codec)
5971{
David Henningsson42cf0d02011-09-20 12:04:56 +02005972 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005973
5974 snd_hda_codec_write(codec, 0x20, 0,
5975 AC_VERB_SET_COEF_INDEX, 0x0c);
5976 snd_hda_codec_write(codec, 0x20, 0,
5977 AC_VERB_SET_PROC_COEF, 0x680);
5978
5979 snd_hda_codec_write(codec, 0x20, 0,
5980 AC_VERB_SET_COEF_INDEX, 0x0c);
5981 snd_hda_codec_write(codec, 0x20, 0,
5982 AC_VERB_SET_PROC_COEF, 0x480);
5983}
5984
5985static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5986 const struct alc_fixup *fix, int action)
5987{
5988 struct alc_spec *spec = codec->spec;
5989 if (action != ALC_FIXUP_ACT_PROBE)
5990 return;
5991 spec->automute_hook = alc269_quanta_automute;
5992}
5993
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005994/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5995static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5996{
5997 struct hda_codec *codec = private_data;
5998 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005999 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006000}
6001
6002static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6003 const struct alc_fixup *fix, int action)
6004{
6005 struct alc_spec *spec = codec->spec;
6006 switch (action) {
6007 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006008 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735cb2012-03-13 07:55:10 +01006009 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006010 /* fallthru */
6011 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006012 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006013 break;
6014 }
6015}
6016
David Henningsson693b6132012-06-22 19:12:10 +02006017
Takashi Iwai1d045db2011-07-07 18:23:21 +02006018enum {
6019 ALC269_FIXUP_SONY_VAIO,
6020 ALC275_FIXUP_SONY_VAIO_GPIO2,
6021 ALC269_FIXUP_DELL_M101Z,
6022 ALC269_FIXUP_SKU_IGNORE,
6023 ALC269_FIXUP_ASUS_G73JW,
6024 ALC269_FIXUP_LENOVO_EAPD,
6025 ALC275_FIXUP_SONY_HWEQ,
6026 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006027 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006028 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006029 ALC269_FIXUP_QUANTA_MUTE,
6030 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006031 ALC269_FIXUP_AMIC,
6032 ALC269_FIXUP_DMIC,
6033 ALC269VB_FIXUP_AMIC,
6034 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006035 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006036 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006037 ALC269_FIXUP_LENOVO_DOCK,
6038 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006039};
6040
6041static const struct alc_fixup alc269_fixups[] = {
6042 [ALC269_FIXUP_SONY_VAIO] = {
6043 .type = ALC_FIXUP_VERBS,
6044 .v.verbs = (const struct hda_verb[]) {
6045 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6046 {}
6047 }
6048 },
6049 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6050 .type = ALC_FIXUP_VERBS,
6051 .v.verbs = (const struct hda_verb[]) {
6052 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6053 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6054 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6055 { }
6056 },
6057 .chained = true,
6058 .chain_id = ALC269_FIXUP_SONY_VAIO
6059 },
6060 [ALC269_FIXUP_DELL_M101Z] = {
6061 .type = ALC_FIXUP_VERBS,
6062 .v.verbs = (const struct hda_verb[]) {
6063 /* Enables internal speaker */
6064 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6065 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6066 {}
6067 }
6068 },
6069 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006070 .type = ALC_FIXUP_FUNC,
6071 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006072 },
6073 [ALC269_FIXUP_ASUS_G73JW] = {
6074 .type = ALC_FIXUP_PINS,
6075 .v.pins = (const struct alc_pincfg[]) {
6076 { 0x17, 0x99130111 }, /* subwoofer */
6077 { }
6078 }
6079 },
6080 [ALC269_FIXUP_LENOVO_EAPD] = {
6081 .type = ALC_FIXUP_VERBS,
6082 .v.verbs = (const struct hda_verb[]) {
6083 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6084 {}
6085 }
6086 },
6087 [ALC275_FIXUP_SONY_HWEQ] = {
6088 .type = ALC_FIXUP_FUNC,
6089 .v.func = alc269_fixup_hweq,
6090 .chained = true,
6091 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6092 },
6093 [ALC271_FIXUP_DMIC] = {
6094 .type = ALC_FIXUP_FUNC,
6095 .v.func = alc271_fixup_dmic,
6096 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006097 [ALC269_FIXUP_PCM_44K] = {
6098 .type = ALC_FIXUP_FUNC,
6099 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006100 .chained = true,
6101 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006102 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006103 [ALC269_FIXUP_STEREO_DMIC] = {
6104 .type = ALC_FIXUP_FUNC,
6105 .v.func = alc269_fixup_stereo_dmic,
6106 },
Takashi Iwai24519912011-08-16 15:08:49 +02006107 [ALC269_FIXUP_QUANTA_MUTE] = {
6108 .type = ALC_FIXUP_FUNC,
6109 .v.func = alc269_fixup_quanta_mute,
6110 },
6111 [ALC269_FIXUP_LIFEBOOK] = {
6112 .type = ALC_FIXUP_PINS,
6113 .v.pins = (const struct alc_pincfg[]) {
6114 { 0x1a, 0x2101103f }, /* dock line-out */
6115 { 0x1b, 0x23a11040 }, /* dock mic-in */
6116 { }
6117 },
6118 .chained = true,
6119 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6120 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006121 [ALC269_FIXUP_AMIC] = {
6122 .type = ALC_FIXUP_PINS,
6123 .v.pins = (const struct alc_pincfg[]) {
6124 { 0x14, 0x99130110 }, /* speaker */
6125 { 0x15, 0x0121401f }, /* HP out */
6126 { 0x18, 0x01a19c20 }, /* mic */
6127 { 0x19, 0x99a3092f }, /* int-mic */
6128 { }
6129 },
6130 },
6131 [ALC269_FIXUP_DMIC] = {
6132 .type = ALC_FIXUP_PINS,
6133 .v.pins = (const struct alc_pincfg[]) {
6134 { 0x12, 0x99a3092f }, /* int-mic */
6135 { 0x14, 0x99130110 }, /* speaker */
6136 { 0x15, 0x0121401f }, /* HP out */
6137 { 0x18, 0x01a19c20 }, /* mic */
6138 { }
6139 },
6140 },
6141 [ALC269VB_FIXUP_AMIC] = {
6142 .type = ALC_FIXUP_PINS,
6143 .v.pins = (const struct alc_pincfg[]) {
6144 { 0x14, 0x99130110 }, /* speaker */
6145 { 0x18, 0x01a19c20 }, /* mic */
6146 { 0x19, 0x99a3092f }, /* int-mic */
6147 { 0x21, 0x0121401f }, /* HP out */
6148 { }
6149 },
6150 },
David Henningsson2267ea92012-01-03 08:45:56 +01006151 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006152 .type = ALC_FIXUP_PINS,
6153 .v.pins = (const struct alc_pincfg[]) {
6154 { 0x12, 0x99a3092f }, /* int-mic */
6155 { 0x14, 0x99130110 }, /* speaker */
6156 { 0x18, 0x01a19c20 }, /* mic */
6157 { 0x21, 0x0121401f }, /* HP out */
6158 { }
6159 },
6160 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006161 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6162 .type = ALC_FIXUP_FUNC,
6163 .v.func = alc269_fixup_mic2_mute,
6164 },
David Henningsson693b6132012-06-22 19:12:10 +02006165 [ALC269_FIXUP_INV_DMIC] = {
6166 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006167 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006168 },
David Henningsson108cc102012-07-20 10:37:25 +02006169 [ALC269_FIXUP_LENOVO_DOCK] = {
6170 .type = ALC_FIXUP_PINS,
6171 .v.pins = (const struct alc_pincfg[]) {
6172 { 0x19, 0x23a11040 }, /* dock mic */
6173 { 0x1b, 0x2121103f }, /* dock headphone */
6174 { }
6175 },
6176 .chained = true,
6177 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6178 },
6179 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6180 .type = ALC_FIXUP_FUNC,
6181 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6182 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006183};
6184
6185static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006186 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6187 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006188 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006189 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006190 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006191 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006192 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6193 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6194 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6195 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6196 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006197 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6198 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6199 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6200 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6201 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6202 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006203 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006204 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6205 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6206 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6207 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6208 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006209 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006210 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006211 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006212 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006213 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006214 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006215
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006216#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006217 /* Below is a quirk table taken from the old code.
6218 * Basically the device should work as is without the fixup table.
6219 * If BIOS doesn't give a proper info, enable the corresponding
6220 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006221 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006222 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6223 ALC269_FIXUP_AMIC),
6224 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006225 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6226 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6227 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6228 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6229 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6230 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6231 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6232 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6233 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6234 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6235 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6236 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6237 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6238 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6239 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6240 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6241 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6242 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6243 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6244 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6245 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6246 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6247 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6248 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6249 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6250 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6251 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6252 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6253 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6254 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6255 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6256 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6257 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6258 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6259 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6260 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6261 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6262 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6263#endif
6264 {}
6265};
6266
6267static const struct alc_model_fixup alc269_fixup_models[] = {
6268 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6269 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006270 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6271 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6272 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006273 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006274 {}
6275};
6276
6277
Takashi Iwai546bb672012-03-07 08:37:19 +01006278static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006279{
Kailang Yang526af6e2012-03-07 08:25:20 +01006280 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006281 int val;
6282
Kailang Yang526af6e2012-03-07 08:25:20 +01006283 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006284 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006285
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006286 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006287 alc_write_coef_idx(codec, 0xf, 0x960b);
6288 alc_write_coef_idx(codec, 0xe, 0x8817);
6289 }
6290
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006291 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006292 alc_write_coef_idx(codec, 0xf, 0x960b);
6293 alc_write_coef_idx(codec, 0xe, 0x8814);
6294 }
6295
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006296 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006297 val = alc_read_coef_idx(codec, 0x04);
6298 /* Power up output pin */
6299 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6300 }
6301
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006302 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006303 val = alc_read_coef_idx(codec, 0xd);
6304 if ((val & 0x0c00) >> 10 != 0x1) {
6305 /* Capless ramp up clock control */
6306 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6307 }
6308 val = alc_read_coef_idx(codec, 0x17);
6309 if ((val & 0x01c0) >> 6 != 0x4) {
6310 /* Class D power on reset */
6311 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6312 }
6313 }
6314
6315 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6316 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6317
6318 val = alc_read_coef_idx(codec, 0x4); /* HP */
6319 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006320}
6321
6322/*
6323 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006324static int patch_alc269(struct hda_codec *codec)
6325{
6326 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006327 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006328
Takashi Iwai3de95172012-05-07 18:03:15 +02006329 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006330 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006331 return err;
6332
6333 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006334
Takashi Iwai1d045db2011-07-07 18:23:21 +02006335 if (codec->vendor_id == 0x10ec0269) {
6336 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006337 switch (alc_get_coef0(codec) & 0x00f0) {
6338 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006339 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006340 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006341 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006342 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006343 break;
6344 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006345 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6346 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006347 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006348 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006349 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006350 case 0x0030:
6351 spec->codec_variant = ALC269_TYPE_ALC269VD;
6352 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006353 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006354 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006355 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006356 if (err < 0)
6357 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006358 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006359 alc269_fill_coef(codec);
6360 }
6361
Takashi Iwaia4297b52011-08-23 18:40:12 +02006362 alc_pick_fixup(codec, alc269_fixup_models,
6363 alc269_fixup_tbl, alc269_fixups);
6364 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006365
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006366 alc_auto_parse_customize_define(codec);
6367
Takashi Iwaia4297b52011-08-23 18:40:12 +02006368 /* automatic parse from the BIOS config */
6369 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006370 if (err < 0)
6371 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006372
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006373 if (!spec->no_analog && has_cdefine_beep(codec)) {
6374 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006375 if (err < 0)
6376 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006377 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006378 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006379
Takashi Iwai1d045db2011-07-07 18:23:21 +02006380 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006381#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006382 codec->patch_ops.resume = alc269_resume;
6383#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006384 spec->shutup = alc269_shutup;
6385
Takashi Iwai589876e2012-02-20 15:47:55 +01006386 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6387
Takashi Iwai1d045db2011-07-07 18:23:21 +02006388 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006389
6390 error:
6391 alc_free(codec);
6392 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006393}
6394
6395/*
6396 * ALC861
6397 */
6398
Takashi Iwai1d045db2011-07-07 18:23:21 +02006399static int alc861_parse_auto_config(struct hda_codec *codec)
6400{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006401 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006402 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6403 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006404}
6405
Takashi Iwai1d045db2011-07-07 18:23:21 +02006406/* Pin config fixes */
6407enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006408 ALC861_FIXUP_FSC_AMILO_PI1505,
6409 ALC861_FIXUP_AMP_VREF_0F,
6410 ALC861_FIXUP_NO_JACK_DETECT,
6411 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006412};
6413
Takashi Iwai31150f22012-01-30 10:54:08 +01006414/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6415static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6416 const struct alc_fixup *fix, int action)
6417{
6418 struct alc_spec *spec = codec->spec;
6419 unsigned int val;
6420
6421 if (action != ALC_FIXUP_ACT_INIT)
6422 return;
6423 val = snd_hda_codec_read(codec, 0x0f, 0,
6424 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6425 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6426 val |= AC_PINCTL_IN_EN;
6427 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006428 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006429 spec->keep_vref_in_automute = 1;
6430}
6431
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006432/* suppress the jack-detection */
6433static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6434 const struct alc_fixup *fix, int action)
6435{
6436 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6437 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006438}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006439
Takashi Iwai1d045db2011-07-07 18:23:21 +02006440static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006441 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006442 .type = ALC_FIXUP_PINS,
6443 .v.pins = (const struct alc_pincfg[]) {
6444 { 0x0b, 0x0221101f }, /* HP */
6445 { 0x0f, 0x90170310 }, /* speaker */
6446 { }
6447 }
6448 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006449 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006450 .type = ALC_FIXUP_FUNC,
6451 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006452 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006453 [ALC861_FIXUP_NO_JACK_DETECT] = {
6454 .type = ALC_FIXUP_FUNC,
6455 .v.func = alc_fixup_no_jack_detect,
6456 },
6457 [ALC861_FIXUP_ASUS_A6RP] = {
6458 .type = ALC_FIXUP_FUNC,
6459 .v.func = alc861_fixup_asus_amp_vref_0f,
6460 .chained = true,
6461 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6462 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006463};
6464
6465static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006466 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6467 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6468 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6469 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6470 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6471 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006472 {}
6473};
6474
6475/*
6476 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006477static int patch_alc861(struct hda_codec *codec)
6478{
6479 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006480 int err;
6481
Takashi Iwai3de95172012-05-07 18:03:15 +02006482 err = alc_alloc_spec(codec, 0x15);
6483 if (err < 0)
6484 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006485
Takashi Iwai3de95172012-05-07 18:03:15 +02006486 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006487
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006488 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6489 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006490
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006491 /* automatic parse from the BIOS config */
6492 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006493 if (err < 0)
6494 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006495
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006496 if (!spec->no_analog) {
6497 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006498 if (err < 0)
6499 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006500 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6501 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006502
Takashi Iwai1d045db2011-07-07 18:23:21 +02006503 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006504#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006505 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006506#endif
6507
Takashi Iwai589876e2012-02-20 15:47:55 +01006508 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6509
Takashi Iwai1d045db2011-07-07 18:23:21 +02006510 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006511
6512 error:
6513 alc_free(codec);
6514 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006515}
6516
6517/*
6518 * ALC861-VD support
6519 *
6520 * Based on ALC882
6521 *
6522 * In addition, an independent DAC
6523 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006524static int alc861vd_parse_auto_config(struct hda_codec *codec)
6525{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006526 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006527 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6528 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006529}
6530
Takashi Iwai1d045db2011-07-07 18:23:21 +02006531enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006532 ALC660VD_FIX_ASUS_GPIO1,
6533 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006534};
6535
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006536/* exclude VREF80 */
6537static void alc861vd_fixup_dallas(struct hda_codec *codec,
6538 const struct alc_fixup *fix, int action)
6539{
6540 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6541 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6542 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6543 }
6544}
6545
Takashi Iwai1d045db2011-07-07 18:23:21 +02006546static const struct alc_fixup alc861vd_fixups[] = {
6547 [ALC660VD_FIX_ASUS_GPIO1] = {
6548 .type = ALC_FIXUP_VERBS,
6549 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006550 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006551 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6552 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6553 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6554 { }
6555 }
6556 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006557 [ALC861VD_FIX_DALLAS] = {
6558 .type = ALC_FIXUP_FUNC,
6559 .v.func = alc861vd_fixup_dallas,
6560 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006561};
6562
6563static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006564 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006565 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006566 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006567 {}
6568};
6569
Takashi Iwai1d045db2011-07-07 18:23:21 +02006570/*
6571 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006572static int patch_alc861vd(struct hda_codec *codec)
6573{
6574 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006575 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006576
Takashi Iwai3de95172012-05-07 18:03:15 +02006577 err = alc_alloc_spec(codec, 0x0b);
6578 if (err < 0)
6579 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006580
Takashi Iwai3de95172012-05-07 18:03:15 +02006581 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006582
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006583 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6584 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006585
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006586 /* automatic parse from the BIOS config */
6587 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006588 if (err < 0)
6589 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006590
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006591 if (!spec->no_analog) {
6592 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006593 if (err < 0)
6594 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006595 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6596 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006597
Takashi Iwai1d045db2011-07-07 18:23:21 +02006598 codec->patch_ops = alc_patch_ops;
6599
Takashi Iwai1d045db2011-07-07 18:23:21 +02006600 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006601
Takashi Iwai589876e2012-02-20 15:47:55 +01006602 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6603
Takashi Iwai1d045db2011-07-07 18:23:21 +02006604 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006605
6606 error:
6607 alc_free(codec);
6608 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006609}
6610
6611/*
6612 * ALC662 support
6613 *
6614 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6615 * configuration. Each pin widget can choose any input DACs and a mixer.
6616 * Each ADC is connected from a mixer of all inputs. This makes possible
6617 * 6-channel independent captures.
6618 *
6619 * In addition, an independent DAC for the multi-playback (not used in this
6620 * driver yet).
6621 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006622
6623/*
6624 * BIOS auto configuration
6625 */
6626
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006627static int alc662_parse_auto_config(struct hda_codec *codec)
6628{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006629 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006630 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6631 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6632 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006633
Kailang Yang6227cdc2010-02-25 08:36:52 +01006634 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6635 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006636 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006637 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006638 ssids = alc662_ssids;
6639 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006640}
6641
Todd Broch6be79482010-12-07 16:51:05 -08006642static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006643 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006644{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006645 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006646 return;
Todd Broch6be79482010-12-07 16:51:05 -08006647 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6648 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6649 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6650 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6651 (0 << AC_AMPCAP_MUTE_SHIFT)))
6652 printk(KERN_WARNING
6653 "hda_codec: failed to override amp caps for NID 0x2\n");
6654}
6655
David Henningsson6cb3b702010-09-09 08:51:44 +02006656enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006657 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006658 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006659 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006660 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006661 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006662 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006663 ALC662_FIXUP_ASUS_MODE1,
6664 ALC662_FIXUP_ASUS_MODE2,
6665 ALC662_FIXUP_ASUS_MODE3,
6666 ALC662_FIXUP_ASUS_MODE4,
6667 ALC662_FIXUP_ASUS_MODE5,
6668 ALC662_FIXUP_ASUS_MODE6,
6669 ALC662_FIXUP_ASUS_MODE7,
6670 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006671 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006672 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006673 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006674};
6675
6676static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006677 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006678 .type = ALC_FIXUP_PINS,
6679 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006680 { 0x15, 0x99130112 }, /* subwoofer */
6681 { }
6682 }
6683 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006684 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006685 .type = ALC_FIXUP_PINS,
6686 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006687 { 0x17, 0x99130112 }, /* subwoofer */
6688 { }
6689 }
6690 },
Todd Broch6be79482010-12-07 16:51:05 -08006691 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006692 .type = ALC_FIXUP_FUNC,
6693 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006694 },
6695 [ALC662_FIXUP_CZC_P10T] = {
6696 .type = ALC_FIXUP_VERBS,
6697 .v.verbs = (const struct hda_verb[]) {
6698 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6699 {}
6700 }
6701 },
David Henningsson94024cd2011-04-29 14:10:55 +02006702 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006703 .type = ALC_FIXUP_FUNC,
6704 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006705 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006706 [ALC662_FIXUP_HP_RP5800] = {
6707 .type = ALC_FIXUP_PINS,
6708 .v.pins = (const struct alc_pincfg[]) {
6709 { 0x14, 0x0221201f }, /* HP out */
6710 { }
6711 },
6712 .chained = true,
6713 .chain_id = ALC662_FIXUP_SKU_IGNORE
6714 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006715 [ALC662_FIXUP_ASUS_MODE1] = {
6716 .type = ALC_FIXUP_PINS,
6717 .v.pins = (const struct alc_pincfg[]) {
6718 { 0x14, 0x99130110 }, /* speaker */
6719 { 0x18, 0x01a19c20 }, /* mic */
6720 { 0x19, 0x99a3092f }, /* int-mic */
6721 { 0x21, 0x0121401f }, /* HP out */
6722 { }
6723 },
6724 .chained = true,
6725 .chain_id = ALC662_FIXUP_SKU_IGNORE
6726 },
6727 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006728 .type = ALC_FIXUP_PINS,
6729 .v.pins = (const struct alc_pincfg[]) {
6730 { 0x14, 0x99130110 }, /* speaker */
6731 { 0x18, 0x01a19820 }, /* mic */
6732 { 0x19, 0x99a3092f }, /* int-mic */
6733 { 0x1b, 0x0121401f }, /* HP out */
6734 { }
6735 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006736 .chained = true,
6737 .chain_id = ALC662_FIXUP_SKU_IGNORE
6738 },
6739 [ALC662_FIXUP_ASUS_MODE3] = {
6740 .type = ALC_FIXUP_PINS,
6741 .v.pins = (const struct alc_pincfg[]) {
6742 { 0x14, 0x99130110 }, /* speaker */
6743 { 0x15, 0x0121441f }, /* HP */
6744 { 0x18, 0x01a19840 }, /* mic */
6745 { 0x19, 0x99a3094f }, /* int-mic */
6746 { 0x21, 0x01211420 }, /* HP2 */
6747 { }
6748 },
6749 .chained = true,
6750 .chain_id = ALC662_FIXUP_SKU_IGNORE
6751 },
6752 [ALC662_FIXUP_ASUS_MODE4] = {
6753 .type = ALC_FIXUP_PINS,
6754 .v.pins = (const struct alc_pincfg[]) {
6755 { 0x14, 0x99130110 }, /* speaker */
6756 { 0x16, 0x99130111 }, /* speaker */
6757 { 0x18, 0x01a19840 }, /* mic */
6758 { 0x19, 0x99a3094f }, /* int-mic */
6759 { 0x21, 0x0121441f }, /* HP */
6760 { }
6761 },
6762 .chained = true,
6763 .chain_id = ALC662_FIXUP_SKU_IGNORE
6764 },
6765 [ALC662_FIXUP_ASUS_MODE5] = {
6766 .type = ALC_FIXUP_PINS,
6767 .v.pins = (const struct alc_pincfg[]) {
6768 { 0x14, 0x99130110 }, /* speaker */
6769 { 0x15, 0x0121441f }, /* HP */
6770 { 0x16, 0x99130111 }, /* speaker */
6771 { 0x18, 0x01a19840 }, /* mic */
6772 { 0x19, 0x99a3094f }, /* int-mic */
6773 { }
6774 },
6775 .chained = true,
6776 .chain_id = ALC662_FIXUP_SKU_IGNORE
6777 },
6778 [ALC662_FIXUP_ASUS_MODE6] = {
6779 .type = ALC_FIXUP_PINS,
6780 .v.pins = (const struct alc_pincfg[]) {
6781 { 0x14, 0x99130110 }, /* speaker */
6782 { 0x15, 0x01211420 }, /* HP2 */
6783 { 0x18, 0x01a19840 }, /* mic */
6784 { 0x19, 0x99a3094f }, /* int-mic */
6785 { 0x1b, 0x0121441f }, /* HP */
6786 { }
6787 },
6788 .chained = true,
6789 .chain_id = ALC662_FIXUP_SKU_IGNORE
6790 },
6791 [ALC662_FIXUP_ASUS_MODE7] = {
6792 .type = ALC_FIXUP_PINS,
6793 .v.pins = (const struct alc_pincfg[]) {
6794 { 0x14, 0x99130110 }, /* speaker */
6795 { 0x17, 0x99130111 }, /* speaker */
6796 { 0x18, 0x01a19840 }, /* mic */
6797 { 0x19, 0x99a3094f }, /* int-mic */
6798 { 0x1b, 0x01214020 }, /* HP */
6799 { 0x21, 0x0121401f }, /* HP */
6800 { }
6801 },
6802 .chained = true,
6803 .chain_id = ALC662_FIXUP_SKU_IGNORE
6804 },
6805 [ALC662_FIXUP_ASUS_MODE8] = {
6806 .type = ALC_FIXUP_PINS,
6807 .v.pins = (const struct alc_pincfg[]) {
6808 { 0x14, 0x99130110 }, /* speaker */
6809 { 0x12, 0x99a30970 }, /* int-mic */
6810 { 0x15, 0x01214020 }, /* HP */
6811 { 0x17, 0x99130111 }, /* speaker */
6812 { 0x18, 0x01a19840 }, /* mic */
6813 { 0x21, 0x0121401f }, /* HP */
6814 { }
6815 },
6816 .chained = true,
6817 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006818 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006819 [ALC662_FIXUP_NO_JACK_DETECT] = {
6820 .type = ALC_FIXUP_FUNC,
6821 .v.func = alc_fixup_no_jack_detect,
6822 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006823 [ALC662_FIXUP_ZOTAC_Z68] = {
6824 .type = ALC_FIXUP_PINS,
6825 .v.pins = (const struct alc_pincfg[]) {
6826 { 0x1b, 0x02214020 }, /* Front HP */
6827 { }
6828 }
6829 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006830 [ALC662_FIXUP_INV_DMIC] = {
6831 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006832 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006833 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006834};
6835
Takashi Iwaia9111322011-05-02 11:30:18 +02006836static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006837 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006838 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006839 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006840 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006841 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006842 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006843 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006844 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006845 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006846 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006847 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006848 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006849 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006850
6851#if 0
6852 /* Below is a quirk table taken from the old code.
6853 * Basically the device should work as is without the fixup table.
6854 * If BIOS doesn't give a proper info, enable the corresponding
6855 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006856 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006857 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6858 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6859 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6860 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6861 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6862 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6863 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6864 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6865 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6866 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6867 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6868 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6869 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6870 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6871 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6872 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6873 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6874 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6875 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6876 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6877 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6878 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6879 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6880 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6881 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6882 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6883 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6884 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6885 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6886 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6887 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6888 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6889 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6890 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6891 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6892 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6893 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6894 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6895 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6896 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6897 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6898 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6899 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6900 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6901 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6902 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6903 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6904 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6905 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6906 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6907#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006908 {}
6909};
6910
Todd Broch6be79482010-12-07 16:51:05 -08006911static const struct alc_model_fixup alc662_fixup_models[] = {
6912 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006913 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6914 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6915 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6916 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6917 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6918 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6919 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6920 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006921 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08006922 {}
6923};
David Henningsson6cb3b702010-09-09 08:51:44 +02006924
Kailang Yang8663ff72012-06-29 09:35:52 +02006925static void alc662_fill_coef(struct hda_codec *codec)
6926{
6927 int val, coef;
6928
6929 coef = alc_get_coef0(codec);
6930
6931 switch (codec->vendor_id) {
6932 case 0x10ec0662:
6933 if ((coef & 0x00f0) == 0x0030) {
6934 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
6935 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
6936 }
6937 break;
6938 case 0x10ec0272:
6939 case 0x10ec0273:
6940 case 0x10ec0663:
6941 case 0x10ec0665:
6942 case 0x10ec0670:
6943 case 0x10ec0671:
6944 case 0x10ec0672:
6945 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
6946 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6947 break;
6948 }
6949}
David Henningsson6cb3b702010-09-09 08:51:44 +02006950
Takashi Iwai1d045db2011-07-07 18:23:21 +02006951/*
6952 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006953static int patch_alc662(struct hda_codec *codec)
6954{
6955 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006956 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006957
Takashi Iwai3de95172012-05-07 18:03:15 +02006958 err = alc_alloc_spec(codec, 0x0b);
6959 if (err < 0)
6960 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006961
Takashi Iwai3de95172012-05-07 18:03:15 +02006962 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006963
Takashi Iwai53c334a2011-08-23 18:27:14 +02006964 /* handle multiple HPs as is */
6965 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6966
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006967 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6968
Kailang Yang8663ff72012-06-29 09:35:52 +02006969 spec->init_hook = alc662_fill_coef;
6970 alc662_fill_coef(codec);
6971
Takashi Iwai8e5a0502012-06-21 15:49:33 +02006972 alc_pick_fixup(codec, alc662_fixup_models,
6973 alc662_fixup_tbl, alc662_fixups);
6974 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6975
6976 alc_auto_parse_customize_define(codec);
6977
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006978 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006979 codec->bus->pci->subsystem_vendor == 0x1025 &&
6980 spec->cdefine.platform_type == 1) {
6981 if (alc_codec_rename(codec, "ALC272X") < 0)
6982 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006983 }
Kailang Yang274693f2009-12-03 10:07:50 +01006984
Takashi Iwaib9c51062011-08-24 18:08:07 +02006985 /* automatic parse from the BIOS config */
6986 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006987 if (err < 0)
6988 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006989
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006990 if (!spec->no_analog && has_cdefine_beep(codec)) {
6991 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006992 if (err < 0)
6993 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006994 switch (codec->vendor_id) {
6995 case 0x10ec0662:
6996 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6997 break;
6998 case 0x10ec0272:
6999 case 0x10ec0663:
7000 case 0x10ec0665:
7001 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7002 break;
7003 case 0x10ec0273:
7004 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7005 break;
7006 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007007 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007008
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007009 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02007010 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007011
Takashi Iwai589876e2012-02-20 15:47:55 +01007012 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7013
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007014 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007015
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007016 error:
7017 alc_free(codec);
7018 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007019}
7020
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007021/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007022 * ALC680 support
7023 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007024
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007025static int alc680_parse_auto_config(struct hda_codec *codec)
7026{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007027 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007028}
7029
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007030/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007031 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007032static int patch_alc680(struct hda_codec *codec)
7033{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007034 int err;
7035
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007036 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007037 err = alc_alloc_spec(codec, 0);
7038 if (err < 0)
7039 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007040
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007041 /* automatic parse from the BIOS config */
7042 err = alc680_parse_auto_config(codec);
7043 if (err < 0) {
7044 alc_free(codec);
7045 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007046 }
7047
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007048 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007049
7050 return 0;
7051}
7052
7053/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007054 * patch entries
7055 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007056static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007057 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007058 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007059 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007060 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007061 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007062 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007063 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007064 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007065 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007066 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007067 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007068 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007069 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007070 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007071 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7072 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7073 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007074 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007075 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007076 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7077 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007078 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7079 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007080 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007081 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007082 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007083 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007084 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007085 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007086 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007087 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007088 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007089 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007090 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007091 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007092 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007093 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007094 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007095 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007096 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007097 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007098 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007099 {} /* terminator */
7100};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007101
7102MODULE_ALIAS("snd-hda-codec-id:10ec*");
7103
7104MODULE_LICENSE("GPL");
7105MODULE_DESCRIPTION("Realtek HD-audio codec");
7106
7107static struct hda_codec_preset_list realtek_list = {
7108 .preset = snd_hda_preset_realtek,
7109 .owner = THIS_MODULE,
7110};
7111
7112static int __init patch_realtek_init(void)
7113{
7114 return snd_hda_add_codec_preset(&realtek_list);
7115}
7116
7117static void __exit patch_realtek_exit(void)
7118{
7119 snd_hda_delete_codec_preset(&realtek_list);
7120}
7121
7122module_init(patch_realtek_init)
7123module_exit(patch_realtek_exit)