blob: f893fb1b23d4efc7418ec70ade01c70121bd745e [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
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100102#define MAX_NID_PATH_DEPTH 5
103
104/* output-path: DAC -> ... -> pin
105 * idx[] contains the source index number of the next widget;
106 * e.g. idx[0] is the index of the DAC selected by path[1] widget
107 * multi[] indicates whether it's a selector widget with multi-connectors
108 * (i.e. the connection selection is mandatory)
109 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
110 */
111struct nid_path {
112 int depth;
113 hda_nid_t path[MAX_NID_PATH_DEPTH];
114 unsigned char idx[MAX_NID_PATH_DEPTH];
115 unsigned char multi[MAX_NID_PATH_DEPTH];
116 unsigned int ctls[2]; /* 0 = volume, 1 = mute */
117};
118
Takashi Iwaiba8111272012-12-06 18:06:23 +0100119enum { NID_PATH_VOL_CTL = 0, NID_PATH_MUTE_CTL = 1 };
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200122 struct hda_gen_spec gen;
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200125 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +0200127 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100128 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200130 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200131 const struct hda_pcm_stream *stream_analog_playback;
132 const struct hda_pcm_stream *stream_analog_capture;
133 const struct hda_pcm_stream *stream_analog_alt_playback;
134 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200136 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200137 const struct hda_pcm_stream *stream_digital_playback;
138 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200141 struct hda_multi_out multiout; /* playback set-up
142 * max_channels, dacs must be set
143 * dig_out_nid and hp_nid are optional
144 */
Takashi Iwai63300792008-01-24 15:31:36 +0100145 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100146 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100147 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 /* capture */
150 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200151 const hda_nid_t *adc_nids;
152 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200153 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200154 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Takashi Iwai840b64c2010-07-13 22:49:01 +0200156 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200157 hda_nid_t cur_adc;
158 unsigned int cur_adc_stream_tag;
159 unsigned int cur_adc_format;
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200162 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 const struct hda_input_mux *input_mux;
164 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200165 hda_nid_t ext_mic_pin;
166 hda_nid_t dock_mic_pin;
167 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100170 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200172 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100173 int const_channel_count; /* min. channel count (for speakers) */
174 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100177 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200178
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200179 /* dynamic controls, init_verbs and input_mux */
180 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100181 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200182 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200183 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200184 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200185 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
186 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200187 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
188 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
189 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200190 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100191
Takashi Iwai463419d2012-12-05 14:17:37 +0100192 /* DAC list */
193 int num_all_dacs;
194 hda_nid_t all_dacs[16];
195
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100196 /* output paths */
197 struct snd_array out_path;
198
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100199 /* hooks */
200 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200201#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500202 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100203#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200204 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200205 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100206
Takashi Iwai834be882006-03-01 14:16:17 +0100207 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200208 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200209 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200210 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200211 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200212 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200213 unsigned int automute_speaker:1; /* automute speaker outputs */
214 unsigned int automute_lo:1; /* automute LO outputs */
215 unsigned int detect_hp:1; /* Headphone detection enabled */
216 unsigned int detect_lo:1; /* Line-out detection enabled */
217 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
218 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100219 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200220
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100221 /* other flags */
222 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200223 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100224 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200225 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200226 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100227 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200228 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
229 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200230 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200231
232 /* auto-mute control */
233 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200234 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200235
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200236 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200237 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100238
Takashi Iwai2134ea42008-01-10 16:53:55 +0100239 /* for virtual master */
240 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100241 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200242#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200243 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100244 int num_loopbacks;
245 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200246#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200247
248 /* for PLL fix */
249 hda_nid_t pll_nid;
250 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200251 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100252
Takashi Iwaice764ab2011-04-27 16:35:23 +0200253 /* multi-io */
254 int multi_ios;
255 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200256
257 /* bind volumes */
258 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100259};
260
Takashi Iwai44c02402011-07-08 15:14:19 +0200261static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
262 int dir, unsigned int bits)
263{
264 if (!nid)
265 return false;
266 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
267 if (query_amp_caps(codec, nid, dir) & bits)
268 return true;
269 return false;
270}
271
272#define nid_has_mute(codec, nid, dir) \
273 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
274#define nid_has_volume(codec, nid, dir) \
275 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277/*
278 * input MUX handling
279 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200280static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
281 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
283 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
284 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200285 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
286 if (mux_idx >= spec->num_mux_defs)
287 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100288 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
289 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200290 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200293static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
294 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
297 struct alc_spec *spec = codec->spec;
298 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
299
300 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
301 return 0;
302}
303
Takashi Iwai21268962011-07-07 15:01:13 +0200304static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Takashi Iwai21268962011-07-07 15:01:13 +0200306 struct alc_spec *spec = codec->spec;
307 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
308
309 if (spec->cur_adc && spec->cur_adc != new_adc) {
310 /* stream is running, let's swap the current ADC */
311 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
312 spec->cur_adc = new_adc;
313 snd_hda_codec_setup_stream(codec, new_adc,
314 spec->cur_adc_stream_tag, 0,
315 spec->cur_adc_format);
316 return true;
317 }
318 return false;
319}
320
Takashi Iwai61071592011-11-23 07:52:15 +0100321static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
322{
323 return spec->capsrc_nids ?
324 spec->capsrc_nids[idx] : spec->adc_nids[idx];
325}
326
Takashi Iwai24de1832011-11-07 17:13:39 +0100327static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200328static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100329
David Henningsson00227f12012-06-27 18:45:44 +0200330/* for shared I/O, change the pin-control accordingly */
331static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
332{
333 struct alc_spec *spec = codec->spec;
334 unsigned int val;
335 hda_nid_t pin = spec->autocfg.inputs[1].pin;
336 /* NOTE: this assumes that there are only two inputs, the
337 * first is the real internal mic and the second is HP/mic jack.
338 */
339
340 val = snd_hda_get_default_vref(codec, pin);
341
342 /* This pin does not have vref caps - let's enable vref on pin 0x18
343 instead, as suggested by Realtek */
344 if (val == AC_PINCTL_VREF_HIZ) {
345 const hda_nid_t vref_pin = 0x18;
346 /* Sanity check pin 0x18 */
347 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
348 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
349 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
350 if (vref_val != AC_PINCTL_VREF_HIZ)
351 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
352 }
353 }
354
355 val = set_as_mic ? val | PIN_IN : PIN_HP;
356 snd_hda_set_pin_ctl(codec, pin, val);
357
358 spec->automute_speaker = !set_as_mic;
359 call_update_outputs(codec);
360}
Takashi Iwai21268962011-07-07 15:01:13 +0200361
362/* select the given imux item; either unmute exclusively or select the route */
363static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
364 unsigned int idx, bool force)
365{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100367 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100368 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100369 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200370 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Takashi Iwai5803a322012-02-21 11:59:45 +0100372 if (!spec->input_mux)
373 return 0;
374
Takashi Iwaicd896c32008-11-18 12:36:33 +0100375 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
376 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100377 if (!imux->num_items && mux_idx > 0)
378 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100379 if (!imux->num_items)
380 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100381
Takashi Iwai21268962011-07-07 15:01:13 +0200382 if (idx >= imux->num_items)
383 idx = imux->num_items - 1;
384 if (spec->cur_mux[adc_idx] == idx && !force)
385 return 0;
386 spec->cur_mux[adc_idx] = idx;
387
David Henningsson00227f12012-06-27 18:45:44 +0200388 if (spec->shared_mic_hp)
389 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100390
Takashi Iwai21268962011-07-07 15:01:13 +0200391 if (spec->dyn_adc_switch) {
392 alc_dyn_adc_pcm_resetup(codec, idx);
393 adc_idx = spec->dyn_adc_idx[idx];
394 }
395
Takashi Iwai61071592011-11-23 07:52:15 +0100396 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200397
398 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200399 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100400 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200401 return 1;
402
Takashi Iwaia22d5432009-07-27 12:54:26 +0200403 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200404 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100405 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100406 int active = imux->items[idx].index;
407 for (i = 0; i < num_conns; i++) {
408 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
409 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100410 HDA_AMP_MUTE, v);
411 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100412 } else {
413 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200414 snd_hda_codec_write_cache(codec, nid, 0,
415 AC_VERB_SET_CONNECT_SEL,
416 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100417 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200418 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200419 return 1;
420}
421
422static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
423 struct snd_ctl_elem_value *ucontrol)
424{
425 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
426 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
427 return alc_mux_select(codec, adc_idx,
428 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100429}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100432 * set up the input pin config (depending on the given auto-pin type)
433 */
434static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
435 int auto_pin_type)
436{
437 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200438 if (auto_pin_type == AUTO_PIN_MIC)
439 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200440 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100441}
442
443/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200444 * Append the given mixer and verb elements for the later use
445 * The mixer array is referred in build_controls(), and init_verbs are
446 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100447 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200448static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100449{
450 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
451 return;
452 spec->mixers[spec->num_mixers++] = mix;
453}
454
Takashi Iwaid88897e2008-10-31 15:01:37 +0100455/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200456 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100457 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200458/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200459static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200460 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
461 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
462 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
463 { }
464};
465
Takashi Iwaia9111322011-05-02 11:30:18 +0200466static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200467 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
468 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
469 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
470 { }
471};
472
Takashi Iwaia9111322011-05-02 11:30:18 +0200473static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200474 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
475 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
476 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
477 { }
478};
479
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200480/*
481 * Fix hardware PLL issue
482 * On some codecs, the analog PLL gating control must be off while
483 * the default value is 1.
484 */
485static void alc_fix_pll(struct hda_codec *codec)
486{
487 struct alc_spec *spec = codec->spec;
488 unsigned int val;
489
490 if (!spec->pll_nid)
491 return;
492 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
493 spec->pll_coef_idx);
494 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
495 AC_VERB_GET_PROC_COEF, 0);
496 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
497 spec->pll_coef_idx);
498 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
499 val & ~(1 << spec->pll_coef_bit));
500}
501
502static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
503 unsigned int coef_idx, unsigned int coef_bit)
504{
505 struct alc_spec *spec = codec->spec;
506 spec->pll_nid = nid;
507 spec->pll_coef_idx = coef_idx;
508 spec->pll_coef_bit = coef_bit;
509 alc_fix_pll(codec);
510}
511
Takashi Iwai1d045db2011-07-07 18:23:21 +0200512/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200513 * Jack detections for HP auto-mute and mic-switch
514 */
515
516/* check each pin in the given array; returns true if any of them is plugged */
517static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200518{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200519 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200520
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200521 for (i = 0; i < num_pins; i++) {
522 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200523 if (!nid)
524 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200525 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200526 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200527 return present;
528}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200529
Takashi Iwai1d045db2011-07-07 18:23:21 +0200530/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200531static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200532 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200533{
534 struct alc_spec *spec = codec->spec;
535 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200536 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537 int i;
538
539 for (i = 0; i < num_pins; i++) {
540 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100541 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200542 if (!nid)
543 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200544 switch (spec->automute_mode) {
545 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100546 /* don't reset VREF value in case it's controlling
547 * the amp (see alc861_fixup_asus_amp_vref_0f())
548 */
549 if (spec->keep_vref_in_automute) {
550 val = snd_hda_codec_read(codec, nid, 0,
551 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
552 val &= ~PIN_HP;
553 } else
554 val = 0;
555 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200556 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200557 break;
558 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200559 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200560 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200561 break;
562 case ALC_AUTOMUTE_MIXER:
563 nid = spec->automute_mixer_nid[i];
564 if (!nid)
565 break;
566 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200567 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200568 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200569 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200570 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200571 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200572 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200573}
574
David Henningsson42cf0d02011-09-20 12:04:56 +0200575/* Toggle outputs muting */
576static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577{
578 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200579 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200580
Takashi Iwaic0a20262011-06-10 15:28:15 +0200581 /* Control HP pins/amps depending on master_mute state;
582 * in general, HP pins/amps control should be enabled in all cases,
583 * but currently set only for master_mute, just to be safe
584 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100585 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
586 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200587 spec->autocfg.hp_pins, spec->master_mute, true);
588
David Henningsson42cf0d02011-09-20 12:04:56 +0200589 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200590 on = 0;
591 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200593 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200594 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200595 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200596
597 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200598 /* if LO is a copy of either HP or Speaker, don't need to handle it */
599 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
600 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200601 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200602 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200603 on = 0;
604 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200605 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200606 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200608 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200609}
610
David Henningsson42cf0d02011-09-20 12:04:56 +0200611static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200612{
613 struct alc_spec *spec = codec->spec;
614 if (spec->automute_hook)
615 spec->automute_hook(codec);
616 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200617 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200618}
619
Takashi Iwai1d045db2011-07-07 18:23:21 +0200620/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200621static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200622{
623 struct alc_spec *spec = codec->spec;
624
David Henningsson42cf0d02011-09-20 12:04:56 +0200625 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200626 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
627 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200628 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200629 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200630 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200631}
632
Takashi Iwai1d045db2011-07-07 18:23:21 +0200633/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200634static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200635{
636 struct alc_spec *spec = codec->spec;
637
David Henningssonf7f4b2322012-10-10 16:32:09 +0200638 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
639 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200640 /* check LO jack only when it's different from HP */
641 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
642 return;
643
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200644 spec->line_jack_present =
645 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
646 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200647 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200648 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200649 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200650}
651
Takashi Iwai8d087c72011-06-28 12:45:47 +0200652#define get_connection_index(codec, mux, nid) \
653 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200654
Takashi Iwai1d045db2011-07-07 18:23:21 +0200655/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200656static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200657{
658 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200659 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200660
Takashi Iwai21268962011-07-07 15:01:13 +0200661 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200662 return;
663 if (snd_BUG_ON(!spec->adc_nids))
664 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200665 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200666 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200667
Takashi Iwai21268962011-07-07 15:01:13 +0200668 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
669 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
670 else if (spec->dock_mic_idx >= 0 &&
671 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
672 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
673 else
674 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200675}
676
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100677/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200678static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100679{
680 unsigned int val;
681 struct snd_kcontrol *kctl;
682 struct snd_ctl_elem_value *uctl;
683
684 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
685 if (!kctl)
686 return;
687 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
688 if (!uctl)
689 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200690 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100691 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
692 val &= HDA_AMP_VOLMASK;
693 uctl->value.integer.value[0] = val;
694 uctl->value.integer.value[1] = val;
695 kctl->put(kctl, uctl);
696 kfree(uctl);
697}
698
David Henningsson29adc4b2012-09-25 11:31:00 +0200699static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100700{
David Henningsson29adc4b2012-09-25 11:31:00 +0200701 /* For some reason, the res given from ALC880 is broken.
702 Here we adjust it properly. */
703 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100704}
705
Takashi Iwai1d045db2011-07-07 18:23:21 +0200706/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200707static void alc_inithook(struct hda_codec *codec)
708{
David Henningsson29adc4b2012-09-25 11:31:00 +0200709 alc_hp_automute(codec, NULL);
710 alc_line_automute(codec, NULL);
711 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200712}
713
Kailang Yangf9423e72008-05-27 12:32:25 +0200714/* additional initialization for ALC888 variants */
715static void alc888_coef_init(struct hda_codec *codec)
716{
717 unsigned int tmp;
718
719 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
720 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100722 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200723 /* alc888S-VC */
724 snd_hda_codec_read(codec, 0x20, 0,
725 AC_VERB_SET_PROC_COEF, 0x830);
726 else
727 /* alc888-VB */
728 snd_hda_codec_read(codec, 0x20, 0,
729 AC_VERB_SET_PROC_COEF, 0x3030);
730}
731
Takashi Iwai1d045db2011-07-07 18:23:21 +0200732/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200733static void alc889_coef_init(struct hda_codec *codec)
734{
735 unsigned int tmp;
736
737 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
738 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
739 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
740 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
741}
742
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100743/* turn on/off EAPD control (only if available) */
744static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
745{
746 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
747 return;
748 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
749 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
750 on ? 2 : 0);
751}
752
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200753/* turn on/off EAPD controls of the codec */
754static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
755{
756 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200757 static hda_nid_t pins[] = {
758 0x0f, 0x10, 0x14, 0x15, 0
759 };
760 hda_nid_t *p;
761 for (p = pins; *p; p++)
762 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200763}
764
Takashi Iwai1c716152011-04-07 10:37:16 +0200765/* generic shutup callback;
766 * just turning off EPAD and a little pause for avoiding pop-noise
767 */
768static void alc_eapd_shutup(struct hda_codec *codec)
769{
770 alc_auto_setup_eapd(codec, false);
771 msleep(200);
772}
773
Takashi Iwai1d045db2011-07-07 18:23:21 +0200774/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200775static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200776{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200778
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200779 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200780 switch (type) {
781 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200782 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
783 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200784 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200785 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
786 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200787 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200788 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
789 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200790 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200791 switch (codec->vendor_id) {
792 case 0x10ec0260:
793 snd_hda_codec_write(codec, 0x1a, 0,
794 AC_VERB_SET_COEF_INDEX, 7);
795 tmp = snd_hda_codec_read(codec, 0x1a, 0,
796 AC_VERB_GET_PROC_COEF, 0);
797 snd_hda_codec_write(codec, 0x1a, 0,
798 AC_VERB_SET_COEF_INDEX, 7);
799 snd_hda_codec_write(codec, 0x1a, 0,
800 AC_VERB_SET_PROC_COEF,
801 tmp | 0x2010);
802 break;
803 case 0x10ec0262:
804 case 0x10ec0880:
805 case 0x10ec0882:
806 case 0x10ec0883:
807 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100808 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100809 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200810 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200811 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200812 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200813 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200814 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100815#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200816 case 0x10ec0267:
817 case 0x10ec0268:
818 snd_hda_codec_write(codec, 0x20, 0,
819 AC_VERB_SET_COEF_INDEX, 7);
820 tmp = snd_hda_codec_read(codec, 0x20, 0,
821 AC_VERB_GET_PROC_COEF, 0);
822 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200823 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200824 snd_hda_codec_write(codec, 0x20, 0,
825 AC_VERB_SET_PROC_COEF,
826 tmp | 0x3000);
827 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100828#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200829 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200830 break;
831 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200832}
Kailang Yangea1fb292008-08-26 12:58:38 +0200833
Takashi Iwai1d045db2011-07-07 18:23:21 +0200834/*
835 * Auto-Mute mode mixer enum support
836 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200837static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
838 struct snd_ctl_elem_info *uinfo)
839{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200840 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
841 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200842 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100843 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200844 };
845
Takashi Iwaidda415d2012-11-30 18:34:38 +0100846 if (spec->automute_speaker_possible && spec->automute_lo_possible)
847 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
848 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200849}
850
851static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
852 struct snd_ctl_elem_value *ucontrol)
853{
854 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
855 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200856 unsigned int val = 0;
857 if (spec->automute_speaker)
858 val++;
859 if (spec->automute_lo)
860 val++;
861
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200862 ucontrol->value.enumerated.item[0] = val;
863 return 0;
864}
865
866static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
867 struct snd_ctl_elem_value *ucontrol)
868{
869 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
870 struct alc_spec *spec = codec->spec;
871
872 switch (ucontrol->value.enumerated.item[0]) {
873 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200874 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200875 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200876 spec->automute_speaker = 0;
877 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200878 break;
879 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200880 if (spec->automute_speaker_possible) {
881 if (!spec->automute_lo && spec->automute_speaker)
882 return 0;
883 spec->automute_speaker = 1;
884 spec->automute_lo = 0;
885 } else if (spec->automute_lo_possible) {
886 if (spec->automute_lo)
887 return 0;
888 spec->automute_lo = 1;
889 } else
890 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200891 break;
892 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200893 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200894 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200895 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200896 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200897 spec->automute_speaker = 1;
898 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899 break;
900 default:
901 return -EINVAL;
902 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200903 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200904 return 1;
905}
906
Takashi Iwaia9111322011-05-02 11:30:18 +0200907static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200908 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
909 .name = "Auto-Mute Mode",
910 .info = alc_automute_mode_info,
911 .get = alc_automute_mode_get,
912 .put = alc_automute_mode_put,
913};
914
Takashi Iwai668d1e92012-11-29 14:10:17 +0100915static struct snd_kcontrol_new *
916alc_kcontrol_new(struct alc_spec *spec, const char *name,
917 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200918{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100919 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
920 if (!knew)
921 return NULL;
922 *knew = *temp;
923 knew->name = kstrdup(name, GFP_KERNEL);
924 if (!knew->name)
925 return NULL;
926 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200927}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200928
929static int alc_add_automute_mode_enum(struct hda_codec *codec)
930{
931 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200932
Takashi Iwai668d1e92012-11-29 14:10:17 +0100933 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200934 return -ENOMEM;
935 return 0;
936}
937
Takashi Iwai1d045db2011-07-07 18:23:21 +0200938/*
939 * Check the availability of HP/line-out auto-mute;
940 * Set up appropriately if really supported
941 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100942static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200943{
944 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200945 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200946 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100947 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200948
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200949 if (cfg->hp_pins[0])
950 present++;
951 if (cfg->line_out_pins[0])
952 present++;
953 if (cfg->speaker_pins[0])
954 present++;
955 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100956 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200957
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200958 if (!cfg->speaker_pins[0] &&
959 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200960 memcpy(cfg->speaker_pins, cfg->line_out_pins,
961 sizeof(cfg->speaker_pins));
962 cfg->speaker_outs = cfg->line_outs;
963 }
964
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200965 if (!cfg->hp_pins[0] &&
966 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200967 memcpy(cfg->hp_pins, cfg->line_out_pins,
968 sizeof(cfg->hp_pins));
969 cfg->hp_outs = cfg->line_outs;
970 }
971
David Henningsson42cf0d02011-09-20 12:04:56 +0200972 spec->automute_mode = ALC_AUTOMUTE_PIN;
973
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200974 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200975 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200976 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200977 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200978 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200979 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200980 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
981 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200982 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200983 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200984
David Henningsson42cf0d02011-09-20 12:04:56 +0200985 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
986 if (cfg->speaker_outs)
987 for (i = 0; i < cfg->line_outs; i++) {
988 hda_nid_t nid = cfg->line_out_pins[i];
989 if (!is_jack_detectable(codec, nid))
990 continue;
991 snd_printdd("realtek: Enable Line-Out "
992 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200993 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
994 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200995 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200996 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200997 spec->automute_lo_possible = spec->detect_hp;
998 }
999
1000 spec->automute_speaker_possible = cfg->speaker_outs &&
1001 (spec->detect_hp || spec->detect_lo);
1002
1003 spec->automute_lo = spec->automute_lo_possible;
1004 spec->automute_speaker = spec->automute_speaker_possible;
1005
Takashi Iwai475c3d22012-11-30 08:31:30 +01001006 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001007 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001008 err = alc_add_automute_mode_enum(codec);
1009 if (err < 0)
1010 return err;
1011 }
1012 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001013}
1014
Takashi Iwai1d045db2011-07-07 18:23:21 +02001015/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001016static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1017{
1018 int i;
1019 for (i = 0; i < nums; i++)
1020 if (list[i] == nid)
1021 return i;
1022 return -1;
1023}
1024
Takashi Iwai1d045db2011-07-07 18:23:21 +02001025/* check whether dynamic ADC-switching is available */
1026static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1027{
1028 struct alc_spec *spec = codec->spec;
1029 struct hda_input_mux *imux = &spec->private_imux[0];
1030 int i, n, idx;
1031 hda_nid_t cap, pin;
1032
1033 if (imux != spec->input_mux) /* no dynamic imux? */
1034 return false;
1035
1036 for (n = 0; n < spec->num_adc_nids; n++) {
1037 cap = spec->private_capsrc_nids[n];
1038 for (i = 0; i < imux->num_items; i++) {
1039 pin = spec->imux_pins[i];
1040 if (!pin)
1041 return false;
1042 if (get_connection_index(codec, cap, pin) < 0)
1043 break;
1044 }
1045 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001046 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001047 }
1048
1049 for (i = 0; i < imux->num_items; i++) {
1050 pin = spec->imux_pins[i];
1051 for (n = 0; n < spec->num_adc_nids; n++) {
1052 cap = spec->private_capsrc_nids[n];
1053 idx = get_connection_index(codec, cap, pin);
1054 if (idx >= 0) {
1055 imux->items[i].index = idx;
1056 spec->dyn_adc_idx[i] = n;
1057 break;
1058 }
1059 }
1060 }
1061
1062 snd_printdd("realtek: enabling ADC switching\n");
1063 spec->dyn_adc_switch = 1;
1064 return true;
1065}
Takashi Iwai21268962011-07-07 15:01:13 +02001066
Takashi Iwai21268962011-07-07 15:01:13 +02001067/* check whether all auto-mic pins are valid; setup indices if OK */
1068static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1069{
1070 struct alc_spec *spec = codec->spec;
1071 const struct hda_input_mux *imux;
1072
1073 if (!spec->auto_mic)
1074 return false;
1075 if (spec->auto_mic_valid_imux)
1076 return true; /* already checked */
1077
1078 /* fill up imux indices */
1079 if (!alc_check_dyn_adc_switch(codec)) {
1080 spec->auto_mic = 0;
1081 return false;
1082 }
1083
1084 imux = spec->input_mux;
1085 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1086 spec->imux_pins, imux->num_items);
1087 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1088 spec->imux_pins, imux->num_items);
1089 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1090 spec->imux_pins, imux->num_items);
1091 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1092 spec->auto_mic = 0;
1093 return false; /* no corresponding imux */
1094 }
1095
David Henningsson29adc4b2012-09-25 11:31:00 +02001096 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1097 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001098 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001099 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1100 ALC_MIC_EVENT,
1101 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001102
1103 spec->auto_mic_valid_imux = 1;
1104 spec->auto_mic = 1;
1105 return true;
1106}
1107
Takashi Iwai1d045db2011-07-07 18:23:21 +02001108/*
1109 * Check the availability of auto-mic switch;
1110 * Set up if really supported
1111 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001112static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001113{
1114 struct alc_spec *spec = codec->spec;
1115 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001116 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001117 int i;
1118
Takashi Iwai24de1832011-11-07 17:13:39 +01001119 if (spec->shared_mic_hp)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001120 return 0; /* no auto-mic for the shared I/O */
Takashi Iwai24de1832011-11-07 17:13:39 +01001121
Takashi Iwai21268962011-07-07 15:01:13 +02001122 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1123
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001124 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001125 for (i = 0; i < cfg->num_inputs; i++) {
1126 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001127 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001128 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001129 switch (snd_hda_get_input_pin_attr(defcfg)) {
1130 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001131 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001132 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001133 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001134 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001135 fixed = nid;
1136 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001137 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001138 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001139 case INPUT_PIN_ATTR_DOCK:
1140 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001141 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001142 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001143 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001144 dock = nid;
1145 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001146 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001147 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001148 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001149 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001150 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001151 ext = nid;
1152 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001153 }
1154 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001155 if (!ext && dock) {
1156 ext = dock;
1157 dock = 0;
1158 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001159 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001160 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001161 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001162 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001163 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001164 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001165
1166 /* check imux indices */
1167 spec->ext_mic_pin = ext;
1168 spec->int_mic_pin = fixed;
1169 spec->dock_mic_pin = dock;
1170
1171 spec->auto_mic = 1;
1172 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001173 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001174
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001175 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1176 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001177
1178 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001179}
1180
Takashi Iwai1d045db2011-07-07 18:23:21 +02001181/* check the availabilities of auto-mute and auto-mic switches */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001182static int alc_auto_check_switches(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02001183{
Takashi Iwai475c3d22012-11-30 08:31:30 +01001184 int err;
1185
1186 err = alc_init_automute(codec);
1187 if (err < 0)
1188 return err;
1189 err = alc_init_auto_mic(codec);
1190 if (err < 0)
1191 return err;
1192 return 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02001193}
1194
1195/*
1196 * Realtek SSID verification
1197 */
1198
David Henningsson90622912010-10-14 14:50:18 +02001199/* Could be any non-zero and even value. When used as fixup, tells
1200 * the driver to ignore any present sku defines.
1201 */
1202#define ALC_FIXUP_SKU_IGNORE (2)
1203
Takashi Iwai23d30f22012-05-07 17:17:32 +02001204static void alc_fixup_sku_ignore(struct hda_codec *codec,
1205 const struct hda_fixup *fix, int action)
1206{
1207 struct alc_spec *spec = codec->spec;
1208 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1209 spec->cdefine.fixup = 1;
1210 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1211 }
1212}
1213
Kailang Yangda00c242010-03-19 11:23:45 +01001214static int alc_auto_parse_customize_define(struct hda_codec *codec)
1215{
1216 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001217 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001218 struct alc_spec *spec = codec->spec;
1219
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001220 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1221
David Henningsson90622912010-10-14 14:50:18 +02001222 if (spec->cdefine.fixup) {
1223 ass = spec->cdefine.sku_cfg;
1224 if (ass == ALC_FIXUP_SKU_IGNORE)
1225 return -1;
1226 goto do_sku;
1227 }
1228
Kailang Yangda00c242010-03-19 11:23:45 +01001229 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001230 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001231 goto do_sku;
1232
1233 nid = 0x1d;
1234 if (codec->vendor_id == 0x10ec0260)
1235 nid = 0x17;
1236 ass = snd_hda_codec_get_pincfg(codec, nid);
1237
1238 if (!(ass & 1)) {
1239 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1240 codec->chip_name, ass);
1241 return -1;
1242 }
1243
1244 /* check sum */
1245 tmp = 0;
1246 for (i = 1; i < 16; i++) {
1247 if ((ass >> i) & 1)
1248 tmp++;
1249 }
1250 if (((ass >> 16) & 0xf) != tmp)
1251 return -1;
1252
1253 spec->cdefine.port_connectivity = ass >> 30;
1254 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1255 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1256 spec->cdefine.customization = ass >> 8;
1257do_sku:
1258 spec->cdefine.sku_cfg = ass;
1259 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1260 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1261 spec->cdefine.swap = (ass & 0x2) >> 1;
1262 spec->cdefine.override = ass & 0x1;
1263
1264 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1265 nid, spec->cdefine.sku_cfg);
1266 snd_printd("SKU: port_connectivity=0x%x\n",
1267 spec->cdefine.port_connectivity);
1268 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1269 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1270 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1271 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1272 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1273 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1274 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1275
1276 return 0;
1277}
1278
Takashi Iwai1d045db2011-07-07 18:23:21 +02001279/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001280static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1281{
Takashi Iwai21268962011-07-07 15:01:13 +02001282 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001283}
1284
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001285/* check subsystem ID and set up device-specific initialization;
1286 * return 1 if initialized, 0 if invalid SSID
1287 */
1288/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1289 * 31 ~ 16 : Manufacture ID
1290 * 15 ~ 8 : SKU ID
1291 * 7 ~ 0 : Assembly ID
1292 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1293 */
1294static int alc_subsystem_id(struct hda_codec *codec,
1295 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001296 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001297{
1298 unsigned int ass, tmp, i;
1299 unsigned nid;
1300 struct alc_spec *spec = codec->spec;
1301
David Henningsson90622912010-10-14 14:50:18 +02001302 if (spec->cdefine.fixup) {
1303 ass = spec->cdefine.sku_cfg;
1304 if (ass == ALC_FIXUP_SKU_IGNORE)
1305 return 0;
1306 goto do_sku;
1307 }
1308
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001309 ass = codec->subsystem_id & 0xffff;
1310 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1311 goto do_sku;
1312
1313 /* invalid SSID, check the special NID pin defcfg instead */
1314 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001315 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001316 * 29~21 : reserve
1317 * 20 : PCBEEP input
1318 * 19~16 : Check sum (15:1)
1319 * 15~1 : Custom
1320 * 0 : override
1321 */
1322 nid = 0x1d;
1323 if (codec->vendor_id == 0x10ec0260)
1324 nid = 0x17;
1325 ass = snd_hda_codec_get_pincfg(codec, nid);
1326 snd_printd("realtek: No valid SSID, "
1327 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001328 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001329 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001330 return 0;
1331 if ((ass >> 30) != 1) /* no physical connection */
1332 return 0;
1333
1334 /* check sum */
1335 tmp = 0;
1336 for (i = 1; i < 16; i++) {
1337 if ((ass >> i) & 1)
1338 tmp++;
1339 }
1340 if (((ass >> 16) & 0xf) != tmp)
1341 return 0;
1342do_sku:
1343 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1344 ass & 0xffff, codec->vendor_id);
1345 /*
1346 * 0 : override
1347 * 1 : Swap Jack
1348 * 2 : 0 --> Desktop, 1 --> Laptop
1349 * 3~5 : External Amplifier control
1350 * 7~6 : Reserved
1351 */
1352 tmp = (ass & 0x38) >> 3; /* external Amp control */
1353 switch (tmp) {
1354 case 1:
1355 spec->init_amp = ALC_INIT_GPIO1;
1356 break;
1357 case 3:
1358 spec->init_amp = ALC_INIT_GPIO2;
1359 break;
1360 case 7:
1361 spec->init_amp = ALC_INIT_GPIO3;
1362 break;
1363 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001364 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001365 spec->init_amp = ALC_INIT_DEFAULT;
1366 break;
1367 }
1368
1369 /* is laptop or Desktop and enable the function "Mute internal speaker
1370 * when the external headphone out jack is plugged"
1371 */
1372 if (!(ass & 0x8000))
1373 return 1;
1374 /*
1375 * 10~8 : Jack location
1376 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1377 * 14~13: Resvered
1378 * 15 : 1 --> enable the function "Mute internal speaker
1379 * when the external headphone out jack is plugged"
1380 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001381 if (!spec->autocfg.hp_pins[0] &&
1382 !(spec->autocfg.line_out_pins[0] &&
1383 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001384 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001385 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1386 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001387 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001388 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001389 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001390 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001391 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001392 else if (tmp == 3)
1393 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001394 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001395 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001396 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1397 spec->autocfg.line_outs))
1398 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001399 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001400 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001401 return 1;
1402}
Kailang Yangea1fb292008-08-26 12:58:38 +02001403
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001404/* Check the validity of ALC subsystem-id
1405 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1406static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001407{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001408 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001409 struct alc_spec *spec = codec->spec;
1410 snd_printd("realtek: "
1411 "Enable default setup for auto mode as fallback\n");
1412 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001413 }
Takashi Iwai21268962011-07-07 15:01:13 +02001414}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001415
Takashi Iwai41e41f12005-06-08 14:48:49 +02001416/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001417 * COEF access helper functions
1418 */
Kailang Yang274693f2009-12-03 10:07:50 +01001419static int alc_read_coef_idx(struct hda_codec *codec,
1420 unsigned int coef_idx)
1421{
1422 unsigned int val;
1423 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1424 coef_idx);
1425 val = snd_hda_codec_read(codec, 0x20, 0,
1426 AC_VERB_GET_PROC_COEF, 0);
1427 return val;
1428}
1429
Kailang Yang977ddd62010-09-15 10:02:29 +02001430static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1431 unsigned int coef_val)
1432{
1433 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1434 coef_idx);
1435 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1436 coef_val);
1437}
1438
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001439/* a special bypass for COEF 0; read the cached value at the second time */
1440static unsigned int alc_get_coef0(struct hda_codec *codec)
1441{
1442 struct alc_spec *spec = codec->spec;
1443 if (!spec->coef0)
1444 spec->coef0 = alc_read_coef_idx(codec, 0);
1445 return spec->coef0;
1446}
1447
Takashi Iwai1d045db2011-07-07 18:23:21 +02001448/*
1449 * Digital I/O handling
1450 */
1451
Takashi Iwai757899a2010-07-30 10:48:14 +02001452/* set right pin controls for digital I/O */
1453static void alc_auto_init_digital(struct hda_codec *codec)
1454{
1455 struct alc_spec *spec = codec->spec;
1456 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001457 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001458
1459 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1460 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001461 if (!pin)
1462 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001463 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001464 if (!i)
1465 dac = spec->multiout.dig_out_nid;
1466 else
1467 dac = spec->slave_dig_outs[i - 1];
1468 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1469 continue;
1470 snd_hda_codec_write(codec, dac, 0,
1471 AC_VERB_SET_AMP_GAIN_MUTE,
1472 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001473 }
1474 pin = spec->autocfg.dig_in_pin;
1475 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001476 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001477}
1478
1479/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1480static void alc_auto_parse_digital(struct hda_codec *codec)
1481{
1482 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001483 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001484 hda_nid_t dig_nid;
1485
1486 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001487 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001488 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001489 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001490 err = snd_hda_get_connections(codec,
1491 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001492 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001493 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001494 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001495 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001496 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001497 spec->multiout.dig_out_nid = dig_nid;
1498 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1499 } else {
1500 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001501 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001502 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001503 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001504 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001505 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001506 }
1507
1508 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001509 dig_nid = codec->start_nid;
1510 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1511 unsigned int wcaps = get_wcaps(codec, dig_nid);
1512 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1513 continue;
1514 if (!(wcaps & AC_WCAP_DIGITAL))
1515 continue;
1516 if (!(wcaps & AC_WCAP_CONN_LIST))
1517 continue;
1518 err = get_connection_index(codec, dig_nid,
1519 spec->autocfg.dig_in_pin);
1520 if (err >= 0) {
1521 spec->dig_in_nid = dig_nid;
1522 break;
1523 }
1524 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001525 }
1526}
1527
Takashi Iwaif95474e2007-07-10 00:47:43 +02001528/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001529 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001530 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001531static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1532 struct snd_ctl_elem_info *uinfo)
1533{
1534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1535 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001536 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001537 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001538
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001539 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001540 if (spec->vol_in_capsrc)
1541 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1542 else
1543 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1544 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001545 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001546 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001547 return err;
1548}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001550static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1551 unsigned int size, unsigned int __user *tlv)
1552{
1553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1554 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001555 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001556 int err;
1557
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001558 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001559 if (spec->vol_in_capsrc)
1560 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1561 else
1562 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1563 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001564 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001565 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001566 return err;
1567}
1568
1569typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1570 struct snd_ctl_elem_value *ucontrol);
1571
1572static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1573 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001574 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001575{
1576 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1577 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001578 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001579
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001580 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001581 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001582 for (i = 0; i < spec->num_adc_nids; i++) {
1583 kcontrol->private_value =
1584 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1585 3, 0, HDA_INPUT);
1586 err = func(kcontrol, ucontrol);
1587 if (err < 0)
1588 goto error;
1589 }
1590 } else {
1591 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001592 if (spec->vol_in_capsrc)
1593 kcontrol->private_value =
1594 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1595 3, 0, HDA_OUTPUT);
1596 else
1597 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001598 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1599 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001600 err = func(kcontrol, ucontrol);
1601 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001602 if (err >= 0 && is_put)
1603 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001604 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001605 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001606 return err;
1607}
1608
1609static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1611{
1612 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001613 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001614}
1615
1616static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1618{
1619 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001620 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001621}
1622
1623/* capture mixer elements */
1624#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1625
1626static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1627 struct snd_ctl_elem_value *ucontrol)
1628{
1629 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001630 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001631}
1632
1633static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1634 struct snd_ctl_elem_value *ucontrol)
1635{
1636 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001637 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001638}
1639
Takashi Iwaia23b6882009-03-23 15:21:36 +01001640#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001641 { \
1642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1643 .name = "Capture Switch", \
1644 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1645 .count = num, \
1646 .info = alc_cap_sw_info, \
1647 .get = alc_cap_sw_get, \
1648 .put = alc_cap_sw_put, \
1649 }, \
1650 { \
1651 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1652 .name = "Capture Volume", \
1653 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1654 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1655 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1656 .count = num, \
1657 .info = alc_cap_vol_info, \
1658 .get = alc_cap_vol_get, \
1659 .put = alc_cap_vol_put, \
1660 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001661 }
1662
1663#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001664 { \
1665 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1666 /* .name = "Capture Source", */ \
1667 .name = "Input Source", \
1668 .count = num, \
1669 .info = alc_mux_enum_info, \
1670 .get = alc_mux_enum_get, \
1671 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001672 }
1673
1674#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001675static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001676 _DEFINE_CAPMIX(num), \
1677 _DEFINE_CAPSRC(num), \
1678 { } /* end */ \
1679}
1680
1681#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001682static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001683 _DEFINE_CAPMIX(num), \
1684 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001685}
1686
1687/* up to three ADCs */
1688DEFINE_CAPMIX(1);
1689DEFINE_CAPMIX(2);
1690DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001691DEFINE_CAPMIX_NOSRC(1);
1692DEFINE_CAPMIX_NOSRC(2);
1693DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001694
1695/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001696 * Inverted digital-mic handling
1697 *
1698 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1699 * gives the additional mute only to the right channel of the digital mic
1700 * capture stream. This is a workaround for avoiding the almost silence
1701 * by summing the stereo stream from some (known to be ForteMedia)
1702 * digital mic unit.
1703 *
1704 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1705 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1706 * without caching so that the cache can still keep the original value.
1707 * The cached value is then restored when the flag is set off or any other
1708 * than d-mic is used as the current input source.
1709 */
1710static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1711{
1712 struct alc_spec *spec = codec->spec;
1713 int i;
1714
1715 if (!spec->inv_dmic_fixup)
1716 return;
1717 if (!spec->inv_dmic_muted && !force)
1718 return;
1719 for (i = 0; i < spec->num_adc_nids; i++) {
1720 int src = spec->dyn_adc_switch ? 0 : i;
1721 bool dmic_fixup = false;
1722 hda_nid_t nid;
1723 int parm, dir, v;
1724
1725 if (spec->inv_dmic_muted &&
1726 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1727 dmic_fixup = true;
1728 if (!dmic_fixup && !force)
1729 continue;
1730 if (spec->vol_in_capsrc) {
1731 nid = spec->capsrc_nids[i];
1732 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1733 dir = HDA_OUTPUT;
1734 } else {
1735 nid = spec->adc_nids[i];
1736 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1737 dir = HDA_INPUT;
1738 }
1739 /* we care only right channel */
1740 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1741 if (v & 0x80) /* if already muted, we don't need to touch */
1742 continue;
1743 if (dmic_fixup) /* add mute for d-mic */
1744 v |= 0x80;
1745 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1746 parm | v);
1747 }
1748}
1749
1750static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1751 struct snd_ctl_elem_value *ucontrol)
1752{
1753 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1754 struct alc_spec *spec = codec->spec;
1755
1756 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1757 return 0;
1758}
1759
1760static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1761 struct snd_ctl_elem_value *ucontrol)
1762{
1763 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1764 struct alc_spec *spec = codec->spec;
1765 unsigned int val = !ucontrol->value.integer.value[0];
1766
1767 if (val == spec->inv_dmic_muted)
1768 return 0;
1769 spec->inv_dmic_muted = val;
1770 alc_inv_dmic_sync(codec, true);
1771 return 0;
1772}
1773
1774static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1776 .info = snd_ctl_boolean_mono_info,
1777 .get = alc_inv_dmic_sw_get,
1778 .put = alc_inv_dmic_sw_put,
1779};
1780
1781static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1782{
1783 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001784
1785 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1786 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001787 return -ENOMEM;
1788 spec->inv_dmic_fixup = 1;
1789 spec->inv_dmic_muted = 0;
1790 spec->inv_dmic_pin = nid;
1791 return 0;
1792}
1793
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001794/* typically the digital mic is put at node 0x12 */
1795static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1796 const struct alc_fixup *fix, int action)
1797{
1798 if (action == ALC_FIXUP_ACT_PROBE)
1799 alc_add_inv_dmic_mixer(codec, 0x12);
1800}
1801
Takashi Iwai125821a2012-06-22 14:30:29 +02001802/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001803 * virtual master controls
1804 */
1805
1806/*
1807 * slave controls for virtual master
1808 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001809static const char * const alc_slave_pfxs[] = {
1810 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001811 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001812 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001813 NULL,
1814};
1815
1816/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001817 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001819
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001820#define NID_MAPPING (-1)
1821
1822#define SUBDEV_SPEAKER_ (0 << 6)
1823#define SUBDEV_HP_ (1 << 6)
1824#define SUBDEV_LINE_ (2 << 6)
1825#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1826#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1827#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1828
Takashi Iwai603c4012008-07-30 15:01:44 +02001829static void alc_free_kctls(struct hda_codec *codec);
1830
Takashi Iwai67d634c2009-11-16 15:35:59 +01001831#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001832/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001833static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001834 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001835 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001836 { } /* end */
1837};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001838#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001839
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001840static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841{
1842 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001843 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001844 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001845 int i, j, err;
1846 unsigned int u;
1847 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
1849 for (i = 0; i < spec->num_mixers; i++) {
1850 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1851 if (err < 0)
1852 return err;
1853 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001854 if (spec->cap_mixer) {
1855 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1856 if (err < 0)
1857 return err;
1858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001860 err = snd_hda_create_dig_out_ctls(codec,
1861 spec->multiout.dig_out_nid,
1862 spec->multiout.dig_out_nid,
1863 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 if (err < 0)
1865 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001866 if (!spec->no_analog) {
1867 err = snd_hda_create_spdif_share_sw(codec,
1868 &spec->multiout);
1869 if (err < 0)
1870 return err;
1871 spec->multiout.share_spdif = 1;
1872 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 }
1874 if (spec->dig_in_nid) {
1875 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1876 if (err < 0)
1877 return err;
1878 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001879
Takashi Iwai67d634c2009-11-16 15:35:59 +01001880#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001881 /* create beep controls if needed */
1882 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001883 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001884 for (knew = alc_beep_mixer; knew->name; knew++) {
1885 struct snd_kcontrol *kctl;
1886 kctl = snd_ctl_new1(knew, codec);
1887 if (!kctl)
1888 return -ENOMEM;
1889 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001890 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001891 if (err < 0)
1892 return err;
1893 }
1894 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001895#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001896
Takashi Iwai2134ea42008-01-10 16:53:55 +01001897 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001898 if (!spec->no_analog &&
1899 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001900 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001901 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001902 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001903 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001904 vmaster_tlv, alc_slave_pfxs,
1905 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001906 if (err < 0)
1907 return err;
1908 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001909 if (!spec->no_analog &&
1910 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001911 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1912 NULL, alc_slave_pfxs,
1913 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001914 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001915 if (err < 0)
1916 return err;
1917 }
1918
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001919 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001920 if (spec->capsrc_nids || spec->adc_nids) {
1921 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1922 if (!kctl)
1923 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1924 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001925 err = snd_hda_add_nid(codec, kctl, i,
1926 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001927 if (err < 0)
1928 return err;
1929 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001930 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001931 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001932 const char *kname = kctl ? kctl->id.name : NULL;
1933 for (knew = spec->cap_mixer; knew->name; knew++) {
1934 if (kname && strcmp(knew->name, kname) == 0)
1935 continue;
1936 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1937 for (i = 0; kctl && i < kctl->count; i++) {
1938 err = snd_hda_add_nid(codec, kctl, i,
1939 spec->adc_nids[i]);
1940 if (err < 0)
1941 return err;
1942 }
1943 }
1944 }
1945
1946 /* other nid->control mapping */
1947 for (i = 0; i < spec->num_mixers; i++) {
1948 for (knew = spec->mixers[i]; knew->name; knew++) {
1949 if (knew->iface != NID_MAPPING)
1950 continue;
1951 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1952 if (kctl == NULL)
1953 continue;
1954 u = knew->subdevice;
1955 for (j = 0; j < 4; j++, u >>= 8) {
1956 nid = u & 0x3f;
1957 if (nid == 0)
1958 continue;
1959 switch (u & 0xc0) {
1960 case SUBDEV_SPEAKER_:
1961 nid = spec->autocfg.speaker_pins[nid];
1962 break;
1963 case SUBDEV_LINE_:
1964 nid = spec->autocfg.line_out_pins[nid];
1965 break;
1966 case SUBDEV_HP_:
1967 nid = spec->autocfg.hp_pins[nid];
1968 break;
1969 default:
1970 continue;
1971 }
1972 err = snd_hda_add_nid(codec, kctl, 0, nid);
1973 if (err < 0)
1974 return err;
1975 }
1976 u = knew->private_value;
1977 for (j = 0; j < 4; j++, u >>= 8) {
1978 nid = u & 0xff;
1979 if (nid == 0)
1980 continue;
1981 err = snd_hda_add_nid(codec, kctl, 0, nid);
1982 if (err < 0)
1983 return err;
1984 }
1985 }
1986 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001987
1988 alc_free_kctls(codec); /* no longer needed */
1989
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001990 return 0;
1991}
1992
David Henningsson5780b622012-06-27 18:45:45 +02001993static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001994{
1995 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001996
1997 if (spec->shared_mic_hp) {
1998 int err;
1999 int nid = spec->autocfg.inputs[1].pin;
2000 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
2001 if (err < 0)
2002 return err;
2003 err = snd_hda_jack_detect_enable(codec, nid, 0);
2004 if (err < 0)
2005 return err;
2006 }
2007
2008 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2009}
2010
2011static int alc_build_controls(struct hda_codec *codec)
2012{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002013 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002014 if (err < 0)
2015 return err;
David Henningsson5780b622012-06-27 18:45:45 +02002016
2017 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002018 if (err < 0)
2019 return err;
2020 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2021 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022}
2023
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002024
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002026 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002027 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002028
Takashi Iwai584c0c42011-03-10 12:51:11 +01002029static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002030static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002031
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032static int alc_init(struct hda_codec *codec)
2033{
2034 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002035
Takashi Iwai546bb672012-03-07 08:37:19 +01002036 if (spec->init_hook)
2037 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002038
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002039 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002040 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002041
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002042 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002043 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002044 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002045
Takashi Iwai58701122011-01-13 15:41:45 +01002046 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2047
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002048 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 return 0;
2050}
2051
Takashi Iwai83012a72012-08-24 18:38:08 +02002052#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002053static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2054{
2055 struct alc_spec *spec = codec->spec;
2056 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2057}
2058#endif
2059
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060/*
2061 * Analog playback callbacks
2062 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002063static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002065 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
2067 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002068 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2069 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070}
2071
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002072static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 struct hda_codec *codec,
2074 unsigned int stream_tag,
2075 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002076 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
2078 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002079 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2080 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081}
2082
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002083static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002085 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
2087 struct alc_spec *spec = codec->spec;
2088 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2089}
2090
2091/*
2092 * Digital out
2093 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002094static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002096 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
2098 struct alc_spec *spec = codec->spec;
2099 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2100}
2101
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002102static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002103 struct hda_codec *codec,
2104 unsigned int stream_tag,
2105 unsigned int format,
2106 struct snd_pcm_substream *substream)
2107{
2108 struct alc_spec *spec = codec->spec;
2109 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2110 stream_tag, format, substream);
2111}
2112
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002113static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002114 struct hda_codec *codec,
2115 struct snd_pcm_substream *substream)
2116{
2117 struct alc_spec *spec = codec->spec;
2118 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2119}
2120
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002121static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002123 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
2125 struct alc_spec *spec = codec->spec;
2126 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2127}
2128
2129/*
2130 * Analog capture
2131 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002132static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 struct hda_codec *codec,
2134 unsigned int stream_tag,
2135 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002136 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
2138 struct alc_spec *spec = codec->spec;
2139
Takashi Iwai63300792008-01-24 15:31:36 +01002140 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 stream_tag, 0, format);
2142 return 0;
2143}
2144
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002145static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002147 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148{
2149 struct alc_spec *spec = codec->spec;
2150
Takashi Iwai888afa12008-03-18 09:57:50 +01002151 snd_hda_codec_cleanup_stream(codec,
2152 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 return 0;
2154}
2155
Takashi Iwai840b64c2010-07-13 22:49:01 +02002156/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002157static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002158 struct hda_codec *codec,
2159 unsigned int stream_tag,
2160 unsigned int format,
2161 struct snd_pcm_substream *substream)
2162{
2163 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002164 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002165 spec->cur_adc_stream_tag = stream_tag;
2166 spec->cur_adc_format = format;
2167 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2168 return 0;
2169}
2170
Takashi Iwai21268962011-07-07 15:01:13 +02002171static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002172 struct hda_codec *codec,
2173 struct snd_pcm_substream *substream)
2174{
2175 struct alc_spec *spec = codec->spec;
2176 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2177 spec->cur_adc = 0;
2178 return 0;
2179}
2180
Takashi Iwai21268962011-07-07 15:01:13 +02002181static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002182 .substreams = 1,
2183 .channels_min = 2,
2184 .channels_max = 2,
2185 .nid = 0, /* fill later */
2186 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002187 .prepare = dyn_adc_capture_pcm_prepare,
2188 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002189 },
2190};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
2192/*
2193 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002194static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 .substreams = 1,
2196 .channels_min = 2,
2197 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002198 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002200 .open = alc_playback_pcm_open,
2201 .prepare = alc_playback_pcm_prepare,
2202 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 },
2204};
2205
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002206static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002207 .substreams = 1,
2208 .channels_min = 2,
2209 .channels_max = 2,
2210 /* NID is set in alc_build_pcms */
2211};
2212
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002213static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002214 .substreams = 1,
2215 .channels_min = 2,
2216 .channels_max = 2,
2217 /* NID is set in alc_build_pcms */
2218};
2219
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002220static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002221 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 .channels_min = 2,
2223 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002224 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002226 .prepare = alc_alt_capture_pcm_prepare,
2227 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 },
2229};
2230
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002231static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 .substreams = 1,
2233 .channels_min = 2,
2234 .channels_max = 2,
2235 /* NID is set in alc_build_pcms */
2236 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002237 .open = alc_dig_playback_pcm_open,
2238 .close = alc_dig_playback_pcm_close,
2239 .prepare = alc_dig_playback_pcm_prepare,
2240 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 },
2242};
2243
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002244static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 .substreams = 1,
2246 .channels_min = 2,
2247 .channels_max = 2,
2248 /* NID is set in alc_build_pcms */
2249};
2250
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002251/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002252static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002253 .substreams = 0,
2254 .channels_min = 0,
2255 .channels_max = 0,
2256};
2257
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258static int alc_build_pcms(struct hda_codec *codec)
2259{
2260 struct alc_spec *spec = codec->spec;
2261 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002262 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002263 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 int i;
2265
2266 codec->num_pcms = 1;
2267 codec->pcm_info = info;
2268
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002269 if (spec->no_analog)
2270 goto skip_analog;
2271
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002272 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2273 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002275
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002276 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002277 p = spec->stream_analog_playback;
2278 if (!p)
2279 p = &alc_pcm_analog_playback;
2280 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002282 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2283 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002284 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2285 spec->autocfg.line_outs == 2)
2286 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2287 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002288 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002289 if (spec->adc_nids) {
2290 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002291 if (!p) {
2292 if (spec->dyn_adc_switch)
2293 p = &dyn_adc_pcm_analog_capture;
2294 else
2295 p = &alc_pcm_analog_capture;
2296 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002297 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002298 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
Takashi Iwai4a471b72005-12-07 13:56:29 +01002301 if (spec->channel_mode) {
2302 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2303 for (i = 0; i < spec->num_channel_mode; i++) {
2304 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2306 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 }
2308 }
2309
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002310 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002311 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002313 snprintf(spec->stream_name_digital,
2314 sizeof(spec->stream_name_digital),
2315 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002316 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002317 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002318 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002320 if (spec->dig_out_type)
2321 info->pcm_type = spec->dig_out_type;
2322 else
2323 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002324 if (spec->multiout.dig_out_nid) {
2325 p = spec->stream_digital_playback;
2326 if (!p)
2327 p = &alc_pcm_digital_playback;
2328 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2330 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002331 if (spec->dig_in_nid) {
2332 p = spec->stream_digital_capture;
2333 if (!p)
2334 p = &alc_pcm_digital_capture;
2335 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2337 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002338 /* FIXME: do we need this for all Realtek codec models? */
2339 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 }
2341
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002342 if (spec->no_analog)
2343 return 0;
2344
Takashi Iwaie08a0072006-09-07 17:52:14 +02002345 /* If the use of more than one ADC is requested for the current
2346 * model, configure a second analog capture-only PCM.
2347 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002348 have_multi_adcs = (spec->num_adc_nids > 1) &&
2349 !spec->dyn_adc_switch && !spec->auto_mic &&
2350 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002351 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002352 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002353 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002354 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002355 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002356 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002357 p = spec->stream_analog_alt_playback;
2358 if (!p)
2359 p = &alc_pcm_analog_alt_playback;
2360 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002361 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2362 spec->alt_dac_nid;
2363 } else {
2364 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2365 alc_pcm_null_stream;
2366 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2367 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002368 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002369 p = spec->stream_analog_alt_capture;
2370 if (!p)
2371 p = &alc_pcm_analog_alt_capture;
2372 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002373 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2374 spec->adc_nids[1];
2375 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2376 spec->num_adc_nids - 1;
2377 } else {
2378 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2379 alc_pcm_null_stream;
2380 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002381 }
2382 }
2383
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 return 0;
2385}
2386
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002387static inline void alc_shutup(struct hda_codec *codec)
2388{
Takashi Iwai1c716152011-04-07 10:37:16 +02002389 struct alc_spec *spec = codec->spec;
2390
2391 if (spec && spec->shutup)
2392 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002393 snd_hda_shutup_pins(codec);
2394}
2395
Takashi Iwai603c4012008-07-30 15:01:44 +02002396static void alc_free_kctls(struct hda_codec *codec)
2397{
2398 struct alc_spec *spec = codec->spec;
2399
2400 if (spec->kctls.list) {
2401 struct snd_kcontrol_new *kctl = spec->kctls.list;
2402 int i;
2403 for (i = 0; i < spec->kctls.used; i++)
2404 kfree(kctl[i].name);
2405 }
2406 snd_array_free(&spec->kctls);
2407}
2408
Takashi Iwai23c09b02011-08-19 09:05:35 +02002409static void alc_free_bind_ctls(struct hda_codec *codec)
2410{
2411 struct alc_spec *spec = codec->spec;
2412 if (spec->bind_ctls.list) {
2413 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2414 int i;
2415 for (i = 0; i < spec->bind_ctls.used; i++)
2416 kfree(ctl[i]);
2417 }
2418 snd_array_free(&spec->bind_ctls);
2419}
2420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421static void alc_free(struct hda_codec *codec)
2422{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002423 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002424
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002425 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002426 return;
2427
Takashi Iwai603c4012008-07-30 15:01:44 +02002428 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002429 alc_free_bind_ctls(codec);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002430 snd_array_free(&spec->out_path);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002431 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002432 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002433 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434}
2435
Takashi Iwai83012a72012-08-24 18:38:08 +02002436#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002437static void alc_power_eapd(struct hda_codec *codec)
2438{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002439 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002440}
2441
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002442static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002443{
2444 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002445 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002446 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002447 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002448 return 0;
2449}
2450#endif
2451
Takashi Iwai2a439522011-07-26 09:52:50 +02002452#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002453static int alc_resume(struct hda_codec *codec)
2454{
Takashi Iwai1c716152011-04-07 10:37:16 +02002455 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002456 codec->patch_ops.init(codec);
2457 snd_hda_codec_resume_amp(codec);
2458 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002459 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002460 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002461 return 0;
2462}
Takashi Iwaie044c392008-10-27 16:56:24 +01002463#endif
2464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465/*
2466 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002467static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 .build_controls = alc_build_controls,
2469 .build_pcms = alc_build_pcms,
2470 .init = alc_init,
2471 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002472 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002473#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002474 .resume = alc_resume,
2475#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002476#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002477 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002478 .check_power_status = alc_check_power_status,
2479#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002480 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481};
2482
David Henningsson29adc4b2012-09-25 11:31:00 +02002483
Kailang Yangc027ddc2010-03-19 11:33:06 +01002484/* replace the codec chip_name with the given string */
2485static int alc_codec_rename(struct hda_codec *codec, const char *name)
2486{
2487 kfree(codec->chip_name);
2488 codec->chip_name = kstrdup(name, GFP_KERNEL);
2489 if (!codec->chip_name) {
2490 alc_free(codec);
2491 return -ENOMEM;
2492 }
2493 return 0;
2494}
2495
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002496/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002497 * Rename codecs appropriately from COEF value
2498 */
2499struct alc_codec_rename_table {
2500 unsigned int vendor_id;
2501 unsigned short coef_mask;
2502 unsigned short coef_bits;
2503 const char *name;
2504};
2505
2506static struct alc_codec_rename_table rename_tbl[] = {
2507 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2508 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2509 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2510 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2511 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2512 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2513 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002514 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002515 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2516 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2517 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2518 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2519 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2520 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2521 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2522 { } /* terminator */
2523};
2524
2525static int alc_codec_rename_from_preset(struct hda_codec *codec)
2526{
2527 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002528
2529 for (p = rename_tbl; p->vendor_id; p++) {
2530 if (p->vendor_id != codec->vendor_id)
2531 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002532 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002533 return alc_codec_rename(codec, p->name);
2534 }
2535 return 0;
2536}
2537
2538/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002539 * Automatic parse of I/O pins from the BIOS configuration
2540 */
2541
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002542enum {
2543 ALC_CTL_WIDGET_VOL,
2544 ALC_CTL_WIDGET_MUTE,
2545 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002546 ALC_CTL_BIND_VOL,
2547 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002548};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002549static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002550 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2551 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002552 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002553 HDA_BIND_VOL(NULL, 0),
2554 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002555};
2556
2557/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002558static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002559 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002560{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002561 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002562
Takashi Iwai668d1e92012-11-29 14:10:17 +01002563 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002564 if (!knew)
2565 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002566 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002567 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002568 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002569 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002570 return 0;
2571}
2572
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002573static int add_control_with_pfx(struct alc_spec *spec, int type,
2574 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002575 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002576{
2577 char name[32];
2578 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002579 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002580}
2581
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002582#define add_pb_vol_ctrl(spec, type, pfx, val) \
2583 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2584#define add_pb_sw_ctrl(spec, type, pfx, val) \
2585 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2586#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2587 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2588#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2589 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002590
Takashi Iwai23c09b02011-08-19 09:05:35 +02002591static const char * const channel_name[4] = {
2592 "Front", "Surround", "CLFE", "Side"
2593};
2594
Takashi Iwai6843ca12011-06-24 11:03:58 +02002595static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2596 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002597{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002598 struct auto_pin_cfg *cfg = &spec->autocfg;
2599
Takashi Iwai6843ca12011-06-24 11:03:58 +02002600 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002601 if (cfg->line_outs == 1 && !spec->multi_ios &&
2602 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002603 return "Master";
2604
2605 switch (cfg->line_out_type) {
2606 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002607 if (cfg->line_outs == 1)
2608 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002609 if (cfg->line_outs == 2)
2610 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002611 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002612 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002613 /* for multi-io case, only the primary out */
2614 if (ch && spec->multi_ios)
2615 break;
2616 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002617 return "Headphone";
2618 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002619 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002620 return "PCM";
2621 break;
2622 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002623 if (ch >= ARRAY_SIZE(channel_name)) {
2624 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002625 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002626 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002627
2628 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002629}
2630
Takashi Iwai83012a72012-08-24 18:38:08 +02002631#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002632/* add the powersave loopback-list entry */
2633static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2634{
2635 struct hda_amp_list *list;
2636
2637 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2638 return;
2639 list = spec->loopback_list + spec->num_loopbacks;
2640 list->nid = mix;
2641 list->dir = HDA_INPUT;
2642 list->idx = idx;
2643 spec->num_loopbacks++;
2644 spec->loopback.amplist = spec->loopback_list;
2645}
2646#else
2647#define add_loopback_list(spec, mix, idx) /* NOP */
2648#endif
2649
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002650/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002651static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002652 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002653 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002654{
Kailang Yangdf694da2005-12-05 19:42:22 +01002655 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002656
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002657 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002658 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2659 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002660 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002661 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002662 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2663 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002664 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002665 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002666 return 0;
2667}
2668
Takashi Iwai05f5f472009-08-25 13:10:18 +02002669static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002670{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002671 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2672 return (pincap & AC_PINCAP_IN) != 0;
2673}
2674
Takashi Iwai1d045db2011-07-07 18:23:21 +02002675/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002676static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002677{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002678 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002679 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002680 hda_nid_t *adc_nids = spec->private_adc_nids;
2681 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2682 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002683 int i, nums = 0;
2684
2685 nid = codec->start_nid;
2686 for (i = 0; i < codec->num_nodes; i++, nid++) {
2687 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002688 unsigned int caps = get_wcaps(codec, nid);
2689 int type = get_wcaps_type(caps);
2690
2691 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2692 continue;
2693 adc_nids[nums] = nid;
2694 cap_nids[nums] = nid;
2695 src = nid;
2696 for (;;) {
2697 int n;
2698 type = get_wcaps_type(get_wcaps(codec, src));
2699 if (type == AC_WID_PIN)
2700 break;
2701 if (type == AC_WID_AUD_SEL) {
2702 cap_nids[nums] = src;
2703 break;
2704 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002705 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002706 if (n > 1) {
2707 cap_nids[nums] = src;
2708 break;
2709 } else if (n != 1)
2710 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002711 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2712 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002713 }
2714 if (++nums >= max_nums)
2715 break;
2716 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002717 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002718 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002719 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002720 return nums;
2721}
2722
Takashi Iwai05f5f472009-08-25 13:10:18 +02002723/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002724static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002725{
2726 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002727 const struct auto_pin_cfg *cfg = &spec->autocfg;
2728 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002729 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002730 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002731 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002732 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002733
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002734 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002735 if (num_adcs < 0)
2736 return 0;
2737
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002738 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002739 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002740 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002741
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002742 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002743 if (!alc_is_input_pin(codec, pin))
2744 continue;
2745
David Henningsson5322bf22011-01-05 11:03:56 +01002746 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002747 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2748 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002749 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002750 type_idx++;
2751 else
2752 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002753 prev_label = label;
2754
Takashi Iwai05f5f472009-08-25 13:10:18 +02002755 if (mixer) {
2756 idx = get_connection_index(codec, mixer, pin);
2757 if (idx >= 0) {
2758 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002759 label, type_idx,
2760 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002761 if (err < 0)
2762 return err;
2763 }
2764 }
2765
Takashi Iwaib7821702011-07-06 15:12:46 +02002766 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002767 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002768 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002769 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002770 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002771 snd_hda_add_imux_item(imux, label, idx, NULL);
2772 break;
2773 }
2774 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002775 }
Takashi Iwai21268962011-07-07 15:01:13 +02002776
2777 spec->num_mux_defs = 1;
2778 spec->input_mux = imux;
2779
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002780 return 0;
2781}
2782
Takashi Iwai24de1832011-11-07 17:13:39 +01002783/* create a shared input with the headphone out */
2784static int alc_auto_create_shared_input(struct hda_codec *codec)
2785{
2786 struct alc_spec *spec = codec->spec;
2787 struct auto_pin_cfg *cfg = &spec->autocfg;
2788 unsigned int defcfg;
2789 hda_nid_t nid;
2790
2791 /* only one internal input pin? */
2792 if (cfg->num_inputs != 1)
2793 return 0;
2794 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2795 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2796 return 0;
2797
2798 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2799 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2800 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2801 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2802 else
2803 return 0; /* both not available */
2804
2805 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2806 return 0; /* no input */
2807
2808 cfg->inputs[1].pin = nid;
2809 cfg->inputs[1].type = AUTO_PIN_MIC;
2810 cfg->num_inputs = 2;
2811 spec->shared_mic_hp = 1;
2812 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2813 return 0;
2814}
2815
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002816static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2817 unsigned int pin_type)
2818{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002819 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002820 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002821 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2822 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002823 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002824}
2825
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002826static int get_pin_type(int line_out_type)
2827{
2828 if (line_out_type == AUTO_PIN_HP_OUT)
2829 return PIN_HP;
2830 else
2831 return PIN_OUT;
2832}
2833
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002834static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002835{
2836 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002837 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002838 int i;
2839
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002840 for (i = 0; i < cfg->num_inputs; i++) {
2841 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002842 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002843 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002844 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002845 snd_hda_codec_write(codec, nid, 0,
2846 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002847 AMP_OUT_MUTE);
2848 }
2849 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002850
2851 /* mute all loopback inputs */
2852 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002853 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002854 for (i = 0; i < nums; i++)
2855 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2856 AC_VERB_SET_AMP_GAIN_MUTE,
2857 AMP_IN_MUTE(i));
2858 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002859}
2860
Takashi Iwai185d99f2012-02-16 18:39:45 +01002861static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2862{
2863 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002864 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002865
2866 for (i = 0; i < spec->out_path.used; i++) {
2867 struct nid_path *path = snd_array_elem(&spec->out_path, i);
2868 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002869 return true;
2870 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002871 return false;
2872}
2873
Takashi Iwai07b18f62011-11-10 15:42:54 +01002874/* check whether the DAC is reachable from the pin */
2875static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2876 hda_nid_t pin, hda_nid_t dac)
2877{
Takashi Iwaidc31b582012-02-17 17:27:53 +01002878 if (!pin || !dac)
2879 return false;
Takashi Iwai6a84c302012-12-05 14:08:45 +01002880 return snd_hda_get_conn_index(codec, pin, dac, true) >= 0;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002881}
2882
Takashi Iwai463419d2012-12-05 14:17:37 +01002883/* look for an empty DAC slot */
2884static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2885{
2886 struct alc_spec *spec = codec->spec;
2887 int i;
2888
2889 for (i = 0; i < spec->num_all_dacs; i++) {
2890 hda_nid_t nid = spec->all_dacs[i];
2891 if (!nid || alc_is_dac_already_used(codec, nid))
2892 continue;
2893 if (alc_auto_is_dac_reachable(codec, pin, nid))
2894 return nid;
2895 }
2896 return 0;
2897}
2898
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002899/* called recursively */
2900static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
2901 hda_nid_t target_dac, int with_aa_mix,
2902 struct nid_path *path, int depth)
2903{
2904 struct alc_spec *spec = codec->spec;
2905 hda_nid_t conn[8];
2906 int i, nums;
2907
2908 if (nid == spec->mixer_nid) {
2909 if (!with_aa_mix)
2910 return false;
2911 with_aa_mix = 2; /* mark aa-mix is included */
2912 }
2913
2914 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
2915 for (i = 0; i < nums; i++) {
2916 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
2917 continue;
2918 if (conn[i] == target_dac ||
2919 (!target_dac && !alc_is_dac_already_used(codec, conn[i]))) {
2920 /* aa-mix is requested but not included? */
2921 if (!(spec->mixer_nid && with_aa_mix == 1))
2922 goto found;
2923 }
2924 }
2925 if (depth >= MAX_NID_PATH_DEPTH)
2926 return false;
2927 for (i = 0; i < nums; i++) {
2928 unsigned int type;
2929 type = get_wcaps_type(get_wcaps(codec, conn[i]));
2930 if (type == AC_WID_AUD_OUT)
2931 continue;
2932 if (__parse_output_path(codec, conn[i], target_dac,
2933 with_aa_mix, path, depth + 1))
2934 goto found;
2935 }
2936 return false;
2937
2938 found:
2939 path->path[path->depth] = conn[i];
2940 path->idx[path->depth] = i;
2941 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
2942 path->multi[path->depth] = 1;
2943 path->depth++;
2944 return true;
2945}
2946
2947/* parse the output path from the given nid to the target DAC;
2948 * when target_dac is 0, try to find an empty DAC;
2949 * when with_aa_mix is 0, paths with spec->mixer_nid are excluded
2950 */
2951static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
2952 hda_nid_t target_dac, int with_aa_mix,
2953 struct nid_path *path)
2954{
2955 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
2956 path->path[path->depth] = nid;
2957 path->depth++;
2958#if 0
2959 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
2960 path->depth, path->path[0], path->path[1],
2961 path->path[2], path->path[3], path->path[4]);
2962#endif
2963 return true;
2964 }
2965 return false;
2966}
2967
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002968static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2969{
Takashi Iwai140547e2012-02-16 17:23:46 +01002970 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002971 int i;
2972 hda_nid_t nid_found = 0;
2973
2974 for (i = 0; i < spec->num_all_dacs; i++) {
2975 hda_nid_t nid = spec->all_dacs[i];
2976 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002977 continue;
Takashi Iwai463419d2012-12-05 14:17:37 +01002978 if (alc_auto_is_dac_reachable(codec, pin, nid)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01002979 if (nid_found)
2980 return 0;
2981 nid_found = nid;
2982 }
2983 }
2984 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002985}
2986
Takashi Iwaiba8111272012-12-06 18:06:23 +01002987static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002988{
Takashi Iwaiba8111272012-12-06 18:06:23 +01002989 struct alc_spec *spec = codec->spec;
2990 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002991
Takashi Iwaiba8111272012-12-06 18:06:23 +01002992 for (i = 0; i < spec->out_path.used; i++) {
2993 struct nid_path *path = snd_array_elem(&spec->out_path, i);
2994 if (path->ctls[type] == val)
2995 return true;
2996 }
2997 return false;
2998}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002999
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003000/* badness definition */
3001enum {
3002 /* No primary DAC is found for the main output */
3003 BAD_NO_PRIMARY_DAC = 0x10000,
3004 /* No DAC is found for the extra output */
3005 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003006 /* No possible multi-ios */
3007 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003008 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003009 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003010 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003011 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003012 /* Primary DAC shared with main surrounds */
3013 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003014 /* Primary DAC shared with main CLFE */
3015 BAD_SHARED_CLFE = 0x10,
3016 /* Primary DAC shared with extra surrounds */
3017 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003018 /* Volume widget is shared */
3019 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003020};
3021
3022static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003023 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003024static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003025 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003026
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003027static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3028 hda_nid_t dac)
3029{
3030 struct alc_spec *spec = codec->spec;
3031 struct nid_path *path;
3032
3033 path = snd_array_new(&spec->out_path);
3034 if (!path)
3035 return false;
3036 memset(path, 0, sizeof(*path));
3037 if (parse_output_path(codec, pin, dac, 0, path))
3038 return true;
3039 /* push back */
3040 spec->out_path.used--;
3041 return false;
3042}
3043
Takashi Iwaiba8111272012-12-06 18:06:23 +01003044/* get the path pointing from the given dac to pin;
3045 * passing 0 to either @pin or @dac behaves as a wildcard
3046 */
3047static struct nid_path *get_out_path(struct hda_codec *codec, hda_nid_t pin,
3048 hda_nid_t dac)
3049{
3050 struct alc_spec *spec = codec->spec;
3051 int i;
3052
3053 for (i = 0; i < spec->out_path.used; i++) {
3054 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3055 if (path->depth <= 0)
3056 continue;
3057 if ((!dac || path->path[0] == dac) &&
3058 (!pin || path->path[path->depth - 1] == pin))
3059 return path;
3060 }
3061 return NULL;
3062}
3063
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003064/* look for widgets in the path between the given NIDs appropriate for
3065 * volume and mute controls, and assign the values to ctls[].
3066 *
3067 * When no appropriate widget is found in the path, the badness value
3068 * is incremented depending on the situation. The function returns the
3069 * total badness for both volume and mute controls.
3070 */
3071static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3072 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003073{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003074 struct nid_path *path = get_out_path(codec, pin, dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003075 hda_nid_t nid;
3076 unsigned int val;
3077 int badness = 0;
3078
Takashi Iwaiba8111272012-12-06 18:06:23 +01003079 if (!path)
3080 return BAD_SHARED_VOL * 2;
3081 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003082 if (nid) {
3083 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003084 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003085 badness += BAD_SHARED_VOL;
3086 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003087 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003088 } else
3089 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003090 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003091 if (nid) {
3092 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003093 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3094 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003095 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3096 else
3097 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003098 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003099 badness += BAD_SHARED_VOL;
3100 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003101 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003102 } else
3103 badness += BAD_SHARED_VOL;
3104 return badness;
3105}
3106
Takashi Iwaidc31b582012-02-17 17:27:53 +01003107struct badness_table {
3108 int no_primary_dac; /* no primary DAC */
3109 int no_dac; /* no secondary DACs */
3110 int shared_primary; /* primary DAC is shared with main output */
3111 int shared_surr; /* secondary DAC shared with main or primary */
3112 int shared_clfe; /* third DAC shared with main or primary */
3113 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3114};
3115
3116static struct badness_table main_out_badness = {
3117 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3118 .no_dac = BAD_NO_DAC,
3119 .shared_primary = BAD_NO_PRIMARY_DAC,
3120 .shared_surr = BAD_SHARED_SURROUND,
3121 .shared_clfe = BAD_SHARED_CLFE,
3122 .shared_surr_main = BAD_SHARED_SURROUND,
3123};
3124
3125static struct badness_table extra_out_badness = {
3126 .no_primary_dac = BAD_NO_DAC,
3127 .no_dac = BAD_NO_DAC,
3128 .shared_primary = BAD_NO_EXTRA_DAC,
3129 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3130 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3131 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3132};
3133
3134/* try to assign DACs to pins and return the resultant badness */
3135static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3136 const hda_nid_t *pins, hda_nid_t *dacs,
3137 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003138{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003139 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003140 struct auto_pin_cfg *cfg = &spec->autocfg;
3141 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003142 int badness = 0;
3143 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003144
Takashi Iwai185d99f2012-02-16 18:39:45 +01003145 if (!num_outs)
3146 return 0;
3147
Takashi Iwaidc31b582012-02-17 17:27:53 +01003148 for (i = 0; i < num_outs; i++) {
3149 hda_nid_t pin = pins[i];
3150 if (!dacs[i])
3151 dacs[i] = alc_auto_look_for_dac(codec, pin);
3152 if (!dacs[i] && !i) {
3153 for (j = 1; j < num_outs; j++) {
3154 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3155 dacs[0] = dacs[j];
3156 dacs[j] = 0;
3157 break;
3158 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003159 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003160 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003161 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003162 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003163 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003164 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003165 else if (cfg->line_outs > i &&
3166 alc_auto_is_dac_reachable(codec, pin,
3167 spec->private_dac_nids[i]))
3168 dac = spec->private_dac_nids[i];
3169 if (dac) {
3170 if (!i)
3171 badness += bad->shared_primary;
3172 else if (i == 1)
3173 badness += bad->shared_surr;
3174 else
3175 badness += bad->shared_clfe;
3176 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003177 spec->private_dac_nids[0])) {
3178 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003179 badness += bad->shared_surr_main;
3180 } else if (!i)
3181 badness += bad->no_primary_dac;
3182 else
3183 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003184 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003185 if (!add_new_out_path(codec, pin, dac))
3186 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003187 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003188 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003189 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003190
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003191 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003192}
3193
3194static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003195 hda_nid_t reference_pin,
3196 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003197
Takashi Iwai185d99f2012-02-16 18:39:45 +01003198static bool alc_map_singles(struct hda_codec *codec, int outs,
3199 const hda_nid_t *pins, hda_nid_t *dacs)
3200{
3201 int i;
3202 bool found = false;
3203 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003204 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003205 if (dacs[i])
3206 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003207 dac = get_dac_if_single(codec, pins[i]);
3208 if (!dac)
3209 continue;
3210 if (add_new_out_path(codec, pins[i], dac)) {
3211 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003212 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003213 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003214 }
3215 return found;
3216}
3217
Takashi Iwai7085ec12009-10-02 09:03:58 +02003218/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003219static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003220 bool fill_hardwired,
3221 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003222{
3223 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003224 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003225 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003226
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003227 /* set num_dacs once to full for alc_auto_look_for_dac() */
3228 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003229 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003230 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3231 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3232 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003233 spec->multi_ios = 0;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003234 snd_array_free(&spec->out_path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003235 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003236
3237 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003238 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003239 bool mapped;
3240 do {
3241 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003242 cfg->line_out_pins,
3243 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003244 mapped |= alc_map_singles(codec, cfg->hp_outs,
3245 cfg->hp_pins,
3246 spec->multiout.hp_out_nid);
3247 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3248 cfg->speaker_pins,
3249 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003250 if (fill_mio_first && cfg->line_outs == 1 &&
3251 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3252 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3253 if (!err)
3254 mapped = true;
3255 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003256 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003257 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003258
Takashi Iwaidc31b582012-02-17 17:27:53 +01003259 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3260 spec->private_dac_nids,
3261 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003262
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003263 /* re-count num_dacs and squash invalid entries */
3264 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003265 for (i = 0; i < cfg->line_outs; i++) {
3266 if (spec->private_dac_nids[i])
3267 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003268 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003269 memmove(spec->private_dac_nids + i,
3270 spec->private_dac_nids + i + 1,
3271 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003272 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3273 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003274 }
3275
Takashi Iwai276dd702012-02-17 16:17:03 +01003276 if (fill_mio_first &&
3277 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003278 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003279 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003280 if (err < 0)
3281 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003282 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003283 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003284
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003285 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003286 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3287 spec->multiout.hp_out_nid,
3288 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003289 if (err < 0)
3290 return err;
3291 badness += err;
3292 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003293 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003294 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3295 cfg->speaker_pins,
3296 spec->multiout.extra_out_nid,
3297 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003298 if (err < 0)
3299 return err;
3300 badness += err;
3301 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003302 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3303 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003304 if (err < 0)
3305 return err;
3306 badness += err;
3307 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003308 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3309 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003310 int offset = 0;
3311 if (cfg->line_outs >= 3)
3312 offset = 1;
3313 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3314 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003315 if (err < 0)
3316 return err;
3317 badness += err;
3318 }
3319
3320 if (spec->multi_ios == 2) {
3321 for (i = 0; i < 2; i++)
3322 spec->private_dac_nids[spec->multiout.num_dacs++] =
3323 spec->multi_io[i].dac;
3324 spec->ext_channel_count = 2;
3325 } else if (spec->multi_ios) {
3326 spec->multi_ios = 0;
3327 badness += BAD_MULTI_IO;
3328 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003329
3330 return badness;
3331}
3332
3333#define DEBUG_BADNESS
3334
3335#ifdef DEBUG_BADNESS
3336#define debug_badness snd_printdd
3337#else
3338#define debug_badness(...)
3339#endif
3340
3341static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3342{
3343 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3344 cfg->line_out_pins[0], cfg->line_out_pins[1],
3345 cfg->line_out_pins[2], cfg->line_out_pins[2],
3346 spec->multiout.dac_nids[0],
3347 spec->multiout.dac_nids[1],
3348 spec->multiout.dac_nids[2],
3349 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003350 if (spec->multi_ios > 0)
3351 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3352 spec->multi_ios,
3353 spec->multi_io[0].pin, spec->multi_io[1].pin,
3354 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003355 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3356 cfg->hp_pins[0], cfg->hp_pins[1],
3357 cfg->hp_pins[2], cfg->hp_pins[2],
3358 spec->multiout.hp_out_nid[0],
3359 spec->multiout.hp_out_nid[1],
3360 spec->multiout.hp_out_nid[2],
3361 spec->multiout.hp_out_nid[3]);
3362 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3363 cfg->speaker_pins[0], cfg->speaker_pins[1],
3364 cfg->speaker_pins[2], cfg->speaker_pins[3],
3365 spec->multiout.extra_out_nid[0],
3366 spec->multiout.extra_out_nid[1],
3367 spec->multiout.extra_out_nid[2],
3368 spec->multiout.extra_out_nid[3]);
3369}
3370
Takashi Iwai463419d2012-12-05 14:17:37 +01003371/* find all available DACs of the codec */
3372static void alc_fill_all_nids(struct hda_codec *codec)
3373{
3374 struct alc_spec *spec = codec->spec;
3375 int i;
3376 hda_nid_t nid = codec->start_nid;
3377
3378 spec->num_all_dacs = 0;
3379 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3380 for (i = 0; i < codec->num_nodes; i++, nid++) {
3381 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3382 continue;
3383 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3384 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3385 break;
3386 }
3387 spec->all_dacs[spec->num_all_dacs++] = nid;
3388 }
3389}
3390
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003391static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3392{
3393 struct alc_spec *spec = codec->spec;
3394 struct auto_pin_cfg *cfg = &spec->autocfg;
3395 struct auto_pin_cfg *best_cfg;
3396 int best_badness = INT_MAX;
3397 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003398 bool fill_hardwired = true, fill_mio_first = true;
3399 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003400 bool hp_spk_swapped = false;
3401
Takashi Iwai463419d2012-12-05 14:17:37 +01003402 alc_fill_all_nids(codec);
3403
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003404 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3405 if (!best_cfg)
3406 return -ENOMEM;
3407 *best_cfg = *cfg;
3408
3409 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003410 badness = fill_and_eval_dacs(codec, fill_hardwired,
3411 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003412 if (badness < 0) {
3413 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003414 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003415 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003416 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3417 cfg->line_out_type, fill_hardwired, fill_mio_first,
3418 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003419 debug_show_configs(spec, cfg);
3420 if (badness < best_badness) {
3421 best_badness = badness;
3422 *best_cfg = *cfg;
3423 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003424 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003425 }
3426 if (!badness)
3427 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003428 fill_mio_first = !fill_mio_first;
3429 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003430 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003431 fill_hardwired = !fill_hardwired;
3432 if (!fill_hardwired)
3433 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003434 if (hp_spk_swapped)
3435 break;
3436 hp_spk_swapped = true;
3437 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003438 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3439 cfg->hp_outs = cfg->line_outs;
3440 memcpy(cfg->hp_pins, cfg->line_out_pins,
3441 sizeof(cfg->hp_pins));
3442 cfg->line_outs = cfg->speaker_outs;
3443 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3444 sizeof(cfg->speaker_pins));
3445 cfg->speaker_outs = 0;
3446 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3447 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003448 fill_hardwired = true;
3449 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003450 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003451 if (cfg->hp_outs > 0 &&
3452 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3453 cfg->speaker_outs = cfg->line_outs;
3454 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3455 sizeof(cfg->speaker_pins));
3456 cfg->line_outs = cfg->hp_outs;
3457 memcpy(cfg->line_out_pins, cfg->hp_pins,
3458 sizeof(cfg->hp_pins));
3459 cfg->hp_outs = 0;
3460 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3461 cfg->line_out_type = AUTO_PIN_HP_OUT;
3462 fill_hardwired = true;
3463 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003464 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003465 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003466 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003467
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003468 if (badness) {
3469 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003470 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003471 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003472 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3473 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003474 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003475
Takashi Iwaiba8111272012-12-06 18:06:23 +01003476 if (cfg->line_out_pins[0]) {
3477 struct nid_path *path = get_out_path(codec,
3478 cfg->line_out_pins[0],
3479 spec->multiout.dac_nids[0]);
3480 if (path)
3481 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3482 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003483
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003484 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003485 return 0;
3486}
3487
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003488/* replace the channels in the composed amp value with the given number */
3489static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3490{
3491 val &= ~(0x3U << 16);
3492 val |= chs << 16;
3493 return val;
3494}
3495
Takashi Iwai343a04b2011-07-06 14:28:39 +02003496static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003497 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003498 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003499 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003500{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003501 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003502 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003503 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003504 val = path->ctls[NID_PATH_VOL_CTL];
3505 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003506 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003507 val = amp_val_replace_channels(val, chs);
3508 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3509}
3510
3511/* return the channel bits suitable for the given path->ctls[] */
3512static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3513 int type)
3514{
3515 int chs = 1; /* mono (left only) */
3516 if (path) {
3517 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3518 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3519 chs = 3; /* stereo */
3520 }
3521 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003522}
3523
Takashi Iwaie29d3772011-11-14 17:13:23 +01003524static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3525 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003526 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003527{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003528 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3529 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003530}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003531
3532/* create a mute-switch for the given mixer widget;
3533 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3534 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003535static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003536 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003537 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003538 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003539{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003540 unsigned int val;
3541 int type = ALC_CTL_WIDGET_MUTE;
3542
3543 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003544 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003545 val = path->ctls[NID_PATH_MUTE_CTL];
3546 if (!val)
3547 return 0;
3548 val = amp_val_replace_channels(val, chs);
3549 if (get_amp_direction_(val) == HDA_INPUT) {
3550 hda_nid_t nid = get_amp_nid_(val);
3551 if (snd_hda_get_num_conns(codec, nid) > 1) {
3552 type = ALC_CTL_BIND_MUTE;
3553 val |= 2 << 19; /* FIXME: fixed two widgets, so far */
3554 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003555 }
3556 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003557}
3558
Takashi Iwaie29d3772011-11-14 17:13:23 +01003559static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003560 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003561{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003562 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3563 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003564}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003565
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003566static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003567 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003568{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003569 int i;
3570
3571 for (i = path->depth - 1; i >= 0; i--) {
3572 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3573 return path->path[i];
3574 if (i != path->depth - 1 && i != 0 &&
3575 nid_has_mute(codec, path->path[i], HDA_INPUT))
3576 return path->path[i];
3577 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003578 return 0;
3579}
3580
3581static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003582 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003583{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003584 int i;
3585
3586 for (i = path->depth - 1; i >= 0; i--) {
3587 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3588 return path->path[i];
3589 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003590 return 0;
3591}
3592
Takashi Iwai7085ec12009-10-02 09:03:58 +02003593/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003594static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003595 const struct auto_pin_cfg *cfg)
3596{
3597 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003598 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003599
Takashi Iwaice764ab2011-04-27 16:35:23 +02003600 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003601 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003602 noutputs += spec->multi_ios;
3603
3604 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003605 const char *name;
3606 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003607 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003608 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003609
3610 dac = spec->multiout.dac_nids[i];
3611 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003612 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003613 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003614 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003615 index = 0;
3616 name = channel_name[i];
3617 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003618 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003619 name = alc_get_line_out_pfx(spec, i, true, &index);
3620 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003621
Takashi Iwaiba8111272012-12-06 18:06:23 +01003622 path = get_out_path(codec, pin, dac);
3623 if (!path)
3624 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003625 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003626 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003627 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003628 if (err < 0)
3629 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003630 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003631 if (err < 0)
3632 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003633 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003634 if (err < 0)
3635 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003636 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003637 if (err < 0)
3638 return err;
3639 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003640 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003641 if (err < 0)
3642 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003643 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003644 if (err < 0)
3645 return err;
3646 }
3647 }
3648 return 0;
3649}
3650
Takashi Iwai343a04b2011-07-06 14:28:39 +02003651static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003652 hda_nid_t dac, const char *pfx,
3653 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003654{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003655 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003656 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003657
Takashi Iwaiba8111272012-12-06 18:06:23 +01003658 path = get_out_path(codec, pin, dac);
3659 if (!path)
3660 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003661 /* bind volume control will be created in the case of dac = 0 */
3662 if (dac) {
3663 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3664 if (err < 0)
3665 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003666 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003667 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003668 if (err < 0)
3669 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003670 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003671}
3672
Takashi Iwai23c09b02011-08-19 09:05:35 +02003673static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3674 unsigned int nums,
3675 struct hda_ctl_ops *ops)
3676{
3677 struct alc_spec *spec = codec->spec;
3678 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003679 ctlp = snd_array_new(&spec->bind_ctls);
3680 if (!ctlp)
3681 return NULL;
3682 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3683 *ctlp = ctl;
3684 if (ctl)
3685 ctl->ops = ops;
3686 return ctl;
3687}
3688
3689/* add playback controls for speaker and HP outputs */
3690static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3691 const hda_nid_t *pins,
3692 const hda_nid_t *dacs,
3693 const char *pfx)
3694{
3695 struct alc_spec *spec = codec->spec;
3696 struct hda_bind_ctls *ctl;
3697 char name[32];
3698 int i, n, err;
3699
3700 if (!num_pins || !pins[0])
3701 return 0;
3702
Takashi Iwai527e4d72011-10-27 16:33:27 +02003703 if (num_pins == 1) {
3704 hda_nid_t dac = *dacs;
3705 if (!dac)
3706 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003707 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003708 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003709
Takashi Iwai23c09b02011-08-19 09:05:35 +02003710 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003711 hda_nid_t dac;
3712 if (dacs[num_pins - 1])
3713 dac = dacs[i]; /* with individual volumes */
3714 else
3715 dac = 0;
3716 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3717 err = alc_auto_create_extra_out(codec, pins[i], dac,
3718 "Bass Speaker", 0);
3719 } else if (num_pins >= 3) {
3720 snprintf(name, sizeof(name), "%s %s",
3721 pfx, channel_name[i]);
3722 err = alc_auto_create_extra_out(codec, pins[i], dac,
3723 name, 0);
3724 } else {
3725 err = alc_auto_create_extra_out(codec, pins[i], dac,
3726 pfx, i);
3727 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003728 if (err < 0)
3729 return err;
3730 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003731 if (dacs[num_pins - 1])
3732 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003733
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003734 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003735 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3736 if (!ctl)
3737 return -ENOMEM;
3738 n = 0;
3739 for (i = 0; i < num_pins; i++) {
3740 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003741 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003742 if (!pins[i] || !dacs[i])
3743 continue;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003744 path = get_out_path(codec, pins[i], dacs[i]);
3745 if (!path)
3746 continue;
3747 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003748 if (vol)
3749 ctl->values[n++] =
3750 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3751 }
3752 if (n) {
3753 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3754 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3755 if (err < 0)
3756 return err;
3757 }
3758 return 0;
3759}
3760
Takashi Iwai343a04b2011-07-06 14:28:39 +02003761static int alc_auto_create_hp_out(struct hda_codec *codec)
3762{
3763 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003764 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3765 spec->autocfg.hp_pins,
3766 spec->multiout.hp_out_nid,
3767 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003768}
3769
3770static int alc_auto_create_speaker_out(struct hda_codec *codec)
3771{
3772 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003773 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3774 spec->autocfg.speaker_pins,
3775 spec->multiout.extra_out_nid,
3776 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003777}
3778
Takashi Iwai78e635c2012-12-10 17:07:16 +01003779/* is a volume or mute control already present? */
3780static bool __is_out_ctl_present(struct hda_codec *codec,
3781 struct nid_path *exclude_path,
3782 hda_nid_t nid, int dir, int types)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003783{
Takashi Iwai78e635c2012-12-10 17:07:16 +01003784 struct alc_spec *spec = codec->spec;
3785 int i, type;
3786
3787 for (i = 0; i < spec->out_path.used; i++) {
3788 struct nid_path *p = snd_array_elem(&spec->out_path, i);
3789 if (p == exclude_path || p->depth <= 0)
3790 continue;
3791 for (type = 0; type < 2; type++) {
3792 if (types & (1 << type)) {
3793 unsigned int val = p->ctls[type];
3794 if (get_amp_nid_(val) == nid &&
3795 get_amp_direction_(val) == dir)
3796 return true;
3797 }
3798 }
3799 }
3800 return false;
3801}
3802
3803#define is_out_ctl_present(codec, path, nid, dir) \
3804 __is_out_ctl_present(codec, path, nid, dir, 3) /* check both types */
3805#define is_out_vol_ctl_present(codec, nid, dir) \
3806 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_VOL_CTL)
3807#define is_out_mute_ctl_present(codec, nid, dir) \
3808 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_MUTE_CTL)
3809
3810static int get_default_amp_val(struct hda_codec *codec, hda_nid_t nid, int dir)
3811{
3812 unsigned int caps, offset;
3813 unsigned int val = 0;
3814
3815 caps = query_amp_caps(codec, nid, dir);
3816 if (caps & AC_AMPCAP_NUM_STEPS) {
3817 offset = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
3818 /* if a volume control is assigned, set the lowest level
3819 * as default; otherwise set to 0dB
3820 */
3821 if (is_out_vol_ctl_present(codec, nid, dir))
3822 val = 0;
3823 else
3824 val = offset;
3825 }
3826 if (caps & AC_AMPCAP_MUTE) {
3827 /* if a mute control is assigned, mute as default */
3828 if (is_out_mute_ctl_present(codec, nid, dir))
3829 val |= HDA_AMP_MUTE;
3830 }
3831 return val;
3832}
3833
3834/* configure the path from the given dac to the pin as the proper output */
3835static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3836 hda_nid_t pin, int pin_type,
3837 hda_nid_t dac, bool force)
3838{
3839 int i, val;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003840 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003841
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003842 alc_set_pin_output(codec, pin, pin_type);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003843 path = get_out_path(codec, pin, dac);
3844 if (!path)
3845 return;
Takashi Iwai43dea222011-11-06 11:25:34 +01003846
Takashi Iwai78e635c2012-12-10 17:07:16 +01003847 for (i = path->depth - 1; i >= 0; i--) {
3848 hda_nid_t nid = path->path[i];
3849 if (i > 0 && path->multi[i - 1])
3850 snd_hda_codec_write(codec, nid, 0,
3851 AC_VERB_SET_CONNECT_SEL,
3852 path->idx[i - 1]);
3853
3854 if (i != 0 && i != path->depth - 1 &&
3855 (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) &&
3856 (force || !is_out_ctl_present(codec, path, nid,
3857 HDA_INPUT))) {
3858 val = get_default_amp_val(codec, nid, HDA_INPUT);
3859 snd_hda_codec_write(codec, nid, 0,
3860 AC_VERB_SET_AMP_GAIN_MUTE,
3861 AMP_IN_UNMUTE(0) | val);
3862 snd_hda_codec_write(codec, nid, 0,
3863 AC_VERB_SET_AMP_GAIN_MUTE,
3864 AMP_IN_UNMUTE(1) | val);
3865 }
3866 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
3867 (force || !is_out_ctl_present(codec, path, nid,
3868 HDA_OUTPUT))) {
3869 val = get_default_amp_val(codec, nid, HDA_OUTPUT);
3870 snd_hda_codec_write(codec, nid, 0,
3871 AC_VERB_SET_AMP_GAIN_MUTE,
3872 AMP_OUT_UNMUTE | val);
3873 }
3874 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003875}
3876
Takashi Iwai343a04b2011-07-06 14:28:39 +02003877static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003878{
3879 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003880 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003881 int i;
3882
3883 for (i = 0; i <= HDA_SIDE; i++) {
3884 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3885 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003886 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai78e635c2012-12-10 17:07:16 +01003887 spec->multiout.dac_nids[i], true);
3888
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003889 }
3890}
3891
Takashi Iwai343a04b2011-07-06 14:28:39 +02003892static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003893{
3894 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003895 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003896 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003897
David Henningsson636030e2011-10-12 19:26:03 +02003898 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003899 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3900 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003901 pin = spec->autocfg.hp_pins[i];
3902 if (!pin)
3903 break;
3904 dac = spec->multiout.hp_out_nid[i];
3905 if (!dac) {
3906 if (i > 0 && spec->multiout.hp_out_nid[0])
3907 dac = spec->multiout.hp_out_nid[0];
3908 else
3909 dac = spec->multiout.dac_nids[0];
3910 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003911 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003912 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003913 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003914 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3915 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003916 pin = spec->autocfg.speaker_pins[i];
3917 if (!pin)
3918 break;
3919 dac = spec->multiout.extra_out_nid[i];
3920 if (!dac) {
3921 if (i > 0 && spec->multiout.extra_out_nid[0])
3922 dac = spec->multiout.extra_out_nid[0];
3923 else
3924 dac = spec->multiout.dac_nids[0];
3925 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003926 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003927 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003928}
3929
Takashi Iwai276dd702012-02-17 16:17:03 +01003930/* check whether the given pin can be a multi-io pin */
3931static bool can_be_multiio_pin(struct hda_codec *codec,
3932 unsigned int location, hda_nid_t nid)
3933{
3934 unsigned int defcfg, caps;
3935
3936 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3937 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3938 return false;
3939 if (location && get_defcfg_location(defcfg) != location)
3940 return false;
3941 caps = snd_hda_query_pin_caps(codec, nid);
3942 if (!(caps & AC_PINCAP_OUT))
3943 return false;
3944 return true;
3945}
3946
Takashi Iwaice764ab2011-04-27 16:35:23 +02003947/*
3948 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003949 *
3950 * When hardwired is set, try to fill ony hardwired pins, and returns
3951 * zero if any pins are filled, non-zero if nothing found.
3952 * When hardwired is off, try to fill possible input pins, and returns
3953 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003954 */
3955static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003956 hda_nid_t reference_pin,
3957 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003958{
3959 struct alc_spec *spec = codec->spec;
3960 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003961 int type, i, j, dacs, num_pins, old_pins;
3962 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3963 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003964 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003965
Takashi Iwai276dd702012-02-17 16:17:03 +01003966 old_pins = spec->multi_ios;
3967 if (old_pins >= 2)
3968 goto end_fill;
3969
3970 num_pins = 0;
3971 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3972 for (i = 0; i < cfg->num_inputs; i++) {
3973 if (cfg->inputs[i].type != type)
3974 continue;
3975 if (can_be_multiio_pin(codec, location,
3976 cfg->inputs[i].pin))
3977 num_pins++;
3978 }
3979 }
3980 if (num_pins < 2)
3981 goto end_fill;
3982
Takashi Iwai07b18f62011-11-10 15:42:54 +01003983 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003984 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3985 for (i = 0; i < cfg->num_inputs; i++) {
3986 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003987 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003988
Takashi Iwaice764ab2011-04-27 16:35:23 +02003989 if (cfg->inputs[i].type != type)
3990 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003991 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003992 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003993 for (j = 0; j < spec->multi_ios; j++) {
3994 if (nid == spec->multi_io[j].pin)
3995 break;
3996 }
3997 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003998 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003999
4000 if (offset && offset + spec->multi_ios < dacs) {
4001 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01004002 if (!alc_auto_is_dac_reachable(codec, nid, dac))
4003 dac = 0;
4004 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004005 if (hardwired)
4006 dac = get_dac_if_single(codec, nid);
4007 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01004008 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004009 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004010 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004011 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004012 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004013 if (!add_new_out_path(codec, nid, dac)) {
4014 badness++;
4015 continue;
4016 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004017 spec->multi_io[spec->multi_ios].pin = nid;
4018 spec->multi_io[spec->multi_ios].dac = dac;
4019 spec->multi_ios++;
4020 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004021 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004022 }
4023 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004024 end_fill:
4025 if (badness)
4026 badness = BAD_MULTI_IO;
4027 if (old_pins == spec->multi_ios) {
4028 if (hardwired)
4029 return 1; /* nothing found */
4030 else
4031 return badness; /* no badness if nothing found */
4032 }
4033 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004034 /* cancel newly assigned paths */
4035 spec->out_path.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004036 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004037 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004038 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004039
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004040 /* assign volume and mute controls */
4041 for (i = old_pins; i < spec->multi_ios; i++)
4042 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4043 spec->multi_io[i].dac);
4044
4045 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004046}
4047
4048static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4049 struct snd_ctl_elem_info *uinfo)
4050{
4051 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4052 struct alc_spec *spec = codec->spec;
4053
4054 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4055 uinfo->count = 1;
4056 uinfo->value.enumerated.items = spec->multi_ios + 1;
4057 if (uinfo->value.enumerated.item > spec->multi_ios)
4058 uinfo->value.enumerated.item = spec->multi_ios;
4059 sprintf(uinfo->value.enumerated.name, "%dch",
4060 (uinfo->value.enumerated.item + 1) * 2);
4061 return 0;
4062}
4063
4064static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4065 struct snd_ctl_elem_value *ucontrol)
4066{
4067 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4068 struct alc_spec *spec = codec->spec;
4069 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4070 return 0;
4071}
4072
4073static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4074{
4075 struct alc_spec *spec = codec->spec;
4076 hda_nid_t nid = spec->multi_io[idx].pin;
4077
4078 if (!spec->multi_io[idx].ctl_in)
4079 spec->multi_io[idx].ctl_in =
4080 snd_hda_codec_read(codec, nid, 0,
4081 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4082 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004083 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004084 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4085 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4086 HDA_AMP_MUTE, 0);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004087 alc_auto_set_output_and_unmute(codec, nid, PIN_OUT,
4088 spec->multi_io[idx].dac, false);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004089 } else {
4090 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4091 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4092 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004093 snd_hda_set_pin_ctl_cache(codec, nid,
4094 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004095 }
4096 return 0;
4097}
4098
4099static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4100 struct snd_ctl_elem_value *ucontrol)
4101{
4102 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4103 struct alc_spec *spec = codec->spec;
4104 int i, ch;
4105
4106 ch = ucontrol->value.enumerated.item[0];
4107 if (ch < 0 || ch > spec->multi_ios)
4108 return -EINVAL;
4109 if (ch == (spec->ext_channel_count - 1) / 2)
4110 return 0;
4111 spec->ext_channel_count = (ch + 1) * 2;
4112 for (i = 0; i < spec->multi_ios; i++)
4113 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004114 spec->multiout.max_channels = max(spec->ext_channel_count,
4115 spec->const_channel_count);
4116 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004117 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004118 return 1;
4119}
4120
Takashi Iwaia9111322011-05-02 11:30:18 +02004121static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004122 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4123 .name = "Channel Mode",
4124 .info = alc_auto_ch_mode_info,
4125 .get = alc_auto_ch_mode_get,
4126 .put = alc_auto_ch_mode_put,
4127};
4128
Takashi Iwai23c09b02011-08-19 09:05:35 +02004129static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004130{
4131 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004132
Takashi Iwaic2674682011-08-24 17:57:44 +02004133 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004134 if (!alc_kcontrol_new(spec, "Channel Mode",
4135 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004136 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004137 }
4138 return 0;
4139}
4140
Takashi Iwai1d045db2011-07-07 18:23:21 +02004141/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4142 * active input pins
4143 */
4144static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4145{
4146 struct alc_spec *spec = codec->spec;
4147 const struct hda_input_mux *imux;
4148 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4149 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4150 int i, n, nums;
4151
4152 imux = spec->input_mux;
4153 if (!imux)
4154 return;
4155 if (spec->dyn_adc_switch)
4156 return;
4157
Takashi Iwai26acaf02012-03-22 14:36:50 +01004158 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004159 nums = 0;
4160 for (n = 0; n < spec->num_adc_nids; n++) {
4161 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004162 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004163 for (i = 0; i < imux->num_items; i++) {
4164 hda_nid_t pin = spec->imux_pins[i];
4165 if (pin) {
4166 if (get_connection_index(codec, cap, pin) < 0)
4167 break;
4168 } else if (num_conns <= imux->items[i].index)
4169 break;
4170 }
4171 if (i >= imux->num_items) {
4172 adc_nids[nums] = spec->private_adc_nids[n];
4173 capsrc_nids[nums++] = cap;
4174 }
4175 }
4176 if (!nums) {
4177 /* check whether ADC-switch is possible */
4178 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004179 if (spec->shared_mic_hp) {
4180 spec->shared_mic_hp = 0;
4181 spec->private_imux[0].num_items = 1;
4182 goto again;
4183 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004184 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4185 " using fallback 0x%x\n",
4186 codec->chip_name, spec->private_adc_nids[0]);
4187 spec->num_adc_nids = 1;
4188 spec->auto_mic = 0;
4189 return;
4190 }
4191 } else if (nums != spec->num_adc_nids) {
4192 memcpy(spec->private_adc_nids, adc_nids,
4193 nums * sizeof(hda_nid_t));
4194 memcpy(spec->private_capsrc_nids, capsrc_nids,
4195 nums * sizeof(hda_nid_t));
4196 spec->num_adc_nids = nums;
4197 }
4198
4199 if (spec->auto_mic)
4200 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004201 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004202 spec->num_adc_nids = 1; /* reduce to a single ADC */
4203}
4204
4205/*
4206 * initialize ADC paths
4207 */
4208static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4209{
4210 struct alc_spec *spec = codec->spec;
4211 hda_nid_t nid;
4212
4213 nid = spec->adc_nids[adc_idx];
4214 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004215 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004216 snd_hda_codec_write(codec, nid, 0,
4217 AC_VERB_SET_AMP_GAIN_MUTE,
4218 AMP_IN_MUTE(0));
4219 return;
4220 }
4221 if (!spec->capsrc_nids)
4222 return;
4223 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004224 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004225 snd_hda_codec_write(codec, nid, 0,
4226 AC_VERB_SET_AMP_GAIN_MUTE,
4227 AMP_OUT_MUTE);
4228}
4229
4230static void alc_auto_init_input_src(struct hda_codec *codec)
4231{
4232 struct alc_spec *spec = codec->spec;
4233 int c, nums;
4234
4235 for (c = 0; c < spec->num_adc_nids; c++)
4236 alc_auto_init_adc(codec, c);
4237 if (spec->dyn_adc_switch)
4238 nums = 1;
4239 else
4240 nums = spec->num_adc_nids;
4241 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004242 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004243}
4244
4245/* add mic boosts if needed */
4246static int alc_auto_add_mic_boost(struct hda_codec *codec)
4247{
4248 struct alc_spec *spec = codec->spec;
4249 struct auto_pin_cfg *cfg = &spec->autocfg;
4250 int i, err;
4251 int type_idx = 0;
4252 hda_nid_t nid;
4253 const char *prev_label = NULL;
4254
4255 for (i = 0; i < cfg->num_inputs; i++) {
4256 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4257 break;
4258 nid = cfg->inputs[i].pin;
4259 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4260 const char *label;
4261 char boost_label[32];
4262
4263 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004264 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4265 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004266 if (prev_label && !strcmp(label, prev_label))
4267 type_idx++;
4268 else
4269 type_idx = 0;
4270 prev_label = label;
4271
4272 snprintf(boost_label, sizeof(boost_label),
4273 "%s Boost Volume", label);
4274 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4275 boost_label, type_idx,
4276 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4277 if (err < 0)
4278 return err;
4279 }
4280 }
4281 return 0;
4282}
4283
4284/* select or unmute the given capsrc route */
4285static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4286 int idx)
4287{
4288 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4289 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4290 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004291 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004292 snd_hda_codec_write_cache(codec, cap, 0,
4293 AC_VERB_SET_CONNECT_SEL, idx);
4294 }
4295}
4296
4297/* set the default connection to that pin */
4298static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4299{
4300 struct alc_spec *spec = codec->spec;
4301 int i;
4302
4303 if (!pin)
4304 return 0;
4305 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004306 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004307 int idx;
4308
4309 idx = get_connection_index(codec, cap, pin);
4310 if (idx < 0)
4311 continue;
4312 select_or_unmute_capsrc(codec, cap, idx);
4313 return i; /* return the found index */
4314 }
4315 return -1; /* not found */
4316}
4317
4318/* initialize some special cases for input sources */
4319static void alc_init_special_input_src(struct hda_codec *codec)
4320{
4321 struct alc_spec *spec = codec->spec;
4322 int i;
4323
4324 for (i = 0; i < spec->autocfg.num_inputs; i++)
4325 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4326}
4327
4328/* assign appropriate capture mixers */
4329static void set_capture_mixer(struct hda_codec *codec)
4330{
4331 struct alc_spec *spec = codec->spec;
4332 static const struct snd_kcontrol_new *caps[2][3] = {
4333 { alc_capture_mixer_nosrc1,
4334 alc_capture_mixer_nosrc2,
4335 alc_capture_mixer_nosrc3 },
4336 { alc_capture_mixer1,
4337 alc_capture_mixer2,
4338 alc_capture_mixer3 },
4339 };
4340
4341 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004342 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004343 if (!spec->capsrc_nids)
4344 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004345 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004346 return; /* no volume in capsrc, too */
4347 spec->vol_in_capsrc = 1;
4348 }
4349
4350 if (spec->num_adc_nids > 0) {
4351 int mux = 0;
4352 int num_adcs = 0;
4353
4354 if (spec->input_mux && spec->input_mux->num_items > 1)
4355 mux = 1;
4356 if (spec->auto_mic) {
4357 num_adcs = 1;
4358 mux = 0;
4359 } else if (spec->dyn_adc_switch)
4360 num_adcs = 1;
4361 if (!num_adcs) {
4362 if (spec->num_adc_nids > 3)
4363 spec->num_adc_nids = 3;
4364 else if (!spec->num_adc_nids)
4365 return;
4366 num_adcs = spec->num_adc_nids;
4367 }
4368 spec->cap_mixer = caps[mux][num_adcs - 1];
4369 }
4370}
4371
4372/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004373 * standard auto-parser initializations
4374 */
4375static void alc_auto_init_std(struct hda_codec *codec)
4376{
Takashi Iwaie4770622011-07-08 11:11:35 +02004377 alc_auto_init_multi_out(codec);
4378 alc_auto_init_extra_out(codec);
4379 alc_auto_init_analog_input(codec);
4380 alc_auto_init_input_src(codec);
4381 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004382 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004383}
4384
4385/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004386 * Digital-beep handlers
4387 */
4388#ifdef CONFIG_SND_HDA_INPUT_BEEP
4389#define set_beep_amp(spec, nid, idx, dir) \
4390 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4391
4392static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004393 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004394 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4395 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4396 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4397 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004398 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004399 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4400 {}
4401};
4402
4403static inline int has_cdefine_beep(struct hda_codec *codec)
4404{
4405 struct alc_spec *spec = codec->spec;
4406 const struct snd_pci_quirk *q;
4407 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4408 if (q)
4409 return q->value;
4410 return spec->cdefine.enable_pcbeep;
4411}
4412#else
4413#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4414#define has_cdefine_beep(codec) 0
4415#endif
4416
4417/* parse the BIOS configuration and set up the alc_spec */
4418/* return 1 if successful, 0 if the proper config is not found,
4419 * or a negative error code
4420 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004421static int alc_parse_auto_config(struct hda_codec *codec,
4422 const hda_nid_t *ignore_nids,
4423 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004424{
4425 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004426 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004427 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004428
Takashi Iwai53c334a2011-08-23 18:27:14 +02004429 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4430 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004431 if (err < 0)
4432 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004433 if (!cfg->line_outs) {
4434 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004435 spec->multiout.max_channels = 2;
4436 spec->no_analog = 1;
4437 goto dig_only;
4438 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004439 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004440 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004441
Takashi Iwaie427c232012-07-29 10:04:08 +02004442 if (!spec->no_primary_hp &&
4443 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004444 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004445 /* use HP as primary out */
4446 cfg->speaker_outs = cfg->line_outs;
4447 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4448 sizeof(cfg->speaker_pins));
4449 cfg->line_outs = cfg->hp_outs;
4450 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4451 cfg->hp_outs = 0;
4452 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4453 cfg->line_out_type = AUTO_PIN_HP_OUT;
4454 }
4455
Takashi Iwai1d045db2011-07-07 18:23:21 +02004456 err = alc_auto_fill_dac_nids(codec);
4457 if (err < 0)
4458 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004459 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004460 if (err < 0)
4461 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004462 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004463 if (err < 0)
4464 return err;
4465 err = alc_auto_create_hp_out(codec);
4466 if (err < 0)
4467 return err;
4468 err = alc_auto_create_speaker_out(codec);
4469 if (err < 0)
4470 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004471 err = alc_auto_create_shared_input(codec);
4472 if (err < 0)
4473 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004474 err = alc_auto_create_input_ctls(codec);
4475 if (err < 0)
4476 return err;
4477
Takashi Iwaib6adb572012-12-03 10:30:58 +01004478 /* check the multiple speaker pins */
4479 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4480 spec->const_channel_count = cfg->line_outs * 2;
4481 else
4482 spec->const_channel_count = cfg->speaker_outs * 2;
4483
4484 if (spec->multi_ios > 0)
4485 spec->multiout.max_channels = max(spec->ext_channel_count,
4486 spec->const_channel_count);
4487 else
4488 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004489
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004490 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004491 alc_auto_parse_digital(codec);
4492
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004493 if (!spec->no_analog)
4494 alc_remove_invalid_adc_nids(codec);
4495
4496 if (ssid_nids)
4497 alc_ssid_check(codec, ssid_nids);
4498
4499 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004500 err = alc_auto_check_switches(codec);
4501 if (err < 0)
4502 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004503 err = alc_auto_add_mic_boost(codec);
4504 if (err < 0)
4505 return err;
4506 }
4507
Takashi Iwai1d045db2011-07-07 18:23:21 +02004508 if (spec->kctls.list)
4509 add_mixer(spec, spec->kctls.list);
4510
Takashi Iwai070cff42012-02-21 12:54:17 +01004511 if (!spec->no_analog && !spec->cap_mixer)
4512 set_capture_mixer(codec);
4513
Takashi Iwai1d045db2011-07-07 18:23:21 +02004514 return 1;
4515}
4516
Takashi Iwai3de95172012-05-07 18:03:15 +02004517/* common preparation job for alc_spec */
4518static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4519{
4520 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4521 int err;
4522
4523 if (!spec)
4524 return -ENOMEM;
4525 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004526 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004527 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004528 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004529 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4530 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004531 snd_array_init(&spec->out_path, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004532
4533 err = alc_codec_rename_from_preset(codec);
4534 if (err < 0) {
4535 kfree(spec);
4536 return err;
4537 }
4538 return 0;
4539}
4540
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004541static int alc880_parse_auto_config(struct hda_codec *codec)
4542{
4543 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004544 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004545 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4546}
4547
Takashi Iwai1d045db2011-07-07 18:23:21 +02004548/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004549 * ALC880 fix-ups
4550 */
4551enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004552 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004553 ALC880_FIXUP_GPIO2,
4554 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004555 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004556 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004557 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004558 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004559 ALC880_FIXUP_VOL_KNOB,
4560 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004561 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004562 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004563 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004564 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004565 ALC880_FIXUP_3ST_BASE,
4566 ALC880_FIXUP_3ST,
4567 ALC880_FIXUP_3ST_DIG,
4568 ALC880_FIXUP_5ST_BASE,
4569 ALC880_FIXUP_5ST,
4570 ALC880_FIXUP_5ST_DIG,
4571 ALC880_FIXUP_6ST_BASE,
4572 ALC880_FIXUP_6ST,
4573 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004574};
4575
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004576/* enable the volume-knob widget support on NID 0x21 */
4577static void alc880_fixup_vol_knob(struct hda_codec *codec,
4578 const struct alc_fixup *fix, int action)
4579{
4580 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004581 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004582}
4583
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004584static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004585 [ALC880_FIXUP_GPIO1] = {
4586 .type = ALC_FIXUP_VERBS,
4587 .v.verbs = alc_gpio1_init_verbs,
4588 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004589 [ALC880_FIXUP_GPIO2] = {
4590 .type = ALC_FIXUP_VERBS,
4591 .v.verbs = alc_gpio2_init_verbs,
4592 },
4593 [ALC880_FIXUP_MEDION_RIM] = {
4594 .type = ALC_FIXUP_VERBS,
4595 .v.verbs = (const struct hda_verb[]) {
4596 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4597 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4598 { }
4599 },
4600 .chained = true,
4601 .chain_id = ALC880_FIXUP_GPIO2,
4602 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004603 [ALC880_FIXUP_LG] = {
4604 .type = ALC_FIXUP_PINS,
4605 .v.pins = (const struct alc_pincfg[]) {
4606 /* disable bogus unused pins */
4607 { 0x16, 0x411111f0 },
4608 { 0x18, 0x411111f0 },
4609 { 0x1a, 0x411111f0 },
4610 { }
4611 }
4612 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004613 [ALC880_FIXUP_W810] = {
4614 .type = ALC_FIXUP_PINS,
4615 .v.pins = (const struct alc_pincfg[]) {
4616 /* disable bogus unused pins */
4617 { 0x17, 0x411111f0 },
4618 { }
4619 },
4620 .chained = true,
4621 .chain_id = ALC880_FIXUP_GPIO2,
4622 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004623 [ALC880_FIXUP_EAPD_COEF] = {
4624 .type = ALC_FIXUP_VERBS,
4625 .v.verbs = (const struct hda_verb[]) {
4626 /* change to EAPD mode */
4627 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4628 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4629 {}
4630 },
4631 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004632 [ALC880_FIXUP_TCL_S700] = {
4633 .type = ALC_FIXUP_VERBS,
4634 .v.verbs = (const struct hda_verb[]) {
4635 /* change to EAPD mode */
4636 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4637 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4638 {}
4639 },
4640 .chained = true,
4641 .chain_id = ALC880_FIXUP_GPIO2,
4642 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004643 [ALC880_FIXUP_VOL_KNOB] = {
4644 .type = ALC_FIXUP_FUNC,
4645 .v.func = alc880_fixup_vol_knob,
4646 },
4647 [ALC880_FIXUP_FUJITSU] = {
4648 /* override all pins as BIOS on old Amilo is broken */
4649 .type = ALC_FIXUP_PINS,
4650 .v.pins = (const struct alc_pincfg[]) {
4651 { 0x14, 0x0121411f }, /* HP */
4652 { 0x15, 0x99030120 }, /* speaker */
4653 { 0x16, 0x99030130 }, /* bass speaker */
4654 { 0x17, 0x411111f0 }, /* N/A */
4655 { 0x18, 0x411111f0 }, /* N/A */
4656 { 0x19, 0x01a19950 }, /* mic-in */
4657 { 0x1a, 0x411111f0 }, /* N/A */
4658 { 0x1b, 0x411111f0 }, /* N/A */
4659 { 0x1c, 0x411111f0 }, /* N/A */
4660 { 0x1d, 0x411111f0 }, /* N/A */
4661 { 0x1e, 0x01454140 }, /* SPDIF out */
4662 { }
4663 },
4664 .chained = true,
4665 .chain_id = ALC880_FIXUP_VOL_KNOB,
4666 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004667 [ALC880_FIXUP_F1734] = {
4668 /* almost compatible with FUJITSU, but no bass and SPDIF */
4669 .type = ALC_FIXUP_PINS,
4670 .v.pins = (const struct alc_pincfg[]) {
4671 { 0x14, 0x0121411f }, /* HP */
4672 { 0x15, 0x99030120 }, /* speaker */
4673 { 0x16, 0x411111f0 }, /* N/A */
4674 { 0x17, 0x411111f0 }, /* N/A */
4675 { 0x18, 0x411111f0 }, /* N/A */
4676 { 0x19, 0x01a19950 }, /* mic-in */
4677 { 0x1a, 0x411111f0 }, /* N/A */
4678 { 0x1b, 0x411111f0 }, /* N/A */
4679 { 0x1c, 0x411111f0 }, /* N/A */
4680 { 0x1d, 0x411111f0 }, /* N/A */
4681 { 0x1e, 0x411111f0 }, /* N/A */
4682 { }
4683 },
4684 .chained = true,
4685 .chain_id = ALC880_FIXUP_VOL_KNOB,
4686 },
Takashi Iwai817de922012-02-20 17:20:48 +01004687 [ALC880_FIXUP_UNIWILL] = {
4688 /* need to fix HP and speaker pins to be parsed correctly */
4689 .type = ALC_FIXUP_PINS,
4690 .v.pins = (const struct alc_pincfg[]) {
4691 { 0x14, 0x0121411f }, /* HP */
4692 { 0x15, 0x99030120 }, /* speaker */
4693 { 0x16, 0x99030130 }, /* bass speaker */
4694 { }
4695 },
4696 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004697 [ALC880_FIXUP_UNIWILL_DIG] = {
4698 .type = ALC_FIXUP_PINS,
4699 .v.pins = (const struct alc_pincfg[]) {
4700 /* disable bogus unused pins */
4701 { 0x17, 0x411111f0 },
4702 { 0x19, 0x411111f0 },
4703 { 0x1b, 0x411111f0 },
4704 { 0x1f, 0x411111f0 },
4705 { }
4706 }
4707 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004708 [ALC880_FIXUP_Z71V] = {
4709 .type = ALC_FIXUP_PINS,
4710 .v.pins = (const struct alc_pincfg[]) {
4711 /* set up the whole pins as BIOS is utterly broken */
4712 { 0x14, 0x99030120 }, /* speaker */
4713 { 0x15, 0x0121411f }, /* HP */
4714 { 0x16, 0x411111f0 }, /* N/A */
4715 { 0x17, 0x411111f0 }, /* N/A */
4716 { 0x18, 0x01a19950 }, /* mic-in */
4717 { 0x19, 0x411111f0 }, /* N/A */
4718 { 0x1a, 0x01813031 }, /* line-in */
4719 { 0x1b, 0x411111f0 }, /* N/A */
4720 { 0x1c, 0x411111f0 }, /* N/A */
4721 { 0x1d, 0x411111f0 }, /* N/A */
4722 { 0x1e, 0x0144111e }, /* SPDIF */
4723 { }
4724 }
4725 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004726 [ALC880_FIXUP_3ST_BASE] = {
4727 .type = ALC_FIXUP_PINS,
4728 .v.pins = (const struct alc_pincfg[]) {
4729 { 0x14, 0x01014010 }, /* line-out */
4730 { 0x15, 0x411111f0 }, /* N/A */
4731 { 0x16, 0x411111f0 }, /* N/A */
4732 { 0x17, 0x411111f0 }, /* N/A */
4733 { 0x18, 0x01a19c30 }, /* mic-in */
4734 { 0x19, 0x0121411f }, /* HP */
4735 { 0x1a, 0x01813031 }, /* line-in */
4736 { 0x1b, 0x02a19c40 }, /* front-mic */
4737 { 0x1c, 0x411111f0 }, /* N/A */
4738 { 0x1d, 0x411111f0 }, /* N/A */
4739 /* 0x1e is filled in below */
4740 { 0x1f, 0x411111f0 }, /* N/A */
4741 { }
4742 }
4743 },
4744 [ALC880_FIXUP_3ST] = {
4745 .type = ALC_FIXUP_PINS,
4746 .v.pins = (const struct alc_pincfg[]) {
4747 { 0x1e, 0x411111f0 }, /* N/A */
4748 { }
4749 },
4750 .chained = true,
4751 .chain_id = ALC880_FIXUP_3ST_BASE,
4752 },
4753 [ALC880_FIXUP_3ST_DIG] = {
4754 .type = ALC_FIXUP_PINS,
4755 .v.pins = (const struct alc_pincfg[]) {
4756 { 0x1e, 0x0144111e }, /* SPDIF */
4757 { }
4758 },
4759 .chained = true,
4760 .chain_id = ALC880_FIXUP_3ST_BASE,
4761 },
4762 [ALC880_FIXUP_5ST_BASE] = {
4763 .type = ALC_FIXUP_PINS,
4764 .v.pins = (const struct alc_pincfg[]) {
4765 { 0x14, 0x01014010 }, /* front */
4766 { 0x15, 0x411111f0 }, /* N/A */
4767 { 0x16, 0x01011411 }, /* CLFE */
4768 { 0x17, 0x01016412 }, /* surr */
4769 { 0x18, 0x01a19c30 }, /* mic-in */
4770 { 0x19, 0x0121411f }, /* HP */
4771 { 0x1a, 0x01813031 }, /* line-in */
4772 { 0x1b, 0x02a19c40 }, /* front-mic */
4773 { 0x1c, 0x411111f0 }, /* N/A */
4774 { 0x1d, 0x411111f0 }, /* N/A */
4775 /* 0x1e is filled in below */
4776 { 0x1f, 0x411111f0 }, /* N/A */
4777 { }
4778 }
4779 },
4780 [ALC880_FIXUP_5ST] = {
4781 .type = ALC_FIXUP_PINS,
4782 .v.pins = (const struct alc_pincfg[]) {
4783 { 0x1e, 0x411111f0 }, /* N/A */
4784 { }
4785 },
4786 .chained = true,
4787 .chain_id = ALC880_FIXUP_5ST_BASE,
4788 },
4789 [ALC880_FIXUP_5ST_DIG] = {
4790 .type = ALC_FIXUP_PINS,
4791 .v.pins = (const struct alc_pincfg[]) {
4792 { 0x1e, 0x0144111e }, /* SPDIF */
4793 { }
4794 },
4795 .chained = true,
4796 .chain_id = ALC880_FIXUP_5ST_BASE,
4797 },
4798 [ALC880_FIXUP_6ST_BASE] = {
4799 .type = ALC_FIXUP_PINS,
4800 .v.pins = (const struct alc_pincfg[]) {
4801 { 0x14, 0x01014010 }, /* front */
4802 { 0x15, 0x01016412 }, /* surr */
4803 { 0x16, 0x01011411 }, /* CLFE */
4804 { 0x17, 0x01012414 }, /* side */
4805 { 0x18, 0x01a19c30 }, /* mic-in */
4806 { 0x19, 0x02a19c40 }, /* front-mic */
4807 { 0x1a, 0x01813031 }, /* line-in */
4808 { 0x1b, 0x0121411f }, /* HP */
4809 { 0x1c, 0x411111f0 }, /* N/A */
4810 { 0x1d, 0x411111f0 }, /* N/A */
4811 /* 0x1e is filled in below */
4812 { 0x1f, 0x411111f0 }, /* N/A */
4813 { }
4814 }
4815 },
4816 [ALC880_FIXUP_6ST] = {
4817 .type = ALC_FIXUP_PINS,
4818 .v.pins = (const struct alc_pincfg[]) {
4819 { 0x1e, 0x411111f0 }, /* N/A */
4820 { }
4821 },
4822 .chained = true,
4823 .chain_id = ALC880_FIXUP_6ST_BASE,
4824 },
4825 [ALC880_FIXUP_6ST_DIG] = {
4826 .type = ALC_FIXUP_PINS,
4827 .v.pins = (const struct alc_pincfg[]) {
4828 { 0x1e, 0x0144111e }, /* SPDIF */
4829 { }
4830 },
4831 .chained = true,
4832 .chain_id = ALC880_FIXUP_6ST_BASE,
4833 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004834};
4835
4836static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004837 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004838 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004839 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4840 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004841 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004842 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004843 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004844 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004845 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004846 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004847 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004848 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004849 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004850 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004851 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004852 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4853 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4854 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004855 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004856
4857 /* Below is the copied entries from alc880_quirks.c.
4858 * It's not quite sure whether BIOS sets the correct pin-config table
4859 * on these machines, thus they are kept to be compatible with
4860 * the old static quirks. Once when it's confirmed to work without
4861 * these overrides, it'd be better to remove.
4862 */
4863 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4864 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4865 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4866 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4867 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4868 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4869 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4870 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4871 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4872 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4873 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4874 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4875 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4876 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4877 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4878 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4879 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4880 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4881 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4882 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4883 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4884 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4885 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4886 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4887 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4888 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4889 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4890 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4891 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4892 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4893 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4894 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4895 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4896 /* default Intel */
4897 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4898 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4899 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4900 {}
4901};
4902
4903static const struct alc_model_fixup alc880_fixup_models[] = {
4904 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4905 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4906 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4907 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4908 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4909 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004910 {}
4911};
4912
4913
4914/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004915 * OK, here we have finally the patch for ALC880
4916 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004917static int patch_alc880(struct hda_codec *codec)
4918{
4919 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004920 int err;
4921
Takashi Iwai3de95172012-05-07 18:03:15 +02004922 err = alc_alloc_spec(codec, 0x0b);
4923 if (err < 0)
4924 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004925
Takashi Iwai3de95172012-05-07 18:03:15 +02004926 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004927 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004928
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004929 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4930 alc880_fixups);
4931 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004932
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004933 /* automatic parse from the BIOS config */
4934 err = alc880_parse_auto_config(codec);
4935 if (err < 0)
4936 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004937
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004938 if (!spec->no_analog) {
4939 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004940 if (err < 0)
4941 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004942 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4943 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004944
Takashi Iwai1d045db2011-07-07 18:23:21 +02004945 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004946 codec->patch_ops.unsol_event = alc880_unsol_event;
4947
Takashi Iwai1d045db2011-07-07 18:23:21 +02004948
Takashi Iwai589876e2012-02-20 15:47:55 +01004949 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4950
Takashi Iwai1d045db2011-07-07 18:23:21 +02004951 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004952
4953 error:
4954 alc_free(codec);
4955 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004956}
4957
4958
4959/*
4960 * ALC260 support
4961 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004962static int alc260_parse_auto_config(struct hda_codec *codec)
4963{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004964 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004965 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4966 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004967}
4968
Takashi Iwai1d045db2011-07-07 18:23:21 +02004969/*
4970 * Pin config fixes
4971 */
4972enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004973 ALC260_FIXUP_HP_DC5750,
4974 ALC260_FIXUP_HP_PIN_0F,
4975 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004976 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004977 ALC260_FIXUP_GPIO1_TOGGLE,
4978 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004979 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004980 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004981};
4982
Takashi Iwai20f7d922012-02-16 12:35:16 +01004983static void alc260_gpio1_automute(struct hda_codec *codec)
4984{
4985 struct alc_spec *spec = codec->spec;
4986 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4987 spec->hp_jack_present);
4988}
4989
4990static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4991 const struct alc_fixup *fix, int action)
4992{
4993 struct alc_spec *spec = codec->spec;
4994 if (action == ALC_FIXUP_ACT_PROBE) {
4995 /* although the machine has only one output pin, we need to
4996 * toggle GPIO1 according to the jack state
4997 */
4998 spec->automute_hook = alc260_gpio1_automute;
4999 spec->detect_hp = 1;
5000 spec->automute_speaker = 1;
5001 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005002 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5003 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005004 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005005 }
5006}
5007
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005008static void alc260_fixup_kn1(struct hda_codec *codec,
5009 const struct alc_fixup *fix, int action)
5010{
5011 struct alc_spec *spec = codec->spec;
5012 static const struct alc_pincfg pincfgs[] = {
5013 { 0x0f, 0x02214000 }, /* HP/speaker */
5014 { 0x12, 0x90a60160 }, /* int mic */
5015 { 0x13, 0x02a19000 }, /* ext mic */
5016 { 0x18, 0x01446000 }, /* SPDIF out */
5017 /* disable bogus I/O pins */
5018 { 0x10, 0x411111f0 },
5019 { 0x11, 0x411111f0 },
5020 { 0x14, 0x411111f0 },
5021 { 0x15, 0x411111f0 },
5022 { 0x16, 0x411111f0 },
5023 { 0x17, 0x411111f0 },
5024 { 0x19, 0x411111f0 },
5025 { }
5026 };
5027
5028 switch (action) {
5029 case ALC_FIXUP_ACT_PRE_PROBE:
5030 alc_apply_pincfgs(codec, pincfgs);
5031 break;
5032 case ALC_FIXUP_ACT_PROBE:
5033 spec->init_amp = ALC_INIT_NONE;
5034 break;
5035 }
5036}
5037
Takashi Iwai1d045db2011-07-07 18:23:21 +02005038static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005039 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005040 .type = ALC_FIXUP_PINS,
5041 .v.pins = (const struct alc_pincfg[]) {
5042 { 0x11, 0x90130110 }, /* speaker */
5043 { }
5044 }
5045 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005046 [ALC260_FIXUP_HP_PIN_0F] = {
5047 .type = ALC_FIXUP_PINS,
5048 .v.pins = (const struct alc_pincfg[]) {
5049 { 0x0f, 0x01214000 }, /* HP */
5050 { }
5051 }
5052 },
5053 [ALC260_FIXUP_COEF] = {
5054 .type = ALC_FIXUP_VERBS,
5055 .v.verbs = (const struct hda_verb[]) {
5056 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5057 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5058 { }
5059 },
5060 .chained = true,
5061 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5062 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005063 [ALC260_FIXUP_GPIO1] = {
5064 .type = ALC_FIXUP_VERBS,
5065 .v.verbs = alc_gpio1_init_verbs,
5066 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005067 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5068 .type = ALC_FIXUP_FUNC,
5069 .v.func = alc260_fixup_gpio1_toggle,
5070 .chained = true,
5071 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5072 },
5073 [ALC260_FIXUP_REPLACER] = {
5074 .type = ALC_FIXUP_VERBS,
5075 .v.verbs = (const struct hda_verb[]) {
5076 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5077 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5078 { }
5079 },
5080 .chained = true,
5081 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5082 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005083 [ALC260_FIXUP_HP_B1900] = {
5084 .type = ALC_FIXUP_FUNC,
5085 .v.func = alc260_fixup_gpio1_toggle,
5086 .chained = true,
5087 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005088 },
5089 [ALC260_FIXUP_KN1] = {
5090 .type = ALC_FIXUP_FUNC,
5091 .v.func = alc260_fixup_kn1,
5092 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005093};
5094
5095static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005096 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005097 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005098 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005099 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005100 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005101 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005102 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005103 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005104 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005105 {}
5106};
5107
5108/*
5109 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005110static int patch_alc260(struct hda_codec *codec)
5111{
5112 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005113 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005114
Takashi Iwai3de95172012-05-07 18:03:15 +02005115 err = alc_alloc_spec(codec, 0x07);
5116 if (err < 0)
5117 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005118
Takashi Iwai3de95172012-05-07 18:03:15 +02005119 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005120
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005121 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5122 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005123
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005124 /* automatic parse from the BIOS config */
5125 err = alc260_parse_auto_config(codec);
5126 if (err < 0)
5127 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005128
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005129 if (!spec->no_analog) {
5130 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005131 if (err < 0)
5132 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005133 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5134 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005135
Takashi Iwai1d045db2011-07-07 18:23:21 +02005136 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005137 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005138
Takashi Iwai589876e2012-02-20 15:47:55 +01005139 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5140
Takashi Iwai1d045db2011-07-07 18:23:21 +02005141 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005142
5143 error:
5144 alc_free(codec);
5145 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005146}
5147
5148
5149/*
5150 * ALC882/883/885/888/889 support
5151 *
5152 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5153 * configuration. Each pin widget can choose any input DACs and a mixer.
5154 * Each ADC is connected from a mixer of all inputs. This makes possible
5155 * 6-channel independent captures.
5156 *
5157 * In addition, an independent DAC for the multi-playback (not used in this
5158 * driver yet).
5159 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005160
5161/*
5162 * Pin config fixes
5163 */
5164enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005165 ALC882_FIXUP_ABIT_AW9D_MAX,
5166 ALC882_FIXUP_LENOVO_Y530,
5167 ALC882_FIXUP_PB_M5210,
5168 ALC882_FIXUP_ACER_ASPIRE_7736,
5169 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005170 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005171 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005172 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005173 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005174 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005175 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005176 ALC882_FIXUP_GPIO1,
5177 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005178 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005179 ALC889_FIXUP_COEF,
5180 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005181 ALC882_FIXUP_ACER_ASPIRE_4930G,
5182 ALC882_FIXUP_ACER_ASPIRE_8930G,
5183 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005184 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005185 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005186 ALC889_FIXUP_MBP_VREF,
5187 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005188 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005189 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005190};
5191
Takashi Iwai68ef0562011-11-09 18:24:44 +01005192static void alc889_fixup_coef(struct hda_codec *codec,
5193 const struct alc_fixup *fix, int action)
5194{
5195 if (action != ALC_FIXUP_ACT_INIT)
5196 return;
5197 alc889_coef_init(codec);
5198}
5199
Takashi Iwai56710872011-11-14 17:42:11 +01005200/* toggle speaker-output according to the hp-jack state */
5201static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5202{
5203 unsigned int gpiostate, gpiomask, gpiodir;
5204
5205 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5206 AC_VERB_GET_GPIO_DATA, 0);
5207
5208 if (!muted)
5209 gpiostate |= (1 << pin);
5210 else
5211 gpiostate &= ~(1 << pin);
5212
5213 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5214 AC_VERB_GET_GPIO_MASK, 0);
5215 gpiomask |= (1 << pin);
5216
5217 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5218 AC_VERB_GET_GPIO_DIRECTION, 0);
5219 gpiodir |= (1 << pin);
5220
5221
5222 snd_hda_codec_write(codec, codec->afg, 0,
5223 AC_VERB_SET_GPIO_MASK, gpiomask);
5224 snd_hda_codec_write(codec, codec->afg, 0,
5225 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5226
5227 msleep(1);
5228
5229 snd_hda_codec_write(codec, codec->afg, 0,
5230 AC_VERB_SET_GPIO_DATA, gpiostate);
5231}
5232
5233/* set up GPIO at initialization */
5234static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5235 const struct alc_fixup *fix, int action)
5236{
5237 if (action != ALC_FIXUP_ACT_INIT)
5238 return;
5239 alc882_gpio_mute(codec, 0, 0);
5240 alc882_gpio_mute(codec, 1, 0);
5241}
5242
Takashi Iwai02a237b2012-02-13 15:25:07 +01005243/* Fix the connection of some pins for ALC889:
5244 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5245 * work correctly (bko#42740)
5246 */
5247static void alc889_fixup_dac_route(struct hda_codec *codec,
5248 const struct alc_fixup *fix, int action)
5249{
5250 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005251 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005252 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5253 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5254 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5255 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5256 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5257 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005258 } else if (action == ALC_FIXUP_ACT_PROBE) {
5259 /* restore the connections */
5260 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5261 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5262 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5263 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5264 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005265 }
5266}
5267
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005268/* Set VREF on HP pin */
5269static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5270 const struct alc_fixup *fix, int action)
5271{
5272 struct alc_spec *spec = codec->spec;
5273 static hda_nid_t nids[2] = { 0x14, 0x15 };
5274 int i;
5275
5276 if (action != ALC_FIXUP_ACT_INIT)
5277 return;
5278 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5279 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5280 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5281 continue;
5282 val = snd_hda_codec_read(codec, nids[i], 0,
5283 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5284 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005285 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005286 spec->keep_vref_in_automute = 1;
5287 break;
5288 }
5289}
5290
5291/* Set VREF on speaker pins on imac91 */
5292static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5293 const struct alc_fixup *fix, int action)
5294{
5295 struct alc_spec *spec = codec->spec;
5296 static hda_nid_t nids[2] = { 0x18, 0x1a };
5297 int i;
5298
5299 if (action != ALC_FIXUP_ACT_INIT)
5300 return;
5301 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5302 unsigned int val;
5303 val = snd_hda_codec_read(codec, nids[i], 0,
5304 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5305 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005306 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005307 }
5308 spec->keep_vref_in_automute = 1;
5309}
5310
Takashi Iwaie427c232012-07-29 10:04:08 +02005311/* Don't take HP output as primary
5312 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5313 */
5314static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5315 const struct alc_fixup *fix, int action)
5316{
5317 struct alc_spec *spec = codec->spec;
5318 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5319 spec->no_primary_hp = 1;
5320}
5321
Takashi Iwai1d045db2011-07-07 18:23:21 +02005322static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005323 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005324 .type = ALC_FIXUP_PINS,
5325 .v.pins = (const struct alc_pincfg[]) {
5326 { 0x15, 0x01080104 }, /* side */
5327 { 0x16, 0x01011012 }, /* rear */
5328 { 0x17, 0x01016011 }, /* clfe */
5329 { }
5330 }
5331 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005332 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005333 .type = ALC_FIXUP_PINS,
5334 .v.pins = (const struct alc_pincfg[]) {
5335 { 0x15, 0x99130112 }, /* rear int speakers */
5336 { 0x16, 0x99130111 }, /* subwoofer */
5337 { }
5338 }
5339 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005340 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005341 .type = ALC_FIXUP_VERBS,
5342 .v.verbs = (const struct hda_verb[]) {
5343 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5344 {}
5345 }
5346 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005347 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005348 .type = ALC_FIXUP_FUNC,
5349 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005350 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005351 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005352 .type = ALC_FIXUP_PINS,
5353 .v.pins = (const struct alc_pincfg[]) {
5354 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5355 { }
5356 }
5357 },
Marton Balint8f239212012-03-05 21:33:23 +01005358 [ALC889_FIXUP_CD] = {
5359 .type = ALC_FIXUP_PINS,
5360 .v.pins = (const struct alc_pincfg[]) {
5361 { 0x1c, 0x993301f0 }, /* CD */
5362 { }
5363 }
5364 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005365 [ALC889_FIXUP_VAIO_TT] = {
5366 .type = ALC_FIXUP_PINS,
5367 .v.pins = (const struct alc_pincfg[]) {
5368 { 0x17, 0x90170111 }, /* hidden surround speaker */
5369 { }
5370 }
5371 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005372 [ALC888_FIXUP_EEE1601] = {
5373 .type = ALC_FIXUP_VERBS,
5374 .v.verbs = (const struct hda_verb[]) {
5375 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5376 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5377 { }
5378 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005379 },
5380 [ALC882_FIXUP_EAPD] = {
5381 .type = ALC_FIXUP_VERBS,
5382 .v.verbs = (const struct hda_verb[]) {
5383 /* change to EAPD mode */
5384 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5385 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5386 { }
5387 }
5388 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005389 [ALC883_FIXUP_EAPD] = {
5390 .type = ALC_FIXUP_VERBS,
5391 .v.verbs = (const struct hda_verb[]) {
5392 /* change to EAPD mode */
5393 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5394 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5395 { }
5396 }
5397 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005398 [ALC883_FIXUP_ACER_EAPD] = {
5399 .type = ALC_FIXUP_VERBS,
5400 .v.verbs = (const struct hda_verb[]) {
5401 /* eanable EAPD on Acer laptops */
5402 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5403 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5404 { }
5405 }
5406 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005407 [ALC882_FIXUP_GPIO1] = {
5408 .type = ALC_FIXUP_VERBS,
5409 .v.verbs = alc_gpio1_init_verbs,
5410 },
5411 [ALC882_FIXUP_GPIO2] = {
5412 .type = ALC_FIXUP_VERBS,
5413 .v.verbs = alc_gpio2_init_verbs,
5414 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005415 [ALC882_FIXUP_GPIO3] = {
5416 .type = ALC_FIXUP_VERBS,
5417 .v.verbs = alc_gpio3_init_verbs,
5418 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005419 [ALC882_FIXUP_ASUS_W2JC] = {
5420 .type = ALC_FIXUP_VERBS,
5421 .v.verbs = alc_gpio1_init_verbs,
5422 .chained = true,
5423 .chain_id = ALC882_FIXUP_EAPD,
5424 },
5425 [ALC889_FIXUP_COEF] = {
5426 .type = ALC_FIXUP_FUNC,
5427 .v.func = alc889_fixup_coef,
5428 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005429 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5430 .type = ALC_FIXUP_PINS,
5431 .v.pins = (const struct alc_pincfg[]) {
5432 { 0x16, 0x99130111 }, /* CLFE speaker */
5433 { 0x17, 0x99130112 }, /* surround speaker */
5434 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005435 },
5436 .chained = true,
5437 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005438 },
5439 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5440 .type = ALC_FIXUP_PINS,
5441 .v.pins = (const struct alc_pincfg[]) {
5442 { 0x16, 0x99130111 }, /* CLFE speaker */
5443 { 0x1b, 0x99130112 }, /* surround speaker */
5444 { }
5445 },
5446 .chained = true,
5447 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5448 },
5449 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5450 /* additional init verbs for Acer Aspire 8930G */
5451 .type = ALC_FIXUP_VERBS,
5452 .v.verbs = (const struct hda_verb[]) {
5453 /* Enable all DACs */
5454 /* DAC DISABLE/MUTE 1? */
5455 /* setting bits 1-5 disables DAC nids 0x02-0x06
5456 * apparently. Init=0x38 */
5457 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5458 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5459 /* DAC DISABLE/MUTE 2? */
5460 /* some bit here disables the other DACs.
5461 * Init=0x4900 */
5462 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5463 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5464 /* DMIC fix
5465 * This laptop has a stereo digital microphone.
5466 * The mics are only 1cm apart which makes the stereo
5467 * useless. However, either the mic or the ALC889
5468 * makes the signal become a difference/sum signal
5469 * instead of standard stereo, which is annoying.
5470 * So instead we flip this bit which makes the
5471 * codec replicate the sum signal to both channels,
5472 * turning it into a normal mono mic.
5473 */
5474 /* DMIC_CONTROL? Init value = 0x0001 */
5475 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5476 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5477 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5478 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5479 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005480 },
5481 .chained = true,
5482 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005483 },
Takashi Iwai56710872011-11-14 17:42:11 +01005484 [ALC885_FIXUP_MACPRO_GPIO] = {
5485 .type = ALC_FIXUP_FUNC,
5486 .v.func = alc885_fixup_macpro_gpio,
5487 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005488 [ALC889_FIXUP_DAC_ROUTE] = {
5489 .type = ALC_FIXUP_FUNC,
5490 .v.func = alc889_fixup_dac_route,
5491 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005492 [ALC889_FIXUP_MBP_VREF] = {
5493 .type = ALC_FIXUP_FUNC,
5494 .v.func = alc889_fixup_mbp_vref,
5495 .chained = true,
5496 .chain_id = ALC882_FIXUP_GPIO1,
5497 },
5498 [ALC889_FIXUP_IMAC91_VREF] = {
5499 .type = ALC_FIXUP_FUNC,
5500 .v.func = alc889_fixup_imac91_vref,
5501 .chained = true,
5502 .chain_id = ALC882_FIXUP_GPIO1,
5503 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005504 [ALC882_FIXUP_INV_DMIC] = {
5505 .type = ALC_FIXUP_FUNC,
5506 .v.func = alc_fixup_inv_dmic_0x12,
5507 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005508 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5509 .type = ALC_FIXUP_FUNC,
5510 .v.func = alc882_fixup_no_primary_hp,
5511 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512};
5513
5514static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005515 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5516 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5517 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5518 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5519 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5520 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005521 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5522 ALC882_FIXUP_ACER_ASPIRE_4930G),
5523 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5524 ALC882_FIXUP_ACER_ASPIRE_4930G),
5525 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5526 ALC882_FIXUP_ACER_ASPIRE_8930G),
5527 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5528 ALC882_FIXUP_ACER_ASPIRE_8930G),
5529 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5530 ALC882_FIXUP_ACER_ASPIRE_4930G),
5531 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5532 ALC882_FIXUP_ACER_ASPIRE_4930G),
5533 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5534 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005535 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005536 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5537 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005538 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005539 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005540 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005541 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005542 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005543 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005544 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005545 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005546 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005547
5548 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005549 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5550 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5551 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005552 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5553 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5554 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005555 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5556 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005557 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005558 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5559 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5560 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5561 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005562 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005563 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5564 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5565 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005566 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005567 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005568 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5569 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5570 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005571
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005572 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005573 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005574 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005575 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005576 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005577 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5578 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005579 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005580 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005581 {}
5582};
5583
Takashi Iwai912093b2012-04-11 14:03:41 +02005584static const struct alc_model_fixup alc882_fixup_models[] = {
5585 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5586 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5587 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005588 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005589 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005590 {}
5591};
5592
Takashi Iwai1d045db2011-07-07 18:23:21 +02005593/*
5594 * BIOS auto configuration
5595 */
5596/* almost identical with ALC880 parser... */
5597static int alc882_parse_auto_config(struct hda_codec *codec)
5598{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005599 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005600 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5601 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005602}
5603
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604/*
5605 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005606static int patch_alc882(struct hda_codec *codec)
5607{
5608 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005609 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005610
Takashi Iwai3de95172012-05-07 18:03:15 +02005611 err = alc_alloc_spec(codec, 0x0b);
5612 if (err < 0)
5613 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005614
Takashi Iwai3de95172012-05-07 18:03:15 +02005615 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005616
5617 switch (codec->vendor_id) {
5618 case 0x10ec0882:
5619 case 0x10ec0885:
5620 break;
5621 default:
5622 /* ALC883 and variants */
5623 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5624 break;
5625 }
5626
Takashi Iwai912093b2012-04-11 14:03:41 +02005627 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5628 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005629 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005630
5631 alc_auto_parse_customize_define(codec);
5632
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005633 /* automatic parse from the BIOS config */
5634 err = alc882_parse_auto_config(codec);
5635 if (err < 0)
5636 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005637
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005638 if (!spec->no_analog && has_cdefine_beep(codec)) {
5639 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005640 if (err < 0)
5641 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005642 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005643 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005644
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005646
Takashi Iwai589876e2012-02-20 15:47:55 +01005647 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5648
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005650
5651 error:
5652 alc_free(codec);
5653 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005654}
5655
5656
5657/*
5658 * ALC262 support
5659 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005660static int alc262_parse_auto_config(struct hda_codec *codec)
5661{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005662 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005663 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5664 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005665}
5666
5667/*
5668 * Pin config fixes
5669 */
5670enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005671 ALC262_FIXUP_FSC_H270,
5672 ALC262_FIXUP_HP_Z200,
5673 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005674 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005675 ALC262_FIXUP_BENQ,
5676 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005677 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005678};
5679
5680static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005681 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005682 .type = ALC_FIXUP_PINS,
5683 .v.pins = (const struct alc_pincfg[]) {
5684 { 0x14, 0x99130110 }, /* speaker */
5685 { 0x15, 0x0221142f }, /* front HP */
5686 { 0x1b, 0x0121141f }, /* rear HP */
5687 { }
5688 }
5689 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005690 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691 .type = ALC_FIXUP_PINS,
5692 .v.pins = (const struct alc_pincfg[]) {
5693 { 0x16, 0x99130120 }, /* internal speaker */
5694 { }
5695 }
5696 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005697 [ALC262_FIXUP_TYAN] = {
5698 .type = ALC_FIXUP_PINS,
5699 .v.pins = (const struct alc_pincfg[]) {
5700 { 0x14, 0x1993e1f0 }, /* int AUX */
5701 { }
5702 }
5703 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005704 [ALC262_FIXUP_LENOVO_3000] = {
5705 .type = ALC_FIXUP_VERBS,
5706 .v.verbs = (const struct hda_verb[]) {
5707 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005708 {}
5709 },
5710 .chained = true,
5711 .chain_id = ALC262_FIXUP_BENQ,
5712 },
5713 [ALC262_FIXUP_BENQ] = {
5714 .type = ALC_FIXUP_VERBS,
5715 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005716 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5717 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5718 {}
5719 }
5720 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005721 [ALC262_FIXUP_BENQ_T31] = {
5722 .type = ALC_FIXUP_VERBS,
5723 .v.verbs = (const struct hda_verb[]) {
5724 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5725 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5726 {}
5727 }
5728 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005729 [ALC262_FIXUP_INV_DMIC] = {
5730 .type = ALC_FIXUP_FUNC,
5731 .v.func = alc_fixup_inv_dmic_0x12,
5732 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005733};
5734
5735static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005736 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005737 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5738 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005739 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5740 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005741 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005742 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5743 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005744 {}
5745};
5746
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005747static const struct alc_model_fixup alc262_fixup_models[] = {
5748 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5749 {}
5750};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005751
Takashi Iwai1d045db2011-07-07 18:23:21 +02005752/*
5753 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754static int patch_alc262(struct hda_codec *codec)
5755{
5756 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757 int err;
5758
Takashi Iwai3de95172012-05-07 18:03:15 +02005759 err = alc_alloc_spec(codec, 0x0b);
5760 if (err < 0)
5761 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005762
Takashi Iwai3de95172012-05-07 18:03:15 +02005763 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005764
5765#if 0
5766 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5767 * under-run
5768 */
5769 {
5770 int tmp;
5771 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5772 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5773 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5774 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5775 }
5776#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005777 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5778
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005779 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5780 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005781 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005782
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005783 alc_auto_parse_customize_define(codec);
5784
Takashi Iwai42399f72011-11-07 17:18:44 +01005785 /* automatic parse from the BIOS config */
5786 err = alc262_parse_auto_config(codec);
5787 if (err < 0)
5788 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005789
Takashi Iwai1d045db2011-07-07 18:23:21 +02005790 if (!spec->no_analog && has_cdefine_beep(codec)) {
5791 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005792 if (err < 0)
5793 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005794 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005795 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005796
Takashi Iwai1d045db2011-07-07 18:23:21 +02005797 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005798 spec->shutup = alc_eapd_shutup;
5799
Takashi Iwai589876e2012-02-20 15:47:55 +01005800 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5801
Takashi Iwai1d045db2011-07-07 18:23:21 +02005802 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005803
5804 error:
5805 alc_free(codec);
5806 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005807}
5808
5809/*
5810 * ALC268
5811 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005812/* bind Beep switches of both NID 0x0f and 0x10 */
5813static const struct hda_bind_ctls alc268_bind_beep_sw = {
5814 .ops = &snd_hda_bind_sw,
5815 .values = {
5816 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5817 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5818 0
5819 },
5820};
5821
5822static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5823 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5824 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5825 { }
5826};
5827
5828/* set PCBEEP vol = 0, mute connections */
5829static const struct hda_verb alc268_beep_init_verbs[] = {
5830 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5831 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5832 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5833 { }
5834};
5835
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005836enum {
5837 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005838 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005839};
5840
5841static const struct alc_fixup alc268_fixups[] = {
5842 [ALC268_FIXUP_INV_DMIC] = {
5843 .type = ALC_FIXUP_FUNC,
5844 .v.func = alc_fixup_inv_dmic_0x12,
5845 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005846 [ALC268_FIXUP_HP_EAPD] = {
5847 .type = ALC_FIXUP_VERBS,
5848 .v.verbs = (const struct hda_verb[]) {
5849 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5850 {}
5851 }
5852 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005853};
5854
5855static const struct alc_model_fixup alc268_fixup_models[] = {
5856 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005857 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5858 {}
5859};
5860
5861static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5862 /* below is codec SSID since multiple Toshiba laptops have the
5863 * same PCI SSID 1179:ff00
5864 */
5865 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005866 {}
5867};
5868
Takashi Iwai1d045db2011-07-07 18:23:21 +02005869/*
5870 * BIOS auto configuration
5871 */
5872static int alc268_parse_auto_config(struct hda_codec *codec)
5873{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005874 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005875 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005876 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5877 if (err > 0) {
5878 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5879 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005880 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005881 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005882 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005883 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005884}
5885
Takashi Iwai1d045db2011-07-07 18:23:21 +02005886/*
5887 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005888static int patch_alc268(struct hda_codec *codec)
5889{
5890 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005891 int i, has_beep, err;
5892
Takashi Iwai1d045db2011-07-07 18:23:21 +02005893 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005894 err = alc_alloc_spec(codec, 0);
5895 if (err < 0)
5896 return err;
5897
5898 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005899
Takashi Iwaicb766402012-10-20 10:55:21 +02005900 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005901 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5902
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005903 /* automatic parse from the BIOS config */
5904 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005905 if (err < 0)
5906 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005907
Takashi Iwai1d045db2011-07-07 18:23:21 +02005908 has_beep = 0;
5909 for (i = 0; i < spec->num_mixers; i++) {
5910 if (spec->mixers[i] == alc268_beep_mixer) {
5911 has_beep = 1;
5912 break;
5913 }
5914 }
5915
5916 if (has_beep) {
5917 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005918 if (err < 0)
5919 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005920 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5921 /* override the amp caps for beep generator */
5922 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5923 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5924 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5925 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5926 (0 << AC_AMPCAP_MUTE_SHIFT));
5927 }
5928
Takashi Iwai1d045db2011-07-07 18:23:21 +02005929 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005930 spec->shutup = alc_eapd_shutup;
5931
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005932 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5933
Takashi Iwai1d045db2011-07-07 18:23:21 +02005934 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005935
5936 error:
5937 alc_free(codec);
5938 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005939}
5940
5941/*
5942 * ALC269
5943 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005944static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5945 .substreams = 1,
5946 .channels_min = 2,
5947 .channels_max = 8,
5948 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5949 /* NID is set in alc_build_pcms */
5950 .ops = {
5951 .open = alc_playback_pcm_open,
5952 .prepare = alc_playback_pcm_prepare,
5953 .cleanup = alc_playback_pcm_cleanup
5954 },
5955};
5956
5957static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5958 .substreams = 1,
5959 .channels_min = 2,
5960 .channels_max = 2,
5961 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5962 /* NID is set in alc_build_pcms */
5963};
5964
Takashi Iwai1d045db2011-07-07 18:23:21 +02005965/* different alc269-variants */
5966enum {
5967 ALC269_TYPE_ALC269VA,
5968 ALC269_TYPE_ALC269VB,
5969 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005970 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005971 ALC269_TYPE_ALC280,
5972 ALC269_TYPE_ALC282,
5973 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005974};
5975
5976/*
5977 * BIOS auto configuration
5978 */
5979static int alc269_parse_auto_config(struct hda_codec *codec)
5980{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005981 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005982 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5983 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5984 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005985 const hda_nid_t *ssids;
5986
5987 switch (spec->codec_variant) {
5988 case ALC269_TYPE_ALC269VA:
5989 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005990 case ALC269_TYPE_ALC280:
5991 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005992 ssids = alc269va_ssids;
5993 break;
5994 case ALC269_TYPE_ALC269VB:
5995 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005996 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005997 ssids = alc269_ssids;
5998 break;
5999 default:
6000 ssids = alc269_ssids;
6001 break;
6002 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006003
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006004 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006005}
6006
Kailang Yang1387e2d2012-11-08 10:23:18 +01006007static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006008{
6009 int val = alc_read_coef_idx(codec, 0x04);
6010 if (power_up)
6011 val |= 1 << 11;
6012 else
6013 val &= ~(1 << 11);
6014 alc_write_coef_idx(codec, 0x04, val);
6015}
6016
6017static void alc269_shutup(struct hda_codec *codec)
6018{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006019 struct alc_spec *spec = codec->spec;
6020
6021 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6022 return;
6023
Kailang Yang1387e2d2012-11-08 10:23:18 +01006024 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6025 alc269vb_toggle_power_output(codec, 0);
6026 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6027 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006028 msleep(150);
6029 }
6030}
6031
Takashi Iwai2a439522011-07-26 09:52:50 +02006032#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006033static int alc269_resume(struct hda_codec *codec)
6034{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006035 struct alc_spec *spec = codec->spec;
6036
Kailang Yang1387e2d2012-11-08 10:23:18 +01006037 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6038 alc269vb_toggle_power_output(codec, 0);
6039 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006040 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006041 msleep(150);
6042 }
6043
6044 codec->patch_ops.init(codec);
6045
Kailang Yang1387e2d2012-11-08 10:23:18 +01006046 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6047 alc269vb_toggle_power_output(codec, 1);
6048 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006049 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006050 msleep(200);
6051 }
6052
Takashi Iwai1d045db2011-07-07 18:23:21 +02006053 snd_hda_codec_resume_amp(codec);
6054 snd_hda_codec_resume_cache(codec);
6055 hda_call_check_power_status(codec, 0x01);
6056 return 0;
6057}
Takashi Iwai2a439522011-07-26 09:52:50 +02006058#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006059
David Henningsson108cc102012-07-20 10:37:25 +02006060static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6061 const struct alc_fixup *fix, int action)
6062{
6063 struct alc_spec *spec = codec->spec;
6064
6065 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6066 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6067}
6068
Takashi Iwai1d045db2011-07-07 18:23:21 +02006069static void alc269_fixup_hweq(struct hda_codec *codec,
6070 const struct alc_fixup *fix, int action)
6071{
6072 int coef;
6073
6074 if (action != ALC_FIXUP_ACT_INIT)
6075 return;
6076 coef = alc_read_coef_idx(codec, 0x1e);
6077 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6078}
6079
6080static void alc271_fixup_dmic(struct hda_codec *codec,
6081 const struct alc_fixup *fix, int action)
6082{
6083 static const struct hda_verb verbs[] = {
6084 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6085 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6086 {}
6087 };
6088 unsigned int cfg;
6089
6090 if (strcmp(codec->chip_name, "ALC271X"))
6091 return;
6092 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6093 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6094 snd_hda_sequence_write(codec, verbs);
6095}
6096
Takashi Iwai017f2a12011-07-09 14:42:25 +02006097static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6098 const struct alc_fixup *fix, int action)
6099{
6100 struct alc_spec *spec = codec->spec;
6101
6102 if (action != ALC_FIXUP_ACT_PROBE)
6103 return;
6104
6105 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6106 * fix the sample rate of analog I/O to 44.1kHz
6107 */
6108 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6109 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6110}
6111
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006112static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6113 const struct alc_fixup *fix, int action)
6114{
6115 int coef;
6116
6117 if (action != ALC_FIXUP_ACT_INIT)
6118 return;
6119 /* The digital-mic unit sends PDM (differential signal) instead of
6120 * the standard PCM, thus you can't record a valid mono stream as is.
6121 * Below is a workaround specific to ALC269 to control the dmic
6122 * signal source as mono.
6123 */
6124 coef = alc_read_coef_idx(codec, 0x07);
6125 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6126}
6127
Takashi Iwai24519912011-08-16 15:08:49 +02006128static void alc269_quanta_automute(struct hda_codec *codec)
6129{
David Henningsson42cf0d02011-09-20 12:04:56 +02006130 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006131
6132 snd_hda_codec_write(codec, 0x20, 0,
6133 AC_VERB_SET_COEF_INDEX, 0x0c);
6134 snd_hda_codec_write(codec, 0x20, 0,
6135 AC_VERB_SET_PROC_COEF, 0x680);
6136
6137 snd_hda_codec_write(codec, 0x20, 0,
6138 AC_VERB_SET_COEF_INDEX, 0x0c);
6139 snd_hda_codec_write(codec, 0x20, 0,
6140 AC_VERB_SET_PROC_COEF, 0x480);
6141}
6142
6143static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6144 const struct alc_fixup *fix, int action)
6145{
6146 struct alc_spec *spec = codec->spec;
6147 if (action != ALC_FIXUP_ACT_PROBE)
6148 return;
6149 spec->automute_hook = alc269_quanta_automute;
6150}
6151
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006152/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6153static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6154{
6155 struct hda_codec *codec = private_data;
6156 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6157 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6158 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6159}
6160
6161static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6162 const struct alc_fixup *fix, int action)
6163{
6164 struct alc_spec *spec = codec->spec;
6165 switch (action) {
6166 case ALC_FIXUP_ACT_BUILD:
6167 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6168 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6169 /* fallthru */
6170 case ALC_FIXUP_ACT_INIT:
6171 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6172 break;
6173 }
6174}
6175
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006176/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6177static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6178{
6179 struct hda_codec *codec = private_data;
6180 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006181 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006182}
6183
6184static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6185 const struct alc_fixup *fix, int action)
6186{
6187 struct alc_spec *spec = codec->spec;
6188 switch (action) {
6189 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006190 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006191 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006192 /* fallthru */
6193 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006194 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006195 break;
6196 }
6197}
6198
Dylan Reid08a978d2012-11-18 22:56:40 -08006199static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6200 const struct alc_fixup *fix,
6201 int action)
6202{
6203 struct alc_spec *spec = codec->spec;
6204
6205 if (action == ALC_FIXUP_ACT_PROBE)
6206 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6207 spec->autocfg.hp_pins[0]);
6208}
David Henningsson693b6132012-06-22 19:12:10 +02006209
Takashi Iwai1d045db2011-07-07 18:23:21 +02006210enum {
6211 ALC269_FIXUP_SONY_VAIO,
6212 ALC275_FIXUP_SONY_VAIO_GPIO2,
6213 ALC269_FIXUP_DELL_M101Z,
6214 ALC269_FIXUP_SKU_IGNORE,
6215 ALC269_FIXUP_ASUS_G73JW,
6216 ALC269_FIXUP_LENOVO_EAPD,
6217 ALC275_FIXUP_SONY_HWEQ,
6218 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006219 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006220 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006221 ALC269_FIXUP_QUANTA_MUTE,
6222 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006223 ALC269_FIXUP_AMIC,
6224 ALC269_FIXUP_DMIC,
6225 ALC269VB_FIXUP_AMIC,
6226 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006227 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006228 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006229 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006230 ALC269_FIXUP_LENOVO_DOCK,
6231 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006232 ALC271_FIXUP_AMIC_MIC2,
6233 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006234};
6235
6236static const struct alc_fixup alc269_fixups[] = {
6237 [ALC269_FIXUP_SONY_VAIO] = {
6238 .type = ALC_FIXUP_VERBS,
6239 .v.verbs = (const struct hda_verb[]) {
6240 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6241 {}
6242 }
6243 },
6244 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6245 .type = ALC_FIXUP_VERBS,
6246 .v.verbs = (const struct hda_verb[]) {
6247 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6248 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6249 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6250 { }
6251 },
6252 .chained = true,
6253 .chain_id = ALC269_FIXUP_SONY_VAIO
6254 },
6255 [ALC269_FIXUP_DELL_M101Z] = {
6256 .type = ALC_FIXUP_VERBS,
6257 .v.verbs = (const struct hda_verb[]) {
6258 /* Enables internal speaker */
6259 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6260 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6261 {}
6262 }
6263 },
6264 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006265 .type = ALC_FIXUP_FUNC,
6266 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006267 },
6268 [ALC269_FIXUP_ASUS_G73JW] = {
6269 .type = ALC_FIXUP_PINS,
6270 .v.pins = (const struct alc_pincfg[]) {
6271 { 0x17, 0x99130111 }, /* subwoofer */
6272 { }
6273 }
6274 },
6275 [ALC269_FIXUP_LENOVO_EAPD] = {
6276 .type = ALC_FIXUP_VERBS,
6277 .v.verbs = (const struct hda_verb[]) {
6278 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6279 {}
6280 }
6281 },
6282 [ALC275_FIXUP_SONY_HWEQ] = {
6283 .type = ALC_FIXUP_FUNC,
6284 .v.func = alc269_fixup_hweq,
6285 .chained = true,
6286 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6287 },
6288 [ALC271_FIXUP_DMIC] = {
6289 .type = ALC_FIXUP_FUNC,
6290 .v.func = alc271_fixup_dmic,
6291 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006292 [ALC269_FIXUP_PCM_44K] = {
6293 .type = ALC_FIXUP_FUNC,
6294 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006295 .chained = true,
6296 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006297 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006298 [ALC269_FIXUP_STEREO_DMIC] = {
6299 .type = ALC_FIXUP_FUNC,
6300 .v.func = alc269_fixup_stereo_dmic,
6301 },
Takashi Iwai24519912011-08-16 15:08:49 +02006302 [ALC269_FIXUP_QUANTA_MUTE] = {
6303 .type = ALC_FIXUP_FUNC,
6304 .v.func = alc269_fixup_quanta_mute,
6305 },
6306 [ALC269_FIXUP_LIFEBOOK] = {
6307 .type = ALC_FIXUP_PINS,
6308 .v.pins = (const struct alc_pincfg[]) {
6309 { 0x1a, 0x2101103f }, /* dock line-out */
6310 { 0x1b, 0x23a11040 }, /* dock mic-in */
6311 { }
6312 },
6313 .chained = true,
6314 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6315 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006316 [ALC269_FIXUP_AMIC] = {
6317 .type = ALC_FIXUP_PINS,
6318 .v.pins = (const struct alc_pincfg[]) {
6319 { 0x14, 0x99130110 }, /* speaker */
6320 { 0x15, 0x0121401f }, /* HP out */
6321 { 0x18, 0x01a19c20 }, /* mic */
6322 { 0x19, 0x99a3092f }, /* int-mic */
6323 { }
6324 },
6325 },
6326 [ALC269_FIXUP_DMIC] = {
6327 .type = ALC_FIXUP_PINS,
6328 .v.pins = (const struct alc_pincfg[]) {
6329 { 0x12, 0x99a3092f }, /* int-mic */
6330 { 0x14, 0x99130110 }, /* speaker */
6331 { 0x15, 0x0121401f }, /* HP out */
6332 { 0x18, 0x01a19c20 }, /* mic */
6333 { }
6334 },
6335 },
6336 [ALC269VB_FIXUP_AMIC] = {
6337 .type = ALC_FIXUP_PINS,
6338 .v.pins = (const struct alc_pincfg[]) {
6339 { 0x14, 0x99130110 }, /* speaker */
6340 { 0x18, 0x01a19c20 }, /* mic */
6341 { 0x19, 0x99a3092f }, /* int-mic */
6342 { 0x21, 0x0121401f }, /* HP out */
6343 { }
6344 },
6345 },
David Henningsson2267ea92012-01-03 08:45:56 +01006346 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006347 .type = ALC_FIXUP_PINS,
6348 .v.pins = (const struct alc_pincfg[]) {
6349 { 0x12, 0x99a3092f }, /* int-mic */
6350 { 0x14, 0x99130110 }, /* speaker */
6351 { 0x18, 0x01a19c20 }, /* mic */
6352 { 0x21, 0x0121401f }, /* HP out */
6353 { }
6354 },
6355 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006356 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6357 .type = ALC_FIXUP_FUNC,
6358 .v.func = alc269_fixup_mic1_mute,
6359 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006360 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6361 .type = ALC_FIXUP_FUNC,
6362 .v.func = alc269_fixup_mic2_mute,
6363 },
David Henningsson693b6132012-06-22 19:12:10 +02006364 [ALC269_FIXUP_INV_DMIC] = {
6365 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006366 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006367 },
David Henningsson108cc102012-07-20 10:37:25 +02006368 [ALC269_FIXUP_LENOVO_DOCK] = {
6369 .type = ALC_FIXUP_PINS,
6370 .v.pins = (const struct alc_pincfg[]) {
6371 { 0x19, 0x23a11040 }, /* dock mic */
6372 { 0x1b, 0x2121103f }, /* dock headphone */
6373 { }
6374 },
6375 .chained = true,
6376 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6377 },
6378 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6379 .type = ALC_FIXUP_FUNC,
6380 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6381 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006382 [ALC271_FIXUP_AMIC_MIC2] = {
6383 .type = ALC_FIXUP_PINS,
6384 .v.pins = (const struct alc_pincfg[]) {
6385 { 0x14, 0x99130110 }, /* speaker */
6386 { 0x19, 0x01a19c20 }, /* mic */
6387 { 0x1b, 0x99a7012f }, /* int-mic */
6388 { 0x21, 0x0121401f }, /* HP out */
6389 { }
6390 },
6391 },
6392 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6393 .type = ALC_FIXUP_FUNC,
6394 .v.func = alc271_hp_gate_mic_jack,
6395 .chained = true,
6396 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6397 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006398};
6399
6400static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006401 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6402 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006403 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006404 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006405 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006406 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006407 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006408 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006409 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6410 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6411 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6412 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6413 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006414 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6415 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6416 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6417 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6418 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006419 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006420 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006421 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006422 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6423 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6424 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6425 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6426 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006427 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006428 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006429 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006430 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006431 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006432 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006433 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006434
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006435#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006436 /* Below is a quirk table taken from the old code.
6437 * Basically the device should work as is without the fixup table.
6438 * If BIOS doesn't give a proper info, enable the corresponding
6439 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006440 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006441 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6442 ALC269_FIXUP_AMIC),
6443 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006444 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6445 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6446 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6447 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6448 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6449 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6450 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6451 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6452 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6453 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6454 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6455 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6456 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6457 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6458 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6459 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6460 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6461 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6462 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6463 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6464 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6465 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6466 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6467 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6468 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6469 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6470 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6471 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6472 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6473 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6474 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6475 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6476 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6477 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6478 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6479 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6480 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6481 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6482#endif
6483 {}
6484};
6485
6486static const struct alc_model_fixup alc269_fixup_models[] = {
6487 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6488 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006489 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6490 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6491 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006492 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006493 {}
6494};
6495
6496
Takashi Iwai546bb672012-03-07 08:37:19 +01006497static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006498{
Kailang Yang526af6e2012-03-07 08:25:20 +01006499 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006500 int val;
6501
Kailang Yang526af6e2012-03-07 08:25:20 +01006502 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006503 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006504
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006505 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006506 alc_write_coef_idx(codec, 0xf, 0x960b);
6507 alc_write_coef_idx(codec, 0xe, 0x8817);
6508 }
6509
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006510 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006511 alc_write_coef_idx(codec, 0xf, 0x960b);
6512 alc_write_coef_idx(codec, 0xe, 0x8814);
6513 }
6514
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006515 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006516 val = alc_read_coef_idx(codec, 0x04);
6517 /* Power up output pin */
6518 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6519 }
6520
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006521 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006522 val = alc_read_coef_idx(codec, 0xd);
6523 if ((val & 0x0c00) >> 10 != 0x1) {
6524 /* Capless ramp up clock control */
6525 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6526 }
6527 val = alc_read_coef_idx(codec, 0x17);
6528 if ((val & 0x01c0) >> 6 != 0x4) {
6529 /* Class D power on reset */
6530 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6531 }
6532 }
6533
6534 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6535 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6536
6537 val = alc_read_coef_idx(codec, 0x4); /* HP */
6538 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006539}
6540
6541/*
6542 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006543static int patch_alc269(struct hda_codec *codec)
6544{
6545 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006546 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006547
Takashi Iwai3de95172012-05-07 18:03:15 +02006548 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006549 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006550 return err;
6551
6552 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006553
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006554 alc_pick_fixup(codec, alc269_fixup_models,
6555 alc269_fixup_tbl, alc269_fixups);
6556 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6557
6558 alc_auto_parse_customize_define(codec);
6559
Kailang Yang065380f2013-01-10 10:25:48 +01006560 switch (codec->vendor_id) {
6561 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006562 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006563 switch (alc_get_coef0(codec) & 0x00f0) {
6564 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006565 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006566 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006567 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006568 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006569 break;
6570 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006571 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6572 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006573 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006574 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006575 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006576 case 0x0030:
6577 spec->codec_variant = ALC269_TYPE_ALC269VD;
6578 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006579 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006580 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006581 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006582 if (err < 0)
6583 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006584 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006585 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006586 break;
6587
6588 case 0x10ec0280:
6589 case 0x10ec0290:
6590 spec->codec_variant = ALC269_TYPE_ALC280;
6591 break;
6592 case 0x10ec0282:
6593 case 0x10ec0283:
6594 spec->codec_variant = ALC269_TYPE_ALC282;
6595 break;
6596 case 0x10ec0284:
6597 case 0x10ec0292:
6598 spec->codec_variant = ALC269_TYPE_ALC284;
6599 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006600 }
6601
Takashi Iwaia4297b52011-08-23 18:40:12 +02006602 /* automatic parse from the BIOS config */
6603 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006604 if (err < 0)
6605 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006606
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006607 if (!spec->no_analog && has_cdefine_beep(codec)) {
6608 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006609 if (err < 0)
6610 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006611 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006612 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006613
Takashi Iwai1d045db2011-07-07 18:23:21 +02006614 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006615#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006616 codec->patch_ops.resume = alc269_resume;
6617#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006618 spec->shutup = alc269_shutup;
6619
Takashi Iwai589876e2012-02-20 15:47:55 +01006620 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6621
Takashi Iwai1d045db2011-07-07 18:23:21 +02006622 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006623
6624 error:
6625 alc_free(codec);
6626 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006627}
6628
6629/*
6630 * ALC861
6631 */
6632
Takashi Iwai1d045db2011-07-07 18:23:21 +02006633static int alc861_parse_auto_config(struct hda_codec *codec)
6634{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006635 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006636 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6637 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006638}
6639
Takashi Iwai1d045db2011-07-07 18:23:21 +02006640/* Pin config fixes */
6641enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006642 ALC861_FIXUP_FSC_AMILO_PI1505,
6643 ALC861_FIXUP_AMP_VREF_0F,
6644 ALC861_FIXUP_NO_JACK_DETECT,
6645 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006646};
6647
Takashi Iwai31150f22012-01-30 10:54:08 +01006648/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6649static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6650 const struct alc_fixup *fix, int action)
6651{
6652 struct alc_spec *spec = codec->spec;
6653 unsigned int val;
6654
6655 if (action != ALC_FIXUP_ACT_INIT)
6656 return;
6657 val = snd_hda_codec_read(codec, 0x0f, 0,
6658 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6659 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6660 val |= AC_PINCTL_IN_EN;
6661 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006662 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006663 spec->keep_vref_in_automute = 1;
6664}
6665
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006666/* suppress the jack-detection */
6667static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6668 const struct alc_fixup *fix, int action)
6669{
6670 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6671 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006672}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006673
Takashi Iwai1d045db2011-07-07 18:23:21 +02006674static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006675 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006676 .type = ALC_FIXUP_PINS,
6677 .v.pins = (const struct alc_pincfg[]) {
6678 { 0x0b, 0x0221101f }, /* HP */
6679 { 0x0f, 0x90170310 }, /* speaker */
6680 { }
6681 }
6682 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006683 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006684 .type = ALC_FIXUP_FUNC,
6685 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006686 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006687 [ALC861_FIXUP_NO_JACK_DETECT] = {
6688 .type = ALC_FIXUP_FUNC,
6689 .v.func = alc_fixup_no_jack_detect,
6690 },
6691 [ALC861_FIXUP_ASUS_A6RP] = {
6692 .type = ALC_FIXUP_FUNC,
6693 .v.func = alc861_fixup_asus_amp_vref_0f,
6694 .chained = true,
6695 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6696 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006697};
6698
6699static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006700 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6701 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6702 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6703 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6704 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6705 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006706 {}
6707};
6708
6709/*
6710 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006711static int patch_alc861(struct hda_codec *codec)
6712{
6713 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006714 int err;
6715
Takashi Iwai3de95172012-05-07 18:03:15 +02006716 err = alc_alloc_spec(codec, 0x15);
6717 if (err < 0)
6718 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006719
Takashi Iwai3de95172012-05-07 18:03:15 +02006720 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006721
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006722 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6723 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006724
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006725 /* automatic parse from the BIOS config */
6726 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006727 if (err < 0)
6728 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006729
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006730 if (!spec->no_analog) {
6731 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006732 if (err < 0)
6733 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006734 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6735 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006736
Takashi Iwai1d045db2011-07-07 18:23:21 +02006737 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006738#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006739 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006740#endif
6741
Takashi Iwai589876e2012-02-20 15:47:55 +01006742 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6743
Takashi Iwai1d045db2011-07-07 18:23:21 +02006744 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006745
6746 error:
6747 alc_free(codec);
6748 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006749}
6750
6751/*
6752 * ALC861-VD support
6753 *
6754 * Based on ALC882
6755 *
6756 * In addition, an independent DAC
6757 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006758static int alc861vd_parse_auto_config(struct hda_codec *codec)
6759{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006760 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006761 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6762 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006763}
6764
Takashi Iwai1d045db2011-07-07 18:23:21 +02006765enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006766 ALC660VD_FIX_ASUS_GPIO1,
6767 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006768};
6769
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006770/* exclude VREF80 */
6771static void alc861vd_fixup_dallas(struct hda_codec *codec,
6772 const struct alc_fixup *fix, int action)
6773{
6774 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006775 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6776 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006777 }
6778}
6779
Takashi Iwai1d045db2011-07-07 18:23:21 +02006780static const struct alc_fixup alc861vd_fixups[] = {
6781 [ALC660VD_FIX_ASUS_GPIO1] = {
6782 .type = ALC_FIXUP_VERBS,
6783 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006784 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006785 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6786 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6787 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6788 { }
6789 }
6790 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006791 [ALC861VD_FIX_DALLAS] = {
6792 .type = ALC_FIXUP_FUNC,
6793 .v.func = alc861vd_fixup_dallas,
6794 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006795};
6796
6797static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006798 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006799 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006800 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006801 {}
6802};
6803
Takashi Iwai1d045db2011-07-07 18:23:21 +02006804/*
6805 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006806static int patch_alc861vd(struct hda_codec *codec)
6807{
6808 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006809 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006810
Takashi Iwai3de95172012-05-07 18:03:15 +02006811 err = alc_alloc_spec(codec, 0x0b);
6812 if (err < 0)
6813 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006814
Takashi Iwai3de95172012-05-07 18:03:15 +02006815 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006816
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006817 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6818 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006819
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006820 /* automatic parse from the BIOS config */
6821 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006822 if (err < 0)
6823 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006824
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006825 if (!spec->no_analog) {
6826 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006827 if (err < 0)
6828 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006829 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6830 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006831
Takashi Iwai1d045db2011-07-07 18:23:21 +02006832 codec->patch_ops = alc_patch_ops;
6833
Takashi Iwai1d045db2011-07-07 18:23:21 +02006834 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006835
Takashi Iwai589876e2012-02-20 15:47:55 +01006836 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6837
Takashi Iwai1d045db2011-07-07 18:23:21 +02006838 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006839
6840 error:
6841 alc_free(codec);
6842 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006843}
6844
6845/*
6846 * ALC662 support
6847 *
6848 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6849 * configuration. Each pin widget can choose any input DACs and a mixer.
6850 * Each ADC is connected from a mixer of all inputs. This makes possible
6851 * 6-channel independent captures.
6852 *
6853 * In addition, an independent DAC for the multi-playback (not used in this
6854 * driver yet).
6855 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006856
6857/*
6858 * BIOS auto configuration
6859 */
6860
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006861static int alc662_parse_auto_config(struct hda_codec *codec)
6862{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006863 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006864 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6865 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6866 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006867
Kailang Yang6227cdc2010-02-25 08:36:52 +01006868 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6869 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006870 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006871 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006872 ssids = alc662_ssids;
6873 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006874}
6875
Todd Broch6be79482010-12-07 16:51:05 -08006876static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006877 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006878{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006879 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006880 return;
Todd Broch6be79482010-12-07 16:51:05 -08006881 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6882 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6883 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6884 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6885 (0 << AC_AMPCAP_MUTE_SHIFT)))
6886 printk(KERN_WARNING
6887 "hda_codec: failed to override amp caps for NID 0x2\n");
6888}
6889
David Henningsson6cb3b702010-09-09 08:51:44 +02006890enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006891 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006892 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006893 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006894 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006895 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006896 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006897 ALC662_FIXUP_ASUS_MODE1,
6898 ALC662_FIXUP_ASUS_MODE2,
6899 ALC662_FIXUP_ASUS_MODE3,
6900 ALC662_FIXUP_ASUS_MODE4,
6901 ALC662_FIXUP_ASUS_MODE5,
6902 ALC662_FIXUP_ASUS_MODE6,
6903 ALC662_FIXUP_ASUS_MODE7,
6904 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006905 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006906 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006907 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006908};
6909
6910static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006911 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006912 .type = ALC_FIXUP_PINS,
6913 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006914 { 0x15, 0x99130112 }, /* subwoofer */
6915 { }
6916 }
6917 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006918 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006919 .type = ALC_FIXUP_PINS,
6920 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006921 { 0x17, 0x99130112 }, /* subwoofer */
6922 { }
6923 }
6924 },
Todd Broch6be79482010-12-07 16:51:05 -08006925 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006926 .type = ALC_FIXUP_FUNC,
6927 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006928 },
6929 [ALC662_FIXUP_CZC_P10T] = {
6930 .type = ALC_FIXUP_VERBS,
6931 .v.verbs = (const struct hda_verb[]) {
6932 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6933 {}
6934 }
6935 },
David Henningsson94024cd2011-04-29 14:10:55 +02006936 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006937 .type = ALC_FIXUP_FUNC,
6938 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006939 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006940 [ALC662_FIXUP_HP_RP5800] = {
6941 .type = ALC_FIXUP_PINS,
6942 .v.pins = (const struct alc_pincfg[]) {
6943 { 0x14, 0x0221201f }, /* HP out */
6944 { }
6945 },
6946 .chained = true,
6947 .chain_id = ALC662_FIXUP_SKU_IGNORE
6948 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006949 [ALC662_FIXUP_ASUS_MODE1] = {
6950 .type = ALC_FIXUP_PINS,
6951 .v.pins = (const struct alc_pincfg[]) {
6952 { 0x14, 0x99130110 }, /* speaker */
6953 { 0x18, 0x01a19c20 }, /* mic */
6954 { 0x19, 0x99a3092f }, /* int-mic */
6955 { 0x21, 0x0121401f }, /* HP out */
6956 { }
6957 },
6958 .chained = true,
6959 .chain_id = ALC662_FIXUP_SKU_IGNORE
6960 },
6961 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006962 .type = ALC_FIXUP_PINS,
6963 .v.pins = (const struct alc_pincfg[]) {
6964 { 0x14, 0x99130110 }, /* speaker */
6965 { 0x18, 0x01a19820 }, /* mic */
6966 { 0x19, 0x99a3092f }, /* int-mic */
6967 { 0x1b, 0x0121401f }, /* HP out */
6968 { }
6969 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006970 .chained = true,
6971 .chain_id = ALC662_FIXUP_SKU_IGNORE
6972 },
6973 [ALC662_FIXUP_ASUS_MODE3] = {
6974 .type = ALC_FIXUP_PINS,
6975 .v.pins = (const struct alc_pincfg[]) {
6976 { 0x14, 0x99130110 }, /* speaker */
6977 { 0x15, 0x0121441f }, /* HP */
6978 { 0x18, 0x01a19840 }, /* mic */
6979 { 0x19, 0x99a3094f }, /* int-mic */
6980 { 0x21, 0x01211420 }, /* HP2 */
6981 { }
6982 },
6983 .chained = true,
6984 .chain_id = ALC662_FIXUP_SKU_IGNORE
6985 },
6986 [ALC662_FIXUP_ASUS_MODE4] = {
6987 .type = ALC_FIXUP_PINS,
6988 .v.pins = (const struct alc_pincfg[]) {
6989 { 0x14, 0x99130110 }, /* speaker */
6990 { 0x16, 0x99130111 }, /* speaker */
6991 { 0x18, 0x01a19840 }, /* mic */
6992 { 0x19, 0x99a3094f }, /* int-mic */
6993 { 0x21, 0x0121441f }, /* HP */
6994 { }
6995 },
6996 .chained = true,
6997 .chain_id = ALC662_FIXUP_SKU_IGNORE
6998 },
6999 [ALC662_FIXUP_ASUS_MODE5] = {
7000 .type = ALC_FIXUP_PINS,
7001 .v.pins = (const struct alc_pincfg[]) {
7002 { 0x14, 0x99130110 }, /* speaker */
7003 { 0x15, 0x0121441f }, /* HP */
7004 { 0x16, 0x99130111 }, /* speaker */
7005 { 0x18, 0x01a19840 }, /* mic */
7006 { 0x19, 0x99a3094f }, /* int-mic */
7007 { }
7008 },
7009 .chained = true,
7010 .chain_id = ALC662_FIXUP_SKU_IGNORE
7011 },
7012 [ALC662_FIXUP_ASUS_MODE6] = {
7013 .type = ALC_FIXUP_PINS,
7014 .v.pins = (const struct alc_pincfg[]) {
7015 { 0x14, 0x99130110 }, /* speaker */
7016 { 0x15, 0x01211420 }, /* HP2 */
7017 { 0x18, 0x01a19840 }, /* mic */
7018 { 0x19, 0x99a3094f }, /* int-mic */
7019 { 0x1b, 0x0121441f }, /* HP */
7020 { }
7021 },
7022 .chained = true,
7023 .chain_id = ALC662_FIXUP_SKU_IGNORE
7024 },
7025 [ALC662_FIXUP_ASUS_MODE7] = {
7026 .type = ALC_FIXUP_PINS,
7027 .v.pins = (const struct alc_pincfg[]) {
7028 { 0x14, 0x99130110 }, /* speaker */
7029 { 0x17, 0x99130111 }, /* speaker */
7030 { 0x18, 0x01a19840 }, /* mic */
7031 { 0x19, 0x99a3094f }, /* int-mic */
7032 { 0x1b, 0x01214020 }, /* HP */
7033 { 0x21, 0x0121401f }, /* HP */
7034 { }
7035 },
7036 .chained = true,
7037 .chain_id = ALC662_FIXUP_SKU_IGNORE
7038 },
7039 [ALC662_FIXUP_ASUS_MODE8] = {
7040 .type = ALC_FIXUP_PINS,
7041 .v.pins = (const struct alc_pincfg[]) {
7042 { 0x14, 0x99130110 }, /* speaker */
7043 { 0x12, 0x99a30970 }, /* int-mic */
7044 { 0x15, 0x01214020 }, /* HP */
7045 { 0x17, 0x99130111 }, /* speaker */
7046 { 0x18, 0x01a19840 }, /* mic */
7047 { 0x21, 0x0121401f }, /* HP */
7048 { }
7049 },
7050 .chained = true,
7051 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007052 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007053 [ALC662_FIXUP_NO_JACK_DETECT] = {
7054 .type = ALC_FIXUP_FUNC,
7055 .v.func = alc_fixup_no_jack_detect,
7056 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007057 [ALC662_FIXUP_ZOTAC_Z68] = {
7058 .type = ALC_FIXUP_PINS,
7059 .v.pins = (const struct alc_pincfg[]) {
7060 { 0x1b, 0x02214020 }, /* Front HP */
7061 { }
7062 }
7063 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007064 [ALC662_FIXUP_INV_DMIC] = {
7065 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007066 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007067 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007068};
7069
Takashi Iwaia9111322011-05-02 11:30:18 +02007070static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007071 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007072 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007073 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007074 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007075 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007076 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007077 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007078 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007079 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007080 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007081 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007082 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007083 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007084
7085#if 0
7086 /* Below is a quirk table taken from the old code.
7087 * Basically the device should work as is without the fixup table.
7088 * If BIOS doesn't give a proper info, enable the corresponding
7089 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007090 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007091 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7092 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7093 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7094 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7095 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7096 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7097 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7098 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7099 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7100 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7101 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7102 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7103 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7104 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7105 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7106 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7107 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7108 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7109 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7110 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7111 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7112 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7113 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7114 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7115 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7116 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7117 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7118 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7119 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7120 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7121 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7122 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7123 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7124 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7125 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7126 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7127 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7128 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7129 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7130 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7131 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7132 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7133 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7134 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7135 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7136 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7137 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7138 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7139 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7140 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7141#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007142 {}
7143};
7144
Todd Broch6be79482010-12-07 16:51:05 -08007145static const struct alc_model_fixup alc662_fixup_models[] = {
7146 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007147 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7148 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7149 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7150 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7151 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7152 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7153 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7154 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007155 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007156 {}
7157};
David Henningsson6cb3b702010-09-09 08:51:44 +02007158
Kailang Yang8663ff72012-06-29 09:35:52 +02007159static void alc662_fill_coef(struct hda_codec *codec)
7160{
7161 int val, coef;
7162
7163 coef = alc_get_coef0(codec);
7164
7165 switch (codec->vendor_id) {
7166 case 0x10ec0662:
7167 if ((coef & 0x00f0) == 0x0030) {
7168 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7169 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7170 }
7171 break;
7172 case 0x10ec0272:
7173 case 0x10ec0273:
7174 case 0x10ec0663:
7175 case 0x10ec0665:
7176 case 0x10ec0670:
7177 case 0x10ec0671:
7178 case 0x10ec0672:
7179 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7180 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7181 break;
7182 }
7183}
David Henningsson6cb3b702010-09-09 08:51:44 +02007184
Takashi Iwai1d045db2011-07-07 18:23:21 +02007185/*
7186 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007187static int patch_alc662(struct hda_codec *codec)
7188{
7189 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007190 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007191
Takashi Iwai3de95172012-05-07 18:03:15 +02007192 err = alc_alloc_spec(codec, 0x0b);
7193 if (err < 0)
7194 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007195
Takashi Iwai3de95172012-05-07 18:03:15 +02007196 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007197
Takashi Iwai53c334a2011-08-23 18:27:14 +02007198 /* handle multiple HPs as is */
7199 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7200
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007201 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7202
Kailang Yang8663ff72012-06-29 09:35:52 +02007203 spec->init_hook = alc662_fill_coef;
7204 alc662_fill_coef(codec);
7205
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007206 alc_pick_fixup(codec, alc662_fixup_models,
7207 alc662_fixup_tbl, alc662_fixups);
7208 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7209
7210 alc_auto_parse_customize_define(codec);
7211
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007212 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007213 codec->bus->pci->subsystem_vendor == 0x1025 &&
7214 spec->cdefine.platform_type == 1) {
7215 if (alc_codec_rename(codec, "ALC272X") < 0)
7216 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007217 }
Kailang Yang274693f2009-12-03 10:07:50 +01007218
Takashi Iwaib9c51062011-08-24 18:08:07 +02007219 /* automatic parse from the BIOS config */
7220 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007221 if (err < 0)
7222 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007223
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007224 if (!spec->no_analog && has_cdefine_beep(codec)) {
7225 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007226 if (err < 0)
7227 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007228 switch (codec->vendor_id) {
7229 case 0x10ec0662:
7230 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7231 break;
7232 case 0x10ec0272:
7233 case 0x10ec0663:
7234 case 0x10ec0665:
7235 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7236 break;
7237 case 0x10ec0273:
7238 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7239 break;
7240 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007241 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007242
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007243 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007244 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007245
Takashi Iwai589876e2012-02-20 15:47:55 +01007246 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7247
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007248 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007249
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007250 error:
7251 alc_free(codec);
7252 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007253}
7254
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007255/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007256 * ALC680 support
7257 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007258
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007259static int alc680_parse_auto_config(struct hda_codec *codec)
7260{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007261 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007262}
7263
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007264/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007265 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007266static int patch_alc680(struct hda_codec *codec)
7267{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007268 int err;
7269
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007270 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007271 err = alc_alloc_spec(codec, 0);
7272 if (err < 0)
7273 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007274
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007275 /* automatic parse from the BIOS config */
7276 err = alc680_parse_auto_config(codec);
7277 if (err < 0) {
7278 alc_free(codec);
7279 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007280 }
7281
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007282 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007283
7284 return 0;
7285}
7286
7287/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007288 * patch entries
7289 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007290static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007291 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007292 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007293 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007294 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007295 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007296 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007297 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007298 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007299 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007300 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007301 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007302 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007303 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007304 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007305 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007306 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007307 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007308 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007309 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7310 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7311 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007312 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007313 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007314 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7315 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007316 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7317 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007318 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007319 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007320 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007321 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007322 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007323 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007324 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007325 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007326 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007327 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007328 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007329 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007330 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007331 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007332 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007333 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007334 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007335 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007336 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007337 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007338 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007339 {} /* terminator */
7340};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007341
7342MODULE_ALIAS("snd-hda-codec-id:10ec*");
7343
7344MODULE_LICENSE("GPL");
7345MODULE_DESCRIPTION("Realtek HD-audio codec");
7346
7347static struct hda_codec_preset_list realtek_list = {
7348 .preset = snd_hda_preset_realtek,
7349 .owner = THIS_MODULE,
7350};
7351
7352static int __init patch_realtek_init(void)
7353{
7354 return snd_hda_add_codec_preset(&realtek_list);
7355}
7356
7357static void __exit patch_realtek_exit(void)
7358{
7359 snd_hda_delete_codec_preset(&realtek_list);
7360}
7361
7362module_init(patch_realtek_init)
7363module_exit(patch_realtek_exit)