blob: c6cc833f4d2a249349d858d38f6f1a00b1d18d53 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe409a3e92012-03-27 13:01:01 +10309 * Jonathan Woithe <jwoithe@just42.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Takashi Iwai23d30f22012-05-07 17:17:32 +020035#include "hda_auto_parser.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090036#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020037#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Takashi Iwai1d045db2011-07-07 18:23:21 +020039/* unsol event tags */
40#define ALC_FRONT_EVENT 0x01
41#define ALC_DCVOL_EVENT 0x02
42#define ALC_HP_EVENT 0x04
43#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020044
Kailang Yangdf694da2005-12-05 19:42:22 +010045/* for GPIO Poll */
46#define GPIO_MASK 0x03
47
Takashi Iwai4a79ba32009-04-22 16:31:35 +020048/* extra amp-initialization sequence types */
49enum {
50 ALC_INIT_NONE,
51 ALC_INIT_DEFAULT,
52 ALC_INIT_GPIO1,
53 ALC_INIT_GPIO2,
54 ALC_INIT_GPIO3,
55};
56
Kailang Yangda00c242010-03-19 11:23:45 +010057struct alc_customize_define {
58 unsigned int sku_cfg;
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
65 unsigned int swap:1;
66 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020067 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010068};
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwaic14c95f2012-02-16 16:38:07 +010076#define MAX_VOL_NIDS 0x40
77
Takashi Iwai23d30f22012-05-07 17:17:32 +020078/* make compatible with old code */
79#define alc_apply_pincfgs snd_hda_apply_pincfgs
80#define alc_apply_fixup snd_hda_apply_fixup
81#define alc_pick_fixup snd_hda_pick_fixup
82#define alc_fixup hda_fixup
83#define alc_pincfg hda_pintbl
84#define alc_model_fixup hda_model_fixup
85
86#define ALC_FIXUP_PINS HDA_FIXUP_PINS
87#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
88#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
89
90#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
91#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
92#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
93#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
94
95
Takashi Iwai30dcd3b2012-12-06 15:45:38 +010096#define MAX_NID_PATH_DEPTH 5
97
Takashi Iwai8dd48672012-12-14 18:19:04 +010098enum {
99 NID_PATH_VOL_CTL,
100 NID_PATH_MUTE_CTL,
101 NID_PATH_BOOST_CTL,
102 NID_PATH_NUM_CTLS
103};
104
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100105/* Widget connection path
106 *
107 * For output, stored in the order of DAC -> ... -> pin,
108 * for input, pin -> ... -> ADC.
109 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100110 * idx[i] contains the source index number to select on of the widget path[i];
111 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100112 * multi[] indicates whether it's a selector widget with multi-connectors
113 * (i.e. the connection selection is mandatory)
114 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
115 */
116struct nid_path {
117 int depth;
118 hda_nid_t path[MAX_NID_PATH_DEPTH];
119 unsigned char idx[MAX_NID_PATH_DEPTH];
120 unsigned char multi[MAX_NID_PATH_DEPTH];
Takashi Iwai8dd48672012-12-14 18:19:04 +0100121 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
Takashi Iwai130e5f02012-12-14 16:09:29 +0100122 bool active;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100123};
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200126 struct hda_gen_spec gen;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200129 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 unsigned int num_mixers;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100131 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200133 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200134 const struct hda_pcm_stream *stream_analog_playback;
135 const struct hda_pcm_stream *stream_analog_capture;
136 const struct hda_pcm_stream *stream_analog_alt_playback;
137 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200139 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200140 const struct hda_pcm_stream *stream_digital_playback;
141 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200144 struct hda_multi_out multiout; /* playback set-up
145 * max_channels, dacs must be set
146 * dig_out_nid and hp_nid are optional
147 */
Takashi Iwai63300792008-01-24 15:31:36 +0100148 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100149 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100150 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 /* capture */
153 unsigned int num_adc_nids;
Takashi Iwai27d31532012-12-18 08:57:05 +0100154 hda_nid_t adc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai16ded522005-06-10 19:58:24 +0200155 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200156 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Takashi Iwai840b64c2010-07-13 22:49:01 +0200158 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200159 hda_nid_t cur_adc;
160 unsigned int cur_adc_stream_tag;
161 unsigned int cur_adc_format;
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200164 unsigned int num_mux_defs;
Takashi Iwai27d31532012-12-18 08:57:05 +0100165 struct hda_input_mux input_mux;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200167 hda_nid_t ext_mic_pin;
168 hda_nid_t dock_mic_pin;
169 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100172 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200174 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100175 int const_channel_count; /* min. channel count (for speakers) */
176 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100179 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200180
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200181 /* dynamic controls, init_verbs and input_mux */
182 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100183 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200184 struct snd_array kctls;
Takashi Iwai41923e42007-10-22 17:20:10 +0200185 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200186 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
187 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
188 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200189 hda_nid_t inv_dmic_pin;
Takashi Iwai37c04202012-12-18 14:22:45 +0100190 hda_nid_t shared_mic_vref_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 Iwaic9967f12012-12-14 16:39:22 +0100196 /* path list */
197 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100198
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 Iwai1c7161532011-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
Takashi Iwai666a70d2012-12-17 20:29:29 +0100277static struct nid_path *
278get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid);
279static void activate_path(struct hda_codec *codec, struct nid_path *path,
280 bool enable, bool add_aamix);
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282/*
283 * input MUX handling
284 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200285static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
289 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +0100290 return snd_hda_input_mux_info(&spec->input_mux, 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 Iwai666a70d2012-12-17 20:29:29 +0100304static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
305{
306 struct alc_spec *spec = codec->spec;
307 if (spec->dyn_adc_switch)
308 adc_idx = spec->dyn_adc_idx[imux_idx];
309 return spec->adc_nids[adc_idx];
310}
311
Takashi Iwai21268962011-07-07 15:01:13 +0200312static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Takashi Iwai21268962011-07-07 15:01:13 +0200314 struct alc_spec *spec = codec->spec;
315 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
316
317 if (spec->cur_adc && spec->cur_adc != new_adc) {
318 /* stream is running, let's swap the current ADC */
319 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
320 spec->cur_adc = new_adc;
321 snd_hda_codec_setup_stream(codec, new_adc,
322 spec->cur_adc_stream_tag, 0,
323 spec->cur_adc_format);
324 return true;
325 }
326 return false;
327}
328
Takashi Iwai24de1832011-11-07 17:13:39 +0100329static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200330static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100331static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx);
Takashi Iwai24de1832011-11-07 17:13:39 +0100332
David Henningsson00227f12012-06-27 18:45:44 +0200333/* for shared I/O, change the pin-control accordingly */
334static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
335{
336 struct alc_spec *spec = codec->spec;
337 unsigned int val;
338 hda_nid_t pin = spec->autocfg.inputs[1].pin;
339 /* NOTE: this assumes that there are only two inputs, the
340 * first is the real internal mic and the second is HP/mic jack.
341 */
342
343 val = snd_hda_get_default_vref(codec, pin);
344
345 /* This pin does not have vref caps - let's enable vref on pin 0x18
346 instead, as suggested by Realtek */
Takashi Iwai37c04202012-12-18 14:22:45 +0100347 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
348 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
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));
David Henningsson00227f12012-06-27 18:45:44 +0200352 }
353
354 val = set_as_mic ? val | PIN_IN : PIN_HP;
355 snd_hda_set_pin_ctl(codec, pin, val);
356
357 spec->automute_speaker = !set_as_mic;
358 call_update_outputs(codec);
359}
Takashi Iwai21268962011-07-07 15:01:13 +0200360
361/* select the given imux item; either unmute exclusively or select the route */
362static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
363 unsigned int idx, bool force)
364{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100366 const struct hda_input_mux *imux;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100367 struct nid_path *path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Takashi Iwai27d31532012-12-18 08:57:05 +0100369 imux = &spec->input_mux;
370 if (!imux->num_items)
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100371 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100372
Takashi Iwai21268962011-07-07 15:01:13 +0200373 if (idx >= imux->num_items)
374 idx = imux->num_items - 1;
375 if (spec->cur_mux[adc_idx] == idx && !force)
376 return 0;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100377
378 path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]],
379 spec->adc_nids[adc_idx]);
380 if (!path)
381 return 0;
382 if (path->active)
383 activate_path(codec, path, false, false);
384
Takashi Iwai21268962011-07-07 15:01:13 +0200385 spec->cur_mux[adc_idx] = idx;
386
David Henningsson00227f12012-06-27 18:45:44 +0200387 if (spec->shared_mic_hp)
388 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100389
Takashi Iwai666a70d2012-12-17 20:29:29 +0100390 if (spec->dyn_adc_switch)
Takashi Iwai21268962011-07-07 15:01:13 +0200391 alc_dyn_adc_pcm_resetup(codec, idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200392
Takashi Iwai666a70d2012-12-17 20:29:29 +0100393 path = get_nid_path(codec, spec->imux_pins[idx],
394 get_adc_nid(codec, adc_idx, idx));
395 if (!path)
396 return 0;
397 if (path->active)
398 return 0;
399 activate_path(codec, path, true, false);
Takashi Iwai125821a2012-06-22 14:30:29 +0200400 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200401 return 1;
402}
403
404static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
405 struct snd_ctl_elem_value *ucontrol)
406{
407 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
408 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
409 return alc_mux_select(codec, adc_idx,
410 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100411}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100414 * set up the input pin config (depending on the given auto-pin type)
415 */
416static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
417 int auto_pin_type)
418{
419 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200420 if (auto_pin_type == AUTO_PIN_MIC)
421 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200422 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100423}
424
425/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200426 * Append the given mixer and verb elements for the later use
427 * The mixer array is referred in build_controls(), and init_verbs are
428 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100429 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200430static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100431{
432 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
433 return;
434 spec->mixers[spec->num_mixers++] = mix;
435}
436
Takashi Iwaid88897e2008-10-31 15:01:37 +0100437/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200438 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100439 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200440/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200441static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200442 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
443 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
444 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
445 { }
446};
447
Takashi Iwaia9111322011-05-02 11:30:18 +0200448static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200449 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
450 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
451 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
452 { }
453};
454
Takashi Iwaia9111322011-05-02 11:30:18 +0200455static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200456 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
457 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
458 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
459 { }
460};
461
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200462/*
463 * Fix hardware PLL issue
464 * On some codecs, the analog PLL gating control must be off while
465 * the default value is 1.
466 */
467static void alc_fix_pll(struct hda_codec *codec)
468{
469 struct alc_spec *spec = codec->spec;
470 unsigned int val;
471
472 if (!spec->pll_nid)
473 return;
474 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
475 spec->pll_coef_idx);
476 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
477 AC_VERB_GET_PROC_COEF, 0);
478 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
479 spec->pll_coef_idx);
480 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
481 val & ~(1 << spec->pll_coef_bit));
482}
483
484static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
485 unsigned int coef_idx, unsigned int coef_bit)
486{
487 struct alc_spec *spec = codec->spec;
488 spec->pll_nid = nid;
489 spec->pll_coef_idx = coef_idx;
490 spec->pll_coef_bit = coef_bit;
491 alc_fix_pll(codec);
492}
493
Takashi Iwai1d045db2011-07-07 18:23:21 +0200494/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200495 * Jack detections for HP auto-mute and mic-switch
496 */
497
498/* check each pin in the given array; returns true if any of them is plugged */
499static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200500{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200502
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200503 for (i = 0; i < num_pins; i++) {
504 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200505 if (!nid)
506 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200508 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200509 return present;
510}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200511
Takashi Iwai1d045db2011-07-07 18:23:21 +0200512/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200513static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200514 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200515{
516 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200517 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200518 int i;
519
520 for (i = 0; i < num_pins; i++) {
521 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100522 unsigned int val;
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200523 if (!nid)
524 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100525 /* don't reset VREF value in case it's controlling
526 * the amp (see alc861_fixup_asus_amp_vref_0f())
527 */
528 if (spec->keep_vref_in_automute) {
529 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100530 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100531 val &= ~PIN_HP;
532 } else
533 val = 0;
534 val |= pin_bits;
535 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200536 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200537}
538
David Henningsson42cf0d02011-09-20 12:04:56 +0200539/* Toggle outputs muting */
540static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200541{
542 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200543 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200544
Takashi Iwaic0a20262011-06-10 15:28:15 +0200545 /* Control HP pins/amps depending on master_mute state;
546 * in general, HP pins/amps control should be enabled in all cases,
547 * but currently set only for master_mute, just to be safe
548 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100549 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
550 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200551 spec->autocfg.hp_pins, spec->master_mute, true);
552
David Henningsson42cf0d02011-09-20 12:04:56 +0200553 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200554 on = 0;
555 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200556 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200557 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200559 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200560
561 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200562 /* if LO is a copy of either HP or Speaker, don't need to handle it */
563 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
564 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200565 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200566 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200567 on = 0;
568 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200569 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200571 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200572 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200573}
574
David Henningsson42cf0d02011-09-20 12:04:56 +0200575static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200576{
577 struct alc_spec *spec = codec->spec;
578 if (spec->automute_hook)
579 spec->automute_hook(codec);
580 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200581 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200582}
583
Takashi Iwai1d045db2011-07-07 18:23:21 +0200584/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200585static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200586{
587 struct alc_spec *spec = codec->spec;
588
David Henningsson42cf0d02011-09-20 12:04:56 +0200589 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
591 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200593 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200594 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200595}
596
Takashi Iwai1d045db2011-07-07 18:23:21 +0200597/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200598static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200599{
600 struct alc_spec *spec = codec->spec;
601
David Henningssonf7f4b2322012-10-10 16:32:09 +0200602 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
603 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200604 /* check LO jack only when it's different from HP */
605 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
606 return;
607
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200608 spec->line_jack_present =
609 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
610 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200611 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200612 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200613 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200614}
615
Takashi Iwai8d087c72011-06-28 12:45:47 +0200616#define get_connection_index(codec, mux, nid) \
617 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200618
Takashi Iwai1d045db2011-07-07 18:23:21 +0200619/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200620static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200621{
622 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200623 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200624
Takashi Iwai21268962011-07-07 15:01:13 +0200625 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200626 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200627 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200628 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200629
Takashi Iwai21268962011-07-07 15:01:13 +0200630 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
631 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
632 else if (spec->dock_mic_idx >= 0 &&
633 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
634 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
635 else
636 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200637}
638
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100639/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200640static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100641{
642 unsigned int val;
643 struct snd_kcontrol *kctl;
644 struct snd_ctl_elem_value *uctl;
645
646 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
647 if (!kctl)
648 return;
649 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
650 if (!uctl)
651 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200652 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100653 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
654 val &= HDA_AMP_VOLMASK;
655 uctl->value.integer.value[0] = val;
656 uctl->value.integer.value[1] = val;
657 kctl->put(kctl, uctl);
658 kfree(uctl);
659}
660
David Henningsson29adc4b2012-09-25 11:31:00 +0200661static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100662{
David Henningsson29adc4b2012-09-25 11:31:00 +0200663 /* For some reason, the res given from ALC880 is broken.
664 Here we adjust it properly. */
665 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100666}
667
Takashi Iwai1d045db2011-07-07 18:23:21 +0200668/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200669static void alc_inithook(struct hda_codec *codec)
670{
David Henningsson29adc4b2012-09-25 11:31:00 +0200671 alc_hp_automute(codec, NULL);
672 alc_line_automute(codec, NULL);
673 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200674}
675
Kailang Yangf9423e72008-05-27 12:32:25 +0200676/* additional initialization for ALC888 variants */
677static void alc888_coef_init(struct hda_codec *codec)
678{
679 unsigned int tmp;
680
681 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
682 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
683 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100684 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200685 /* alc888S-VC */
686 snd_hda_codec_read(codec, 0x20, 0,
687 AC_VERB_SET_PROC_COEF, 0x830);
688 else
689 /* alc888-VB */
690 snd_hda_codec_read(codec, 0x20, 0,
691 AC_VERB_SET_PROC_COEF, 0x3030);
692}
693
Takashi Iwai1d045db2011-07-07 18:23:21 +0200694/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200695static void alc889_coef_init(struct hda_codec *codec)
696{
697 unsigned int tmp;
698
699 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
700 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
701 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
702 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
703}
704
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100705/* turn on/off EAPD control (only if available) */
706static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
707{
708 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
709 return;
710 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
711 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
712 on ? 2 : 0);
713}
714
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200715/* turn on/off EAPD controls of the codec */
716static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
717{
718 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200719 static hda_nid_t pins[] = {
720 0x0f, 0x10, 0x14, 0x15, 0
721 };
722 hda_nid_t *p;
723 for (p = pins; *p; p++)
724 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200725}
726
Takashi Iwai1c7161532011-04-07 10:37:16 +0200727/* generic shutup callback;
728 * just turning off EPAD and a little pause for avoiding pop-noise
729 */
730static void alc_eapd_shutup(struct hda_codec *codec)
731{
732 alc_auto_setup_eapd(codec, false);
733 msleep(200);
734}
735
Takashi Iwai1d045db2011-07-07 18:23:21 +0200736/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200737static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200738{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200739 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200740
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200741 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200742 switch (type) {
743 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200744 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
745 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200746 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200747 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
748 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200749 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200750 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
751 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200752 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200753 switch (codec->vendor_id) {
754 case 0x10ec0260:
755 snd_hda_codec_write(codec, 0x1a, 0,
756 AC_VERB_SET_COEF_INDEX, 7);
757 tmp = snd_hda_codec_read(codec, 0x1a, 0,
758 AC_VERB_GET_PROC_COEF, 0);
759 snd_hda_codec_write(codec, 0x1a, 0,
760 AC_VERB_SET_COEF_INDEX, 7);
761 snd_hda_codec_write(codec, 0x1a, 0,
762 AC_VERB_SET_PROC_COEF,
763 tmp | 0x2010);
764 break;
765 case 0x10ec0262:
766 case 0x10ec0880:
767 case 0x10ec0882:
768 case 0x10ec0883:
769 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100770 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100771 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200772 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200773 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200774 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200775 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200776 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100777#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200778 case 0x10ec0267:
779 case 0x10ec0268:
780 snd_hda_codec_write(codec, 0x20, 0,
781 AC_VERB_SET_COEF_INDEX, 7);
782 tmp = snd_hda_codec_read(codec, 0x20, 0,
783 AC_VERB_GET_PROC_COEF, 0);
784 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200785 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200786 snd_hda_codec_write(codec, 0x20, 0,
787 AC_VERB_SET_PROC_COEF,
788 tmp | 0x3000);
789 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100790#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200791 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200792 break;
793 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200794}
Kailang Yangea1fb292008-08-26 12:58:38 +0200795
Takashi Iwai1d045db2011-07-07 18:23:21 +0200796/*
797 * Auto-Mute mode mixer enum support
798 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200799static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
800 struct snd_ctl_elem_info *uinfo)
801{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200802 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
803 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200804 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100805 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200806 };
807
Takashi Iwaidda415d2012-11-30 18:34:38 +0100808 if (spec->automute_speaker_possible && spec->automute_lo_possible)
809 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
810 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200811}
812
813static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_value *ucontrol)
815{
816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200818 unsigned int val = 0;
819 if (spec->automute_speaker)
820 val++;
821 if (spec->automute_lo)
822 val++;
823
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200824 ucontrol->value.enumerated.item[0] = val;
825 return 0;
826}
827
828static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
829 struct snd_ctl_elem_value *ucontrol)
830{
831 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
832 struct alc_spec *spec = codec->spec;
833
834 switch (ucontrol->value.enumerated.item[0]) {
835 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200836 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200837 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200838 spec->automute_speaker = 0;
839 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200840 break;
841 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200842 if (spec->automute_speaker_possible) {
843 if (!spec->automute_lo && spec->automute_speaker)
844 return 0;
845 spec->automute_speaker = 1;
846 spec->automute_lo = 0;
847 } else if (spec->automute_lo_possible) {
848 if (spec->automute_lo)
849 return 0;
850 spec->automute_lo = 1;
851 } else
852 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200853 break;
854 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200855 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200856 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200857 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200858 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200859 spec->automute_speaker = 1;
860 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200861 break;
862 default:
863 return -EINVAL;
864 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200865 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200866 return 1;
867}
868
Takashi Iwaia9111322011-05-02 11:30:18 +0200869static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200870 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
871 .name = "Auto-Mute Mode",
872 .info = alc_automute_mode_info,
873 .get = alc_automute_mode_get,
874 .put = alc_automute_mode_put,
875};
876
Takashi Iwai668d1e92012-11-29 14:10:17 +0100877static struct snd_kcontrol_new *
878alc_kcontrol_new(struct alc_spec *spec, const char *name,
879 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200880{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100881 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
882 if (!knew)
883 return NULL;
884 *knew = *temp;
885 knew->name = kstrdup(name, GFP_KERNEL);
886 if (!knew->name)
887 return NULL;
888 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200889}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200890
891static int alc_add_automute_mode_enum(struct hda_codec *codec)
892{
893 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200894
Takashi Iwai668d1e92012-11-29 14:10:17 +0100895 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200896 return -ENOMEM;
897 return 0;
898}
899
Takashi Iwai1d045db2011-07-07 18:23:21 +0200900/*
901 * Check the availability of HP/line-out auto-mute;
902 * Set up appropriately if really supported
903 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100904static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200905{
906 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200907 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200908 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100909 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200910
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200911 if (cfg->hp_pins[0])
912 present++;
913 if (cfg->line_out_pins[0])
914 present++;
915 if (cfg->speaker_pins[0])
916 present++;
917 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100918 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200919
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200920 if (!cfg->speaker_pins[0] &&
921 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200922 memcpy(cfg->speaker_pins, cfg->line_out_pins,
923 sizeof(cfg->speaker_pins));
924 cfg->speaker_outs = cfg->line_outs;
925 }
926
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200927 if (!cfg->hp_pins[0] &&
928 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200929 memcpy(cfg->hp_pins, cfg->line_out_pins,
930 sizeof(cfg->hp_pins));
931 cfg->hp_outs = cfg->line_outs;
932 }
933
934 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200935 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200936 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200937 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200938 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200939 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200940 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
941 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200942 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200943 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200944
David Henningsson42cf0d02011-09-20 12:04:56 +0200945 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
946 if (cfg->speaker_outs)
947 for (i = 0; i < cfg->line_outs; i++) {
948 hda_nid_t nid = cfg->line_out_pins[i];
949 if (!is_jack_detectable(codec, nid))
950 continue;
951 snd_printdd("realtek: Enable Line-Out "
952 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200953 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
954 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200955 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200956 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200957 spec->automute_lo_possible = spec->detect_hp;
958 }
959
960 spec->automute_speaker_possible = cfg->speaker_outs &&
961 (spec->detect_hp || spec->detect_lo);
962
963 spec->automute_lo = spec->automute_lo_possible;
964 spec->automute_speaker = spec->automute_speaker_possible;
965
Takashi Iwai475c3d22012-11-30 08:31:30 +0100966 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200967 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100968 err = alc_add_automute_mode_enum(codec);
969 if (err < 0)
970 return err;
971 }
972 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200973}
974
Takashi Iwai1d045db2011-07-07 18:23:21 +0200975/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200976static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
977{
978 int i;
979 for (i = 0; i < nums; i++)
980 if (list[i] == nid)
981 return i;
982 return -1;
983}
984
Takashi Iwai21268962011-07-07 15:01:13 +0200985/* check whether all auto-mic pins are valid; setup indices if OK */
986static bool alc_auto_mic_check_imux(struct hda_codec *codec)
987{
988 struct alc_spec *spec = codec->spec;
989 const struct hda_input_mux *imux;
990
Takashi Iwai27d31532012-12-18 08:57:05 +0100991 imux = &spec->input_mux;
Takashi Iwai21268962011-07-07 15:01:13 +0200992 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
993 spec->imux_pins, imux->num_items);
994 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
995 spec->imux_pins, imux->num_items);
996 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
997 spec->imux_pins, imux->num_items);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100998 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0)
Takashi Iwai21268962011-07-07 15:01:13 +0200999 return false; /* no corresponding imux */
Takashi Iwai21268962011-07-07 15:01:13 +02001000
David Henningsson29adc4b2012-09-25 11:31:00 +02001001 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1002 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001003 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001004 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1005 ALC_MIC_EVENT,
1006 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001007
1008 spec->auto_mic_valid_imux = 1;
Takashi Iwai21268962011-07-07 15:01:13 +02001009 return true;
1010}
1011
Takashi Iwai1d045db2011-07-07 18:23:21 +02001012/*
1013 * Check the availability of auto-mic switch;
1014 * Set up if really supported
1015 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001016static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001017{
1018 struct alc_spec *spec = codec->spec;
1019 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001020 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001021 int i;
1022
Takashi Iwai21268962011-07-07 15:01:13 +02001023 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1024
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001025 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001026 for (i = 0; i < cfg->num_inputs; i++) {
1027 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001028 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001029 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001030 switch (snd_hda_get_input_pin_attr(defcfg)) {
1031 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001032 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001033 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001034 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001035 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001036 fixed = nid;
1037 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001038 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001039 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001040 case INPUT_PIN_ATTR_DOCK:
1041 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001042 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001043 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001044 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001045 dock = nid;
1046 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001047 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001048 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001049 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001050 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001051 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001052 ext = nid;
1053 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001054 }
1055 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001056 if (!ext && dock) {
1057 ext = dock;
1058 dock = 0;
1059 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001060 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001061 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001062 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001063 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001064 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001065 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001066
1067 /* check imux indices */
1068 spec->ext_mic_pin = ext;
1069 spec->int_mic_pin = fixed;
1070 spec->dock_mic_pin = dock;
1071
Takashi Iwai21268962011-07-07 15:01:13 +02001072 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001073 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001074
Takashi Iwai666a70d2012-12-17 20:29:29 +01001075 spec->auto_mic = 1;
1076 spec->num_adc_nids = 1;
1077 spec->cur_mux[0] = spec->int_mic_idx;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001078 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1079 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001080
1081 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001082}
1083
Takashi Iwai1d045db2011-07-07 18:23:21 +02001084/*
1085 * Realtek SSID verification
1086 */
1087
David Henningsson90622912010-10-14 14:50:18 +02001088/* Could be any non-zero and even value. When used as fixup, tells
1089 * the driver to ignore any present sku defines.
1090 */
1091#define ALC_FIXUP_SKU_IGNORE (2)
1092
Takashi Iwai23d30f22012-05-07 17:17:32 +02001093static void alc_fixup_sku_ignore(struct hda_codec *codec,
1094 const struct hda_fixup *fix, int action)
1095{
1096 struct alc_spec *spec = codec->spec;
1097 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1098 spec->cdefine.fixup = 1;
1099 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1100 }
1101}
1102
Kailang Yangda00c242010-03-19 11:23:45 +01001103static int alc_auto_parse_customize_define(struct hda_codec *codec)
1104{
1105 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001106 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001107 struct alc_spec *spec = codec->spec;
1108
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001109 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1110
David Henningsson90622912010-10-14 14:50:18 +02001111 if (spec->cdefine.fixup) {
1112 ass = spec->cdefine.sku_cfg;
1113 if (ass == ALC_FIXUP_SKU_IGNORE)
1114 return -1;
1115 goto do_sku;
1116 }
1117
Kailang Yangda00c242010-03-19 11:23:45 +01001118 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001119 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001120 goto do_sku;
1121
1122 nid = 0x1d;
1123 if (codec->vendor_id == 0x10ec0260)
1124 nid = 0x17;
1125 ass = snd_hda_codec_get_pincfg(codec, nid);
1126
1127 if (!(ass & 1)) {
1128 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1129 codec->chip_name, ass);
1130 return -1;
1131 }
1132
1133 /* check sum */
1134 tmp = 0;
1135 for (i = 1; i < 16; i++) {
1136 if ((ass >> i) & 1)
1137 tmp++;
1138 }
1139 if (((ass >> 16) & 0xf) != tmp)
1140 return -1;
1141
1142 spec->cdefine.port_connectivity = ass >> 30;
1143 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1144 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1145 spec->cdefine.customization = ass >> 8;
1146do_sku:
1147 spec->cdefine.sku_cfg = ass;
1148 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1149 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1150 spec->cdefine.swap = (ass & 0x2) >> 1;
1151 spec->cdefine.override = ass & 0x1;
1152
1153 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1154 nid, spec->cdefine.sku_cfg);
1155 snd_printd("SKU: port_connectivity=0x%x\n",
1156 spec->cdefine.port_connectivity);
1157 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1158 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1159 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1160 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1161 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1162 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1163 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1164
1165 return 0;
1166}
1167
Takashi Iwai1d045db2011-07-07 18:23:21 +02001168/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001169static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1170{
Takashi Iwai21268962011-07-07 15:01:13 +02001171 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001172}
1173
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001174/* check subsystem ID and set up device-specific initialization;
1175 * return 1 if initialized, 0 if invalid SSID
1176 */
1177/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1178 * 31 ~ 16 : Manufacture ID
1179 * 15 ~ 8 : SKU ID
1180 * 7 ~ 0 : Assembly ID
1181 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1182 */
1183static int alc_subsystem_id(struct hda_codec *codec,
1184 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001185 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001186{
1187 unsigned int ass, tmp, i;
1188 unsigned nid;
1189 struct alc_spec *spec = codec->spec;
1190
David Henningsson90622912010-10-14 14:50:18 +02001191 if (spec->cdefine.fixup) {
1192 ass = spec->cdefine.sku_cfg;
1193 if (ass == ALC_FIXUP_SKU_IGNORE)
1194 return 0;
1195 goto do_sku;
1196 }
1197
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001198 ass = codec->subsystem_id & 0xffff;
1199 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1200 goto do_sku;
1201
1202 /* invalid SSID, check the special NID pin defcfg instead */
1203 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001204 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001205 * 29~21 : reserve
1206 * 20 : PCBEEP input
1207 * 19~16 : Check sum (15:1)
1208 * 15~1 : Custom
1209 * 0 : override
1210 */
1211 nid = 0x1d;
1212 if (codec->vendor_id == 0x10ec0260)
1213 nid = 0x17;
1214 ass = snd_hda_codec_get_pincfg(codec, nid);
1215 snd_printd("realtek: No valid SSID, "
1216 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001217 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001218 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001219 return 0;
1220 if ((ass >> 30) != 1) /* no physical connection */
1221 return 0;
1222
1223 /* check sum */
1224 tmp = 0;
1225 for (i = 1; i < 16; i++) {
1226 if ((ass >> i) & 1)
1227 tmp++;
1228 }
1229 if (((ass >> 16) & 0xf) != tmp)
1230 return 0;
1231do_sku:
1232 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1233 ass & 0xffff, codec->vendor_id);
1234 /*
1235 * 0 : override
1236 * 1 : Swap Jack
1237 * 2 : 0 --> Desktop, 1 --> Laptop
1238 * 3~5 : External Amplifier control
1239 * 7~6 : Reserved
1240 */
1241 tmp = (ass & 0x38) >> 3; /* external Amp control */
1242 switch (tmp) {
1243 case 1:
1244 spec->init_amp = ALC_INIT_GPIO1;
1245 break;
1246 case 3:
1247 spec->init_amp = ALC_INIT_GPIO2;
1248 break;
1249 case 7:
1250 spec->init_amp = ALC_INIT_GPIO3;
1251 break;
1252 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001253 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001254 spec->init_amp = ALC_INIT_DEFAULT;
1255 break;
1256 }
1257
1258 /* is laptop or Desktop and enable the function "Mute internal speaker
1259 * when the external headphone out jack is plugged"
1260 */
1261 if (!(ass & 0x8000))
1262 return 1;
1263 /*
1264 * 10~8 : Jack location
1265 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1266 * 14~13: Resvered
1267 * 15 : 1 --> enable the function "Mute internal speaker
1268 * when the external headphone out jack is plugged"
1269 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001270 if (!spec->autocfg.hp_pins[0] &&
1271 !(spec->autocfg.line_out_pins[0] &&
1272 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001273 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001274 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1275 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001276 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001277 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001278 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001279 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001280 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001281 else if (tmp == 3)
1282 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001283 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001284 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001285 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1286 spec->autocfg.line_outs))
1287 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001288 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001289 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001290 return 1;
1291}
Kailang Yangea1fb292008-08-26 12:58:38 +02001292
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001293/* Check the validity of ALC subsystem-id
1294 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1295static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001296{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001297 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001298 struct alc_spec *spec = codec->spec;
1299 snd_printd("realtek: "
1300 "Enable default setup for auto mode as fallback\n");
1301 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001302 }
Takashi Iwai21268962011-07-07 15:01:13 +02001303}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001304
Takashi Iwai41e41f12005-06-08 14:48:49 +02001305/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001306 * COEF access helper functions
1307 */
Kailang Yang274693f2009-12-03 10:07:50 +01001308static int alc_read_coef_idx(struct hda_codec *codec,
1309 unsigned int coef_idx)
1310{
1311 unsigned int val;
1312 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1313 coef_idx);
1314 val = snd_hda_codec_read(codec, 0x20, 0,
1315 AC_VERB_GET_PROC_COEF, 0);
1316 return val;
1317}
1318
Kailang Yang977ddd62010-09-15 10:02:29 +02001319static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1320 unsigned int coef_val)
1321{
1322 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1323 coef_idx);
1324 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1325 coef_val);
1326}
1327
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001328/* a special bypass for COEF 0; read the cached value at the second time */
1329static unsigned int alc_get_coef0(struct hda_codec *codec)
1330{
1331 struct alc_spec *spec = codec->spec;
1332 if (!spec->coef0)
1333 spec->coef0 = alc_read_coef_idx(codec, 0);
1334 return spec->coef0;
1335}
1336
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001337static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1338 hda_nid_t pin, int pin_type,
1339 hda_nid_t dac);
1340static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1341 bool is_digital);
Takashi Iwai965cceb2012-12-18 11:46:37 +01001342static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
1343 hda_nid_t to_nid, int with_aa_mix,
1344 struct nid_path *path);
1345static struct nid_path *add_new_nid_path(struct hda_codec *codec,
1346 hda_nid_t from_nid, hda_nid_t to_nid,
1347 int with_aa_mix);
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001348
Takashi Iwai1d045db2011-07-07 18:23:21 +02001349/*
1350 * Digital I/O handling
1351 */
1352
Takashi Iwai757899a2010-07-30 10:48:14 +02001353/* set right pin controls for digital I/O */
1354static void alc_auto_init_digital(struct hda_codec *codec)
1355{
1356 struct alc_spec *spec = codec->spec;
1357 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001358 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001359
1360 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1361 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001362 if (!pin)
1363 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001364 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001365 }
1366 pin = spec->autocfg.dig_in_pin;
1367 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001368 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001369}
1370
1371/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1372static void alc_auto_parse_digital(struct hda_codec *codec)
1373{
1374 struct alc_spec *spec = codec->spec;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001375 int i, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001376 hda_nid_t dig_nid;
1377
1378 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001379 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001380 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001381 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1382 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1383 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001384 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001385 if (!add_new_nid_path(codec, dig_nid, pin, 2))
1386 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001387 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001388 spec->multiout.dig_out_nid = dig_nid;
1389 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1390 } else {
1391 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001392 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001393 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001394 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001395 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001396 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001397 }
1398
1399 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001400 dig_nid = codec->start_nid;
1401 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001402 struct nid_path *path;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001403 unsigned int wcaps = get_wcaps(codec, dig_nid);
1404 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1405 continue;
1406 if (!(wcaps & AC_WCAP_DIGITAL))
1407 continue;
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001408 path = add_new_nid_path(codec, spec->autocfg.dig_in_pin,
1409 dig_nid, 2);
1410 if (path) {
1411 path->active = true;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001412 spec->dig_in_nid = dig_nid;
1413 break;
1414 }
1415 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001416 }
1417}
1418
Takashi Iwaif95474e2007-07-10 00:47:43 +02001419/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001420 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001421 */
Takashi Iwai666a70d2012-12-17 20:29:29 +01001422#define alc_cap_vol_info snd_hda_mixer_amp_volume_info
1423#define alc_cap_vol_get snd_hda_mixer_amp_volume_get
1424#define alc_cap_vol_tlv snd_hda_mixer_amp_tlv
1425
1426typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
1427 struct snd_ctl_elem_value *ucontrol);
1428
1429static int alc_cap_put_caller(struct snd_kcontrol *kcontrol,
1430 struct snd_ctl_elem_value *ucontrol,
1431 put_call_t func, int type)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001432{
1433 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1434 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001435 const struct hda_input_mux *imux;
1436 struct nid_path *path;
1437 int i, adc_idx, err = 0;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001438
Takashi Iwai27d31532012-12-18 08:57:05 +01001439 imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001440 adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001441 mutex_lock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001442 codec->cached_write = 1;
1443 for (i = 0; i < imux->num_items; i++) {
1444 path = get_nid_path(codec, spec->imux_pins[i],
1445 get_adc_nid(codec, adc_idx, i));
1446 if (!path->ctls[type])
1447 continue;
1448 kcontrol->private_value = path->ctls[type];
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001449 err = func(kcontrol, ucontrol);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001450 if (err < 0)
1451 goto error;
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001452 }
1453 error:
Takashi Iwai666a70d2012-12-17 20:29:29 +01001454 codec->cached_write = 0;
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001455 mutex_unlock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001456 snd_hda_codec_resume_amp(codec);
1457 if (err >= 0 && type == NID_PATH_MUTE_CTL &&
1458 spec->inv_dmic_fixup && spec->inv_dmic_muted)
1459 alc_inv_dmic_sync_adc(codec, adc_idx);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001460 return err;
1461}
1462
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001463static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1464 struct snd_ctl_elem_value *ucontrol)
1465{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001466 return alc_cap_put_caller(kcontrol, ucontrol,
1467 snd_hda_mixer_amp_volume_put,
1468 NID_PATH_VOL_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001469}
1470
1471/* capture mixer elements */
1472#define alc_cap_sw_info snd_ctl_boolean_stereo_info
Takashi Iwai666a70d2012-12-17 20:29:29 +01001473#define alc_cap_sw_get snd_hda_mixer_amp_switch_get
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001474
1475static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1476 struct snd_ctl_elem_value *ucontrol)
1477{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001478 return alc_cap_put_caller(kcontrol, ucontrol,
1479 snd_hda_mixer_amp_switch_put,
1480 NID_PATH_MUTE_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001481}
1482
Takashi Iwai666a70d2012-12-17 20:29:29 +01001483static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1484{
1485 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01001486 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001487 struct nid_path *path;
1488 hda_nid_t nid;
1489 int i, dir, parm;
1490 unsigned int val;
1491
1492 for (i = 0; i < imux->num_items; i++) {
1493 if (spec->imux_pins[i] == spec->inv_dmic_pin)
1494 break;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001495 }
Takashi Iwai666a70d2012-12-17 20:29:29 +01001496 if (i >= imux->num_items)
1497 return;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001498
Takashi Iwai666a70d2012-12-17 20:29:29 +01001499 path = get_nid_path(codec, spec->inv_dmic_pin,
1500 get_adc_nid(codec, adc_idx, i));
1501 val = path->ctls[NID_PATH_MUTE_CTL];
1502 if (!val)
1503 return;
1504 nid = get_amp_nid_(val);
1505 dir = get_amp_direction_(val);
1506 parm = AC_AMP_SET_RIGHT |
1507 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001508
Takashi Iwai666a70d2012-12-17 20:29:29 +01001509 /* we care only right channel */
1510 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1511 if (val & 0x80) /* if already muted, we don't need to touch */
1512 return;
1513 val |= 0x80;
1514 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1515 parm | val);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001516}
1517
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001518/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001519 * Inverted digital-mic handling
1520 *
1521 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1522 * gives the additional mute only to the right channel of the digital mic
1523 * capture stream. This is a workaround for avoiding the almost silence
1524 * by summing the stereo stream from some (known to be ForteMedia)
1525 * digital mic unit.
1526 *
1527 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1528 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1529 * without caching so that the cache can still keep the original value.
1530 * The cached value is then restored when the flag is set off or any other
1531 * than d-mic is used as the current input source.
1532 */
1533static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1534{
1535 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001536 int src, nums;
Takashi Iwai125821a2012-06-22 14:30:29 +02001537
1538 if (!spec->inv_dmic_fixup)
1539 return;
1540 if (!spec->inv_dmic_muted && !force)
1541 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001542 nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids;
1543 for (src = 0; src < nums; src++) {
Takashi Iwai125821a2012-06-22 14:30:29 +02001544 bool dmic_fixup = false;
Takashi Iwai125821a2012-06-22 14:30:29 +02001545
1546 if (spec->inv_dmic_muted &&
1547 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1548 dmic_fixup = true;
1549 if (!dmic_fixup && !force)
1550 continue;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001551 alc_inv_dmic_sync_adc(codec, src);
Takashi Iwai125821a2012-06-22 14:30:29 +02001552 }
1553}
1554
1555static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1556 struct snd_ctl_elem_value *ucontrol)
1557{
1558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1559 struct alc_spec *spec = codec->spec;
1560
1561 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1562 return 0;
1563}
1564
1565static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1566 struct snd_ctl_elem_value *ucontrol)
1567{
1568 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1569 struct alc_spec *spec = codec->spec;
1570 unsigned int val = !ucontrol->value.integer.value[0];
1571
1572 if (val == spec->inv_dmic_muted)
1573 return 0;
1574 spec->inv_dmic_muted = val;
1575 alc_inv_dmic_sync(codec, true);
1576 return 0;
1577}
1578
1579static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1580 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1581 .info = snd_ctl_boolean_mono_info,
1582 .get = alc_inv_dmic_sw_get,
1583 .put = alc_inv_dmic_sw_put,
1584};
1585
1586static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1587{
1588 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001589
1590 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1591 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001592 return -ENOMEM;
1593 spec->inv_dmic_fixup = 1;
1594 spec->inv_dmic_muted = 0;
1595 spec->inv_dmic_pin = nid;
1596 return 0;
1597}
1598
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001599/* typically the digital mic is put at node 0x12 */
1600static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1601 const struct alc_fixup *fix, int action)
1602{
1603 if (action == ALC_FIXUP_ACT_PROBE)
1604 alc_add_inv_dmic_mixer(codec, 0x12);
1605}
1606
Takashi Iwai125821a2012-06-22 14:30:29 +02001607/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001608 * virtual master controls
1609 */
1610
1611/*
1612 * slave controls for virtual master
1613 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001614static const char * const alc_slave_pfxs[] = {
1615 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001616 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001617 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001618 NULL,
1619};
1620
1621/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001622 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001624
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001625#define NID_MAPPING (-1)
1626
Takashi Iwai603c4012008-07-30 15:01:44 +02001627static void alc_free_kctls(struct hda_codec *codec);
1628
Takashi Iwai67d634c2009-11-16 15:35:59 +01001629#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001630/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001631static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001632 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001633 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001634 { } /* end */
1635};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001636#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001637
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001638static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639{
1640 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001641 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
1643 for (i = 0; i < spec->num_mixers; i++) {
1644 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1645 if (err < 0)
1646 return err;
1647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001649 err = snd_hda_create_dig_out_ctls(codec,
1650 spec->multiout.dig_out_nid,
1651 spec->multiout.dig_out_nid,
1652 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 if (err < 0)
1654 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001655 if (!spec->no_analog) {
1656 err = snd_hda_create_spdif_share_sw(codec,
1657 &spec->multiout);
1658 if (err < 0)
1659 return err;
1660 spec->multiout.share_spdif = 1;
1661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 }
1663 if (spec->dig_in_nid) {
1664 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1665 if (err < 0)
1666 return err;
1667 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001668
Takashi Iwai67d634c2009-11-16 15:35:59 +01001669#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001670 /* create beep controls if needed */
1671 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001672 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001673 for (knew = alc_beep_mixer; knew->name; knew++) {
1674 struct snd_kcontrol *kctl;
1675 kctl = snd_ctl_new1(knew, codec);
1676 if (!kctl)
1677 return -ENOMEM;
1678 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001679 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001680 if (err < 0)
1681 return err;
1682 }
1683 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001684#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001685
Takashi Iwai2134ea42008-01-10 16:53:55 +01001686 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001687 if (!spec->no_analog &&
1688 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001689 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001690 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001691 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001692 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001693 vmaster_tlv, alc_slave_pfxs,
1694 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001695 if (err < 0)
1696 return err;
1697 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001698 if (!spec->no_analog &&
1699 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001700 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1701 NULL, alc_slave_pfxs,
1702 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001703 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001704 if (err < 0)
1705 return err;
1706 }
1707
Takashi Iwaibae84e72010-03-22 08:30:20 +01001708 alc_free_kctls(codec); /* no longer needed */
1709
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001710 return 0;
1711}
1712
David Henningsson5780b622012-06-27 18:45:45 +02001713static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001714{
1715 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001716
1717 if (spec->shared_mic_hp) {
1718 int err;
1719 int nid = spec->autocfg.inputs[1].pin;
1720 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1721 if (err < 0)
1722 return err;
1723 err = snd_hda_jack_detect_enable(codec, nid, 0);
1724 if (err < 0)
1725 return err;
1726 }
1727
1728 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1729}
1730
1731static int alc_build_controls(struct hda_codec *codec)
1732{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001733 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001734 if (err < 0)
1735 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001736
1737 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001738 if (err < 0)
1739 return err;
1740 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1741 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742}
1743
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001744
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001746 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001747 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001748
Takashi Iwai070cff42012-02-21 12:54:17 +01001749static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001750
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751static int alc_init(struct hda_codec *codec)
1752{
1753 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001754
Takashi Iwai546bb672012-03-07 08:37:19 +01001755 if (spec->init_hook)
1756 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001757
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001758 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001759 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001760
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02001761 snd_hda_gen_apply_verbs(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001762 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001763
Takashi Iwai58701122011-01-13 15:41:45 +01001764 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1765
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001766 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 return 0;
1768}
1769
Takashi Iwai83012a72012-08-24 18:38:08 +02001770#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001771static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1772{
1773 struct alc_spec *spec = codec->spec;
1774 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1775}
1776#endif
1777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778/*
1779 * Analog playback callbacks
1780 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001781static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001783 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
1785 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001786 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1787 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788}
1789
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001790static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 struct hda_codec *codec,
1792 unsigned int stream_tag,
1793 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001794 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795{
1796 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001797 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1798 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
1800
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001801static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001803 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804{
1805 struct alc_spec *spec = codec->spec;
1806 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1807}
1808
1809/*
1810 * Digital out
1811 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001812static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001814 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815{
1816 struct alc_spec *spec = codec->spec;
1817 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1818}
1819
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001820static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001821 struct hda_codec *codec,
1822 unsigned int stream_tag,
1823 unsigned int format,
1824 struct snd_pcm_substream *substream)
1825{
1826 struct alc_spec *spec = codec->spec;
1827 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1828 stream_tag, format, substream);
1829}
1830
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001831static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001832 struct hda_codec *codec,
1833 struct snd_pcm_substream *substream)
1834{
1835 struct alc_spec *spec = codec->spec;
1836 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1837}
1838
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001839static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001841 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842{
1843 struct alc_spec *spec = codec->spec;
1844 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1845}
1846
1847/*
1848 * Analog capture
1849 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001850static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 struct hda_codec *codec,
1852 unsigned int stream_tag,
1853 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001854 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
1856 struct alc_spec *spec = codec->spec;
1857
Takashi Iwai63300792008-01-24 15:31:36 +01001858 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 stream_tag, 0, format);
1860 return 0;
1861}
1862
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001863static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001865 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866{
1867 struct alc_spec *spec = codec->spec;
1868
Takashi Iwai888afa12008-03-18 09:57:50 +01001869 snd_hda_codec_cleanup_stream(codec,
1870 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 return 0;
1872}
1873
Takashi Iwai840b64c2010-07-13 22:49:01 +02001874/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02001875static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001876 struct hda_codec *codec,
1877 unsigned int stream_tag,
1878 unsigned int format,
1879 struct snd_pcm_substream *substream)
1880{
1881 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001882 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02001883 spec->cur_adc_stream_tag = stream_tag;
1884 spec->cur_adc_format = format;
1885 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1886 return 0;
1887}
1888
Takashi Iwai21268962011-07-07 15:01:13 +02001889static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001890 struct hda_codec *codec,
1891 struct snd_pcm_substream *substream)
1892{
1893 struct alc_spec *spec = codec->spec;
1894 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1895 spec->cur_adc = 0;
1896 return 0;
1897}
1898
Takashi Iwai21268962011-07-07 15:01:13 +02001899static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02001900 .substreams = 1,
1901 .channels_min = 2,
1902 .channels_max = 2,
1903 .nid = 0, /* fill later */
1904 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02001905 .prepare = dyn_adc_capture_pcm_prepare,
1906 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02001907 },
1908};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
1910/*
1911 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001912static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 .substreams = 1,
1914 .channels_min = 2,
1915 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001916 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001918 .open = alc_playback_pcm_open,
1919 .prepare = alc_playback_pcm_prepare,
1920 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 },
1922};
1923
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001924static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001925 .substreams = 1,
1926 .channels_min = 2,
1927 .channels_max = 2,
1928 /* NID is set in alc_build_pcms */
1929};
1930
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001931static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01001932 .substreams = 1,
1933 .channels_min = 2,
1934 .channels_max = 2,
1935 /* NID is set in alc_build_pcms */
1936};
1937
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001938static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001939 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 .channels_min = 2,
1941 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001942 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001944 .prepare = alc_alt_capture_pcm_prepare,
1945 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 },
1947};
1948
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001949static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 .substreams = 1,
1951 .channels_min = 2,
1952 .channels_max = 2,
1953 /* NID is set in alc_build_pcms */
1954 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001955 .open = alc_dig_playback_pcm_open,
1956 .close = alc_dig_playback_pcm_close,
1957 .prepare = alc_dig_playback_pcm_prepare,
1958 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 },
1960};
1961
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001962static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 .substreams = 1,
1964 .channels_min = 2,
1965 .channels_max = 2,
1966 /* NID is set in alc_build_pcms */
1967};
1968
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001969/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02001970static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001971 .substreams = 0,
1972 .channels_min = 0,
1973 .channels_max = 0,
1974};
1975
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976static int alc_build_pcms(struct hda_codec *codec)
1977{
1978 struct alc_spec *spec = codec->spec;
1979 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001980 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01001981 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 int i;
1983
1984 codec->num_pcms = 1;
1985 codec->pcm_info = info;
1986
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001987 if (spec->no_analog)
1988 goto skip_analog;
1989
Takashi Iwai812a2cc2009-05-16 10:00:49 +02001990 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1991 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01001993
Takashi Iwaieedec3d2012-02-06 10:24:04 +01001994 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001995 p = spec->stream_analog_playback;
1996 if (!p)
1997 p = &alc_pcm_analog_playback;
1998 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001999 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002000 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2001 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002002 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2003 spec->autocfg.line_outs == 2)
2004 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2005 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002006 }
Takashi Iwai27d31532012-12-18 08:57:05 +01002007 if (spec->num_adc_nids) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002008 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002009 if (!p) {
2010 if (spec->dyn_adc_switch)
2011 p = &dyn_adc_pcm_analog_capture;
2012 else
2013 p = &alc_pcm_analog_capture;
2014 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002015 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002016 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2017 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
Takashi Iwai4a471b72005-12-07 13:56:29 +01002019 if (spec->channel_mode) {
2020 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2021 for (i = 0; i < spec->num_channel_mode; i++) {
2022 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2023 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 }
2026 }
2027
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002028 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002029 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002031 snprintf(spec->stream_name_digital,
2032 sizeof(spec->stream_name_digital),
2033 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002034 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002035 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002036 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002038 if (spec->dig_out_type)
2039 info->pcm_type = spec->dig_out_type;
2040 else
2041 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002042 if (spec->multiout.dig_out_nid) {
2043 p = spec->stream_digital_playback;
2044 if (!p)
2045 p = &alc_pcm_digital_playback;
2046 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2048 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002049 if (spec->dig_in_nid) {
2050 p = spec->stream_digital_capture;
2051 if (!p)
2052 p = &alc_pcm_digital_capture;
2053 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2055 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002056 /* FIXME: do we need this for all Realtek codec models? */
2057 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 }
2059
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002060 if (spec->no_analog)
2061 return 0;
2062
Takashi Iwaie08a0072006-09-07 17:52:14 +02002063 /* If the use of more than one ADC is requested for the current
2064 * model, configure a second analog capture-only PCM.
2065 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002066 have_multi_adcs = (spec->num_adc_nids > 1) &&
Takashi Iwai27d31532012-12-18 08:57:05 +01002067 !spec->dyn_adc_switch && !spec->auto_mic;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002068 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002069 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002070 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002071 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002072 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002073 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002074 p = spec->stream_analog_alt_playback;
2075 if (!p)
2076 p = &alc_pcm_analog_alt_playback;
2077 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002078 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2079 spec->alt_dac_nid;
2080 } else {
2081 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2082 alc_pcm_null_stream;
2083 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2084 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002085 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002086 p = spec->stream_analog_alt_capture;
2087 if (!p)
2088 p = &alc_pcm_analog_alt_capture;
2089 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002090 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2091 spec->adc_nids[1];
2092 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2093 spec->num_adc_nids - 1;
2094 } else {
2095 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2096 alc_pcm_null_stream;
2097 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002098 }
2099 }
2100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 return 0;
2102}
2103
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002104static inline void alc_shutup(struct hda_codec *codec)
2105{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002106 struct alc_spec *spec = codec->spec;
2107
2108 if (spec && spec->shutup)
2109 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002110 snd_hda_shutup_pins(codec);
2111}
2112
Takashi Iwai603c4012008-07-30 15:01:44 +02002113static void alc_free_kctls(struct hda_codec *codec)
2114{
2115 struct alc_spec *spec = codec->spec;
2116
2117 if (spec->kctls.list) {
2118 struct snd_kcontrol_new *kctl = spec->kctls.list;
2119 int i;
2120 for (i = 0; i < spec->kctls.used; i++)
2121 kfree(kctl[i].name);
2122 }
2123 snd_array_free(&spec->kctls);
2124}
2125
Takashi Iwai23c09b02011-08-19 09:05:35 +02002126static void alc_free_bind_ctls(struct hda_codec *codec)
2127{
2128 struct alc_spec *spec = codec->spec;
2129 if (spec->bind_ctls.list) {
2130 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2131 int i;
2132 for (i = 0; i < spec->bind_ctls.used; i++)
2133 kfree(ctl[i]);
2134 }
2135 snd_array_free(&spec->bind_ctls);
2136}
2137
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138static void alc_free(struct hda_codec *codec)
2139{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002140 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002141
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002142 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002143 return;
2144
Takashi Iwai603c4012008-07-30 15:01:44 +02002145 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002146 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002147 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002148 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002149 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002150 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151}
2152
Takashi Iwai83012a72012-08-24 18:38:08 +02002153#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002154static void alc_power_eapd(struct hda_codec *codec)
2155{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002156 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002157}
2158
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002159static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002160{
2161 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002162 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002163 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002164 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002165 return 0;
2166}
2167#endif
2168
Takashi Iwai2a439522011-07-26 09:52:50 +02002169#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002170static int alc_resume(struct hda_codec *codec)
2171{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002172 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002173 codec->patch_ops.init(codec);
2174 snd_hda_codec_resume_amp(codec);
2175 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002176 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002177 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002178 return 0;
2179}
Takashi Iwaie044c392008-10-27 16:56:24 +01002180#endif
2181
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182/*
2183 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002184static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 .build_controls = alc_build_controls,
2186 .build_pcms = alc_build_pcms,
2187 .init = alc_init,
2188 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002189 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002190#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002191 .resume = alc_resume,
2192#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002193#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002194 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002195 .check_power_status = alc_check_power_status,
2196#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002197 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198};
2199
David Henningsson29adc4b2012-09-25 11:31:00 +02002200
Kailang Yangc027ddc2010-03-19 11:33:06 +01002201/* replace the codec chip_name with the given string */
2202static int alc_codec_rename(struct hda_codec *codec, const char *name)
2203{
2204 kfree(codec->chip_name);
2205 codec->chip_name = kstrdup(name, GFP_KERNEL);
2206 if (!codec->chip_name) {
2207 alc_free(codec);
2208 return -ENOMEM;
2209 }
2210 return 0;
2211}
2212
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002213/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002214 * Rename codecs appropriately from COEF value
2215 */
2216struct alc_codec_rename_table {
2217 unsigned int vendor_id;
2218 unsigned short coef_mask;
2219 unsigned short coef_bits;
2220 const char *name;
2221};
2222
2223static struct alc_codec_rename_table rename_tbl[] = {
2224 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2225 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2226 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2227 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2228 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2229 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2230 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002231 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002232 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2233 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2234 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2235 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2236 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2237 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2238 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2239 { } /* terminator */
2240};
2241
2242static int alc_codec_rename_from_preset(struct hda_codec *codec)
2243{
2244 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002245
2246 for (p = rename_tbl; p->vendor_id; p++) {
2247 if (p->vendor_id != codec->vendor_id)
2248 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002249 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002250 return alc_codec_rename(codec, p->name);
2251 }
2252 return 0;
2253}
2254
2255/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002256 * Automatic parse of I/O pins from the BIOS configuration
2257 */
2258
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002259enum {
2260 ALC_CTL_WIDGET_VOL,
2261 ALC_CTL_WIDGET_MUTE,
2262 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002263 ALC_CTL_BIND_VOL,
2264 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002265};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002266static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002267 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2268 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002269 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002270 HDA_BIND_VOL(NULL, 0),
2271 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002272};
2273
2274/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002275static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002276 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002277{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002278 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002279
Takashi Iwai668d1e92012-11-29 14:10:17 +01002280 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002281 if (!knew)
2282 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002283 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002284 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002285 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002286 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002287 return 0;
2288}
2289
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002290static int add_control_with_pfx(struct alc_spec *spec, int type,
2291 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002292 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002293{
2294 char name[32];
2295 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002296 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002297}
2298
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002299#define add_pb_vol_ctrl(spec, type, pfx, val) \
2300 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2301#define add_pb_sw_ctrl(spec, type, pfx, val) \
2302 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2303#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2304 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2305#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2306 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002307
Takashi Iwai23c09b02011-08-19 09:05:35 +02002308static const char * const channel_name[4] = {
2309 "Front", "Surround", "CLFE", "Side"
2310};
2311
Takashi Iwai6843ca12011-06-24 11:03:58 +02002312static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2313 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002314{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002315 struct auto_pin_cfg *cfg = &spec->autocfg;
2316
Takashi Iwai6843ca12011-06-24 11:03:58 +02002317 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002318 if (cfg->line_outs == 1 && !spec->multi_ios &&
2319 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002320 return "Master";
2321
2322 switch (cfg->line_out_type) {
2323 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002324 if (cfg->line_outs == 1)
2325 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002326 if (cfg->line_outs == 2)
2327 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002328 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002329 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002330 /* for multi-io case, only the primary out */
2331 if (ch && spec->multi_ios)
2332 break;
2333 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002334 return "Headphone";
2335 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002336 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002337 return "PCM";
2338 break;
2339 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002340 if (ch >= ARRAY_SIZE(channel_name)) {
2341 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002342 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002343 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002344
2345 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002346}
2347
Takashi Iwai83012a72012-08-24 18:38:08 +02002348#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002349/* add the powersave loopback-list entry */
2350static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2351{
2352 struct hda_amp_list *list;
2353
2354 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2355 return;
2356 list = spec->loopback_list + spec->num_loopbacks;
2357 list->nid = mix;
2358 list->dir = HDA_INPUT;
2359 list->idx = idx;
2360 spec->num_loopbacks++;
2361 spec->loopback.amplist = spec->loopback_list;
2362}
2363#else
2364#define add_loopback_list(spec, mix, idx) /* NOP */
2365#endif
2366
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002367/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002368static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002369 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002370 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002371{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002372 struct alc_spec *spec = codec->spec;
2373 struct nid_path *path;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002374 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002375 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002376
Takashi Iwaibd32f782012-12-12 18:08:52 +01002377 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2378 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2379 return 0; /* no need for analog loopback */
2380
Takashi Iwai965cceb2012-12-18 11:46:37 +01002381 path = add_new_nid_path(codec, pin, mix_nid, 2);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002382 if (!path)
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002383 return -EINVAL;
2384
2385 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002386 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002387 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2388 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002389 if (err < 0)
2390 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002391 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002392 }
2393
2394 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002395 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2396 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002397 if (err < 0)
2398 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002399 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002400 }
2401
Takashi Iwai829f69e2012-12-14 18:26:02 +01002402 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002403 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002404 return 0;
2405}
2406
Takashi Iwai05f5f472009-08-25 13:10:18 +02002407static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002408{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002409 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2410 return (pincap & AC_PINCAP_IN) != 0;
2411}
2412
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002413/* check whether the given two widgets can be connected */
2414static bool is_reachable_path(struct hda_codec *codec,
2415 hda_nid_t from_nid, hda_nid_t to_nid)
2416{
2417 if (!from_nid || !to_nid)
2418 return false;
2419 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2420}
2421
Takashi Iwai666a70d2012-12-17 20:29:29 +01002422/* Parse the codec tree and retrieve ADCs */
2423static int alc_auto_fill_adc_nids(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002424{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002425 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002426 hda_nid_t nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002427 hda_nid_t *adc_nids = spec->adc_nids;
2428 int max_nums = ARRAY_SIZE(spec->adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002429 int i, nums = 0;
2430
2431 nid = codec->start_nid;
2432 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwaib7821702011-07-06 15:12:46 +02002433 unsigned int caps = get_wcaps(codec, nid);
2434 int type = get_wcaps_type(caps);
2435
2436 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2437 continue;
2438 adc_nids[nums] = nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002439 if (++nums >= max_nums)
2440 break;
2441 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002442 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002443 return nums;
2444}
2445
Takashi Iwai666a70d2012-12-17 20:29:29 +01002446/* filter out invalid adc_nids that don't give all active input pins;
2447 * if needed, check whether dynamic ADC-switching is available
2448 */
2449static int check_dyn_adc_switch(struct hda_codec *codec)
2450{
2451 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002452 struct hda_input_mux *imux = &spec->input_mux;
2453 hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)];
Takashi Iwai666a70d2012-12-17 20:29:29 +01002454 int i, n, nums;
2455 hda_nid_t pin, adc;
2456
2457 again:
2458 nums = 0;
2459 for (n = 0; n < spec->num_adc_nids; n++) {
2460 adc = spec->adc_nids[n];
2461 for (i = 0; i < imux->num_items; i++) {
2462 pin = spec->imux_pins[i];
2463 if (!is_reachable_path(codec, pin, adc))
2464 break;
2465 }
2466 if (i >= imux->num_items)
2467 adc_nids[nums++] = adc;
2468 }
2469
2470 if (!nums) {
2471 if (spec->shared_mic_hp) {
2472 spec->shared_mic_hp = 0;
Takashi Iwai27d31532012-12-18 08:57:05 +01002473 imux->num_items = 1;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002474 goto again;
2475 }
2476
2477 /* check whether ADC-switch is possible */
2478 for (i = 0; i < imux->num_items; i++) {
2479 pin = spec->imux_pins[i];
2480 for (n = 0; n < spec->num_adc_nids; n++) {
2481 adc = spec->adc_nids[n];
2482 if (is_reachable_path(codec, pin, adc)) {
2483 spec->dyn_adc_idx[i] = n;
2484 break;
2485 }
2486 }
2487 }
2488
2489 snd_printdd("realtek: enabling ADC switching\n");
2490 spec->dyn_adc_switch = 1;
2491 } else if (nums != spec->num_adc_nids) {
Takashi Iwai27d31532012-12-18 08:57:05 +01002492 memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t));
Takashi Iwai666a70d2012-12-17 20:29:29 +01002493 spec->num_adc_nids = nums;
2494 }
2495
Takashi Iwai27d31532012-12-18 08:57:05 +01002496 if (imux->num_items == 1 || spec->shared_mic_hp) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002497 snd_printdd("realtek: reducing to a single ADC\n");
2498 spec->num_adc_nids = 1; /* reduce to a single ADC */
2499 }
2500
2501 return 0;
2502}
2503
2504/* templates for capture controls */
2505static const struct snd_kcontrol_new cap_src_temp = {
2506 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2507 .name = "Input Source",
2508 .info = alc_mux_enum_info,
2509 .get = alc_mux_enum_get,
2510 .put = alc_mux_enum_put,
2511};
2512
2513static const struct snd_kcontrol_new cap_vol_temp = {
2514 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2515 .name = "Capture Volume",
2516 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2517 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2518 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2519 .info = alc_cap_vol_info,
2520 .get = alc_cap_vol_get,
2521 .put = alc_cap_vol_put,
2522 .tlv = { .c = alc_cap_vol_tlv },
2523};
2524
2525static const struct snd_kcontrol_new cap_sw_temp = {
2526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2527 .name = "Capture Switch",
2528 .info = alc_cap_sw_info,
2529 .get = alc_cap_sw_get,
2530 .put = alc_cap_sw_put,
2531};
2532
2533static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2534{
2535 hda_nid_t nid;
2536 int i, depth;
2537
2538 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2539 for (depth = 0; depth < 3; depth++) {
2540 if (depth >= path->depth)
2541 return -EINVAL;
2542 i = path->depth - depth - 1;
2543 nid = path->path[i];
2544 if (!path->ctls[NID_PATH_VOL_CTL]) {
2545 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2546 path->ctls[NID_PATH_VOL_CTL] =
2547 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2548 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2549 int idx = path->idx[i];
2550 if (!depth && codec->single_adc_amp)
2551 idx = 0;
2552 path->ctls[NID_PATH_VOL_CTL] =
2553 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2554 }
2555 }
2556 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2557 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2558 path->ctls[NID_PATH_MUTE_CTL] =
2559 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2560 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2561 int idx = path->idx[i];
2562 if (!depth && codec->single_adc_amp)
2563 idx = 0;
2564 path->ctls[NID_PATH_MUTE_CTL] =
2565 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2566 }
2567 }
2568 }
2569 return 0;
2570}
2571
2572static int create_capture_mixers(struct hda_codec *codec)
2573{
2574 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002575 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002576 struct snd_kcontrol_new *knew;
2577 int i, n, nums;
2578
2579 if (spec->dyn_adc_switch)
2580 nums = 1;
2581 else
2582 nums = spec->num_adc_nids;
2583
2584 if (!spec->auto_mic && imux->num_items > 1) {
2585 knew = alc_kcontrol_new(spec, "Input Source", &cap_src_temp);
2586 if (!knew)
2587 return -ENOMEM;
2588 knew->count = nums;
2589 }
2590
2591 for (n = 0; n < nums; n++) {
2592 int vol, sw;
2593
2594 vol = sw = 0;
2595 for (i = 0; i < imux->num_items; i++) {
2596 struct nid_path *path;
2597 path = get_nid_path(codec, spec->imux_pins[i],
2598 get_adc_nid(codec, n, i));
2599 if (!path)
2600 continue;
2601 parse_capvol_in_path(codec, path);
2602 if (!vol)
2603 vol = path->ctls[NID_PATH_VOL_CTL];
2604 if (!sw)
2605 sw = path->ctls[NID_PATH_MUTE_CTL];
2606 }
2607
2608 if (vol) {
2609 knew = alc_kcontrol_new(spec, "Capture Volume",
2610 &cap_vol_temp);
2611 if (!knew)
2612 return -ENOMEM;
2613 knew->index = n;
2614 knew->private_value = vol;
2615 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2616 }
2617 if (sw) {
2618 knew = alc_kcontrol_new(spec, "Capture Switch",
2619 &cap_sw_temp);
2620 if (!knew)
2621 return -ENOMEM;
2622 knew->index = n;
2623 knew->private_value = sw;
2624 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2625 }
2626 }
2627
2628 return 0;
2629}
2630
Takashi Iwai05f5f472009-08-25 13:10:18 +02002631/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002632static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002633{
2634 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002635 const struct auto_pin_cfg *cfg = &spec->autocfg;
2636 hda_nid_t mixer = spec->mixer_nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002637 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwaib7821702011-07-06 15:12:46 +02002638 int num_adcs;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002639 int i, c, err, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002640 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002641
Takashi Iwai666a70d2012-12-17 20:29:29 +01002642 num_adcs = alc_auto_fill_adc_nids(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002643 if (num_adcs < 0)
2644 return 0;
2645
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002646 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002647 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002648 const char *label;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002649 bool imux_added;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002650
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002651 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002652 if (!alc_is_input_pin(codec, pin))
2653 continue;
2654
David Henningsson5322bf22011-01-05 11:03:56 +01002655 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002656 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2657 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002658 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002659 type_idx++;
2660 else
2661 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002662 prev_label = label;
2663
Takashi Iwai05f5f472009-08-25 13:10:18 +02002664 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002665 if (is_reachable_path(codec, pin, mixer)) {
2666 err = new_analog_input(codec, pin,
2667 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002668 if (err < 0)
2669 return err;
2670 }
2671 }
2672
Takashi Iwai666a70d2012-12-17 20:29:29 +01002673 imux_added = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002674 for (c = 0; c < num_adcs; c++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002675 struct nid_path *path;
2676 hda_nid_t adc = spec->adc_nids[c];
2677
2678 if (!is_reachable_path(codec, pin, adc))
2679 continue;
2680 path = snd_array_new(&spec->paths);
2681 if (!path)
2682 return -ENOMEM;
2683 memset(path, 0, sizeof(*path));
2684 if (!parse_nid_path(codec, pin, adc, 2, path)) {
2685 snd_printd(KERN_ERR
2686 "invalid input path 0x%x -> 0x%x\n",
2687 pin, adc);
2688 spec->paths.used--;
2689 continue;
2690 }
2691
2692 if (!imux_added) {
2693 spec->imux_pins[imux->num_items] = pin;
2694 snd_hda_add_imux_item(imux, label,
2695 imux->num_items, NULL);
2696 imux_added = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002697 }
2698 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002699 }
Takashi Iwai21268962011-07-07 15:01:13 +02002700
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002701 return 0;
2702}
2703
Takashi Iwai24de1832011-11-07 17:13:39 +01002704/* create a shared input with the headphone out */
2705static int alc_auto_create_shared_input(struct hda_codec *codec)
2706{
2707 struct alc_spec *spec = codec->spec;
2708 struct auto_pin_cfg *cfg = &spec->autocfg;
2709 unsigned int defcfg;
2710 hda_nid_t nid;
2711
2712 /* only one internal input pin? */
2713 if (cfg->num_inputs != 1)
2714 return 0;
2715 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2716 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2717 return 0;
2718
2719 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2720 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2721 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2722 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2723 else
2724 return 0; /* both not available */
2725
2726 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2727 return 0; /* no input */
2728
2729 cfg->inputs[1].pin = nid;
2730 cfg->inputs[1].type = AUTO_PIN_MIC;
2731 cfg->num_inputs = 2;
2732 spec->shared_mic_hp = 1;
2733 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2734 return 0;
2735}
2736
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002737static int get_pin_type(int line_out_type)
2738{
2739 if (line_out_type == AUTO_PIN_HP_OUT)
2740 return PIN_HP;
2741 else
2742 return PIN_OUT;
2743}
2744
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002745static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002746{
2747 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002748 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002749 int i;
2750
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002751 for (i = 0; i < cfg->num_inputs; i++) {
2752 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai62343992012-12-18 09:06:01 +01002753 if (alc_is_input_pin(codec, nid))
Takashi Iwai30ea0982010-09-16 18:47:56 +02002754 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002755
Takashi Iwai829f69e2012-12-14 18:26:02 +01002756 /* mute loopback inputs */
2757 if (spec->mixer_nid) {
2758 struct nid_path *path;
2759 path = get_nid_path(codec, nid, spec->mixer_nid);
2760 if (path)
Takashi Iwai666a70d2012-12-17 20:29:29 +01002761 activate_path(codec, path, path->active, false);
Takashi Iwai829f69e2012-12-14 18:26:02 +01002762 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002763 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002764}
2765
Takashi Iwai185d99f2012-02-16 18:39:45 +01002766static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2767{
2768 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002769 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002770
Takashi Iwaic9967f12012-12-14 16:39:22 +01002771 for (i = 0; i < spec->paths.used; i++) {
2772 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002773 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002774 return true;
2775 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002776 return false;
2777}
2778
Takashi Iwai463419d2012-12-05 14:17:37 +01002779/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002780static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2781 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002782{
2783 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002784 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002785 int i;
2786
2787 for (i = 0; i < spec->num_all_dacs; i++) {
2788 hda_nid_t nid = spec->all_dacs[i];
2789 if (!nid || alc_is_dac_already_used(codec, nid))
2790 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002791 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2792 if (is_digital != cap_digital)
2793 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002794 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002795 return nid;
2796 }
2797 return 0;
2798}
2799
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002800/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002801static bool __parse_nid_path(struct hda_codec *codec,
2802 hda_nid_t from_nid, hda_nid_t to_nid,
2803 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002804{
2805 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002806 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002807 int i, nums;
2808
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002809 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002810 if (!with_aa_mix)
2811 return false;
2812 with_aa_mix = 2; /* mark aa-mix is included */
2813 }
2814
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002815 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002816 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002817 if (conn[i] != from_nid) {
2818 /* special case: when from_nid is 0,
2819 * try to find an empty DAC
2820 */
2821 if (from_nid ||
2822 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2823 alc_is_dac_already_used(codec, conn[i]))
2824 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002825 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002826 /* aa-mix is requested but not included? */
2827 if (!(spec->mixer_nid && with_aa_mix == 1))
2828 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002829 }
2830 if (depth >= MAX_NID_PATH_DEPTH)
2831 return false;
2832 for (i = 0; i < nums; i++) {
2833 unsigned int type;
2834 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002835 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2836 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002837 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002838 if (__parse_nid_path(codec, from_nid, conn[i],
2839 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002840 goto found;
2841 }
2842 return false;
2843
2844 found:
2845 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002846 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002847 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002848 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002849 path->depth++;
2850 return true;
2851}
2852
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002853/* parse the widget path from the given nid to the target nid;
2854 * when @from_nid is 0, try to find an empty DAC;
2855 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2856 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2857 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002858 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002859static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2860 hda_nid_t to_nid, int with_aa_mix,
2861 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002862{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002863 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2864 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002865 path->depth++;
2866#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002867 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002868 path->depth, path->path[0], path->path[1],
2869 path->path[2], path->path[3], path->path[4]);
2870#endif
2871 return true;
2872 }
2873 return false;
2874}
2875
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002876static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2877{
Takashi Iwai140547e2012-02-16 17:23:46 +01002878 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002879 int i;
2880 hda_nid_t nid_found = 0;
2881
2882 for (i = 0; i < spec->num_all_dacs; i++) {
2883 hda_nid_t nid = spec->all_dacs[i];
2884 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002885 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002886 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01002887 if (nid_found)
2888 return 0;
2889 nid_found = nid;
2890 }
2891 }
2892 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002893}
2894
Takashi Iwaiba8111272012-12-06 18:06:23 +01002895static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002896{
Takashi Iwaiba8111272012-12-06 18:06:23 +01002897 struct alc_spec *spec = codec->spec;
2898 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002899
Takashi Iwaic9967f12012-12-14 16:39:22 +01002900 for (i = 0; i < spec->paths.used; i++) {
2901 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002902 if (path->ctls[type] == val)
2903 return true;
2904 }
2905 return false;
2906}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002907
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002908/* badness definition */
2909enum {
2910 /* No primary DAC is found for the main output */
2911 BAD_NO_PRIMARY_DAC = 0x10000,
2912 /* No DAC is found for the extra output */
2913 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01002914 /* No possible multi-ios */
2915 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002916 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01002917 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002918 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01002919 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002920 /* Primary DAC shared with main surrounds */
2921 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002922 /* Primary DAC shared with main CLFE */
2923 BAD_SHARED_CLFE = 0x10,
2924 /* Primary DAC shared with extra surrounds */
2925 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01002926 /* Volume widget is shared */
2927 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002928};
2929
2930static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002931 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002932static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002933 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002934
Takashi Iwai965cceb2012-12-18 11:46:37 +01002935static struct nid_path *add_new_nid_path(struct hda_codec *codec,
2936 hda_nid_t from_nid, hda_nid_t to_nid,
2937 int with_aa_mix)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002938{
2939 struct alc_spec *spec = codec->spec;
2940 struct nid_path *path;
2941
Takashi Iwai965cceb2012-12-18 11:46:37 +01002942 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
2943 return NULL;
2944
Takashi Iwaic9967f12012-12-14 16:39:22 +01002945 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002946 if (!path)
Takashi Iwai965cceb2012-12-18 11:46:37 +01002947 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002948 memset(path, 0, sizeof(*path));
Takashi Iwai965cceb2012-12-18 11:46:37 +01002949 if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path))
2950 return path;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002951 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01002952 spec->paths.used--;
Takashi Iwai965cceb2012-12-18 11:46:37 +01002953 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002954}
2955
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002956/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01002957 * passing 0 to either @pin or @dac behaves as a wildcard
2958 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002959static struct nid_path *
2960get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01002961{
2962 struct alc_spec *spec = codec->spec;
2963 int i;
2964
Takashi Iwaic9967f12012-12-14 16:39:22 +01002965 for (i = 0; i < spec->paths.used; i++) {
2966 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002967 if (path->depth <= 0)
2968 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002969 if ((!from_nid || path->path[0] == from_nid) &&
2970 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01002971 return path;
2972 }
2973 return NULL;
2974}
2975
Takashi Iwai792cf2f2012-12-10 16:04:30 +01002976/* look for widgets in the path between the given NIDs appropriate for
2977 * volume and mute controls, and assign the values to ctls[].
2978 *
2979 * When no appropriate widget is found in the path, the badness value
2980 * is incremented depending on the situation. The function returns the
2981 * total badness for both volume and mute controls.
2982 */
2983static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
2984 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002985{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002986 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002987 hda_nid_t nid;
2988 unsigned int val;
2989 int badness = 0;
2990
Takashi Iwaiba8111272012-12-06 18:06:23 +01002991 if (!path)
2992 return BAD_SHARED_VOL * 2;
2993 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002994 if (nid) {
2995 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002996 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002997 badness += BAD_SHARED_VOL;
2998 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01002999 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003000 } else
3001 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003002 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003003 if (nid) {
3004 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003005 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3006 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003007 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3008 else
3009 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003010 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003011 badness += BAD_SHARED_VOL;
3012 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003013 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003014 } else
3015 badness += BAD_SHARED_VOL;
3016 return badness;
3017}
3018
Takashi Iwaidc31b582012-02-17 17:27:53 +01003019struct badness_table {
3020 int no_primary_dac; /* no primary DAC */
3021 int no_dac; /* no secondary DACs */
3022 int shared_primary; /* primary DAC is shared with main output */
3023 int shared_surr; /* secondary DAC shared with main or primary */
3024 int shared_clfe; /* third DAC shared with main or primary */
3025 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3026};
3027
3028static struct badness_table main_out_badness = {
3029 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3030 .no_dac = BAD_NO_DAC,
3031 .shared_primary = BAD_NO_PRIMARY_DAC,
3032 .shared_surr = BAD_SHARED_SURROUND,
3033 .shared_clfe = BAD_SHARED_CLFE,
3034 .shared_surr_main = BAD_SHARED_SURROUND,
3035};
3036
3037static struct badness_table extra_out_badness = {
3038 .no_primary_dac = BAD_NO_DAC,
3039 .no_dac = BAD_NO_DAC,
3040 .shared_primary = BAD_NO_EXTRA_DAC,
3041 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3042 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3043 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3044};
3045
3046/* try to assign DACs to pins and return the resultant badness */
3047static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3048 const hda_nid_t *pins, hda_nid_t *dacs,
3049 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003050{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003051 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003052 struct auto_pin_cfg *cfg = &spec->autocfg;
3053 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003054 int badness = 0;
3055 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003056
Takashi Iwai185d99f2012-02-16 18:39:45 +01003057 if (!num_outs)
3058 return 0;
3059
Takashi Iwaidc31b582012-02-17 17:27:53 +01003060 for (i = 0; i < num_outs; i++) {
3061 hda_nid_t pin = pins[i];
3062 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003063 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003064 if (!dacs[i] && !i) {
3065 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003066 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003067 dacs[0] = dacs[j];
3068 dacs[j] = 0;
3069 break;
3070 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003071 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003072 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003073 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003074 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003075 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003076 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003077 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003078 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003079 dac = spec->private_dac_nids[i];
3080 if (dac) {
3081 if (!i)
3082 badness += bad->shared_primary;
3083 else if (i == 1)
3084 badness += bad->shared_surr;
3085 else
3086 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003087 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003088 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003089 badness += bad->shared_surr_main;
3090 } else if (!i)
3091 badness += bad->no_primary_dac;
3092 else
3093 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003094 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003095 if (!add_new_nid_path(codec, dac, pin, 0))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003096 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003097 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003098 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003099 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003100
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003101 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003102}
3103
3104static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003105 hda_nid_t reference_pin,
3106 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003107
Takashi Iwai185d99f2012-02-16 18:39:45 +01003108static bool alc_map_singles(struct hda_codec *codec, int outs,
3109 const hda_nid_t *pins, hda_nid_t *dacs)
3110{
3111 int i;
3112 bool found = false;
3113 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003114 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003115 if (dacs[i])
3116 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003117 dac = get_dac_if_single(codec, pins[i]);
3118 if (!dac)
3119 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003120 if (add_new_nid_path(codec, dac, pins[i], 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003121 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003122 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003123 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003124 }
3125 return found;
3126}
3127
Takashi Iwai7085ec12009-10-02 09:03:58 +02003128/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003129static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003130 bool fill_hardwired,
3131 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003132{
3133 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003134 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003135 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003136
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003137 /* set num_dacs once to full for alc_auto_look_for_dac() */
3138 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003139 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003140 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3141 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3142 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003143 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003144 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003145 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003146
3147 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003148 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003149 bool mapped;
3150 do {
3151 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003152 cfg->line_out_pins,
3153 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003154 mapped |= alc_map_singles(codec, cfg->hp_outs,
3155 cfg->hp_pins,
3156 spec->multiout.hp_out_nid);
3157 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3158 cfg->speaker_pins,
3159 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003160 if (fill_mio_first && cfg->line_outs == 1 &&
3161 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3162 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3163 if (!err)
3164 mapped = true;
3165 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003166 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003167 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003168
Takashi Iwaidc31b582012-02-17 17:27:53 +01003169 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3170 spec->private_dac_nids,
3171 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003172
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003173 /* re-count num_dacs and squash invalid entries */
3174 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003175 for (i = 0; i < cfg->line_outs; i++) {
3176 if (spec->private_dac_nids[i])
3177 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003178 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003179 memmove(spec->private_dac_nids + i,
3180 spec->private_dac_nids + i + 1,
3181 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003182 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3183 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003184 }
3185
Takashi Iwai276dd702012-02-17 16:17:03 +01003186 if (fill_mio_first &&
3187 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003188 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003189 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003190 if (err < 0)
3191 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003192 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003193 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003194
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003195 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003196 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3197 spec->multiout.hp_out_nid,
3198 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003199 if (err < 0)
3200 return err;
3201 badness += err;
3202 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003203 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003204 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3205 cfg->speaker_pins,
3206 spec->multiout.extra_out_nid,
3207 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003208 if (err < 0)
3209 return err;
3210 badness += err;
3211 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003212 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3213 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003214 if (err < 0)
3215 return err;
3216 badness += err;
3217 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003218 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3219 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003220 int offset = 0;
3221 if (cfg->line_outs >= 3)
3222 offset = 1;
3223 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3224 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003225 if (err < 0)
3226 return err;
3227 badness += err;
3228 }
3229
3230 if (spec->multi_ios == 2) {
3231 for (i = 0; i < 2; i++)
3232 spec->private_dac_nids[spec->multiout.num_dacs++] =
3233 spec->multi_io[i].dac;
3234 spec->ext_channel_count = 2;
3235 } else if (spec->multi_ios) {
3236 spec->multi_ios = 0;
3237 badness += BAD_MULTI_IO;
3238 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003239
3240 return badness;
3241}
3242
3243#define DEBUG_BADNESS
3244
3245#ifdef DEBUG_BADNESS
3246#define debug_badness snd_printdd
3247#else
3248#define debug_badness(...)
3249#endif
3250
3251static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3252{
3253 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3254 cfg->line_out_pins[0], cfg->line_out_pins[1],
3255 cfg->line_out_pins[2], cfg->line_out_pins[2],
3256 spec->multiout.dac_nids[0],
3257 spec->multiout.dac_nids[1],
3258 spec->multiout.dac_nids[2],
3259 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003260 if (spec->multi_ios > 0)
3261 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3262 spec->multi_ios,
3263 spec->multi_io[0].pin, spec->multi_io[1].pin,
3264 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003265 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3266 cfg->hp_pins[0], cfg->hp_pins[1],
3267 cfg->hp_pins[2], cfg->hp_pins[2],
3268 spec->multiout.hp_out_nid[0],
3269 spec->multiout.hp_out_nid[1],
3270 spec->multiout.hp_out_nid[2],
3271 spec->multiout.hp_out_nid[3]);
3272 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3273 cfg->speaker_pins[0], cfg->speaker_pins[1],
3274 cfg->speaker_pins[2], cfg->speaker_pins[3],
3275 spec->multiout.extra_out_nid[0],
3276 spec->multiout.extra_out_nid[1],
3277 spec->multiout.extra_out_nid[2],
3278 spec->multiout.extra_out_nid[3]);
3279}
3280
Takashi Iwai463419d2012-12-05 14:17:37 +01003281/* find all available DACs of the codec */
3282static void alc_fill_all_nids(struct hda_codec *codec)
3283{
3284 struct alc_spec *spec = codec->spec;
3285 int i;
3286 hda_nid_t nid = codec->start_nid;
3287
3288 spec->num_all_dacs = 0;
3289 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3290 for (i = 0; i < codec->num_nodes; i++, nid++) {
3291 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3292 continue;
3293 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3294 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3295 break;
3296 }
3297 spec->all_dacs[spec->num_all_dacs++] = nid;
3298 }
3299}
3300
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003301static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3302{
3303 struct alc_spec *spec = codec->spec;
3304 struct auto_pin_cfg *cfg = &spec->autocfg;
3305 struct auto_pin_cfg *best_cfg;
3306 int best_badness = INT_MAX;
3307 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003308 bool fill_hardwired = true, fill_mio_first = true;
3309 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003310 bool hp_spk_swapped = false;
3311
Takashi Iwai463419d2012-12-05 14:17:37 +01003312 alc_fill_all_nids(codec);
3313
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003314 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3315 if (!best_cfg)
3316 return -ENOMEM;
3317 *best_cfg = *cfg;
3318
3319 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003320 badness = fill_and_eval_dacs(codec, fill_hardwired,
3321 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003322 if (badness < 0) {
3323 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003324 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003325 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003326 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3327 cfg->line_out_type, fill_hardwired, fill_mio_first,
3328 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003329 debug_show_configs(spec, cfg);
3330 if (badness < best_badness) {
3331 best_badness = badness;
3332 *best_cfg = *cfg;
3333 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003334 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003335 }
3336 if (!badness)
3337 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003338 fill_mio_first = !fill_mio_first;
3339 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003340 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003341 fill_hardwired = !fill_hardwired;
3342 if (!fill_hardwired)
3343 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003344 if (hp_spk_swapped)
3345 break;
3346 hp_spk_swapped = true;
3347 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003348 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3349 cfg->hp_outs = cfg->line_outs;
3350 memcpy(cfg->hp_pins, cfg->line_out_pins,
3351 sizeof(cfg->hp_pins));
3352 cfg->line_outs = cfg->speaker_outs;
3353 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3354 sizeof(cfg->speaker_pins));
3355 cfg->speaker_outs = 0;
3356 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3357 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003358 fill_hardwired = true;
3359 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003360 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003361 if (cfg->hp_outs > 0 &&
3362 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3363 cfg->speaker_outs = cfg->line_outs;
3364 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3365 sizeof(cfg->speaker_pins));
3366 cfg->line_outs = cfg->hp_outs;
3367 memcpy(cfg->line_out_pins, cfg->hp_pins,
3368 sizeof(cfg->hp_pins));
3369 cfg->hp_outs = 0;
3370 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3371 cfg->line_out_type = AUTO_PIN_HP_OUT;
3372 fill_hardwired = true;
3373 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003374 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003375 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003376 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003377
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003378 if (badness) {
3379 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003380 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003381 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003382 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3383 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003384 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003385
Takashi Iwaiba8111272012-12-06 18:06:23 +01003386 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003387 struct nid_path *path = get_nid_path(codec,
3388 spec->multiout.dac_nids[0],
3389 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003390 if (path)
3391 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3392 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003393
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003394 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003395 return 0;
3396}
3397
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003398/* replace the channels in the composed amp value with the given number */
3399static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3400{
3401 val &= ~(0x3U << 16);
3402 val |= chs << 16;
3403 return val;
3404}
3405
Takashi Iwai343a04b2011-07-06 14:28:39 +02003406static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003407 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003408 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003409 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003410{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003411 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003412 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003413 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003414 val = path->ctls[NID_PATH_VOL_CTL];
3415 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003416 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003417 val = amp_val_replace_channels(val, chs);
3418 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3419}
3420
3421/* return the channel bits suitable for the given path->ctls[] */
3422static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3423 int type)
3424{
3425 int chs = 1; /* mono (left only) */
3426 if (path) {
3427 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3428 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3429 chs = 3; /* stereo */
3430 }
3431 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003432}
3433
Takashi Iwaie29d3772011-11-14 17:13:23 +01003434static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3435 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003436 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003437{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003438 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3439 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003440}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003441
3442/* create a mute-switch for the given mixer widget;
3443 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3444 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003445static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003446 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003447 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003448 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003449{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003450 unsigned int val;
3451 int type = ALC_CTL_WIDGET_MUTE;
3452
3453 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003454 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003455 val = path->ctls[NID_PATH_MUTE_CTL];
3456 if (!val)
3457 return 0;
3458 val = amp_val_replace_channels(val, chs);
3459 if (get_amp_direction_(val) == HDA_INPUT) {
3460 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003461 int nums = snd_hda_get_num_conns(codec, nid);
3462 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003463 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003464 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003465 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003466 }
3467 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003468}
3469
Takashi Iwaie29d3772011-11-14 17:13:23 +01003470static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003471 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003472{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003473 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3474 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003475}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003476
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003477static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003478 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003479{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003480 int i;
3481
3482 for (i = path->depth - 1; i >= 0; i--) {
3483 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3484 return path->path[i];
3485 if (i != path->depth - 1 && i != 0 &&
3486 nid_has_mute(codec, path->path[i], HDA_INPUT))
3487 return path->path[i];
3488 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003489 return 0;
3490}
3491
3492static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003493 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003494{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003495 int i;
3496
3497 for (i = path->depth - 1; i >= 0; i--) {
3498 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3499 return path->path[i];
3500 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003501 return 0;
3502}
3503
Takashi Iwai7085ec12009-10-02 09:03:58 +02003504/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003505static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003506 const struct auto_pin_cfg *cfg)
3507{
3508 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003509 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003510
Takashi Iwaice764ab2011-04-27 16:35:23 +02003511 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003512 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003513 noutputs += spec->multi_ios;
3514
3515 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003516 const char *name;
3517 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003518 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003519 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003520
3521 dac = spec->multiout.dac_nids[i];
3522 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003523 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003524 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003525 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003526 index = 0;
3527 name = channel_name[i];
3528 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003529 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003530 name = alc_get_line_out_pfx(spec, i, true, &index);
3531 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003532
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003533 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003534 if (!path)
3535 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003536 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003537 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003538 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003539 if (err < 0)
3540 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003541 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003542 if (err < 0)
3543 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003544 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003545 if (err < 0)
3546 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003547 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003548 if (err < 0)
3549 return err;
3550 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003551 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003552 if (err < 0)
3553 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003554 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003555 if (err < 0)
3556 return err;
3557 }
3558 }
3559 return 0;
3560}
3561
Takashi Iwai343a04b2011-07-06 14:28:39 +02003562static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003563 hda_nid_t dac, const char *pfx,
3564 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003565{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003566 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003567 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003568
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003569 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003570 if (!path)
3571 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003572 /* bind volume control will be created in the case of dac = 0 */
3573 if (dac) {
3574 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3575 if (err < 0)
3576 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003577 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003578 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003579 if (err < 0)
3580 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003581 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003582}
3583
Takashi Iwai23c09b02011-08-19 09:05:35 +02003584static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3585 unsigned int nums,
3586 struct hda_ctl_ops *ops)
3587{
3588 struct alc_spec *spec = codec->spec;
3589 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003590 ctlp = snd_array_new(&spec->bind_ctls);
3591 if (!ctlp)
3592 return NULL;
3593 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3594 *ctlp = ctl;
3595 if (ctl)
3596 ctl->ops = ops;
3597 return ctl;
3598}
3599
3600/* add playback controls for speaker and HP outputs */
3601static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3602 const hda_nid_t *pins,
3603 const hda_nid_t *dacs,
3604 const char *pfx)
3605{
3606 struct alc_spec *spec = codec->spec;
3607 struct hda_bind_ctls *ctl;
3608 char name[32];
3609 int i, n, err;
3610
3611 if (!num_pins || !pins[0])
3612 return 0;
3613
Takashi Iwai527e4d72011-10-27 16:33:27 +02003614 if (num_pins == 1) {
3615 hda_nid_t dac = *dacs;
3616 if (!dac)
3617 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003618 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003619 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003620
Takashi Iwai23c09b02011-08-19 09:05:35 +02003621 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003622 hda_nid_t dac;
3623 if (dacs[num_pins - 1])
3624 dac = dacs[i]; /* with individual volumes */
3625 else
3626 dac = 0;
3627 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3628 err = alc_auto_create_extra_out(codec, pins[i], dac,
3629 "Bass Speaker", 0);
3630 } else if (num_pins >= 3) {
3631 snprintf(name, sizeof(name), "%s %s",
3632 pfx, channel_name[i]);
3633 err = alc_auto_create_extra_out(codec, pins[i], dac,
3634 name, 0);
3635 } else {
3636 err = alc_auto_create_extra_out(codec, pins[i], dac,
3637 pfx, i);
3638 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003639 if (err < 0)
3640 return err;
3641 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003642 if (dacs[num_pins - 1])
3643 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003644
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003645 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003646 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3647 if (!ctl)
3648 return -ENOMEM;
3649 n = 0;
3650 for (i = 0; i < num_pins; i++) {
3651 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003652 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003653 if (!pins[i] || !dacs[i])
3654 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003655 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003656 if (!path)
3657 continue;
3658 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003659 if (vol)
3660 ctl->values[n++] =
3661 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3662 }
3663 if (n) {
3664 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3665 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3666 if (err < 0)
3667 return err;
3668 }
3669 return 0;
3670}
3671
Takashi Iwai343a04b2011-07-06 14:28:39 +02003672static int alc_auto_create_hp_out(struct hda_codec *codec)
3673{
3674 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003675 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3676 spec->autocfg.hp_pins,
3677 spec->multiout.hp_out_nid,
3678 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003679}
3680
3681static int alc_auto_create_speaker_out(struct hda_codec *codec)
3682{
3683 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003684 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3685 spec->autocfg.speaker_pins,
3686 spec->multiout.extra_out_nid,
3687 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003688}
3689
Takashi Iwai130e5f02012-12-14 16:09:29 +01003690/* check whether a control with the given (nid, dir, idx) was assigned */
3691static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3692 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003693{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003694 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003695 int i, type;
3696
3697 for (i = 0; i < spec->paths.used; i++) {
3698 struct nid_path *p = snd_array_elem(&spec->paths, i);
3699 if (p->depth <= 0)
3700 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003701 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003702 unsigned int val = p->ctls[type];
3703 if (get_amp_nid_(val) == nid &&
3704 get_amp_direction_(val) == dir &&
3705 get_amp_index_(val) == idx)
3706 return true;
3707 }
3708 }
3709 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003710}
3711
3712/* can have the amp-in capability? */
3713static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3714{
3715 hda_nid_t nid = path->path[idx];
3716 unsigned int caps = get_wcaps(codec, nid);
3717 unsigned int type = get_wcaps_type(caps);
3718
3719 if (!(caps & AC_WCAP_IN_AMP))
3720 return false;
3721 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3722 return false;
3723 return true;
3724}
3725
3726/* can have the amp-out capability? */
3727static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3728{
3729 hda_nid_t nid = path->path[idx];
3730 unsigned int caps = get_wcaps(codec, nid);
3731 unsigned int type = get_wcaps_type(caps);
3732
3733 if (!(caps & AC_WCAP_OUT_AMP))
3734 return false;
3735 if (type == AC_WID_PIN && !idx) /* only for output pins */
3736 return false;
3737 return true;
3738}
3739
Takashi Iwaic9967f12012-12-14 16:39:22 +01003740/* check whether the given (nid,dir,idx) is active */
3741static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3742 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003743{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003744 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003745 int i, n;
3746
Takashi Iwaic9967f12012-12-14 16:39:22 +01003747 for (n = 0; n < spec->paths.used; n++) {
3748 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003749 if (!path->active)
3750 continue;
3751 for (i = 0; i < path->depth; i++) {
3752 if (path->path[i] == nid) {
3753 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3754 return true;
3755 break;
3756 }
3757 }
3758 }
3759 return false;
3760}
3761
Takashi Iwai130e5f02012-12-14 16:09:29 +01003762/* get the default amp value for the target state */
3763static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3764 int dir, bool enable)
3765{
3766 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003767 unsigned int val = 0;
3768
3769 caps = query_amp_caps(codec, nid, dir);
3770 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003771 /* set to 0dB */
3772 if (enable)
3773 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003774 }
3775 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003776 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003777 val |= HDA_AMP_MUTE;
3778 }
3779 return val;
3780}
3781
Takashi Iwai130e5f02012-12-14 16:09:29 +01003782/* initialize the amp value (only at the first time) */
3783static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3784{
3785 int val = get_amp_val_to_activate(codec, nid, dir, false);
3786 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3787}
3788
3789static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3790 int idx, bool enable)
3791{
3792 int val;
3793 if (is_ctl_associated(codec, nid, dir, idx) ||
3794 is_active_nid(codec, nid, dir, idx))
3795 return;
3796 val = get_amp_val_to_activate(codec, nid, dir, enable);
3797 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3798}
3799
3800static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3801 int i, bool enable)
3802{
3803 hda_nid_t nid = path->path[i];
3804 init_amp(codec, nid, HDA_OUTPUT, 0);
3805 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3806}
3807
3808static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003809 int i, bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003810{
3811 struct alc_spec *spec = codec->spec;
3812 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003813 int n, nums, idx;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003814 int type;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003815 hda_nid_t nid = path->path[i];
3816
3817 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai666a70d2012-12-17 20:29:29 +01003818 type = get_wcaps_type(get_wcaps(codec, nid));
3819 if (type == AC_WID_PIN ||
3820 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003821 nums = 1;
3822 idx = 0;
3823 } else
3824 idx = path->idx[i];
3825
Takashi Iwai130e5f02012-12-14 16:09:29 +01003826 for (n = 0; n < nums; n++)
3827 init_amp(codec, nid, HDA_INPUT, n);
3828
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003829 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003830 return;
3831
3832 /* here is a little bit tricky in comparison with activate_amp_out();
3833 * when aa-mixer is available, we need to enable the path as well
3834 */
3835 for (n = 0; n < nums; n++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01003836 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003837 continue;
3838 activate_amp(codec, nid, HDA_INPUT, n, enable);
3839 }
3840}
3841
3842static void activate_path(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003843 bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003844{
3845 int i;
3846
Takashi Iwai130e5f02012-12-14 16:09:29 +01003847 if (!enable)
3848 path->active = false;
3849
3850 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003851 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003852 snd_hda_codec_write_cache(codec, path->path[i], 0,
3853 AC_VERB_SET_CONNECT_SEL,
3854 path->idx[i]);
3855 if (has_amp_in(codec, path, i))
Takashi Iwai666a70d2012-12-17 20:29:29 +01003856 activate_amp_in(codec, path, i, enable, add_aamix);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003857 if (has_amp_out(codec, path, i))
3858 activate_amp_out(codec, path, i, enable);
3859 }
3860
3861 if (enable)
3862 path->active = true;
3863}
3864
Takashi Iwai78e635c2012-12-10 17:07:16 +01003865/* configure the path from the given dac to the pin as the proper output */
3866static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3867 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003868 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003869{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003870 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003871
Takashi Iwai130e5f02012-12-14 16:09:29 +01003872 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003873 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003874 if (!path)
3875 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003876 if (path->active)
3877 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003878 activate_path(codec, path, true, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003879}
3880
Takashi Iwai343a04b2011-07-06 14:28:39 +02003881static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003882{
3883 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003884 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003885 int i;
3886
3887 for (i = 0; i <= HDA_SIDE; i++) {
3888 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3889 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003890 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003891 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003892
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003893 }
3894}
3895
Takashi Iwai343a04b2011-07-06 14:28:39 +02003896static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003897{
3898 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003899 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003900 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003901
David Henningsson636030e2011-10-12 19:26:03 +02003902 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003903 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3904 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003905 pin = spec->autocfg.hp_pins[i];
3906 if (!pin)
3907 break;
3908 dac = spec->multiout.hp_out_nid[i];
3909 if (!dac) {
3910 if (i > 0 && spec->multiout.hp_out_nid[0])
3911 dac = spec->multiout.hp_out_nid[0];
3912 else
3913 dac = spec->multiout.dac_nids[0];
3914 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003915 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003916 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003917 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003918 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3919 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003920 pin = spec->autocfg.speaker_pins[i];
3921 if (!pin)
3922 break;
3923 dac = spec->multiout.extra_out_nid[i];
3924 if (!dac) {
3925 if (i > 0 && spec->multiout.extra_out_nid[0])
3926 dac = spec->multiout.extra_out_nid[0];
3927 else
3928 dac = spec->multiout.dac_nids[0];
3929 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003930 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003931 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003932}
3933
Takashi Iwai276dd702012-02-17 16:17:03 +01003934/* check whether the given pin can be a multi-io pin */
3935static bool can_be_multiio_pin(struct hda_codec *codec,
3936 unsigned int location, hda_nid_t nid)
3937{
3938 unsigned int defcfg, caps;
3939
3940 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3941 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3942 return false;
3943 if (location && get_defcfg_location(defcfg) != location)
3944 return false;
3945 caps = snd_hda_query_pin_caps(codec, nid);
3946 if (!(caps & AC_PINCAP_OUT))
3947 return false;
3948 return true;
3949}
3950
Takashi Iwaice764ab2011-04-27 16:35:23 +02003951/*
3952 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003953 *
3954 * When hardwired is set, try to fill ony hardwired pins, and returns
3955 * zero if any pins are filled, non-zero if nothing found.
3956 * When hardwired is off, try to fill possible input pins, and returns
3957 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003958 */
3959static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003960 hda_nid_t reference_pin,
3961 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003962{
3963 struct alc_spec *spec = codec->spec;
3964 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003965 int type, i, j, dacs, num_pins, old_pins;
3966 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3967 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003968 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003969
Takashi Iwai276dd702012-02-17 16:17:03 +01003970 old_pins = spec->multi_ios;
3971 if (old_pins >= 2)
3972 goto end_fill;
3973
3974 num_pins = 0;
3975 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3976 for (i = 0; i < cfg->num_inputs; i++) {
3977 if (cfg->inputs[i].type != type)
3978 continue;
3979 if (can_be_multiio_pin(codec, location,
3980 cfg->inputs[i].pin))
3981 num_pins++;
3982 }
3983 }
3984 if (num_pins < 2)
3985 goto end_fill;
3986
Takashi Iwai07b18f62011-11-10 15:42:54 +01003987 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003988 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3989 for (i = 0; i < cfg->num_inputs; i++) {
3990 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003991 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003992
Takashi Iwaice764ab2011-04-27 16:35:23 +02003993 if (cfg->inputs[i].type != type)
3994 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003995 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003996 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003997 for (j = 0; j < spec->multi_ios; j++) {
3998 if (nid == spec->multi_io[j].pin)
3999 break;
4000 }
4001 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004002 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004003
4004 if (offset && offset + spec->multi_ios < dacs) {
4005 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004006 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004007 dac = 0;
4008 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004009 if (hardwired)
4010 dac = get_dac_if_single(codec, nid);
4011 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004012 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004013 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004014 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004015 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004016 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01004017 if (!add_new_nid_path(codec, dac, nid, 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004018 badness++;
4019 continue;
4020 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004021 spec->multi_io[spec->multi_ios].pin = nid;
4022 spec->multi_io[spec->multi_ios].dac = dac;
4023 spec->multi_ios++;
4024 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004025 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004026 }
4027 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004028 end_fill:
4029 if (badness)
4030 badness = BAD_MULTI_IO;
4031 if (old_pins == spec->multi_ios) {
4032 if (hardwired)
4033 return 1; /* nothing found */
4034 else
4035 return badness; /* no badness if nothing found */
4036 }
4037 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004038 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004039 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004040 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004041 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004042 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004043
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004044 /* assign volume and mute controls */
4045 for (i = old_pins; i < spec->multi_ios; i++)
4046 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4047 spec->multi_io[i].dac);
4048
4049 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004050}
4051
4052static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4053 struct snd_ctl_elem_info *uinfo)
4054{
4055 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4056 struct alc_spec *spec = codec->spec;
4057
4058 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4059 uinfo->count = 1;
4060 uinfo->value.enumerated.items = spec->multi_ios + 1;
4061 if (uinfo->value.enumerated.item > spec->multi_ios)
4062 uinfo->value.enumerated.item = spec->multi_ios;
4063 sprintf(uinfo->value.enumerated.name, "%dch",
4064 (uinfo->value.enumerated.item + 1) * 2);
4065 return 0;
4066}
4067
4068static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4069 struct snd_ctl_elem_value *ucontrol)
4070{
4071 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4072 struct alc_spec *spec = codec->spec;
4073 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4074 return 0;
4075}
4076
4077static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4078{
4079 struct alc_spec *spec = codec->spec;
4080 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004081 struct nid_path *path;
4082
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004083 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004084 if (!path)
4085 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004086
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004087 if (path->active == output)
4088 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004089
Takashi Iwaice764ab2011-04-27 16:35:23 +02004090 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004091 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004092 activate_path(codec, path, true, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004093 } else {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004094 activate_path(codec, path, false, true);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004095 snd_hda_set_pin_ctl_cache(codec, nid,
4096 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004097 }
4098 return 0;
4099}
4100
4101static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4102 struct snd_ctl_elem_value *ucontrol)
4103{
4104 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4105 struct alc_spec *spec = codec->spec;
4106 int i, ch;
4107
4108 ch = ucontrol->value.enumerated.item[0];
4109 if (ch < 0 || ch > spec->multi_ios)
4110 return -EINVAL;
4111 if (ch == (spec->ext_channel_count - 1) / 2)
4112 return 0;
4113 spec->ext_channel_count = (ch + 1) * 2;
4114 for (i = 0; i < spec->multi_ios; i++)
4115 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004116 spec->multiout.max_channels = max(spec->ext_channel_count,
4117 spec->const_channel_count);
4118 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004119 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004120 return 1;
4121}
4122
Takashi Iwaia9111322011-05-02 11:30:18 +02004123static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004124 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4125 .name = "Channel Mode",
4126 .info = alc_auto_ch_mode_info,
4127 .get = alc_auto_ch_mode_get,
4128 .put = alc_auto_ch_mode_put,
4129};
4130
Takashi Iwai23c09b02011-08-19 09:05:35 +02004131static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004132{
4133 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004134
Takashi Iwaic2674682011-08-24 17:57:44 +02004135 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004136 if (!alc_kcontrol_new(spec, "Channel Mode",
4137 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004138 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004139 }
4140 return 0;
4141}
4142
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004143static void alc_auto_init_multi_io(struct hda_codec *codec)
4144{
4145 struct alc_spec *spec = codec->spec;
4146 int i;
4147
4148 for (i = 0; i < spec->multi_ios; i++) {
4149 hda_nid_t pin = spec->multi_io[i].pin;
4150 struct nid_path *path;
4151 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4152 if (!path)
4153 continue;
4154 if (!spec->multi_io[i].ctl_in)
4155 spec->multi_io[i].ctl_in =
4156 snd_hda_codec_update_cache(codec, pin, 0,
4157 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004158 activate_path(codec, path, path->active, true);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004159 }
4160}
4161
Takashi Iwai1d045db2011-07-07 18:23:21 +02004162/*
4163 * initialize ADC paths
4164 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004165static void alc_auto_init_input_src(struct hda_codec *codec)
4166{
4167 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01004168 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004169 struct nid_path *path;
4170 int i, c, nums;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004171
Takashi Iwai1d045db2011-07-07 18:23:21 +02004172 if (spec->dyn_adc_switch)
4173 nums = 1;
4174 else
4175 nums = spec->num_adc_nids;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004176
4177 for (c = 0; c < nums; c++) {
4178 for (i = 0; i < imux->num_items; i++) {
4179 path = get_nid_path(codec, spec->imux_pins[i],
4180 get_adc_nid(codec, c, i));
4181 if (path) {
4182 bool active = path->active;
4183 if (i == spec->cur_mux[c])
4184 active = true;
4185 activate_path(codec, path, active, false);
4186 }
4187 }
4188 }
4189
4190 alc_inv_dmic_sync(codec, true);
4191 if (spec->shared_mic_hp)
4192 update_shared_mic_hp(codec, spec->cur_mux[0]);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004193}
4194
4195/* add mic boosts if needed */
4196static int alc_auto_add_mic_boost(struct hda_codec *codec)
4197{
4198 struct alc_spec *spec = codec->spec;
4199 struct auto_pin_cfg *cfg = &spec->autocfg;
4200 int i, err;
4201 int type_idx = 0;
4202 hda_nid_t nid;
4203 const char *prev_label = NULL;
4204
4205 for (i = 0; i < cfg->num_inputs; i++) {
4206 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4207 break;
4208 nid = cfg->inputs[i].pin;
4209 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4210 const char *label;
4211 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004212 struct nid_path *path;
4213 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004214
4215 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004216 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4217 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004218 if (prev_label && !strcmp(label, prev_label))
4219 type_idx++;
4220 else
4221 type_idx = 0;
4222 prev_label = label;
4223
4224 snprintf(boost_label, sizeof(boost_label),
4225 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004226 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004227 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004228 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004229 if (err < 0)
4230 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004231
4232 path = get_nid_path(codec, nid, 0);
4233 if (path)
4234 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004235 }
4236 }
4237 return 0;
4238}
4239
Takashi Iwai1d045db2011-07-07 18:23:21 +02004240/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004241 * standard auto-parser initializations
4242 */
4243static void alc_auto_init_std(struct hda_codec *codec)
4244{
Takashi Iwaie4770622011-07-08 11:11:35 +02004245 alc_auto_init_multi_out(codec);
4246 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004247 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004248 alc_auto_init_analog_input(codec);
4249 alc_auto_init_input_src(codec);
4250 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004251 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004252}
4253
4254/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004255 * Digital-beep handlers
4256 */
4257#ifdef CONFIG_SND_HDA_INPUT_BEEP
4258#define set_beep_amp(spec, nid, idx, dir) \
4259 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4260
4261static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004262 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004263 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4264 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4265 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4266 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004267 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004268 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4269 {}
4270};
4271
4272static inline int has_cdefine_beep(struct hda_codec *codec)
4273{
4274 struct alc_spec *spec = codec->spec;
4275 const struct snd_pci_quirk *q;
4276 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4277 if (q)
4278 return q->value;
4279 return spec->cdefine.enable_pcbeep;
4280}
4281#else
4282#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4283#define has_cdefine_beep(codec) 0
4284#endif
4285
4286/* parse the BIOS configuration and set up the alc_spec */
4287/* return 1 if successful, 0 if the proper config is not found,
4288 * or a negative error code
4289 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004290static int alc_parse_auto_config(struct hda_codec *codec,
4291 const hda_nid_t *ignore_nids,
4292 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004293{
4294 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004295 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004296 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004297
Takashi Iwai53c334a2011-08-23 18:27:14 +02004298 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4299 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004300 if (err < 0)
4301 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004302 if (!cfg->line_outs) {
4303 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004304 spec->multiout.max_channels = 2;
4305 spec->no_analog = 1;
4306 goto dig_only;
4307 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004308 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004309 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004310
Takashi Iwaie427c232012-07-29 10:04:08 +02004311 if (!spec->no_primary_hp &&
4312 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004313 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004314 /* use HP as primary out */
4315 cfg->speaker_outs = cfg->line_outs;
4316 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4317 sizeof(cfg->speaker_pins));
4318 cfg->line_outs = cfg->hp_outs;
4319 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4320 cfg->hp_outs = 0;
4321 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4322 cfg->line_out_type = AUTO_PIN_HP_OUT;
4323 }
4324
Takashi Iwai1d045db2011-07-07 18:23:21 +02004325 err = alc_auto_fill_dac_nids(codec);
4326 if (err < 0)
4327 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004328 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004329 if (err < 0)
4330 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004331 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004332 if (err < 0)
4333 return err;
4334 err = alc_auto_create_hp_out(codec);
4335 if (err < 0)
4336 return err;
4337 err = alc_auto_create_speaker_out(codec);
4338 if (err < 0)
4339 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004340 err = alc_auto_create_shared_input(codec);
4341 if (err < 0)
4342 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004343 err = alc_auto_create_input_ctls(codec);
4344 if (err < 0)
4345 return err;
4346
Takashi Iwaib6adb572012-12-03 10:30:58 +01004347 /* check the multiple speaker pins */
4348 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4349 spec->const_channel_count = cfg->line_outs * 2;
4350 else
4351 spec->const_channel_count = cfg->speaker_outs * 2;
4352
4353 if (spec->multi_ios > 0)
4354 spec->multiout.max_channels = max(spec->ext_channel_count,
4355 spec->const_channel_count);
4356 else
4357 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004358
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004359 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004360 alc_auto_parse_digital(codec);
4361
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004362 if (ssid_nids)
4363 alc_ssid_check(codec, ssid_nids);
4364
4365 if (!spec->no_analog) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004366 err = alc_init_automute(codec);
Takashi Iwai475c3d22012-11-30 08:31:30 +01004367 if (err < 0)
4368 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004369
4370 err = check_dyn_adc_switch(codec);
4371 if (err < 0)
4372 return err;
4373
4374 if (!spec->shared_mic_hp) {
4375 err = alc_init_auto_mic(codec);
4376 if (err < 0)
4377 return err;
4378 }
4379
4380 err = create_capture_mixers(codec);
4381 if (err < 0)
4382 return err;
4383
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004384 err = alc_auto_add_mic_boost(codec);
4385 if (err < 0)
4386 return err;
4387 }
4388
Takashi Iwai1d045db2011-07-07 18:23:21 +02004389 if (spec->kctls.list)
4390 add_mixer(spec, spec->kctls.list);
4391
Takashi Iwai1d045db2011-07-07 18:23:21 +02004392 return 1;
4393}
4394
Takashi Iwai3de95172012-05-07 18:03:15 +02004395/* common preparation job for alc_spec */
4396static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4397{
4398 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4399 int err;
4400
4401 if (!spec)
4402 return -ENOMEM;
4403 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004404 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004405 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004406 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004407 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4408 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004409 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004410
4411 err = alc_codec_rename_from_preset(codec);
4412 if (err < 0) {
4413 kfree(spec);
4414 return err;
4415 }
4416 return 0;
4417}
4418
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004419static int alc880_parse_auto_config(struct hda_codec *codec)
4420{
4421 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004422 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004423 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4424}
4425
Takashi Iwai1d045db2011-07-07 18:23:21 +02004426/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004427 * ALC880 fix-ups
4428 */
4429enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004430 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004431 ALC880_FIXUP_GPIO2,
4432 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004433 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004434 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004435 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004436 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004437 ALC880_FIXUP_VOL_KNOB,
4438 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004439 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004440 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004441 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004442 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004443 ALC880_FIXUP_3ST_BASE,
4444 ALC880_FIXUP_3ST,
4445 ALC880_FIXUP_3ST_DIG,
4446 ALC880_FIXUP_5ST_BASE,
4447 ALC880_FIXUP_5ST,
4448 ALC880_FIXUP_5ST_DIG,
4449 ALC880_FIXUP_6ST_BASE,
4450 ALC880_FIXUP_6ST,
4451 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004452};
4453
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004454/* enable the volume-knob widget support on NID 0x21 */
4455static void alc880_fixup_vol_knob(struct hda_codec *codec,
4456 const struct alc_fixup *fix, int action)
4457{
4458 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004459 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004460}
4461
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004462static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004463 [ALC880_FIXUP_GPIO1] = {
4464 .type = ALC_FIXUP_VERBS,
4465 .v.verbs = alc_gpio1_init_verbs,
4466 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004467 [ALC880_FIXUP_GPIO2] = {
4468 .type = ALC_FIXUP_VERBS,
4469 .v.verbs = alc_gpio2_init_verbs,
4470 },
4471 [ALC880_FIXUP_MEDION_RIM] = {
4472 .type = ALC_FIXUP_VERBS,
4473 .v.verbs = (const struct hda_verb[]) {
4474 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4475 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4476 { }
4477 },
4478 .chained = true,
4479 .chain_id = ALC880_FIXUP_GPIO2,
4480 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004481 [ALC880_FIXUP_LG] = {
4482 .type = ALC_FIXUP_PINS,
4483 .v.pins = (const struct alc_pincfg[]) {
4484 /* disable bogus unused pins */
4485 { 0x16, 0x411111f0 },
4486 { 0x18, 0x411111f0 },
4487 { 0x1a, 0x411111f0 },
4488 { }
4489 }
4490 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004491 [ALC880_FIXUP_W810] = {
4492 .type = ALC_FIXUP_PINS,
4493 .v.pins = (const struct alc_pincfg[]) {
4494 /* disable bogus unused pins */
4495 { 0x17, 0x411111f0 },
4496 { }
4497 },
4498 .chained = true,
4499 .chain_id = ALC880_FIXUP_GPIO2,
4500 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004501 [ALC880_FIXUP_EAPD_COEF] = {
4502 .type = ALC_FIXUP_VERBS,
4503 .v.verbs = (const struct hda_verb[]) {
4504 /* change to EAPD mode */
4505 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4506 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4507 {}
4508 },
4509 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004510 [ALC880_FIXUP_TCL_S700] = {
4511 .type = ALC_FIXUP_VERBS,
4512 .v.verbs = (const struct hda_verb[]) {
4513 /* change to EAPD mode */
4514 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4515 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4516 {}
4517 },
4518 .chained = true,
4519 .chain_id = ALC880_FIXUP_GPIO2,
4520 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004521 [ALC880_FIXUP_VOL_KNOB] = {
4522 .type = ALC_FIXUP_FUNC,
4523 .v.func = alc880_fixup_vol_knob,
4524 },
4525 [ALC880_FIXUP_FUJITSU] = {
4526 /* override all pins as BIOS on old Amilo is broken */
4527 .type = ALC_FIXUP_PINS,
4528 .v.pins = (const struct alc_pincfg[]) {
4529 { 0x14, 0x0121411f }, /* HP */
4530 { 0x15, 0x99030120 }, /* speaker */
4531 { 0x16, 0x99030130 }, /* bass speaker */
4532 { 0x17, 0x411111f0 }, /* N/A */
4533 { 0x18, 0x411111f0 }, /* N/A */
4534 { 0x19, 0x01a19950 }, /* mic-in */
4535 { 0x1a, 0x411111f0 }, /* N/A */
4536 { 0x1b, 0x411111f0 }, /* N/A */
4537 { 0x1c, 0x411111f0 }, /* N/A */
4538 { 0x1d, 0x411111f0 }, /* N/A */
4539 { 0x1e, 0x01454140 }, /* SPDIF out */
4540 { }
4541 },
4542 .chained = true,
4543 .chain_id = ALC880_FIXUP_VOL_KNOB,
4544 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004545 [ALC880_FIXUP_F1734] = {
4546 /* almost compatible with FUJITSU, but no bass and SPDIF */
4547 .type = ALC_FIXUP_PINS,
4548 .v.pins = (const struct alc_pincfg[]) {
4549 { 0x14, 0x0121411f }, /* HP */
4550 { 0x15, 0x99030120 }, /* speaker */
4551 { 0x16, 0x411111f0 }, /* N/A */
4552 { 0x17, 0x411111f0 }, /* N/A */
4553 { 0x18, 0x411111f0 }, /* N/A */
4554 { 0x19, 0x01a19950 }, /* mic-in */
4555 { 0x1a, 0x411111f0 }, /* N/A */
4556 { 0x1b, 0x411111f0 }, /* N/A */
4557 { 0x1c, 0x411111f0 }, /* N/A */
4558 { 0x1d, 0x411111f0 }, /* N/A */
4559 { 0x1e, 0x411111f0 }, /* N/A */
4560 { }
4561 },
4562 .chained = true,
4563 .chain_id = ALC880_FIXUP_VOL_KNOB,
4564 },
Takashi Iwai817de922012-02-20 17:20:48 +01004565 [ALC880_FIXUP_UNIWILL] = {
4566 /* need to fix HP and speaker pins to be parsed correctly */
4567 .type = ALC_FIXUP_PINS,
4568 .v.pins = (const struct alc_pincfg[]) {
4569 { 0x14, 0x0121411f }, /* HP */
4570 { 0x15, 0x99030120 }, /* speaker */
4571 { 0x16, 0x99030130 }, /* bass speaker */
4572 { }
4573 },
4574 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004575 [ALC880_FIXUP_UNIWILL_DIG] = {
4576 .type = ALC_FIXUP_PINS,
4577 .v.pins = (const struct alc_pincfg[]) {
4578 /* disable bogus unused pins */
4579 { 0x17, 0x411111f0 },
4580 { 0x19, 0x411111f0 },
4581 { 0x1b, 0x411111f0 },
4582 { 0x1f, 0x411111f0 },
4583 { }
4584 }
4585 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004586 [ALC880_FIXUP_Z71V] = {
4587 .type = ALC_FIXUP_PINS,
4588 .v.pins = (const struct alc_pincfg[]) {
4589 /* set up the whole pins as BIOS is utterly broken */
4590 { 0x14, 0x99030120 }, /* speaker */
4591 { 0x15, 0x0121411f }, /* HP */
4592 { 0x16, 0x411111f0 }, /* N/A */
4593 { 0x17, 0x411111f0 }, /* N/A */
4594 { 0x18, 0x01a19950 }, /* mic-in */
4595 { 0x19, 0x411111f0 }, /* N/A */
4596 { 0x1a, 0x01813031 }, /* line-in */
4597 { 0x1b, 0x411111f0 }, /* N/A */
4598 { 0x1c, 0x411111f0 }, /* N/A */
4599 { 0x1d, 0x411111f0 }, /* N/A */
4600 { 0x1e, 0x0144111e }, /* SPDIF */
4601 { }
4602 }
4603 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004604 [ALC880_FIXUP_3ST_BASE] = {
4605 .type = ALC_FIXUP_PINS,
4606 .v.pins = (const struct alc_pincfg[]) {
4607 { 0x14, 0x01014010 }, /* line-out */
4608 { 0x15, 0x411111f0 }, /* N/A */
4609 { 0x16, 0x411111f0 }, /* N/A */
4610 { 0x17, 0x411111f0 }, /* N/A */
4611 { 0x18, 0x01a19c30 }, /* mic-in */
4612 { 0x19, 0x0121411f }, /* HP */
4613 { 0x1a, 0x01813031 }, /* line-in */
4614 { 0x1b, 0x02a19c40 }, /* front-mic */
4615 { 0x1c, 0x411111f0 }, /* N/A */
4616 { 0x1d, 0x411111f0 }, /* N/A */
4617 /* 0x1e is filled in below */
4618 { 0x1f, 0x411111f0 }, /* N/A */
4619 { }
4620 }
4621 },
4622 [ALC880_FIXUP_3ST] = {
4623 .type = ALC_FIXUP_PINS,
4624 .v.pins = (const struct alc_pincfg[]) {
4625 { 0x1e, 0x411111f0 }, /* N/A */
4626 { }
4627 },
4628 .chained = true,
4629 .chain_id = ALC880_FIXUP_3ST_BASE,
4630 },
4631 [ALC880_FIXUP_3ST_DIG] = {
4632 .type = ALC_FIXUP_PINS,
4633 .v.pins = (const struct alc_pincfg[]) {
4634 { 0x1e, 0x0144111e }, /* SPDIF */
4635 { }
4636 },
4637 .chained = true,
4638 .chain_id = ALC880_FIXUP_3ST_BASE,
4639 },
4640 [ALC880_FIXUP_5ST_BASE] = {
4641 .type = ALC_FIXUP_PINS,
4642 .v.pins = (const struct alc_pincfg[]) {
4643 { 0x14, 0x01014010 }, /* front */
4644 { 0x15, 0x411111f0 }, /* N/A */
4645 { 0x16, 0x01011411 }, /* CLFE */
4646 { 0x17, 0x01016412 }, /* surr */
4647 { 0x18, 0x01a19c30 }, /* mic-in */
4648 { 0x19, 0x0121411f }, /* HP */
4649 { 0x1a, 0x01813031 }, /* line-in */
4650 { 0x1b, 0x02a19c40 }, /* front-mic */
4651 { 0x1c, 0x411111f0 }, /* N/A */
4652 { 0x1d, 0x411111f0 }, /* N/A */
4653 /* 0x1e is filled in below */
4654 { 0x1f, 0x411111f0 }, /* N/A */
4655 { }
4656 }
4657 },
4658 [ALC880_FIXUP_5ST] = {
4659 .type = ALC_FIXUP_PINS,
4660 .v.pins = (const struct alc_pincfg[]) {
4661 { 0x1e, 0x411111f0 }, /* N/A */
4662 { }
4663 },
4664 .chained = true,
4665 .chain_id = ALC880_FIXUP_5ST_BASE,
4666 },
4667 [ALC880_FIXUP_5ST_DIG] = {
4668 .type = ALC_FIXUP_PINS,
4669 .v.pins = (const struct alc_pincfg[]) {
4670 { 0x1e, 0x0144111e }, /* SPDIF */
4671 { }
4672 },
4673 .chained = true,
4674 .chain_id = ALC880_FIXUP_5ST_BASE,
4675 },
4676 [ALC880_FIXUP_6ST_BASE] = {
4677 .type = ALC_FIXUP_PINS,
4678 .v.pins = (const struct alc_pincfg[]) {
4679 { 0x14, 0x01014010 }, /* front */
4680 { 0x15, 0x01016412 }, /* surr */
4681 { 0x16, 0x01011411 }, /* CLFE */
4682 { 0x17, 0x01012414 }, /* side */
4683 { 0x18, 0x01a19c30 }, /* mic-in */
4684 { 0x19, 0x02a19c40 }, /* front-mic */
4685 { 0x1a, 0x01813031 }, /* line-in */
4686 { 0x1b, 0x0121411f }, /* HP */
4687 { 0x1c, 0x411111f0 }, /* N/A */
4688 { 0x1d, 0x411111f0 }, /* N/A */
4689 /* 0x1e is filled in below */
4690 { 0x1f, 0x411111f0 }, /* N/A */
4691 { }
4692 }
4693 },
4694 [ALC880_FIXUP_6ST] = {
4695 .type = ALC_FIXUP_PINS,
4696 .v.pins = (const struct alc_pincfg[]) {
4697 { 0x1e, 0x411111f0 }, /* N/A */
4698 { }
4699 },
4700 .chained = true,
4701 .chain_id = ALC880_FIXUP_6ST_BASE,
4702 },
4703 [ALC880_FIXUP_6ST_DIG] = {
4704 .type = ALC_FIXUP_PINS,
4705 .v.pins = (const struct alc_pincfg[]) {
4706 { 0x1e, 0x0144111e }, /* SPDIF */
4707 { }
4708 },
4709 .chained = true,
4710 .chain_id = ALC880_FIXUP_6ST_BASE,
4711 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004712};
4713
4714static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004715 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004716 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004717 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4718 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004719 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004720 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004721 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004722 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004723 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004724 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004725 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004726 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004727 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004728 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004729 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004730 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4731 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4732 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004733 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004734
4735 /* Below is the copied entries from alc880_quirks.c.
4736 * It's not quite sure whether BIOS sets the correct pin-config table
4737 * on these machines, thus they are kept to be compatible with
4738 * the old static quirks. Once when it's confirmed to work without
4739 * these overrides, it'd be better to remove.
4740 */
4741 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4742 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4743 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4744 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4745 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4746 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4747 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4748 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4749 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4750 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4751 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4752 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4753 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4754 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4755 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4756 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4757 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4758 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4759 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4760 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4761 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4762 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4763 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4764 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4765 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4766 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4767 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4768 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4769 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4770 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4771 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4772 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4773 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4774 /* default Intel */
4775 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4776 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4777 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4778 {}
4779};
4780
4781static const struct alc_model_fixup alc880_fixup_models[] = {
4782 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4783 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4784 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4785 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4786 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4787 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004788 {}
4789};
4790
4791
4792/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004793 * OK, here we have finally the patch for ALC880
4794 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004795static int patch_alc880(struct hda_codec *codec)
4796{
4797 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004798 int err;
4799
Takashi Iwai3de95172012-05-07 18:03:15 +02004800 err = alc_alloc_spec(codec, 0x0b);
4801 if (err < 0)
4802 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004803
Takashi Iwai3de95172012-05-07 18:03:15 +02004804 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004805 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004806
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004807 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4808 alc880_fixups);
4809 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004810
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004811 /* automatic parse from the BIOS config */
4812 err = alc880_parse_auto_config(codec);
4813 if (err < 0)
4814 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004815
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004816 if (!spec->no_analog) {
4817 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004818 if (err < 0)
4819 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004820 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4821 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004822
Takashi Iwai1d045db2011-07-07 18:23:21 +02004823 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004824 codec->patch_ops.unsol_event = alc880_unsol_event;
4825
Takashi Iwai1d045db2011-07-07 18:23:21 +02004826
Takashi Iwai589876e2012-02-20 15:47:55 +01004827 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4828
Takashi Iwai1d045db2011-07-07 18:23:21 +02004829 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004830
4831 error:
4832 alc_free(codec);
4833 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004834}
4835
4836
4837/*
4838 * ALC260 support
4839 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004840static int alc260_parse_auto_config(struct hda_codec *codec)
4841{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004842 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004843 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4844 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004845}
4846
Takashi Iwai1d045db2011-07-07 18:23:21 +02004847/*
4848 * Pin config fixes
4849 */
4850enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004851 ALC260_FIXUP_HP_DC5750,
4852 ALC260_FIXUP_HP_PIN_0F,
4853 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004854 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004855 ALC260_FIXUP_GPIO1_TOGGLE,
4856 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004857 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004858 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004859};
4860
Takashi Iwai20f7d922012-02-16 12:35:16 +01004861static void alc260_gpio1_automute(struct hda_codec *codec)
4862{
4863 struct alc_spec *spec = codec->spec;
4864 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4865 spec->hp_jack_present);
4866}
4867
4868static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4869 const struct alc_fixup *fix, int action)
4870{
4871 struct alc_spec *spec = codec->spec;
4872 if (action == ALC_FIXUP_ACT_PROBE) {
4873 /* although the machine has only one output pin, we need to
4874 * toggle GPIO1 according to the jack state
4875 */
4876 spec->automute_hook = alc260_gpio1_automute;
4877 spec->detect_hp = 1;
4878 spec->automute_speaker = 1;
4879 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004880 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4881 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004882 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004883 }
4884}
4885
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004886static void alc260_fixup_kn1(struct hda_codec *codec,
4887 const struct alc_fixup *fix, int action)
4888{
4889 struct alc_spec *spec = codec->spec;
4890 static const struct alc_pincfg pincfgs[] = {
4891 { 0x0f, 0x02214000 }, /* HP/speaker */
4892 { 0x12, 0x90a60160 }, /* int mic */
4893 { 0x13, 0x02a19000 }, /* ext mic */
4894 { 0x18, 0x01446000 }, /* SPDIF out */
4895 /* disable bogus I/O pins */
4896 { 0x10, 0x411111f0 },
4897 { 0x11, 0x411111f0 },
4898 { 0x14, 0x411111f0 },
4899 { 0x15, 0x411111f0 },
4900 { 0x16, 0x411111f0 },
4901 { 0x17, 0x411111f0 },
4902 { 0x19, 0x411111f0 },
4903 { }
4904 };
4905
4906 switch (action) {
4907 case ALC_FIXUP_ACT_PRE_PROBE:
4908 alc_apply_pincfgs(codec, pincfgs);
4909 break;
4910 case ALC_FIXUP_ACT_PROBE:
4911 spec->init_amp = ALC_INIT_NONE;
4912 break;
4913 }
4914}
4915
Takashi Iwai1d045db2011-07-07 18:23:21 +02004916static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004917 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004918 .type = ALC_FIXUP_PINS,
4919 .v.pins = (const struct alc_pincfg[]) {
4920 { 0x11, 0x90130110 }, /* speaker */
4921 { }
4922 }
4923 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004924 [ALC260_FIXUP_HP_PIN_0F] = {
4925 .type = ALC_FIXUP_PINS,
4926 .v.pins = (const struct alc_pincfg[]) {
4927 { 0x0f, 0x01214000 }, /* HP */
4928 { }
4929 }
4930 },
4931 [ALC260_FIXUP_COEF] = {
4932 .type = ALC_FIXUP_VERBS,
4933 .v.verbs = (const struct hda_verb[]) {
4934 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4935 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4936 { }
4937 },
4938 .chained = true,
4939 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4940 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004941 [ALC260_FIXUP_GPIO1] = {
4942 .type = ALC_FIXUP_VERBS,
4943 .v.verbs = alc_gpio1_init_verbs,
4944 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004945 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4946 .type = ALC_FIXUP_FUNC,
4947 .v.func = alc260_fixup_gpio1_toggle,
4948 .chained = true,
4949 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4950 },
4951 [ALC260_FIXUP_REPLACER] = {
4952 .type = ALC_FIXUP_VERBS,
4953 .v.verbs = (const struct hda_verb[]) {
4954 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4955 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4956 { }
4957 },
4958 .chained = true,
4959 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4960 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004961 [ALC260_FIXUP_HP_B1900] = {
4962 .type = ALC_FIXUP_FUNC,
4963 .v.func = alc260_fixup_gpio1_toggle,
4964 .chained = true,
4965 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004966 },
4967 [ALC260_FIXUP_KN1] = {
4968 .type = ALC_FIXUP_FUNC,
4969 .v.func = alc260_fixup_kn1,
4970 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004971};
4972
4973static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004974 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004975 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004976 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004977 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004978 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004979 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004980 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004981 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004982 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004983 {}
4984};
4985
4986/*
4987 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004988static int patch_alc260(struct hda_codec *codec)
4989{
4990 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004991 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004992
Takashi Iwai3de95172012-05-07 18:03:15 +02004993 err = alc_alloc_spec(codec, 0x07);
4994 if (err < 0)
4995 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004996
Takashi Iwai3de95172012-05-07 18:03:15 +02004997 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004998
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004999 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5000 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005001
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005002 /* automatic parse from the BIOS config */
5003 err = alc260_parse_auto_config(codec);
5004 if (err < 0)
5005 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005006
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005007 if (!spec->no_analog) {
5008 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005009 if (err < 0)
5010 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005011 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5012 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005013
Takashi Iwai1d045db2011-07-07 18:23:21 +02005014 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005015 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005016
Takashi Iwai589876e2012-02-20 15:47:55 +01005017 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5018
Takashi Iwai1d045db2011-07-07 18:23:21 +02005019 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005020
5021 error:
5022 alc_free(codec);
5023 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005024}
5025
5026
5027/*
5028 * ALC882/883/885/888/889 support
5029 *
5030 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5031 * configuration. Each pin widget can choose any input DACs and a mixer.
5032 * Each ADC is connected from a mixer of all inputs. This makes possible
5033 * 6-channel independent captures.
5034 *
5035 * In addition, an independent DAC for the multi-playback (not used in this
5036 * driver yet).
5037 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005038
5039/*
5040 * Pin config fixes
5041 */
5042enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005043 ALC882_FIXUP_ABIT_AW9D_MAX,
5044 ALC882_FIXUP_LENOVO_Y530,
5045 ALC882_FIXUP_PB_M5210,
5046 ALC882_FIXUP_ACER_ASPIRE_7736,
5047 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005048 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005049 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005050 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005051 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005052 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005053 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005054 ALC882_FIXUP_GPIO1,
5055 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005056 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005057 ALC889_FIXUP_COEF,
5058 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005059 ALC882_FIXUP_ACER_ASPIRE_4930G,
5060 ALC882_FIXUP_ACER_ASPIRE_8930G,
5061 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005062 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005063 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005064 ALC889_FIXUP_MBP_VREF,
5065 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005066 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005067 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005068};
5069
Takashi Iwai68ef0562011-11-09 18:24:44 +01005070static void alc889_fixup_coef(struct hda_codec *codec,
5071 const struct alc_fixup *fix, int action)
5072{
5073 if (action != ALC_FIXUP_ACT_INIT)
5074 return;
5075 alc889_coef_init(codec);
5076}
5077
Takashi Iwai56710872011-11-14 17:42:11 +01005078/* toggle speaker-output according to the hp-jack state */
5079static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5080{
5081 unsigned int gpiostate, gpiomask, gpiodir;
5082
5083 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5084 AC_VERB_GET_GPIO_DATA, 0);
5085
5086 if (!muted)
5087 gpiostate |= (1 << pin);
5088 else
5089 gpiostate &= ~(1 << pin);
5090
5091 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5092 AC_VERB_GET_GPIO_MASK, 0);
5093 gpiomask |= (1 << pin);
5094
5095 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5096 AC_VERB_GET_GPIO_DIRECTION, 0);
5097 gpiodir |= (1 << pin);
5098
5099
5100 snd_hda_codec_write(codec, codec->afg, 0,
5101 AC_VERB_SET_GPIO_MASK, gpiomask);
5102 snd_hda_codec_write(codec, codec->afg, 0,
5103 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5104
5105 msleep(1);
5106
5107 snd_hda_codec_write(codec, codec->afg, 0,
5108 AC_VERB_SET_GPIO_DATA, gpiostate);
5109}
5110
5111/* set up GPIO at initialization */
5112static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5113 const struct alc_fixup *fix, int action)
5114{
5115 if (action != ALC_FIXUP_ACT_INIT)
5116 return;
5117 alc882_gpio_mute(codec, 0, 0);
5118 alc882_gpio_mute(codec, 1, 0);
5119}
5120
Takashi Iwai02a237b2012-02-13 15:25:07 +01005121/* Fix the connection of some pins for ALC889:
5122 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5123 * work correctly (bko#42740)
5124 */
5125static void alc889_fixup_dac_route(struct hda_codec *codec,
5126 const struct alc_fixup *fix, int action)
5127{
5128 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005129 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005130 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5131 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5132 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5133 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5134 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5135 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005136 } else if (action == ALC_FIXUP_ACT_PROBE) {
5137 /* restore the connections */
5138 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5139 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5140 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5141 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5142 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005143 }
5144}
5145
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005146/* Set VREF on HP pin */
5147static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5148 const struct alc_fixup *fix, int action)
5149{
5150 struct alc_spec *spec = codec->spec;
5151 static hda_nid_t nids[2] = { 0x14, 0x15 };
5152 int i;
5153
5154 if (action != ALC_FIXUP_ACT_INIT)
5155 return;
5156 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5157 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5158 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5159 continue;
5160 val = snd_hda_codec_read(codec, nids[i], 0,
5161 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5162 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005163 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005164 spec->keep_vref_in_automute = 1;
5165 break;
5166 }
5167}
5168
5169/* Set VREF on speaker pins on imac91 */
5170static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5171 const struct alc_fixup *fix, int action)
5172{
5173 struct alc_spec *spec = codec->spec;
5174 static hda_nid_t nids[2] = { 0x18, 0x1a };
5175 int i;
5176
5177 if (action != ALC_FIXUP_ACT_INIT)
5178 return;
5179 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5180 unsigned int val;
5181 val = snd_hda_codec_read(codec, nids[i], 0,
5182 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5183 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005184 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005185 }
5186 spec->keep_vref_in_automute = 1;
5187}
5188
Takashi Iwaie427c232012-07-29 10:04:08 +02005189/* Don't take HP output as primary
5190 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5191 */
5192static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5193 const struct alc_fixup *fix, int action)
5194{
5195 struct alc_spec *spec = codec->spec;
5196 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5197 spec->no_primary_hp = 1;
5198}
5199
Takashi Iwai1d045db2011-07-07 18:23:21 +02005200static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005201 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005202 .type = ALC_FIXUP_PINS,
5203 .v.pins = (const struct alc_pincfg[]) {
5204 { 0x15, 0x01080104 }, /* side */
5205 { 0x16, 0x01011012 }, /* rear */
5206 { 0x17, 0x01016011 }, /* clfe */
5207 { }
5208 }
5209 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005210 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005211 .type = ALC_FIXUP_PINS,
5212 .v.pins = (const struct alc_pincfg[]) {
5213 { 0x15, 0x99130112 }, /* rear int speakers */
5214 { 0x16, 0x99130111 }, /* subwoofer */
5215 { }
5216 }
5217 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005218 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005219 .type = ALC_FIXUP_VERBS,
5220 .v.verbs = (const struct hda_verb[]) {
5221 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5222 {}
5223 }
5224 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005225 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005226 .type = ALC_FIXUP_FUNC,
5227 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005228 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005229 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005230 .type = ALC_FIXUP_PINS,
5231 .v.pins = (const struct alc_pincfg[]) {
5232 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5233 { }
5234 }
5235 },
Marton Balint8f239212012-03-05 21:33:23 +01005236 [ALC889_FIXUP_CD] = {
5237 .type = ALC_FIXUP_PINS,
5238 .v.pins = (const struct alc_pincfg[]) {
5239 { 0x1c, 0x993301f0 }, /* CD */
5240 { }
5241 }
5242 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005243 [ALC889_FIXUP_VAIO_TT] = {
5244 .type = ALC_FIXUP_PINS,
5245 .v.pins = (const struct alc_pincfg[]) {
5246 { 0x17, 0x90170111 }, /* hidden surround speaker */
5247 { }
5248 }
5249 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005250 [ALC888_FIXUP_EEE1601] = {
5251 .type = ALC_FIXUP_VERBS,
5252 .v.verbs = (const struct hda_verb[]) {
5253 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5254 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5255 { }
5256 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005257 },
5258 [ALC882_FIXUP_EAPD] = {
5259 .type = ALC_FIXUP_VERBS,
5260 .v.verbs = (const struct hda_verb[]) {
5261 /* change to EAPD mode */
5262 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5263 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5264 { }
5265 }
5266 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005267 [ALC883_FIXUP_EAPD] = {
5268 .type = ALC_FIXUP_VERBS,
5269 .v.verbs = (const struct hda_verb[]) {
5270 /* change to EAPD mode */
5271 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5272 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5273 { }
5274 }
5275 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005276 [ALC883_FIXUP_ACER_EAPD] = {
5277 .type = ALC_FIXUP_VERBS,
5278 .v.verbs = (const struct hda_verb[]) {
5279 /* eanable EAPD on Acer laptops */
5280 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5281 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5282 { }
5283 }
5284 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005285 [ALC882_FIXUP_GPIO1] = {
5286 .type = ALC_FIXUP_VERBS,
5287 .v.verbs = alc_gpio1_init_verbs,
5288 },
5289 [ALC882_FIXUP_GPIO2] = {
5290 .type = ALC_FIXUP_VERBS,
5291 .v.verbs = alc_gpio2_init_verbs,
5292 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005293 [ALC882_FIXUP_GPIO3] = {
5294 .type = ALC_FIXUP_VERBS,
5295 .v.verbs = alc_gpio3_init_verbs,
5296 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005297 [ALC882_FIXUP_ASUS_W2JC] = {
5298 .type = ALC_FIXUP_VERBS,
5299 .v.verbs = alc_gpio1_init_verbs,
5300 .chained = true,
5301 .chain_id = ALC882_FIXUP_EAPD,
5302 },
5303 [ALC889_FIXUP_COEF] = {
5304 .type = ALC_FIXUP_FUNC,
5305 .v.func = alc889_fixup_coef,
5306 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005307 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5308 .type = ALC_FIXUP_PINS,
5309 .v.pins = (const struct alc_pincfg[]) {
5310 { 0x16, 0x99130111 }, /* CLFE speaker */
5311 { 0x17, 0x99130112 }, /* surround speaker */
5312 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005313 },
5314 .chained = true,
5315 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005316 },
5317 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5318 .type = ALC_FIXUP_PINS,
5319 .v.pins = (const struct alc_pincfg[]) {
5320 { 0x16, 0x99130111 }, /* CLFE speaker */
5321 { 0x1b, 0x99130112 }, /* surround speaker */
5322 { }
5323 },
5324 .chained = true,
5325 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5326 },
5327 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5328 /* additional init verbs for Acer Aspire 8930G */
5329 .type = ALC_FIXUP_VERBS,
5330 .v.verbs = (const struct hda_verb[]) {
5331 /* Enable all DACs */
5332 /* DAC DISABLE/MUTE 1? */
5333 /* setting bits 1-5 disables DAC nids 0x02-0x06
5334 * apparently. Init=0x38 */
5335 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5336 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5337 /* DAC DISABLE/MUTE 2? */
5338 /* some bit here disables the other DACs.
5339 * Init=0x4900 */
5340 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5341 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5342 /* DMIC fix
5343 * This laptop has a stereo digital microphone.
5344 * The mics are only 1cm apart which makes the stereo
5345 * useless. However, either the mic or the ALC889
5346 * makes the signal become a difference/sum signal
5347 * instead of standard stereo, which is annoying.
5348 * So instead we flip this bit which makes the
5349 * codec replicate the sum signal to both channels,
5350 * turning it into a normal mono mic.
5351 */
5352 /* DMIC_CONTROL? Init value = 0x0001 */
5353 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5354 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5355 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5356 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5357 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005358 },
5359 .chained = true,
5360 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005361 },
Takashi Iwai56710872011-11-14 17:42:11 +01005362 [ALC885_FIXUP_MACPRO_GPIO] = {
5363 .type = ALC_FIXUP_FUNC,
5364 .v.func = alc885_fixup_macpro_gpio,
5365 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005366 [ALC889_FIXUP_DAC_ROUTE] = {
5367 .type = ALC_FIXUP_FUNC,
5368 .v.func = alc889_fixup_dac_route,
5369 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005370 [ALC889_FIXUP_MBP_VREF] = {
5371 .type = ALC_FIXUP_FUNC,
5372 .v.func = alc889_fixup_mbp_vref,
5373 .chained = true,
5374 .chain_id = ALC882_FIXUP_GPIO1,
5375 },
5376 [ALC889_FIXUP_IMAC91_VREF] = {
5377 .type = ALC_FIXUP_FUNC,
5378 .v.func = alc889_fixup_imac91_vref,
5379 .chained = true,
5380 .chain_id = ALC882_FIXUP_GPIO1,
5381 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005382 [ALC882_FIXUP_INV_DMIC] = {
5383 .type = ALC_FIXUP_FUNC,
5384 .v.func = alc_fixup_inv_dmic_0x12,
5385 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005386 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5387 .type = ALC_FIXUP_FUNC,
5388 .v.func = alc882_fixup_no_primary_hp,
5389 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005390};
5391
5392static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005393 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5394 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5395 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5396 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5397 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5398 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005399 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5400 ALC882_FIXUP_ACER_ASPIRE_4930G),
5401 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5402 ALC882_FIXUP_ACER_ASPIRE_4930G),
5403 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5404 ALC882_FIXUP_ACER_ASPIRE_8930G),
5405 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5406 ALC882_FIXUP_ACER_ASPIRE_8930G),
5407 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5408 ALC882_FIXUP_ACER_ASPIRE_4930G),
5409 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5410 ALC882_FIXUP_ACER_ASPIRE_4930G),
5411 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5412 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005413 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005414 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5415 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005416 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005417 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005418 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005419 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005420 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005421 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005422 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005423 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005424 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005425
5426 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005427 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5428 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5429 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005430 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5431 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5432 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005433 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5434 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005435 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005436 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5437 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5438 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5439 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005440 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005441 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5442 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5443 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005444 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005445 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005446 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5447 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5448 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005449
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005450 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005451 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005452 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005453 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005454 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005455 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5456 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005457 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005458 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005459 {}
5460};
5461
Takashi Iwai912093b2012-04-11 14:03:41 +02005462static const struct alc_model_fixup alc882_fixup_models[] = {
5463 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5464 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5465 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005466 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005467 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005468 {}
5469};
5470
Takashi Iwai1d045db2011-07-07 18:23:21 +02005471/*
5472 * BIOS auto configuration
5473 */
5474/* almost identical with ALC880 parser... */
5475static int alc882_parse_auto_config(struct hda_codec *codec)
5476{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005477 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005478 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5479 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005480}
5481
Takashi Iwai1d045db2011-07-07 18:23:21 +02005482/*
5483 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005484static int patch_alc882(struct hda_codec *codec)
5485{
5486 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005487 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005488
Takashi Iwai3de95172012-05-07 18:03:15 +02005489 err = alc_alloc_spec(codec, 0x0b);
5490 if (err < 0)
5491 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005492
Takashi Iwai3de95172012-05-07 18:03:15 +02005493 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005494
5495 switch (codec->vendor_id) {
5496 case 0x10ec0882:
5497 case 0x10ec0885:
5498 break;
5499 default:
5500 /* ALC883 and variants */
5501 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5502 break;
5503 }
5504
Takashi Iwai912093b2012-04-11 14:03:41 +02005505 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5506 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005507 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508
5509 alc_auto_parse_customize_define(codec);
5510
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005511 /* automatic parse from the BIOS config */
5512 err = alc882_parse_auto_config(codec);
5513 if (err < 0)
5514 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005515
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005516 if (!spec->no_analog && has_cdefine_beep(codec)) {
5517 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005518 if (err < 0)
5519 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005520 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005521 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005522
Takashi Iwai1d045db2011-07-07 18:23:21 +02005523 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005524
Takashi Iwai589876e2012-02-20 15:47:55 +01005525 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5526
Takashi Iwai1d045db2011-07-07 18:23:21 +02005527 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005528
5529 error:
5530 alc_free(codec);
5531 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005532}
5533
5534
5535/*
5536 * ALC262 support
5537 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005538static int alc262_parse_auto_config(struct hda_codec *codec)
5539{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005540 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005541 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5542 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005543}
5544
5545/*
5546 * Pin config fixes
5547 */
5548enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005549 ALC262_FIXUP_FSC_H270,
5550 ALC262_FIXUP_HP_Z200,
5551 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005552 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005553 ALC262_FIXUP_BENQ,
5554 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005555 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005556};
5557
5558static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005559 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005560 .type = ALC_FIXUP_PINS,
5561 .v.pins = (const struct alc_pincfg[]) {
5562 { 0x14, 0x99130110 }, /* speaker */
5563 { 0x15, 0x0221142f }, /* front HP */
5564 { 0x1b, 0x0121141f }, /* rear HP */
5565 { }
5566 }
5567 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005568 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005569 .type = ALC_FIXUP_PINS,
5570 .v.pins = (const struct alc_pincfg[]) {
5571 { 0x16, 0x99130120 }, /* internal speaker */
5572 { }
5573 }
5574 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005575 [ALC262_FIXUP_TYAN] = {
5576 .type = ALC_FIXUP_PINS,
5577 .v.pins = (const struct alc_pincfg[]) {
5578 { 0x14, 0x1993e1f0 }, /* int AUX */
5579 { }
5580 }
5581 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005582 [ALC262_FIXUP_LENOVO_3000] = {
5583 .type = ALC_FIXUP_VERBS,
5584 .v.verbs = (const struct hda_verb[]) {
5585 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005586 {}
5587 },
5588 .chained = true,
5589 .chain_id = ALC262_FIXUP_BENQ,
5590 },
5591 [ALC262_FIXUP_BENQ] = {
5592 .type = ALC_FIXUP_VERBS,
5593 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005594 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5595 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5596 {}
5597 }
5598 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005599 [ALC262_FIXUP_BENQ_T31] = {
5600 .type = ALC_FIXUP_VERBS,
5601 .v.verbs = (const struct hda_verb[]) {
5602 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5603 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5604 {}
5605 }
5606 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005607 [ALC262_FIXUP_INV_DMIC] = {
5608 .type = ALC_FIXUP_FUNC,
5609 .v.func = alc_fixup_inv_dmic_0x12,
5610 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005611};
5612
5613static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005614 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005615 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5616 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005617 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5618 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005619 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005620 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5621 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005622 {}
5623};
5624
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005625static const struct alc_model_fixup alc262_fixup_models[] = {
5626 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5627 {}
5628};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005629
Takashi Iwai1d045db2011-07-07 18:23:21 +02005630/*
5631 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005632static int patch_alc262(struct hda_codec *codec)
5633{
5634 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005635 int err;
5636
Takashi Iwai3de95172012-05-07 18:03:15 +02005637 err = alc_alloc_spec(codec, 0x0b);
5638 if (err < 0)
5639 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005640
Takashi Iwai3de95172012-05-07 18:03:15 +02005641 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01005642 spec->shared_mic_vref_pin = 0x18;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643
5644#if 0
5645 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5646 * under-run
5647 */
5648 {
5649 int tmp;
5650 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5651 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5652 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5653 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5654 }
5655#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5657
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005658 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5659 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005660 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005662 alc_auto_parse_customize_define(codec);
5663
Takashi Iwai42399f72011-11-07 17:18:44 +01005664 /* automatic parse from the BIOS config */
5665 err = alc262_parse_auto_config(codec);
5666 if (err < 0)
5667 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005668
Takashi Iwai1d045db2011-07-07 18:23:21 +02005669 if (!spec->no_analog && has_cdefine_beep(codec)) {
5670 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005671 if (err < 0)
5672 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005673 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005674 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005675
Takashi Iwai1d045db2011-07-07 18:23:21 +02005676 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005677 spec->shutup = alc_eapd_shutup;
5678
Takashi Iwai589876e2012-02-20 15:47:55 +01005679 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5680
Takashi Iwai1d045db2011-07-07 18:23:21 +02005681 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005682
5683 error:
5684 alc_free(codec);
5685 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005686}
5687
5688/*
5689 * ALC268
5690 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691/* bind Beep switches of both NID 0x0f and 0x10 */
5692static const struct hda_bind_ctls alc268_bind_beep_sw = {
5693 .ops = &snd_hda_bind_sw,
5694 .values = {
5695 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5696 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5697 0
5698 },
5699};
5700
5701static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5702 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5703 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5704 { }
5705};
5706
5707/* set PCBEEP vol = 0, mute connections */
5708static const struct hda_verb alc268_beep_init_verbs[] = {
5709 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5710 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5711 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5712 { }
5713};
5714
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005715enum {
5716 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005717 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005718};
5719
5720static const struct alc_fixup alc268_fixups[] = {
5721 [ALC268_FIXUP_INV_DMIC] = {
5722 .type = ALC_FIXUP_FUNC,
5723 .v.func = alc_fixup_inv_dmic_0x12,
5724 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005725 [ALC268_FIXUP_HP_EAPD] = {
5726 .type = ALC_FIXUP_VERBS,
5727 .v.verbs = (const struct hda_verb[]) {
5728 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5729 {}
5730 }
5731 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005732};
5733
5734static const struct alc_model_fixup alc268_fixup_models[] = {
5735 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005736 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5737 {}
5738};
5739
5740static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5741 /* below is codec SSID since multiple Toshiba laptops have the
5742 * same PCI SSID 1179:ff00
5743 */
5744 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005745 {}
5746};
5747
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748/*
5749 * BIOS auto configuration
5750 */
5751static int alc268_parse_auto_config(struct hda_codec *codec)
5752{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005753 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005755 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5756 if (err > 0) {
5757 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5758 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005759 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005760 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005761 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005762 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005763}
5764
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765/*
5766 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767static int patch_alc268(struct hda_codec *codec)
5768{
5769 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005770 int i, has_beep, err;
5771
Takashi Iwai1d045db2011-07-07 18:23:21 +02005772 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005773 err = alc_alloc_spec(codec, 0);
5774 if (err < 0)
5775 return err;
5776
5777 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005778
Takashi Iwaicb766402012-10-20 10:55:21 +02005779 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005780 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5781
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005782 /* automatic parse from the BIOS config */
5783 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005784 if (err < 0)
5785 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786
Takashi Iwai1d045db2011-07-07 18:23:21 +02005787 has_beep = 0;
5788 for (i = 0; i < spec->num_mixers; i++) {
5789 if (spec->mixers[i] == alc268_beep_mixer) {
5790 has_beep = 1;
5791 break;
5792 }
5793 }
5794
5795 if (has_beep) {
5796 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005797 if (err < 0)
5798 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005799 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5800 /* override the amp caps for beep generator */
5801 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5802 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5803 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5804 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5805 (0 << AC_AMPCAP_MUTE_SHIFT));
5806 }
5807
Takashi Iwai1d045db2011-07-07 18:23:21 +02005808 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005809 spec->shutup = alc_eapd_shutup;
5810
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005811 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5812
Takashi Iwai1d045db2011-07-07 18:23:21 +02005813 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005814
5815 error:
5816 alc_free(codec);
5817 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005818}
5819
5820/*
5821 * ALC269
5822 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005823static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5824 .substreams = 1,
5825 .channels_min = 2,
5826 .channels_max = 8,
5827 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5828 /* NID is set in alc_build_pcms */
5829 .ops = {
5830 .open = alc_playback_pcm_open,
5831 .prepare = alc_playback_pcm_prepare,
5832 .cleanup = alc_playback_pcm_cleanup
5833 },
5834};
5835
5836static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5837 .substreams = 1,
5838 .channels_min = 2,
5839 .channels_max = 2,
5840 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5841 /* NID is set in alc_build_pcms */
5842};
5843
Takashi Iwai1d045db2011-07-07 18:23:21 +02005844/* different alc269-variants */
5845enum {
5846 ALC269_TYPE_ALC269VA,
5847 ALC269_TYPE_ALC269VB,
5848 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005849 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005850 ALC269_TYPE_ALC280,
5851 ALC269_TYPE_ALC282,
5852 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005853};
5854
5855/*
5856 * BIOS auto configuration
5857 */
5858static int alc269_parse_auto_config(struct hda_codec *codec)
5859{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005860 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005861 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5862 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5863 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005864 const hda_nid_t *ssids;
5865
5866 switch (spec->codec_variant) {
5867 case ALC269_TYPE_ALC269VA:
5868 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005869 case ALC269_TYPE_ALC280:
5870 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005871 ssids = alc269va_ssids;
5872 break;
5873 case ALC269_TYPE_ALC269VB:
5874 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005875 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005876 ssids = alc269_ssids;
5877 break;
5878 default:
5879 ssids = alc269_ssids;
5880 break;
5881 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005882
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005883 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005884}
5885
Kailang Yang1387e2d2012-11-08 10:23:18 +01005886static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887{
5888 int val = alc_read_coef_idx(codec, 0x04);
5889 if (power_up)
5890 val |= 1 << 11;
5891 else
5892 val &= ~(1 << 11);
5893 alc_write_coef_idx(codec, 0x04, val);
5894}
5895
5896static void alc269_shutup(struct hda_codec *codec)
5897{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005898 struct alc_spec *spec = codec->spec;
5899
5900 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5901 return;
5902
Kailang Yang1387e2d2012-11-08 10:23:18 +01005903 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5904 alc269vb_toggle_power_output(codec, 0);
5905 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5906 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005907 msleep(150);
5908 }
5909}
5910
Takashi Iwai2a439522011-07-26 09:52:50 +02005911#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005912static int alc269_resume(struct hda_codec *codec)
5913{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005914 struct alc_spec *spec = codec->spec;
5915
Kailang Yang1387e2d2012-11-08 10:23:18 +01005916 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5917 alc269vb_toggle_power_output(codec, 0);
5918 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005919 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005920 msleep(150);
5921 }
5922
5923 codec->patch_ops.init(codec);
5924
Kailang Yang1387e2d2012-11-08 10:23:18 +01005925 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5926 alc269vb_toggle_power_output(codec, 1);
5927 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005928 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005929 msleep(200);
5930 }
5931
Takashi Iwai1d045db2011-07-07 18:23:21 +02005932 snd_hda_codec_resume_amp(codec);
5933 snd_hda_codec_resume_cache(codec);
5934 hda_call_check_power_status(codec, 0x01);
5935 return 0;
5936}
Takashi Iwai2a439522011-07-26 09:52:50 +02005937#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005938
David Henningsson108cc102012-07-20 10:37:25 +02005939static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5940 const struct alc_fixup *fix, int action)
5941{
5942 struct alc_spec *spec = codec->spec;
5943
5944 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5945 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5946}
5947
Takashi Iwai1d045db2011-07-07 18:23:21 +02005948static void alc269_fixup_hweq(struct hda_codec *codec,
5949 const struct alc_fixup *fix, int action)
5950{
5951 int coef;
5952
5953 if (action != ALC_FIXUP_ACT_INIT)
5954 return;
5955 coef = alc_read_coef_idx(codec, 0x1e);
5956 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5957}
5958
5959static void alc271_fixup_dmic(struct hda_codec *codec,
5960 const struct alc_fixup *fix, int action)
5961{
5962 static const struct hda_verb verbs[] = {
5963 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5964 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5965 {}
5966 };
5967 unsigned int cfg;
5968
5969 if (strcmp(codec->chip_name, "ALC271X"))
5970 return;
5971 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5972 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5973 snd_hda_sequence_write(codec, verbs);
5974}
5975
Takashi Iwai017f2a12011-07-09 14:42:25 +02005976static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5977 const struct alc_fixup *fix, int action)
5978{
5979 struct alc_spec *spec = codec->spec;
5980
5981 if (action != ALC_FIXUP_ACT_PROBE)
5982 return;
5983
5984 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5985 * fix the sample rate of analog I/O to 44.1kHz
5986 */
5987 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5988 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5989}
5990
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005991static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5992 const struct alc_fixup *fix, int action)
5993{
5994 int coef;
5995
5996 if (action != ALC_FIXUP_ACT_INIT)
5997 return;
5998 /* The digital-mic unit sends PDM (differential signal) instead of
5999 * the standard PCM, thus you can't record a valid mono stream as is.
6000 * Below is a workaround specific to ALC269 to control the dmic
6001 * signal source as mono.
6002 */
6003 coef = alc_read_coef_idx(codec, 0x07);
6004 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6005}
6006
Takashi Iwai24519912011-08-16 15:08:49 +02006007static void alc269_quanta_automute(struct hda_codec *codec)
6008{
David Henningsson42cf0d02011-09-20 12:04:56 +02006009 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006010
6011 snd_hda_codec_write(codec, 0x20, 0,
6012 AC_VERB_SET_COEF_INDEX, 0x0c);
6013 snd_hda_codec_write(codec, 0x20, 0,
6014 AC_VERB_SET_PROC_COEF, 0x680);
6015
6016 snd_hda_codec_write(codec, 0x20, 0,
6017 AC_VERB_SET_COEF_INDEX, 0x0c);
6018 snd_hda_codec_write(codec, 0x20, 0,
6019 AC_VERB_SET_PROC_COEF, 0x480);
6020}
6021
6022static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6023 const struct alc_fixup *fix, int action)
6024{
6025 struct alc_spec *spec = codec->spec;
6026 if (action != ALC_FIXUP_ACT_PROBE)
6027 return;
6028 spec->automute_hook = alc269_quanta_automute;
6029}
6030
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006031/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6032static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6033{
6034 struct hda_codec *codec = private_data;
6035 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6036 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6037 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6038}
6039
6040static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6041 const struct alc_fixup *fix, int action)
6042{
6043 struct alc_spec *spec = codec->spec;
6044 switch (action) {
6045 case ALC_FIXUP_ACT_BUILD:
6046 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6047 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6048 /* fallthru */
6049 case ALC_FIXUP_ACT_INIT:
6050 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6051 break;
6052 }
6053}
6054
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006055/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6056static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6057{
6058 struct hda_codec *codec = private_data;
6059 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006060 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006061}
6062
6063static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6064 const struct alc_fixup *fix, int action)
6065{
6066 struct alc_spec *spec = codec->spec;
6067 switch (action) {
6068 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006069 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006070 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006071 /* fallthru */
6072 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006073 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006074 break;
6075 }
6076}
6077
Dylan Reid08a978d2012-11-18 22:56:40 -08006078static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6079 const struct alc_fixup *fix,
6080 int action)
6081{
6082 struct alc_spec *spec = codec->spec;
6083
6084 if (action == ALC_FIXUP_ACT_PROBE)
6085 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6086 spec->autocfg.hp_pins[0]);
6087}
David Henningsson693b6132012-06-22 19:12:10 +02006088
Takashi Iwai1d045db2011-07-07 18:23:21 +02006089enum {
6090 ALC269_FIXUP_SONY_VAIO,
6091 ALC275_FIXUP_SONY_VAIO_GPIO2,
6092 ALC269_FIXUP_DELL_M101Z,
6093 ALC269_FIXUP_SKU_IGNORE,
6094 ALC269_FIXUP_ASUS_G73JW,
6095 ALC269_FIXUP_LENOVO_EAPD,
6096 ALC275_FIXUP_SONY_HWEQ,
6097 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006098 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006099 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006100 ALC269_FIXUP_QUANTA_MUTE,
6101 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006102 ALC269_FIXUP_AMIC,
6103 ALC269_FIXUP_DMIC,
6104 ALC269VB_FIXUP_AMIC,
6105 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006106 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006107 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006108 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006109 ALC269_FIXUP_LENOVO_DOCK,
6110 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006111 ALC271_FIXUP_AMIC_MIC2,
6112 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006113};
6114
6115static const struct alc_fixup alc269_fixups[] = {
6116 [ALC269_FIXUP_SONY_VAIO] = {
6117 .type = ALC_FIXUP_VERBS,
6118 .v.verbs = (const struct hda_verb[]) {
6119 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6120 {}
6121 }
6122 },
6123 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6124 .type = ALC_FIXUP_VERBS,
6125 .v.verbs = (const struct hda_verb[]) {
6126 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6127 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6128 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6129 { }
6130 },
6131 .chained = true,
6132 .chain_id = ALC269_FIXUP_SONY_VAIO
6133 },
6134 [ALC269_FIXUP_DELL_M101Z] = {
6135 .type = ALC_FIXUP_VERBS,
6136 .v.verbs = (const struct hda_verb[]) {
6137 /* Enables internal speaker */
6138 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6139 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6140 {}
6141 }
6142 },
6143 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006144 .type = ALC_FIXUP_FUNC,
6145 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006146 },
6147 [ALC269_FIXUP_ASUS_G73JW] = {
6148 .type = ALC_FIXUP_PINS,
6149 .v.pins = (const struct alc_pincfg[]) {
6150 { 0x17, 0x99130111 }, /* subwoofer */
6151 { }
6152 }
6153 },
6154 [ALC269_FIXUP_LENOVO_EAPD] = {
6155 .type = ALC_FIXUP_VERBS,
6156 .v.verbs = (const struct hda_verb[]) {
6157 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6158 {}
6159 }
6160 },
6161 [ALC275_FIXUP_SONY_HWEQ] = {
6162 .type = ALC_FIXUP_FUNC,
6163 .v.func = alc269_fixup_hweq,
6164 .chained = true,
6165 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6166 },
6167 [ALC271_FIXUP_DMIC] = {
6168 .type = ALC_FIXUP_FUNC,
6169 .v.func = alc271_fixup_dmic,
6170 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006171 [ALC269_FIXUP_PCM_44K] = {
6172 .type = ALC_FIXUP_FUNC,
6173 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006174 .chained = true,
6175 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006176 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006177 [ALC269_FIXUP_STEREO_DMIC] = {
6178 .type = ALC_FIXUP_FUNC,
6179 .v.func = alc269_fixup_stereo_dmic,
6180 },
Takashi Iwai24519912011-08-16 15:08:49 +02006181 [ALC269_FIXUP_QUANTA_MUTE] = {
6182 .type = ALC_FIXUP_FUNC,
6183 .v.func = alc269_fixup_quanta_mute,
6184 },
6185 [ALC269_FIXUP_LIFEBOOK] = {
6186 .type = ALC_FIXUP_PINS,
6187 .v.pins = (const struct alc_pincfg[]) {
6188 { 0x1a, 0x2101103f }, /* dock line-out */
6189 { 0x1b, 0x23a11040 }, /* dock mic-in */
6190 { }
6191 },
6192 .chained = true,
6193 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6194 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006195 [ALC269_FIXUP_AMIC] = {
6196 .type = ALC_FIXUP_PINS,
6197 .v.pins = (const struct alc_pincfg[]) {
6198 { 0x14, 0x99130110 }, /* speaker */
6199 { 0x15, 0x0121401f }, /* HP out */
6200 { 0x18, 0x01a19c20 }, /* mic */
6201 { 0x19, 0x99a3092f }, /* int-mic */
6202 { }
6203 },
6204 },
6205 [ALC269_FIXUP_DMIC] = {
6206 .type = ALC_FIXUP_PINS,
6207 .v.pins = (const struct alc_pincfg[]) {
6208 { 0x12, 0x99a3092f }, /* int-mic */
6209 { 0x14, 0x99130110 }, /* speaker */
6210 { 0x15, 0x0121401f }, /* HP out */
6211 { 0x18, 0x01a19c20 }, /* mic */
6212 { }
6213 },
6214 },
6215 [ALC269VB_FIXUP_AMIC] = {
6216 .type = ALC_FIXUP_PINS,
6217 .v.pins = (const struct alc_pincfg[]) {
6218 { 0x14, 0x99130110 }, /* speaker */
6219 { 0x18, 0x01a19c20 }, /* mic */
6220 { 0x19, 0x99a3092f }, /* int-mic */
6221 { 0x21, 0x0121401f }, /* HP out */
6222 { }
6223 },
6224 },
David Henningsson2267ea92012-01-03 08:45:56 +01006225 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006226 .type = ALC_FIXUP_PINS,
6227 .v.pins = (const struct alc_pincfg[]) {
6228 { 0x12, 0x99a3092f }, /* int-mic */
6229 { 0x14, 0x99130110 }, /* speaker */
6230 { 0x18, 0x01a19c20 }, /* mic */
6231 { 0x21, 0x0121401f }, /* HP out */
6232 { }
6233 },
6234 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006235 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6236 .type = ALC_FIXUP_FUNC,
6237 .v.func = alc269_fixup_mic1_mute,
6238 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006239 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6240 .type = ALC_FIXUP_FUNC,
6241 .v.func = alc269_fixup_mic2_mute,
6242 },
David Henningsson693b6132012-06-22 19:12:10 +02006243 [ALC269_FIXUP_INV_DMIC] = {
6244 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006245 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006246 },
David Henningsson108cc102012-07-20 10:37:25 +02006247 [ALC269_FIXUP_LENOVO_DOCK] = {
6248 .type = ALC_FIXUP_PINS,
6249 .v.pins = (const struct alc_pincfg[]) {
6250 { 0x19, 0x23a11040 }, /* dock mic */
6251 { 0x1b, 0x2121103f }, /* dock headphone */
6252 { }
6253 },
6254 .chained = true,
6255 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6256 },
6257 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6258 .type = ALC_FIXUP_FUNC,
6259 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6260 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006261 [ALC271_FIXUP_AMIC_MIC2] = {
6262 .type = ALC_FIXUP_PINS,
6263 .v.pins = (const struct alc_pincfg[]) {
6264 { 0x14, 0x99130110 }, /* speaker */
6265 { 0x19, 0x01a19c20 }, /* mic */
6266 { 0x1b, 0x99a7012f }, /* int-mic */
6267 { 0x21, 0x0121401f }, /* HP out */
6268 { }
6269 },
6270 },
6271 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6272 .type = ALC_FIXUP_FUNC,
6273 .v.func = alc271_hp_gate_mic_jack,
6274 .chained = true,
6275 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6276 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006277};
6278
6279static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006280 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6281 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006282 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006283 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006284 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006285 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006286 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006287 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006288 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6289 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6290 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6291 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6292 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006293 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6294 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6295 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6296 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6297 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006298 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006300 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006301 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6302 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6303 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6304 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6305 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006306 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006307 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006308 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006309 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006310 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006311 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006312 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006313
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006314#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006315 /* Below is a quirk table taken from the old code.
6316 * Basically the device should work as is without the fixup table.
6317 * If BIOS doesn't give a proper info, enable the corresponding
6318 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006319 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006320 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6321 ALC269_FIXUP_AMIC),
6322 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006323 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6324 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6325 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6326 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6327 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6328 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6329 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6330 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6331 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6332 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6333 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6334 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6335 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6336 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6337 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6338 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6339 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6340 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6341 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6342 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6343 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6344 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6345 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6346 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6347 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6348 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6349 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6350 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6351 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6352 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6353 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6354 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6355 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6356 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6357 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6358 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6359 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6360 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6361#endif
6362 {}
6363};
6364
6365static const struct alc_model_fixup alc269_fixup_models[] = {
6366 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6367 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006368 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6369 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6370 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006371 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006372 {}
6373};
6374
6375
Takashi Iwai546bb672012-03-07 08:37:19 +01006376static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006377{
Kailang Yang526af6e2012-03-07 08:25:20 +01006378 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006379 int val;
6380
Kailang Yang526af6e2012-03-07 08:25:20 +01006381 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006382 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006383
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006384 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006385 alc_write_coef_idx(codec, 0xf, 0x960b);
6386 alc_write_coef_idx(codec, 0xe, 0x8817);
6387 }
6388
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006389 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006390 alc_write_coef_idx(codec, 0xf, 0x960b);
6391 alc_write_coef_idx(codec, 0xe, 0x8814);
6392 }
6393
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006394 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006395 val = alc_read_coef_idx(codec, 0x04);
6396 /* Power up output pin */
6397 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6398 }
6399
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006400 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006401 val = alc_read_coef_idx(codec, 0xd);
6402 if ((val & 0x0c00) >> 10 != 0x1) {
6403 /* Capless ramp up clock control */
6404 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6405 }
6406 val = alc_read_coef_idx(codec, 0x17);
6407 if ((val & 0x01c0) >> 6 != 0x4) {
6408 /* Class D power on reset */
6409 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6410 }
6411 }
6412
6413 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6414 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6415
6416 val = alc_read_coef_idx(codec, 0x4); /* HP */
6417 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006418}
6419
6420/*
6421 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006422static int patch_alc269(struct hda_codec *codec)
6423{
6424 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006425 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006426
Takashi Iwai3de95172012-05-07 18:03:15 +02006427 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006428 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006429 return err;
6430
6431 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01006432 spec->shared_mic_vref_pin = 0x18;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006433
Herton Ronaldo Krzesinski9f720bb92012-09-27 10:38:14 -03006434 alc_pick_fixup(codec, alc269_fixup_models,
6435 alc269_fixup_tbl, alc269_fixups);
6436 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6437
6438 alc_auto_parse_customize_define(codec);
6439
Kailang Yang065380f2013-01-10 10:25:48 +01006440 switch (codec->vendor_id) {
6441 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006442 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006443 switch (alc_get_coef0(codec) & 0x00f0) {
6444 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006445 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006446 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006447 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006448 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006449 break;
6450 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006451 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6452 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006453 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006454 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006455 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006456 case 0x0030:
6457 spec->codec_variant = ALC269_TYPE_ALC269VD;
6458 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006459 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006460 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006461 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006462 if (err < 0)
6463 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006464 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006465 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006466 break;
6467
6468 case 0x10ec0280:
6469 case 0x10ec0290:
6470 spec->codec_variant = ALC269_TYPE_ALC280;
6471 break;
6472 case 0x10ec0282:
6473 case 0x10ec0283:
6474 spec->codec_variant = ALC269_TYPE_ALC282;
6475 break;
6476 case 0x10ec0284:
6477 case 0x10ec0292:
6478 spec->codec_variant = ALC269_TYPE_ALC284;
6479 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006480 }
6481
Takashi Iwaia4297b52011-08-23 18:40:12 +02006482 /* automatic parse from the BIOS config */
6483 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006484 if (err < 0)
6485 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006486
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006487 if (!spec->no_analog && has_cdefine_beep(codec)) {
6488 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006489 if (err < 0)
6490 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006491 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006492 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006493
Takashi Iwai1d045db2011-07-07 18:23:21 +02006494 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006495#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006496 codec->patch_ops.resume = alc269_resume;
6497#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006498 spec->shutup = alc269_shutup;
6499
Takashi Iwai589876e2012-02-20 15:47:55 +01006500 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6501
Takashi Iwai1d045db2011-07-07 18:23:21 +02006502 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006503
6504 error:
6505 alc_free(codec);
6506 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006507}
6508
6509/*
6510 * ALC861
6511 */
6512
Takashi Iwai1d045db2011-07-07 18:23:21 +02006513static int alc861_parse_auto_config(struct hda_codec *codec)
6514{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006515 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006516 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6517 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006518}
6519
Takashi Iwai1d045db2011-07-07 18:23:21 +02006520/* Pin config fixes */
6521enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006522 ALC861_FIXUP_FSC_AMILO_PI1505,
6523 ALC861_FIXUP_AMP_VREF_0F,
6524 ALC861_FIXUP_NO_JACK_DETECT,
6525 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006526};
6527
Takashi Iwai31150f22012-01-30 10:54:08 +01006528/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6529static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6530 const struct alc_fixup *fix, int action)
6531{
6532 struct alc_spec *spec = codec->spec;
6533 unsigned int val;
6534
6535 if (action != ALC_FIXUP_ACT_INIT)
6536 return;
6537 val = snd_hda_codec_read(codec, 0x0f, 0,
6538 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6539 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6540 val |= AC_PINCTL_IN_EN;
6541 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006542 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006543 spec->keep_vref_in_automute = 1;
6544}
6545
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006546/* suppress the jack-detection */
6547static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6548 const struct alc_fixup *fix, int action)
6549{
6550 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6551 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006552}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006553
Takashi Iwai1d045db2011-07-07 18:23:21 +02006554static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006555 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006556 .type = ALC_FIXUP_PINS,
6557 .v.pins = (const struct alc_pincfg[]) {
6558 { 0x0b, 0x0221101f }, /* HP */
6559 { 0x0f, 0x90170310 }, /* speaker */
6560 { }
6561 }
6562 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006563 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006564 .type = ALC_FIXUP_FUNC,
6565 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006566 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006567 [ALC861_FIXUP_NO_JACK_DETECT] = {
6568 .type = ALC_FIXUP_FUNC,
6569 .v.func = alc_fixup_no_jack_detect,
6570 },
6571 [ALC861_FIXUP_ASUS_A6RP] = {
6572 .type = ALC_FIXUP_FUNC,
6573 .v.func = alc861_fixup_asus_amp_vref_0f,
6574 .chained = true,
6575 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6576 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006577};
6578
6579static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006580 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6581 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6582 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6583 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6584 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6585 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006586 {}
6587};
6588
6589/*
6590 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006591static int patch_alc861(struct hda_codec *codec)
6592{
6593 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006594 int err;
6595
Takashi Iwai3de95172012-05-07 18:03:15 +02006596 err = alc_alloc_spec(codec, 0x15);
6597 if (err < 0)
6598 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006599
Takashi Iwai3de95172012-05-07 18:03:15 +02006600 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006601
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006602 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6603 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006604
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006605 /* automatic parse from the BIOS config */
6606 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006607 if (err < 0)
6608 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006609
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006610 if (!spec->no_analog) {
6611 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006612 if (err < 0)
6613 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006614 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6615 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006616
Takashi Iwai1d045db2011-07-07 18:23:21 +02006617 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006618#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006619 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006620#endif
6621
Takashi Iwai589876e2012-02-20 15:47:55 +01006622 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6623
Takashi Iwai1d045db2011-07-07 18:23:21 +02006624 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006625
6626 error:
6627 alc_free(codec);
6628 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006629}
6630
6631/*
6632 * ALC861-VD support
6633 *
6634 * Based on ALC882
6635 *
6636 * In addition, an independent DAC
6637 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006638static int alc861vd_parse_auto_config(struct hda_codec *codec)
6639{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006640 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006641 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6642 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006643}
6644
Takashi Iwai1d045db2011-07-07 18:23:21 +02006645enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006646 ALC660VD_FIX_ASUS_GPIO1,
6647 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006648};
6649
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006650/* exclude VREF80 */
6651static void alc861vd_fixup_dallas(struct hda_codec *codec,
6652 const struct alc_fixup *fix, int action)
6653{
6654 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006655 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6656 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006657 }
6658}
6659
Takashi Iwai1d045db2011-07-07 18:23:21 +02006660static const struct alc_fixup alc861vd_fixups[] = {
6661 [ALC660VD_FIX_ASUS_GPIO1] = {
6662 .type = ALC_FIXUP_VERBS,
6663 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006664 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006665 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6666 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6667 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6668 { }
6669 }
6670 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006671 [ALC861VD_FIX_DALLAS] = {
6672 .type = ALC_FIXUP_FUNC,
6673 .v.func = alc861vd_fixup_dallas,
6674 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006675};
6676
6677static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006678 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006679 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006680 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006681 {}
6682};
6683
Takashi Iwai1d045db2011-07-07 18:23:21 +02006684/*
6685 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006686static int patch_alc861vd(struct hda_codec *codec)
6687{
6688 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006689 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006690
Takashi Iwai3de95172012-05-07 18:03:15 +02006691 err = alc_alloc_spec(codec, 0x0b);
6692 if (err < 0)
6693 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006694
Takashi Iwai3de95172012-05-07 18:03:15 +02006695 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006696
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006697 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6698 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006699
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006700 /* automatic parse from the BIOS config */
6701 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006702 if (err < 0)
6703 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006704
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006705 if (!spec->no_analog) {
6706 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006707 if (err < 0)
6708 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006709 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6710 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006711
Takashi Iwai1d045db2011-07-07 18:23:21 +02006712 codec->patch_ops = alc_patch_ops;
6713
Takashi Iwai1d045db2011-07-07 18:23:21 +02006714 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006715
Takashi Iwai589876e2012-02-20 15:47:55 +01006716 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6717
Takashi Iwai1d045db2011-07-07 18:23:21 +02006718 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006719
6720 error:
6721 alc_free(codec);
6722 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006723}
6724
6725/*
6726 * ALC662 support
6727 *
6728 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6729 * configuration. Each pin widget can choose any input DACs and a mixer.
6730 * Each ADC is connected from a mixer of all inputs. This makes possible
6731 * 6-channel independent captures.
6732 *
6733 * In addition, an independent DAC for the multi-playback (not used in this
6734 * driver yet).
6735 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006736
6737/*
6738 * BIOS auto configuration
6739 */
6740
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006741static int alc662_parse_auto_config(struct hda_codec *codec)
6742{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006743 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006744 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6745 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6746 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006747
Kailang Yang6227cdc2010-02-25 08:36:52 +01006748 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6749 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006750 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006751 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006752 ssids = alc662_ssids;
6753 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006754}
6755
Todd Broch6be79482010-12-07 16:51:05 -08006756static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006757 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006758{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006759 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006760 return;
Todd Broch6be79482010-12-07 16:51:05 -08006761 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6762 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6763 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6764 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6765 (0 << AC_AMPCAP_MUTE_SHIFT)))
6766 printk(KERN_WARNING
6767 "hda_codec: failed to override amp caps for NID 0x2\n");
6768}
6769
David Henningsson6cb3b702010-09-09 08:51:44 +02006770enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006771 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006772 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006773 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006774 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006775 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006776 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006777 ALC662_FIXUP_ASUS_MODE1,
6778 ALC662_FIXUP_ASUS_MODE2,
6779 ALC662_FIXUP_ASUS_MODE3,
6780 ALC662_FIXUP_ASUS_MODE4,
6781 ALC662_FIXUP_ASUS_MODE5,
6782 ALC662_FIXUP_ASUS_MODE6,
6783 ALC662_FIXUP_ASUS_MODE7,
6784 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006785 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006786 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006787 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006788};
6789
6790static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006791 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006792 .type = ALC_FIXUP_PINS,
6793 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006794 { 0x15, 0x99130112 }, /* subwoofer */
6795 { }
6796 }
6797 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006798 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006799 .type = ALC_FIXUP_PINS,
6800 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006801 { 0x17, 0x99130112 }, /* subwoofer */
6802 { }
6803 }
6804 },
Todd Broch6be79482010-12-07 16:51:05 -08006805 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006806 .type = ALC_FIXUP_FUNC,
6807 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006808 },
6809 [ALC662_FIXUP_CZC_P10T] = {
6810 .type = ALC_FIXUP_VERBS,
6811 .v.verbs = (const struct hda_verb[]) {
6812 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6813 {}
6814 }
6815 },
David Henningsson94024cd2011-04-29 14:10:55 +02006816 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006817 .type = ALC_FIXUP_FUNC,
6818 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006819 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006820 [ALC662_FIXUP_HP_RP5800] = {
6821 .type = ALC_FIXUP_PINS,
6822 .v.pins = (const struct alc_pincfg[]) {
6823 { 0x14, 0x0221201f }, /* HP out */
6824 { }
6825 },
6826 .chained = true,
6827 .chain_id = ALC662_FIXUP_SKU_IGNORE
6828 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006829 [ALC662_FIXUP_ASUS_MODE1] = {
6830 .type = ALC_FIXUP_PINS,
6831 .v.pins = (const struct alc_pincfg[]) {
6832 { 0x14, 0x99130110 }, /* speaker */
6833 { 0x18, 0x01a19c20 }, /* mic */
6834 { 0x19, 0x99a3092f }, /* int-mic */
6835 { 0x21, 0x0121401f }, /* HP out */
6836 { }
6837 },
6838 .chained = true,
6839 .chain_id = ALC662_FIXUP_SKU_IGNORE
6840 },
6841 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006842 .type = ALC_FIXUP_PINS,
6843 .v.pins = (const struct alc_pincfg[]) {
6844 { 0x14, 0x99130110 }, /* speaker */
6845 { 0x18, 0x01a19820 }, /* mic */
6846 { 0x19, 0x99a3092f }, /* int-mic */
6847 { 0x1b, 0x0121401f }, /* HP out */
6848 { }
6849 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006850 .chained = true,
6851 .chain_id = ALC662_FIXUP_SKU_IGNORE
6852 },
6853 [ALC662_FIXUP_ASUS_MODE3] = {
6854 .type = ALC_FIXUP_PINS,
6855 .v.pins = (const struct alc_pincfg[]) {
6856 { 0x14, 0x99130110 }, /* speaker */
6857 { 0x15, 0x0121441f }, /* HP */
6858 { 0x18, 0x01a19840 }, /* mic */
6859 { 0x19, 0x99a3094f }, /* int-mic */
6860 { 0x21, 0x01211420 }, /* HP2 */
6861 { }
6862 },
6863 .chained = true,
6864 .chain_id = ALC662_FIXUP_SKU_IGNORE
6865 },
6866 [ALC662_FIXUP_ASUS_MODE4] = {
6867 .type = ALC_FIXUP_PINS,
6868 .v.pins = (const struct alc_pincfg[]) {
6869 { 0x14, 0x99130110 }, /* speaker */
6870 { 0x16, 0x99130111 }, /* speaker */
6871 { 0x18, 0x01a19840 }, /* mic */
6872 { 0x19, 0x99a3094f }, /* int-mic */
6873 { 0x21, 0x0121441f }, /* HP */
6874 { }
6875 },
6876 .chained = true,
6877 .chain_id = ALC662_FIXUP_SKU_IGNORE
6878 },
6879 [ALC662_FIXUP_ASUS_MODE5] = {
6880 .type = ALC_FIXUP_PINS,
6881 .v.pins = (const struct alc_pincfg[]) {
6882 { 0x14, 0x99130110 }, /* speaker */
6883 { 0x15, 0x0121441f }, /* HP */
6884 { 0x16, 0x99130111 }, /* speaker */
6885 { 0x18, 0x01a19840 }, /* mic */
6886 { 0x19, 0x99a3094f }, /* int-mic */
6887 { }
6888 },
6889 .chained = true,
6890 .chain_id = ALC662_FIXUP_SKU_IGNORE
6891 },
6892 [ALC662_FIXUP_ASUS_MODE6] = {
6893 .type = ALC_FIXUP_PINS,
6894 .v.pins = (const struct alc_pincfg[]) {
6895 { 0x14, 0x99130110 }, /* speaker */
6896 { 0x15, 0x01211420 }, /* HP2 */
6897 { 0x18, 0x01a19840 }, /* mic */
6898 { 0x19, 0x99a3094f }, /* int-mic */
6899 { 0x1b, 0x0121441f }, /* HP */
6900 { }
6901 },
6902 .chained = true,
6903 .chain_id = ALC662_FIXUP_SKU_IGNORE
6904 },
6905 [ALC662_FIXUP_ASUS_MODE7] = {
6906 .type = ALC_FIXUP_PINS,
6907 .v.pins = (const struct alc_pincfg[]) {
6908 { 0x14, 0x99130110 }, /* speaker */
6909 { 0x17, 0x99130111 }, /* speaker */
6910 { 0x18, 0x01a19840 }, /* mic */
6911 { 0x19, 0x99a3094f }, /* int-mic */
6912 { 0x1b, 0x01214020 }, /* HP */
6913 { 0x21, 0x0121401f }, /* HP */
6914 { }
6915 },
6916 .chained = true,
6917 .chain_id = ALC662_FIXUP_SKU_IGNORE
6918 },
6919 [ALC662_FIXUP_ASUS_MODE8] = {
6920 .type = ALC_FIXUP_PINS,
6921 .v.pins = (const struct alc_pincfg[]) {
6922 { 0x14, 0x99130110 }, /* speaker */
6923 { 0x12, 0x99a30970 }, /* int-mic */
6924 { 0x15, 0x01214020 }, /* HP */
6925 { 0x17, 0x99130111 }, /* speaker */
6926 { 0x18, 0x01a19840 }, /* mic */
6927 { 0x21, 0x0121401f }, /* HP */
6928 { }
6929 },
6930 .chained = true,
6931 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006932 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006933 [ALC662_FIXUP_NO_JACK_DETECT] = {
6934 .type = ALC_FIXUP_FUNC,
6935 .v.func = alc_fixup_no_jack_detect,
6936 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006937 [ALC662_FIXUP_ZOTAC_Z68] = {
6938 .type = ALC_FIXUP_PINS,
6939 .v.pins = (const struct alc_pincfg[]) {
6940 { 0x1b, 0x02214020 }, /* Front HP */
6941 { }
6942 }
6943 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006944 [ALC662_FIXUP_INV_DMIC] = {
6945 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006946 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006947 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006948};
6949
Takashi Iwaia9111322011-05-02 11:30:18 +02006950static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006951 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006952 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006953 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006954 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006955 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006956 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006957 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006958 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006959 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006960 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006961 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006962 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006963 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006964
6965#if 0
6966 /* Below is a quirk table taken from the old code.
6967 * Basically the device should work as is without the fixup table.
6968 * If BIOS doesn't give a proper info, enable the corresponding
6969 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006970 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006971 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6972 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6973 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6974 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6975 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6976 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6977 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6978 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6979 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6980 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6981 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6982 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6983 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6984 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6985 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6986 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6987 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6988 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6989 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6990 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6991 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6992 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6993 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6994 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6995 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6996 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6997 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6998 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6999 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7000 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7001 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7002 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7003 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7004 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7005 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7006 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7007 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7008 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7009 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7010 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7011 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7012 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7013 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7014 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7015 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7016 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7017 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7018 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7019 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7020 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7021#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007022 {}
7023};
7024
Todd Broch6be79482010-12-07 16:51:05 -08007025static const struct alc_model_fixup alc662_fixup_models[] = {
7026 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007027 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7028 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7029 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7030 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7031 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7032 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7033 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7034 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007035 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007036 {}
7037};
David Henningsson6cb3b702010-09-09 08:51:44 +02007038
Kailang Yang8663ff72012-06-29 09:35:52 +02007039static void alc662_fill_coef(struct hda_codec *codec)
7040{
7041 int val, coef;
7042
7043 coef = alc_get_coef0(codec);
7044
7045 switch (codec->vendor_id) {
7046 case 0x10ec0662:
7047 if ((coef & 0x00f0) == 0x0030) {
7048 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7049 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7050 }
7051 break;
7052 case 0x10ec0272:
7053 case 0x10ec0273:
7054 case 0x10ec0663:
7055 case 0x10ec0665:
7056 case 0x10ec0670:
7057 case 0x10ec0671:
7058 case 0x10ec0672:
7059 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7060 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7061 break;
7062 }
7063}
David Henningsson6cb3b702010-09-09 08:51:44 +02007064
Takashi Iwai1d045db2011-07-07 18:23:21 +02007065/*
7066 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007067static int patch_alc662(struct hda_codec *codec)
7068{
7069 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007070 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007071
Takashi Iwai3de95172012-05-07 18:03:15 +02007072 err = alc_alloc_spec(codec, 0x0b);
7073 if (err < 0)
7074 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007075
Takashi Iwai3de95172012-05-07 18:03:15 +02007076 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007077
Takashi Iwai53c334a2011-08-23 18:27:14 +02007078 /* handle multiple HPs as is */
7079 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7080
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007081 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7082
Kailang Yang8663ff72012-06-29 09:35:52 +02007083 spec->init_hook = alc662_fill_coef;
7084 alc662_fill_coef(codec);
7085
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007086 alc_pick_fixup(codec, alc662_fixup_models,
7087 alc662_fixup_tbl, alc662_fixups);
7088 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7089
7090 alc_auto_parse_customize_define(codec);
7091
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007092 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007093 codec->bus->pci->subsystem_vendor == 0x1025 &&
7094 spec->cdefine.platform_type == 1) {
7095 if (alc_codec_rename(codec, "ALC272X") < 0)
7096 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007097 }
Kailang Yang274693f2009-12-03 10:07:50 +01007098
Takashi Iwaib9c51062011-08-24 18:08:07 +02007099 /* automatic parse from the BIOS config */
7100 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007101 if (err < 0)
7102 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007103
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007104 if (!spec->no_analog && has_cdefine_beep(codec)) {
7105 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007106 if (err < 0)
7107 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007108 switch (codec->vendor_id) {
7109 case 0x10ec0662:
7110 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7111 break;
7112 case 0x10ec0272:
7113 case 0x10ec0663:
7114 case 0x10ec0665:
7115 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7116 break;
7117 case 0x10ec0273:
7118 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7119 break;
7120 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007121 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007122
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007123 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02007124 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007125
Takashi Iwai589876e2012-02-20 15:47:55 +01007126 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7127
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007128 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007129
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007130 error:
7131 alc_free(codec);
7132 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007133}
7134
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007135/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007136 * ALC680 support
7137 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007138
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007139static int alc680_parse_auto_config(struct hda_codec *codec)
7140{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007141 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007142}
7143
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007144/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007145 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007146static int patch_alc680(struct hda_codec *codec)
7147{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007148 int err;
7149
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007150 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007151 err = alc_alloc_spec(codec, 0);
7152 if (err < 0)
7153 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007154
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007155 /* automatic parse from the BIOS config */
7156 err = alc680_parse_auto_config(codec);
7157 if (err < 0) {
7158 alc_free(codec);
7159 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007160 }
7161
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007162 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007163
7164 return 0;
7165}
7166
7167/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007168 * patch entries
7169 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007170static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007171 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007172 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007173 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007174 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007175 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007176 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007177 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007178 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007179 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007180 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007181 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007182 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007183 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007184 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007185 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007186 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007187 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007188 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007189 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7190 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7191 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007192 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007193 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007194 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7195 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007196 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7197 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007198 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007199 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007200 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007201 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007202 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007203 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007204 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007205 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007206 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007207 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007208 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007209 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007210 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007211 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007212 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007213 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007214 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007215 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007216 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007217 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007218 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007219 {} /* terminator */
7220};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007221
7222MODULE_ALIAS("snd-hda-codec-id:10ec*");
7223
7224MODULE_LICENSE("GPL");
7225MODULE_DESCRIPTION("Realtek HD-audio codec");
7226
7227static struct hda_codec_preset_list realtek_list = {
7228 .preset = snd_hda_preset_realtek,
7229 .owner = THIS_MODULE,
7230};
7231
7232static int __init patch_realtek_init(void)
7233{
7234 return snd_hda_add_codec_preset(&realtek_list);
7235}
7236
7237static void __exit patch_realtek_exit(void)
7238{
7239 snd_hda_delete_codec_preset(&realtek_list);
7240}
7241
7242module_init(patch_realtek_init)
7243module_exit(patch_realtek_exit)