blob: fbdcbded3417d7168c7ee3fcf01653251e6e1f48 [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 Iwai23d30f22012-05-07 17:17:32 +020076/* make compatible with old code */
77#define alc_apply_pincfgs snd_hda_apply_pincfgs
78#define alc_apply_fixup snd_hda_apply_fixup
79#define alc_pick_fixup snd_hda_pick_fixup
80#define alc_fixup hda_fixup
81#define alc_pincfg hda_pintbl
82#define alc_model_fixup hda_model_fixup
83
84#define ALC_FIXUP_PINS HDA_FIXUP_PINS
85#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
86#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
87
88#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
89#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
90#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
91#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
92
93
Takashi Iwai30dcd3b2012-12-06 15:45:38 +010094#define MAX_NID_PATH_DEPTH 5
95
Takashi Iwai8dd48672012-12-14 18:19:04 +010096enum {
97 NID_PATH_VOL_CTL,
98 NID_PATH_MUTE_CTL,
99 NID_PATH_BOOST_CTL,
100 NID_PATH_NUM_CTLS
101};
102
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100103/* Widget connection path
104 *
105 * For output, stored in the order of DAC -> ... -> pin,
106 * for input, pin -> ... -> ADC.
107 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100108 * idx[i] contains the source index number to select on of the widget path[i];
109 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100110 * multi[] indicates whether it's a selector widget with multi-connectors
111 * (i.e. the connection selection is mandatory)
112 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
113 */
114struct nid_path {
115 int depth;
116 hda_nid_t path[MAX_NID_PATH_DEPTH];
117 unsigned char idx[MAX_NID_PATH_DEPTH];
118 unsigned char multi[MAX_NID_PATH_DEPTH];
Takashi Iwai8dd48672012-12-14 18:19:04 +0100119 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
Takashi Iwai130e5f02012-12-14 16:09:29 +0100120 bool active;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100121};
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200124 struct hda_gen_spec gen;
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200127 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 unsigned int num_mixers;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100129 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200131 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200132 const struct hda_pcm_stream *stream_analog_playback;
133 const struct hda_pcm_stream *stream_analog_capture;
134 const struct hda_pcm_stream *stream_analog_alt_playback;
135 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200137 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200138 const struct hda_pcm_stream *stream_digital_playback;
139 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200142 struct hda_multi_out multiout; /* playback set-up
143 * max_channels, dacs must be set
144 * dig_out_nid and hp_nid are optional
145 */
Takashi Iwai63300792008-01-24 15:31:36 +0100146 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100147 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100148 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 /* capture */
151 unsigned int num_adc_nids;
Takashi Iwai27d31532012-12-18 08:57:05 +0100152 hda_nid_t adc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai16ded522005-06-10 19:58:24 +0200153 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200154 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Takashi Iwai840b64c2010-07-13 22:49:01 +0200156 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200157 hda_nid_t cur_adc;
158 unsigned int cur_adc_stream_tag;
159 unsigned int cur_adc_format;
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 /* capture source */
Takashi Iwai27d31532012-12-18 08:57:05 +0100162 struct hda_input_mux input_mux;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200164 hda_nid_t ext_mic_pin;
165 hda_nid_t dock_mic_pin;
166 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100169 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 int num_channel_mode;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100171 int const_channel_count; /* min. channel count (for speakers) */
172 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100175 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200176
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200177 /* dynamic controls, init_verbs and input_mux */
178 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100179 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200180 struct snd_array kctls;
Takashi Iwai41923e42007-10-22 17:20:10 +0200181 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200182 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
183 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
184 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200185 hda_nid_t inv_dmic_pin;
Takashi Iwai37c04202012-12-18 14:22:45 +0100186 hda_nid_t shared_mic_vref_pin;
Takashi Iwai81fede82012-12-18 17:24:25 +0100187 int inv_dmic_split_idx; /* used internally for inv_dmic_split */
Takashi Iwai834be882006-03-01 14:16:17 +0100188
Takashi Iwai463419d2012-12-05 14:17:37 +0100189 /* DAC list */
190 int num_all_dacs;
191 hda_nid_t all_dacs[16];
192
Takashi Iwaic9967f12012-12-14 16:39:22 +0100193 /* path list */
194 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100195
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100196 /* hooks */
197 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200198#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500199 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100200#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200201 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200202 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100203
Takashi Iwai834be882006-03-01 14:16:17 +0100204 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200205 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200206 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200207 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200208 unsigned int auto_mic:1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200209 unsigned int automute_speaker:1; /* automute speaker outputs */
210 unsigned int automute_lo:1; /* automute LO outputs */
211 unsigned int detect_hp:1; /* Headphone detection enabled */
212 unsigned int detect_lo:1; /* Line-out detection enabled */
213 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
214 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100215 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200216
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100217 /* other flags */
Takashi Iwai20c18f52012-12-18 14:33:21 +0100218 unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100219 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200220 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai24de1832011-11-07 17:13:39 +0100221 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200222 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
223 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200224 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwai9bf387b2012-12-18 17:18:21 +0100225 unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */
Takashi Iwai81fede82012-12-18 17:24:25 +0100226 unsigned int inv_dmic_split:1; /* inverted dmic w/a for conexant */
Takashi Iwaid922b512011-04-28 12:18:53 +0200227
Takashi Iwai20c18f52012-12-18 14:33:21 +0100228 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwaid922b512011-04-28 12:18:53 +0200229
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200230 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200231 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100232
Takashi Iwai2134ea42008-01-10 16:53:55 +0100233 /* for virtual master */
234 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100235 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200236#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200237 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100238 int num_loopbacks;
239 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200240#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200241
242 /* for PLL fix */
243 hda_nid_t pll_nid;
244 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200245 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100246
Takashi Iwaice764ab2011-04-27 16:35:23 +0200247 /* multi-io */
248 int multi_ios;
249 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200250
251 /* bind volumes */
252 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100253};
254
Takashi Iwai44c02402011-07-08 15:14:19 +0200255static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
256 int dir, unsigned int bits)
257{
258 if (!nid)
259 return false;
260 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
261 if (query_amp_caps(codec, nid, dir) & bits)
262 return true;
263 return false;
264}
265
266#define nid_has_mute(codec, nid, dir) \
267 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
268#define nid_has_volume(codec, nid, dir) \
269 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
270
Takashi Iwai666a70d2012-12-17 20:29:29 +0100271static struct nid_path *
272get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid);
273static void activate_path(struct hda_codec *codec, struct nid_path *path,
274 bool enable, bool add_aamix);
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276/*
277 * input MUX handling
278 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200279static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
282 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
283 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +0100284 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200287static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
288 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
291 struct alc_spec *spec = codec->spec;
292 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
293
294 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
295 return 0;
296}
297
Takashi Iwai666a70d2012-12-17 20:29:29 +0100298static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
299{
300 struct alc_spec *spec = codec->spec;
301 if (spec->dyn_adc_switch)
302 adc_idx = spec->dyn_adc_idx[imux_idx];
303 return spec->adc_nids[adc_idx];
304}
305
Takashi Iwai21268962011-07-07 15:01:13 +0200306static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
Takashi Iwai21268962011-07-07 15:01:13 +0200308 struct alc_spec *spec = codec->spec;
309 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
310
311 if (spec->cur_adc && spec->cur_adc != new_adc) {
312 /* stream is running, let's swap the current ADC */
313 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
314 spec->cur_adc = new_adc;
315 snd_hda_codec_setup_stream(codec, new_adc,
316 spec->cur_adc_stream_tag, 0,
317 spec->cur_adc_format);
318 return true;
319 }
320 return false;
321}
322
Takashi Iwai24de1832011-11-07 17:13:39 +0100323static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200324static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100325static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx);
Takashi Iwai24de1832011-11-07 17:13:39 +0100326
David Henningsson00227f12012-06-27 18:45:44 +0200327/* for shared I/O, change the pin-control accordingly */
328static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
329{
330 struct alc_spec *spec = codec->spec;
331 unsigned int val;
332 hda_nid_t pin = spec->autocfg.inputs[1].pin;
333 /* NOTE: this assumes that there are only two inputs, the
334 * first is the real internal mic and the second is HP/mic jack.
335 */
336
337 val = snd_hda_get_default_vref(codec, pin);
338
339 /* This pin does not have vref caps - let's enable vref on pin 0x18
340 instead, as suggested by Realtek */
Takashi Iwai37c04202012-12-18 14:22:45 +0100341 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
342 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
343 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
344 if (vref_val != AC_PINCTL_VREF_HIZ)
345 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
David Henningsson00227f12012-06-27 18:45:44 +0200346 }
347
348 val = set_as_mic ? val | PIN_IN : PIN_HP;
349 snd_hda_set_pin_ctl(codec, pin, val);
350
351 spec->automute_speaker = !set_as_mic;
352 call_update_outputs(codec);
353}
Takashi Iwai21268962011-07-07 15:01:13 +0200354
355/* select the given imux item; either unmute exclusively or select the route */
356static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
357 unsigned int idx, bool force)
358{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100360 const struct hda_input_mux *imux;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100361 struct nid_path *path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Takashi Iwai27d31532012-12-18 08:57:05 +0100363 imux = &spec->input_mux;
364 if (!imux->num_items)
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100365 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100366
Takashi Iwai21268962011-07-07 15:01:13 +0200367 if (idx >= imux->num_items)
368 idx = imux->num_items - 1;
369 if (spec->cur_mux[adc_idx] == idx && !force)
370 return 0;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100371
372 path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]],
373 spec->adc_nids[adc_idx]);
374 if (!path)
375 return 0;
376 if (path->active)
377 activate_path(codec, path, false, false);
378
Takashi Iwai21268962011-07-07 15:01:13 +0200379 spec->cur_mux[adc_idx] = idx;
380
David Henningsson00227f12012-06-27 18:45:44 +0200381 if (spec->shared_mic_hp)
382 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100383
Takashi Iwai666a70d2012-12-17 20:29:29 +0100384 if (spec->dyn_adc_switch)
Takashi Iwai21268962011-07-07 15:01:13 +0200385 alc_dyn_adc_pcm_resetup(codec, idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200386
Takashi Iwai666a70d2012-12-17 20:29:29 +0100387 path = get_nid_path(codec, spec->imux_pins[idx],
388 get_adc_nid(codec, adc_idx, idx));
389 if (!path)
390 return 0;
391 if (path->active)
392 return 0;
393 activate_path(codec, path, true, false);
Takashi Iwai125821a2012-06-22 14:30:29 +0200394 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200395 return 1;
396}
397
398static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403 return alc_mux_select(codec, adc_idx,
404 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100405}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100408 * set up the input pin config (depending on the given auto-pin type)
409 */
410static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
411 int auto_pin_type)
412{
413 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200414 if (auto_pin_type == AUTO_PIN_MIC)
415 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200416 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100417}
418
419/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200420 * Append the given mixer and verb elements for the later use
421 * The mixer array is referred in build_controls(), and init_verbs are
422 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100423 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200424static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100425{
426 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
427 return;
428 spec->mixers[spec->num_mixers++] = mix;
429}
430
Takashi Iwaid88897e2008-10-31 15:01:37 +0100431/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200432 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100433 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200434/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200435static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200436 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
437 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
438 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
439 { }
440};
441
Takashi Iwaia9111322011-05-02 11:30:18 +0200442static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200443 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
444 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
445 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
446 { }
447};
448
Takashi Iwaia9111322011-05-02 11:30:18 +0200449static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200450 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
451 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
452 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
453 { }
454};
455
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200456/*
457 * Fix hardware PLL issue
458 * On some codecs, the analog PLL gating control must be off while
459 * the default value is 1.
460 */
461static void alc_fix_pll(struct hda_codec *codec)
462{
463 struct alc_spec *spec = codec->spec;
464 unsigned int val;
465
466 if (!spec->pll_nid)
467 return;
468 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
469 spec->pll_coef_idx);
470 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
471 AC_VERB_GET_PROC_COEF, 0);
472 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
473 spec->pll_coef_idx);
474 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
475 val & ~(1 << spec->pll_coef_bit));
476}
477
478static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
479 unsigned int coef_idx, unsigned int coef_bit)
480{
481 struct alc_spec *spec = codec->spec;
482 spec->pll_nid = nid;
483 spec->pll_coef_idx = coef_idx;
484 spec->pll_coef_bit = coef_bit;
485 alc_fix_pll(codec);
486}
487
Takashi Iwai1d045db2011-07-07 18:23:21 +0200488/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200489 * Jack detections for HP auto-mute and mic-switch
490 */
491
492/* check each pin in the given array; returns true if any of them is plugged */
493static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200494{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200496
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200499 if (!nid)
500 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200502 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200503 return present;
504}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200505
Takashi Iwai1d045db2011-07-07 18:23:21 +0200506/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200508 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200509{
510 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200511 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200512 int i;
513
514 for (i = 0; i < num_pins; i++) {
515 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100516 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200517 if (!nid)
518 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100519 /* don't reset VREF value in case it's controlling
520 * the amp (see alc861_fixup_asus_amp_vref_0f())
521 */
522 if (spec->keep_vref_in_automute) {
523 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100524 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100525 val &= ~PIN_HP;
526 } else
527 val = 0;
528 val |= pin_bits;
529 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200530 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200531}
532
David Henningsson42cf0d02011-09-20 12:04:56 +0200533/* Toggle outputs muting */
534static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200535{
536 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200537 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200538
Takashi Iwaic0a20262011-06-10 15:28:15 +0200539 /* Control HP pins/amps depending on master_mute state;
540 * in general, HP pins/amps control should be enabled in all cases,
541 * but currently set only for master_mute, just to be safe
542 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100543 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
544 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200545 spec->autocfg.hp_pins, spec->master_mute, true);
546
David Henningsson42cf0d02011-09-20 12:04:56 +0200547 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200548 on = 0;
549 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200550 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200551 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200552 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200553 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200554
555 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200556 /* if LO is a copy of either HP or Speaker, don't need to handle it */
557 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
558 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200559 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200560 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200561 on = 0;
562 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200563 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200564 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200565 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200567}
568
David Henningsson42cf0d02011-09-20 12:04:56 +0200569static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200570{
571 struct alc_spec *spec = codec->spec;
572 if (spec->automute_hook)
573 spec->automute_hook(codec);
574 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200575 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200576}
577
Takashi Iwai1d045db2011-07-07 18:23:21 +0200578/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200579static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200580{
581 struct alc_spec *spec = codec->spec;
582
David Henningsson42cf0d02011-09-20 12:04:56 +0200583 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200584 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
585 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200586 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200587 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200588 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200589}
590
Takashi Iwai1d045db2011-07-07 18:23:21 +0200591/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200592static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200593{
594 struct alc_spec *spec = codec->spec;
595
David Henningssonf7f4b232012-10-10 16:32:09 +0200596 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
597 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200598 /* check LO jack only when it's different from HP */
599 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
600 return;
601
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602 spec->line_jack_present =
603 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
604 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200605 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200606 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200607 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200608}
609
Takashi Iwai1d045db2011-07-07 18:23:21 +0200610/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200611static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200612{
613 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200614 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200615
Takashi Iwai480967d2012-12-18 14:29:52 +0100616 if (!spec->auto_mic)
Takashi Iwai6c819492009-08-10 18:47:44 +0200617 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200618 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200619 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200620
Takashi Iwai21268962011-07-07 15:01:13 +0200621 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
622 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
623 else if (spec->dock_mic_idx >= 0 &&
624 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
625 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
626 else
627 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200628}
629
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100630/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200631static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100632{
633 unsigned int val;
634 struct snd_kcontrol *kctl;
635 struct snd_ctl_elem_value *uctl;
636
637 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
638 if (!kctl)
639 return;
640 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
641 if (!uctl)
642 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200643 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100644 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
645 val &= HDA_AMP_VOLMASK;
646 uctl->value.integer.value[0] = val;
647 uctl->value.integer.value[1] = val;
648 kctl->put(kctl, uctl);
649 kfree(uctl);
650}
651
David Henningsson29adc4b2012-09-25 11:31:00 +0200652static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100653{
David Henningsson29adc4b2012-09-25 11:31:00 +0200654 /* For some reason, the res given from ALC880 is broken.
655 Here we adjust it properly. */
656 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100657}
658
Kailang Yangf9423e72008-05-27 12:32:25 +0200659/* additional initialization for ALC888 variants */
660static void alc888_coef_init(struct hda_codec *codec)
661{
662 unsigned int tmp;
663
664 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
665 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
666 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100667 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200668 /* alc888S-VC */
669 snd_hda_codec_read(codec, 0x20, 0,
670 AC_VERB_SET_PROC_COEF, 0x830);
671 else
672 /* alc888-VB */
673 snd_hda_codec_read(codec, 0x20, 0,
674 AC_VERB_SET_PROC_COEF, 0x3030);
675}
676
Takashi Iwai1d045db2011-07-07 18:23:21 +0200677/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200678static void alc889_coef_init(struct hda_codec *codec)
679{
680 unsigned int tmp;
681
682 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
683 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
684 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
685 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
686}
687
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100688/* turn on/off EAPD control (only if available) */
689static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
690{
691 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
692 return;
693 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
694 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
695 on ? 2 : 0);
696}
697
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200698/* turn on/off EAPD controls of the codec */
699static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
700{
701 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200702 static hda_nid_t pins[] = {
703 0x0f, 0x10, 0x14, 0x15, 0
704 };
705 hda_nid_t *p;
706 for (p = pins; *p; p++)
707 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200708}
709
Takashi Iwai1c716152011-04-07 10:37:16 +0200710/* generic shutup callback;
711 * just turning off EPAD and a little pause for avoiding pop-noise
712 */
713static void alc_eapd_shutup(struct hda_codec *codec)
714{
715 alc_auto_setup_eapd(codec, false);
716 msleep(200);
717}
718
Takashi Iwai1d045db2011-07-07 18:23:21 +0200719/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200720static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200721{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200722 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200723
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200724 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200725 switch (type) {
726 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200727 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
728 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200729 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200730 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
731 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200732 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200733 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
734 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200735 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200736 switch (codec->vendor_id) {
737 case 0x10ec0260:
738 snd_hda_codec_write(codec, 0x1a, 0,
739 AC_VERB_SET_COEF_INDEX, 7);
740 tmp = snd_hda_codec_read(codec, 0x1a, 0,
741 AC_VERB_GET_PROC_COEF, 0);
742 snd_hda_codec_write(codec, 0x1a, 0,
743 AC_VERB_SET_COEF_INDEX, 7);
744 snd_hda_codec_write(codec, 0x1a, 0,
745 AC_VERB_SET_PROC_COEF,
746 tmp | 0x2010);
747 break;
748 case 0x10ec0262:
749 case 0x10ec0880:
750 case 0x10ec0882:
751 case 0x10ec0883:
752 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100753 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100754 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200755 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200756 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200757 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200758 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200759 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100760#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200761 case 0x10ec0267:
762 case 0x10ec0268:
763 snd_hda_codec_write(codec, 0x20, 0,
764 AC_VERB_SET_COEF_INDEX, 7);
765 tmp = snd_hda_codec_read(codec, 0x20, 0,
766 AC_VERB_GET_PROC_COEF, 0);
767 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200768 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200769 snd_hda_codec_write(codec, 0x20, 0,
770 AC_VERB_SET_PROC_COEF,
771 tmp | 0x3000);
772 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100773#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200774 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200775 break;
776 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777}
Kailang Yangea1fb292008-08-26 12:58:38 +0200778
Takashi Iwai1d045db2011-07-07 18:23:21 +0200779/*
780 * Auto-Mute mode mixer enum support
781 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200782static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
783 struct snd_ctl_elem_info *uinfo)
784{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200785 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
786 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200787 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100788 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200789 };
790
Takashi Iwaidda415d2012-11-30 18:34:38 +0100791 if (spec->automute_speaker_possible && spec->automute_lo_possible)
792 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
793 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200794}
795
796static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
797 struct snd_ctl_elem_value *ucontrol)
798{
799 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
800 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200801 unsigned int val = 0;
802 if (spec->automute_speaker)
803 val++;
804 if (spec->automute_lo)
805 val++;
806
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200807 ucontrol->value.enumerated.item[0] = val;
808 return 0;
809}
810
811static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_value *ucontrol)
813{
814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct alc_spec *spec = codec->spec;
816
817 switch (ucontrol->value.enumerated.item[0]) {
818 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200819 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200820 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200821 spec->automute_speaker = 0;
822 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200823 break;
824 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200825 if (spec->automute_speaker_possible) {
826 if (!spec->automute_lo && spec->automute_speaker)
827 return 0;
828 spec->automute_speaker = 1;
829 spec->automute_lo = 0;
830 } else if (spec->automute_lo_possible) {
831 if (spec->automute_lo)
832 return 0;
833 spec->automute_lo = 1;
834 } else
835 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200836 break;
837 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200838 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200839 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200840 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200841 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200842 spec->automute_speaker = 1;
843 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200844 break;
845 default:
846 return -EINVAL;
847 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200848 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200849 return 1;
850}
851
Takashi Iwaia9111322011-05-02 11:30:18 +0200852static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200853 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
854 .name = "Auto-Mute Mode",
855 .info = alc_automute_mode_info,
856 .get = alc_automute_mode_get,
857 .put = alc_automute_mode_put,
858};
859
Takashi Iwai668d1e92012-11-29 14:10:17 +0100860static struct snd_kcontrol_new *
861alc_kcontrol_new(struct alc_spec *spec, const char *name,
862 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200863{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100864 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
865 if (!knew)
866 return NULL;
867 *knew = *temp;
Takashi Iwaibc549762012-12-18 15:35:11 +0100868 if (name)
869 knew->name = kstrdup(name, GFP_KERNEL);
870 else if (knew->name)
871 knew->name = kstrdup(knew->name, GFP_KERNEL);
Takashi Iwai668d1e92012-11-29 14:10:17 +0100872 if (!knew->name)
873 return NULL;
874 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200875}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200876
877static int alc_add_automute_mode_enum(struct hda_codec *codec)
878{
879 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880
Takashi Iwaibc549762012-12-18 15:35:11 +0100881 if (!alc_kcontrol_new(spec, NULL, &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200882 return -ENOMEM;
883 return 0;
884}
885
Takashi Iwai1d045db2011-07-07 18:23:21 +0200886/*
887 * Check the availability of HP/line-out auto-mute;
888 * Set up appropriately if really supported
889 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100890static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200891{
892 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200893 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200894 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100895 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200896
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200897 if (cfg->hp_pins[0])
898 present++;
899 if (cfg->line_out_pins[0])
900 present++;
901 if (cfg->speaker_pins[0])
902 present++;
903 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100904 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200905
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200906 if (!cfg->speaker_pins[0] &&
907 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200908 memcpy(cfg->speaker_pins, cfg->line_out_pins,
909 sizeof(cfg->speaker_pins));
910 cfg->speaker_outs = cfg->line_outs;
911 }
912
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200913 if (!cfg->hp_pins[0] &&
914 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200915 memcpy(cfg->hp_pins, cfg->line_out_pins,
916 sizeof(cfg->hp_pins));
917 cfg->hp_outs = cfg->line_outs;
918 }
919
920 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200921 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200922 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200923 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200924 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200925 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200926 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
927 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200928 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200929 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200930
David Henningsson42cf0d02011-09-20 12:04:56 +0200931 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
932 if (cfg->speaker_outs)
933 for (i = 0; i < cfg->line_outs; i++) {
934 hda_nid_t nid = cfg->line_out_pins[i];
935 if (!is_jack_detectable(codec, nid))
936 continue;
937 snd_printdd("realtek: Enable Line-Out "
938 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200939 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
940 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200941 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200942 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200943 spec->automute_lo_possible = spec->detect_hp;
944 }
945
946 spec->automute_speaker_possible = cfg->speaker_outs &&
947 (spec->detect_hp || spec->detect_lo);
948
949 spec->automute_lo = spec->automute_lo_possible;
950 spec->automute_speaker = spec->automute_speaker_possible;
951
Takashi Iwai475c3d22012-11-30 08:31:30 +0100952 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200953 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100954 err = alc_add_automute_mode_enum(codec);
955 if (err < 0)
956 return err;
957 }
958 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200959}
960
Takashi Iwai1d045db2011-07-07 18:23:21 +0200961/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200962static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
963{
964 int i;
965 for (i = 0; i < nums; i++)
966 if (list[i] == nid)
967 return i;
968 return -1;
969}
970
Takashi Iwai21268962011-07-07 15:01:13 +0200971/* check whether all auto-mic pins are valid; setup indices if OK */
972static bool alc_auto_mic_check_imux(struct hda_codec *codec)
973{
974 struct alc_spec *spec = codec->spec;
975 const struct hda_input_mux *imux;
976
Takashi Iwai27d31532012-12-18 08:57:05 +0100977 imux = &spec->input_mux;
Takashi Iwai21268962011-07-07 15:01:13 +0200978 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
979 spec->imux_pins, imux->num_items);
980 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
981 spec->imux_pins, imux->num_items);
982 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
983 spec->imux_pins, imux->num_items);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100984 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0)
Takashi Iwai21268962011-07-07 15:01:13 +0200985 return false; /* no corresponding imux */
Takashi Iwai21268962011-07-07 15:01:13 +0200986
David Henningsson29adc4b2012-09-25 11:31:00 +0200987 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
988 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200989 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +0200990 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
991 ALC_MIC_EVENT,
992 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200993 return true;
994}
995
Takashi Iwai1d045db2011-07-07 18:23:21 +0200996/*
997 * Check the availability of auto-mic switch;
998 * Set up if really supported
999 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001000static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001001{
1002 struct alc_spec *spec = codec->spec;
1003 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001004 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001005 int i;
1006
Takashi Iwai21268962011-07-07 15:01:13 +02001007 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1008
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001009 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001010 for (i = 0; i < cfg->num_inputs; i++) {
1011 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001012 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001013 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001014 switch (snd_hda_get_input_pin_attr(defcfg)) {
1015 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001016 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001017 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001018 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001019 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001020 fixed = nid;
1021 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001022 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001023 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001024 case INPUT_PIN_ATTR_DOCK:
1025 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001026 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001027 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001028 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001029 dock = nid;
1030 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001031 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001032 if (ext)
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 ext = nid;
1037 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001038 }
1039 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001040 if (!ext && dock) {
1041 ext = dock;
1042 dock = 0;
1043 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001044 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001045 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001046 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001047 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001048 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001049 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001050
1051 /* check imux indices */
1052 spec->ext_mic_pin = ext;
1053 spec->int_mic_pin = fixed;
1054 spec->dock_mic_pin = dock;
1055
Takashi Iwai21268962011-07-07 15:01:13 +02001056 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001057 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001058
Takashi Iwai666a70d2012-12-17 20:29:29 +01001059 spec->auto_mic = 1;
1060 spec->num_adc_nids = 1;
1061 spec->cur_mux[0] = spec->int_mic_idx;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001062 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1063 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001064
1065 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001066}
1067
Takashi Iwai1d045db2011-07-07 18:23:21 +02001068/*
1069 * Realtek SSID verification
1070 */
1071
David Henningsson90622912010-10-14 14:50:18 +02001072/* Could be any non-zero and even value. When used as fixup, tells
1073 * the driver to ignore any present sku defines.
1074 */
1075#define ALC_FIXUP_SKU_IGNORE (2)
1076
Takashi Iwai23d30f22012-05-07 17:17:32 +02001077static void alc_fixup_sku_ignore(struct hda_codec *codec,
1078 const struct hda_fixup *fix, int action)
1079{
1080 struct alc_spec *spec = codec->spec;
1081 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1082 spec->cdefine.fixup = 1;
1083 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1084 }
1085}
1086
Kailang Yangda00c242010-03-19 11:23:45 +01001087static int alc_auto_parse_customize_define(struct hda_codec *codec)
1088{
1089 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001090 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001091 struct alc_spec *spec = codec->spec;
1092
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001093 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1094
David Henningsson90622912010-10-14 14:50:18 +02001095 if (spec->cdefine.fixup) {
1096 ass = spec->cdefine.sku_cfg;
1097 if (ass == ALC_FIXUP_SKU_IGNORE)
1098 return -1;
1099 goto do_sku;
1100 }
1101
Kailang Yangda00c242010-03-19 11:23:45 +01001102 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001103 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001104 goto do_sku;
1105
1106 nid = 0x1d;
1107 if (codec->vendor_id == 0x10ec0260)
1108 nid = 0x17;
1109 ass = snd_hda_codec_get_pincfg(codec, nid);
1110
1111 if (!(ass & 1)) {
1112 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1113 codec->chip_name, ass);
1114 return -1;
1115 }
1116
1117 /* check sum */
1118 tmp = 0;
1119 for (i = 1; i < 16; i++) {
1120 if ((ass >> i) & 1)
1121 tmp++;
1122 }
1123 if (((ass >> 16) & 0xf) != tmp)
1124 return -1;
1125
1126 spec->cdefine.port_connectivity = ass >> 30;
1127 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1128 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1129 spec->cdefine.customization = ass >> 8;
1130do_sku:
1131 spec->cdefine.sku_cfg = ass;
1132 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1133 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1134 spec->cdefine.swap = (ass & 0x2) >> 1;
1135 spec->cdefine.override = ass & 0x1;
1136
1137 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1138 nid, spec->cdefine.sku_cfg);
1139 snd_printd("SKU: port_connectivity=0x%x\n",
1140 spec->cdefine.port_connectivity);
1141 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1142 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1143 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1144 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1145 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1146 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1147 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1148
1149 return 0;
1150}
1151
Takashi Iwai1d045db2011-07-07 18:23:21 +02001152/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001153static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1154{
Takashi Iwai21268962011-07-07 15:01:13 +02001155 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001156}
1157
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001158/* check subsystem ID and set up device-specific initialization;
1159 * return 1 if initialized, 0 if invalid SSID
1160 */
1161/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1162 * 31 ~ 16 : Manufacture ID
1163 * 15 ~ 8 : SKU ID
1164 * 7 ~ 0 : Assembly ID
1165 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1166 */
1167static int alc_subsystem_id(struct hda_codec *codec,
1168 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001169 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001170{
1171 unsigned int ass, tmp, i;
1172 unsigned nid;
1173 struct alc_spec *spec = codec->spec;
1174
David Henningsson90622912010-10-14 14:50:18 +02001175 if (spec->cdefine.fixup) {
1176 ass = spec->cdefine.sku_cfg;
1177 if (ass == ALC_FIXUP_SKU_IGNORE)
1178 return 0;
1179 goto do_sku;
1180 }
1181
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001182 ass = codec->subsystem_id & 0xffff;
1183 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1184 goto do_sku;
1185
1186 /* invalid SSID, check the special NID pin defcfg instead */
1187 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001188 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001189 * 29~21 : reserve
1190 * 20 : PCBEEP input
1191 * 19~16 : Check sum (15:1)
1192 * 15~1 : Custom
1193 * 0 : override
1194 */
1195 nid = 0x1d;
1196 if (codec->vendor_id == 0x10ec0260)
1197 nid = 0x17;
1198 ass = snd_hda_codec_get_pincfg(codec, nid);
1199 snd_printd("realtek: No valid SSID, "
1200 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001201 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001202 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001203 return 0;
1204 if ((ass >> 30) != 1) /* no physical connection */
1205 return 0;
1206
1207 /* check sum */
1208 tmp = 0;
1209 for (i = 1; i < 16; i++) {
1210 if ((ass >> i) & 1)
1211 tmp++;
1212 }
1213 if (((ass >> 16) & 0xf) != tmp)
1214 return 0;
1215do_sku:
1216 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1217 ass & 0xffff, codec->vendor_id);
1218 /*
1219 * 0 : override
1220 * 1 : Swap Jack
1221 * 2 : 0 --> Desktop, 1 --> Laptop
1222 * 3~5 : External Amplifier control
1223 * 7~6 : Reserved
1224 */
1225 tmp = (ass & 0x38) >> 3; /* external Amp control */
1226 switch (tmp) {
1227 case 1:
1228 spec->init_amp = ALC_INIT_GPIO1;
1229 break;
1230 case 3:
1231 spec->init_amp = ALC_INIT_GPIO2;
1232 break;
1233 case 7:
1234 spec->init_amp = ALC_INIT_GPIO3;
1235 break;
1236 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001237 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001238 spec->init_amp = ALC_INIT_DEFAULT;
1239 break;
1240 }
1241
1242 /* is laptop or Desktop and enable the function "Mute internal speaker
1243 * when the external headphone out jack is plugged"
1244 */
1245 if (!(ass & 0x8000))
1246 return 1;
1247 /*
1248 * 10~8 : Jack location
1249 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1250 * 14~13: Resvered
1251 * 15 : 1 --> enable the function "Mute internal speaker
1252 * when the external headphone out jack is plugged"
1253 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001254 if (!spec->autocfg.hp_pins[0] &&
1255 !(spec->autocfg.line_out_pins[0] &&
1256 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001257 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001258 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1259 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001260 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001261 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001262 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001263 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001264 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001265 else if (tmp == 3)
1266 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001267 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001268 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001269 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1270 spec->autocfg.line_outs))
1271 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001272 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001273 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001274 return 1;
1275}
Kailang Yangea1fb292008-08-26 12:58:38 +02001276
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001277/* Check the validity of ALC subsystem-id
1278 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1279static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001280{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001281 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001282 struct alc_spec *spec = codec->spec;
1283 snd_printd("realtek: "
1284 "Enable default setup for auto mode as fallback\n");
1285 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001286 }
Takashi Iwai21268962011-07-07 15:01:13 +02001287}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001288
Takashi Iwai41e41f12005-06-08 14:48:49 +02001289/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001290 * COEF access helper functions
1291 */
Kailang Yang274693f2009-12-03 10:07:50 +01001292static int alc_read_coef_idx(struct hda_codec *codec,
1293 unsigned int coef_idx)
1294{
1295 unsigned int val;
1296 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1297 coef_idx);
1298 val = snd_hda_codec_read(codec, 0x20, 0,
1299 AC_VERB_GET_PROC_COEF, 0);
1300 return val;
1301}
1302
Kailang Yang977ddd62010-09-15 10:02:29 +02001303static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1304 unsigned int coef_val)
1305{
1306 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1307 coef_idx);
1308 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1309 coef_val);
1310}
1311
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001312/* a special bypass for COEF 0; read the cached value at the second time */
1313static unsigned int alc_get_coef0(struct hda_codec *codec)
1314{
1315 struct alc_spec *spec = codec->spec;
1316 if (!spec->coef0)
1317 spec->coef0 = alc_read_coef_idx(codec, 0);
1318 return spec->coef0;
1319}
1320
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001321static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1322 hda_nid_t pin, int pin_type,
1323 hda_nid_t dac);
1324static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1325 bool is_digital);
Takashi Iwai965cceb2012-12-18 11:46:37 +01001326static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
1327 hda_nid_t to_nid, int with_aa_mix,
1328 struct nid_path *path);
1329static struct nid_path *add_new_nid_path(struct hda_codec *codec,
1330 hda_nid_t from_nid, hda_nid_t to_nid,
1331 int with_aa_mix);
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001332
Takashi Iwai1d045db2011-07-07 18:23:21 +02001333/*
1334 * Digital I/O handling
1335 */
1336
Takashi Iwai757899a2010-07-30 10:48:14 +02001337/* set right pin controls for digital I/O */
1338static void alc_auto_init_digital(struct hda_codec *codec)
1339{
1340 struct alc_spec *spec = codec->spec;
1341 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001342 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001343
1344 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1345 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001346 if (!pin)
1347 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001348 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001349 }
1350 pin = spec->autocfg.dig_in_pin;
1351 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001352 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001353}
1354
1355/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1356static void alc_auto_parse_digital(struct hda_codec *codec)
1357{
1358 struct alc_spec *spec = codec->spec;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001359 int i, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001360 hda_nid_t dig_nid;
1361
1362 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001363 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001364 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001365 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1366 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1367 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001368 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001369 if (!add_new_nid_path(codec, dig_nid, pin, 2))
1370 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001371 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001372 spec->multiout.dig_out_nid = dig_nid;
1373 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1374 } else {
1375 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001376 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001377 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001378 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001379 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001380 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001381 }
1382
1383 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001384 dig_nid = codec->start_nid;
1385 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001386 struct nid_path *path;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001387 unsigned int wcaps = get_wcaps(codec, dig_nid);
1388 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1389 continue;
1390 if (!(wcaps & AC_WCAP_DIGITAL))
1391 continue;
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001392 path = add_new_nid_path(codec, spec->autocfg.dig_in_pin,
1393 dig_nid, 2);
1394 if (path) {
1395 path->active = true;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001396 spec->dig_in_nid = dig_nid;
1397 break;
1398 }
1399 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001400 }
1401}
1402
Takashi Iwaif95474e2007-07-10 00:47:43 +02001403/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001404 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001405 */
Takashi Iwai666a70d2012-12-17 20:29:29 +01001406#define alc_cap_vol_info snd_hda_mixer_amp_volume_info
1407#define alc_cap_vol_get snd_hda_mixer_amp_volume_get
1408#define alc_cap_vol_tlv snd_hda_mixer_amp_tlv
1409
1410typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
1411 struct snd_ctl_elem_value *ucontrol);
1412
1413static int alc_cap_put_caller(struct snd_kcontrol *kcontrol,
1414 struct snd_ctl_elem_value *ucontrol,
1415 put_call_t func, int type)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001416{
1417 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1418 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001419 const struct hda_input_mux *imux;
1420 struct nid_path *path;
1421 int i, adc_idx, err = 0;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001422
Takashi Iwai27d31532012-12-18 08:57:05 +01001423 imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001424 adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001425 mutex_lock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001426 codec->cached_write = 1;
1427 for (i = 0; i < imux->num_items; i++) {
1428 path = get_nid_path(codec, spec->imux_pins[i],
1429 get_adc_nid(codec, adc_idx, i));
1430 if (!path->ctls[type])
1431 continue;
1432 kcontrol->private_value = path->ctls[type];
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001433 err = func(kcontrol, ucontrol);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001434 if (err < 0)
1435 goto error;
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001436 }
1437 error:
Takashi Iwai666a70d2012-12-17 20:29:29 +01001438 codec->cached_write = 0;
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001439 mutex_unlock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001440 snd_hda_codec_resume_amp(codec);
1441 if (err >= 0 && type == NID_PATH_MUTE_CTL &&
1442 spec->inv_dmic_fixup && spec->inv_dmic_muted)
1443 alc_inv_dmic_sync_adc(codec, adc_idx);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001444 return err;
1445}
1446
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001447static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1448 struct snd_ctl_elem_value *ucontrol)
1449{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001450 return alc_cap_put_caller(kcontrol, ucontrol,
1451 snd_hda_mixer_amp_volume_put,
1452 NID_PATH_VOL_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001453}
1454
1455/* capture mixer elements */
1456#define alc_cap_sw_info snd_ctl_boolean_stereo_info
Takashi Iwai666a70d2012-12-17 20:29:29 +01001457#define alc_cap_sw_get snd_hda_mixer_amp_switch_get
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001458
1459static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1460 struct snd_ctl_elem_value *ucontrol)
1461{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001462 return alc_cap_put_caller(kcontrol, ucontrol,
1463 snd_hda_mixer_amp_switch_put,
1464 NID_PATH_MUTE_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001465}
1466
Takashi Iwai666a70d2012-12-17 20:29:29 +01001467static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1468{
1469 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01001470 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001471 struct nid_path *path;
1472 hda_nid_t nid;
1473 int i, dir, parm;
1474 unsigned int val;
1475
1476 for (i = 0; i < imux->num_items; i++) {
1477 if (spec->imux_pins[i] == spec->inv_dmic_pin)
1478 break;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001479 }
Takashi Iwai666a70d2012-12-17 20:29:29 +01001480 if (i >= imux->num_items)
1481 return;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001482
Takashi Iwai666a70d2012-12-17 20:29:29 +01001483 path = get_nid_path(codec, spec->inv_dmic_pin,
1484 get_adc_nid(codec, adc_idx, i));
1485 val = path->ctls[NID_PATH_MUTE_CTL];
1486 if (!val)
1487 return;
1488 nid = get_amp_nid_(val);
1489 dir = get_amp_direction_(val);
1490 parm = AC_AMP_SET_RIGHT |
1491 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001492
Takashi Iwai666a70d2012-12-17 20:29:29 +01001493 /* we care only right channel */
1494 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1495 if (val & 0x80) /* if already muted, we don't need to touch */
1496 return;
1497 val |= 0x80;
1498 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1499 parm | val);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001500}
1501
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001502/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001503 * Inverted digital-mic handling
1504 *
1505 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1506 * gives the additional mute only to the right channel of the digital mic
1507 * capture stream. This is a workaround for avoiding the almost silence
1508 * by summing the stereo stream from some (known to be ForteMedia)
1509 * digital mic unit.
1510 *
1511 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1512 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1513 * without caching so that the cache can still keep the original value.
1514 * The cached value is then restored when the flag is set off or any other
1515 * than d-mic is used as the current input source.
1516 */
1517static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1518{
1519 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001520 int src, nums;
Takashi Iwai125821a2012-06-22 14:30:29 +02001521
1522 if (!spec->inv_dmic_fixup)
1523 return;
1524 if (!spec->inv_dmic_muted && !force)
1525 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001526 nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids;
1527 for (src = 0; src < nums; src++) {
Takashi Iwai125821a2012-06-22 14:30:29 +02001528 bool dmic_fixup = false;
Takashi Iwai125821a2012-06-22 14:30:29 +02001529
1530 if (spec->inv_dmic_muted &&
1531 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1532 dmic_fixup = true;
1533 if (!dmic_fixup && !force)
1534 continue;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001535 alc_inv_dmic_sync_adc(codec, src);
Takashi Iwai125821a2012-06-22 14:30:29 +02001536 }
1537}
1538
1539static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1540 struct snd_ctl_elem_value *ucontrol)
1541{
1542 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1543 struct alc_spec *spec = codec->spec;
1544
1545 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1546 return 0;
1547}
1548
1549static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1550 struct snd_ctl_elem_value *ucontrol)
1551{
1552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1553 struct alc_spec *spec = codec->spec;
1554 unsigned int val = !ucontrol->value.integer.value[0];
1555
1556 if (val == spec->inv_dmic_muted)
1557 return 0;
1558 spec->inv_dmic_muted = val;
1559 alc_inv_dmic_sync(codec, true);
1560 return 0;
1561}
1562
1563static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwaibc549762012-12-18 15:35:11 +01001565 .name = "Inverted Internal Mic Capture Switch",
Takashi Iwai125821a2012-06-22 14:30:29 +02001566 .info = snd_ctl_boolean_mono_info,
1567 .get = alc_inv_dmic_sw_get,
1568 .put = alc_inv_dmic_sw_put,
1569};
1570
1571static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1572{
1573 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001574
Takashi Iwaibc549762012-12-18 15:35:11 +01001575 if (!alc_kcontrol_new(spec, NULL, &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001576 return -ENOMEM;
1577 spec->inv_dmic_fixup = 1;
1578 spec->inv_dmic_muted = 0;
1579 spec->inv_dmic_pin = nid;
1580 return 0;
1581}
1582
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001583/* typically the digital mic is put at node 0x12 */
1584static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1585 const struct alc_fixup *fix, int action)
1586{
1587 if (action == ALC_FIXUP_ACT_PROBE)
1588 alc_add_inv_dmic_mixer(codec, 0x12);
1589}
1590
Takashi Iwai125821a2012-06-22 14:30:29 +02001591/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001592 * virtual master controls
1593 */
1594
1595/*
1596 * slave controls for virtual master
1597 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001598static const char * const alc_slave_pfxs[] = {
1599 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001600 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001601 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001602 NULL,
1603};
1604
1605/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001606 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001608
1609static void alc_free_kctls(struct hda_codec *codec);
1610
Takashi Iwai67d634c2009-11-16 15:35:59 +01001611#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001612/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001613static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001614 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001615 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001616 { } /* end */
1617};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001618#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001619
Takashi Iwai2eab6942012-12-18 15:30:41 +01001620static int alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
1622 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001623 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625 for (i = 0; i < spec->num_mixers; i++) {
1626 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1627 if (err < 0)
1628 return err;
1629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001631 err = snd_hda_create_dig_out_ctls(codec,
1632 spec->multiout.dig_out_nid,
1633 spec->multiout.dig_out_nid,
1634 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 if (err < 0)
1636 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001637 if (!spec->no_analog) {
1638 err = snd_hda_create_spdif_share_sw(codec,
1639 &spec->multiout);
1640 if (err < 0)
1641 return err;
1642 spec->multiout.share_spdif = 1;
1643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 }
1645 if (spec->dig_in_nid) {
1646 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1647 if (err < 0)
1648 return err;
1649 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001650
Takashi Iwai67d634c2009-11-16 15:35:59 +01001651#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001652 /* create beep controls if needed */
1653 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001654 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001655 for (knew = alc_beep_mixer; knew->name; knew++) {
1656 struct snd_kcontrol *kctl;
1657 kctl = snd_ctl_new1(knew, codec);
1658 if (!kctl)
1659 return -ENOMEM;
1660 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001661 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001662 if (err < 0)
1663 return err;
1664 }
1665 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001666#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001667
Takashi Iwai2134ea42008-01-10 16:53:55 +01001668 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001669 if (!spec->no_analog &&
1670 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001671 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001672 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001673 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001674 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001675 vmaster_tlv, alc_slave_pfxs,
1676 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001677 if (err < 0)
1678 return err;
1679 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001680 if (!spec->no_analog &&
1681 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001682 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1683 NULL, alc_slave_pfxs,
1684 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001685 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001686 if (err < 0)
1687 return err;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001688 if (spec->vmaster_mute.hook)
1689 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001690 }
1691
Takashi Iwaibae84e72010-03-22 08:30:20 +01001692 alc_free_kctls(codec); /* no longer needed */
1693
David Henningsson5780b622012-06-27 18:45:45 +02001694 if (spec->shared_mic_hp) {
1695 int err;
1696 int nid = spec->autocfg.inputs[1].pin;
1697 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1698 if (err < 0)
1699 return err;
1700 err = snd_hda_jack_detect_enable(codec, nid, 0);
1701 if (err < 0)
1702 return err;
1703 }
1704
Takashi Iwai2eab6942012-12-18 15:30:41 +01001705 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001706 if (err < 0)
1707 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001708
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001709 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1710 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711}
1712
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001713
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001715 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001716 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001717
Takashi Iwai070cff42012-02-21 12:54:17 +01001718static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720static int alc_init(struct hda_codec *codec)
1721{
1722 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001723
Takashi Iwai546bb672012-03-07 08:37:19 +01001724 if (spec->init_hook)
1725 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001726
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001727 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001728 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001729
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02001730 snd_hda_gen_apply_verbs(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001731 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001732
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001733 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
1734 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
1735
Takashi Iwai58701122011-01-13 15:41:45 +01001736 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1737
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001738 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 return 0;
1740}
1741
Takashi Iwai83012a72012-08-24 18:38:08 +02001742#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001743static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1744{
1745 struct alc_spec *spec = codec->spec;
1746 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1747}
1748#endif
1749
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750/*
1751 * Analog playback callbacks
1752 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001753static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001755 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
1757 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001758 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1759 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760}
1761
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001762static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 struct hda_codec *codec,
1764 unsigned int stream_tag,
1765 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001766 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767{
1768 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001769 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1770 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
1772
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001773static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001775 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776{
1777 struct alc_spec *spec = codec->spec;
1778 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1779}
1780
1781/*
1782 * Digital out
1783 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001784static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001786 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787{
1788 struct alc_spec *spec = codec->spec;
1789 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1790}
1791
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001792static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001793 struct hda_codec *codec,
1794 unsigned int stream_tag,
1795 unsigned int format,
1796 struct snd_pcm_substream *substream)
1797{
1798 struct alc_spec *spec = codec->spec;
1799 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1800 stream_tag, format, substream);
1801}
1802
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001803static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001804 struct hda_codec *codec,
1805 struct snd_pcm_substream *substream)
1806{
1807 struct alc_spec *spec = codec->spec;
1808 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1809}
1810
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001811static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001813 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
1815 struct alc_spec *spec = codec->spec;
1816 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1817}
1818
1819/*
1820 * Analog capture
1821 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001822static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 struct hda_codec *codec,
1824 unsigned int stream_tag,
1825 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001826 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
1828 struct alc_spec *spec = codec->spec;
1829
Takashi Iwai63300792008-01-24 15:31:36 +01001830 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 stream_tag, 0, format);
1832 return 0;
1833}
1834
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001835static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001837 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838{
1839 struct alc_spec *spec = codec->spec;
1840
Takashi Iwai888afa12008-03-18 09:57:50 +01001841 snd_hda_codec_cleanup_stream(codec,
1842 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 return 0;
1844}
1845
Takashi Iwai840b64c2010-07-13 22:49:01 +02001846/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02001847static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001848 struct hda_codec *codec,
1849 unsigned int stream_tag,
1850 unsigned int format,
1851 struct snd_pcm_substream *substream)
1852{
1853 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001854 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02001855 spec->cur_adc_stream_tag = stream_tag;
1856 spec->cur_adc_format = format;
1857 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1858 return 0;
1859}
1860
Takashi Iwai21268962011-07-07 15:01:13 +02001861static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001862 struct hda_codec *codec,
1863 struct snd_pcm_substream *substream)
1864{
1865 struct alc_spec *spec = codec->spec;
1866 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1867 spec->cur_adc = 0;
1868 return 0;
1869}
1870
Takashi Iwai21268962011-07-07 15:01:13 +02001871static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02001872 .substreams = 1,
1873 .channels_min = 2,
1874 .channels_max = 2,
1875 .nid = 0, /* fill later */
1876 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02001877 .prepare = dyn_adc_capture_pcm_prepare,
1878 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02001879 },
1880};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
1882/*
1883 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001884static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 .substreams = 1,
1886 .channels_min = 2,
1887 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001888 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001890 .open = alc_playback_pcm_open,
1891 .prepare = alc_playback_pcm_prepare,
1892 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 },
1894};
1895
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001896static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001897 .substreams = 1,
1898 .channels_min = 2,
1899 .channels_max = 2,
1900 /* NID is set in alc_build_pcms */
1901};
1902
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001903static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01001904 .substreams = 1,
1905 .channels_min = 2,
1906 .channels_max = 2,
1907 /* NID is set in alc_build_pcms */
1908};
1909
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001910static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001911 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 .channels_min = 2,
1913 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001914 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001916 .prepare = alc_alt_capture_pcm_prepare,
1917 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 },
1919};
1920
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001921static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 .substreams = 1,
1923 .channels_min = 2,
1924 .channels_max = 2,
1925 /* NID is set in alc_build_pcms */
1926 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001927 .open = alc_dig_playback_pcm_open,
1928 .close = alc_dig_playback_pcm_close,
1929 .prepare = alc_dig_playback_pcm_prepare,
1930 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 },
1932};
1933
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001934static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 .substreams = 1,
1936 .channels_min = 2,
1937 .channels_max = 2,
1938 /* NID is set in alc_build_pcms */
1939};
1940
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001941/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02001942static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001943 .substreams = 0,
1944 .channels_min = 0,
1945 .channels_max = 0,
1946};
1947
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948static int alc_build_pcms(struct hda_codec *codec)
1949{
1950 struct alc_spec *spec = codec->spec;
1951 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001952 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01001953 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 int i;
1955
1956 codec->num_pcms = 1;
1957 codec->pcm_info = info;
1958
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001959 if (spec->no_analog)
1960 goto skip_analog;
1961
Takashi Iwai812a2cc2009-05-16 10:00:49 +02001962 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1963 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01001965
Takashi Iwaieedec3d2012-02-06 10:24:04 +01001966 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001967 p = spec->stream_analog_playback;
1968 if (!p)
1969 p = &alc_pcm_analog_playback;
1970 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001971 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02001972 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1973 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01001974 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
1975 spec->autocfg.line_outs == 2)
1976 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1977 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001978 }
Takashi Iwai27d31532012-12-18 08:57:05 +01001979 if (spec->num_adc_nids) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001980 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02001981 if (!p) {
1982 if (spec->dyn_adc_switch)
1983 p = &dyn_adc_pcm_analog_capture;
1984 else
1985 p = &alc_pcm_analog_capture;
1986 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001987 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001988 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1989 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Takashi Iwai4a471b72005-12-07 13:56:29 +01001991 if (spec->channel_mode) {
1992 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
1993 for (i = 0; i < spec->num_channel_mode; i++) {
1994 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
1995 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
1996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 }
1998 }
1999
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002000 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002001 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002003 snprintf(spec->stream_name_digital,
2004 sizeof(spec->stream_name_digital),
2005 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002006 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002007 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002008 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002010 if (spec->dig_out_type)
2011 info->pcm_type = spec->dig_out_type;
2012 else
2013 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002014 if (spec->multiout.dig_out_nid) {
2015 p = spec->stream_digital_playback;
2016 if (!p)
2017 p = &alc_pcm_digital_playback;
2018 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2020 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002021 if (spec->dig_in_nid) {
2022 p = spec->stream_digital_capture;
2023 if (!p)
2024 p = &alc_pcm_digital_capture;
2025 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2027 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002028 /* FIXME: do we need this for all Realtek codec models? */
2029 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 }
2031
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002032 if (spec->no_analog)
2033 return 0;
2034
Takashi Iwaie08a0072006-09-07 17:52:14 +02002035 /* If the use of more than one ADC is requested for the current
2036 * model, configure a second analog capture-only PCM.
2037 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002038 have_multi_adcs = (spec->num_adc_nids > 1) &&
Takashi Iwai27d31532012-12-18 08:57:05 +01002039 !spec->dyn_adc_switch && !spec->auto_mic;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002040 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002041 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002042 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002043 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002044 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002045 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002046 p = spec->stream_analog_alt_playback;
2047 if (!p)
2048 p = &alc_pcm_analog_alt_playback;
2049 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002050 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2051 spec->alt_dac_nid;
2052 } else {
2053 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2054 alc_pcm_null_stream;
2055 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2056 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002057 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002058 p = spec->stream_analog_alt_capture;
2059 if (!p)
2060 p = &alc_pcm_analog_alt_capture;
2061 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002062 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2063 spec->adc_nids[1];
2064 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2065 spec->num_adc_nids - 1;
2066 } else {
2067 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2068 alc_pcm_null_stream;
2069 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002070 }
2071 }
2072
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 return 0;
2074}
2075
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002076static inline void alc_shutup(struct hda_codec *codec)
2077{
Takashi Iwai1c716152011-04-07 10:37:16 +02002078 struct alc_spec *spec = codec->spec;
2079
2080 if (spec && spec->shutup)
2081 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002082 snd_hda_shutup_pins(codec);
2083}
2084
Takashi Iwai603c4012008-07-30 15:01:44 +02002085static void alc_free_kctls(struct hda_codec *codec)
2086{
2087 struct alc_spec *spec = codec->spec;
2088
2089 if (spec->kctls.list) {
2090 struct snd_kcontrol_new *kctl = spec->kctls.list;
2091 int i;
2092 for (i = 0; i < spec->kctls.used; i++)
2093 kfree(kctl[i].name);
2094 }
2095 snd_array_free(&spec->kctls);
2096}
2097
Takashi Iwai23c09b02011-08-19 09:05:35 +02002098static void alc_free_bind_ctls(struct hda_codec *codec)
2099{
2100 struct alc_spec *spec = codec->spec;
2101 if (spec->bind_ctls.list) {
2102 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2103 int i;
2104 for (i = 0; i < spec->bind_ctls.used; i++)
2105 kfree(ctl[i]);
2106 }
2107 snd_array_free(&spec->bind_ctls);
2108}
2109
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110static void alc_free(struct hda_codec *codec)
2111{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002112 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002113
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002114 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002115 return;
2116
Takashi Iwai603c4012008-07-30 15:01:44 +02002117 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002118 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002119 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002120 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002121 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002122 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
Takashi Iwai83012a72012-08-24 18:38:08 +02002125#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002126static void alc_power_eapd(struct hda_codec *codec)
2127{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002128 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002129}
2130
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002131static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002132{
2133 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002134 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002135 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002136 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002137 return 0;
2138}
2139#endif
2140
Takashi Iwai2a439522011-07-26 09:52:50 +02002141#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002142static int alc_resume(struct hda_codec *codec)
2143{
Takashi Iwai1c716152011-04-07 10:37:16 +02002144 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002145 codec->patch_ops.init(codec);
2146 snd_hda_codec_resume_amp(codec);
2147 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002148 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002149 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002150 return 0;
2151}
Takashi Iwaie044c392008-10-27 16:56:24 +01002152#endif
2153
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154/*
2155 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002156static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 .build_controls = alc_build_controls,
2158 .build_pcms = alc_build_pcms,
2159 .init = alc_init,
2160 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002161 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002162#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002163 .resume = alc_resume,
2164#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002165#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002166 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002167 .check_power_status = alc_check_power_status,
2168#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002169 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170};
2171
David Henningsson29adc4b2012-09-25 11:31:00 +02002172
Kailang Yangc027ddc2010-03-19 11:33:06 +01002173/* replace the codec chip_name with the given string */
2174static int alc_codec_rename(struct hda_codec *codec, const char *name)
2175{
2176 kfree(codec->chip_name);
2177 codec->chip_name = kstrdup(name, GFP_KERNEL);
2178 if (!codec->chip_name) {
2179 alc_free(codec);
2180 return -ENOMEM;
2181 }
2182 return 0;
2183}
2184
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002185/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002186 * Rename codecs appropriately from COEF value
2187 */
2188struct alc_codec_rename_table {
2189 unsigned int vendor_id;
2190 unsigned short coef_mask;
2191 unsigned short coef_bits;
2192 const char *name;
2193};
2194
2195static struct alc_codec_rename_table rename_tbl[] = {
2196 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2197 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2198 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2199 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2200 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2201 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2202 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002203 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002204 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2205 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2206 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2207 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2208 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2209 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2210 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2211 { } /* terminator */
2212};
2213
2214static int alc_codec_rename_from_preset(struct hda_codec *codec)
2215{
2216 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002217
2218 for (p = rename_tbl; p->vendor_id; p++) {
2219 if (p->vendor_id != codec->vendor_id)
2220 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002221 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002222 return alc_codec_rename(codec, p->name);
2223 }
2224 return 0;
2225}
2226
2227/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002228 * Automatic parse of I/O pins from the BIOS configuration
2229 */
2230
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002231enum {
2232 ALC_CTL_WIDGET_VOL,
2233 ALC_CTL_WIDGET_MUTE,
2234 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002235 ALC_CTL_BIND_VOL,
2236 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002237};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002238static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002239 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2240 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002241 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002242 HDA_BIND_VOL(NULL, 0),
2243 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002244};
2245
2246/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002247static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002248 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002249{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002250 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002251
Takashi Iwai668d1e92012-11-29 14:10:17 +01002252 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002253 if (!knew)
2254 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002255 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002256 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002257 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002258 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002259 return 0;
2260}
2261
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002262static int add_control_with_pfx(struct alc_spec *spec, int type,
2263 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002264 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002265{
2266 char name[32];
2267 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002268 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002269}
2270
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002271#define add_pb_vol_ctrl(spec, type, pfx, val) \
2272 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2273#define add_pb_sw_ctrl(spec, type, pfx, val) \
2274 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2275#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2276 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2277#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2278 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002279
Takashi Iwai23c09b02011-08-19 09:05:35 +02002280static const char * const channel_name[4] = {
2281 "Front", "Surround", "CLFE", "Side"
2282};
2283
Takashi Iwai6843ca12011-06-24 11:03:58 +02002284static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2285 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002286{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002287 struct auto_pin_cfg *cfg = &spec->autocfg;
2288
Takashi Iwai6843ca12011-06-24 11:03:58 +02002289 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002290 if (cfg->line_outs == 1 && !spec->multi_ios &&
2291 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwai52a8efa2012-12-18 17:33:04 +01002292 return spec->vmaster_mute.hook ? "PCM" : "Master";
2293
2294 /* if there is really a single DAC used in the whole output paths,
2295 * use it master (or "PCM" if a vmaster hook is present)
2296 */
2297 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
2298 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
2299 return spec->vmaster_mute.hook ? "PCM" : "Master";
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002300
2301 switch (cfg->line_out_type) {
2302 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002303 if (cfg->line_outs == 1)
2304 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002305 if (cfg->line_outs == 2)
2306 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002307 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002308 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002309 /* for multi-io case, only the primary out */
2310 if (ch && spec->multi_ios)
2311 break;
2312 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002313 return "Headphone";
2314 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002315 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002316 return "PCM";
2317 break;
2318 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002319 if (ch >= ARRAY_SIZE(channel_name)) {
2320 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002321 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002322 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002323
2324 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002325}
2326
Takashi Iwai83012a72012-08-24 18:38:08 +02002327#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002328/* add the powersave loopback-list entry */
2329static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2330{
2331 struct hda_amp_list *list;
2332
2333 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2334 return;
2335 list = spec->loopback_list + spec->num_loopbacks;
2336 list->nid = mix;
2337 list->dir = HDA_INPUT;
2338 list->idx = idx;
2339 spec->num_loopbacks++;
2340 spec->loopback.amplist = spec->loopback_list;
2341}
2342#else
2343#define add_loopback_list(spec, mix, idx) /* NOP */
2344#endif
2345
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002346/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002347static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002348 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002349 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002350{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002351 struct alc_spec *spec = codec->spec;
2352 struct nid_path *path;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002353 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002354 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002355
Takashi Iwaibd32f782012-12-12 18:08:52 +01002356 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2357 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2358 return 0; /* no need for analog loopback */
2359
Takashi Iwai965cceb2012-12-18 11:46:37 +01002360 path = add_new_nid_path(codec, pin, mix_nid, 2);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002361 if (!path)
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002362 return -EINVAL;
2363
2364 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002365 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002366 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2367 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002368 if (err < 0)
2369 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002370 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002371 }
2372
2373 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002374 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2375 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002376 if (err < 0)
2377 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002378 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002379 }
2380
Takashi Iwai829f69e2012-12-14 18:26:02 +01002381 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002382 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002383 return 0;
2384}
2385
Takashi Iwai05f5f472009-08-25 13:10:18 +02002386static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002387{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002388 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2389 return (pincap & AC_PINCAP_IN) != 0;
2390}
2391
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002392/* check whether the given two widgets can be connected */
2393static bool is_reachable_path(struct hda_codec *codec,
2394 hda_nid_t from_nid, hda_nid_t to_nid)
2395{
2396 if (!from_nid || !to_nid)
2397 return false;
2398 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2399}
2400
Takashi Iwai666a70d2012-12-17 20:29:29 +01002401/* Parse the codec tree and retrieve ADCs */
2402static int alc_auto_fill_adc_nids(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002403{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002404 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002405 hda_nid_t nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002406 hda_nid_t *adc_nids = spec->adc_nids;
2407 int max_nums = ARRAY_SIZE(spec->adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002408 int i, nums = 0;
2409
2410 nid = codec->start_nid;
2411 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwaib7821702011-07-06 15:12:46 +02002412 unsigned int caps = get_wcaps(codec, nid);
2413 int type = get_wcaps_type(caps);
2414
2415 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2416 continue;
2417 adc_nids[nums] = nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002418 if (++nums >= max_nums)
2419 break;
2420 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002421 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002422 return nums;
2423}
2424
Takashi Iwai666a70d2012-12-17 20:29:29 +01002425/* filter out invalid adc_nids that don't give all active input pins;
2426 * if needed, check whether dynamic ADC-switching is available
2427 */
2428static int check_dyn_adc_switch(struct hda_codec *codec)
2429{
2430 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002431 struct hda_input_mux *imux = &spec->input_mux;
2432 hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)];
Takashi Iwai666a70d2012-12-17 20:29:29 +01002433 int i, n, nums;
2434 hda_nid_t pin, adc;
2435
2436 again:
2437 nums = 0;
2438 for (n = 0; n < spec->num_adc_nids; n++) {
2439 adc = spec->adc_nids[n];
2440 for (i = 0; i < imux->num_items; i++) {
2441 pin = spec->imux_pins[i];
2442 if (!is_reachable_path(codec, pin, adc))
2443 break;
2444 }
2445 if (i >= imux->num_items)
2446 adc_nids[nums++] = adc;
2447 }
2448
2449 if (!nums) {
2450 if (spec->shared_mic_hp) {
2451 spec->shared_mic_hp = 0;
Takashi Iwai27d31532012-12-18 08:57:05 +01002452 imux->num_items = 1;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002453 goto again;
2454 }
2455
2456 /* check whether ADC-switch is possible */
2457 for (i = 0; i < imux->num_items; i++) {
2458 pin = spec->imux_pins[i];
2459 for (n = 0; n < spec->num_adc_nids; n++) {
2460 adc = spec->adc_nids[n];
2461 if (is_reachable_path(codec, pin, adc)) {
2462 spec->dyn_adc_idx[i] = n;
2463 break;
2464 }
2465 }
2466 }
2467
2468 snd_printdd("realtek: enabling ADC switching\n");
2469 spec->dyn_adc_switch = 1;
2470 } else if (nums != spec->num_adc_nids) {
Takashi Iwai27d31532012-12-18 08:57:05 +01002471 memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t));
Takashi Iwai666a70d2012-12-17 20:29:29 +01002472 spec->num_adc_nids = nums;
2473 }
2474
Takashi Iwai27d31532012-12-18 08:57:05 +01002475 if (imux->num_items == 1 || spec->shared_mic_hp) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002476 snd_printdd("realtek: reducing to a single ADC\n");
2477 spec->num_adc_nids = 1; /* reduce to a single ADC */
2478 }
2479
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002480 /* single index for individual volumes ctls */
2481 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
2482 spec->num_adc_nids = 1;
2483
Takashi Iwai666a70d2012-12-17 20:29:29 +01002484 return 0;
2485}
2486
2487/* templates for capture controls */
2488static const struct snd_kcontrol_new cap_src_temp = {
2489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2490 .name = "Input Source",
2491 .info = alc_mux_enum_info,
2492 .get = alc_mux_enum_get,
2493 .put = alc_mux_enum_put,
2494};
2495
2496static const struct snd_kcontrol_new cap_vol_temp = {
2497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2498 .name = "Capture Volume",
2499 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2500 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2501 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2502 .info = alc_cap_vol_info,
2503 .get = alc_cap_vol_get,
2504 .put = alc_cap_vol_put,
2505 .tlv = { .c = alc_cap_vol_tlv },
2506};
2507
2508static const struct snd_kcontrol_new cap_sw_temp = {
2509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2510 .name = "Capture Switch",
2511 .info = alc_cap_sw_info,
2512 .get = alc_cap_sw_get,
2513 .put = alc_cap_sw_put,
2514};
2515
2516static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2517{
2518 hda_nid_t nid;
2519 int i, depth;
2520
2521 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2522 for (depth = 0; depth < 3; depth++) {
2523 if (depth >= path->depth)
2524 return -EINVAL;
2525 i = path->depth - depth - 1;
2526 nid = path->path[i];
2527 if (!path->ctls[NID_PATH_VOL_CTL]) {
2528 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2529 path->ctls[NID_PATH_VOL_CTL] =
2530 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2531 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2532 int idx = path->idx[i];
2533 if (!depth && codec->single_adc_amp)
2534 idx = 0;
2535 path->ctls[NID_PATH_VOL_CTL] =
2536 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2537 }
2538 }
2539 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2540 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2541 path->ctls[NID_PATH_MUTE_CTL] =
2542 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2543 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2544 int idx = path->idx[i];
2545 if (!depth && codec->single_adc_amp)
2546 idx = 0;
2547 path->ctls[NID_PATH_MUTE_CTL] =
2548 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2549 }
2550 }
2551 }
2552 return 0;
2553}
2554
Takashi Iwai81fede82012-12-18 17:24:25 +01002555static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs);
2556
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002557static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
2558 int idx, bool is_switch, unsigned int ctl)
2559{
2560 struct alc_spec *spec = codec->spec;
2561 char tmpname[44];
2562 int type = is_switch ? ALC_CTL_WIDGET_MUTE : ALC_CTL_WIDGET_VOL;
2563 const char *sfx = is_switch ? "Switch" : "Volume";
Takashi Iwai81fede82012-12-18 17:24:25 +01002564 unsigned int chs;
2565 int err;
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002566
2567 if (!ctl)
2568 return 0;
2569
Takashi Iwai81fede82012-12-18 17:24:25 +01002570 if (idx == spec->inv_dmic_split_idx)
2571 chs = 1;
2572 else
2573 chs = 3;
2574
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002575 if (label)
2576 snprintf(tmpname, sizeof(tmpname),
2577 "%s Capture %s", label, sfx);
2578 else
2579 snprintf(tmpname, sizeof(tmpname),
2580 "Capture %s", sfx);
Takashi Iwai81fede82012-12-18 17:24:25 +01002581 err = add_control(spec, type, tmpname, idx,
2582 amp_val_replace_channels(ctl, chs));
2583 if (err < 0 || chs == 3)
2584 return err;
2585
2586 /* Make independent right kcontrol */
2587 if (label)
2588 snprintf(tmpname, sizeof(tmpname),
2589 "Inverted %s Capture %s", label, sfx);
2590 else
2591 snprintf(tmpname, sizeof(tmpname),
2592 "Inverted Capture %s", sfx);
2593 return add_control(spec, type, tmpname, idx,
2594 amp_val_replace_channels(ctl, 2));
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002595}
2596
2597/* create single (and simple) capture volume and switch controls */
2598static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
2599 unsigned int vol_ctl, unsigned int sw_ctl)
2600{
2601 int err;
2602 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl);
2603 if (err < 0)
2604 return err;
2605 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl);
2606 if (err < 0)
2607 return err;
2608 return 0;
2609}
2610
2611/* create bound capture volume and switch controls */
2612static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
2613 unsigned int vol_ctl, unsigned int sw_ctl)
2614{
2615 struct alc_spec *spec = codec->spec;
2616 struct snd_kcontrol_new *knew;
2617
2618 if (vol_ctl) {
2619 knew = alc_kcontrol_new(spec, NULL, &cap_vol_temp);
2620 if (!knew)
2621 return -ENOMEM;
2622 knew->index = idx;
2623 knew->private_value = vol_ctl;
2624 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2625 }
2626 if (sw_ctl) {
2627 knew = alc_kcontrol_new(spec, NULL, &cap_sw_temp);
2628 if (!knew)
2629 return -ENOMEM;
2630 knew->index = idx;
2631 knew->private_value = sw_ctl;
2632 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2633 }
2634 return 0;
2635}
2636
2637/* return the vol ctl when used first in the imux list */
2638static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
2639{
2640 struct alc_spec *spec = codec->spec;
2641 struct nid_path *path;
2642 unsigned int ctl;
2643 int i;
2644
2645 path = get_nid_path(codec, spec->imux_pins[idx],
2646 get_adc_nid(codec, 0, idx));
2647 if (!path)
2648 return 0;
2649 ctl = path->ctls[type];
2650 if (!ctl)
2651 return 0;
2652 for (i = 0; i < idx - 1; i++) {
2653 path = get_nid_path(codec, spec->imux_pins[i],
2654 get_adc_nid(codec, 0, i));
2655 if (path && path->ctls[type] == ctl)
2656 return 0;
2657 }
2658 return ctl;
2659}
2660
2661/* create individual capture volume and switch controls per input */
2662static int create_multi_cap_vol_ctl(struct hda_codec *codec)
2663{
2664 struct alc_spec *spec = codec->spec;
2665 struct hda_input_mux *imux = &spec->input_mux;
2666 int i, err, type, type_idx = 0;
2667 const char *prev_label = NULL;
2668
2669 for (i = 0; i < imux->num_items; i++) {
2670 const char *label;
2671 label = hda_get_autocfg_input_label(codec, &spec->autocfg, i);
2672 if (prev_label && !strcmp(label, prev_label))
2673 type_idx++;
2674 else
2675 type_idx = 0;
2676 prev_label = label;
2677
2678 for (type = 0; type < 2; type++) {
2679 err = add_single_cap_ctl(codec, label, type_idx, type,
2680 get_first_cap_ctl(codec, i, type));
2681 if (err < 0)
2682 return err;
2683 }
2684 }
2685 return 0;
2686}
2687
Takashi Iwai666a70d2012-12-17 20:29:29 +01002688static int create_capture_mixers(struct hda_codec *codec)
2689{
2690 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002691 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002692 int i, n, nums, err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002693
2694 if (spec->dyn_adc_switch)
2695 nums = 1;
2696 else
2697 nums = spec->num_adc_nids;
2698
2699 if (!spec->auto_mic && imux->num_items > 1) {
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002700 struct snd_kcontrol_new *knew;
Takashi Iwaibc549762012-12-18 15:35:11 +01002701 knew = alc_kcontrol_new(spec, NULL, &cap_src_temp);
Takashi Iwai666a70d2012-12-17 20:29:29 +01002702 if (!knew)
2703 return -ENOMEM;
2704 knew->count = nums;
2705 }
2706
2707 for (n = 0; n < nums; n++) {
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002708 bool multi = false;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002709 int vol, sw;
2710
2711 vol = sw = 0;
2712 for (i = 0; i < imux->num_items; i++) {
2713 struct nid_path *path;
2714 path = get_nid_path(codec, spec->imux_pins[i],
2715 get_adc_nid(codec, n, i));
2716 if (!path)
2717 continue;
2718 parse_capvol_in_path(codec, path);
2719 if (!vol)
2720 vol = path->ctls[NID_PATH_VOL_CTL];
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002721 else if (vol != path->ctls[NID_PATH_VOL_CTL])
2722 multi = true;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002723 if (!sw)
2724 sw = path->ctls[NID_PATH_MUTE_CTL];
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002725 else if (sw != path->ctls[NID_PATH_MUTE_CTL])
2726 multi = true;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002727 }
2728
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002729 if (!multi)
2730 err = create_single_cap_vol_ctl(codec, n, vol, sw);
2731 else if (!spec->multi_cap_vol)
2732 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
2733 else
2734 err = create_multi_cap_vol_ctl(codec);
2735 if (err < 0)
2736 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002737 }
2738
2739 return 0;
2740}
2741
Takashi Iwai05f5f472009-08-25 13:10:18 +02002742/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002743static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002744{
2745 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002746 const struct auto_pin_cfg *cfg = &spec->autocfg;
2747 hda_nid_t mixer = spec->mixer_nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002748 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwaib7821702011-07-06 15:12:46 +02002749 int num_adcs;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002750 int i, c, err, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002751 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002752
Takashi Iwai666a70d2012-12-17 20:29:29 +01002753 num_adcs = alc_auto_fill_adc_nids(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002754 if (num_adcs < 0)
2755 return 0;
2756
Takashi Iwai81fede82012-12-18 17:24:25 +01002757 spec->inv_dmic_split_idx = -1;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002758 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002759 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002760 const char *label;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002761 bool imux_added;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002762
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002763 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002764 if (!alc_is_input_pin(codec, pin))
2765 continue;
2766
David Henningsson5322bf22011-01-05 11:03:56 +01002767 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002768 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2769 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002770 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002771 type_idx++;
2772 else
2773 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002774 prev_label = label;
2775
Takashi Iwai05f5f472009-08-25 13:10:18 +02002776 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002777 if (is_reachable_path(codec, pin, mixer)) {
2778 err = new_analog_input(codec, pin,
2779 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002780 if (err < 0)
2781 return err;
2782 }
2783 }
2784
Takashi Iwai666a70d2012-12-17 20:29:29 +01002785 imux_added = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002786 for (c = 0; c < num_adcs; c++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002787 struct nid_path *path;
2788 hda_nid_t adc = spec->adc_nids[c];
2789
2790 if (!is_reachable_path(codec, pin, adc))
2791 continue;
2792 path = snd_array_new(&spec->paths);
2793 if (!path)
2794 return -ENOMEM;
2795 memset(path, 0, sizeof(*path));
2796 if (!parse_nid_path(codec, pin, adc, 2, path)) {
2797 snd_printd(KERN_ERR
2798 "invalid input path 0x%x -> 0x%x\n",
2799 pin, adc);
2800 spec->paths.used--;
2801 continue;
2802 }
2803
2804 if (!imux_added) {
2805 spec->imux_pins[imux->num_items] = pin;
2806 snd_hda_add_imux_item(imux, label,
2807 imux->num_items, NULL);
2808 imux_added = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002809 }
2810 }
Takashi Iwai81fede82012-12-18 17:24:25 +01002811
2812 if (spec->inv_dmic_split) {
2813 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
2814 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
2815 if (snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT)
2816 spec->inv_dmic_split_idx = i;
2817 }
2818 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002819 }
Takashi Iwai21268962011-07-07 15:01:13 +02002820
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002821 return 0;
2822}
2823
Takashi Iwai24de1832011-11-07 17:13:39 +01002824/* create a shared input with the headphone out */
2825static int alc_auto_create_shared_input(struct hda_codec *codec)
2826{
2827 struct alc_spec *spec = codec->spec;
2828 struct auto_pin_cfg *cfg = &spec->autocfg;
2829 unsigned int defcfg;
2830 hda_nid_t nid;
2831
2832 /* only one internal input pin? */
2833 if (cfg->num_inputs != 1)
2834 return 0;
2835 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2836 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2837 return 0;
2838
2839 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2840 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2841 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2842 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2843 else
2844 return 0; /* both not available */
2845
2846 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2847 return 0; /* no input */
2848
2849 cfg->inputs[1].pin = nid;
2850 cfg->inputs[1].type = AUTO_PIN_MIC;
2851 cfg->num_inputs = 2;
2852 spec->shared_mic_hp = 1;
2853 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2854 return 0;
2855}
2856
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002857static int get_pin_type(int line_out_type)
2858{
2859 if (line_out_type == AUTO_PIN_HP_OUT)
2860 return PIN_HP;
2861 else
2862 return PIN_OUT;
2863}
2864
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002865static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002866{
2867 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002868 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002869 int i;
2870
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002871 for (i = 0; i < cfg->num_inputs; i++) {
2872 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai62343992012-12-18 09:06:01 +01002873 if (alc_is_input_pin(codec, nid))
Takashi Iwai30ea0982010-09-16 18:47:56 +02002874 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002875
Takashi Iwai829f69e2012-12-14 18:26:02 +01002876 /* mute loopback inputs */
2877 if (spec->mixer_nid) {
2878 struct nid_path *path;
2879 path = get_nid_path(codec, nid, spec->mixer_nid);
2880 if (path)
Takashi Iwai666a70d2012-12-17 20:29:29 +01002881 activate_path(codec, path, path->active, false);
Takashi Iwai829f69e2012-12-14 18:26:02 +01002882 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002883 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002884}
2885
Takashi Iwai185d99f2012-02-16 18:39:45 +01002886static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2887{
2888 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002889 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002890
Takashi Iwaic9967f12012-12-14 16:39:22 +01002891 for (i = 0; i < spec->paths.used; i++) {
2892 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002893 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002894 return true;
2895 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002896 return false;
2897}
2898
Takashi Iwai463419d2012-12-05 14:17:37 +01002899/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002900static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2901 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002902{
2903 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002904 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002905 int i;
2906
2907 for (i = 0; i < spec->num_all_dacs; i++) {
2908 hda_nid_t nid = spec->all_dacs[i];
2909 if (!nid || alc_is_dac_already_used(codec, nid))
2910 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002911 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2912 if (is_digital != cap_digital)
2913 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002914 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002915 return nid;
2916 }
2917 return 0;
2918}
2919
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002920/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002921static bool __parse_nid_path(struct hda_codec *codec,
2922 hda_nid_t from_nid, hda_nid_t to_nid,
2923 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002924{
2925 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002926 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002927 int i, nums;
2928
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002929 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002930 if (!with_aa_mix)
2931 return false;
2932 with_aa_mix = 2; /* mark aa-mix is included */
2933 }
2934
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002935 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002936 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002937 if (conn[i] != from_nid) {
2938 /* special case: when from_nid is 0,
2939 * try to find an empty DAC
2940 */
2941 if (from_nid ||
2942 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2943 alc_is_dac_already_used(codec, conn[i]))
2944 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002945 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002946 /* aa-mix is requested but not included? */
2947 if (!(spec->mixer_nid && with_aa_mix == 1))
2948 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002949 }
2950 if (depth >= MAX_NID_PATH_DEPTH)
2951 return false;
2952 for (i = 0; i < nums; i++) {
2953 unsigned int type;
2954 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002955 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2956 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002957 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002958 if (__parse_nid_path(codec, from_nid, conn[i],
2959 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002960 goto found;
2961 }
2962 return false;
2963
2964 found:
2965 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002966 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002967 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002968 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002969 path->depth++;
2970 return true;
2971}
2972
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002973/* parse the widget path from the given nid to the target nid;
2974 * when @from_nid is 0, try to find an empty DAC;
2975 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2976 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2977 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002978 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002979static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2980 hda_nid_t to_nid, int with_aa_mix,
2981 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002982{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002983 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2984 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002985 path->depth++;
2986#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002987 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002988 path->depth, path->path[0], path->path[1],
2989 path->path[2], path->path[3], path->path[4]);
2990#endif
2991 return true;
2992 }
2993 return false;
2994}
2995
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002996static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2997{
Takashi Iwai140547e2012-02-16 17:23:46 +01002998 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002999 int i;
3000 hda_nid_t nid_found = 0;
3001
3002 for (i = 0; i < spec->num_all_dacs; i++) {
3003 hda_nid_t nid = spec->all_dacs[i];
3004 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003005 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01003006 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003007 if (nid_found)
3008 return 0;
3009 nid_found = nid;
3010 }
3011 }
3012 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003013}
3014
Takashi Iwaiba8111272012-12-06 18:06:23 +01003015static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003016{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003017 struct alc_spec *spec = codec->spec;
3018 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003019
Takashi Iwaic9967f12012-12-14 16:39:22 +01003020 for (i = 0; i < spec->paths.used; i++) {
3021 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003022 if (path->ctls[type] == val)
3023 return true;
3024 }
3025 return false;
3026}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003027
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003028/* badness definition */
3029enum {
3030 /* No primary DAC is found for the main output */
3031 BAD_NO_PRIMARY_DAC = 0x10000,
3032 /* No DAC is found for the extra output */
3033 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003034 /* No possible multi-ios */
3035 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003036 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003037 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003038 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003039 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003040 /* Primary DAC shared with main surrounds */
3041 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003042 /* Primary DAC shared with main CLFE */
3043 BAD_SHARED_CLFE = 0x10,
3044 /* Primary DAC shared with extra surrounds */
3045 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003046 /* Volume widget is shared */
3047 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003048};
3049
3050static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003051 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003052static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003053 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003054
Takashi Iwai965cceb2012-12-18 11:46:37 +01003055static struct nid_path *add_new_nid_path(struct hda_codec *codec,
3056 hda_nid_t from_nid, hda_nid_t to_nid,
3057 int with_aa_mix)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003058{
3059 struct alc_spec *spec = codec->spec;
3060 struct nid_path *path;
3061
Takashi Iwai965cceb2012-12-18 11:46:37 +01003062 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
3063 return NULL;
3064
Takashi Iwaic9967f12012-12-14 16:39:22 +01003065 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003066 if (!path)
Takashi Iwai965cceb2012-12-18 11:46:37 +01003067 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003068 memset(path, 0, sizeof(*path));
Takashi Iwai965cceb2012-12-18 11:46:37 +01003069 if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path))
3070 return path;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003071 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01003072 spec->paths.used--;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003073 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003074}
3075
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003076/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003077 * passing 0 to either @pin or @dac behaves as a wildcard
3078 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003079static struct nid_path *
3080get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01003081{
3082 struct alc_spec *spec = codec->spec;
3083 int i;
3084
Takashi Iwaic9967f12012-12-14 16:39:22 +01003085 for (i = 0; i < spec->paths.used; i++) {
3086 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003087 if (path->depth <= 0)
3088 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003089 if ((!from_nid || path->path[0] == from_nid) &&
3090 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01003091 return path;
3092 }
3093 return NULL;
3094}
3095
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003096/* look for widgets in the path between the given NIDs appropriate for
3097 * volume and mute controls, and assign the values to ctls[].
3098 *
3099 * When no appropriate widget is found in the path, the badness value
3100 * is incremented depending on the situation. The function returns the
3101 * total badness for both volume and mute controls.
3102 */
3103static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3104 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003105{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003106 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003107 hda_nid_t nid;
3108 unsigned int val;
3109 int badness = 0;
3110
Takashi Iwaiba8111272012-12-06 18:06:23 +01003111 if (!path)
3112 return BAD_SHARED_VOL * 2;
3113 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003114 if (nid) {
3115 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003116 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003117 badness += BAD_SHARED_VOL;
3118 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003119 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003120 } else
3121 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003122 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003123 if (nid) {
3124 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003125 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3126 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003127 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3128 else
3129 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003130 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003131 badness += BAD_SHARED_VOL;
3132 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003133 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003134 } else
3135 badness += BAD_SHARED_VOL;
3136 return badness;
3137}
3138
Takashi Iwaidc31b582012-02-17 17:27:53 +01003139struct badness_table {
3140 int no_primary_dac; /* no primary DAC */
3141 int no_dac; /* no secondary DACs */
3142 int shared_primary; /* primary DAC is shared with main output */
3143 int shared_surr; /* secondary DAC shared with main or primary */
3144 int shared_clfe; /* third DAC shared with main or primary */
3145 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3146};
3147
3148static struct badness_table main_out_badness = {
3149 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3150 .no_dac = BAD_NO_DAC,
3151 .shared_primary = BAD_NO_PRIMARY_DAC,
3152 .shared_surr = BAD_SHARED_SURROUND,
3153 .shared_clfe = BAD_SHARED_CLFE,
3154 .shared_surr_main = BAD_SHARED_SURROUND,
3155};
3156
3157static struct badness_table extra_out_badness = {
3158 .no_primary_dac = BAD_NO_DAC,
3159 .no_dac = BAD_NO_DAC,
3160 .shared_primary = BAD_NO_EXTRA_DAC,
3161 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3162 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3163 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3164};
3165
3166/* try to assign DACs to pins and return the resultant badness */
3167static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3168 const hda_nid_t *pins, hda_nid_t *dacs,
3169 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003170{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003171 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003172 struct auto_pin_cfg *cfg = &spec->autocfg;
3173 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003174 int badness = 0;
3175 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003176
Takashi Iwai185d99f2012-02-16 18:39:45 +01003177 if (!num_outs)
3178 return 0;
3179
Takashi Iwaidc31b582012-02-17 17:27:53 +01003180 for (i = 0; i < num_outs; i++) {
3181 hda_nid_t pin = pins[i];
3182 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003183 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003184 if (!dacs[i] && !i) {
3185 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003186 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003187 dacs[0] = dacs[j];
3188 dacs[j] = 0;
3189 break;
3190 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003191 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003192 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003193 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003194 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003195 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003196 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003197 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003198 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003199 dac = spec->private_dac_nids[i];
3200 if (dac) {
3201 if (!i)
3202 badness += bad->shared_primary;
3203 else if (i == 1)
3204 badness += bad->shared_surr;
3205 else
3206 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003207 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003208 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003209 badness += bad->shared_surr_main;
3210 } else if (!i)
3211 badness += bad->no_primary_dac;
3212 else
3213 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003214 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003215 if (!add_new_nid_path(codec, dac, pin, 0))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003216 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003217 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003218 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003219 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003220
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003221 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003222}
3223
3224static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003225 hda_nid_t reference_pin,
3226 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003227
Takashi Iwai185d99f2012-02-16 18:39:45 +01003228static bool alc_map_singles(struct hda_codec *codec, int outs,
3229 const hda_nid_t *pins, hda_nid_t *dacs)
3230{
3231 int i;
3232 bool found = false;
3233 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003234 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003235 if (dacs[i])
3236 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003237 dac = get_dac_if_single(codec, pins[i]);
3238 if (!dac)
3239 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003240 if (add_new_nid_path(codec, dac, pins[i], 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003241 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003242 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003243 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003244 }
3245 return found;
3246}
3247
Takashi Iwai7085ec12009-10-02 09:03:58 +02003248/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003249static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003250 bool fill_hardwired,
3251 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003252{
3253 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003254 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003255 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003256
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003257 /* set num_dacs once to full for alc_auto_look_for_dac() */
3258 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003259 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003260 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3261 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3262 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003263 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003264 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003265 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003266
3267 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003268 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003269 bool mapped;
3270 do {
3271 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003272 cfg->line_out_pins,
3273 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003274 mapped |= alc_map_singles(codec, cfg->hp_outs,
3275 cfg->hp_pins,
3276 spec->multiout.hp_out_nid);
3277 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3278 cfg->speaker_pins,
3279 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003280 if (fill_mio_first && cfg->line_outs == 1 &&
3281 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3282 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3283 if (!err)
3284 mapped = true;
3285 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003286 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003287 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003288
Takashi Iwaidc31b582012-02-17 17:27:53 +01003289 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3290 spec->private_dac_nids,
3291 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003292
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003293 /* re-count num_dacs and squash invalid entries */
3294 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003295 for (i = 0; i < cfg->line_outs; i++) {
3296 if (spec->private_dac_nids[i])
3297 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003298 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003299 memmove(spec->private_dac_nids + i,
3300 spec->private_dac_nids + i + 1,
3301 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003302 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3303 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003304 }
3305
Takashi Iwai276dd702012-02-17 16:17:03 +01003306 if (fill_mio_first &&
3307 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003308 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003309 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003310 if (err < 0)
3311 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003312 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003313 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003314
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003315 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003316 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3317 spec->multiout.hp_out_nid,
3318 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003319 if (err < 0)
3320 return err;
3321 badness += err;
3322 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003323 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003324 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3325 cfg->speaker_pins,
3326 spec->multiout.extra_out_nid,
3327 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003328 if (err < 0)
3329 return err;
3330 badness += err;
3331 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003332 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3333 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003334 if (err < 0)
3335 return err;
3336 badness += err;
3337 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003338 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3339 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003340 int offset = 0;
3341 if (cfg->line_outs >= 3)
3342 offset = 1;
3343 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3344 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003345 if (err < 0)
3346 return err;
3347 badness += err;
3348 }
3349
3350 if (spec->multi_ios == 2) {
3351 for (i = 0; i < 2; i++)
3352 spec->private_dac_nids[spec->multiout.num_dacs++] =
3353 spec->multi_io[i].dac;
3354 spec->ext_channel_count = 2;
3355 } else if (spec->multi_ios) {
3356 spec->multi_ios = 0;
3357 badness += BAD_MULTI_IO;
3358 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003359
3360 return badness;
3361}
3362
3363#define DEBUG_BADNESS
3364
3365#ifdef DEBUG_BADNESS
3366#define debug_badness snd_printdd
3367#else
3368#define debug_badness(...)
3369#endif
3370
3371static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3372{
3373 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3374 cfg->line_out_pins[0], cfg->line_out_pins[1],
3375 cfg->line_out_pins[2], cfg->line_out_pins[2],
3376 spec->multiout.dac_nids[0],
3377 spec->multiout.dac_nids[1],
3378 spec->multiout.dac_nids[2],
3379 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003380 if (spec->multi_ios > 0)
3381 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3382 spec->multi_ios,
3383 spec->multi_io[0].pin, spec->multi_io[1].pin,
3384 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003385 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3386 cfg->hp_pins[0], cfg->hp_pins[1],
3387 cfg->hp_pins[2], cfg->hp_pins[2],
3388 spec->multiout.hp_out_nid[0],
3389 spec->multiout.hp_out_nid[1],
3390 spec->multiout.hp_out_nid[2],
3391 spec->multiout.hp_out_nid[3]);
3392 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3393 cfg->speaker_pins[0], cfg->speaker_pins[1],
3394 cfg->speaker_pins[2], cfg->speaker_pins[3],
3395 spec->multiout.extra_out_nid[0],
3396 spec->multiout.extra_out_nid[1],
3397 spec->multiout.extra_out_nid[2],
3398 spec->multiout.extra_out_nid[3]);
3399}
3400
Takashi Iwai463419d2012-12-05 14:17:37 +01003401/* find all available DACs of the codec */
3402static void alc_fill_all_nids(struct hda_codec *codec)
3403{
3404 struct alc_spec *spec = codec->spec;
3405 int i;
3406 hda_nid_t nid = codec->start_nid;
3407
3408 spec->num_all_dacs = 0;
3409 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3410 for (i = 0; i < codec->num_nodes; i++, nid++) {
3411 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3412 continue;
3413 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3414 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3415 break;
3416 }
3417 spec->all_dacs[spec->num_all_dacs++] = nid;
3418 }
3419}
3420
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003421static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3422{
3423 struct alc_spec *spec = codec->spec;
3424 struct auto_pin_cfg *cfg = &spec->autocfg;
3425 struct auto_pin_cfg *best_cfg;
3426 int best_badness = INT_MAX;
3427 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003428 bool fill_hardwired = true, fill_mio_first = true;
3429 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003430 bool hp_spk_swapped = false;
3431
Takashi Iwai463419d2012-12-05 14:17:37 +01003432 alc_fill_all_nids(codec);
3433
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003434 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3435 if (!best_cfg)
3436 return -ENOMEM;
3437 *best_cfg = *cfg;
3438
3439 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003440 badness = fill_and_eval_dacs(codec, fill_hardwired,
3441 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003442 if (badness < 0) {
3443 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003444 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003445 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003446 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3447 cfg->line_out_type, fill_hardwired, fill_mio_first,
3448 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003449 debug_show_configs(spec, cfg);
3450 if (badness < best_badness) {
3451 best_badness = badness;
3452 *best_cfg = *cfg;
3453 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003454 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003455 }
3456 if (!badness)
3457 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003458 fill_mio_first = !fill_mio_first;
3459 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003460 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003461 fill_hardwired = !fill_hardwired;
3462 if (!fill_hardwired)
3463 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003464 if (hp_spk_swapped)
3465 break;
3466 hp_spk_swapped = true;
3467 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003468 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3469 cfg->hp_outs = cfg->line_outs;
3470 memcpy(cfg->hp_pins, cfg->line_out_pins,
3471 sizeof(cfg->hp_pins));
3472 cfg->line_outs = cfg->speaker_outs;
3473 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3474 sizeof(cfg->speaker_pins));
3475 cfg->speaker_outs = 0;
3476 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3477 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003478 fill_hardwired = true;
3479 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003480 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003481 if (cfg->hp_outs > 0 &&
3482 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3483 cfg->speaker_outs = cfg->line_outs;
3484 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3485 sizeof(cfg->speaker_pins));
3486 cfg->line_outs = cfg->hp_outs;
3487 memcpy(cfg->line_out_pins, cfg->hp_pins,
3488 sizeof(cfg->hp_pins));
3489 cfg->hp_outs = 0;
3490 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3491 cfg->line_out_type = AUTO_PIN_HP_OUT;
3492 fill_hardwired = true;
3493 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003494 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003495 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003496 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003497
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003498 if (badness) {
3499 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003500 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003501 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003502 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3503 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003504 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003505
Takashi Iwaiba8111272012-12-06 18:06:23 +01003506 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003507 struct nid_path *path = get_nid_path(codec,
3508 spec->multiout.dac_nids[0],
3509 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003510 if (path)
3511 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3512 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003513
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003514 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003515 return 0;
3516}
3517
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003518/* replace the channels in the composed amp value with the given number */
3519static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3520{
3521 val &= ~(0x3U << 16);
3522 val |= chs << 16;
3523 return val;
3524}
3525
Takashi Iwai343a04b2011-07-06 14:28:39 +02003526static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003527 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003528 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003529 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003530{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003531 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003532 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003533 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003534 val = path->ctls[NID_PATH_VOL_CTL];
3535 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003536 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003537 val = amp_val_replace_channels(val, chs);
3538 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3539}
3540
3541/* return the channel bits suitable for the given path->ctls[] */
3542static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3543 int type)
3544{
3545 int chs = 1; /* mono (left only) */
3546 if (path) {
3547 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3548 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3549 chs = 3; /* stereo */
3550 }
3551 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003552}
3553
Takashi Iwaie29d3772011-11-14 17:13:23 +01003554static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3555 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003556 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003557{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003558 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3559 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003560}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003561
3562/* create a mute-switch for the given mixer widget;
3563 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3564 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003565static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003566 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003567 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003568 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003569{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003570 unsigned int val;
3571 int type = ALC_CTL_WIDGET_MUTE;
3572
3573 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003574 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003575 val = path->ctls[NID_PATH_MUTE_CTL];
3576 if (!val)
3577 return 0;
3578 val = amp_val_replace_channels(val, chs);
3579 if (get_amp_direction_(val) == HDA_INPUT) {
3580 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003581 int nums = snd_hda_get_num_conns(codec, nid);
3582 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003583 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003584 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003585 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003586 }
3587 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003588}
3589
Takashi Iwaie29d3772011-11-14 17:13:23 +01003590static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003591 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003592{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003593 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3594 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003595}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003596
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003597static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003598 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003599{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003600 int i;
3601
3602 for (i = path->depth - 1; i >= 0; i--) {
3603 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3604 return path->path[i];
3605 if (i != path->depth - 1 && i != 0 &&
3606 nid_has_mute(codec, path->path[i], HDA_INPUT))
3607 return path->path[i];
3608 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003609 return 0;
3610}
3611
3612static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003613 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003614{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003615 int i;
3616
3617 for (i = path->depth - 1; i >= 0; i--) {
3618 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3619 return path->path[i];
3620 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003621 return 0;
3622}
3623
Takashi Iwai7085ec12009-10-02 09:03:58 +02003624/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003625static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003626 const struct auto_pin_cfg *cfg)
3627{
3628 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003629 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003630
Takashi Iwaice764ab2011-04-27 16:35:23 +02003631 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003632 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003633 noutputs += spec->multi_ios;
3634
3635 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003636 const char *name;
3637 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003638 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003639 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003640
3641 dac = spec->multiout.dac_nids[i];
3642 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003643 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003644 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003645 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003646 index = 0;
3647 name = channel_name[i];
3648 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003649 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003650 name = alc_get_line_out_pfx(spec, i, true, &index);
3651 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003652
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003653 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003654 if (!path)
3655 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003656 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003657 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003658 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003659 if (err < 0)
3660 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003661 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003662 if (err < 0)
3663 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003664 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003665 if (err < 0)
3666 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003667 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003668 if (err < 0)
3669 return err;
3670 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003671 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003672 if (err < 0)
3673 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003674 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003675 if (err < 0)
3676 return err;
3677 }
3678 }
3679 return 0;
3680}
3681
Takashi Iwai343a04b2011-07-06 14:28:39 +02003682static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003683 hda_nid_t dac, const char *pfx,
3684 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003685{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003686 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003687 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003688
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003689 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003690 if (!path)
3691 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003692 /* bind volume control will be created in the case of dac = 0 */
3693 if (dac) {
3694 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3695 if (err < 0)
3696 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003697 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003698 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003699 if (err < 0)
3700 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003701 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003702}
3703
Takashi Iwai23c09b02011-08-19 09:05:35 +02003704static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3705 unsigned int nums,
3706 struct hda_ctl_ops *ops)
3707{
3708 struct alc_spec *spec = codec->spec;
3709 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003710 ctlp = snd_array_new(&spec->bind_ctls);
3711 if (!ctlp)
3712 return NULL;
3713 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3714 *ctlp = ctl;
3715 if (ctl)
3716 ctl->ops = ops;
3717 return ctl;
3718}
3719
3720/* add playback controls for speaker and HP outputs */
3721static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3722 const hda_nid_t *pins,
3723 const hda_nid_t *dacs,
3724 const char *pfx)
3725{
3726 struct alc_spec *spec = codec->spec;
3727 struct hda_bind_ctls *ctl;
3728 char name[32];
3729 int i, n, err;
3730
3731 if (!num_pins || !pins[0])
3732 return 0;
3733
Takashi Iwai527e4d72011-10-27 16:33:27 +02003734 if (num_pins == 1) {
3735 hda_nid_t dac = *dacs;
3736 if (!dac)
3737 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003738 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003739 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003740
Takashi Iwai23c09b02011-08-19 09:05:35 +02003741 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003742 hda_nid_t dac;
3743 if (dacs[num_pins - 1])
3744 dac = dacs[i]; /* with individual volumes */
3745 else
3746 dac = 0;
3747 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3748 err = alc_auto_create_extra_out(codec, pins[i], dac,
3749 "Bass Speaker", 0);
3750 } else if (num_pins >= 3) {
3751 snprintf(name, sizeof(name), "%s %s",
3752 pfx, channel_name[i]);
3753 err = alc_auto_create_extra_out(codec, pins[i], dac,
3754 name, 0);
3755 } else {
3756 err = alc_auto_create_extra_out(codec, pins[i], dac,
3757 pfx, i);
3758 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003759 if (err < 0)
3760 return err;
3761 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003762 if (dacs[num_pins - 1])
3763 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003764
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003765 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003766 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3767 if (!ctl)
3768 return -ENOMEM;
3769 n = 0;
3770 for (i = 0; i < num_pins; i++) {
3771 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003772 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003773 if (!pins[i] || !dacs[i])
3774 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003775 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003776 if (!path)
3777 continue;
3778 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003779 if (vol)
3780 ctl->values[n++] =
3781 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3782 }
3783 if (n) {
3784 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3785 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3786 if (err < 0)
3787 return err;
3788 }
3789 return 0;
3790}
3791
Takashi Iwai343a04b2011-07-06 14:28:39 +02003792static int alc_auto_create_hp_out(struct hda_codec *codec)
3793{
3794 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003795 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3796 spec->autocfg.hp_pins,
3797 spec->multiout.hp_out_nid,
3798 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003799}
3800
3801static int alc_auto_create_speaker_out(struct hda_codec *codec)
3802{
3803 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003804 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3805 spec->autocfg.speaker_pins,
3806 spec->multiout.extra_out_nid,
3807 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003808}
3809
Takashi Iwai130e5f02012-12-14 16:09:29 +01003810/* check whether a control with the given (nid, dir, idx) was assigned */
3811static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3812 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003813{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003814 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003815 int i, type;
3816
3817 for (i = 0; i < spec->paths.used; i++) {
3818 struct nid_path *p = snd_array_elem(&spec->paths, i);
3819 if (p->depth <= 0)
3820 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003821 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003822 unsigned int val = p->ctls[type];
3823 if (get_amp_nid_(val) == nid &&
3824 get_amp_direction_(val) == dir &&
3825 get_amp_index_(val) == idx)
3826 return true;
3827 }
3828 }
3829 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003830}
3831
3832/* can have the amp-in capability? */
3833static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3834{
3835 hda_nid_t nid = path->path[idx];
3836 unsigned int caps = get_wcaps(codec, nid);
3837 unsigned int type = get_wcaps_type(caps);
3838
3839 if (!(caps & AC_WCAP_IN_AMP))
3840 return false;
3841 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3842 return false;
3843 return true;
3844}
3845
3846/* can have the amp-out capability? */
3847static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3848{
3849 hda_nid_t nid = path->path[idx];
3850 unsigned int caps = get_wcaps(codec, nid);
3851 unsigned int type = get_wcaps_type(caps);
3852
3853 if (!(caps & AC_WCAP_OUT_AMP))
3854 return false;
3855 if (type == AC_WID_PIN && !idx) /* only for output pins */
3856 return false;
3857 return true;
3858}
3859
Takashi Iwaic9967f12012-12-14 16:39:22 +01003860/* check whether the given (nid,dir,idx) is active */
3861static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3862 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003863{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003864 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003865 int i, n;
3866
Takashi Iwaic9967f12012-12-14 16:39:22 +01003867 for (n = 0; n < spec->paths.used; n++) {
3868 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003869 if (!path->active)
3870 continue;
3871 for (i = 0; i < path->depth; i++) {
3872 if (path->path[i] == nid) {
3873 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3874 return true;
3875 break;
3876 }
3877 }
3878 }
3879 return false;
3880}
3881
Takashi Iwai130e5f02012-12-14 16:09:29 +01003882/* get the default amp value for the target state */
3883static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3884 int dir, bool enable)
3885{
3886 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003887 unsigned int val = 0;
3888
3889 caps = query_amp_caps(codec, nid, dir);
3890 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003891 /* set to 0dB */
3892 if (enable)
3893 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003894 }
3895 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003896 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003897 val |= HDA_AMP_MUTE;
3898 }
3899 return val;
3900}
3901
Takashi Iwai130e5f02012-12-14 16:09:29 +01003902/* initialize the amp value (only at the first time) */
3903static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3904{
3905 int val = get_amp_val_to_activate(codec, nid, dir, false);
3906 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3907}
3908
3909static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3910 int idx, bool enable)
3911{
3912 int val;
3913 if (is_ctl_associated(codec, nid, dir, idx) ||
3914 is_active_nid(codec, nid, dir, idx))
3915 return;
3916 val = get_amp_val_to_activate(codec, nid, dir, enable);
3917 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3918}
3919
3920static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3921 int i, bool enable)
3922{
3923 hda_nid_t nid = path->path[i];
3924 init_amp(codec, nid, HDA_OUTPUT, 0);
3925 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3926}
3927
3928static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003929 int i, bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003930{
3931 struct alc_spec *spec = codec->spec;
3932 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003933 int n, nums, idx;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003934 int type;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003935 hda_nid_t nid = path->path[i];
3936
3937 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai666a70d2012-12-17 20:29:29 +01003938 type = get_wcaps_type(get_wcaps(codec, nid));
3939 if (type == AC_WID_PIN ||
3940 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003941 nums = 1;
3942 idx = 0;
3943 } else
3944 idx = path->idx[i];
3945
Takashi Iwai130e5f02012-12-14 16:09:29 +01003946 for (n = 0; n < nums; n++)
3947 init_amp(codec, nid, HDA_INPUT, n);
3948
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003949 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003950 return;
3951
3952 /* here is a little bit tricky in comparison with activate_amp_out();
3953 * when aa-mixer is available, we need to enable the path as well
3954 */
3955 for (n = 0; n < nums; n++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01003956 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003957 continue;
3958 activate_amp(codec, nid, HDA_INPUT, n, enable);
3959 }
3960}
3961
3962static void activate_path(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003963 bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003964{
3965 int i;
3966
Takashi Iwai130e5f02012-12-14 16:09:29 +01003967 if (!enable)
3968 path->active = false;
3969
3970 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003971 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003972 snd_hda_codec_write_cache(codec, path->path[i], 0,
3973 AC_VERB_SET_CONNECT_SEL,
3974 path->idx[i]);
3975 if (has_amp_in(codec, path, i))
Takashi Iwai666a70d2012-12-17 20:29:29 +01003976 activate_amp_in(codec, path, i, enable, add_aamix);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003977 if (has_amp_out(codec, path, i))
3978 activate_amp_out(codec, path, i, enable);
3979 }
3980
3981 if (enable)
3982 path->active = true;
3983}
3984
Takashi Iwai78e635c2012-12-10 17:07:16 +01003985/* configure the path from the given dac to the pin as the proper output */
3986static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3987 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003988 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003989{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003990 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003991
Takashi Iwai130e5f02012-12-14 16:09:29 +01003992 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003993 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003994 if (!path)
3995 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003996 if (path->active)
3997 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003998 activate_path(codec, path, true, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003999}
4000
Takashi Iwai343a04b2011-07-06 14:28:39 +02004001static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004002{
4003 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02004004 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004005 int i;
4006
4007 for (i = 0; i <= HDA_SIDE; i++) {
4008 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4009 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02004010 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01004011 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004012
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004013 }
4014}
4015
Takashi Iwai343a04b2011-07-06 14:28:39 +02004016static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004017{
4018 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004019 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004020 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004021
David Henningsson636030e2011-10-12 19:26:03 +02004022 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004023 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4024 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02004025 pin = spec->autocfg.hp_pins[i];
4026 if (!pin)
4027 break;
4028 dac = spec->multiout.hp_out_nid[i];
4029 if (!dac) {
4030 if (i > 0 && spec->multiout.hp_out_nid[0])
4031 dac = spec->multiout.hp_out_nid[0];
4032 else
4033 dac = spec->multiout.dac_nids[0];
4034 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004035 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004036 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02004037 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004038 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4039 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004040 pin = spec->autocfg.speaker_pins[i];
4041 if (!pin)
4042 break;
4043 dac = spec->multiout.extra_out_nid[i];
4044 if (!dac) {
4045 if (i > 0 && spec->multiout.extra_out_nid[0])
4046 dac = spec->multiout.extra_out_nid[0];
4047 else
4048 dac = spec->multiout.dac_nids[0];
4049 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004050 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004051 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004052}
4053
Takashi Iwai276dd702012-02-17 16:17:03 +01004054/* check whether the given pin can be a multi-io pin */
4055static bool can_be_multiio_pin(struct hda_codec *codec,
4056 unsigned int location, hda_nid_t nid)
4057{
4058 unsigned int defcfg, caps;
4059
4060 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4061 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4062 return false;
4063 if (location && get_defcfg_location(defcfg) != location)
4064 return false;
4065 caps = snd_hda_query_pin_caps(codec, nid);
4066 if (!(caps & AC_PINCAP_OUT))
4067 return false;
4068 return true;
4069}
4070
Takashi Iwaice764ab2011-04-27 16:35:23 +02004071/*
4072 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004073 *
4074 * When hardwired is set, try to fill ony hardwired pins, and returns
4075 * zero if any pins are filled, non-zero if nothing found.
4076 * When hardwired is off, try to fill possible input pins, and returns
4077 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004078 */
4079static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004080 hda_nid_t reference_pin,
4081 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004082{
4083 struct alc_spec *spec = codec->spec;
4084 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004085 int type, i, j, dacs, num_pins, old_pins;
4086 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4087 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004088 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004089
Takashi Iwai276dd702012-02-17 16:17:03 +01004090 old_pins = spec->multi_ios;
4091 if (old_pins >= 2)
4092 goto end_fill;
4093
4094 num_pins = 0;
4095 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4096 for (i = 0; i < cfg->num_inputs; i++) {
4097 if (cfg->inputs[i].type != type)
4098 continue;
4099 if (can_be_multiio_pin(codec, location,
4100 cfg->inputs[i].pin))
4101 num_pins++;
4102 }
4103 }
4104 if (num_pins < 2)
4105 goto end_fill;
4106
Takashi Iwai07b18f62011-11-10 15:42:54 +01004107 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004108 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4109 for (i = 0; i < cfg->num_inputs; i++) {
4110 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004111 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004112
Takashi Iwaice764ab2011-04-27 16:35:23 +02004113 if (cfg->inputs[i].type != type)
4114 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004115 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004116 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004117 for (j = 0; j < spec->multi_ios; j++) {
4118 if (nid == spec->multi_io[j].pin)
4119 break;
4120 }
4121 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004122 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004123
4124 if (offset && offset + spec->multi_ios < dacs) {
4125 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004126 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004127 dac = 0;
4128 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004129 if (hardwired)
4130 dac = get_dac_if_single(codec, nid);
4131 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004132 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004133 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004134 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004135 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004136 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01004137 if (!add_new_nid_path(codec, dac, nid, 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004138 badness++;
4139 continue;
4140 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004141 spec->multi_io[spec->multi_ios].pin = nid;
4142 spec->multi_io[spec->multi_ios].dac = dac;
4143 spec->multi_ios++;
4144 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004145 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004146 }
4147 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004148 end_fill:
4149 if (badness)
4150 badness = BAD_MULTI_IO;
4151 if (old_pins == spec->multi_ios) {
4152 if (hardwired)
4153 return 1; /* nothing found */
4154 else
4155 return badness; /* no badness if nothing found */
4156 }
4157 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004158 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004159 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004160 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004161 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004162 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004163
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004164 /* assign volume and mute controls */
4165 for (i = old_pins; i < spec->multi_ios; i++)
4166 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4167 spec->multi_io[i].dac);
4168
4169 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004170}
4171
4172static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4173 struct snd_ctl_elem_info *uinfo)
4174{
4175 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4176 struct alc_spec *spec = codec->spec;
4177
4178 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4179 uinfo->count = 1;
4180 uinfo->value.enumerated.items = spec->multi_ios + 1;
4181 if (uinfo->value.enumerated.item > spec->multi_ios)
4182 uinfo->value.enumerated.item = spec->multi_ios;
4183 sprintf(uinfo->value.enumerated.name, "%dch",
4184 (uinfo->value.enumerated.item + 1) * 2);
4185 return 0;
4186}
4187
4188static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4189 struct snd_ctl_elem_value *ucontrol)
4190{
4191 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4192 struct alc_spec *spec = codec->spec;
4193 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4194 return 0;
4195}
4196
4197static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4198{
4199 struct alc_spec *spec = codec->spec;
4200 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004201 struct nid_path *path;
4202
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004203 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004204 if (!path)
4205 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004206
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004207 if (path->active == output)
4208 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004209
Takashi Iwaice764ab2011-04-27 16:35:23 +02004210 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004211 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004212 activate_path(codec, path, true, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004213 } else {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004214 activate_path(codec, path, false, true);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004215 snd_hda_set_pin_ctl_cache(codec, nid,
4216 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004217 }
4218 return 0;
4219}
4220
4221static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4222 struct snd_ctl_elem_value *ucontrol)
4223{
4224 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4225 struct alc_spec *spec = codec->spec;
4226 int i, ch;
4227
4228 ch = ucontrol->value.enumerated.item[0];
4229 if (ch < 0 || ch > spec->multi_ios)
4230 return -EINVAL;
4231 if (ch == (spec->ext_channel_count - 1) / 2)
4232 return 0;
4233 spec->ext_channel_count = (ch + 1) * 2;
4234 for (i = 0; i < spec->multi_ios; i++)
4235 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004236 spec->multiout.max_channels = max(spec->ext_channel_count,
4237 spec->const_channel_count);
4238 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004239 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004240 return 1;
4241}
4242
Takashi Iwaia9111322011-05-02 11:30:18 +02004243static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4245 .name = "Channel Mode",
4246 .info = alc_auto_ch_mode_info,
4247 .get = alc_auto_ch_mode_get,
4248 .put = alc_auto_ch_mode_put,
4249};
4250
Takashi Iwai23c09b02011-08-19 09:05:35 +02004251static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004252{
4253 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004254
Takashi Iwaic2674682011-08-24 17:57:44 +02004255 if (spec->multi_ios > 0) {
Takashi Iwaibc549762012-12-18 15:35:11 +01004256 if (!alc_kcontrol_new(spec, NULL, &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004257 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004258 }
4259 return 0;
4260}
4261
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004262static void alc_auto_init_multi_io(struct hda_codec *codec)
4263{
4264 struct alc_spec *spec = codec->spec;
4265 int i;
4266
4267 for (i = 0; i < spec->multi_ios; i++) {
4268 hda_nid_t pin = spec->multi_io[i].pin;
4269 struct nid_path *path;
4270 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4271 if (!path)
4272 continue;
4273 if (!spec->multi_io[i].ctl_in)
4274 spec->multi_io[i].ctl_in =
4275 snd_hda_codec_update_cache(codec, pin, 0,
4276 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004277 activate_path(codec, path, path->active, true);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004278 }
4279}
4280
Takashi Iwai1d045db2011-07-07 18:23:21 +02004281/*
4282 * initialize ADC paths
4283 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004284static void alc_auto_init_input_src(struct hda_codec *codec)
4285{
4286 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01004287 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004288 struct nid_path *path;
4289 int i, c, nums;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004290
Takashi Iwai1d045db2011-07-07 18:23:21 +02004291 if (spec->dyn_adc_switch)
4292 nums = 1;
4293 else
4294 nums = spec->num_adc_nids;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004295
4296 for (c = 0; c < nums; c++) {
4297 for (i = 0; i < imux->num_items; i++) {
4298 path = get_nid_path(codec, spec->imux_pins[i],
4299 get_adc_nid(codec, c, i));
4300 if (path) {
4301 bool active = path->active;
4302 if (i == spec->cur_mux[c])
4303 active = true;
4304 activate_path(codec, path, active, false);
4305 }
4306 }
4307 }
4308
4309 alc_inv_dmic_sync(codec, true);
4310 if (spec->shared_mic_hp)
4311 update_shared_mic_hp(codec, spec->cur_mux[0]);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004312}
4313
4314/* add mic boosts if needed */
4315static int alc_auto_add_mic_boost(struct hda_codec *codec)
4316{
4317 struct alc_spec *spec = codec->spec;
4318 struct auto_pin_cfg *cfg = &spec->autocfg;
4319 int i, err;
4320 int type_idx = 0;
4321 hda_nid_t nid;
4322 const char *prev_label = NULL;
4323
4324 for (i = 0; i < cfg->num_inputs; i++) {
4325 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4326 break;
4327 nid = cfg->inputs[i].pin;
4328 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4329 const char *label;
4330 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004331 struct nid_path *path;
4332 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004333
4334 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004335 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4336 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004337 if (prev_label && !strcmp(label, prev_label))
4338 type_idx++;
4339 else
4340 type_idx = 0;
4341 prev_label = label;
4342
4343 snprintf(boost_label, sizeof(boost_label),
4344 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004345 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004346 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004347 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004348 if (err < 0)
4349 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004350
4351 path = get_nid_path(codec, nid, 0);
4352 if (path)
4353 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004354 }
4355 }
4356 return 0;
4357}
4358
Takashi Iwai1d045db2011-07-07 18:23:21 +02004359/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004360 * standard auto-parser initializations
4361 */
4362static void alc_auto_init_std(struct hda_codec *codec)
4363{
Takashi Iwaie4770622011-07-08 11:11:35 +02004364 alc_auto_init_multi_out(codec);
4365 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004366 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004367 alc_auto_init_analog_input(codec);
4368 alc_auto_init_input_src(codec);
4369 alc_auto_init_digital(codec);
Takashi Iwai2eab6942012-12-18 15:30:41 +01004370 /* call init functions of standard auto-mute helpers */
4371 alc_hp_automute(codec, NULL);
4372 alc_line_automute(codec, NULL);
4373 alc_mic_automute(codec, NULL);
Takashi Iwaie4770622011-07-08 11:11:35 +02004374}
4375
4376/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004377 * Digital-beep handlers
4378 */
4379#ifdef CONFIG_SND_HDA_INPUT_BEEP
4380#define set_beep_amp(spec, nid, idx, dir) \
4381 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4382
4383static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004384 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4386 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4387 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4388 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004389 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004390 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4391 {}
4392};
4393
4394static inline int has_cdefine_beep(struct hda_codec *codec)
4395{
4396 struct alc_spec *spec = codec->spec;
4397 const struct snd_pci_quirk *q;
4398 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4399 if (q)
4400 return q->value;
4401 return spec->cdefine.enable_pcbeep;
4402}
4403#else
4404#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4405#define has_cdefine_beep(codec) 0
4406#endif
4407
4408/* parse the BIOS configuration and set up the alc_spec */
4409/* return 1 if successful, 0 if the proper config is not found,
4410 * or a negative error code
4411 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004412static int alc_parse_auto_config(struct hda_codec *codec,
4413 const hda_nid_t *ignore_nids,
4414 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004415{
4416 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004417 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004418 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004419
Takashi Iwai53c334a2011-08-23 18:27:14 +02004420 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4421 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004422 if (err < 0)
4423 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004424 if (!cfg->line_outs) {
4425 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004426 spec->multiout.max_channels = 2;
4427 spec->no_analog = 1;
4428 goto dig_only;
4429 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004430 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004431 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004432
Takashi Iwaie427c232012-07-29 10:04:08 +02004433 if (!spec->no_primary_hp &&
4434 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004435 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004436 /* use HP as primary out */
4437 cfg->speaker_outs = cfg->line_outs;
4438 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4439 sizeof(cfg->speaker_pins));
4440 cfg->line_outs = cfg->hp_outs;
4441 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4442 cfg->hp_outs = 0;
4443 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4444 cfg->line_out_type = AUTO_PIN_HP_OUT;
4445 }
4446
Takashi Iwai1d045db2011-07-07 18:23:21 +02004447 err = alc_auto_fill_dac_nids(codec);
4448 if (err < 0)
4449 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004450 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004451 if (err < 0)
4452 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004453 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004454 if (err < 0)
4455 return err;
4456 err = alc_auto_create_hp_out(codec);
4457 if (err < 0)
4458 return err;
4459 err = alc_auto_create_speaker_out(codec);
4460 if (err < 0)
4461 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004462 err = alc_auto_create_shared_input(codec);
4463 if (err < 0)
4464 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004465 err = alc_auto_create_input_ctls(codec);
4466 if (err < 0)
4467 return err;
4468
Takashi Iwaib6adb572012-12-03 10:30:58 +01004469 /* check the multiple speaker pins */
4470 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4471 spec->const_channel_count = cfg->line_outs * 2;
4472 else
4473 spec->const_channel_count = cfg->speaker_outs * 2;
4474
4475 if (spec->multi_ios > 0)
4476 spec->multiout.max_channels = max(spec->ext_channel_count,
4477 spec->const_channel_count);
4478 else
4479 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004480
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004481 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004482 alc_auto_parse_digital(codec);
4483
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004484 if (ssid_nids)
4485 alc_ssid_check(codec, ssid_nids);
4486
4487 if (!spec->no_analog) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004488 err = alc_init_automute(codec);
Takashi Iwai475c3d22012-11-30 08:31:30 +01004489 if (err < 0)
4490 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004491
4492 err = check_dyn_adc_switch(codec);
4493 if (err < 0)
4494 return err;
4495
4496 if (!spec->shared_mic_hp) {
4497 err = alc_init_auto_mic(codec);
4498 if (err < 0)
4499 return err;
4500 }
4501
4502 err = create_capture_mixers(codec);
4503 if (err < 0)
4504 return err;
4505
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004506 err = alc_auto_add_mic_boost(codec);
4507 if (err < 0)
4508 return err;
4509 }
4510
Takashi Iwai1d045db2011-07-07 18:23:21 +02004511 if (spec->kctls.list)
4512 add_mixer(spec, spec->kctls.list);
4513
Takashi Iwai1d045db2011-07-07 18:23:21 +02004514 return 1;
4515}
4516
Takashi Iwai3de95172012-05-07 18:03:15 +02004517/* common preparation job for alc_spec */
4518static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4519{
4520 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4521 int err;
4522
4523 if (!spec)
4524 return -ENOMEM;
4525 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004526 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004527 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004528 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004529 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4530 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004531 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004532
4533 err = alc_codec_rename_from_preset(codec);
4534 if (err < 0) {
4535 kfree(spec);
4536 return err;
4537 }
4538 return 0;
4539}
4540
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004541static int alc880_parse_auto_config(struct hda_codec *codec)
4542{
4543 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004544 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004545 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4546}
4547
Takashi Iwai1d045db2011-07-07 18:23:21 +02004548/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004549 * ALC880 fix-ups
4550 */
4551enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004552 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004553 ALC880_FIXUP_GPIO2,
4554 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004555 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004556 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004557 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004558 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004559 ALC880_FIXUP_VOL_KNOB,
4560 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004561 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004562 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004563 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004564 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004565 ALC880_FIXUP_3ST_BASE,
4566 ALC880_FIXUP_3ST,
4567 ALC880_FIXUP_3ST_DIG,
4568 ALC880_FIXUP_5ST_BASE,
4569 ALC880_FIXUP_5ST,
4570 ALC880_FIXUP_5ST_DIG,
4571 ALC880_FIXUP_6ST_BASE,
4572 ALC880_FIXUP_6ST,
4573 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004574};
4575
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004576/* enable the volume-knob widget support on NID 0x21 */
4577static void alc880_fixup_vol_knob(struct hda_codec *codec,
4578 const struct alc_fixup *fix, int action)
4579{
4580 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004581 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004582}
4583
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004584static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004585 [ALC880_FIXUP_GPIO1] = {
4586 .type = ALC_FIXUP_VERBS,
4587 .v.verbs = alc_gpio1_init_verbs,
4588 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004589 [ALC880_FIXUP_GPIO2] = {
4590 .type = ALC_FIXUP_VERBS,
4591 .v.verbs = alc_gpio2_init_verbs,
4592 },
4593 [ALC880_FIXUP_MEDION_RIM] = {
4594 .type = ALC_FIXUP_VERBS,
4595 .v.verbs = (const struct hda_verb[]) {
4596 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4597 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4598 { }
4599 },
4600 .chained = true,
4601 .chain_id = ALC880_FIXUP_GPIO2,
4602 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004603 [ALC880_FIXUP_LG] = {
4604 .type = ALC_FIXUP_PINS,
4605 .v.pins = (const struct alc_pincfg[]) {
4606 /* disable bogus unused pins */
4607 { 0x16, 0x411111f0 },
4608 { 0x18, 0x411111f0 },
4609 { 0x1a, 0x411111f0 },
4610 { }
4611 }
4612 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004613 [ALC880_FIXUP_W810] = {
4614 .type = ALC_FIXUP_PINS,
4615 .v.pins = (const struct alc_pincfg[]) {
4616 /* disable bogus unused pins */
4617 { 0x17, 0x411111f0 },
4618 { }
4619 },
4620 .chained = true,
4621 .chain_id = ALC880_FIXUP_GPIO2,
4622 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004623 [ALC880_FIXUP_EAPD_COEF] = {
4624 .type = ALC_FIXUP_VERBS,
4625 .v.verbs = (const struct hda_verb[]) {
4626 /* change to EAPD mode */
4627 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4628 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4629 {}
4630 },
4631 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004632 [ALC880_FIXUP_TCL_S700] = {
4633 .type = ALC_FIXUP_VERBS,
4634 .v.verbs = (const struct hda_verb[]) {
4635 /* change to EAPD mode */
4636 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4637 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4638 {}
4639 },
4640 .chained = true,
4641 .chain_id = ALC880_FIXUP_GPIO2,
4642 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004643 [ALC880_FIXUP_VOL_KNOB] = {
4644 .type = ALC_FIXUP_FUNC,
4645 .v.func = alc880_fixup_vol_knob,
4646 },
4647 [ALC880_FIXUP_FUJITSU] = {
4648 /* override all pins as BIOS on old Amilo is broken */
4649 .type = ALC_FIXUP_PINS,
4650 .v.pins = (const struct alc_pincfg[]) {
4651 { 0x14, 0x0121411f }, /* HP */
4652 { 0x15, 0x99030120 }, /* speaker */
4653 { 0x16, 0x99030130 }, /* bass speaker */
4654 { 0x17, 0x411111f0 }, /* N/A */
4655 { 0x18, 0x411111f0 }, /* N/A */
4656 { 0x19, 0x01a19950 }, /* mic-in */
4657 { 0x1a, 0x411111f0 }, /* N/A */
4658 { 0x1b, 0x411111f0 }, /* N/A */
4659 { 0x1c, 0x411111f0 }, /* N/A */
4660 { 0x1d, 0x411111f0 }, /* N/A */
4661 { 0x1e, 0x01454140 }, /* SPDIF out */
4662 { }
4663 },
4664 .chained = true,
4665 .chain_id = ALC880_FIXUP_VOL_KNOB,
4666 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004667 [ALC880_FIXUP_F1734] = {
4668 /* almost compatible with FUJITSU, but no bass and SPDIF */
4669 .type = ALC_FIXUP_PINS,
4670 .v.pins = (const struct alc_pincfg[]) {
4671 { 0x14, 0x0121411f }, /* HP */
4672 { 0x15, 0x99030120 }, /* speaker */
4673 { 0x16, 0x411111f0 }, /* N/A */
4674 { 0x17, 0x411111f0 }, /* N/A */
4675 { 0x18, 0x411111f0 }, /* N/A */
4676 { 0x19, 0x01a19950 }, /* mic-in */
4677 { 0x1a, 0x411111f0 }, /* N/A */
4678 { 0x1b, 0x411111f0 }, /* N/A */
4679 { 0x1c, 0x411111f0 }, /* N/A */
4680 { 0x1d, 0x411111f0 }, /* N/A */
4681 { 0x1e, 0x411111f0 }, /* N/A */
4682 { }
4683 },
4684 .chained = true,
4685 .chain_id = ALC880_FIXUP_VOL_KNOB,
4686 },
Takashi Iwai817de922012-02-20 17:20:48 +01004687 [ALC880_FIXUP_UNIWILL] = {
4688 /* need to fix HP and speaker pins to be parsed correctly */
4689 .type = ALC_FIXUP_PINS,
4690 .v.pins = (const struct alc_pincfg[]) {
4691 { 0x14, 0x0121411f }, /* HP */
4692 { 0x15, 0x99030120 }, /* speaker */
4693 { 0x16, 0x99030130 }, /* bass speaker */
4694 { }
4695 },
4696 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004697 [ALC880_FIXUP_UNIWILL_DIG] = {
4698 .type = ALC_FIXUP_PINS,
4699 .v.pins = (const struct alc_pincfg[]) {
4700 /* disable bogus unused pins */
4701 { 0x17, 0x411111f0 },
4702 { 0x19, 0x411111f0 },
4703 { 0x1b, 0x411111f0 },
4704 { 0x1f, 0x411111f0 },
4705 { }
4706 }
4707 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004708 [ALC880_FIXUP_Z71V] = {
4709 .type = ALC_FIXUP_PINS,
4710 .v.pins = (const struct alc_pincfg[]) {
4711 /* set up the whole pins as BIOS is utterly broken */
4712 { 0x14, 0x99030120 }, /* speaker */
4713 { 0x15, 0x0121411f }, /* HP */
4714 { 0x16, 0x411111f0 }, /* N/A */
4715 { 0x17, 0x411111f0 }, /* N/A */
4716 { 0x18, 0x01a19950 }, /* mic-in */
4717 { 0x19, 0x411111f0 }, /* N/A */
4718 { 0x1a, 0x01813031 }, /* line-in */
4719 { 0x1b, 0x411111f0 }, /* N/A */
4720 { 0x1c, 0x411111f0 }, /* N/A */
4721 { 0x1d, 0x411111f0 }, /* N/A */
4722 { 0x1e, 0x0144111e }, /* SPDIF */
4723 { }
4724 }
4725 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004726 [ALC880_FIXUP_3ST_BASE] = {
4727 .type = ALC_FIXUP_PINS,
4728 .v.pins = (const struct alc_pincfg[]) {
4729 { 0x14, 0x01014010 }, /* line-out */
4730 { 0x15, 0x411111f0 }, /* N/A */
4731 { 0x16, 0x411111f0 }, /* N/A */
4732 { 0x17, 0x411111f0 }, /* N/A */
4733 { 0x18, 0x01a19c30 }, /* mic-in */
4734 { 0x19, 0x0121411f }, /* HP */
4735 { 0x1a, 0x01813031 }, /* line-in */
4736 { 0x1b, 0x02a19c40 }, /* front-mic */
4737 { 0x1c, 0x411111f0 }, /* N/A */
4738 { 0x1d, 0x411111f0 }, /* N/A */
4739 /* 0x1e is filled in below */
4740 { 0x1f, 0x411111f0 }, /* N/A */
4741 { }
4742 }
4743 },
4744 [ALC880_FIXUP_3ST] = {
4745 .type = ALC_FIXUP_PINS,
4746 .v.pins = (const struct alc_pincfg[]) {
4747 { 0x1e, 0x411111f0 }, /* N/A */
4748 { }
4749 },
4750 .chained = true,
4751 .chain_id = ALC880_FIXUP_3ST_BASE,
4752 },
4753 [ALC880_FIXUP_3ST_DIG] = {
4754 .type = ALC_FIXUP_PINS,
4755 .v.pins = (const struct alc_pincfg[]) {
4756 { 0x1e, 0x0144111e }, /* SPDIF */
4757 { }
4758 },
4759 .chained = true,
4760 .chain_id = ALC880_FIXUP_3ST_BASE,
4761 },
4762 [ALC880_FIXUP_5ST_BASE] = {
4763 .type = ALC_FIXUP_PINS,
4764 .v.pins = (const struct alc_pincfg[]) {
4765 { 0x14, 0x01014010 }, /* front */
4766 { 0x15, 0x411111f0 }, /* N/A */
4767 { 0x16, 0x01011411 }, /* CLFE */
4768 { 0x17, 0x01016412 }, /* surr */
4769 { 0x18, 0x01a19c30 }, /* mic-in */
4770 { 0x19, 0x0121411f }, /* HP */
4771 { 0x1a, 0x01813031 }, /* line-in */
4772 { 0x1b, 0x02a19c40 }, /* front-mic */
4773 { 0x1c, 0x411111f0 }, /* N/A */
4774 { 0x1d, 0x411111f0 }, /* N/A */
4775 /* 0x1e is filled in below */
4776 { 0x1f, 0x411111f0 }, /* N/A */
4777 { }
4778 }
4779 },
4780 [ALC880_FIXUP_5ST] = {
4781 .type = ALC_FIXUP_PINS,
4782 .v.pins = (const struct alc_pincfg[]) {
4783 { 0x1e, 0x411111f0 }, /* N/A */
4784 { }
4785 },
4786 .chained = true,
4787 .chain_id = ALC880_FIXUP_5ST_BASE,
4788 },
4789 [ALC880_FIXUP_5ST_DIG] = {
4790 .type = ALC_FIXUP_PINS,
4791 .v.pins = (const struct alc_pincfg[]) {
4792 { 0x1e, 0x0144111e }, /* SPDIF */
4793 { }
4794 },
4795 .chained = true,
4796 .chain_id = ALC880_FIXUP_5ST_BASE,
4797 },
4798 [ALC880_FIXUP_6ST_BASE] = {
4799 .type = ALC_FIXUP_PINS,
4800 .v.pins = (const struct alc_pincfg[]) {
4801 { 0x14, 0x01014010 }, /* front */
4802 { 0x15, 0x01016412 }, /* surr */
4803 { 0x16, 0x01011411 }, /* CLFE */
4804 { 0x17, 0x01012414 }, /* side */
4805 { 0x18, 0x01a19c30 }, /* mic-in */
4806 { 0x19, 0x02a19c40 }, /* front-mic */
4807 { 0x1a, 0x01813031 }, /* line-in */
4808 { 0x1b, 0x0121411f }, /* HP */
4809 { 0x1c, 0x411111f0 }, /* N/A */
4810 { 0x1d, 0x411111f0 }, /* N/A */
4811 /* 0x1e is filled in below */
4812 { 0x1f, 0x411111f0 }, /* N/A */
4813 { }
4814 }
4815 },
4816 [ALC880_FIXUP_6ST] = {
4817 .type = ALC_FIXUP_PINS,
4818 .v.pins = (const struct alc_pincfg[]) {
4819 { 0x1e, 0x411111f0 }, /* N/A */
4820 { }
4821 },
4822 .chained = true,
4823 .chain_id = ALC880_FIXUP_6ST_BASE,
4824 },
4825 [ALC880_FIXUP_6ST_DIG] = {
4826 .type = ALC_FIXUP_PINS,
4827 .v.pins = (const struct alc_pincfg[]) {
4828 { 0x1e, 0x0144111e }, /* SPDIF */
4829 { }
4830 },
4831 .chained = true,
4832 .chain_id = ALC880_FIXUP_6ST_BASE,
4833 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004834};
4835
4836static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004837 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004838 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004839 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4840 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004841 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004842 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004843 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004844 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004845 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004846 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004847 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004848 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004849 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004850 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004851 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004852 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4853 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4854 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004855 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004856
4857 /* Below is the copied entries from alc880_quirks.c.
4858 * It's not quite sure whether BIOS sets the correct pin-config table
4859 * on these machines, thus they are kept to be compatible with
4860 * the old static quirks. Once when it's confirmed to work without
4861 * these overrides, it'd be better to remove.
4862 */
4863 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4864 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4865 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4866 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4867 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4868 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4869 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4870 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4871 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4872 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4873 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4874 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4875 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4876 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4877 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4878 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4879 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4880 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4881 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4882 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4883 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4884 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4885 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4886 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4887 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4888 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4889 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4890 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4891 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4892 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4893 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4894 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4895 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4896 /* default Intel */
4897 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4898 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4899 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4900 {}
4901};
4902
4903static const struct alc_model_fixup alc880_fixup_models[] = {
4904 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4905 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4906 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4907 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4908 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4909 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004910 {}
4911};
4912
4913
4914/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004915 * OK, here we have finally the patch for ALC880
4916 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004917static int patch_alc880(struct hda_codec *codec)
4918{
4919 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004920 int err;
4921
Takashi Iwai3de95172012-05-07 18:03:15 +02004922 err = alc_alloc_spec(codec, 0x0b);
4923 if (err < 0)
4924 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004925
Takashi Iwai3de95172012-05-07 18:03:15 +02004926 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004927 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004928
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004929 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4930 alc880_fixups);
4931 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004932
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004933 /* automatic parse from the BIOS config */
4934 err = alc880_parse_auto_config(codec);
4935 if (err < 0)
4936 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004937
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004938 if (!spec->no_analog) {
4939 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004940 if (err < 0)
4941 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004942 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4943 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004944
Takashi Iwai1d045db2011-07-07 18:23:21 +02004945 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004946 codec->patch_ops.unsol_event = alc880_unsol_event;
4947
Takashi Iwai1d045db2011-07-07 18:23:21 +02004948
Takashi Iwai589876e2012-02-20 15:47:55 +01004949 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4950
Takashi Iwai1d045db2011-07-07 18:23:21 +02004951 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004952
4953 error:
4954 alc_free(codec);
4955 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004956}
4957
4958
4959/*
4960 * ALC260 support
4961 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004962static int alc260_parse_auto_config(struct hda_codec *codec)
4963{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004964 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004965 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4966 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004967}
4968
Takashi Iwai1d045db2011-07-07 18:23:21 +02004969/*
4970 * Pin config fixes
4971 */
4972enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004973 ALC260_FIXUP_HP_DC5750,
4974 ALC260_FIXUP_HP_PIN_0F,
4975 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004976 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004977 ALC260_FIXUP_GPIO1_TOGGLE,
4978 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004979 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004980 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004981};
4982
Takashi Iwai20f7d922012-02-16 12:35:16 +01004983static void alc260_gpio1_automute(struct hda_codec *codec)
4984{
4985 struct alc_spec *spec = codec->spec;
4986 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4987 spec->hp_jack_present);
4988}
4989
4990static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4991 const struct alc_fixup *fix, int action)
4992{
4993 struct alc_spec *spec = codec->spec;
4994 if (action == ALC_FIXUP_ACT_PROBE) {
4995 /* although the machine has only one output pin, we need to
4996 * toggle GPIO1 according to the jack state
4997 */
4998 spec->automute_hook = alc260_gpio1_automute;
4999 spec->detect_hp = 1;
5000 spec->automute_speaker = 1;
5001 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005002 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5003 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005004 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005005 }
5006}
5007
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005008static void alc260_fixup_kn1(struct hda_codec *codec,
5009 const struct alc_fixup *fix, int action)
5010{
5011 struct alc_spec *spec = codec->spec;
5012 static const struct alc_pincfg pincfgs[] = {
5013 { 0x0f, 0x02214000 }, /* HP/speaker */
5014 { 0x12, 0x90a60160 }, /* int mic */
5015 { 0x13, 0x02a19000 }, /* ext mic */
5016 { 0x18, 0x01446000 }, /* SPDIF out */
5017 /* disable bogus I/O pins */
5018 { 0x10, 0x411111f0 },
5019 { 0x11, 0x411111f0 },
5020 { 0x14, 0x411111f0 },
5021 { 0x15, 0x411111f0 },
5022 { 0x16, 0x411111f0 },
5023 { 0x17, 0x411111f0 },
5024 { 0x19, 0x411111f0 },
5025 { }
5026 };
5027
5028 switch (action) {
5029 case ALC_FIXUP_ACT_PRE_PROBE:
5030 alc_apply_pincfgs(codec, pincfgs);
5031 break;
5032 case ALC_FIXUP_ACT_PROBE:
5033 spec->init_amp = ALC_INIT_NONE;
5034 break;
5035 }
5036}
5037
Takashi Iwai1d045db2011-07-07 18:23:21 +02005038static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005039 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005040 .type = ALC_FIXUP_PINS,
5041 .v.pins = (const struct alc_pincfg[]) {
5042 { 0x11, 0x90130110 }, /* speaker */
5043 { }
5044 }
5045 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005046 [ALC260_FIXUP_HP_PIN_0F] = {
5047 .type = ALC_FIXUP_PINS,
5048 .v.pins = (const struct alc_pincfg[]) {
5049 { 0x0f, 0x01214000 }, /* HP */
5050 { }
5051 }
5052 },
5053 [ALC260_FIXUP_COEF] = {
5054 .type = ALC_FIXUP_VERBS,
5055 .v.verbs = (const struct hda_verb[]) {
5056 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5057 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5058 { }
5059 },
5060 .chained = true,
5061 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5062 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005063 [ALC260_FIXUP_GPIO1] = {
5064 .type = ALC_FIXUP_VERBS,
5065 .v.verbs = alc_gpio1_init_verbs,
5066 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005067 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5068 .type = ALC_FIXUP_FUNC,
5069 .v.func = alc260_fixup_gpio1_toggle,
5070 .chained = true,
5071 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5072 },
5073 [ALC260_FIXUP_REPLACER] = {
5074 .type = ALC_FIXUP_VERBS,
5075 .v.verbs = (const struct hda_verb[]) {
5076 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5077 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5078 { }
5079 },
5080 .chained = true,
5081 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5082 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005083 [ALC260_FIXUP_HP_B1900] = {
5084 .type = ALC_FIXUP_FUNC,
5085 .v.func = alc260_fixup_gpio1_toggle,
5086 .chained = true,
5087 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005088 },
5089 [ALC260_FIXUP_KN1] = {
5090 .type = ALC_FIXUP_FUNC,
5091 .v.func = alc260_fixup_kn1,
5092 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005093};
5094
5095static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005096 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005097 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005098 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005099 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005100 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005101 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005102 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005103 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005104 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005105 {}
5106};
5107
5108/*
5109 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005110static int patch_alc260(struct hda_codec *codec)
5111{
5112 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005113 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005114
Takashi Iwai3de95172012-05-07 18:03:15 +02005115 err = alc_alloc_spec(codec, 0x07);
5116 if (err < 0)
5117 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005118
Takashi Iwai3de95172012-05-07 18:03:15 +02005119 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005120
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005121 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5122 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005123
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005124 /* automatic parse from the BIOS config */
5125 err = alc260_parse_auto_config(codec);
5126 if (err < 0)
5127 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005128
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005129 if (!spec->no_analog) {
5130 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005131 if (err < 0)
5132 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005133 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5134 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005135
Takashi Iwai1d045db2011-07-07 18:23:21 +02005136 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005137 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005138
Takashi Iwai589876e2012-02-20 15:47:55 +01005139 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5140
Takashi Iwai1d045db2011-07-07 18:23:21 +02005141 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005142
5143 error:
5144 alc_free(codec);
5145 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005146}
5147
5148
5149/*
5150 * ALC882/883/885/888/889 support
5151 *
5152 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5153 * configuration. Each pin widget can choose any input DACs and a mixer.
5154 * Each ADC is connected from a mixer of all inputs. This makes possible
5155 * 6-channel independent captures.
5156 *
5157 * In addition, an independent DAC for the multi-playback (not used in this
5158 * driver yet).
5159 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005160
5161/*
5162 * Pin config fixes
5163 */
5164enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005165 ALC882_FIXUP_ABIT_AW9D_MAX,
5166 ALC882_FIXUP_LENOVO_Y530,
5167 ALC882_FIXUP_PB_M5210,
5168 ALC882_FIXUP_ACER_ASPIRE_7736,
5169 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005170 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005171 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005172 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005173 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005174 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005175 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005176 ALC882_FIXUP_GPIO1,
5177 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005178 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005179 ALC889_FIXUP_COEF,
5180 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005181 ALC882_FIXUP_ACER_ASPIRE_4930G,
5182 ALC882_FIXUP_ACER_ASPIRE_8930G,
5183 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005184 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005185 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005186 ALC889_FIXUP_MBP_VREF,
5187 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005188 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005189 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005190};
5191
Takashi Iwai68ef0562011-11-09 18:24:44 +01005192static void alc889_fixup_coef(struct hda_codec *codec,
5193 const struct alc_fixup *fix, int action)
5194{
5195 if (action != ALC_FIXUP_ACT_INIT)
5196 return;
5197 alc889_coef_init(codec);
5198}
5199
Takashi Iwai56710872011-11-14 17:42:11 +01005200/* toggle speaker-output according to the hp-jack state */
5201static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5202{
5203 unsigned int gpiostate, gpiomask, gpiodir;
5204
5205 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5206 AC_VERB_GET_GPIO_DATA, 0);
5207
5208 if (!muted)
5209 gpiostate |= (1 << pin);
5210 else
5211 gpiostate &= ~(1 << pin);
5212
5213 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5214 AC_VERB_GET_GPIO_MASK, 0);
5215 gpiomask |= (1 << pin);
5216
5217 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5218 AC_VERB_GET_GPIO_DIRECTION, 0);
5219 gpiodir |= (1 << pin);
5220
5221
5222 snd_hda_codec_write(codec, codec->afg, 0,
5223 AC_VERB_SET_GPIO_MASK, gpiomask);
5224 snd_hda_codec_write(codec, codec->afg, 0,
5225 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5226
5227 msleep(1);
5228
5229 snd_hda_codec_write(codec, codec->afg, 0,
5230 AC_VERB_SET_GPIO_DATA, gpiostate);
5231}
5232
5233/* set up GPIO at initialization */
5234static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5235 const struct alc_fixup *fix, int action)
5236{
5237 if (action != ALC_FIXUP_ACT_INIT)
5238 return;
5239 alc882_gpio_mute(codec, 0, 0);
5240 alc882_gpio_mute(codec, 1, 0);
5241}
5242
Takashi Iwai02a237b2012-02-13 15:25:07 +01005243/* Fix the connection of some pins for ALC889:
5244 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5245 * work correctly (bko#42740)
5246 */
5247static void alc889_fixup_dac_route(struct hda_codec *codec,
5248 const struct alc_fixup *fix, int action)
5249{
5250 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005251 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005252 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5253 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5254 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5255 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5256 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5257 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005258 } else if (action == ALC_FIXUP_ACT_PROBE) {
5259 /* restore the connections */
5260 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5261 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5262 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5263 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5264 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005265 }
5266}
5267
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005268/* Set VREF on HP pin */
5269static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5270 const struct alc_fixup *fix, int action)
5271{
5272 struct alc_spec *spec = codec->spec;
5273 static hda_nid_t nids[2] = { 0x14, 0x15 };
5274 int i;
5275
5276 if (action != ALC_FIXUP_ACT_INIT)
5277 return;
5278 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5279 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5280 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5281 continue;
5282 val = snd_hda_codec_read(codec, nids[i], 0,
5283 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5284 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005285 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005286 spec->keep_vref_in_automute = 1;
5287 break;
5288 }
5289}
5290
5291/* Set VREF on speaker pins on imac91 */
5292static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5293 const struct alc_fixup *fix, int action)
5294{
5295 struct alc_spec *spec = codec->spec;
5296 static hda_nid_t nids[2] = { 0x18, 0x1a };
5297 int i;
5298
5299 if (action != ALC_FIXUP_ACT_INIT)
5300 return;
5301 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5302 unsigned int val;
5303 val = snd_hda_codec_read(codec, nids[i], 0,
5304 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5305 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005306 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005307 }
5308 spec->keep_vref_in_automute = 1;
5309}
5310
Takashi Iwaie427c232012-07-29 10:04:08 +02005311/* Don't take HP output as primary
5312 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5313 */
5314static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5315 const struct alc_fixup *fix, int action)
5316{
5317 struct alc_spec *spec = codec->spec;
5318 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5319 spec->no_primary_hp = 1;
5320}
5321
Takashi Iwai1d045db2011-07-07 18:23:21 +02005322static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005323 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005324 .type = ALC_FIXUP_PINS,
5325 .v.pins = (const struct alc_pincfg[]) {
5326 { 0x15, 0x01080104 }, /* side */
5327 { 0x16, 0x01011012 }, /* rear */
5328 { 0x17, 0x01016011 }, /* clfe */
5329 { }
5330 }
5331 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005332 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005333 .type = ALC_FIXUP_PINS,
5334 .v.pins = (const struct alc_pincfg[]) {
5335 { 0x15, 0x99130112 }, /* rear int speakers */
5336 { 0x16, 0x99130111 }, /* subwoofer */
5337 { }
5338 }
5339 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005340 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005341 .type = ALC_FIXUP_VERBS,
5342 .v.verbs = (const struct hda_verb[]) {
5343 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5344 {}
5345 }
5346 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005347 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005348 .type = ALC_FIXUP_FUNC,
5349 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005350 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005351 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005352 .type = ALC_FIXUP_PINS,
5353 .v.pins = (const struct alc_pincfg[]) {
5354 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5355 { }
5356 }
5357 },
Marton Balint8f239212012-03-05 21:33:23 +01005358 [ALC889_FIXUP_CD] = {
5359 .type = ALC_FIXUP_PINS,
5360 .v.pins = (const struct alc_pincfg[]) {
5361 { 0x1c, 0x993301f0 }, /* CD */
5362 { }
5363 }
5364 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005365 [ALC889_FIXUP_VAIO_TT] = {
5366 .type = ALC_FIXUP_PINS,
5367 .v.pins = (const struct alc_pincfg[]) {
5368 { 0x17, 0x90170111 }, /* hidden surround speaker */
5369 { }
5370 }
5371 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005372 [ALC888_FIXUP_EEE1601] = {
5373 .type = ALC_FIXUP_VERBS,
5374 .v.verbs = (const struct hda_verb[]) {
5375 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5376 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5377 { }
5378 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005379 },
5380 [ALC882_FIXUP_EAPD] = {
5381 .type = ALC_FIXUP_VERBS,
5382 .v.verbs = (const struct hda_verb[]) {
5383 /* change to EAPD mode */
5384 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5385 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5386 { }
5387 }
5388 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005389 [ALC883_FIXUP_EAPD] = {
5390 .type = ALC_FIXUP_VERBS,
5391 .v.verbs = (const struct hda_verb[]) {
5392 /* change to EAPD mode */
5393 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5394 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5395 { }
5396 }
5397 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005398 [ALC883_FIXUP_ACER_EAPD] = {
5399 .type = ALC_FIXUP_VERBS,
5400 .v.verbs = (const struct hda_verb[]) {
5401 /* eanable EAPD on Acer laptops */
5402 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5403 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5404 { }
5405 }
5406 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005407 [ALC882_FIXUP_GPIO1] = {
5408 .type = ALC_FIXUP_VERBS,
5409 .v.verbs = alc_gpio1_init_verbs,
5410 },
5411 [ALC882_FIXUP_GPIO2] = {
5412 .type = ALC_FIXUP_VERBS,
5413 .v.verbs = alc_gpio2_init_verbs,
5414 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005415 [ALC882_FIXUP_GPIO3] = {
5416 .type = ALC_FIXUP_VERBS,
5417 .v.verbs = alc_gpio3_init_verbs,
5418 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005419 [ALC882_FIXUP_ASUS_W2JC] = {
5420 .type = ALC_FIXUP_VERBS,
5421 .v.verbs = alc_gpio1_init_verbs,
5422 .chained = true,
5423 .chain_id = ALC882_FIXUP_EAPD,
5424 },
5425 [ALC889_FIXUP_COEF] = {
5426 .type = ALC_FIXUP_FUNC,
5427 .v.func = alc889_fixup_coef,
5428 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005429 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5430 .type = ALC_FIXUP_PINS,
5431 .v.pins = (const struct alc_pincfg[]) {
5432 { 0x16, 0x99130111 }, /* CLFE speaker */
5433 { 0x17, 0x99130112 }, /* surround speaker */
5434 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005435 },
5436 .chained = true,
5437 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005438 },
5439 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5440 .type = ALC_FIXUP_PINS,
5441 .v.pins = (const struct alc_pincfg[]) {
5442 { 0x16, 0x99130111 }, /* CLFE speaker */
5443 { 0x1b, 0x99130112 }, /* surround speaker */
5444 { }
5445 },
5446 .chained = true,
5447 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5448 },
5449 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5450 /* additional init verbs for Acer Aspire 8930G */
5451 .type = ALC_FIXUP_VERBS,
5452 .v.verbs = (const struct hda_verb[]) {
5453 /* Enable all DACs */
5454 /* DAC DISABLE/MUTE 1? */
5455 /* setting bits 1-5 disables DAC nids 0x02-0x06
5456 * apparently. Init=0x38 */
5457 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5458 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5459 /* DAC DISABLE/MUTE 2? */
5460 /* some bit here disables the other DACs.
5461 * Init=0x4900 */
5462 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5463 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5464 /* DMIC fix
5465 * This laptop has a stereo digital microphone.
5466 * The mics are only 1cm apart which makes the stereo
5467 * useless. However, either the mic or the ALC889
5468 * makes the signal become a difference/sum signal
5469 * instead of standard stereo, which is annoying.
5470 * So instead we flip this bit which makes the
5471 * codec replicate the sum signal to both channels,
5472 * turning it into a normal mono mic.
5473 */
5474 /* DMIC_CONTROL? Init value = 0x0001 */
5475 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5476 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5477 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5478 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5479 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005480 },
5481 .chained = true,
5482 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005483 },
Takashi Iwai56710872011-11-14 17:42:11 +01005484 [ALC885_FIXUP_MACPRO_GPIO] = {
5485 .type = ALC_FIXUP_FUNC,
5486 .v.func = alc885_fixup_macpro_gpio,
5487 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005488 [ALC889_FIXUP_DAC_ROUTE] = {
5489 .type = ALC_FIXUP_FUNC,
5490 .v.func = alc889_fixup_dac_route,
5491 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005492 [ALC889_FIXUP_MBP_VREF] = {
5493 .type = ALC_FIXUP_FUNC,
5494 .v.func = alc889_fixup_mbp_vref,
5495 .chained = true,
5496 .chain_id = ALC882_FIXUP_GPIO1,
5497 },
5498 [ALC889_FIXUP_IMAC91_VREF] = {
5499 .type = ALC_FIXUP_FUNC,
5500 .v.func = alc889_fixup_imac91_vref,
5501 .chained = true,
5502 .chain_id = ALC882_FIXUP_GPIO1,
5503 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005504 [ALC882_FIXUP_INV_DMIC] = {
5505 .type = ALC_FIXUP_FUNC,
5506 .v.func = alc_fixup_inv_dmic_0x12,
5507 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005508 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5509 .type = ALC_FIXUP_FUNC,
5510 .v.func = alc882_fixup_no_primary_hp,
5511 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512};
5513
5514static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005515 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5516 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5517 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5518 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5519 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5520 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005521 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5522 ALC882_FIXUP_ACER_ASPIRE_4930G),
5523 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5524 ALC882_FIXUP_ACER_ASPIRE_4930G),
5525 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5526 ALC882_FIXUP_ACER_ASPIRE_8930G),
5527 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5528 ALC882_FIXUP_ACER_ASPIRE_8930G),
5529 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5530 ALC882_FIXUP_ACER_ASPIRE_4930G),
5531 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5532 ALC882_FIXUP_ACER_ASPIRE_4930G),
5533 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5534 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005535 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005536 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5537 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005538 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005539 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005540 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005541 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005542 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005543 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005544 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005545 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005546 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005547
5548 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005549 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5550 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5551 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005552 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5553 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5554 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005555 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5556 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005557 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005558 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5559 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5560 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5561 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005562 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005563 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5564 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5565 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005566 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005567 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005568 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5569 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5570 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005571
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005572 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005573 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005574 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005575 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005576 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005577 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5578 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005579 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005580 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005581 {}
5582};
5583
Takashi Iwai912093b2012-04-11 14:03:41 +02005584static const struct alc_model_fixup alc882_fixup_models[] = {
5585 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5586 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5587 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005588 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005589 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005590 {}
5591};
5592
Takashi Iwai1d045db2011-07-07 18:23:21 +02005593/*
5594 * BIOS auto configuration
5595 */
5596/* almost identical with ALC880 parser... */
5597static int alc882_parse_auto_config(struct hda_codec *codec)
5598{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005599 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005600 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5601 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005602}
5603
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604/*
5605 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005606static int patch_alc882(struct hda_codec *codec)
5607{
5608 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005609 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005610
Takashi Iwai3de95172012-05-07 18:03:15 +02005611 err = alc_alloc_spec(codec, 0x0b);
5612 if (err < 0)
5613 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005614
Takashi Iwai3de95172012-05-07 18:03:15 +02005615 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005616
5617 switch (codec->vendor_id) {
5618 case 0x10ec0882:
5619 case 0x10ec0885:
5620 break;
5621 default:
5622 /* ALC883 and variants */
5623 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5624 break;
5625 }
5626
Takashi Iwai912093b2012-04-11 14:03:41 +02005627 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5628 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005629 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005630
5631 alc_auto_parse_customize_define(codec);
5632
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005633 /* automatic parse from the BIOS config */
5634 err = alc882_parse_auto_config(codec);
5635 if (err < 0)
5636 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005637
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005638 if (!spec->no_analog && has_cdefine_beep(codec)) {
5639 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005640 if (err < 0)
5641 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005642 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005643 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005644
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005646
Takashi Iwai589876e2012-02-20 15:47:55 +01005647 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5648
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005650
5651 error:
5652 alc_free(codec);
5653 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005654}
5655
5656
5657/*
5658 * ALC262 support
5659 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005660static int alc262_parse_auto_config(struct hda_codec *codec)
5661{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005662 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005663 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5664 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005665}
5666
5667/*
5668 * Pin config fixes
5669 */
5670enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005671 ALC262_FIXUP_FSC_H270,
5672 ALC262_FIXUP_HP_Z200,
5673 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005674 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005675 ALC262_FIXUP_BENQ,
5676 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005677 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005678};
5679
5680static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005681 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005682 .type = ALC_FIXUP_PINS,
5683 .v.pins = (const struct alc_pincfg[]) {
5684 { 0x14, 0x99130110 }, /* speaker */
5685 { 0x15, 0x0221142f }, /* front HP */
5686 { 0x1b, 0x0121141f }, /* rear HP */
5687 { }
5688 }
5689 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005690 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691 .type = ALC_FIXUP_PINS,
5692 .v.pins = (const struct alc_pincfg[]) {
5693 { 0x16, 0x99130120 }, /* internal speaker */
5694 { }
5695 }
5696 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005697 [ALC262_FIXUP_TYAN] = {
5698 .type = ALC_FIXUP_PINS,
5699 .v.pins = (const struct alc_pincfg[]) {
5700 { 0x14, 0x1993e1f0 }, /* int AUX */
5701 { }
5702 }
5703 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005704 [ALC262_FIXUP_LENOVO_3000] = {
5705 .type = ALC_FIXUP_VERBS,
5706 .v.verbs = (const struct hda_verb[]) {
5707 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005708 {}
5709 },
5710 .chained = true,
5711 .chain_id = ALC262_FIXUP_BENQ,
5712 },
5713 [ALC262_FIXUP_BENQ] = {
5714 .type = ALC_FIXUP_VERBS,
5715 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005716 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5717 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5718 {}
5719 }
5720 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005721 [ALC262_FIXUP_BENQ_T31] = {
5722 .type = ALC_FIXUP_VERBS,
5723 .v.verbs = (const struct hda_verb[]) {
5724 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5725 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5726 {}
5727 }
5728 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005729 [ALC262_FIXUP_INV_DMIC] = {
5730 .type = ALC_FIXUP_FUNC,
5731 .v.func = alc_fixup_inv_dmic_0x12,
5732 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005733};
5734
5735static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005736 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005737 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5738 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005739 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5740 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005741 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005742 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5743 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005744 {}
5745};
5746
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005747static const struct alc_model_fixup alc262_fixup_models[] = {
5748 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5749 {}
5750};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005751
Takashi Iwai1d045db2011-07-07 18:23:21 +02005752/*
5753 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754static int patch_alc262(struct hda_codec *codec)
5755{
5756 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757 int err;
5758
Takashi Iwai3de95172012-05-07 18:03:15 +02005759 err = alc_alloc_spec(codec, 0x0b);
5760 if (err < 0)
5761 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005762
Takashi Iwai3de95172012-05-07 18:03:15 +02005763 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01005764 spec->shared_mic_vref_pin = 0x18;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765
5766#if 0
5767 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5768 * under-run
5769 */
5770 {
5771 int tmp;
5772 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5773 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5774 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5775 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5776 }
5777#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005778 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5779
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005780 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5781 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005782 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005783
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005784 alc_auto_parse_customize_define(codec);
5785
Takashi Iwai42399f72011-11-07 17:18:44 +01005786 /* automatic parse from the BIOS config */
5787 err = alc262_parse_auto_config(codec);
5788 if (err < 0)
5789 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005790
Takashi Iwai1d045db2011-07-07 18:23:21 +02005791 if (!spec->no_analog && has_cdefine_beep(codec)) {
5792 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005793 if (err < 0)
5794 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005795 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005796 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005797
Takashi Iwai1d045db2011-07-07 18:23:21 +02005798 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005799 spec->shutup = alc_eapd_shutup;
5800
Takashi Iwai589876e2012-02-20 15:47:55 +01005801 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5802
Takashi Iwai1d045db2011-07-07 18:23:21 +02005803 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005804
5805 error:
5806 alc_free(codec);
5807 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005808}
5809
5810/*
5811 * ALC268
5812 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005813/* bind Beep switches of both NID 0x0f and 0x10 */
5814static const struct hda_bind_ctls alc268_bind_beep_sw = {
5815 .ops = &snd_hda_bind_sw,
5816 .values = {
5817 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5818 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5819 0
5820 },
5821};
5822
5823static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5824 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5825 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5826 { }
5827};
5828
5829/* set PCBEEP vol = 0, mute connections */
5830static const struct hda_verb alc268_beep_init_verbs[] = {
5831 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5832 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5833 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5834 { }
5835};
5836
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005837enum {
5838 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005839 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005840};
5841
5842static const struct alc_fixup alc268_fixups[] = {
5843 [ALC268_FIXUP_INV_DMIC] = {
5844 .type = ALC_FIXUP_FUNC,
5845 .v.func = alc_fixup_inv_dmic_0x12,
5846 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005847 [ALC268_FIXUP_HP_EAPD] = {
5848 .type = ALC_FIXUP_VERBS,
5849 .v.verbs = (const struct hda_verb[]) {
5850 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5851 {}
5852 }
5853 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005854};
5855
5856static const struct alc_model_fixup alc268_fixup_models[] = {
5857 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005858 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5859 {}
5860};
5861
5862static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5863 /* below is codec SSID since multiple Toshiba laptops have the
5864 * same PCI SSID 1179:ff00
5865 */
5866 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005867 {}
5868};
5869
Takashi Iwai1d045db2011-07-07 18:23:21 +02005870/*
5871 * BIOS auto configuration
5872 */
5873static int alc268_parse_auto_config(struct hda_codec *codec)
5874{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005875 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005876 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005877 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5878 if (err > 0) {
5879 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5880 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005881 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005882 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005883 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005884 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005885}
5886
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887/*
5888 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005889static int patch_alc268(struct hda_codec *codec)
5890{
5891 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005892 int i, has_beep, err;
5893
Takashi Iwai1d045db2011-07-07 18:23:21 +02005894 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005895 err = alc_alloc_spec(codec, 0);
5896 if (err < 0)
5897 return err;
5898
5899 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005900
Takashi Iwaicb766402012-10-20 10:55:21 +02005901 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005902 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5903
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005904 /* automatic parse from the BIOS config */
5905 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005906 if (err < 0)
5907 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005908
Takashi Iwai1d045db2011-07-07 18:23:21 +02005909 has_beep = 0;
5910 for (i = 0; i < spec->num_mixers; i++) {
5911 if (spec->mixers[i] == alc268_beep_mixer) {
5912 has_beep = 1;
5913 break;
5914 }
5915 }
5916
5917 if (has_beep) {
5918 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005919 if (err < 0)
5920 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005921 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5922 /* override the amp caps for beep generator */
5923 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5924 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5925 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5926 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5927 (0 << AC_AMPCAP_MUTE_SHIFT));
5928 }
5929
Takashi Iwai1d045db2011-07-07 18:23:21 +02005930 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005931 spec->shutup = alc_eapd_shutup;
5932
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005933 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5934
Takashi Iwai1d045db2011-07-07 18:23:21 +02005935 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005936
5937 error:
5938 alc_free(codec);
5939 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005940}
5941
5942/*
5943 * ALC269
5944 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005945static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5946 .substreams = 1,
5947 .channels_min = 2,
5948 .channels_max = 8,
5949 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5950 /* NID is set in alc_build_pcms */
5951 .ops = {
5952 .open = alc_playback_pcm_open,
5953 .prepare = alc_playback_pcm_prepare,
5954 .cleanup = alc_playback_pcm_cleanup
5955 },
5956};
5957
5958static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5959 .substreams = 1,
5960 .channels_min = 2,
5961 .channels_max = 2,
5962 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5963 /* NID is set in alc_build_pcms */
5964};
5965
Takashi Iwai1d045db2011-07-07 18:23:21 +02005966/* different alc269-variants */
5967enum {
5968 ALC269_TYPE_ALC269VA,
5969 ALC269_TYPE_ALC269VB,
5970 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005971 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005972 ALC269_TYPE_ALC280,
5973 ALC269_TYPE_ALC282,
5974 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005975};
5976
5977/*
5978 * BIOS auto configuration
5979 */
5980static int alc269_parse_auto_config(struct hda_codec *codec)
5981{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005982 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005983 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5984 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5985 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005986 const hda_nid_t *ssids;
5987
5988 switch (spec->codec_variant) {
5989 case ALC269_TYPE_ALC269VA:
5990 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005991 case ALC269_TYPE_ALC280:
5992 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005993 ssids = alc269va_ssids;
5994 break;
5995 case ALC269_TYPE_ALC269VB:
5996 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005997 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005998 ssids = alc269_ssids;
5999 break;
6000 default:
6001 ssids = alc269_ssids;
6002 break;
6003 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006004
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006005 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006006}
6007
Kailang Yang1387e2d2012-11-08 10:23:18 +01006008static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006009{
6010 int val = alc_read_coef_idx(codec, 0x04);
6011 if (power_up)
6012 val |= 1 << 11;
6013 else
6014 val &= ~(1 << 11);
6015 alc_write_coef_idx(codec, 0x04, val);
6016}
6017
6018static void alc269_shutup(struct hda_codec *codec)
6019{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006020 struct alc_spec *spec = codec->spec;
6021
6022 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6023 return;
6024
Kailang Yang1387e2d2012-11-08 10:23:18 +01006025 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6026 alc269vb_toggle_power_output(codec, 0);
6027 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6028 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006029 msleep(150);
6030 }
6031}
6032
Takashi Iwai2a439522011-07-26 09:52:50 +02006033#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006034static int alc269_resume(struct hda_codec *codec)
6035{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006036 struct alc_spec *spec = codec->spec;
6037
Kailang Yang1387e2d2012-11-08 10:23:18 +01006038 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6039 alc269vb_toggle_power_output(codec, 0);
6040 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006041 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006042 msleep(150);
6043 }
6044
6045 codec->patch_ops.init(codec);
6046
Kailang Yang1387e2d2012-11-08 10:23:18 +01006047 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6048 alc269vb_toggle_power_output(codec, 1);
6049 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006050 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006051 msleep(200);
6052 }
6053
Takashi Iwai1d045db2011-07-07 18:23:21 +02006054 snd_hda_codec_resume_amp(codec);
6055 snd_hda_codec_resume_cache(codec);
6056 hda_call_check_power_status(codec, 0x01);
6057 return 0;
6058}
Takashi Iwai2a439522011-07-26 09:52:50 +02006059#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006060
David Henningsson108cc102012-07-20 10:37:25 +02006061static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6062 const struct alc_fixup *fix, int action)
6063{
6064 struct alc_spec *spec = codec->spec;
6065
6066 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6067 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6068}
6069
Takashi Iwai1d045db2011-07-07 18:23:21 +02006070static void alc269_fixup_hweq(struct hda_codec *codec,
6071 const struct alc_fixup *fix, int action)
6072{
6073 int coef;
6074
6075 if (action != ALC_FIXUP_ACT_INIT)
6076 return;
6077 coef = alc_read_coef_idx(codec, 0x1e);
6078 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6079}
6080
6081static void alc271_fixup_dmic(struct hda_codec *codec,
6082 const struct alc_fixup *fix, int action)
6083{
6084 static const struct hda_verb verbs[] = {
6085 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6086 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6087 {}
6088 };
6089 unsigned int cfg;
6090
6091 if (strcmp(codec->chip_name, "ALC271X"))
6092 return;
6093 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6094 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6095 snd_hda_sequence_write(codec, verbs);
6096}
6097
Takashi Iwai017f2a12011-07-09 14:42:25 +02006098static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6099 const struct alc_fixup *fix, int action)
6100{
6101 struct alc_spec *spec = codec->spec;
6102
6103 if (action != ALC_FIXUP_ACT_PROBE)
6104 return;
6105
6106 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6107 * fix the sample rate of analog I/O to 44.1kHz
6108 */
6109 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6110 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6111}
6112
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006113static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6114 const struct alc_fixup *fix, int action)
6115{
6116 int coef;
6117
6118 if (action != ALC_FIXUP_ACT_INIT)
6119 return;
6120 /* The digital-mic unit sends PDM (differential signal) instead of
6121 * the standard PCM, thus you can't record a valid mono stream as is.
6122 * Below is a workaround specific to ALC269 to control the dmic
6123 * signal source as mono.
6124 */
6125 coef = alc_read_coef_idx(codec, 0x07);
6126 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6127}
6128
Takashi Iwai24519912011-08-16 15:08:49 +02006129static void alc269_quanta_automute(struct hda_codec *codec)
6130{
David Henningsson42cf0d02011-09-20 12:04:56 +02006131 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006132
6133 snd_hda_codec_write(codec, 0x20, 0,
6134 AC_VERB_SET_COEF_INDEX, 0x0c);
6135 snd_hda_codec_write(codec, 0x20, 0,
6136 AC_VERB_SET_PROC_COEF, 0x680);
6137
6138 snd_hda_codec_write(codec, 0x20, 0,
6139 AC_VERB_SET_COEF_INDEX, 0x0c);
6140 snd_hda_codec_write(codec, 0x20, 0,
6141 AC_VERB_SET_PROC_COEF, 0x480);
6142}
6143
6144static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6145 const struct alc_fixup *fix, int action)
6146{
6147 struct alc_spec *spec = codec->spec;
6148 if (action != ALC_FIXUP_ACT_PROBE)
6149 return;
6150 spec->automute_hook = alc269_quanta_automute;
6151}
6152
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006153/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6154static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6155{
6156 struct hda_codec *codec = private_data;
6157 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6158 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6159 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6160}
6161
6162static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6163 const struct alc_fixup *fix, int action)
6164{
6165 struct alc_spec *spec = codec->spec;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01006166 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006167 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006168}
6169
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006170/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6171static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6172{
6173 struct hda_codec *codec = private_data;
6174 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006175 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006176}
6177
6178static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6179 const struct alc_fixup *fix, int action)
6180{
6181 struct alc_spec *spec = codec->spec;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01006182 if (action == ALC_FIXUP_ACT_PROBE)
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006183 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006184}
6185
Dylan Reid08a978d2012-11-18 22:56:40 -08006186static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6187 const struct alc_fixup *fix,
6188 int action)
6189{
6190 struct alc_spec *spec = codec->spec;
6191
6192 if (action == ALC_FIXUP_ACT_PROBE)
6193 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6194 spec->autocfg.hp_pins[0]);
6195}
David Henningsson693b6132012-06-22 19:12:10 +02006196
Takashi Iwai1d045db2011-07-07 18:23:21 +02006197enum {
6198 ALC269_FIXUP_SONY_VAIO,
6199 ALC275_FIXUP_SONY_VAIO_GPIO2,
6200 ALC269_FIXUP_DELL_M101Z,
6201 ALC269_FIXUP_SKU_IGNORE,
6202 ALC269_FIXUP_ASUS_G73JW,
6203 ALC269_FIXUP_LENOVO_EAPD,
6204 ALC275_FIXUP_SONY_HWEQ,
6205 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006206 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006207 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006208 ALC269_FIXUP_QUANTA_MUTE,
6209 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006210 ALC269_FIXUP_AMIC,
6211 ALC269_FIXUP_DMIC,
6212 ALC269VB_FIXUP_AMIC,
6213 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006214 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006215 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006216 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006217 ALC269_FIXUP_LENOVO_DOCK,
6218 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006219 ALC271_FIXUP_AMIC_MIC2,
6220 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006221};
6222
6223static const struct alc_fixup alc269_fixups[] = {
6224 [ALC269_FIXUP_SONY_VAIO] = {
6225 .type = ALC_FIXUP_VERBS,
6226 .v.verbs = (const struct hda_verb[]) {
6227 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6228 {}
6229 }
6230 },
6231 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6232 .type = ALC_FIXUP_VERBS,
6233 .v.verbs = (const struct hda_verb[]) {
6234 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6235 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6236 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6237 { }
6238 },
6239 .chained = true,
6240 .chain_id = ALC269_FIXUP_SONY_VAIO
6241 },
6242 [ALC269_FIXUP_DELL_M101Z] = {
6243 .type = ALC_FIXUP_VERBS,
6244 .v.verbs = (const struct hda_verb[]) {
6245 /* Enables internal speaker */
6246 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6247 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6248 {}
6249 }
6250 },
6251 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006252 .type = ALC_FIXUP_FUNC,
6253 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006254 },
6255 [ALC269_FIXUP_ASUS_G73JW] = {
6256 .type = ALC_FIXUP_PINS,
6257 .v.pins = (const struct alc_pincfg[]) {
6258 { 0x17, 0x99130111 }, /* subwoofer */
6259 { }
6260 }
6261 },
6262 [ALC269_FIXUP_LENOVO_EAPD] = {
6263 .type = ALC_FIXUP_VERBS,
6264 .v.verbs = (const struct hda_verb[]) {
6265 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6266 {}
6267 }
6268 },
6269 [ALC275_FIXUP_SONY_HWEQ] = {
6270 .type = ALC_FIXUP_FUNC,
6271 .v.func = alc269_fixup_hweq,
6272 .chained = true,
6273 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6274 },
6275 [ALC271_FIXUP_DMIC] = {
6276 .type = ALC_FIXUP_FUNC,
6277 .v.func = alc271_fixup_dmic,
6278 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006279 [ALC269_FIXUP_PCM_44K] = {
6280 .type = ALC_FIXUP_FUNC,
6281 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006282 .chained = true,
6283 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006284 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006285 [ALC269_FIXUP_STEREO_DMIC] = {
6286 .type = ALC_FIXUP_FUNC,
6287 .v.func = alc269_fixup_stereo_dmic,
6288 },
Takashi Iwai24519912011-08-16 15:08:49 +02006289 [ALC269_FIXUP_QUANTA_MUTE] = {
6290 .type = ALC_FIXUP_FUNC,
6291 .v.func = alc269_fixup_quanta_mute,
6292 },
6293 [ALC269_FIXUP_LIFEBOOK] = {
6294 .type = ALC_FIXUP_PINS,
6295 .v.pins = (const struct alc_pincfg[]) {
6296 { 0x1a, 0x2101103f }, /* dock line-out */
6297 { 0x1b, 0x23a11040 }, /* dock mic-in */
6298 { }
6299 },
6300 .chained = true,
6301 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6302 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006303 [ALC269_FIXUP_AMIC] = {
6304 .type = ALC_FIXUP_PINS,
6305 .v.pins = (const struct alc_pincfg[]) {
6306 { 0x14, 0x99130110 }, /* speaker */
6307 { 0x15, 0x0121401f }, /* HP out */
6308 { 0x18, 0x01a19c20 }, /* mic */
6309 { 0x19, 0x99a3092f }, /* int-mic */
6310 { }
6311 },
6312 },
6313 [ALC269_FIXUP_DMIC] = {
6314 .type = ALC_FIXUP_PINS,
6315 .v.pins = (const struct alc_pincfg[]) {
6316 { 0x12, 0x99a3092f }, /* int-mic */
6317 { 0x14, 0x99130110 }, /* speaker */
6318 { 0x15, 0x0121401f }, /* HP out */
6319 { 0x18, 0x01a19c20 }, /* mic */
6320 { }
6321 },
6322 },
6323 [ALC269VB_FIXUP_AMIC] = {
6324 .type = ALC_FIXUP_PINS,
6325 .v.pins = (const struct alc_pincfg[]) {
6326 { 0x14, 0x99130110 }, /* speaker */
6327 { 0x18, 0x01a19c20 }, /* mic */
6328 { 0x19, 0x99a3092f }, /* int-mic */
6329 { 0x21, 0x0121401f }, /* HP out */
6330 { }
6331 },
6332 },
David Henningsson2267ea92012-01-03 08:45:56 +01006333 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006334 .type = ALC_FIXUP_PINS,
6335 .v.pins = (const struct alc_pincfg[]) {
6336 { 0x12, 0x99a3092f }, /* int-mic */
6337 { 0x14, 0x99130110 }, /* speaker */
6338 { 0x18, 0x01a19c20 }, /* mic */
6339 { 0x21, 0x0121401f }, /* HP out */
6340 { }
6341 },
6342 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006343 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6344 .type = ALC_FIXUP_FUNC,
6345 .v.func = alc269_fixup_mic1_mute,
6346 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006347 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6348 .type = ALC_FIXUP_FUNC,
6349 .v.func = alc269_fixup_mic2_mute,
6350 },
David Henningsson693b6132012-06-22 19:12:10 +02006351 [ALC269_FIXUP_INV_DMIC] = {
6352 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006353 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006354 },
David Henningsson108cc102012-07-20 10:37:25 +02006355 [ALC269_FIXUP_LENOVO_DOCK] = {
6356 .type = ALC_FIXUP_PINS,
6357 .v.pins = (const struct alc_pincfg[]) {
6358 { 0x19, 0x23a11040 }, /* dock mic */
6359 { 0x1b, 0x2121103f }, /* dock headphone */
6360 { }
6361 },
6362 .chained = true,
6363 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6364 },
6365 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6366 .type = ALC_FIXUP_FUNC,
6367 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6368 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006369 [ALC271_FIXUP_AMIC_MIC2] = {
6370 .type = ALC_FIXUP_PINS,
6371 .v.pins = (const struct alc_pincfg[]) {
6372 { 0x14, 0x99130110 }, /* speaker */
6373 { 0x19, 0x01a19c20 }, /* mic */
6374 { 0x1b, 0x99a7012f }, /* int-mic */
6375 { 0x21, 0x0121401f }, /* HP out */
6376 { }
6377 },
6378 },
6379 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6380 .type = ALC_FIXUP_FUNC,
6381 .v.func = alc271_hp_gate_mic_jack,
6382 .chained = true,
6383 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6384 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006385};
6386
6387static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006388 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6389 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006390 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006391 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006392 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006393 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006394 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006395 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006396 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6397 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6398 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6399 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6400 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006401 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6402 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6403 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6404 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6405 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006406 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006407 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006408 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006409 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6410 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6411 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6412 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6413 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006414 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006415 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006416 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006417 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006418 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006419 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006420 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006421
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006422#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006423 /* Below is a quirk table taken from the old code.
6424 * Basically the device should work as is without the fixup table.
6425 * If BIOS doesn't give a proper info, enable the corresponding
6426 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006427 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006428 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6429 ALC269_FIXUP_AMIC),
6430 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006431 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6432 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6433 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6434 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6435 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6436 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6437 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6438 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6439 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6440 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6441 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6442 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6443 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6444 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6445 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6446 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6447 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6448 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6449 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6450 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6451 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6452 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6453 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6454 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6455 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6456 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6457 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6458 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6459 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6460 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6461 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6462 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6463 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6464 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6465 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6466 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6467 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6468 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6469#endif
6470 {}
6471};
6472
6473static const struct alc_model_fixup alc269_fixup_models[] = {
6474 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6475 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006476 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6477 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6478 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006479 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006480 {}
6481};
6482
6483
Takashi Iwai546bb672012-03-07 08:37:19 +01006484static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006485{
Kailang Yang526af6e2012-03-07 08:25:20 +01006486 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006487 int val;
6488
Kailang Yang526af6e2012-03-07 08:25:20 +01006489 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006490 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006491
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006492 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006493 alc_write_coef_idx(codec, 0xf, 0x960b);
6494 alc_write_coef_idx(codec, 0xe, 0x8817);
6495 }
6496
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006497 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006498 alc_write_coef_idx(codec, 0xf, 0x960b);
6499 alc_write_coef_idx(codec, 0xe, 0x8814);
6500 }
6501
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006502 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006503 val = alc_read_coef_idx(codec, 0x04);
6504 /* Power up output pin */
6505 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6506 }
6507
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006508 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006509 val = alc_read_coef_idx(codec, 0xd);
6510 if ((val & 0x0c00) >> 10 != 0x1) {
6511 /* Capless ramp up clock control */
6512 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6513 }
6514 val = alc_read_coef_idx(codec, 0x17);
6515 if ((val & 0x01c0) >> 6 != 0x4) {
6516 /* Class D power on reset */
6517 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6518 }
6519 }
6520
6521 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6522 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6523
6524 val = alc_read_coef_idx(codec, 0x4); /* HP */
6525 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006526}
6527
6528/*
6529 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006530static int patch_alc269(struct hda_codec *codec)
6531{
6532 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006533 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006534
Takashi Iwai3de95172012-05-07 18:03:15 +02006535 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006536 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006537 return err;
6538
6539 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01006540 spec->shared_mic_vref_pin = 0x18;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006541
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006542 alc_pick_fixup(codec, alc269_fixup_models,
6543 alc269_fixup_tbl, alc269_fixups);
6544 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6545
6546 alc_auto_parse_customize_define(codec);
6547
Kailang Yang065380f2013-01-10 10:25:48 +01006548 switch (codec->vendor_id) {
6549 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006550 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006551 switch (alc_get_coef0(codec) & 0x00f0) {
6552 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006553 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006554 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006555 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006556 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006557 break;
6558 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006559 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6560 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006561 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006562 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006563 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006564 case 0x0030:
6565 spec->codec_variant = ALC269_TYPE_ALC269VD;
6566 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006567 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006568 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006569 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006570 if (err < 0)
6571 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006572 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006573 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006574 break;
6575
6576 case 0x10ec0280:
6577 case 0x10ec0290:
6578 spec->codec_variant = ALC269_TYPE_ALC280;
6579 break;
6580 case 0x10ec0282:
6581 case 0x10ec0283:
6582 spec->codec_variant = ALC269_TYPE_ALC282;
6583 break;
6584 case 0x10ec0284:
6585 case 0x10ec0292:
6586 spec->codec_variant = ALC269_TYPE_ALC284;
6587 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006588 }
6589
Takashi Iwaia4297b52011-08-23 18:40:12 +02006590 /* automatic parse from the BIOS config */
6591 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006592 if (err < 0)
6593 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006594
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006595 if (!spec->no_analog && has_cdefine_beep(codec)) {
6596 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006597 if (err < 0)
6598 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006599 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006600 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006601
Takashi Iwai1d045db2011-07-07 18:23:21 +02006602 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006603#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006604 codec->patch_ops.resume = alc269_resume;
6605#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006606 spec->shutup = alc269_shutup;
6607
Takashi Iwai589876e2012-02-20 15:47:55 +01006608 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6609
Takashi Iwai1d045db2011-07-07 18:23:21 +02006610 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006611
6612 error:
6613 alc_free(codec);
6614 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006615}
6616
6617/*
6618 * ALC861
6619 */
6620
Takashi Iwai1d045db2011-07-07 18:23:21 +02006621static int alc861_parse_auto_config(struct hda_codec *codec)
6622{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006623 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006624 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6625 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006626}
6627
Takashi Iwai1d045db2011-07-07 18:23:21 +02006628/* Pin config fixes */
6629enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006630 ALC861_FIXUP_FSC_AMILO_PI1505,
6631 ALC861_FIXUP_AMP_VREF_0F,
6632 ALC861_FIXUP_NO_JACK_DETECT,
6633 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006634};
6635
Takashi Iwai31150f22012-01-30 10:54:08 +01006636/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6637static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6638 const struct alc_fixup *fix, int action)
6639{
6640 struct alc_spec *spec = codec->spec;
6641 unsigned int val;
6642
6643 if (action != ALC_FIXUP_ACT_INIT)
6644 return;
6645 val = snd_hda_codec_read(codec, 0x0f, 0,
6646 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6647 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6648 val |= AC_PINCTL_IN_EN;
6649 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006650 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006651 spec->keep_vref_in_automute = 1;
6652}
6653
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006654/* suppress the jack-detection */
6655static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6656 const struct alc_fixup *fix, int action)
6657{
6658 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6659 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006660}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006661
Takashi Iwai1d045db2011-07-07 18:23:21 +02006662static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006663 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006664 .type = ALC_FIXUP_PINS,
6665 .v.pins = (const struct alc_pincfg[]) {
6666 { 0x0b, 0x0221101f }, /* HP */
6667 { 0x0f, 0x90170310 }, /* speaker */
6668 { }
6669 }
6670 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006671 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006672 .type = ALC_FIXUP_FUNC,
6673 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006674 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006675 [ALC861_FIXUP_NO_JACK_DETECT] = {
6676 .type = ALC_FIXUP_FUNC,
6677 .v.func = alc_fixup_no_jack_detect,
6678 },
6679 [ALC861_FIXUP_ASUS_A6RP] = {
6680 .type = ALC_FIXUP_FUNC,
6681 .v.func = alc861_fixup_asus_amp_vref_0f,
6682 .chained = true,
6683 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6684 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006685};
6686
6687static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006688 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6689 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6690 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6691 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6692 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6693 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006694 {}
6695};
6696
6697/*
6698 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006699static int patch_alc861(struct hda_codec *codec)
6700{
6701 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006702 int err;
6703
Takashi Iwai3de95172012-05-07 18:03:15 +02006704 err = alc_alloc_spec(codec, 0x15);
6705 if (err < 0)
6706 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006707
Takashi Iwai3de95172012-05-07 18:03:15 +02006708 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006709
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006710 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6711 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006712
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006713 /* automatic parse from the BIOS config */
6714 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006715 if (err < 0)
6716 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006717
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006718 if (!spec->no_analog) {
6719 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006720 if (err < 0)
6721 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006722 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6723 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006724
Takashi Iwai1d045db2011-07-07 18:23:21 +02006725 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006726#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006727 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006728#endif
6729
Takashi Iwai589876e2012-02-20 15:47:55 +01006730 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6731
Takashi Iwai1d045db2011-07-07 18:23:21 +02006732 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006733
6734 error:
6735 alc_free(codec);
6736 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006737}
6738
6739/*
6740 * ALC861-VD support
6741 *
6742 * Based on ALC882
6743 *
6744 * In addition, an independent DAC
6745 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006746static int alc861vd_parse_auto_config(struct hda_codec *codec)
6747{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006748 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006749 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6750 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006751}
6752
Takashi Iwai1d045db2011-07-07 18:23:21 +02006753enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006754 ALC660VD_FIX_ASUS_GPIO1,
6755 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006756};
6757
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006758/* exclude VREF80 */
6759static void alc861vd_fixup_dallas(struct hda_codec *codec,
6760 const struct alc_fixup *fix, int action)
6761{
6762 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006763 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6764 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006765 }
6766}
6767
Takashi Iwai1d045db2011-07-07 18:23:21 +02006768static const struct alc_fixup alc861vd_fixups[] = {
6769 [ALC660VD_FIX_ASUS_GPIO1] = {
6770 .type = ALC_FIXUP_VERBS,
6771 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006772 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006773 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6774 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6775 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6776 { }
6777 }
6778 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006779 [ALC861VD_FIX_DALLAS] = {
6780 .type = ALC_FIXUP_FUNC,
6781 .v.func = alc861vd_fixup_dallas,
6782 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006783};
6784
6785static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006786 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006787 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006788 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006789 {}
6790};
6791
Takashi Iwai1d045db2011-07-07 18:23:21 +02006792/*
6793 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006794static int patch_alc861vd(struct hda_codec *codec)
6795{
6796 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006797 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006798
Takashi Iwai3de95172012-05-07 18:03:15 +02006799 err = alc_alloc_spec(codec, 0x0b);
6800 if (err < 0)
6801 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006802
Takashi Iwai3de95172012-05-07 18:03:15 +02006803 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006804
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006805 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6806 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006807
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006808 /* automatic parse from the BIOS config */
6809 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006810 if (err < 0)
6811 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006812
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006813 if (!spec->no_analog) {
6814 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006815 if (err < 0)
6816 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006817 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6818 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006819
Takashi Iwai1d045db2011-07-07 18:23:21 +02006820 codec->patch_ops = alc_patch_ops;
6821
Takashi Iwai1d045db2011-07-07 18:23:21 +02006822 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006823
Takashi Iwai589876e2012-02-20 15:47:55 +01006824 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6825
Takashi Iwai1d045db2011-07-07 18:23:21 +02006826 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006827
6828 error:
6829 alc_free(codec);
6830 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006831}
6832
6833/*
6834 * ALC662 support
6835 *
6836 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6837 * configuration. Each pin widget can choose any input DACs and a mixer.
6838 * Each ADC is connected from a mixer of all inputs. This makes possible
6839 * 6-channel independent captures.
6840 *
6841 * In addition, an independent DAC for the multi-playback (not used in this
6842 * driver yet).
6843 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006844
6845/*
6846 * BIOS auto configuration
6847 */
6848
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006849static int alc662_parse_auto_config(struct hda_codec *codec)
6850{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006851 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006852 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6853 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6854 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006855
Kailang Yang6227cdc2010-02-25 08:36:52 +01006856 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6857 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006858 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006859 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006860 ssids = alc662_ssids;
6861 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006862}
6863
Todd Broch6be79482010-12-07 16:51:05 -08006864static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006865 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006866{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006867 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006868 return;
Todd Broch6be79482010-12-07 16:51:05 -08006869 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6870 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6871 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6872 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6873 (0 << AC_AMPCAP_MUTE_SHIFT)))
6874 printk(KERN_WARNING
6875 "hda_codec: failed to override amp caps for NID 0x2\n");
6876}
6877
David Henningsson6cb3b702010-09-09 08:51:44 +02006878enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006879 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006880 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006881 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006882 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006883 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006884 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006885 ALC662_FIXUP_ASUS_MODE1,
6886 ALC662_FIXUP_ASUS_MODE2,
6887 ALC662_FIXUP_ASUS_MODE3,
6888 ALC662_FIXUP_ASUS_MODE4,
6889 ALC662_FIXUP_ASUS_MODE5,
6890 ALC662_FIXUP_ASUS_MODE6,
6891 ALC662_FIXUP_ASUS_MODE7,
6892 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006893 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006894 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006895 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006896};
6897
6898static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006899 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006900 .type = ALC_FIXUP_PINS,
6901 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006902 { 0x15, 0x99130112 }, /* subwoofer */
6903 { }
6904 }
6905 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006906 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006907 .type = ALC_FIXUP_PINS,
6908 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006909 { 0x17, 0x99130112 }, /* subwoofer */
6910 { }
6911 }
6912 },
Todd Broch6be79482010-12-07 16:51:05 -08006913 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006914 .type = ALC_FIXUP_FUNC,
6915 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006916 },
6917 [ALC662_FIXUP_CZC_P10T] = {
6918 .type = ALC_FIXUP_VERBS,
6919 .v.verbs = (const struct hda_verb[]) {
6920 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6921 {}
6922 }
6923 },
David Henningsson94024cd2011-04-29 14:10:55 +02006924 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006925 .type = ALC_FIXUP_FUNC,
6926 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006927 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006928 [ALC662_FIXUP_HP_RP5800] = {
6929 .type = ALC_FIXUP_PINS,
6930 .v.pins = (const struct alc_pincfg[]) {
6931 { 0x14, 0x0221201f }, /* HP out */
6932 { }
6933 },
6934 .chained = true,
6935 .chain_id = ALC662_FIXUP_SKU_IGNORE
6936 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006937 [ALC662_FIXUP_ASUS_MODE1] = {
6938 .type = ALC_FIXUP_PINS,
6939 .v.pins = (const struct alc_pincfg[]) {
6940 { 0x14, 0x99130110 }, /* speaker */
6941 { 0x18, 0x01a19c20 }, /* mic */
6942 { 0x19, 0x99a3092f }, /* int-mic */
6943 { 0x21, 0x0121401f }, /* HP out */
6944 { }
6945 },
6946 .chained = true,
6947 .chain_id = ALC662_FIXUP_SKU_IGNORE
6948 },
6949 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006950 .type = ALC_FIXUP_PINS,
6951 .v.pins = (const struct alc_pincfg[]) {
6952 { 0x14, 0x99130110 }, /* speaker */
6953 { 0x18, 0x01a19820 }, /* mic */
6954 { 0x19, 0x99a3092f }, /* int-mic */
6955 { 0x1b, 0x0121401f }, /* HP out */
6956 { }
6957 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006958 .chained = true,
6959 .chain_id = ALC662_FIXUP_SKU_IGNORE
6960 },
6961 [ALC662_FIXUP_ASUS_MODE3] = {
6962 .type = ALC_FIXUP_PINS,
6963 .v.pins = (const struct alc_pincfg[]) {
6964 { 0x14, 0x99130110 }, /* speaker */
6965 { 0x15, 0x0121441f }, /* HP */
6966 { 0x18, 0x01a19840 }, /* mic */
6967 { 0x19, 0x99a3094f }, /* int-mic */
6968 { 0x21, 0x01211420 }, /* HP2 */
6969 { }
6970 },
6971 .chained = true,
6972 .chain_id = ALC662_FIXUP_SKU_IGNORE
6973 },
6974 [ALC662_FIXUP_ASUS_MODE4] = {
6975 .type = ALC_FIXUP_PINS,
6976 .v.pins = (const struct alc_pincfg[]) {
6977 { 0x14, 0x99130110 }, /* speaker */
6978 { 0x16, 0x99130111 }, /* speaker */
6979 { 0x18, 0x01a19840 }, /* mic */
6980 { 0x19, 0x99a3094f }, /* int-mic */
6981 { 0x21, 0x0121441f }, /* HP */
6982 { }
6983 },
6984 .chained = true,
6985 .chain_id = ALC662_FIXUP_SKU_IGNORE
6986 },
6987 [ALC662_FIXUP_ASUS_MODE5] = {
6988 .type = ALC_FIXUP_PINS,
6989 .v.pins = (const struct alc_pincfg[]) {
6990 { 0x14, 0x99130110 }, /* speaker */
6991 { 0x15, 0x0121441f }, /* HP */
6992 { 0x16, 0x99130111 }, /* speaker */
6993 { 0x18, 0x01a19840 }, /* mic */
6994 { 0x19, 0x99a3094f }, /* int-mic */
6995 { }
6996 },
6997 .chained = true,
6998 .chain_id = ALC662_FIXUP_SKU_IGNORE
6999 },
7000 [ALC662_FIXUP_ASUS_MODE6] = {
7001 .type = ALC_FIXUP_PINS,
7002 .v.pins = (const struct alc_pincfg[]) {
7003 { 0x14, 0x99130110 }, /* speaker */
7004 { 0x15, 0x01211420 }, /* HP2 */
7005 { 0x18, 0x01a19840 }, /* mic */
7006 { 0x19, 0x99a3094f }, /* int-mic */
7007 { 0x1b, 0x0121441f }, /* HP */
7008 { }
7009 },
7010 .chained = true,
7011 .chain_id = ALC662_FIXUP_SKU_IGNORE
7012 },
7013 [ALC662_FIXUP_ASUS_MODE7] = {
7014 .type = ALC_FIXUP_PINS,
7015 .v.pins = (const struct alc_pincfg[]) {
7016 { 0x14, 0x99130110 }, /* speaker */
7017 { 0x17, 0x99130111 }, /* speaker */
7018 { 0x18, 0x01a19840 }, /* mic */
7019 { 0x19, 0x99a3094f }, /* int-mic */
7020 { 0x1b, 0x01214020 }, /* HP */
7021 { 0x21, 0x0121401f }, /* HP */
7022 { }
7023 },
7024 .chained = true,
7025 .chain_id = ALC662_FIXUP_SKU_IGNORE
7026 },
7027 [ALC662_FIXUP_ASUS_MODE8] = {
7028 .type = ALC_FIXUP_PINS,
7029 .v.pins = (const struct alc_pincfg[]) {
7030 { 0x14, 0x99130110 }, /* speaker */
7031 { 0x12, 0x99a30970 }, /* int-mic */
7032 { 0x15, 0x01214020 }, /* HP */
7033 { 0x17, 0x99130111 }, /* speaker */
7034 { 0x18, 0x01a19840 }, /* mic */
7035 { 0x21, 0x0121401f }, /* HP */
7036 { }
7037 },
7038 .chained = true,
7039 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007040 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007041 [ALC662_FIXUP_NO_JACK_DETECT] = {
7042 .type = ALC_FIXUP_FUNC,
7043 .v.func = alc_fixup_no_jack_detect,
7044 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007045 [ALC662_FIXUP_ZOTAC_Z68] = {
7046 .type = ALC_FIXUP_PINS,
7047 .v.pins = (const struct alc_pincfg[]) {
7048 { 0x1b, 0x02214020 }, /* Front HP */
7049 { }
7050 }
7051 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007052 [ALC662_FIXUP_INV_DMIC] = {
7053 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007054 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007055 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007056};
7057
Takashi Iwaia9111322011-05-02 11:30:18 +02007058static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007059 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007060 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007061 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007062 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007063 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007064 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007065 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007066 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007067 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007068 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007069 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007070 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007071 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007072
7073#if 0
7074 /* Below is a quirk table taken from the old code.
7075 * Basically the device should work as is without the fixup table.
7076 * If BIOS doesn't give a proper info, enable the corresponding
7077 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007078 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007079 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7080 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7081 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7082 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7083 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7084 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7085 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7086 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7087 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7088 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7089 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7090 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7091 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7092 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7093 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7094 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7095 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7096 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7097 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7098 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7099 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7100 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7101 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7102 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7103 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7104 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7105 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7106 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7107 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7108 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7109 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7110 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7111 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7112 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7113 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7114 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7115 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7116 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7117 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7118 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7119 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7120 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7121 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7122 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7123 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7124 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7125 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7126 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7127 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7128 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7129#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007130 {}
7131};
7132
Todd Broch6be79482010-12-07 16:51:05 -08007133static const struct alc_model_fixup alc662_fixup_models[] = {
7134 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007135 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7136 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7137 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7138 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7139 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7140 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7141 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7142 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007143 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007144 {}
7145};
David Henningsson6cb3b702010-09-09 08:51:44 +02007146
Kailang Yang8663ff72012-06-29 09:35:52 +02007147static void alc662_fill_coef(struct hda_codec *codec)
7148{
7149 int val, coef;
7150
7151 coef = alc_get_coef0(codec);
7152
7153 switch (codec->vendor_id) {
7154 case 0x10ec0662:
7155 if ((coef & 0x00f0) == 0x0030) {
7156 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7157 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7158 }
7159 break;
7160 case 0x10ec0272:
7161 case 0x10ec0273:
7162 case 0x10ec0663:
7163 case 0x10ec0665:
7164 case 0x10ec0670:
7165 case 0x10ec0671:
7166 case 0x10ec0672:
7167 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7168 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7169 break;
7170 }
7171}
David Henningsson6cb3b702010-09-09 08:51:44 +02007172
Takashi Iwai1d045db2011-07-07 18:23:21 +02007173/*
7174 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007175static int patch_alc662(struct hda_codec *codec)
7176{
7177 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007178 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007179
Takashi Iwai3de95172012-05-07 18:03:15 +02007180 err = alc_alloc_spec(codec, 0x0b);
7181 if (err < 0)
7182 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007183
Takashi Iwai3de95172012-05-07 18:03:15 +02007184 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007185
Takashi Iwai53c334a2011-08-23 18:27:14 +02007186 /* handle multiple HPs as is */
7187 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7188
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007189 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7190
Kailang Yang8663ff72012-06-29 09:35:52 +02007191 spec->init_hook = alc662_fill_coef;
7192 alc662_fill_coef(codec);
7193
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007194 alc_pick_fixup(codec, alc662_fixup_models,
7195 alc662_fixup_tbl, alc662_fixups);
7196 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7197
7198 alc_auto_parse_customize_define(codec);
7199
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007200 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007201 codec->bus->pci->subsystem_vendor == 0x1025 &&
7202 spec->cdefine.platform_type == 1) {
7203 if (alc_codec_rename(codec, "ALC272X") < 0)
7204 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007205 }
Kailang Yang274693f2009-12-03 10:07:50 +01007206
Takashi Iwaib9c51062011-08-24 18:08:07 +02007207 /* automatic parse from the BIOS config */
7208 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007209 if (err < 0)
7210 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007211
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007212 if (!spec->no_analog && has_cdefine_beep(codec)) {
7213 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007214 if (err < 0)
7215 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007216 switch (codec->vendor_id) {
7217 case 0x10ec0662:
7218 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7219 break;
7220 case 0x10ec0272:
7221 case 0x10ec0663:
7222 case 0x10ec0665:
7223 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7224 break;
7225 case 0x10ec0273:
7226 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7227 break;
7228 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007229 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007230
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007231 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007232 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007233
Takashi Iwai589876e2012-02-20 15:47:55 +01007234 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7235
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007236 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007237
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007238 error:
7239 alc_free(codec);
7240 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007241}
7242
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007243/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007244 * ALC680 support
7245 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007246
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007247static int alc680_parse_auto_config(struct hda_codec *codec)
7248{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007249 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007250}
7251
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007252/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007253 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007254static int patch_alc680(struct hda_codec *codec)
7255{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007256 int err;
7257
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007258 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007259 err = alc_alloc_spec(codec, 0);
7260 if (err < 0)
7261 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007262
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007263 /* automatic parse from the BIOS config */
7264 err = alc680_parse_auto_config(codec);
7265 if (err < 0) {
7266 alc_free(codec);
7267 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007268 }
7269
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007270 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007271
7272 return 0;
7273}
7274
7275/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007276 * patch entries
7277 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007278static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007279 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007280 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007281 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007282 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007283 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007284 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007285 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007286 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007287 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007288 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007289 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007290 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007291 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007292 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007293 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007294 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007295 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007296 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007297 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7298 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7299 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007300 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007301 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007302 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7303 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007304 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7305 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007306 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007307 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007308 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007309 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007310 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007311 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007312 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007313 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007314 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007315 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007316 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007317 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007318 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007319 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007320 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007321 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007322 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007323 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007324 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007325 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007326 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007327 {} /* terminator */
7328};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007329
7330MODULE_ALIAS("snd-hda-codec-id:10ec*");
7331
7332MODULE_LICENSE("GPL");
7333MODULE_DESCRIPTION("Realtek HD-audio codec");
7334
7335static struct hda_codec_preset_list realtek_list = {
7336 .preset = snd_hda_preset_realtek,
7337 .owner = THIS_MODULE,
7338};
7339
7340static int __init patch_realtek_init(void)
7341{
7342 return snd_hda_add_codec_preset(&realtek_list);
7343}
7344
7345static void __exit patch_realtek_exit(void)
7346{
7347 snd_hda_delete_codec_preset(&realtek_list);
7348}
7349
7350module_init(patch_realtek_init)
7351module_exit(patch_realtek_exit)