blob: 13d4548a538139219b9398e7ada5225ce736811a [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 Iwai834be882006-03-01 14:16:17 +0100187
Takashi Iwai463419d2012-12-05 14:17:37 +0100188 /* DAC list */
189 int num_all_dacs;
190 hda_nid_t all_dacs[16];
191
Takashi Iwaic9967f12012-12-14 16:39:22 +0100192 /* path list */
193 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100194
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100195 /* hooks */
196 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200197#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500198 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100199#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200200 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200201 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100202
Takashi Iwai834be882006-03-01 14:16:17 +0100203 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200204 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200205 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200206 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200207 unsigned int auto_mic:1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200208 unsigned int automute_speaker:1; /* automute speaker outputs */
209 unsigned int automute_lo:1; /* automute LO outputs */
210 unsigned int detect_hp:1; /* Headphone detection enabled */
211 unsigned int detect_lo:1; /* Line-out detection enabled */
212 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
213 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100214 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200215
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100216 /* other flags */
Takashi Iwai20c18f52012-12-18 14:33:21 +0100217 unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100218 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200219 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai24de1832011-11-07 17:13:39 +0100220 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200221 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
222 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200223 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200224
Takashi Iwai20c18f52012-12-18 14:33:21 +0100225 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwaid922b512011-04-28 12:18:53 +0200226
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200227 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200228 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100229
Takashi Iwai2134ea42008-01-10 16:53:55 +0100230 /* for virtual master */
231 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100232 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200233#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200234 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100235 int num_loopbacks;
236 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200237#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200238
239 /* for PLL fix */
240 hda_nid_t pll_nid;
241 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200242 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100243
Takashi Iwaice764ab2011-04-27 16:35:23 +0200244 /* multi-io */
245 int multi_ios;
246 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200247
248 /* bind volumes */
249 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100250};
251
Takashi Iwai44c02402011-07-08 15:14:19 +0200252static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
253 int dir, unsigned int bits)
254{
255 if (!nid)
256 return false;
257 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
258 if (query_amp_caps(codec, nid, dir) & bits)
259 return true;
260 return false;
261}
262
263#define nid_has_mute(codec, nid, dir) \
264 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
265#define nid_has_volume(codec, nid, dir) \
266 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
267
Takashi Iwai666a70d2012-12-17 20:29:29 +0100268static struct nid_path *
269get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid);
270static void activate_path(struct hda_codec *codec, struct nid_path *path,
271 bool enable, bool add_aamix);
272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273/*
274 * input MUX handling
275 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200276static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
277 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
280 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +0100281 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200284static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
285 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
288 struct alc_spec *spec = codec->spec;
289 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
290
291 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
292 return 0;
293}
294
Takashi Iwai666a70d2012-12-17 20:29:29 +0100295static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
296{
297 struct alc_spec *spec = codec->spec;
298 if (spec->dyn_adc_switch)
299 adc_idx = spec->dyn_adc_idx[imux_idx];
300 return spec->adc_nids[adc_idx];
301}
302
Takashi Iwai21268962011-07-07 15:01:13 +0200303static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Takashi Iwai21268962011-07-07 15:01:13 +0200305 struct alc_spec *spec = codec->spec;
306 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
307
308 if (spec->cur_adc && spec->cur_adc != new_adc) {
309 /* stream is running, let's swap the current ADC */
310 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
311 spec->cur_adc = new_adc;
312 snd_hda_codec_setup_stream(codec, new_adc,
313 spec->cur_adc_stream_tag, 0,
314 spec->cur_adc_format);
315 return true;
316 }
317 return false;
318}
319
Takashi Iwai24de1832011-11-07 17:13:39 +0100320static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200321static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100322static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx);
Takashi Iwai24de1832011-11-07 17:13:39 +0100323
David Henningsson00227f12012-06-27 18:45:44 +0200324/* for shared I/O, change the pin-control accordingly */
325static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
326{
327 struct alc_spec *spec = codec->spec;
328 unsigned int val;
329 hda_nid_t pin = spec->autocfg.inputs[1].pin;
330 /* NOTE: this assumes that there are only two inputs, the
331 * first is the real internal mic and the second is HP/mic jack.
332 */
333
334 val = snd_hda_get_default_vref(codec, pin);
335
336 /* This pin does not have vref caps - let's enable vref on pin 0x18
337 instead, as suggested by Realtek */
Takashi Iwai37c04202012-12-18 14:22:45 +0100338 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
339 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
340 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
341 if (vref_val != AC_PINCTL_VREF_HIZ)
342 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
David Henningsson00227f12012-06-27 18:45:44 +0200343 }
344
345 val = set_as_mic ? val | PIN_IN : PIN_HP;
346 snd_hda_set_pin_ctl(codec, pin, val);
347
348 spec->automute_speaker = !set_as_mic;
349 call_update_outputs(codec);
350}
Takashi Iwai21268962011-07-07 15:01:13 +0200351
352/* select the given imux item; either unmute exclusively or select the route */
353static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
354 unsigned int idx, bool force)
355{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100357 const struct hda_input_mux *imux;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100358 struct nid_path *path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Takashi Iwai27d31532012-12-18 08:57:05 +0100360 imux = &spec->input_mux;
361 if (!imux->num_items)
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100362 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100363
Takashi Iwai21268962011-07-07 15:01:13 +0200364 if (idx >= imux->num_items)
365 idx = imux->num_items - 1;
366 if (spec->cur_mux[adc_idx] == idx && !force)
367 return 0;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100368
369 path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]],
370 spec->adc_nids[adc_idx]);
371 if (!path)
372 return 0;
373 if (path->active)
374 activate_path(codec, path, false, false);
375
Takashi Iwai21268962011-07-07 15:01:13 +0200376 spec->cur_mux[adc_idx] = idx;
377
David Henningsson00227f12012-06-27 18:45:44 +0200378 if (spec->shared_mic_hp)
379 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100380
Takashi Iwai666a70d2012-12-17 20:29:29 +0100381 if (spec->dyn_adc_switch)
Takashi Iwai21268962011-07-07 15:01:13 +0200382 alc_dyn_adc_pcm_resetup(codec, idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200383
Takashi Iwai666a70d2012-12-17 20:29:29 +0100384 path = get_nid_path(codec, spec->imux_pins[idx],
385 get_adc_nid(codec, adc_idx, idx));
386 if (!path)
387 return 0;
388 if (path->active)
389 return 0;
390 activate_path(codec, path, true, false);
Takashi Iwai125821a2012-06-22 14:30:29 +0200391 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200392 return 1;
393}
394
395static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
396 struct snd_ctl_elem_value *ucontrol)
397{
398 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
399 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
400 return alc_mux_select(codec, adc_idx,
401 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100402}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100405 * set up the input pin config (depending on the given auto-pin type)
406 */
407static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
408 int auto_pin_type)
409{
410 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200411 if (auto_pin_type == AUTO_PIN_MIC)
412 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200413 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100414}
415
416/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200417 * Append the given mixer and verb elements for the later use
418 * The mixer array is referred in build_controls(), and init_verbs are
419 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100420 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200421static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100422{
423 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
424 return;
425 spec->mixers[spec->num_mixers++] = mix;
426}
427
Takashi Iwaid88897e2008-10-31 15:01:37 +0100428/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200429 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100430 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200431/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200432static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200433 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
434 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
435 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
436 { }
437};
438
Takashi Iwaia9111322011-05-02 11:30:18 +0200439static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200440 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
441 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
442 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
443 { }
444};
445
Takashi Iwaia9111322011-05-02 11:30:18 +0200446static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200447 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
448 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
449 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
450 { }
451};
452
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200453/*
454 * Fix hardware PLL issue
455 * On some codecs, the analog PLL gating control must be off while
456 * the default value is 1.
457 */
458static void alc_fix_pll(struct hda_codec *codec)
459{
460 struct alc_spec *spec = codec->spec;
461 unsigned int val;
462
463 if (!spec->pll_nid)
464 return;
465 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
466 spec->pll_coef_idx);
467 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
468 AC_VERB_GET_PROC_COEF, 0);
469 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
470 spec->pll_coef_idx);
471 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
472 val & ~(1 << spec->pll_coef_bit));
473}
474
475static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
476 unsigned int coef_idx, unsigned int coef_bit)
477{
478 struct alc_spec *spec = codec->spec;
479 spec->pll_nid = nid;
480 spec->pll_coef_idx = coef_idx;
481 spec->pll_coef_bit = coef_bit;
482 alc_fix_pll(codec);
483}
484
Takashi Iwai1d045db2011-07-07 18:23:21 +0200485/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200486 * Jack detections for HP auto-mute and mic-switch
487 */
488
489/* check each pin in the given array; returns true if any of them is plugged */
490static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200491{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200492 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200493
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200494 for (i = 0; i < num_pins; i++) {
495 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200496 if (!nid)
497 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200498 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200499 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200500 return present;
501}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200502
Takashi Iwai1d045db2011-07-07 18:23:21 +0200503/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200504static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200505 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200506{
507 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200508 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200509 int i;
510
511 for (i = 0; i < num_pins; i++) {
512 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100513 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200514 if (!nid)
515 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100516 /* don't reset VREF value in case it's controlling
517 * the amp (see alc861_fixup_asus_amp_vref_0f())
518 */
519 if (spec->keep_vref_in_automute) {
520 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100521 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100522 val &= ~PIN_HP;
523 } else
524 val = 0;
525 val |= pin_bits;
526 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200527 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200528}
529
David Henningsson42cf0d02011-09-20 12:04:56 +0200530/* Toggle outputs muting */
531static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532{
533 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200534 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200535
Takashi Iwaic0a20262011-06-10 15:28:15 +0200536 /* Control HP pins/amps depending on master_mute state;
537 * in general, HP pins/amps control should be enabled in all cases,
538 * but currently set only for master_mute, just to be safe
539 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100540 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
541 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200542 spec->autocfg.hp_pins, spec->master_mute, true);
543
David Henningsson42cf0d02011-09-20 12:04:56 +0200544 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200545 on = 0;
546 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200547 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200548 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200549 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200550 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200551
552 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200553 /* if LO is a copy of either HP or Speaker, don't need to handle it */
554 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
555 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200557 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200558 on = 0;
559 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200560 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200561 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200562 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200563 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200564}
565
David Henningsson42cf0d02011-09-20 12:04:56 +0200566static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200567{
568 struct alc_spec *spec = codec->spec;
569 if (spec->automute_hook)
570 spec->automute_hook(codec);
571 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200572 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200573}
574
Takashi Iwai1d045db2011-07-07 18:23:21 +0200575/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200576static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577{
578 struct alc_spec *spec = codec->spec;
579
David Henningsson42cf0d02011-09-20 12:04:56 +0200580 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200581 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
582 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200583 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200584 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200585 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200586}
587
Takashi Iwai1d045db2011-07-07 18:23:21 +0200588/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200589static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590{
591 struct alc_spec *spec = codec->spec;
592
David Henningssonf7f4b2322012-10-10 16:32:09 +0200593 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
594 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200595 /* check LO jack only when it's different from HP */
596 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
597 return;
598
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200599 spec->line_jack_present =
600 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
601 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200602 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200603 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200604 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200605}
606
Takashi Iwai1d045db2011-07-07 18:23:21 +0200607/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200608static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200609{
610 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200611 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200612
Takashi Iwai480967d2012-12-18 14:29:52 +0100613 if (!spec->auto_mic)
Takashi Iwai6c819492009-08-10 18:47:44 +0200614 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200615 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200616 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200617
Takashi Iwai21268962011-07-07 15:01:13 +0200618 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
619 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
620 else if (spec->dock_mic_idx >= 0 &&
621 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
622 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
623 else
624 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200625}
626
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100627/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200628static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100629{
630 unsigned int val;
631 struct snd_kcontrol *kctl;
632 struct snd_ctl_elem_value *uctl;
633
634 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
635 if (!kctl)
636 return;
637 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
638 if (!uctl)
639 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200640 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100641 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
642 val &= HDA_AMP_VOLMASK;
643 uctl->value.integer.value[0] = val;
644 uctl->value.integer.value[1] = val;
645 kctl->put(kctl, uctl);
646 kfree(uctl);
647}
648
David Henningsson29adc4b2012-09-25 11:31:00 +0200649static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100650{
David Henningsson29adc4b2012-09-25 11:31:00 +0200651 /* For some reason, the res given from ALC880 is broken.
652 Here we adjust it properly. */
653 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100654}
655
Kailang Yangf9423e72008-05-27 12:32:25 +0200656/* additional initialization for ALC888 variants */
657static void alc888_coef_init(struct hda_codec *codec)
658{
659 unsigned int tmp;
660
661 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
662 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
663 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100664 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200665 /* alc888S-VC */
666 snd_hda_codec_read(codec, 0x20, 0,
667 AC_VERB_SET_PROC_COEF, 0x830);
668 else
669 /* alc888-VB */
670 snd_hda_codec_read(codec, 0x20, 0,
671 AC_VERB_SET_PROC_COEF, 0x3030);
672}
673
Takashi Iwai1d045db2011-07-07 18:23:21 +0200674/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200675static void alc889_coef_init(struct hda_codec *codec)
676{
677 unsigned int tmp;
678
679 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
680 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
681 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
682 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
683}
684
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100685/* turn on/off EAPD control (only if available) */
686static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
687{
688 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
689 return;
690 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
691 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
692 on ? 2 : 0);
693}
694
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200695/* turn on/off EAPD controls of the codec */
696static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
697{
698 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200699 static hda_nid_t pins[] = {
700 0x0f, 0x10, 0x14, 0x15, 0
701 };
702 hda_nid_t *p;
703 for (p = pins; *p; p++)
704 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200705}
706
Takashi Iwai1c716152011-04-07 10:37:16 +0200707/* generic shutup callback;
708 * just turning off EPAD and a little pause for avoiding pop-noise
709 */
710static void alc_eapd_shutup(struct hda_codec *codec)
711{
712 alc_auto_setup_eapd(codec, false);
713 msleep(200);
714}
715
Takashi Iwai1d045db2011-07-07 18:23:21 +0200716/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200717static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200718{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200719 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200720
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200721 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200722 switch (type) {
723 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200724 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
725 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200726 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200727 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
728 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200729 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200730 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
731 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200732 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200733 switch (codec->vendor_id) {
734 case 0x10ec0260:
735 snd_hda_codec_write(codec, 0x1a, 0,
736 AC_VERB_SET_COEF_INDEX, 7);
737 tmp = snd_hda_codec_read(codec, 0x1a, 0,
738 AC_VERB_GET_PROC_COEF, 0);
739 snd_hda_codec_write(codec, 0x1a, 0,
740 AC_VERB_SET_COEF_INDEX, 7);
741 snd_hda_codec_write(codec, 0x1a, 0,
742 AC_VERB_SET_PROC_COEF,
743 tmp | 0x2010);
744 break;
745 case 0x10ec0262:
746 case 0x10ec0880:
747 case 0x10ec0882:
748 case 0x10ec0883:
749 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100750 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100751 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200752 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200753 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200754 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200755 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200756 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100757#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200758 case 0x10ec0267:
759 case 0x10ec0268:
760 snd_hda_codec_write(codec, 0x20, 0,
761 AC_VERB_SET_COEF_INDEX, 7);
762 tmp = snd_hda_codec_read(codec, 0x20, 0,
763 AC_VERB_GET_PROC_COEF, 0);
764 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200765 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200766 snd_hda_codec_write(codec, 0x20, 0,
767 AC_VERB_SET_PROC_COEF,
768 tmp | 0x3000);
769 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100770#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200771 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200772 break;
773 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200774}
Kailang Yangea1fb292008-08-26 12:58:38 +0200775
Takashi Iwai1d045db2011-07-07 18:23:21 +0200776/*
777 * Auto-Mute mode mixer enum support
778 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200779static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
780 struct snd_ctl_elem_info *uinfo)
781{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200782 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
783 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200784 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100785 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200786 };
787
Takashi Iwaidda415d2012-11-30 18:34:38 +0100788 if (spec->automute_speaker_possible && spec->automute_lo_possible)
789 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
790 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200791}
792
793static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
794 struct snd_ctl_elem_value *ucontrol)
795{
796 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
797 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200798 unsigned int val = 0;
799 if (spec->automute_speaker)
800 val++;
801 if (spec->automute_lo)
802 val++;
803
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200804 ucontrol->value.enumerated.item[0] = val;
805 return 0;
806}
807
808static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
809 struct snd_ctl_elem_value *ucontrol)
810{
811 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
812 struct alc_spec *spec = codec->spec;
813
814 switch (ucontrol->value.enumerated.item[0]) {
815 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200816 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200817 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200818 spec->automute_speaker = 0;
819 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200820 break;
821 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200822 if (spec->automute_speaker_possible) {
823 if (!spec->automute_lo && spec->automute_speaker)
824 return 0;
825 spec->automute_speaker = 1;
826 spec->automute_lo = 0;
827 } else if (spec->automute_lo_possible) {
828 if (spec->automute_lo)
829 return 0;
830 spec->automute_lo = 1;
831 } else
832 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200833 break;
834 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200835 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200836 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200837 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200838 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200839 spec->automute_speaker = 1;
840 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200841 break;
842 default:
843 return -EINVAL;
844 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200845 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200846 return 1;
847}
848
Takashi Iwaia9111322011-05-02 11:30:18 +0200849static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200850 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
851 .name = "Auto-Mute Mode",
852 .info = alc_automute_mode_info,
853 .get = alc_automute_mode_get,
854 .put = alc_automute_mode_put,
855};
856
Takashi Iwai668d1e92012-11-29 14:10:17 +0100857static struct snd_kcontrol_new *
858alc_kcontrol_new(struct alc_spec *spec, const char *name,
859 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200860{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100861 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
862 if (!knew)
863 return NULL;
864 *knew = *temp;
Takashi Iwaibc549762012-12-18 15:35:11 +0100865 if (name)
866 knew->name = kstrdup(name, GFP_KERNEL);
867 else if (knew->name)
868 knew->name = kstrdup(knew->name, GFP_KERNEL);
Takashi Iwai668d1e92012-11-29 14:10:17 +0100869 if (!knew->name)
870 return NULL;
871 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200872}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200873
874static int alc_add_automute_mode_enum(struct hda_codec *codec)
875{
876 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200877
Takashi Iwaibc549762012-12-18 15:35:11 +0100878 if (!alc_kcontrol_new(spec, NULL, &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200879 return -ENOMEM;
880 return 0;
881}
882
Takashi Iwai1d045db2011-07-07 18:23:21 +0200883/*
884 * Check the availability of HP/line-out auto-mute;
885 * Set up appropriately if really supported
886 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100887static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200888{
889 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200890 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200891 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100892 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200893
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200894 if (cfg->hp_pins[0])
895 present++;
896 if (cfg->line_out_pins[0])
897 present++;
898 if (cfg->speaker_pins[0])
899 present++;
900 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100901 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200902
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200903 if (!cfg->speaker_pins[0] &&
904 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200905 memcpy(cfg->speaker_pins, cfg->line_out_pins,
906 sizeof(cfg->speaker_pins));
907 cfg->speaker_outs = cfg->line_outs;
908 }
909
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200910 if (!cfg->hp_pins[0] &&
911 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200912 memcpy(cfg->hp_pins, cfg->line_out_pins,
913 sizeof(cfg->hp_pins));
914 cfg->hp_outs = cfg->line_outs;
915 }
916
917 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200918 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200919 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200920 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200921 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200922 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200923 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
924 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200925 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200926 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200927
David Henningsson42cf0d02011-09-20 12:04:56 +0200928 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
929 if (cfg->speaker_outs)
930 for (i = 0; i < cfg->line_outs; i++) {
931 hda_nid_t nid = cfg->line_out_pins[i];
932 if (!is_jack_detectable(codec, nid))
933 continue;
934 snd_printdd("realtek: Enable Line-Out "
935 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200936 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
937 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200938 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200939 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200940 spec->automute_lo_possible = spec->detect_hp;
941 }
942
943 spec->automute_speaker_possible = cfg->speaker_outs &&
944 (spec->detect_hp || spec->detect_lo);
945
946 spec->automute_lo = spec->automute_lo_possible;
947 spec->automute_speaker = spec->automute_speaker_possible;
948
Takashi Iwai475c3d22012-11-30 08:31:30 +0100949 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200950 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100951 err = alc_add_automute_mode_enum(codec);
952 if (err < 0)
953 return err;
954 }
955 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200956}
957
Takashi Iwai1d045db2011-07-07 18:23:21 +0200958/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200959static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
960{
961 int i;
962 for (i = 0; i < nums; i++)
963 if (list[i] == nid)
964 return i;
965 return -1;
966}
967
Takashi Iwai21268962011-07-07 15:01:13 +0200968/* check whether all auto-mic pins are valid; setup indices if OK */
969static bool alc_auto_mic_check_imux(struct hda_codec *codec)
970{
971 struct alc_spec *spec = codec->spec;
972 const struct hda_input_mux *imux;
973
Takashi Iwai27d31532012-12-18 08:57:05 +0100974 imux = &spec->input_mux;
Takashi Iwai21268962011-07-07 15:01:13 +0200975 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
976 spec->imux_pins, imux->num_items);
977 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
978 spec->imux_pins, imux->num_items);
979 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
980 spec->imux_pins, imux->num_items);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100981 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0)
Takashi Iwai21268962011-07-07 15:01:13 +0200982 return false; /* no corresponding imux */
Takashi Iwai21268962011-07-07 15:01:13 +0200983
David Henningsson29adc4b2012-09-25 11:31:00 +0200984 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
985 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200986 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +0200987 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
988 ALC_MIC_EVENT,
989 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200990 return true;
991}
992
Takashi Iwai1d045db2011-07-07 18:23:21 +0200993/*
994 * Check the availability of auto-mic switch;
995 * Set up if really supported
996 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100997static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +0200998{
999 struct alc_spec *spec = codec->spec;
1000 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001001 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001002 int i;
1003
Takashi Iwai21268962011-07-07 15:01:13 +02001004 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1005
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001006 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001007 for (i = 0; i < cfg->num_inputs; i++) {
1008 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001009 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001010 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001011 switch (snd_hda_get_input_pin_attr(defcfg)) {
1012 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001013 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001014 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001015 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001016 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001017 fixed = nid;
1018 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001019 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001020 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001021 case INPUT_PIN_ATTR_DOCK:
1022 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001023 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001024 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001025 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001026 dock = nid;
1027 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001028 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001029 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001030 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001031 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001032 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001033 ext = nid;
1034 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001035 }
1036 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001037 if (!ext && dock) {
1038 ext = dock;
1039 dock = 0;
1040 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001041 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001042 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001043 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001044 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001045 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001046 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001047
1048 /* check imux indices */
1049 spec->ext_mic_pin = ext;
1050 spec->int_mic_pin = fixed;
1051 spec->dock_mic_pin = dock;
1052
Takashi Iwai21268962011-07-07 15:01:13 +02001053 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001054 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001055
Takashi Iwai666a70d2012-12-17 20:29:29 +01001056 spec->auto_mic = 1;
1057 spec->num_adc_nids = 1;
1058 spec->cur_mux[0] = spec->int_mic_idx;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001059 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1060 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001061
1062 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001063}
1064
Takashi Iwai1d045db2011-07-07 18:23:21 +02001065/*
1066 * Realtek SSID verification
1067 */
1068
David Henningsson90622912010-10-14 14:50:18 +02001069/* Could be any non-zero and even value. When used as fixup, tells
1070 * the driver to ignore any present sku defines.
1071 */
1072#define ALC_FIXUP_SKU_IGNORE (2)
1073
Takashi Iwai23d30f22012-05-07 17:17:32 +02001074static void alc_fixup_sku_ignore(struct hda_codec *codec,
1075 const struct hda_fixup *fix, int action)
1076{
1077 struct alc_spec *spec = codec->spec;
1078 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1079 spec->cdefine.fixup = 1;
1080 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1081 }
1082}
1083
Kailang Yangda00c242010-03-19 11:23:45 +01001084static int alc_auto_parse_customize_define(struct hda_codec *codec)
1085{
1086 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001087 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001088 struct alc_spec *spec = codec->spec;
1089
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001090 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1091
David Henningsson90622912010-10-14 14:50:18 +02001092 if (spec->cdefine.fixup) {
1093 ass = spec->cdefine.sku_cfg;
1094 if (ass == ALC_FIXUP_SKU_IGNORE)
1095 return -1;
1096 goto do_sku;
1097 }
1098
Kailang Yangda00c242010-03-19 11:23:45 +01001099 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001100 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001101 goto do_sku;
1102
1103 nid = 0x1d;
1104 if (codec->vendor_id == 0x10ec0260)
1105 nid = 0x17;
1106 ass = snd_hda_codec_get_pincfg(codec, nid);
1107
1108 if (!(ass & 1)) {
1109 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1110 codec->chip_name, ass);
1111 return -1;
1112 }
1113
1114 /* check sum */
1115 tmp = 0;
1116 for (i = 1; i < 16; i++) {
1117 if ((ass >> i) & 1)
1118 tmp++;
1119 }
1120 if (((ass >> 16) & 0xf) != tmp)
1121 return -1;
1122
1123 spec->cdefine.port_connectivity = ass >> 30;
1124 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1125 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1126 spec->cdefine.customization = ass >> 8;
1127do_sku:
1128 spec->cdefine.sku_cfg = ass;
1129 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1130 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1131 spec->cdefine.swap = (ass & 0x2) >> 1;
1132 spec->cdefine.override = ass & 0x1;
1133
1134 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1135 nid, spec->cdefine.sku_cfg);
1136 snd_printd("SKU: port_connectivity=0x%x\n",
1137 spec->cdefine.port_connectivity);
1138 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1139 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1140 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1141 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1142 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1143 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1144 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1145
1146 return 0;
1147}
1148
Takashi Iwai1d045db2011-07-07 18:23:21 +02001149/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001150static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1151{
Takashi Iwai21268962011-07-07 15:01:13 +02001152 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001153}
1154
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001155/* check subsystem ID and set up device-specific initialization;
1156 * return 1 if initialized, 0 if invalid SSID
1157 */
1158/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1159 * 31 ~ 16 : Manufacture ID
1160 * 15 ~ 8 : SKU ID
1161 * 7 ~ 0 : Assembly ID
1162 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1163 */
1164static int alc_subsystem_id(struct hda_codec *codec,
1165 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001166 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001167{
1168 unsigned int ass, tmp, i;
1169 unsigned nid;
1170 struct alc_spec *spec = codec->spec;
1171
David Henningsson90622912010-10-14 14:50:18 +02001172 if (spec->cdefine.fixup) {
1173 ass = spec->cdefine.sku_cfg;
1174 if (ass == ALC_FIXUP_SKU_IGNORE)
1175 return 0;
1176 goto do_sku;
1177 }
1178
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001179 ass = codec->subsystem_id & 0xffff;
1180 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1181 goto do_sku;
1182
1183 /* invalid SSID, check the special NID pin defcfg instead */
1184 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001185 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001186 * 29~21 : reserve
1187 * 20 : PCBEEP input
1188 * 19~16 : Check sum (15:1)
1189 * 15~1 : Custom
1190 * 0 : override
1191 */
1192 nid = 0x1d;
1193 if (codec->vendor_id == 0x10ec0260)
1194 nid = 0x17;
1195 ass = snd_hda_codec_get_pincfg(codec, nid);
1196 snd_printd("realtek: No valid SSID, "
1197 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001198 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001199 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001200 return 0;
1201 if ((ass >> 30) != 1) /* no physical connection */
1202 return 0;
1203
1204 /* check sum */
1205 tmp = 0;
1206 for (i = 1; i < 16; i++) {
1207 if ((ass >> i) & 1)
1208 tmp++;
1209 }
1210 if (((ass >> 16) & 0xf) != tmp)
1211 return 0;
1212do_sku:
1213 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1214 ass & 0xffff, codec->vendor_id);
1215 /*
1216 * 0 : override
1217 * 1 : Swap Jack
1218 * 2 : 0 --> Desktop, 1 --> Laptop
1219 * 3~5 : External Amplifier control
1220 * 7~6 : Reserved
1221 */
1222 tmp = (ass & 0x38) >> 3; /* external Amp control */
1223 switch (tmp) {
1224 case 1:
1225 spec->init_amp = ALC_INIT_GPIO1;
1226 break;
1227 case 3:
1228 spec->init_amp = ALC_INIT_GPIO2;
1229 break;
1230 case 7:
1231 spec->init_amp = ALC_INIT_GPIO3;
1232 break;
1233 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001234 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001235 spec->init_amp = ALC_INIT_DEFAULT;
1236 break;
1237 }
1238
1239 /* is laptop or Desktop and enable the function "Mute internal speaker
1240 * when the external headphone out jack is plugged"
1241 */
1242 if (!(ass & 0x8000))
1243 return 1;
1244 /*
1245 * 10~8 : Jack location
1246 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1247 * 14~13: Resvered
1248 * 15 : 1 --> enable the function "Mute internal speaker
1249 * when the external headphone out jack is plugged"
1250 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001251 if (!spec->autocfg.hp_pins[0] &&
1252 !(spec->autocfg.line_out_pins[0] &&
1253 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001254 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001255 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1256 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001257 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001258 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001259 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001260 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001261 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001262 else if (tmp == 3)
1263 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001264 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001265 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001266 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1267 spec->autocfg.line_outs))
1268 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001269 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001270 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001271 return 1;
1272}
Kailang Yangea1fb292008-08-26 12:58:38 +02001273
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001274/* Check the validity of ALC subsystem-id
1275 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1276static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001277{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001278 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001279 struct alc_spec *spec = codec->spec;
1280 snd_printd("realtek: "
1281 "Enable default setup for auto mode as fallback\n");
1282 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001283 }
Takashi Iwai21268962011-07-07 15:01:13 +02001284}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001285
Takashi Iwai41e41f12005-06-08 14:48:49 +02001286/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001287 * COEF access helper functions
1288 */
Kailang Yang274693f2009-12-03 10:07:50 +01001289static int alc_read_coef_idx(struct hda_codec *codec,
1290 unsigned int coef_idx)
1291{
1292 unsigned int val;
1293 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1294 coef_idx);
1295 val = snd_hda_codec_read(codec, 0x20, 0,
1296 AC_VERB_GET_PROC_COEF, 0);
1297 return val;
1298}
1299
Kailang Yang977ddd62010-09-15 10:02:29 +02001300static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1301 unsigned int coef_val)
1302{
1303 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1304 coef_idx);
1305 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1306 coef_val);
1307}
1308
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001309/* a special bypass for COEF 0; read the cached value at the second time */
1310static unsigned int alc_get_coef0(struct hda_codec *codec)
1311{
1312 struct alc_spec *spec = codec->spec;
1313 if (!spec->coef0)
1314 spec->coef0 = alc_read_coef_idx(codec, 0);
1315 return spec->coef0;
1316}
1317
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001318static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1319 hda_nid_t pin, int pin_type,
1320 hda_nid_t dac);
1321static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1322 bool is_digital);
Takashi Iwai965cceb2012-12-18 11:46:37 +01001323static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
1324 hda_nid_t to_nid, int with_aa_mix,
1325 struct nid_path *path);
1326static struct nid_path *add_new_nid_path(struct hda_codec *codec,
1327 hda_nid_t from_nid, hda_nid_t to_nid,
1328 int with_aa_mix);
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001329
Takashi Iwai1d045db2011-07-07 18:23:21 +02001330/*
1331 * Digital I/O handling
1332 */
1333
Takashi Iwai757899a2010-07-30 10:48:14 +02001334/* set right pin controls for digital I/O */
1335static void alc_auto_init_digital(struct hda_codec *codec)
1336{
1337 struct alc_spec *spec = codec->spec;
1338 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001339 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001340
1341 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1342 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001343 if (!pin)
1344 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001345 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001346 }
1347 pin = spec->autocfg.dig_in_pin;
1348 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001349 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001350}
1351
1352/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1353static void alc_auto_parse_digital(struct hda_codec *codec)
1354{
1355 struct alc_spec *spec = codec->spec;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001356 int i, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001357 hda_nid_t dig_nid;
1358
1359 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001360 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001361 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001362 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1363 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1364 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001365 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001366 if (!add_new_nid_path(codec, dig_nid, pin, 2))
1367 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001368 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001369 spec->multiout.dig_out_nid = dig_nid;
1370 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1371 } else {
1372 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001373 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001374 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001375 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001376 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001377 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001378 }
1379
1380 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001381 dig_nid = codec->start_nid;
1382 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001383 struct nid_path *path;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001384 unsigned int wcaps = get_wcaps(codec, dig_nid);
1385 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1386 continue;
1387 if (!(wcaps & AC_WCAP_DIGITAL))
1388 continue;
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001389 path = add_new_nid_path(codec, spec->autocfg.dig_in_pin,
1390 dig_nid, 2);
1391 if (path) {
1392 path->active = true;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001393 spec->dig_in_nid = dig_nid;
1394 break;
1395 }
1396 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001397 }
1398}
1399
Takashi Iwaif95474e2007-07-10 00:47:43 +02001400/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001401 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001402 */
Takashi Iwai666a70d2012-12-17 20:29:29 +01001403#define alc_cap_vol_info snd_hda_mixer_amp_volume_info
1404#define alc_cap_vol_get snd_hda_mixer_amp_volume_get
1405#define alc_cap_vol_tlv snd_hda_mixer_amp_tlv
1406
1407typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
1408 struct snd_ctl_elem_value *ucontrol);
1409
1410static int alc_cap_put_caller(struct snd_kcontrol *kcontrol,
1411 struct snd_ctl_elem_value *ucontrol,
1412 put_call_t func, int type)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001413{
1414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1415 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001416 const struct hda_input_mux *imux;
1417 struct nid_path *path;
1418 int i, adc_idx, err = 0;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001419
Takashi Iwai27d31532012-12-18 08:57:05 +01001420 imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001421 adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001422 mutex_lock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001423 codec->cached_write = 1;
1424 for (i = 0; i < imux->num_items; i++) {
1425 path = get_nid_path(codec, spec->imux_pins[i],
1426 get_adc_nid(codec, adc_idx, i));
1427 if (!path->ctls[type])
1428 continue;
1429 kcontrol->private_value = path->ctls[type];
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001430 err = func(kcontrol, ucontrol);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001431 if (err < 0)
1432 goto error;
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001433 }
1434 error:
Takashi Iwai666a70d2012-12-17 20:29:29 +01001435 codec->cached_write = 0;
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001436 mutex_unlock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001437 snd_hda_codec_resume_amp(codec);
1438 if (err >= 0 && type == NID_PATH_MUTE_CTL &&
1439 spec->inv_dmic_fixup && spec->inv_dmic_muted)
1440 alc_inv_dmic_sync_adc(codec, adc_idx);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001441 return err;
1442}
1443
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001444static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1445 struct snd_ctl_elem_value *ucontrol)
1446{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001447 return alc_cap_put_caller(kcontrol, ucontrol,
1448 snd_hda_mixer_amp_volume_put,
1449 NID_PATH_VOL_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001450}
1451
1452/* capture mixer elements */
1453#define alc_cap_sw_info snd_ctl_boolean_stereo_info
Takashi Iwai666a70d2012-12-17 20:29:29 +01001454#define alc_cap_sw_get snd_hda_mixer_amp_switch_get
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001455
1456static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1457 struct snd_ctl_elem_value *ucontrol)
1458{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001459 return alc_cap_put_caller(kcontrol, ucontrol,
1460 snd_hda_mixer_amp_switch_put,
1461 NID_PATH_MUTE_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001462}
1463
Takashi Iwai666a70d2012-12-17 20:29:29 +01001464static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1465{
1466 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01001467 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001468 struct nid_path *path;
1469 hda_nid_t nid;
1470 int i, dir, parm;
1471 unsigned int val;
1472
1473 for (i = 0; i < imux->num_items; i++) {
1474 if (spec->imux_pins[i] == spec->inv_dmic_pin)
1475 break;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001476 }
Takashi Iwai666a70d2012-12-17 20:29:29 +01001477 if (i >= imux->num_items)
1478 return;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001479
Takashi Iwai666a70d2012-12-17 20:29:29 +01001480 path = get_nid_path(codec, spec->inv_dmic_pin,
1481 get_adc_nid(codec, adc_idx, i));
1482 val = path->ctls[NID_PATH_MUTE_CTL];
1483 if (!val)
1484 return;
1485 nid = get_amp_nid_(val);
1486 dir = get_amp_direction_(val);
1487 parm = AC_AMP_SET_RIGHT |
1488 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001489
Takashi Iwai666a70d2012-12-17 20:29:29 +01001490 /* we care only right channel */
1491 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1492 if (val & 0x80) /* if already muted, we don't need to touch */
1493 return;
1494 val |= 0x80;
1495 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1496 parm | val);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001497}
1498
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001499/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001500 * Inverted digital-mic handling
1501 *
1502 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1503 * gives the additional mute only to the right channel of the digital mic
1504 * capture stream. This is a workaround for avoiding the almost silence
1505 * by summing the stereo stream from some (known to be ForteMedia)
1506 * digital mic unit.
1507 *
1508 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1509 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1510 * without caching so that the cache can still keep the original value.
1511 * The cached value is then restored when the flag is set off or any other
1512 * than d-mic is used as the current input source.
1513 */
1514static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1515{
1516 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001517 int src, nums;
Takashi Iwai125821a2012-06-22 14:30:29 +02001518
1519 if (!spec->inv_dmic_fixup)
1520 return;
1521 if (!spec->inv_dmic_muted && !force)
1522 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001523 nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids;
1524 for (src = 0; src < nums; src++) {
Takashi Iwai125821a2012-06-22 14:30:29 +02001525 bool dmic_fixup = false;
Takashi Iwai125821a2012-06-22 14:30:29 +02001526
1527 if (spec->inv_dmic_muted &&
1528 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1529 dmic_fixup = true;
1530 if (!dmic_fixup && !force)
1531 continue;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001532 alc_inv_dmic_sync_adc(codec, src);
Takashi Iwai125821a2012-06-22 14:30:29 +02001533 }
1534}
1535
1536static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1537 struct snd_ctl_elem_value *ucontrol)
1538{
1539 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1540 struct alc_spec *spec = codec->spec;
1541
1542 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1543 return 0;
1544}
1545
1546static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1547 struct snd_ctl_elem_value *ucontrol)
1548{
1549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1550 struct alc_spec *spec = codec->spec;
1551 unsigned int val = !ucontrol->value.integer.value[0];
1552
1553 if (val == spec->inv_dmic_muted)
1554 return 0;
1555 spec->inv_dmic_muted = val;
1556 alc_inv_dmic_sync(codec, true);
1557 return 0;
1558}
1559
1560static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1561 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwaibc549762012-12-18 15:35:11 +01001562 .name = "Inverted Internal Mic Capture Switch",
Takashi Iwai125821a2012-06-22 14:30:29 +02001563 .info = snd_ctl_boolean_mono_info,
1564 .get = alc_inv_dmic_sw_get,
1565 .put = alc_inv_dmic_sw_put,
1566};
1567
1568static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1569{
1570 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001571
Takashi Iwaibc549762012-12-18 15:35:11 +01001572 if (!alc_kcontrol_new(spec, NULL, &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001573 return -ENOMEM;
1574 spec->inv_dmic_fixup = 1;
1575 spec->inv_dmic_muted = 0;
1576 spec->inv_dmic_pin = nid;
1577 return 0;
1578}
1579
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001580/* typically the digital mic is put at node 0x12 */
1581static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1582 const struct alc_fixup *fix, int action)
1583{
1584 if (action == ALC_FIXUP_ACT_PROBE)
1585 alc_add_inv_dmic_mixer(codec, 0x12);
1586}
1587
Takashi Iwai125821a2012-06-22 14:30:29 +02001588/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001589 * virtual master controls
1590 */
1591
1592/*
1593 * slave controls for virtual master
1594 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001595static const char * const alc_slave_pfxs[] = {
1596 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001597 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001598 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001599 NULL,
1600};
1601
1602/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001603 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001605
1606static void alc_free_kctls(struct hda_codec *codec);
1607
Takashi Iwai67d634c2009-11-16 15:35:59 +01001608#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001609/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001610static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001611 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001612 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001613 { } /* end */
1614};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001615#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001616
Takashi Iwai2eab6942012-12-18 15:30:41 +01001617static int alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
1619 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001620 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
1622 for (i = 0; i < spec->num_mixers; i++) {
1623 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1624 if (err < 0)
1625 return err;
1626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001628 err = snd_hda_create_dig_out_ctls(codec,
1629 spec->multiout.dig_out_nid,
1630 spec->multiout.dig_out_nid,
1631 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 if (err < 0)
1633 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001634 if (!spec->no_analog) {
1635 err = snd_hda_create_spdif_share_sw(codec,
1636 &spec->multiout);
1637 if (err < 0)
1638 return err;
1639 spec->multiout.share_spdif = 1;
1640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 }
1642 if (spec->dig_in_nid) {
1643 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1644 if (err < 0)
1645 return err;
1646 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001647
Takashi Iwai67d634c2009-11-16 15:35:59 +01001648#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001649 /* create beep controls if needed */
1650 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001651 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001652 for (knew = alc_beep_mixer; knew->name; knew++) {
1653 struct snd_kcontrol *kctl;
1654 kctl = snd_ctl_new1(knew, codec);
1655 if (!kctl)
1656 return -ENOMEM;
1657 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001658 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001659 if (err < 0)
1660 return err;
1661 }
1662 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001663#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001664
Takashi Iwai2134ea42008-01-10 16:53:55 +01001665 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001666 if (!spec->no_analog &&
1667 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001668 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001669 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001670 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001671 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001672 vmaster_tlv, alc_slave_pfxs,
1673 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001674 if (err < 0)
1675 return err;
1676 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001677 if (!spec->no_analog &&
1678 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001679 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1680 NULL, alc_slave_pfxs,
1681 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001682 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001683 if (err < 0)
1684 return err;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001685 if (spec->vmaster_mute.hook)
1686 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001687 }
1688
Takashi Iwaibae84e72010-03-22 08:30:20 +01001689 alc_free_kctls(codec); /* no longer needed */
1690
David Henningsson5780b622012-06-27 18:45:45 +02001691 if (spec->shared_mic_hp) {
1692 int err;
1693 int nid = spec->autocfg.inputs[1].pin;
1694 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1695 if (err < 0)
1696 return err;
1697 err = snd_hda_jack_detect_enable(codec, nid, 0);
1698 if (err < 0)
1699 return err;
1700 }
1701
Takashi Iwai2eab6942012-12-18 15:30:41 +01001702 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001703 if (err < 0)
1704 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001705
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001706 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1707 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
1709
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001710
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001712 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001713 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001714
Takashi Iwai070cff42012-02-21 12:54:17 +01001715static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001716
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717static int alc_init(struct hda_codec *codec)
1718{
1719 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001720
Takashi Iwai546bb672012-03-07 08:37:19 +01001721 if (spec->init_hook)
1722 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001723
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001724 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001725 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001726
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02001727 snd_hda_gen_apply_verbs(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001728 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001729
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001730 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
1731 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
1732
Takashi Iwai58701122011-01-13 15:41:45 +01001733 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1734
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001735 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 return 0;
1737}
1738
Takashi Iwai83012a72012-08-24 18:38:08 +02001739#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001740static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1741{
1742 struct alc_spec *spec = codec->spec;
1743 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1744}
1745#endif
1746
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747/*
1748 * Analog playback callbacks
1749 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001750static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001752 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753{
1754 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001755 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1756 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757}
1758
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001759static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 struct hda_codec *codec,
1761 unsigned int stream_tag,
1762 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001763 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764{
1765 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001766 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1767 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001770static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001772 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
1774 struct alc_spec *spec = codec->spec;
1775 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1776}
1777
1778/*
1779 * Digital out
1780 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001781static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001783 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
1785 struct alc_spec *spec = codec->spec;
1786 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1787}
1788
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001789static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001790 struct hda_codec *codec,
1791 unsigned int stream_tag,
1792 unsigned int format,
1793 struct snd_pcm_substream *substream)
1794{
1795 struct alc_spec *spec = codec->spec;
1796 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1797 stream_tag, format, substream);
1798}
1799
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001800static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001801 struct hda_codec *codec,
1802 struct snd_pcm_substream *substream)
1803{
1804 struct alc_spec *spec = codec->spec;
1805 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1806}
1807
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001808static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001810 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811{
1812 struct alc_spec *spec = codec->spec;
1813 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1814}
1815
1816/*
1817 * Analog capture
1818 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001819static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 struct hda_codec *codec,
1821 unsigned int stream_tag,
1822 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001823 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824{
1825 struct alc_spec *spec = codec->spec;
1826
Takashi Iwai63300792008-01-24 15:31:36 +01001827 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 stream_tag, 0, format);
1829 return 0;
1830}
1831
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001832static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001834 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
1836 struct alc_spec *spec = codec->spec;
1837
Takashi Iwai888afa12008-03-18 09:57:50 +01001838 snd_hda_codec_cleanup_stream(codec,
1839 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 return 0;
1841}
1842
Takashi Iwai840b64c2010-07-13 22:49:01 +02001843/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02001844static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001845 struct hda_codec *codec,
1846 unsigned int stream_tag,
1847 unsigned int format,
1848 struct snd_pcm_substream *substream)
1849{
1850 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001851 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02001852 spec->cur_adc_stream_tag = stream_tag;
1853 spec->cur_adc_format = format;
1854 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1855 return 0;
1856}
1857
Takashi Iwai21268962011-07-07 15:01:13 +02001858static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001859 struct hda_codec *codec,
1860 struct snd_pcm_substream *substream)
1861{
1862 struct alc_spec *spec = codec->spec;
1863 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1864 spec->cur_adc = 0;
1865 return 0;
1866}
1867
Takashi Iwai21268962011-07-07 15:01:13 +02001868static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02001869 .substreams = 1,
1870 .channels_min = 2,
1871 .channels_max = 2,
1872 .nid = 0, /* fill later */
1873 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02001874 .prepare = dyn_adc_capture_pcm_prepare,
1875 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02001876 },
1877};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
1879/*
1880 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001881static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 .substreams = 1,
1883 .channels_min = 2,
1884 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001885 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001887 .open = alc_playback_pcm_open,
1888 .prepare = alc_playback_pcm_prepare,
1889 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 },
1891};
1892
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001893static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001894 .substreams = 1,
1895 .channels_min = 2,
1896 .channels_max = 2,
1897 /* NID is set in alc_build_pcms */
1898};
1899
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001900static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01001901 .substreams = 1,
1902 .channels_min = 2,
1903 .channels_max = 2,
1904 /* NID is set in alc_build_pcms */
1905};
1906
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001907static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001908 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 .channels_min = 2,
1910 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001911 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001913 .prepare = alc_alt_capture_pcm_prepare,
1914 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 },
1916};
1917
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001918static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 .substreams = 1,
1920 .channels_min = 2,
1921 .channels_max = 2,
1922 /* NID is set in alc_build_pcms */
1923 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001924 .open = alc_dig_playback_pcm_open,
1925 .close = alc_dig_playback_pcm_close,
1926 .prepare = alc_dig_playback_pcm_prepare,
1927 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 },
1929};
1930
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001931static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 .substreams = 1,
1933 .channels_min = 2,
1934 .channels_max = 2,
1935 /* NID is set in alc_build_pcms */
1936};
1937
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001938/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02001939static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001940 .substreams = 0,
1941 .channels_min = 0,
1942 .channels_max = 0,
1943};
1944
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945static int alc_build_pcms(struct hda_codec *codec)
1946{
1947 struct alc_spec *spec = codec->spec;
1948 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001949 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01001950 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 int i;
1952
1953 codec->num_pcms = 1;
1954 codec->pcm_info = info;
1955
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001956 if (spec->no_analog)
1957 goto skip_analog;
1958
Takashi Iwai812a2cc2009-05-16 10:00:49 +02001959 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1960 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01001962
Takashi Iwaieedec3d2012-02-06 10:24:04 +01001963 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001964 p = spec->stream_analog_playback;
1965 if (!p)
1966 p = &alc_pcm_analog_playback;
1967 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001968 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02001969 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1970 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01001971 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
1972 spec->autocfg.line_outs == 2)
1973 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1974 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001975 }
Takashi Iwai27d31532012-12-18 08:57:05 +01001976 if (spec->num_adc_nids) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001977 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02001978 if (!p) {
1979 if (spec->dyn_adc_switch)
1980 p = &dyn_adc_pcm_analog_capture;
1981 else
1982 p = &alc_pcm_analog_capture;
1983 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001984 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001985 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1986 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
Takashi Iwai4a471b72005-12-07 13:56:29 +01001988 if (spec->channel_mode) {
1989 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
1990 for (i = 0; i < spec->num_channel_mode; i++) {
1991 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
1992 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
1993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 }
1995 }
1996
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001997 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02001998 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002000 snprintf(spec->stream_name_digital,
2001 sizeof(spec->stream_name_digital),
2002 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002003 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002004 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002005 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002007 if (spec->dig_out_type)
2008 info->pcm_type = spec->dig_out_type;
2009 else
2010 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002011 if (spec->multiout.dig_out_nid) {
2012 p = spec->stream_digital_playback;
2013 if (!p)
2014 p = &alc_pcm_digital_playback;
2015 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2017 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002018 if (spec->dig_in_nid) {
2019 p = spec->stream_digital_capture;
2020 if (!p)
2021 p = &alc_pcm_digital_capture;
2022 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2024 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002025 /* FIXME: do we need this for all Realtek codec models? */
2026 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 }
2028
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002029 if (spec->no_analog)
2030 return 0;
2031
Takashi Iwaie08a0072006-09-07 17:52:14 +02002032 /* If the use of more than one ADC is requested for the current
2033 * model, configure a second analog capture-only PCM.
2034 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002035 have_multi_adcs = (spec->num_adc_nids > 1) &&
Takashi Iwai27d31532012-12-18 08:57:05 +01002036 !spec->dyn_adc_switch && !spec->auto_mic;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002037 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002038 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002039 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002040 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002041 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002042 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002043 p = spec->stream_analog_alt_playback;
2044 if (!p)
2045 p = &alc_pcm_analog_alt_playback;
2046 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002047 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2048 spec->alt_dac_nid;
2049 } else {
2050 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2051 alc_pcm_null_stream;
2052 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2053 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002054 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002055 p = spec->stream_analog_alt_capture;
2056 if (!p)
2057 p = &alc_pcm_analog_alt_capture;
2058 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002059 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2060 spec->adc_nids[1];
2061 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2062 spec->num_adc_nids - 1;
2063 } else {
2064 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2065 alc_pcm_null_stream;
2066 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002067 }
2068 }
2069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 return 0;
2071}
2072
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002073static inline void alc_shutup(struct hda_codec *codec)
2074{
Takashi Iwai1c716152011-04-07 10:37:16 +02002075 struct alc_spec *spec = codec->spec;
2076
2077 if (spec && spec->shutup)
2078 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002079 snd_hda_shutup_pins(codec);
2080}
2081
Takashi Iwai603c4012008-07-30 15:01:44 +02002082static void alc_free_kctls(struct hda_codec *codec)
2083{
2084 struct alc_spec *spec = codec->spec;
2085
2086 if (spec->kctls.list) {
2087 struct snd_kcontrol_new *kctl = spec->kctls.list;
2088 int i;
2089 for (i = 0; i < spec->kctls.used; i++)
2090 kfree(kctl[i].name);
2091 }
2092 snd_array_free(&spec->kctls);
2093}
2094
Takashi Iwai23c09b02011-08-19 09:05:35 +02002095static void alc_free_bind_ctls(struct hda_codec *codec)
2096{
2097 struct alc_spec *spec = codec->spec;
2098 if (spec->bind_ctls.list) {
2099 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2100 int i;
2101 for (i = 0; i < spec->bind_ctls.used; i++)
2102 kfree(ctl[i]);
2103 }
2104 snd_array_free(&spec->bind_ctls);
2105}
2106
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107static void alc_free(struct hda_codec *codec)
2108{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002109 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002110
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002111 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002112 return;
2113
Takashi Iwai603c4012008-07-30 15:01:44 +02002114 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002115 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002116 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002117 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002118 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002119 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120}
2121
Takashi Iwai83012a72012-08-24 18:38:08 +02002122#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002123static void alc_power_eapd(struct hda_codec *codec)
2124{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002125 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002126}
2127
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002128static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002129{
2130 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002131 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002132 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002133 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002134 return 0;
2135}
2136#endif
2137
Takashi Iwai2a439522011-07-26 09:52:50 +02002138#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002139static int alc_resume(struct hda_codec *codec)
2140{
Takashi Iwai1c716152011-04-07 10:37:16 +02002141 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002142 codec->patch_ops.init(codec);
2143 snd_hda_codec_resume_amp(codec);
2144 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002145 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002146 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002147 return 0;
2148}
Takashi Iwaie044c392008-10-27 16:56:24 +01002149#endif
2150
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151/*
2152 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002153static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 .build_controls = alc_build_controls,
2155 .build_pcms = alc_build_pcms,
2156 .init = alc_init,
2157 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002158 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002159#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002160 .resume = alc_resume,
2161#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002162#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002163 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002164 .check_power_status = alc_check_power_status,
2165#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002166 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167};
2168
David Henningsson29adc4b2012-09-25 11:31:00 +02002169
Kailang Yangc027ddc2010-03-19 11:33:06 +01002170/* replace the codec chip_name with the given string */
2171static int alc_codec_rename(struct hda_codec *codec, const char *name)
2172{
2173 kfree(codec->chip_name);
2174 codec->chip_name = kstrdup(name, GFP_KERNEL);
2175 if (!codec->chip_name) {
2176 alc_free(codec);
2177 return -ENOMEM;
2178 }
2179 return 0;
2180}
2181
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002182/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002183 * Rename codecs appropriately from COEF value
2184 */
2185struct alc_codec_rename_table {
2186 unsigned int vendor_id;
2187 unsigned short coef_mask;
2188 unsigned short coef_bits;
2189 const char *name;
2190};
2191
2192static struct alc_codec_rename_table rename_tbl[] = {
2193 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2194 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2195 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2196 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2197 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2198 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2199 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002200 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002201 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2202 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2203 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2204 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2205 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2206 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2207 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2208 { } /* terminator */
2209};
2210
2211static int alc_codec_rename_from_preset(struct hda_codec *codec)
2212{
2213 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002214
2215 for (p = rename_tbl; p->vendor_id; p++) {
2216 if (p->vendor_id != codec->vendor_id)
2217 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002218 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002219 return alc_codec_rename(codec, p->name);
2220 }
2221 return 0;
2222}
2223
2224/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002225 * Automatic parse of I/O pins from the BIOS configuration
2226 */
2227
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002228enum {
2229 ALC_CTL_WIDGET_VOL,
2230 ALC_CTL_WIDGET_MUTE,
2231 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002232 ALC_CTL_BIND_VOL,
2233 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002234};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002235static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002236 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2237 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002238 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002239 HDA_BIND_VOL(NULL, 0),
2240 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002241};
2242
2243/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002244static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002245 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002246{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002247 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002248
Takashi Iwai668d1e92012-11-29 14:10:17 +01002249 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002250 if (!knew)
2251 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002252 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002253 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002254 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002255 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002256 return 0;
2257}
2258
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002259static int add_control_with_pfx(struct alc_spec *spec, int type,
2260 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002261 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002262{
2263 char name[32];
2264 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002265 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002266}
2267
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002268#define add_pb_vol_ctrl(spec, type, pfx, val) \
2269 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2270#define add_pb_sw_ctrl(spec, type, pfx, val) \
2271 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2272#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2273 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2274#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2275 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002276
Takashi Iwai23c09b02011-08-19 09:05:35 +02002277static const char * const channel_name[4] = {
2278 "Front", "Surround", "CLFE", "Side"
2279};
2280
Takashi Iwai6843ca12011-06-24 11:03:58 +02002281static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2282 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002283{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002284 struct auto_pin_cfg *cfg = &spec->autocfg;
2285
Takashi Iwai6843ca12011-06-24 11:03:58 +02002286 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002287 if (cfg->line_outs == 1 && !spec->multi_ios &&
2288 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwai52a8efa2012-12-18 17:33:04 +01002289 return spec->vmaster_mute.hook ? "PCM" : "Master";
2290
2291 /* if there is really a single DAC used in the whole output paths,
2292 * use it master (or "PCM" if a vmaster hook is present)
2293 */
2294 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
2295 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
2296 return spec->vmaster_mute.hook ? "PCM" : "Master";
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002297
2298 switch (cfg->line_out_type) {
2299 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002300 if (cfg->line_outs == 1)
2301 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002302 if (cfg->line_outs == 2)
2303 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002304 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002305 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002306 /* for multi-io case, only the primary out */
2307 if (ch && spec->multi_ios)
2308 break;
2309 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002310 return "Headphone";
2311 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002312 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002313 return "PCM";
2314 break;
2315 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002316 if (ch >= ARRAY_SIZE(channel_name)) {
2317 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002318 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002319 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002320
2321 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002322}
2323
Takashi Iwai83012a72012-08-24 18:38:08 +02002324#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002325/* add the powersave loopback-list entry */
2326static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2327{
2328 struct hda_amp_list *list;
2329
2330 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2331 return;
2332 list = spec->loopback_list + spec->num_loopbacks;
2333 list->nid = mix;
2334 list->dir = HDA_INPUT;
2335 list->idx = idx;
2336 spec->num_loopbacks++;
2337 spec->loopback.amplist = spec->loopback_list;
2338}
2339#else
2340#define add_loopback_list(spec, mix, idx) /* NOP */
2341#endif
2342
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002343/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002344static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002345 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002346 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002347{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002348 struct alc_spec *spec = codec->spec;
2349 struct nid_path *path;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002350 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002351 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002352
Takashi Iwaibd32f782012-12-12 18:08:52 +01002353 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2354 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2355 return 0; /* no need for analog loopback */
2356
Takashi Iwai965cceb2012-12-18 11:46:37 +01002357 path = add_new_nid_path(codec, pin, mix_nid, 2);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002358 if (!path)
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002359 return -EINVAL;
2360
2361 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002362 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002363 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2364 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002365 if (err < 0)
2366 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002367 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002368 }
2369
2370 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002371 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2372 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002373 if (err < 0)
2374 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002375 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002376 }
2377
Takashi Iwai829f69e2012-12-14 18:26:02 +01002378 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002379 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002380 return 0;
2381}
2382
Takashi Iwai05f5f472009-08-25 13:10:18 +02002383static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002384{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002385 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2386 return (pincap & AC_PINCAP_IN) != 0;
2387}
2388
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002389/* check whether the given two widgets can be connected */
2390static bool is_reachable_path(struct hda_codec *codec,
2391 hda_nid_t from_nid, hda_nid_t to_nid)
2392{
2393 if (!from_nid || !to_nid)
2394 return false;
2395 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2396}
2397
Takashi Iwai666a70d2012-12-17 20:29:29 +01002398/* Parse the codec tree and retrieve ADCs */
2399static int alc_auto_fill_adc_nids(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002400{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002401 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002402 hda_nid_t nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002403 hda_nid_t *adc_nids = spec->adc_nids;
2404 int max_nums = ARRAY_SIZE(spec->adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002405 int i, nums = 0;
2406
2407 nid = codec->start_nid;
2408 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwaib7821702011-07-06 15:12:46 +02002409 unsigned int caps = get_wcaps(codec, nid);
2410 int type = get_wcaps_type(caps);
2411
2412 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2413 continue;
2414 adc_nids[nums] = nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002415 if (++nums >= max_nums)
2416 break;
2417 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002418 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002419 return nums;
2420}
2421
Takashi Iwai666a70d2012-12-17 20:29:29 +01002422/* filter out invalid adc_nids that don't give all active input pins;
2423 * if needed, check whether dynamic ADC-switching is available
2424 */
2425static int check_dyn_adc_switch(struct hda_codec *codec)
2426{
2427 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002428 struct hda_input_mux *imux = &spec->input_mux;
2429 hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)];
Takashi Iwai666a70d2012-12-17 20:29:29 +01002430 int i, n, nums;
2431 hda_nid_t pin, adc;
2432
2433 again:
2434 nums = 0;
2435 for (n = 0; n < spec->num_adc_nids; n++) {
2436 adc = spec->adc_nids[n];
2437 for (i = 0; i < imux->num_items; i++) {
2438 pin = spec->imux_pins[i];
2439 if (!is_reachable_path(codec, pin, adc))
2440 break;
2441 }
2442 if (i >= imux->num_items)
2443 adc_nids[nums++] = adc;
2444 }
2445
2446 if (!nums) {
2447 if (spec->shared_mic_hp) {
2448 spec->shared_mic_hp = 0;
Takashi Iwai27d31532012-12-18 08:57:05 +01002449 imux->num_items = 1;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002450 goto again;
2451 }
2452
2453 /* check whether ADC-switch is possible */
2454 for (i = 0; i < imux->num_items; i++) {
2455 pin = spec->imux_pins[i];
2456 for (n = 0; n < spec->num_adc_nids; n++) {
2457 adc = spec->adc_nids[n];
2458 if (is_reachable_path(codec, pin, adc)) {
2459 spec->dyn_adc_idx[i] = n;
2460 break;
2461 }
2462 }
2463 }
2464
2465 snd_printdd("realtek: enabling ADC switching\n");
2466 spec->dyn_adc_switch = 1;
2467 } else if (nums != spec->num_adc_nids) {
Takashi Iwai27d31532012-12-18 08:57:05 +01002468 memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t));
Takashi Iwai666a70d2012-12-17 20:29:29 +01002469 spec->num_adc_nids = nums;
2470 }
2471
Takashi Iwai27d31532012-12-18 08:57:05 +01002472 if (imux->num_items == 1 || spec->shared_mic_hp) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002473 snd_printdd("realtek: reducing to a single ADC\n");
2474 spec->num_adc_nids = 1; /* reduce to a single ADC */
2475 }
2476
2477 return 0;
2478}
2479
2480/* templates for capture controls */
2481static const struct snd_kcontrol_new cap_src_temp = {
2482 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2483 .name = "Input Source",
2484 .info = alc_mux_enum_info,
2485 .get = alc_mux_enum_get,
2486 .put = alc_mux_enum_put,
2487};
2488
2489static const struct snd_kcontrol_new cap_vol_temp = {
2490 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2491 .name = "Capture Volume",
2492 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2493 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2494 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2495 .info = alc_cap_vol_info,
2496 .get = alc_cap_vol_get,
2497 .put = alc_cap_vol_put,
2498 .tlv = { .c = alc_cap_vol_tlv },
2499};
2500
2501static const struct snd_kcontrol_new cap_sw_temp = {
2502 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2503 .name = "Capture Switch",
2504 .info = alc_cap_sw_info,
2505 .get = alc_cap_sw_get,
2506 .put = alc_cap_sw_put,
2507};
2508
2509static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2510{
2511 hda_nid_t nid;
2512 int i, depth;
2513
2514 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2515 for (depth = 0; depth < 3; depth++) {
2516 if (depth >= path->depth)
2517 return -EINVAL;
2518 i = path->depth - depth - 1;
2519 nid = path->path[i];
2520 if (!path->ctls[NID_PATH_VOL_CTL]) {
2521 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2522 path->ctls[NID_PATH_VOL_CTL] =
2523 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2524 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2525 int idx = path->idx[i];
2526 if (!depth && codec->single_adc_amp)
2527 idx = 0;
2528 path->ctls[NID_PATH_VOL_CTL] =
2529 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2530 }
2531 }
2532 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2533 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2534 path->ctls[NID_PATH_MUTE_CTL] =
2535 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2536 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2537 int idx = path->idx[i];
2538 if (!depth && codec->single_adc_amp)
2539 idx = 0;
2540 path->ctls[NID_PATH_MUTE_CTL] =
2541 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2542 }
2543 }
2544 }
2545 return 0;
2546}
2547
2548static int create_capture_mixers(struct hda_codec *codec)
2549{
2550 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002551 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002552 struct snd_kcontrol_new *knew;
2553 int i, n, nums;
2554
2555 if (spec->dyn_adc_switch)
2556 nums = 1;
2557 else
2558 nums = spec->num_adc_nids;
2559
2560 if (!spec->auto_mic && imux->num_items > 1) {
Takashi Iwaibc549762012-12-18 15:35:11 +01002561 knew = alc_kcontrol_new(spec, NULL, &cap_src_temp);
Takashi Iwai666a70d2012-12-17 20:29:29 +01002562 if (!knew)
2563 return -ENOMEM;
2564 knew->count = nums;
2565 }
2566
2567 for (n = 0; n < nums; n++) {
2568 int vol, sw;
2569
2570 vol = sw = 0;
2571 for (i = 0; i < imux->num_items; i++) {
2572 struct nid_path *path;
2573 path = get_nid_path(codec, spec->imux_pins[i],
2574 get_adc_nid(codec, n, i));
2575 if (!path)
2576 continue;
2577 parse_capvol_in_path(codec, path);
2578 if (!vol)
2579 vol = path->ctls[NID_PATH_VOL_CTL];
2580 if (!sw)
2581 sw = path->ctls[NID_PATH_MUTE_CTL];
2582 }
2583
2584 if (vol) {
Takashi Iwaibc549762012-12-18 15:35:11 +01002585 knew = alc_kcontrol_new(spec, NULL, &cap_vol_temp);
Takashi Iwai666a70d2012-12-17 20:29:29 +01002586 if (!knew)
2587 return -ENOMEM;
2588 knew->index = n;
2589 knew->private_value = vol;
2590 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2591 }
2592 if (sw) {
Takashi Iwaibc549762012-12-18 15:35:11 +01002593 knew = alc_kcontrol_new(spec, NULL, &cap_sw_temp);
Takashi Iwai666a70d2012-12-17 20:29:29 +01002594 if (!knew)
2595 return -ENOMEM;
2596 knew->index = n;
2597 knew->private_value = sw;
2598 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2599 }
2600 }
2601
2602 return 0;
2603}
2604
Takashi Iwai05f5f472009-08-25 13:10:18 +02002605/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002606static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002607{
2608 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002609 const struct auto_pin_cfg *cfg = &spec->autocfg;
2610 hda_nid_t mixer = spec->mixer_nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002611 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwaib7821702011-07-06 15:12:46 +02002612 int num_adcs;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002613 int i, c, err, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002614 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002615
Takashi Iwai666a70d2012-12-17 20:29:29 +01002616 num_adcs = alc_auto_fill_adc_nids(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002617 if (num_adcs < 0)
2618 return 0;
2619
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002620 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002621 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002622 const char *label;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002623 bool imux_added;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002624
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002625 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002626 if (!alc_is_input_pin(codec, pin))
2627 continue;
2628
David Henningsson5322bf22011-01-05 11:03:56 +01002629 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002630 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2631 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002632 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002633 type_idx++;
2634 else
2635 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002636 prev_label = label;
2637
Takashi Iwai05f5f472009-08-25 13:10:18 +02002638 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002639 if (is_reachable_path(codec, pin, mixer)) {
2640 err = new_analog_input(codec, pin,
2641 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002642 if (err < 0)
2643 return err;
2644 }
2645 }
2646
Takashi Iwai666a70d2012-12-17 20:29:29 +01002647 imux_added = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002648 for (c = 0; c < num_adcs; c++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002649 struct nid_path *path;
2650 hda_nid_t adc = spec->adc_nids[c];
2651
2652 if (!is_reachable_path(codec, pin, adc))
2653 continue;
2654 path = snd_array_new(&spec->paths);
2655 if (!path)
2656 return -ENOMEM;
2657 memset(path, 0, sizeof(*path));
2658 if (!parse_nid_path(codec, pin, adc, 2, path)) {
2659 snd_printd(KERN_ERR
2660 "invalid input path 0x%x -> 0x%x\n",
2661 pin, adc);
2662 spec->paths.used--;
2663 continue;
2664 }
2665
2666 if (!imux_added) {
2667 spec->imux_pins[imux->num_items] = pin;
2668 snd_hda_add_imux_item(imux, label,
2669 imux->num_items, NULL);
2670 imux_added = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002671 }
2672 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002673 }
Takashi Iwai21268962011-07-07 15:01:13 +02002674
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002675 return 0;
2676}
2677
Takashi Iwai24de1832011-11-07 17:13:39 +01002678/* create a shared input with the headphone out */
2679static int alc_auto_create_shared_input(struct hda_codec *codec)
2680{
2681 struct alc_spec *spec = codec->spec;
2682 struct auto_pin_cfg *cfg = &spec->autocfg;
2683 unsigned int defcfg;
2684 hda_nid_t nid;
2685
2686 /* only one internal input pin? */
2687 if (cfg->num_inputs != 1)
2688 return 0;
2689 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2690 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2691 return 0;
2692
2693 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2694 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2695 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2696 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2697 else
2698 return 0; /* both not available */
2699
2700 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2701 return 0; /* no input */
2702
2703 cfg->inputs[1].pin = nid;
2704 cfg->inputs[1].type = AUTO_PIN_MIC;
2705 cfg->num_inputs = 2;
2706 spec->shared_mic_hp = 1;
2707 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2708 return 0;
2709}
2710
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002711static int get_pin_type(int line_out_type)
2712{
2713 if (line_out_type == AUTO_PIN_HP_OUT)
2714 return PIN_HP;
2715 else
2716 return PIN_OUT;
2717}
2718
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002719static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002720{
2721 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002722 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002723 int i;
2724
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002725 for (i = 0; i < cfg->num_inputs; i++) {
2726 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai62343992012-12-18 09:06:01 +01002727 if (alc_is_input_pin(codec, nid))
Takashi Iwai30ea0982010-09-16 18:47:56 +02002728 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002729
Takashi Iwai829f69e2012-12-14 18:26:02 +01002730 /* mute loopback inputs */
2731 if (spec->mixer_nid) {
2732 struct nid_path *path;
2733 path = get_nid_path(codec, nid, spec->mixer_nid);
2734 if (path)
Takashi Iwai666a70d2012-12-17 20:29:29 +01002735 activate_path(codec, path, path->active, false);
Takashi Iwai829f69e2012-12-14 18:26:02 +01002736 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002737 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002738}
2739
Takashi Iwai185d99f2012-02-16 18:39:45 +01002740static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2741{
2742 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002743 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002744
Takashi Iwaic9967f12012-12-14 16:39:22 +01002745 for (i = 0; i < spec->paths.used; i++) {
2746 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002747 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002748 return true;
2749 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002750 return false;
2751}
2752
Takashi Iwai463419d2012-12-05 14:17:37 +01002753/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002754static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2755 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002756{
2757 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002758 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002759 int i;
2760
2761 for (i = 0; i < spec->num_all_dacs; i++) {
2762 hda_nid_t nid = spec->all_dacs[i];
2763 if (!nid || alc_is_dac_already_used(codec, nid))
2764 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002765 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2766 if (is_digital != cap_digital)
2767 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002768 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002769 return nid;
2770 }
2771 return 0;
2772}
2773
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002774/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002775static bool __parse_nid_path(struct hda_codec *codec,
2776 hda_nid_t from_nid, hda_nid_t to_nid,
2777 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002778{
2779 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002780 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002781 int i, nums;
2782
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002783 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002784 if (!with_aa_mix)
2785 return false;
2786 with_aa_mix = 2; /* mark aa-mix is included */
2787 }
2788
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002789 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002790 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002791 if (conn[i] != from_nid) {
2792 /* special case: when from_nid is 0,
2793 * try to find an empty DAC
2794 */
2795 if (from_nid ||
2796 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2797 alc_is_dac_already_used(codec, conn[i]))
2798 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002799 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002800 /* aa-mix is requested but not included? */
2801 if (!(spec->mixer_nid && with_aa_mix == 1))
2802 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002803 }
2804 if (depth >= MAX_NID_PATH_DEPTH)
2805 return false;
2806 for (i = 0; i < nums; i++) {
2807 unsigned int type;
2808 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002809 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2810 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002811 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002812 if (__parse_nid_path(codec, from_nid, conn[i],
2813 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002814 goto found;
2815 }
2816 return false;
2817
2818 found:
2819 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002820 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002821 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002822 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002823 path->depth++;
2824 return true;
2825}
2826
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002827/* parse the widget path from the given nid to the target nid;
2828 * when @from_nid is 0, try to find an empty DAC;
2829 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2830 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2831 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002832 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002833static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2834 hda_nid_t to_nid, int with_aa_mix,
2835 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002836{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002837 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2838 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002839 path->depth++;
2840#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002841 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002842 path->depth, path->path[0], path->path[1],
2843 path->path[2], path->path[3], path->path[4]);
2844#endif
2845 return true;
2846 }
2847 return false;
2848}
2849
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002850static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2851{
Takashi Iwai140547e2012-02-16 17:23:46 +01002852 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002853 int i;
2854 hda_nid_t nid_found = 0;
2855
2856 for (i = 0; i < spec->num_all_dacs; i++) {
2857 hda_nid_t nid = spec->all_dacs[i];
2858 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002859 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002860 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01002861 if (nid_found)
2862 return 0;
2863 nid_found = nid;
2864 }
2865 }
2866 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002867}
2868
Takashi Iwaiba8111272012-12-06 18:06:23 +01002869static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002870{
Takashi Iwaiba8111272012-12-06 18:06:23 +01002871 struct alc_spec *spec = codec->spec;
2872 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002873
Takashi Iwaic9967f12012-12-14 16:39:22 +01002874 for (i = 0; i < spec->paths.used; i++) {
2875 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002876 if (path->ctls[type] == val)
2877 return true;
2878 }
2879 return false;
2880}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002881
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002882/* badness definition */
2883enum {
2884 /* No primary DAC is found for the main output */
2885 BAD_NO_PRIMARY_DAC = 0x10000,
2886 /* No DAC is found for the extra output */
2887 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01002888 /* No possible multi-ios */
2889 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002890 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01002891 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002892 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01002893 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002894 /* Primary DAC shared with main surrounds */
2895 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002896 /* Primary DAC shared with main CLFE */
2897 BAD_SHARED_CLFE = 0x10,
2898 /* Primary DAC shared with extra surrounds */
2899 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01002900 /* Volume widget is shared */
2901 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002902};
2903
2904static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002905 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002906static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002907 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002908
Takashi Iwai965cceb2012-12-18 11:46:37 +01002909static struct nid_path *add_new_nid_path(struct hda_codec *codec,
2910 hda_nid_t from_nid, hda_nid_t to_nid,
2911 int with_aa_mix)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002912{
2913 struct alc_spec *spec = codec->spec;
2914 struct nid_path *path;
2915
Takashi Iwai965cceb2012-12-18 11:46:37 +01002916 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
2917 return NULL;
2918
Takashi Iwaic9967f12012-12-14 16:39:22 +01002919 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002920 if (!path)
Takashi Iwai965cceb2012-12-18 11:46:37 +01002921 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002922 memset(path, 0, sizeof(*path));
Takashi Iwai965cceb2012-12-18 11:46:37 +01002923 if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path))
2924 return path;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002925 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01002926 spec->paths.used--;
Takashi Iwai965cceb2012-12-18 11:46:37 +01002927 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002928}
2929
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002930/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01002931 * passing 0 to either @pin or @dac behaves as a wildcard
2932 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002933static struct nid_path *
2934get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01002935{
2936 struct alc_spec *spec = codec->spec;
2937 int i;
2938
Takashi Iwaic9967f12012-12-14 16:39:22 +01002939 for (i = 0; i < spec->paths.used; i++) {
2940 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002941 if (path->depth <= 0)
2942 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002943 if ((!from_nid || path->path[0] == from_nid) &&
2944 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01002945 return path;
2946 }
2947 return NULL;
2948}
2949
Takashi Iwai792cf2f2012-12-10 16:04:30 +01002950/* look for widgets in the path between the given NIDs appropriate for
2951 * volume and mute controls, and assign the values to ctls[].
2952 *
2953 * When no appropriate widget is found in the path, the badness value
2954 * is incremented depending on the situation. The function returns the
2955 * total badness for both volume and mute controls.
2956 */
2957static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
2958 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002959{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002960 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002961 hda_nid_t nid;
2962 unsigned int val;
2963 int badness = 0;
2964
Takashi Iwaiba8111272012-12-06 18:06:23 +01002965 if (!path)
2966 return BAD_SHARED_VOL * 2;
2967 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002968 if (nid) {
2969 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002970 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002971 badness += BAD_SHARED_VOL;
2972 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01002973 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002974 } else
2975 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01002976 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002977 if (nid) {
2978 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01002979 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
2980 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002981 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2982 else
2983 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002984 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002985 badness += BAD_SHARED_VOL;
2986 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01002987 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002988 } else
2989 badness += BAD_SHARED_VOL;
2990 return badness;
2991}
2992
Takashi Iwaidc31b582012-02-17 17:27:53 +01002993struct badness_table {
2994 int no_primary_dac; /* no primary DAC */
2995 int no_dac; /* no secondary DACs */
2996 int shared_primary; /* primary DAC is shared with main output */
2997 int shared_surr; /* secondary DAC shared with main or primary */
2998 int shared_clfe; /* third DAC shared with main or primary */
2999 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3000};
3001
3002static struct badness_table main_out_badness = {
3003 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3004 .no_dac = BAD_NO_DAC,
3005 .shared_primary = BAD_NO_PRIMARY_DAC,
3006 .shared_surr = BAD_SHARED_SURROUND,
3007 .shared_clfe = BAD_SHARED_CLFE,
3008 .shared_surr_main = BAD_SHARED_SURROUND,
3009};
3010
3011static struct badness_table extra_out_badness = {
3012 .no_primary_dac = BAD_NO_DAC,
3013 .no_dac = BAD_NO_DAC,
3014 .shared_primary = BAD_NO_EXTRA_DAC,
3015 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3016 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3017 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3018};
3019
3020/* try to assign DACs to pins and return the resultant badness */
3021static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3022 const hda_nid_t *pins, hda_nid_t *dacs,
3023 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003024{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003025 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003026 struct auto_pin_cfg *cfg = &spec->autocfg;
3027 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003028 int badness = 0;
3029 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003030
Takashi Iwai185d99f2012-02-16 18:39:45 +01003031 if (!num_outs)
3032 return 0;
3033
Takashi Iwaidc31b582012-02-17 17:27:53 +01003034 for (i = 0; i < num_outs; i++) {
3035 hda_nid_t pin = pins[i];
3036 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003037 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003038 if (!dacs[i] && !i) {
3039 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003040 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003041 dacs[0] = dacs[j];
3042 dacs[j] = 0;
3043 break;
3044 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003045 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003046 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003047 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003048 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003049 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003050 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003051 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003052 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003053 dac = spec->private_dac_nids[i];
3054 if (dac) {
3055 if (!i)
3056 badness += bad->shared_primary;
3057 else if (i == 1)
3058 badness += bad->shared_surr;
3059 else
3060 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003061 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003062 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003063 badness += bad->shared_surr_main;
3064 } else if (!i)
3065 badness += bad->no_primary_dac;
3066 else
3067 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003068 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003069 if (!add_new_nid_path(codec, dac, pin, 0))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003070 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003071 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003072 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003073 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003074
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003075 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003076}
3077
3078static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003079 hda_nid_t reference_pin,
3080 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003081
Takashi Iwai185d99f2012-02-16 18:39:45 +01003082static bool alc_map_singles(struct hda_codec *codec, int outs,
3083 const hda_nid_t *pins, hda_nid_t *dacs)
3084{
3085 int i;
3086 bool found = false;
3087 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003088 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003089 if (dacs[i])
3090 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003091 dac = get_dac_if_single(codec, pins[i]);
3092 if (!dac)
3093 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003094 if (add_new_nid_path(codec, dac, pins[i], 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003095 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003096 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003097 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003098 }
3099 return found;
3100}
3101
Takashi Iwai7085ec12009-10-02 09:03:58 +02003102/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003103static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003104 bool fill_hardwired,
3105 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003106{
3107 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003108 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003109 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003110
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003111 /* set num_dacs once to full for alc_auto_look_for_dac() */
3112 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003113 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003114 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3115 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3116 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003117 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003118 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003119 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003120
3121 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003122 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003123 bool mapped;
3124 do {
3125 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003126 cfg->line_out_pins,
3127 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003128 mapped |= alc_map_singles(codec, cfg->hp_outs,
3129 cfg->hp_pins,
3130 spec->multiout.hp_out_nid);
3131 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3132 cfg->speaker_pins,
3133 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003134 if (fill_mio_first && cfg->line_outs == 1 &&
3135 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3136 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3137 if (!err)
3138 mapped = true;
3139 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003140 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003141 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003142
Takashi Iwaidc31b582012-02-17 17:27:53 +01003143 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3144 spec->private_dac_nids,
3145 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003146
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003147 /* re-count num_dacs and squash invalid entries */
3148 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003149 for (i = 0; i < cfg->line_outs; i++) {
3150 if (spec->private_dac_nids[i])
3151 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003152 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003153 memmove(spec->private_dac_nids + i,
3154 spec->private_dac_nids + i + 1,
3155 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003156 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3157 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003158 }
3159
Takashi Iwai276dd702012-02-17 16:17:03 +01003160 if (fill_mio_first &&
3161 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003162 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003163 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003164 if (err < 0)
3165 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003166 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003167 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003168
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003169 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003170 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3171 spec->multiout.hp_out_nid,
3172 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003173 if (err < 0)
3174 return err;
3175 badness += err;
3176 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003177 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003178 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3179 cfg->speaker_pins,
3180 spec->multiout.extra_out_nid,
3181 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003182 if (err < 0)
3183 return err;
3184 badness += err;
3185 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003186 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3187 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003188 if (err < 0)
3189 return err;
3190 badness += err;
3191 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003192 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3193 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003194 int offset = 0;
3195 if (cfg->line_outs >= 3)
3196 offset = 1;
3197 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3198 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003199 if (err < 0)
3200 return err;
3201 badness += err;
3202 }
3203
3204 if (spec->multi_ios == 2) {
3205 for (i = 0; i < 2; i++)
3206 spec->private_dac_nids[spec->multiout.num_dacs++] =
3207 spec->multi_io[i].dac;
3208 spec->ext_channel_count = 2;
3209 } else if (spec->multi_ios) {
3210 spec->multi_ios = 0;
3211 badness += BAD_MULTI_IO;
3212 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003213
3214 return badness;
3215}
3216
3217#define DEBUG_BADNESS
3218
3219#ifdef DEBUG_BADNESS
3220#define debug_badness snd_printdd
3221#else
3222#define debug_badness(...)
3223#endif
3224
3225static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3226{
3227 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3228 cfg->line_out_pins[0], cfg->line_out_pins[1],
3229 cfg->line_out_pins[2], cfg->line_out_pins[2],
3230 spec->multiout.dac_nids[0],
3231 spec->multiout.dac_nids[1],
3232 spec->multiout.dac_nids[2],
3233 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003234 if (spec->multi_ios > 0)
3235 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3236 spec->multi_ios,
3237 spec->multi_io[0].pin, spec->multi_io[1].pin,
3238 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003239 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3240 cfg->hp_pins[0], cfg->hp_pins[1],
3241 cfg->hp_pins[2], cfg->hp_pins[2],
3242 spec->multiout.hp_out_nid[0],
3243 spec->multiout.hp_out_nid[1],
3244 spec->multiout.hp_out_nid[2],
3245 spec->multiout.hp_out_nid[3]);
3246 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3247 cfg->speaker_pins[0], cfg->speaker_pins[1],
3248 cfg->speaker_pins[2], cfg->speaker_pins[3],
3249 spec->multiout.extra_out_nid[0],
3250 spec->multiout.extra_out_nid[1],
3251 spec->multiout.extra_out_nid[2],
3252 spec->multiout.extra_out_nid[3]);
3253}
3254
Takashi Iwai463419d2012-12-05 14:17:37 +01003255/* find all available DACs of the codec */
3256static void alc_fill_all_nids(struct hda_codec *codec)
3257{
3258 struct alc_spec *spec = codec->spec;
3259 int i;
3260 hda_nid_t nid = codec->start_nid;
3261
3262 spec->num_all_dacs = 0;
3263 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3264 for (i = 0; i < codec->num_nodes; i++, nid++) {
3265 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3266 continue;
3267 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3268 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3269 break;
3270 }
3271 spec->all_dacs[spec->num_all_dacs++] = nid;
3272 }
3273}
3274
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003275static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3276{
3277 struct alc_spec *spec = codec->spec;
3278 struct auto_pin_cfg *cfg = &spec->autocfg;
3279 struct auto_pin_cfg *best_cfg;
3280 int best_badness = INT_MAX;
3281 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003282 bool fill_hardwired = true, fill_mio_first = true;
3283 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003284 bool hp_spk_swapped = false;
3285
Takashi Iwai463419d2012-12-05 14:17:37 +01003286 alc_fill_all_nids(codec);
3287
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003288 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3289 if (!best_cfg)
3290 return -ENOMEM;
3291 *best_cfg = *cfg;
3292
3293 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003294 badness = fill_and_eval_dacs(codec, fill_hardwired,
3295 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003296 if (badness < 0) {
3297 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003298 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003299 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003300 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3301 cfg->line_out_type, fill_hardwired, fill_mio_first,
3302 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003303 debug_show_configs(spec, cfg);
3304 if (badness < best_badness) {
3305 best_badness = badness;
3306 *best_cfg = *cfg;
3307 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003308 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003309 }
3310 if (!badness)
3311 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003312 fill_mio_first = !fill_mio_first;
3313 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003314 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003315 fill_hardwired = !fill_hardwired;
3316 if (!fill_hardwired)
3317 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003318 if (hp_spk_swapped)
3319 break;
3320 hp_spk_swapped = true;
3321 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003322 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3323 cfg->hp_outs = cfg->line_outs;
3324 memcpy(cfg->hp_pins, cfg->line_out_pins,
3325 sizeof(cfg->hp_pins));
3326 cfg->line_outs = cfg->speaker_outs;
3327 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3328 sizeof(cfg->speaker_pins));
3329 cfg->speaker_outs = 0;
3330 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3331 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003332 fill_hardwired = true;
3333 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003334 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003335 if (cfg->hp_outs > 0 &&
3336 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3337 cfg->speaker_outs = cfg->line_outs;
3338 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3339 sizeof(cfg->speaker_pins));
3340 cfg->line_outs = cfg->hp_outs;
3341 memcpy(cfg->line_out_pins, cfg->hp_pins,
3342 sizeof(cfg->hp_pins));
3343 cfg->hp_outs = 0;
3344 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3345 cfg->line_out_type = AUTO_PIN_HP_OUT;
3346 fill_hardwired = true;
3347 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003348 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003349 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003350 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003351
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003352 if (badness) {
3353 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003354 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003355 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003356 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3357 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003358 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003359
Takashi Iwaiba8111272012-12-06 18:06:23 +01003360 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003361 struct nid_path *path = get_nid_path(codec,
3362 spec->multiout.dac_nids[0],
3363 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003364 if (path)
3365 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3366 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003367
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003368 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003369 return 0;
3370}
3371
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003372/* replace the channels in the composed amp value with the given number */
3373static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3374{
3375 val &= ~(0x3U << 16);
3376 val |= chs << 16;
3377 return val;
3378}
3379
Takashi Iwai343a04b2011-07-06 14:28:39 +02003380static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003381 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003382 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003383 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003384{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003385 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003386 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003387 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003388 val = path->ctls[NID_PATH_VOL_CTL];
3389 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003390 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003391 val = amp_val_replace_channels(val, chs);
3392 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3393}
3394
3395/* return the channel bits suitable for the given path->ctls[] */
3396static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3397 int type)
3398{
3399 int chs = 1; /* mono (left only) */
3400 if (path) {
3401 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3402 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3403 chs = 3; /* stereo */
3404 }
3405 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003406}
3407
Takashi Iwaie29d3772011-11-14 17:13:23 +01003408static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3409 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003410 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003411{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003412 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3413 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003414}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003415
3416/* create a mute-switch for the given mixer widget;
3417 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3418 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003419static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003420 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003421 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003422 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003423{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003424 unsigned int val;
3425 int type = ALC_CTL_WIDGET_MUTE;
3426
3427 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003428 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003429 val = path->ctls[NID_PATH_MUTE_CTL];
3430 if (!val)
3431 return 0;
3432 val = amp_val_replace_channels(val, chs);
3433 if (get_amp_direction_(val) == HDA_INPUT) {
3434 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003435 int nums = snd_hda_get_num_conns(codec, nid);
3436 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003437 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003438 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003439 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003440 }
3441 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003442}
3443
Takashi Iwaie29d3772011-11-14 17:13:23 +01003444static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003445 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003446{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003447 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3448 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003449}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003450
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003451static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003452 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003453{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003454 int i;
3455
3456 for (i = path->depth - 1; i >= 0; i--) {
3457 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3458 return path->path[i];
3459 if (i != path->depth - 1 && i != 0 &&
3460 nid_has_mute(codec, path->path[i], HDA_INPUT))
3461 return path->path[i];
3462 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003463 return 0;
3464}
3465
3466static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003467 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003468{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003469 int i;
3470
3471 for (i = path->depth - 1; i >= 0; i--) {
3472 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3473 return path->path[i];
3474 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003475 return 0;
3476}
3477
Takashi Iwai7085ec12009-10-02 09:03:58 +02003478/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003479static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003480 const struct auto_pin_cfg *cfg)
3481{
3482 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003483 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003484
Takashi Iwaice764ab2011-04-27 16:35:23 +02003485 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003486 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003487 noutputs += spec->multi_ios;
3488
3489 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003490 const char *name;
3491 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003492 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003493 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003494
3495 dac = spec->multiout.dac_nids[i];
3496 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003497 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003498 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003499 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003500 index = 0;
3501 name = channel_name[i];
3502 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003503 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003504 name = alc_get_line_out_pfx(spec, i, true, &index);
3505 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003506
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003507 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003508 if (!path)
3509 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003510 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003511 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003512 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003513 if (err < 0)
3514 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003515 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003516 if (err < 0)
3517 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003518 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003519 if (err < 0)
3520 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003521 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003522 if (err < 0)
3523 return err;
3524 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003525 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003526 if (err < 0)
3527 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003528 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003529 if (err < 0)
3530 return err;
3531 }
3532 }
3533 return 0;
3534}
3535
Takashi Iwai343a04b2011-07-06 14:28:39 +02003536static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003537 hda_nid_t dac, const char *pfx,
3538 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003539{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003540 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003541 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003542
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003543 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003544 if (!path)
3545 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003546 /* bind volume control will be created in the case of dac = 0 */
3547 if (dac) {
3548 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3549 if (err < 0)
3550 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003551 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003552 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003553 if (err < 0)
3554 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003555 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003556}
3557
Takashi Iwai23c09b02011-08-19 09:05:35 +02003558static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3559 unsigned int nums,
3560 struct hda_ctl_ops *ops)
3561{
3562 struct alc_spec *spec = codec->spec;
3563 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003564 ctlp = snd_array_new(&spec->bind_ctls);
3565 if (!ctlp)
3566 return NULL;
3567 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3568 *ctlp = ctl;
3569 if (ctl)
3570 ctl->ops = ops;
3571 return ctl;
3572}
3573
3574/* add playback controls for speaker and HP outputs */
3575static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3576 const hda_nid_t *pins,
3577 const hda_nid_t *dacs,
3578 const char *pfx)
3579{
3580 struct alc_spec *spec = codec->spec;
3581 struct hda_bind_ctls *ctl;
3582 char name[32];
3583 int i, n, err;
3584
3585 if (!num_pins || !pins[0])
3586 return 0;
3587
Takashi Iwai527e4d72011-10-27 16:33:27 +02003588 if (num_pins == 1) {
3589 hda_nid_t dac = *dacs;
3590 if (!dac)
3591 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003592 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003593 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003594
Takashi Iwai23c09b02011-08-19 09:05:35 +02003595 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003596 hda_nid_t dac;
3597 if (dacs[num_pins - 1])
3598 dac = dacs[i]; /* with individual volumes */
3599 else
3600 dac = 0;
3601 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3602 err = alc_auto_create_extra_out(codec, pins[i], dac,
3603 "Bass Speaker", 0);
3604 } else if (num_pins >= 3) {
3605 snprintf(name, sizeof(name), "%s %s",
3606 pfx, channel_name[i]);
3607 err = alc_auto_create_extra_out(codec, pins[i], dac,
3608 name, 0);
3609 } else {
3610 err = alc_auto_create_extra_out(codec, pins[i], dac,
3611 pfx, i);
3612 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003613 if (err < 0)
3614 return err;
3615 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003616 if (dacs[num_pins - 1])
3617 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003618
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003619 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003620 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3621 if (!ctl)
3622 return -ENOMEM;
3623 n = 0;
3624 for (i = 0; i < num_pins; i++) {
3625 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003626 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003627 if (!pins[i] || !dacs[i])
3628 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003629 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003630 if (!path)
3631 continue;
3632 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003633 if (vol)
3634 ctl->values[n++] =
3635 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3636 }
3637 if (n) {
3638 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3639 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3640 if (err < 0)
3641 return err;
3642 }
3643 return 0;
3644}
3645
Takashi Iwai343a04b2011-07-06 14:28:39 +02003646static int alc_auto_create_hp_out(struct hda_codec *codec)
3647{
3648 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003649 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3650 spec->autocfg.hp_pins,
3651 spec->multiout.hp_out_nid,
3652 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003653}
3654
3655static int alc_auto_create_speaker_out(struct hda_codec *codec)
3656{
3657 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003658 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3659 spec->autocfg.speaker_pins,
3660 spec->multiout.extra_out_nid,
3661 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003662}
3663
Takashi Iwai130e5f02012-12-14 16:09:29 +01003664/* check whether a control with the given (nid, dir, idx) was assigned */
3665static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3666 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003667{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003668 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003669 int i, type;
3670
3671 for (i = 0; i < spec->paths.used; i++) {
3672 struct nid_path *p = snd_array_elem(&spec->paths, i);
3673 if (p->depth <= 0)
3674 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003675 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003676 unsigned int val = p->ctls[type];
3677 if (get_amp_nid_(val) == nid &&
3678 get_amp_direction_(val) == dir &&
3679 get_amp_index_(val) == idx)
3680 return true;
3681 }
3682 }
3683 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003684}
3685
3686/* can have the amp-in capability? */
3687static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3688{
3689 hda_nid_t nid = path->path[idx];
3690 unsigned int caps = get_wcaps(codec, nid);
3691 unsigned int type = get_wcaps_type(caps);
3692
3693 if (!(caps & AC_WCAP_IN_AMP))
3694 return false;
3695 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3696 return false;
3697 return true;
3698}
3699
3700/* can have the amp-out capability? */
3701static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3702{
3703 hda_nid_t nid = path->path[idx];
3704 unsigned int caps = get_wcaps(codec, nid);
3705 unsigned int type = get_wcaps_type(caps);
3706
3707 if (!(caps & AC_WCAP_OUT_AMP))
3708 return false;
3709 if (type == AC_WID_PIN && !idx) /* only for output pins */
3710 return false;
3711 return true;
3712}
3713
Takashi Iwaic9967f12012-12-14 16:39:22 +01003714/* check whether the given (nid,dir,idx) is active */
3715static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3716 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003717{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003718 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003719 int i, n;
3720
Takashi Iwaic9967f12012-12-14 16:39:22 +01003721 for (n = 0; n < spec->paths.used; n++) {
3722 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003723 if (!path->active)
3724 continue;
3725 for (i = 0; i < path->depth; i++) {
3726 if (path->path[i] == nid) {
3727 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3728 return true;
3729 break;
3730 }
3731 }
3732 }
3733 return false;
3734}
3735
Takashi Iwai130e5f02012-12-14 16:09:29 +01003736/* get the default amp value for the target state */
3737static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3738 int dir, bool enable)
3739{
3740 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003741 unsigned int val = 0;
3742
3743 caps = query_amp_caps(codec, nid, dir);
3744 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003745 /* set to 0dB */
3746 if (enable)
3747 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003748 }
3749 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003750 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003751 val |= HDA_AMP_MUTE;
3752 }
3753 return val;
3754}
3755
Takashi Iwai130e5f02012-12-14 16:09:29 +01003756/* initialize the amp value (only at the first time) */
3757static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3758{
3759 int val = get_amp_val_to_activate(codec, nid, dir, false);
3760 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3761}
3762
3763static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3764 int idx, bool enable)
3765{
3766 int val;
3767 if (is_ctl_associated(codec, nid, dir, idx) ||
3768 is_active_nid(codec, nid, dir, idx))
3769 return;
3770 val = get_amp_val_to_activate(codec, nid, dir, enable);
3771 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3772}
3773
3774static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3775 int i, bool enable)
3776{
3777 hda_nid_t nid = path->path[i];
3778 init_amp(codec, nid, HDA_OUTPUT, 0);
3779 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3780}
3781
3782static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003783 int i, bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003784{
3785 struct alc_spec *spec = codec->spec;
3786 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003787 int n, nums, idx;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003788 int type;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003789 hda_nid_t nid = path->path[i];
3790
3791 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai666a70d2012-12-17 20:29:29 +01003792 type = get_wcaps_type(get_wcaps(codec, nid));
3793 if (type == AC_WID_PIN ||
3794 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003795 nums = 1;
3796 idx = 0;
3797 } else
3798 idx = path->idx[i];
3799
Takashi Iwai130e5f02012-12-14 16:09:29 +01003800 for (n = 0; n < nums; n++)
3801 init_amp(codec, nid, HDA_INPUT, n);
3802
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003803 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003804 return;
3805
3806 /* here is a little bit tricky in comparison with activate_amp_out();
3807 * when aa-mixer is available, we need to enable the path as well
3808 */
3809 for (n = 0; n < nums; n++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01003810 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003811 continue;
3812 activate_amp(codec, nid, HDA_INPUT, n, enable);
3813 }
3814}
3815
3816static void activate_path(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003817 bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003818{
3819 int i;
3820
Takashi Iwai130e5f02012-12-14 16:09:29 +01003821 if (!enable)
3822 path->active = false;
3823
3824 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003825 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003826 snd_hda_codec_write_cache(codec, path->path[i], 0,
3827 AC_VERB_SET_CONNECT_SEL,
3828 path->idx[i]);
3829 if (has_amp_in(codec, path, i))
Takashi Iwai666a70d2012-12-17 20:29:29 +01003830 activate_amp_in(codec, path, i, enable, add_aamix);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003831 if (has_amp_out(codec, path, i))
3832 activate_amp_out(codec, path, i, enable);
3833 }
3834
3835 if (enable)
3836 path->active = true;
3837}
3838
Takashi Iwai78e635c2012-12-10 17:07:16 +01003839/* configure the path from the given dac to the pin as the proper output */
3840static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3841 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003842 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003843{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003844 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003845
Takashi Iwai130e5f02012-12-14 16:09:29 +01003846 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003847 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003848 if (!path)
3849 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003850 if (path->active)
3851 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003852 activate_path(codec, path, true, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003853}
3854
Takashi Iwai343a04b2011-07-06 14:28:39 +02003855static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003856{
3857 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003858 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003859 int i;
3860
3861 for (i = 0; i <= HDA_SIDE; i++) {
3862 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3863 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003864 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003865 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003866
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003867 }
3868}
3869
Takashi Iwai343a04b2011-07-06 14:28:39 +02003870static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003871{
3872 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003873 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003874 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003875
David Henningsson636030e2011-10-12 19:26:03 +02003876 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003877 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3878 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003879 pin = spec->autocfg.hp_pins[i];
3880 if (!pin)
3881 break;
3882 dac = spec->multiout.hp_out_nid[i];
3883 if (!dac) {
3884 if (i > 0 && spec->multiout.hp_out_nid[0])
3885 dac = spec->multiout.hp_out_nid[0];
3886 else
3887 dac = spec->multiout.dac_nids[0];
3888 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003889 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003890 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003891 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003892 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3893 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003894 pin = spec->autocfg.speaker_pins[i];
3895 if (!pin)
3896 break;
3897 dac = spec->multiout.extra_out_nid[i];
3898 if (!dac) {
3899 if (i > 0 && spec->multiout.extra_out_nid[0])
3900 dac = spec->multiout.extra_out_nid[0];
3901 else
3902 dac = spec->multiout.dac_nids[0];
3903 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003904 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003905 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003906}
3907
Takashi Iwai276dd702012-02-17 16:17:03 +01003908/* check whether the given pin can be a multi-io pin */
3909static bool can_be_multiio_pin(struct hda_codec *codec,
3910 unsigned int location, hda_nid_t nid)
3911{
3912 unsigned int defcfg, caps;
3913
3914 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3915 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3916 return false;
3917 if (location && get_defcfg_location(defcfg) != location)
3918 return false;
3919 caps = snd_hda_query_pin_caps(codec, nid);
3920 if (!(caps & AC_PINCAP_OUT))
3921 return false;
3922 return true;
3923}
3924
Takashi Iwaice764ab2011-04-27 16:35:23 +02003925/*
3926 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003927 *
3928 * When hardwired is set, try to fill ony hardwired pins, and returns
3929 * zero if any pins are filled, non-zero if nothing found.
3930 * When hardwired is off, try to fill possible input pins, and returns
3931 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003932 */
3933static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003934 hda_nid_t reference_pin,
3935 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003936{
3937 struct alc_spec *spec = codec->spec;
3938 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003939 int type, i, j, dacs, num_pins, old_pins;
3940 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3941 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003942 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003943
Takashi Iwai276dd702012-02-17 16:17:03 +01003944 old_pins = spec->multi_ios;
3945 if (old_pins >= 2)
3946 goto end_fill;
3947
3948 num_pins = 0;
3949 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3950 for (i = 0; i < cfg->num_inputs; i++) {
3951 if (cfg->inputs[i].type != type)
3952 continue;
3953 if (can_be_multiio_pin(codec, location,
3954 cfg->inputs[i].pin))
3955 num_pins++;
3956 }
3957 }
3958 if (num_pins < 2)
3959 goto end_fill;
3960
Takashi Iwai07b18f62011-11-10 15:42:54 +01003961 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003962 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3963 for (i = 0; i < cfg->num_inputs; i++) {
3964 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003965 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003966
Takashi Iwaice764ab2011-04-27 16:35:23 +02003967 if (cfg->inputs[i].type != type)
3968 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003969 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003970 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003971 for (j = 0; j < spec->multi_ios; j++) {
3972 if (nid == spec->multi_io[j].pin)
3973 break;
3974 }
3975 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003976 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003977
3978 if (offset && offset + spec->multi_ios < dacs) {
3979 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01003980 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01003981 dac = 0;
3982 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003983 if (hardwired)
3984 dac = get_dac_if_single(codec, nid);
3985 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003986 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003987 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003988 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003989 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003990 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003991 if (!add_new_nid_path(codec, dac, nid, 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003992 badness++;
3993 continue;
3994 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003995 spec->multi_io[spec->multi_ios].pin = nid;
3996 spec->multi_io[spec->multi_ios].dac = dac;
3997 spec->multi_ios++;
3998 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003999 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004000 }
4001 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004002 end_fill:
4003 if (badness)
4004 badness = BAD_MULTI_IO;
4005 if (old_pins == spec->multi_ios) {
4006 if (hardwired)
4007 return 1; /* nothing found */
4008 else
4009 return badness; /* no badness if nothing found */
4010 }
4011 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004012 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004013 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004014 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004015 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004016 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004017
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004018 /* assign volume and mute controls */
4019 for (i = old_pins; i < spec->multi_ios; i++)
4020 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4021 spec->multi_io[i].dac);
4022
4023 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004024}
4025
4026static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4027 struct snd_ctl_elem_info *uinfo)
4028{
4029 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4030 struct alc_spec *spec = codec->spec;
4031
4032 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4033 uinfo->count = 1;
4034 uinfo->value.enumerated.items = spec->multi_ios + 1;
4035 if (uinfo->value.enumerated.item > spec->multi_ios)
4036 uinfo->value.enumerated.item = spec->multi_ios;
4037 sprintf(uinfo->value.enumerated.name, "%dch",
4038 (uinfo->value.enumerated.item + 1) * 2);
4039 return 0;
4040}
4041
4042static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4043 struct snd_ctl_elem_value *ucontrol)
4044{
4045 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4046 struct alc_spec *spec = codec->spec;
4047 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4048 return 0;
4049}
4050
4051static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4052{
4053 struct alc_spec *spec = codec->spec;
4054 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004055 struct nid_path *path;
4056
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004057 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004058 if (!path)
4059 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004060
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004061 if (path->active == output)
4062 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004063
Takashi Iwaice764ab2011-04-27 16:35:23 +02004064 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004065 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004066 activate_path(codec, path, true, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004067 } else {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004068 activate_path(codec, path, false, true);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004069 snd_hda_set_pin_ctl_cache(codec, nid,
4070 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004071 }
4072 return 0;
4073}
4074
4075static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4076 struct snd_ctl_elem_value *ucontrol)
4077{
4078 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4079 struct alc_spec *spec = codec->spec;
4080 int i, ch;
4081
4082 ch = ucontrol->value.enumerated.item[0];
4083 if (ch < 0 || ch > spec->multi_ios)
4084 return -EINVAL;
4085 if (ch == (spec->ext_channel_count - 1) / 2)
4086 return 0;
4087 spec->ext_channel_count = (ch + 1) * 2;
4088 for (i = 0; i < spec->multi_ios; i++)
4089 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004090 spec->multiout.max_channels = max(spec->ext_channel_count,
4091 spec->const_channel_count);
4092 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004093 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004094 return 1;
4095}
4096
Takashi Iwaia9111322011-05-02 11:30:18 +02004097static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004098 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4099 .name = "Channel Mode",
4100 .info = alc_auto_ch_mode_info,
4101 .get = alc_auto_ch_mode_get,
4102 .put = alc_auto_ch_mode_put,
4103};
4104
Takashi Iwai23c09b02011-08-19 09:05:35 +02004105static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004106{
4107 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004108
Takashi Iwaic2674682011-08-24 17:57:44 +02004109 if (spec->multi_ios > 0) {
Takashi Iwaibc549762012-12-18 15:35:11 +01004110 if (!alc_kcontrol_new(spec, NULL, &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004111 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004112 }
4113 return 0;
4114}
4115
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004116static void alc_auto_init_multi_io(struct hda_codec *codec)
4117{
4118 struct alc_spec *spec = codec->spec;
4119 int i;
4120
4121 for (i = 0; i < spec->multi_ios; i++) {
4122 hda_nid_t pin = spec->multi_io[i].pin;
4123 struct nid_path *path;
4124 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4125 if (!path)
4126 continue;
4127 if (!spec->multi_io[i].ctl_in)
4128 spec->multi_io[i].ctl_in =
4129 snd_hda_codec_update_cache(codec, pin, 0,
4130 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004131 activate_path(codec, path, path->active, true);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004132 }
4133}
4134
Takashi Iwai1d045db2011-07-07 18:23:21 +02004135/*
4136 * initialize ADC paths
4137 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004138static void alc_auto_init_input_src(struct hda_codec *codec)
4139{
4140 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01004141 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004142 struct nid_path *path;
4143 int i, c, nums;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004144
Takashi Iwai1d045db2011-07-07 18:23:21 +02004145 if (spec->dyn_adc_switch)
4146 nums = 1;
4147 else
4148 nums = spec->num_adc_nids;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004149
4150 for (c = 0; c < nums; c++) {
4151 for (i = 0; i < imux->num_items; i++) {
4152 path = get_nid_path(codec, spec->imux_pins[i],
4153 get_adc_nid(codec, c, i));
4154 if (path) {
4155 bool active = path->active;
4156 if (i == spec->cur_mux[c])
4157 active = true;
4158 activate_path(codec, path, active, false);
4159 }
4160 }
4161 }
4162
4163 alc_inv_dmic_sync(codec, true);
4164 if (spec->shared_mic_hp)
4165 update_shared_mic_hp(codec, spec->cur_mux[0]);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004166}
4167
4168/* add mic boosts if needed */
4169static int alc_auto_add_mic_boost(struct hda_codec *codec)
4170{
4171 struct alc_spec *spec = codec->spec;
4172 struct auto_pin_cfg *cfg = &spec->autocfg;
4173 int i, err;
4174 int type_idx = 0;
4175 hda_nid_t nid;
4176 const char *prev_label = NULL;
4177
4178 for (i = 0; i < cfg->num_inputs; i++) {
4179 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4180 break;
4181 nid = cfg->inputs[i].pin;
4182 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4183 const char *label;
4184 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004185 struct nid_path *path;
4186 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004187
4188 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004189 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4190 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004191 if (prev_label && !strcmp(label, prev_label))
4192 type_idx++;
4193 else
4194 type_idx = 0;
4195 prev_label = label;
4196
4197 snprintf(boost_label, sizeof(boost_label),
4198 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004199 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004200 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004201 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004202 if (err < 0)
4203 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004204
4205 path = get_nid_path(codec, nid, 0);
4206 if (path)
4207 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004208 }
4209 }
4210 return 0;
4211}
4212
Takashi Iwai1d045db2011-07-07 18:23:21 +02004213/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004214 * standard auto-parser initializations
4215 */
4216static void alc_auto_init_std(struct hda_codec *codec)
4217{
Takashi Iwaie4770622011-07-08 11:11:35 +02004218 alc_auto_init_multi_out(codec);
4219 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004220 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004221 alc_auto_init_analog_input(codec);
4222 alc_auto_init_input_src(codec);
4223 alc_auto_init_digital(codec);
Takashi Iwai2eab6942012-12-18 15:30:41 +01004224 /* call init functions of standard auto-mute helpers */
4225 alc_hp_automute(codec, NULL);
4226 alc_line_automute(codec, NULL);
4227 alc_mic_automute(codec, NULL);
Takashi Iwaie4770622011-07-08 11:11:35 +02004228}
4229
4230/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004231 * Digital-beep handlers
4232 */
4233#ifdef CONFIG_SND_HDA_INPUT_BEEP
4234#define set_beep_amp(spec, nid, idx, dir) \
4235 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4236
4237static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004238 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004239 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4240 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4241 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4242 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004243 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004244 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4245 {}
4246};
4247
4248static inline int has_cdefine_beep(struct hda_codec *codec)
4249{
4250 struct alc_spec *spec = codec->spec;
4251 const struct snd_pci_quirk *q;
4252 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4253 if (q)
4254 return q->value;
4255 return spec->cdefine.enable_pcbeep;
4256}
4257#else
4258#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4259#define has_cdefine_beep(codec) 0
4260#endif
4261
4262/* parse the BIOS configuration and set up the alc_spec */
4263/* return 1 if successful, 0 if the proper config is not found,
4264 * or a negative error code
4265 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004266static int alc_parse_auto_config(struct hda_codec *codec,
4267 const hda_nid_t *ignore_nids,
4268 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004269{
4270 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004271 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004272 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004273
Takashi Iwai53c334a2011-08-23 18:27:14 +02004274 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4275 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004276 if (err < 0)
4277 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004278 if (!cfg->line_outs) {
4279 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004280 spec->multiout.max_channels = 2;
4281 spec->no_analog = 1;
4282 goto dig_only;
4283 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004284 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004285 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004286
Takashi Iwaie427c232012-07-29 10:04:08 +02004287 if (!spec->no_primary_hp &&
4288 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004289 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004290 /* use HP as primary out */
4291 cfg->speaker_outs = cfg->line_outs;
4292 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4293 sizeof(cfg->speaker_pins));
4294 cfg->line_outs = cfg->hp_outs;
4295 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4296 cfg->hp_outs = 0;
4297 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4298 cfg->line_out_type = AUTO_PIN_HP_OUT;
4299 }
4300
Takashi Iwai1d045db2011-07-07 18:23:21 +02004301 err = alc_auto_fill_dac_nids(codec);
4302 if (err < 0)
4303 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004304 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004305 if (err < 0)
4306 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004307 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004308 if (err < 0)
4309 return err;
4310 err = alc_auto_create_hp_out(codec);
4311 if (err < 0)
4312 return err;
4313 err = alc_auto_create_speaker_out(codec);
4314 if (err < 0)
4315 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004316 err = alc_auto_create_shared_input(codec);
4317 if (err < 0)
4318 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004319 err = alc_auto_create_input_ctls(codec);
4320 if (err < 0)
4321 return err;
4322
Takashi Iwaib6adb572012-12-03 10:30:58 +01004323 /* check the multiple speaker pins */
4324 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4325 spec->const_channel_count = cfg->line_outs * 2;
4326 else
4327 spec->const_channel_count = cfg->speaker_outs * 2;
4328
4329 if (spec->multi_ios > 0)
4330 spec->multiout.max_channels = max(spec->ext_channel_count,
4331 spec->const_channel_count);
4332 else
4333 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004334
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004335 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004336 alc_auto_parse_digital(codec);
4337
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004338 if (ssid_nids)
4339 alc_ssid_check(codec, ssid_nids);
4340
4341 if (!spec->no_analog) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004342 err = alc_init_automute(codec);
Takashi Iwai475c3d22012-11-30 08:31:30 +01004343 if (err < 0)
4344 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004345
4346 err = check_dyn_adc_switch(codec);
4347 if (err < 0)
4348 return err;
4349
4350 if (!spec->shared_mic_hp) {
4351 err = alc_init_auto_mic(codec);
4352 if (err < 0)
4353 return err;
4354 }
4355
4356 err = create_capture_mixers(codec);
4357 if (err < 0)
4358 return err;
4359
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004360 err = alc_auto_add_mic_boost(codec);
4361 if (err < 0)
4362 return err;
4363 }
4364
Takashi Iwai1d045db2011-07-07 18:23:21 +02004365 if (spec->kctls.list)
4366 add_mixer(spec, spec->kctls.list);
4367
Takashi Iwai1d045db2011-07-07 18:23:21 +02004368 return 1;
4369}
4370
Takashi Iwai3de95172012-05-07 18:03:15 +02004371/* common preparation job for alc_spec */
4372static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4373{
4374 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4375 int err;
4376
4377 if (!spec)
4378 return -ENOMEM;
4379 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004380 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004381 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004382 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004383 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4384 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004385 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004386
4387 err = alc_codec_rename_from_preset(codec);
4388 if (err < 0) {
4389 kfree(spec);
4390 return err;
4391 }
4392 return 0;
4393}
4394
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004395static int alc880_parse_auto_config(struct hda_codec *codec)
4396{
4397 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004398 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004399 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4400}
4401
Takashi Iwai1d045db2011-07-07 18:23:21 +02004402/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004403 * ALC880 fix-ups
4404 */
4405enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004406 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004407 ALC880_FIXUP_GPIO2,
4408 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004409 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004410 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004411 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004412 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004413 ALC880_FIXUP_VOL_KNOB,
4414 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004415 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004416 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004417 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004418 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004419 ALC880_FIXUP_3ST_BASE,
4420 ALC880_FIXUP_3ST,
4421 ALC880_FIXUP_3ST_DIG,
4422 ALC880_FIXUP_5ST_BASE,
4423 ALC880_FIXUP_5ST,
4424 ALC880_FIXUP_5ST_DIG,
4425 ALC880_FIXUP_6ST_BASE,
4426 ALC880_FIXUP_6ST,
4427 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004428};
4429
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004430/* enable the volume-knob widget support on NID 0x21 */
4431static void alc880_fixup_vol_knob(struct hda_codec *codec,
4432 const struct alc_fixup *fix, int action)
4433{
4434 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004435 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004436}
4437
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004438static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004439 [ALC880_FIXUP_GPIO1] = {
4440 .type = ALC_FIXUP_VERBS,
4441 .v.verbs = alc_gpio1_init_verbs,
4442 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004443 [ALC880_FIXUP_GPIO2] = {
4444 .type = ALC_FIXUP_VERBS,
4445 .v.verbs = alc_gpio2_init_verbs,
4446 },
4447 [ALC880_FIXUP_MEDION_RIM] = {
4448 .type = ALC_FIXUP_VERBS,
4449 .v.verbs = (const struct hda_verb[]) {
4450 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4451 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4452 { }
4453 },
4454 .chained = true,
4455 .chain_id = ALC880_FIXUP_GPIO2,
4456 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004457 [ALC880_FIXUP_LG] = {
4458 .type = ALC_FIXUP_PINS,
4459 .v.pins = (const struct alc_pincfg[]) {
4460 /* disable bogus unused pins */
4461 { 0x16, 0x411111f0 },
4462 { 0x18, 0x411111f0 },
4463 { 0x1a, 0x411111f0 },
4464 { }
4465 }
4466 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004467 [ALC880_FIXUP_W810] = {
4468 .type = ALC_FIXUP_PINS,
4469 .v.pins = (const struct alc_pincfg[]) {
4470 /* disable bogus unused pins */
4471 { 0x17, 0x411111f0 },
4472 { }
4473 },
4474 .chained = true,
4475 .chain_id = ALC880_FIXUP_GPIO2,
4476 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004477 [ALC880_FIXUP_EAPD_COEF] = {
4478 .type = ALC_FIXUP_VERBS,
4479 .v.verbs = (const struct hda_verb[]) {
4480 /* change to EAPD mode */
4481 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4482 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4483 {}
4484 },
4485 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004486 [ALC880_FIXUP_TCL_S700] = {
4487 .type = ALC_FIXUP_VERBS,
4488 .v.verbs = (const struct hda_verb[]) {
4489 /* change to EAPD mode */
4490 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4491 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4492 {}
4493 },
4494 .chained = true,
4495 .chain_id = ALC880_FIXUP_GPIO2,
4496 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004497 [ALC880_FIXUP_VOL_KNOB] = {
4498 .type = ALC_FIXUP_FUNC,
4499 .v.func = alc880_fixup_vol_knob,
4500 },
4501 [ALC880_FIXUP_FUJITSU] = {
4502 /* override all pins as BIOS on old Amilo is broken */
4503 .type = ALC_FIXUP_PINS,
4504 .v.pins = (const struct alc_pincfg[]) {
4505 { 0x14, 0x0121411f }, /* HP */
4506 { 0x15, 0x99030120 }, /* speaker */
4507 { 0x16, 0x99030130 }, /* bass speaker */
4508 { 0x17, 0x411111f0 }, /* N/A */
4509 { 0x18, 0x411111f0 }, /* N/A */
4510 { 0x19, 0x01a19950 }, /* mic-in */
4511 { 0x1a, 0x411111f0 }, /* N/A */
4512 { 0x1b, 0x411111f0 }, /* N/A */
4513 { 0x1c, 0x411111f0 }, /* N/A */
4514 { 0x1d, 0x411111f0 }, /* N/A */
4515 { 0x1e, 0x01454140 }, /* SPDIF out */
4516 { }
4517 },
4518 .chained = true,
4519 .chain_id = ALC880_FIXUP_VOL_KNOB,
4520 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004521 [ALC880_FIXUP_F1734] = {
4522 /* almost compatible with FUJITSU, but no bass and SPDIF */
4523 .type = ALC_FIXUP_PINS,
4524 .v.pins = (const struct alc_pincfg[]) {
4525 { 0x14, 0x0121411f }, /* HP */
4526 { 0x15, 0x99030120 }, /* speaker */
4527 { 0x16, 0x411111f0 }, /* N/A */
4528 { 0x17, 0x411111f0 }, /* N/A */
4529 { 0x18, 0x411111f0 }, /* N/A */
4530 { 0x19, 0x01a19950 }, /* mic-in */
4531 { 0x1a, 0x411111f0 }, /* N/A */
4532 { 0x1b, 0x411111f0 }, /* N/A */
4533 { 0x1c, 0x411111f0 }, /* N/A */
4534 { 0x1d, 0x411111f0 }, /* N/A */
4535 { 0x1e, 0x411111f0 }, /* N/A */
4536 { }
4537 },
4538 .chained = true,
4539 .chain_id = ALC880_FIXUP_VOL_KNOB,
4540 },
Takashi Iwai817de922012-02-20 17:20:48 +01004541 [ALC880_FIXUP_UNIWILL] = {
4542 /* need to fix HP and speaker pins to be parsed correctly */
4543 .type = ALC_FIXUP_PINS,
4544 .v.pins = (const struct alc_pincfg[]) {
4545 { 0x14, 0x0121411f }, /* HP */
4546 { 0x15, 0x99030120 }, /* speaker */
4547 { 0x16, 0x99030130 }, /* bass speaker */
4548 { }
4549 },
4550 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004551 [ALC880_FIXUP_UNIWILL_DIG] = {
4552 .type = ALC_FIXUP_PINS,
4553 .v.pins = (const struct alc_pincfg[]) {
4554 /* disable bogus unused pins */
4555 { 0x17, 0x411111f0 },
4556 { 0x19, 0x411111f0 },
4557 { 0x1b, 0x411111f0 },
4558 { 0x1f, 0x411111f0 },
4559 { }
4560 }
4561 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004562 [ALC880_FIXUP_Z71V] = {
4563 .type = ALC_FIXUP_PINS,
4564 .v.pins = (const struct alc_pincfg[]) {
4565 /* set up the whole pins as BIOS is utterly broken */
4566 { 0x14, 0x99030120 }, /* speaker */
4567 { 0x15, 0x0121411f }, /* HP */
4568 { 0x16, 0x411111f0 }, /* N/A */
4569 { 0x17, 0x411111f0 }, /* N/A */
4570 { 0x18, 0x01a19950 }, /* mic-in */
4571 { 0x19, 0x411111f0 }, /* N/A */
4572 { 0x1a, 0x01813031 }, /* line-in */
4573 { 0x1b, 0x411111f0 }, /* N/A */
4574 { 0x1c, 0x411111f0 }, /* N/A */
4575 { 0x1d, 0x411111f0 }, /* N/A */
4576 { 0x1e, 0x0144111e }, /* SPDIF */
4577 { }
4578 }
4579 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004580 [ALC880_FIXUP_3ST_BASE] = {
4581 .type = ALC_FIXUP_PINS,
4582 .v.pins = (const struct alc_pincfg[]) {
4583 { 0x14, 0x01014010 }, /* line-out */
4584 { 0x15, 0x411111f0 }, /* N/A */
4585 { 0x16, 0x411111f0 }, /* N/A */
4586 { 0x17, 0x411111f0 }, /* N/A */
4587 { 0x18, 0x01a19c30 }, /* mic-in */
4588 { 0x19, 0x0121411f }, /* HP */
4589 { 0x1a, 0x01813031 }, /* line-in */
4590 { 0x1b, 0x02a19c40 }, /* front-mic */
4591 { 0x1c, 0x411111f0 }, /* N/A */
4592 { 0x1d, 0x411111f0 }, /* N/A */
4593 /* 0x1e is filled in below */
4594 { 0x1f, 0x411111f0 }, /* N/A */
4595 { }
4596 }
4597 },
4598 [ALC880_FIXUP_3ST] = {
4599 .type = ALC_FIXUP_PINS,
4600 .v.pins = (const struct alc_pincfg[]) {
4601 { 0x1e, 0x411111f0 }, /* N/A */
4602 { }
4603 },
4604 .chained = true,
4605 .chain_id = ALC880_FIXUP_3ST_BASE,
4606 },
4607 [ALC880_FIXUP_3ST_DIG] = {
4608 .type = ALC_FIXUP_PINS,
4609 .v.pins = (const struct alc_pincfg[]) {
4610 { 0x1e, 0x0144111e }, /* SPDIF */
4611 { }
4612 },
4613 .chained = true,
4614 .chain_id = ALC880_FIXUP_3ST_BASE,
4615 },
4616 [ALC880_FIXUP_5ST_BASE] = {
4617 .type = ALC_FIXUP_PINS,
4618 .v.pins = (const struct alc_pincfg[]) {
4619 { 0x14, 0x01014010 }, /* front */
4620 { 0x15, 0x411111f0 }, /* N/A */
4621 { 0x16, 0x01011411 }, /* CLFE */
4622 { 0x17, 0x01016412 }, /* surr */
4623 { 0x18, 0x01a19c30 }, /* mic-in */
4624 { 0x19, 0x0121411f }, /* HP */
4625 { 0x1a, 0x01813031 }, /* line-in */
4626 { 0x1b, 0x02a19c40 }, /* front-mic */
4627 { 0x1c, 0x411111f0 }, /* N/A */
4628 { 0x1d, 0x411111f0 }, /* N/A */
4629 /* 0x1e is filled in below */
4630 { 0x1f, 0x411111f0 }, /* N/A */
4631 { }
4632 }
4633 },
4634 [ALC880_FIXUP_5ST] = {
4635 .type = ALC_FIXUP_PINS,
4636 .v.pins = (const struct alc_pincfg[]) {
4637 { 0x1e, 0x411111f0 }, /* N/A */
4638 { }
4639 },
4640 .chained = true,
4641 .chain_id = ALC880_FIXUP_5ST_BASE,
4642 },
4643 [ALC880_FIXUP_5ST_DIG] = {
4644 .type = ALC_FIXUP_PINS,
4645 .v.pins = (const struct alc_pincfg[]) {
4646 { 0x1e, 0x0144111e }, /* SPDIF */
4647 { }
4648 },
4649 .chained = true,
4650 .chain_id = ALC880_FIXUP_5ST_BASE,
4651 },
4652 [ALC880_FIXUP_6ST_BASE] = {
4653 .type = ALC_FIXUP_PINS,
4654 .v.pins = (const struct alc_pincfg[]) {
4655 { 0x14, 0x01014010 }, /* front */
4656 { 0x15, 0x01016412 }, /* surr */
4657 { 0x16, 0x01011411 }, /* CLFE */
4658 { 0x17, 0x01012414 }, /* side */
4659 { 0x18, 0x01a19c30 }, /* mic-in */
4660 { 0x19, 0x02a19c40 }, /* front-mic */
4661 { 0x1a, 0x01813031 }, /* line-in */
4662 { 0x1b, 0x0121411f }, /* HP */
4663 { 0x1c, 0x411111f0 }, /* N/A */
4664 { 0x1d, 0x411111f0 }, /* N/A */
4665 /* 0x1e is filled in below */
4666 { 0x1f, 0x411111f0 }, /* N/A */
4667 { }
4668 }
4669 },
4670 [ALC880_FIXUP_6ST] = {
4671 .type = ALC_FIXUP_PINS,
4672 .v.pins = (const struct alc_pincfg[]) {
4673 { 0x1e, 0x411111f0 }, /* N/A */
4674 { }
4675 },
4676 .chained = true,
4677 .chain_id = ALC880_FIXUP_6ST_BASE,
4678 },
4679 [ALC880_FIXUP_6ST_DIG] = {
4680 .type = ALC_FIXUP_PINS,
4681 .v.pins = (const struct alc_pincfg[]) {
4682 { 0x1e, 0x0144111e }, /* SPDIF */
4683 { }
4684 },
4685 .chained = true,
4686 .chain_id = ALC880_FIXUP_6ST_BASE,
4687 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004688};
4689
4690static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004691 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004692 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004693 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4694 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004695 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004696 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004697 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004698 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004699 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004700 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004701 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004702 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004703 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004704 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004705 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004706 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4707 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4708 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004709 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004710
4711 /* Below is the copied entries from alc880_quirks.c.
4712 * It's not quite sure whether BIOS sets the correct pin-config table
4713 * on these machines, thus they are kept to be compatible with
4714 * the old static quirks. Once when it's confirmed to work without
4715 * these overrides, it'd be better to remove.
4716 */
4717 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4718 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4719 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4720 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4721 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4722 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4723 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4724 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4725 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4726 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4727 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4728 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4729 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4730 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4731 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4732 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4733 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4734 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4735 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4736 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4737 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4738 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4739 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4740 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4741 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4742 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4743 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4744 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4745 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4746 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4747 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4748 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4749 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4750 /* default Intel */
4751 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4752 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4753 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4754 {}
4755};
4756
4757static const struct alc_model_fixup alc880_fixup_models[] = {
4758 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4759 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4760 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4761 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4762 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4763 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004764 {}
4765};
4766
4767
4768/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004769 * OK, here we have finally the patch for ALC880
4770 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004771static int patch_alc880(struct hda_codec *codec)
4772{
4773 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004774 int err;
4775
Takashi Iwai3de95172012-05-07 18:03:15 +02004776 err = alc_alloc_spec(codec, 0x0b);
4777 if (err < 0)
4778 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004779
Takashi Iwai3de95172012-05-07 18:03:15 +02004780 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004781 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004782
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004783 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4784 alc880_fixups);
4785 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004786
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004787 /* automatic parse from the BIOS config */
4788 err = alc880_parse_auto_config(codec);
4789 if (err < 0)
4790 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004791
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004792 if (!spec->no_analog) {
4793 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004794 if (err < 0)
4795 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004796 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4797 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004798
Takashi Iwai1d045db2011-07-07 18:23:21 +02004799 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004800 codec->patch_ops.unsol_event = alc880_unsol_event;
4801
Takashi Iwai1d045db2011-07-07 18:23:21 +02004802
Takashi Iwai589876e2012-02-20 15:47:55 +01004803 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4804
Takashi Iwai1d045db2011-07-07 18:23:21 +02004805 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004806
4807 error:
4808 alc_free(codec);
4809 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004810}
4811
4812
4813/*
4814 * ALC260 support
4815 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004816static int alc260_parse_auto_config(struct hda_codec *codec)
4817{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004818 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004819 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4820 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004821}
4822
Takashi Iwai1d045db2011-07-07 18:23:21 +02004823/*
4824 * Pin config fixes
4825 */
4826enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004827 ALC260_FIXUP_HP_DC5750,
4828 ALC260_FIXUP_HP_PIN_0F,
4829 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004830 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004831 ALC260_FIXUP_GPIO1_TOGGLE,
4832 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004833 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004834 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004835};
4836
Takashi Iwai20f7d922012-02-16 12:35:16 +01004837static void alc260_gpio1_automute(struct hda_codec *codec)
4838{
4839 struct alc_spec *spec = codec->spec;
4840 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4841 spec->hp_jack_present);
4842}
4843
4844static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4845 const struct alc_fixup *fix, int action)
4846{
4847 struct alc_spec *spec = codec->spec;
4848 if (action == ALC_FIXUP_ACT_PROBE) {
4849 /* although the machine has only one output pin, we need to
4850 * toggle GPIO1 according to the jack state
4851 */
4852 spec->automute_hook = alc260_gpio1_automute;
4853 spec->detect_hp = 1;
4854 spec->automute_speaker = 1;
4855 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004856 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4857 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004858 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004859 }
4860}
4861
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004862static void alc260_fixup_kn1(struct hda_codec *codec,
4863 const struct alc_fixup *fix, int action)
4864{
4865 struct alc_spec *spec = codec->spec;
4866 static const struct alc_pincfg pincfgs[] = {
4867 { 0x0f, 0x02214000 }, /* HP/speaker */
4868 { 0x12, 0x90a60160 }, /* int mic */
4869 { 0x13, 0x02a19000 }, /* ext mic */
4870 { 0x18, 0x01446000 }, /* SPDIF out */
4871 /* disable bogus I/O pins */
4872 { 0x10, 0x411111f0 },
4873 { 0x11, 0x411111f0 },
4874 { 0x14, 0x411111f0 },
4875 { 0x15, 0x411111f0 },
4876 { 0x16, 0x411111f0 },
4877 { 0x17, 0x411111f0 },
4878 { 0x19, 0x411111f0 },
4879 { }
4880 };
4881
4882 switch (action) {
4883 case ALC_FIXUP_ACT_PRE_PROBE:
4884 alc_apply_pincfgs(codec, pincfgs);
4885 break;
4886 case ALC_FIXUP_ACT_PROBE:
4887 spec->init_amp = ALC_INIT_NONE;
4888 break;
4889 }
4890}
4891
Takashi Iwai1d045db2011-07-07 18:23:21 +02004892static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004893 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004894 .type = ALC_FIXUP_PINS,
4895 .v.pins = (const struct alc_pincfg[]) {
4896 { 0x11, 0x90130110 }, /* speaker */
4897 { }
4898 }
4899 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004900 [ALC260_FIXUP_HP_PIN_0F] = {
4901 .type = ALC_FIXUP_PINS,
4902 .v.pins = (const struct alc_pincfg[]) {
4903 { 0x0f, 0x01214000 }, /* HP */
4904 { }
4905 }
4906 },
4907 [ALC260_FIXUP_COEF] = {
4908 .type = ALC_FIXUP_VERBS,
4909 .v.verbs = (const struct hda_verb[]) {
4910 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4911 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4912 { }
4913 },
4914 .chained = true,
4915 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4916 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004917 [ALC260_FIXUP_GPIO1] = {
4918 .type = ALC_FIXUP_VERBS,
4919 .v.verbs = alc_gpio1_init_verbs,
4920 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004921 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4922 .type = ALC_FIXUP_FUNC,
4923 .v.func = alc260_fixup_gpio1_toggle,
4924 .chained = true,
4925 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4926 },
4927 [ALC260_FIXUP_REPLACER] = {
4928 .type = ALC_FIXUP_VERBS,
4929 .v.verbs = (const struct hda_verb[]) {
4930 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4931 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4932 { }
4933 },
4934 .chained = true,
4935 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4936 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004937 [ALC260_FIXUP_HP_B1900] = {
4938 .type = ALC_FIXUP_FUNC,
4939 .v.func = alc260_fixup_gpio1_toggle,
4940 .chained = true,
4941 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004942 },
4943 [ALC260_FIXUP_KN1] = {
4944 .type = ALC_FIXUP_FUNC,
4945 .v.func = alc260_fixup_kn1,
4946 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004947};
4948
4949static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004950 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004951 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004952 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004953 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004954 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004955 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004956 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004957 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004958 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004959 {}
4960};
4961
4962/*
4963 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004964static int patch_alc260(struct hda_codec *codec)
4965{
4966 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004967 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004968
Takashi Iwai3de95172012-05-07 18:03:15 +02004969 err = alc_alloc_spec(codec, 0x07);
4970 if (err < 0)
4971 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004972
Takashi Iwai3de95172012-05-07 18:03:15 +02004973 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004974
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004975 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4976 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004977
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004978 /* automatic parse from the BIOS config */
4979 err = alc260_parse_auto_config(codec);
4980 if (err < 0)
4981 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004982
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004983 if (!spec->no_analog) {
4984 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004985 if (err < 0)
4986 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004987 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4988 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989
Takashi Iwai1d045db2011-07-07 18:23:21 +02004990 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004991 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004992
Takashi Iwai589876e2012-02-20 15:47:55 +01004993 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4994
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004996
4997 error:
4998 alc_free(codec);
4999 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000}
5001
5002
5003/*
5004 * ALC882/883/885/888/889 support
5005 *
5006 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5007 * configuration. Each pin widget can choose any input DACs and a mixer.
5008 * Each ADC is connected from a mixer of all inputs. This makes possible
5009 * 6-channel independent captures.
5010 *
5011 * In addition, an independent DAC for the multi-playback (not used in this
5012 * driver yet).
5013 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005014
5015/*
5016 * Pin config fixes
5017 */
5018enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005019 ALC882_FIXUP_ABIT_AW9D_MAX,
5020 ALC882_FIXUP_LENOVO_Y530,
5021 ALC882_FIXUP_PB_M5210,
5022 ALC882_FIXUP_ACER_ASPIRE_7736,
5023 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005024 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005025 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005026 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005027 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005028 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005029 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005030 ALC882_FIXUP_GPIO1,
5031 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005032 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005033 ALC889_FIXUP_COEF,
5034 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005035 ALC882_FIXUP_ACER_ASPIRE_4930G,
5036 ALC882_FIXUP_ACER_ASPIRE_8930G,
5037 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005038 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005039 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005040 ALC889_FIXUP_MBP_VREF,
5041 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005042 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005043 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005044};
5045
Takashi Iwai68ef0562011-11-09 18:24:44 +01005046static void alc889_fixup_coef(struct hda_codec *codec,
5047 const struct alc_fixup *fix, int action)
5048{
5049 if (action != ALC_FIXUP_ACT_INIT)
5050 return;
5051 alc889_coef_init(codec);
5052}
5053
Takashi Iwai56710872011-11-14 17:42:11 +01005054/* toggle speaker-output according to the hp-jack state */
5055static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5056{
5057 unsigned int gpiostate, gpiomask, gpiodir;
5058
5059 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5060 AC_VERB_GET_GPIO_DATA, 0);
5061
5062 if (!muted)
5063 gpiostate |= (1 << pin);
5064 else
5065 gpiostate &= ~(1 << pin);
5066
5067 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5068 AC_VERB_GET_GPIO_MASK, 0);
5069 gpiomask |= (1 << pin);
5070
5071 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5072 AC_VERB_GET_GPIO_DIRECTION, 0);
5073 gpiodir |= (1 << pin);
5074
5075
5076 snd_hda_codec_write(codec, codec->afg, 0,
5077 AC_VERB_SET_GPIO_MASK, gpiomask);
5078 snd_hda_codec_write(codec, codec->afg, 0,
5079 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5080
5081 msleep(1);
5082
5083 snd_hda_codec_write(codec, codec->afg, 0,
5084 AC_VERB_SET_GPIO_DATA, gpiostate);
5085}
5086
5087/* set up GPIO at initialization */
5088static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5089 const struct alc_fixup *fix, int action)
5090{
5091 if (action != ALC_FIXUP_ACT_INIT)
5092 return;
5093 alc882_gpio_mute(codec, 0, 0);
5094 alc882_gpio_mute(codec, 1, 0);
5095}
5096
Takashi Iwai02a237b2012-02-13 15:25:07 +01005097/* Fix the connection of some pins for ALC889:
5098 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5099 * work correctly (bko#42740)
5100 */
5101static void alc889_fixup_dac_route(struct hda_codec *codec,
5102 const struct alc_fixup *fix, int action)
5103{
5104 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005105 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005106 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5107 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5108 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5109 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5110 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5111 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005112 } else if (action == ALC_FIXUP_ACT_PROBE) {
5113 /* restore the connections */
5114 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5115 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5116 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5117 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5118 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005119 }
5120}
5121
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005122/* Set VREF on HP pin */
5123static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5124 const struct alc_fixup *fix, int action)
5125{
5126 struct alc_spec *spec = codec->spec;
5127 static hda_nid_t nids[2] = { 0x14, 0x15 };
5128 int i;
5129
5130 if (action != ALC_FIXUP_ACT_INIT)
5131 return;
5132 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5133 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5134 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5135 continue;
5136 val = snd_hda_codec_read(codec, nids[i], 0,
5137 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5138 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005139 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005140 spec->keep_vref_in_automute = 1;
5141 break;
5142 }
5143}
5144
5145/* Set VREF on speaker pins on imac91 */
5146static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5147 const struct alc_fixup *fix, int action)
5148{
5149 struct alc_spec *spec = codec->spec;
5150 static hda_nid_t nids[2] = { 0x18, 0x1a };
5151 int i;
5152
5153 if (action != ALC_FIXUP_ACT_INIT)
5154 return;
5155 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5156 unsigned int val;
5157 val = snd_hda_codec_read(codec, nids[i], 0,
5158 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5159 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005160 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005161 }
5162 spec->keep_vref_in_automute = 1;
5163}
5164
Takashi Iwaie427c232012-07-29 10:04:08 +02005165/* Don't take HP output as primary
5166 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5167 */
5168static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5169 const struct alc_fixup *fix, int action)
5170{
5171 struct alc_spec *spec = codec->spec;
5172 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5173 spec->no_primary_hp = 1;
5174}
5175
Takashi Iwai1d045db2011-07-07 18:23:21 +02005176static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005177 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005178 .type = ALC_FIXUP_PINS,
5179 .v.pins = (const struct alc_pincfg[]) {
5180 { 0x15, 0x01080104 }, /* side */
5181 { 0x16, 0x01011012 }, /* rear */
5182 { 0x17, 0x01016011 }, /* clfe */
5183 { }
5184 }
5185 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005186 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005187 .type = ALC_FIXUP_PINS,
5188 .v.pins = (const struct alc_pincfg[]) {
5189 { 0x15, 0x99130112 }, /* rear int speakers */
5190 { 0x16, 0x99130111 }, /* subwoofer */
5191 { }
5192 }
5193 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005194 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005195 .type = ALC_FIXUP_VERBS,
5196 .v.verbs = (const struct hda_verb[]) {
5197 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5198 {}
5199 }
5200 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005201 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005202 .type = ALC_FIXUP_FUNC,
5203 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005204 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005205 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005206 .type = ALC_FIXUP_PINS,
5207 .v.pins = (const struct alc_pincfg[]) {
5208 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5209 { }
5210 }
5211 },
Marton Balint8f239212012-03-05 21:33:23 +01005212 [ALC889_FIXUP_CD] = {
5213 .type = ALC_FIXUP_PINS,
5214 .v.pins = (const struct alc_pincfg[]) {
5215 { 0x1c, 0x993301f0 }, /* CD */
5216 { }
5217 }
5218 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005219 [ALC889_FIXUP_VAIO_TT] = {
5220 .type = ALC_FIXUP_PINS,
5221 .v.pins = (const struct alc_pincfg[]) {
5222 { 0x17, 0x90170111 }, /* hidden surround speaker */
5223 { }
5224 }
5225 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005226 [ALC888_FIXUP_EEE1601] = {
5227 .type = ALC_FIXUP_VERBS,
5228 .v.verbs = (const struct hda_verb[]) {
5229 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5230 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5231 { }
5232 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005233 },
5234 [ALC882_FIXUP_EAPD] = {
5235 .type = ALC_FIXUP_VERBS,
5236 .v.verbs = (const struct hda_verb[]) {
5237 /* change to EAPD mode */
5238 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5239 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5240 { }
5241 }
5242 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005243 [ALC883_FIXUP_EAPD] = {
5244 .type = ALC_FIXUP_VERBS,
5245 .v.verbs = (const struct hda_verb[]) {
5246 /* change to EAPD mode */
5247 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5248 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5249 { }
5250 }
5251 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005252 [ALC883_FIXUP_ACER_EAPD] = {
5253 .type = ALC_FIXUP_VERBS,
5254 .v.verbs = (const struct hda_verb[]) {
5255 /* eanable EAPD on Acer laptops */
5256 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5257 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5258 { }
5259 }
5260 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005261 [ALC882_FIXUP_GPIO1] = {
5262 .type = ALC_FIXUP_VERBS,
5263 .v.verbs = alc_gpio1_init_verbs,
5264 },
5265 [ALC882_FIXUP_GPIO2] = {
5266 .type = ALC_FIXUP_VERBS,
5267 .v.verbs = alc_gpio2_init_verbs,
5268 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005269 [ALC882_FIXUP_GPIO3] = {
5270 .type = ALC_FIXUP_VERBS,
5271 .v.verbs = alc_gpio3_init_verbs,
5272 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005273 [ALC882_FIXUP_ASUS_W2JC] = {
5274 .type = ALC_FIXUP_VERBS,
5275 .v.verbs = alc_gpio1_init_verbs,
5276 .chained = true,
5277 .chain_id = ALC882_FIXUP_EAPD,
5278 },
5279 [ALC889_FIXUP_COEF] = {
5280 .type = ALC_FIXUP_FUNC,
5281 .v.func = alc889_fixup_coef,
5282 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005283 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5284 .type = ALC_FIXUP_PINS,
5285 .v.pins = (const struct alc_pincfg[]) {
5286 { 0x16, 0x99130111 }, /* CLFE speaker */
5287 { 0x17, 0x99130112 }, /* surround speaker */
5288 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005289 },
5290 .chained = true,
5291 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005292 },
5293 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5294 .type = ALC_FIXUP_PINS,
5295 .v.pins = (const struct alc_pincfg[]) {
5296 { 0x16, 0x99130111 }, /* CLFE speaker */
5297 { 0x1b, 0x99130112 }, /* surround speaker */
5298 { }
5299 },
5300 .chained = true,
5301 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5302 },
5303 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5304 /* additional init verbs for Acer Aspire 8930G */
5305 .type = ALC_FIXUP_VERBS,
5306 .v.verbs = (const struct hda_verb[]) {
5307 /* Enable all DACs */
5308 /* DAC DISABLE/MUTE 1? */
5309 /* setting bits 1-5 disables DAC nids 0x02-0x06
5310 * apparently. Init=0x38 */
5311 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5312 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5313 /* DAC DISABLE/MUTE 2? */
5314 /* some bit here disables the other DACs.
5315 * Init=0x4900 */
5316 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5317 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5318 /* DMIC fix
5319 * This laptop has a stereo digital microphone.
5320 * The mics are only 1cm apart which makes the stereo
5321 * useless. However, either the mic or the ALC889
5322 * makes the signal become a difference/sum signal
5323 * instead of standard stereo, which is annoying.
5324 * So instead we flip this bit which makes the
5325 * codec replicate the sum signal to both channels,
5326 * turning it into a normal mono mic.
5327 */
5328 /* DMIC_CONTROL? Init value = 0x0001 */
5329 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5330 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5331 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5332 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5333 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005334 },
5335 .chained = true,
5336 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005337 },
Takashi Iwai56710872011-11-14 17:42:11 +01005338 [ALC885_FIXUP_MACPRO_GPIO] = {
5339 .type = ALC_FIXUP_FUNC,
5340 .v.func = alc885_fixup_macpro_gpio,
5341 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005342 [ALC889_FIXUP_DAC_ROUTE] = {
5343 .type = ALC_FIXUP_FUNC,
5344 .v.func = alc889_fixup_dac_route,
5345 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005346 [ALC889_FIXUP_MBP_VREF] = {
5347 .type = ALC_FIXUP_FUNC,
5348 .v.func = alc889_fixup_mbp_vref,
5349 .chained = true,
5350 .chain_id = ALC882_FIXUP_GPIO1,
5351 },
5352 [ALC889_FIXUP_IMAC91_VREF] = {
5353 .type = ALC_FIXUP_FUNC,
5354 .v.func = alc889_fixup_imac91_vref,
5355 .chained = true,
5356 .chain_id = ALC882_FIXUP_GPIO1,
5357 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005358 [ALC882_FIXUP_INV_DMIC] = {
5359 .type = ALC_FIXUP_FUNC,
5360 .v.func = alc_fixup_inv_dmic_0x12,
5361 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005362 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5363 .type = ALC_FIXUP_FUNC,
5364 .v.func = alc882_fixup_no_primary_hp,
5365 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005366};
5367
5368static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005369 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5370 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5371 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5372 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5373 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5374 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005375 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5376 ALC882_FIXUP_ACER_ASPIRE_4930G),
5377 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5378 ALC882_FIXUP_ACER_ASPIRE_4930G),
5379 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5380 ALC882_FIXUP_ACER_ASPIRE_8930G),
5381 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5382 ALC882_FIXUP_ACER_ASPIRE_8930G),
5383 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5384 ALC882_FIXUP_ACER_ASPIRE_4930G),
5385 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5386 ALC882_FIXUP_ACER_ASPIRE_4930G),
5387 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5388 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005389 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005390 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5391 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005392 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005393 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005394 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005395 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005396 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005397 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005398 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005399 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005400 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005401
5402 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005403 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5404 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5405 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005406 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5407 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5408 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005409 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5410 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005411 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005412 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5413 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5414 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5415 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005416 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005417 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5418 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5419 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005420 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005421 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005422 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5423 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5424 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005425
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005426 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005427 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005428 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005429 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005430 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005431 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5432 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005433 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005434 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005435 {}
5436};
5437
Takashi Iwai912093b2012-04-11 14:03:41 +02005438static const struct alc_model_fixup alc882_fixup_models[] = {
5439 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5440 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5441 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005442 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005443 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005444 {}
5445};
5446
Takashi Iwai1d045db2011-07-07 18:23:21 +02005447/*
5448 * BIOS auto configuration
5449 */
5450/* almost identical with ALC880 parser... */
5451static int alc882_parse_auto_config(struct hda_codec *codec)
5452{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005453 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005454 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5455 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005456}
5457
Takashi Iwai1d045db2011-07-07 18:23:21 +02005458/*
5459 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005460static int patch_alc882(struct hda_codec *codec)
5461{
5462 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005463 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005464
Takashi Iwai3de95172012-05-07 18:03:15 +02005465 err = alc_alloc_spec(codec, 0x0b);
5466 if (err < 0)
5467 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005468
Takashi Iwai3de95172012-05-07 18:03:15 +02005469 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005470
5471 switch (codec->vendor_id) {
5472 case 0x10ec0882:
5473 case 0x10ec0885:
5474 break;
5475 default:
5476 /* ALC883 and variants */
5477 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5478 break;
5479 }
5480
Takashi Iwai912093b2012-04-11 14:03:41 +02005481 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5482 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005483 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005484
5485 alc_auto_parse_customize_define(codec);
5486
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005487 /* automatic parse from the BIOS config */
5488 err = alc882_parse_auto_config(codec);
5489 if (err < 0)
5490 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005491
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005492 if (!spec->no_analog && has_cdefine_beep(codec)) {
5493 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005494 if (err < 0)
5495 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005496 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005497 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005498
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005500
Takashi Iwai589876e2012-02-20 15:47:55 +01005501 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5502
Takashi Iwai1d045db2011-07-07 18:23:21 +02005503 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005504
5505 error:
5506 alc_free(codec);
5507 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508}
5509
5510
5511/*
5512 * ALC262 support
5513 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005514static int alc262_parse_auto_config(struct hda_codec *codec)
5515{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005516 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005517 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5518 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005519}
5520
5521/*
5522 * Pin config fixes
5523 */
5524enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005525 ALC262_FIXUP_FSC_H270,
5526 ALC262_FIXUP_HP_Z200,
5527 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005528 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005529 ALC262_FIXUP_BENQ,
5530 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005531 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005532};
5533
5534static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005535 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005536 .type = ALC_FIXUP_PINS,
5537 .v.pins = (const struct alc_pincfg[]) {
5538 { 0x14, 0x99130110 }, /* speaker */
5539 { 0x15, 0x0221142f }, /* front HP */
5540 { 0x1b, 0x0121141f }, /* rear HP */
5541 { }
5542 }
5543 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005544 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005545 .type = ALC_FIXUP_PINS,
5546 .v.pins = (const struct alc_pincfg[]) {
5547 { 0x16, 0x99130120 }, /* internal speaker */
5548 { }
5549 }
5550 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005551 [ALC262_FIXUP_TYAN] = {
5552 .type = ALC_FIXUP_PINS,
5553 .v.pins = (const struct alc_pincfg[]) {
5554 { 0x14, 0x1993e1f0 }, /* int AUX */
5555 { }
5556 }
5557 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005558 [ALC262_FIXUP_LENOVO_3000] = {
5559 .type = ALC_FIXUP_VERBS,
5560 .v.verbs = (const struct hda_verb[]) {
5561 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005562 {}
5563 },
5564 .chained = true,
5565 .chain_id = ALC262_FIXUP_BENQ,
5566 },
5567 [ALC262_FIXUP_BENQ] = {
5568 .type = ALC_FIXUP_VERBS,
5569 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005570 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5571 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5572 {}
5573 }
5574 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005575 [ALC262_FIXUP_BENQ_T31] = {
5576 .type = ALC_FIXUP_VERBS,
5577 .v.verbs = (const struct hda_verb[]) {
5578 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5579 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5580 {}
5581 }
5582 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005583 [ALC262_FIXUP_INV_DMIC] = {
5584 .type = ALC_FIXUP_FUNC,
5585 .v.func = alc_fixup_inv_dmic_0x12,
5586 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005587};
5588
5589static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005590 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005591 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5592 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005593 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5594 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005595 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005596 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5597 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005598 {}
5599};
5600
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005601static const struct alc_model_fixup alc262_fixup_models[] = {
5602 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5603 {}
5604};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005605
Takashi Iwai1d045db2011-07-07 18:23:21 +02005606/*
5607 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005608static int patch_alc262(struct hda_codec *codec)
5609{
5610 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005611 int err;
5612
Takashi Iwai3de95172012-05-07 18:03:15 +02005613 err = alc_alloc_spec(codec, 0x0b);
5614 if (err < 0)
5615 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005616
Takashi Iwai3de95172012-05-07 18:03:15 +02005617 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01005618 spec->shared_mic_vref_pin = 0x18;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005619
5620#if 0
5621 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5622 * under-run
5623 */
5624 {
5625 int tmp;
5626 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5627 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5628 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5629 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5630 }
5631#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005632 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5633
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005634 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5635 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005636 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005637
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005638 alc_auto_parse_customize_define(codec);
5639
Takashi Iwai42399f72011-11-07 17:18:44 +01005640 /* automatic parse from the BIOS config */
5641 err = alc262_parse_auto_config(codec);
5642 if (err < 0)
5643 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005644
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645 if (!spec->no_analog && has_cdefine_beep(codec)) {
5646 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005647 if (err < 0)
5648 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005650 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005651
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005653 spec->shutup = alc_eapd_shutup;
5654
Takashi Iwai589876e2012-02-20 15:47:55 +01005655 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5656
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005658
5659 error:
5660 alc_free(codec);
5661 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005662}
5663
5664/*
5665 * ALC268
5666 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005667/* bind Beep switches of both NID 0x0f and 0x10 */
5668static const struct hda_bind_ctls alc268_bind_beep_sw = {
5669 .ops = &snd_hda_bind_sw,
5670 .values = {
5671 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5672 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5673 0
5674 },
5675};
5676
5677static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5678 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5679 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5680 { }
5681};
5682
5683/* set PCBEEP vol = 0, mute connections */
5684static const struct hda_verb alc268_beep_init_verbs[] = {
5685 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5686 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5687 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5688 { }
5689};
5690
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005691enum {
5692 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005693 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005694};
5695
5696static const struct alc_fixup alc268_fixups[] = {
5697 [ALC268_FIXUP_INV_DMIC] = {
5698 .type = ALC_FIXUP_FUNC,
5699 .v.func = alc_fixup_inv_dmic_0x12,
5700 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005701 [ALC268_FIXUP_HP_EAPD] = {
5702 .type = ALC_FIXUP_VERBS,
5703 .v.verbs = (const struct hda_verb[]) {
5704 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5705 {}
5706 }
5707 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005708};
5709
5710static const struct alc_model_fixup alc268_fixup_models[] = {
5711 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005712 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5713 {}
5714};
5715
5716static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5717 /* below is codec SSID since multiple Toshiba laptops have the
5718 * same PCI SSID 1179:ff00
5719 */
5720 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005721 {}
5722};
5723
Takashi Iwai1d045db2011-07-07 18:23:21 +02005724/*
5725 * BIOS auto configuration
5726 */
5727static int alc268_parse_auto_config(struct hda_codec *codec)
5728{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005729 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005730 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005731 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5732 if (err > 0) {
5733 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5734 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005735 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005736 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005737 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005738 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005739}
5740
Takashi Iwai1d045db2011-07-07 18:23:21 +02005741/*
5742 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743static int patch_alc268(struct hda_codec *codec)
5744{
5745 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005746 int i, has_beep, err;
5747
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005749 err = alc_alloc_spec(codec, 0);
5750 if (err < 0)
5751 return err;
5752
5753 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754
Takashi Iwaicb766402012-10-20 10:55:21 +02005755 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005756 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5757
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005758 /* automatic parse from the BIOS config */
5759 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005760 if (err < 0)
5761 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005762
Takashi Iwai1d045db2011-07-07 18:23:21 +02005763 has_beep = 0;
5764 for (i = 0; i < spec->num_mixers; i++) {
5765 if (spec->mixers[i] == alc268_beep_mixer) {
5766 has_beep = 1;
5767 break;
5768 }
5769 }
5770
5771 if (has_beep) {
5772 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005773 if (err < 0)
5774 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005775 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5776 /* override the amp caps for beep generator */
5777 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5778 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5779 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5780 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5781 (0 << AC_AMPCAP_MUTE_SHIFT));
5782 }
5783
Takashi Iwai1d045db2011-07-07 18:23:21 +02005784 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005785 spec->shutup = alc_eapd_shutup;
5786
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005787 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5788
Takashi Iwai1d045db2011-07-07 18:23:21 +02005789 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005790
5791 error:
5792 alc_free(codec);
5793 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005794}
5795
5796/*
5797 * ALC269
5798 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005799static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5800 .substreams = 1,
5801 .channels_min = 2,
5802 .channels_max = 8,
5803 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5804 /* NID is set in alc_build_pcms */
5805 .ops = {
5806 .open = alc_playback_pcm_open,
5807 .prepare = alc_playback_pcm_prepare,
5808 .cleanup = alc_playback_pcm_cleanup
5809 },
5810};
5811
5812static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5813 .substreams = 1,
5814 .channels_min = 2,
5815 .channels_max = 2,
5816 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5817 /* NID is set in alc_build_pcms */
5818};
5819
Takashi Iwai1d045db2011-07-07 18:23:21 +02005820/* different alc269-variants */
5821enum {
5822 ALC269_TYPE_ALC269VA,
5823 ALC269_TYPE_ALC269VB,
5824 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005825 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005826 ALC269_TYPE_ALC280,
5827 ALC269_TYPE_ALC282,
5828 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005829};
5830
5831/*
5832 * BIOS auto configuration
5833 */
5834static int alc269_parse_auto_config(struct hda_codec *codec)
5835{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005836 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005837 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5838 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5839 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005840 const hda_nid_t *ssids;
5841
5842 switch (spec->codec_variant) {
5843 case ALC269_TYPE_ALC269VA:
5844 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005845 case ALC269_TYPE_ALC280:
5846 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005847 ssids = alc269va_ssids;
5848 break;
5849 case ALC269_TYPE_ALC269VB:
5850 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005851 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005852 ssids = alc269_ssids;
5853 break;
5854 default:
5855 ssids = alc269_ssids;
5856 break;
5857 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005858
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005859 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005860}
5861
Kailang Yang1387e2d2012-11-08 10:23:18 +01005862static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005863{
5864 int val = alc_read_coef_idx(codec, 0x04);
5865 if (power_up)
5866 val |= 1 << 11;
5867 else
5868 val &= ~(1 << 11);
5869 alc_write_coef_idx(codec, 0x04, val);
5870}
5871
5872static void alc269_shutup(struct hda_codec *codec)
5873{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005874 struct alc_spec *spec = codec->spec;
5875
5876 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5877 return;
5878
Kailang Yang1387e2d2012-11-08 10:23:18 +01005879 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5880 alc269vb_toggle_power_output(codec, 0);
5881 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5882 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005883 msleep(150);
5884 }
5885}
5886
Takashi Iwai2a439522011-07-26 09:52:50 +02005887#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005888static int alc269_resume(struct hda_codec *codec)
5889{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005890 struct alc_spec *spec = codec->spec;
5891
Kailang Yang1387e2d2012-11-08 10:23:18 +01005892 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5893 alc269vb_toggle_power_output(codec, 0);
5894 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005895 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005896 msleep(150);
5897 }
5898
5899 codec->patch_ops.init(codec);
5900
Kailang Yang1387e2d2012-11-08 10:23:18 +01005901 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5902 alc269vb_toggle_power_output(codec, 1);
5903 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005904 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005905 msleep(200);
5906 }
5907
Takashi Iwai1d045db2011-07-07 18:23:21 +02005908 snd_hda_codec_resume_amp(codec);
5909 snd_hda_codec_resume_cache(codec);
5910 hda_call_check_power_status(codec, 0x01);
5911 return 0;
5912}
Takashi Iwai2a439522011-07-26 09:52:50 +02005913#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005914
David Henningsson108cc102012-07-20 10:37:25 +02005915static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5916 const struct alc_fixup *fix, int action)
5917{
5918 struct alc_spec *spec = codec->spec;
5919
5920 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5921 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5922}
5923
Takashi Iwai1d045db2011-07-07 18:23:21 +02005924static void alc269_fixup_hweq(struct hda_codec *codec,
5925 const struct alc_fixup *fix, int action)
5926{
5927 int coef;
5928
5929 if (action != ALC_FIXUP_ACT_INIT)
5930 return;
5931 coef = alc_read_coef_idx(codec, 0x1e);
5932 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5933}
5934
5935static void alc271_fixup_dmic(struct hda_codec *codec,
5936 const struct alc_fixup *fix, int action)
5937{
5938 static const struct hda_verb verbs[] = {
5939 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5940 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5941 {}
5942 };
5943 unsigned int cfg;
5944
5945 if (strcmp(codec->chip_name, "ALC271X"))
5946 return;
5947 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5948 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5949 snd_hda_sequence_write(codec, verbs);
5950}
5951
Takashi Iwai017f2a12011-07-09 14:42:25 +02005952static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5953 const struct alc_fixup *fix, int action)
5954{
5955 struct alc_spec *spec = codec->spec;
5956
5957 if (action != ALC_FIXUP_ACT_PROBE)
5958 return;
5959
5960 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5961 * fix the sample rate of analog I/O to 44.1kHz
5962 */
5963 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5964 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5965}
5966
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005967static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5968 const struct alc_fixup *fix, int action)
5969{
5970 int coef;
5971
5972 if (action != ALC_FIXUP_ACT_INIT)
5973 return;
5974 /* The digital-mic unit sends PDM (differential signal) instead of
5975 * the standard PCM, thus you can't record a valid mono stream as is.
5976 * Below is a workaround specific to ALC269 to control the dmic
5977 * signal source as mono.
5978 */
5979 coef = alc_read_coef_idx(codec, 0x07);
5980 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5981}
5982
Takashi Iwai24519912011-08-16 15:08:49 +02005983static void alc269_quanta_automute(struct hda_codec *codec)
5984{
David Henningsson42cf0d02011-09-20 12:04:56 +02005985 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005986
5987 snd_hda_codec_write(codec, 0x20, 0,
5988 AC_VERB_SET_COEF_INDEX, 0x0c);
5989 snd_hda_codec_write(codec, 0x20, 0,
5990 AC_VERB_SET_PROC_COEF, 0x680);
5991
5992 snd_hda_codec_write(codec, 0x20, 0,
5993 AC_VERB_SET_COEF_INDEX, 0x0c);
5994 snd_hda_codec_write(codec, 0x20, 0,
5995 AC_VERB_SET_PROC_COEF, 0x480);
5996}
5997
5998static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5999 const struct alc_fixup *fix, int action)
6000{
6001 struct alc_spec *spec = codec->spec;
6002 if (action != ALC_FIXUP_ACT_PROBE)
6003 return;
6004 spec->automute_hook = alc269_quanta_automute;
6005}
6006
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006007/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6008static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6009{
6010 struct hda_codec *codec = private_data;
6011 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6012 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6013 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6014}
6015
6016static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6017 const struct alc_fixup *fix, int action)
6018{
6019 struct alc_spec *spec = codec->spec;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01006020 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006021 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006022}
6023
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006024/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6025static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6026{
6027 struct hda_codec *codec = private_data;
6028 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006029 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006030}
6031
6032static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6033 const struct alc_fixup *fix, int action)
6034{
6035 struct alc_spec *spec = codec->spec;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01006036 if (action == ALC_FIXUP_ACT_PROBE)
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006037 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006038}
6039
Dylan Reid08a978d2012-11-18 22:56:40 -08006040static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6041 const struct alc_fixup *fix,
6042 int action)
6043{
6044 struct alc_spec *spec = codec->spec;
6045
6046 if (action == ALC_FIXUP_ACT_PROBE)
6047 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6048 spec->autocfg.hp_pins[0]);
6049}
David Henningsson693b6132012-06-22 19:12:10 +02006050
Takashi Iwai1d045db2011-07-07 18:23:21 +02006051enum {
6052 ALC269_FIXUP_SONY_VAIO,
6053 ALC275_FIXUP_SONY_VAIO_GPIO2,
6054 ALC269_FIXUP_DELL_M101Z,
6055 ALC269_FIXUP_SKU_IGNORE,
6056 ALC269_FIXUP_ASUS_G73JW,
6057 ALC269_FIXUP_LENOVO_EAPD,
6058 ALC275_FIXUP_SONY_HWEQ,
6059 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006060 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006061 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006062 ALC269_FIXUP_QUANTA_MUTE,
6063 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006064 ALC269_FIXUP_AMIC,
6065 ALC269_FIXUP_DMIC,
6066 ALC269VB_FIXUP_AMIC,
6067 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006068 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006069 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006070 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006071 ALC269_FIXUP_LENOVO_DOCK,
6072 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006073 ALC271_FIXUP_AMIC_MIC2,
6074 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006075};
6076
6077static const struct alc_fixup alc269_fixups[] = {
6078 [ALC269_FIXUP_SONY_VAIO] = {
6079 .type = ALC_FIXUP_VERBS,
6080 .v.verbs = (const struct hda_verb[]) {
6081 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6082 {}
6083 }
6084 },
6085 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6086 .type = ALC_FIXUP_VERBS,
6087 .v.verbs = (const struct hda_verb[]) {
6088 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6089 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6090 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6091 { }
6092 },
6093 .chained = true,
6094 .chain_id = ALC269_FIXUP_SONY_VAIO
6095 },
6096 [ALC269_FIXUP_DELL_M101Z] = {
6097 .type = ALC_FIXUP_VERBS,
6098 .v.verbs = (const struct hda_verb[]) {
6099 /* Enables internal speaker */
6100 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6101 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6102 {}
6103 }
6104 },
6105 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006106 .type = ALC_FIXUP_FUNC,
6107 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006108 },
6109 [ALC269_FIXUP_ASUS_G73JW] = {
6110 .type = ALC_FIXUP_PINS,
6111 .v.pins = (const struct alc_pincfg[]) {
6112 { 0x17, 0x99130111 }, /* subwoofer */
6113 { }
6114 }
6115 },
6116 [ALC269_FIXUP_LENOVO_EAPD] = {
6117 .type = ALC_FIXUP_VERBS,
6118 .v.verbs = (const struct hda_verb[]) {
6119 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6120 {}
6121 }
6122 },
6123 [ALC275_FIXUP_SONY_HWEQ] = {
6124 .type = ALC_FIXUP_FUNC,
6125 .v.func = alc269_fixup_hweq,
6126 .chained = true,
6127 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6128 },
6129 [ALC271_FIXUP_DMIC] = {
6130 .type = ALC_FIXUP_FUNC,
6131 .v.func = alc271_fixup_dmic,
6132 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006133 [ALC269_FIXUP_PCM_44K] = {
6134 .type = ALC_FIXUP_FUNC,
6135 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006136 .chained = true,
6137 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006138 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006139 [ALC269_FIXUP_STEREO_DMIC] = {
6140 .type = ALC_FIXUP_FUNC,
6141 .v.func = alc269_fixup_stereo_dmic,
6142 },
Takashi Iwai24519912011-08-16 15:08:49 +02006143 [ALC269_FIXUP_QUANTA_MUTE] = {
6144 .type = ALC_FIXUP_FUNC,
6145 .v.func = alc269_fixup_quanta_mute,
6146 },
6147 [ALC269_FIXUP_LIFEBOOK] = {
6148 .type = ALC_FIXUP_PINS,
6149 .v.pins = (const struct alc_pincfg[]) {
6150 { 0x1a, 0x2101103f }, /* dock line-out */
6151 { 0x1b, 0x23a11040 }, /* dock mic-in */
6152 { }
6153 },
6154 .chained = true,
6155 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6156 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006157 [ALC269_FIXUP_AMIC] = {
6158 .type = ALC_FIXUP_PINS,
6159 .v.pins = (const struct alc_pincfg[]) {
6160 { 0x14, 0x99130110 }, /* speaker */
6161 { 0x15, 0x0121401f }, /* HP out */
6162 { 0x18, 0x01a19c20 }, /* mic */
6163 { 0x19, 0x99a3092f }, /* int-mic */
6164 { }
6165 },
6166 },
6167 [ALC269_FIXUP_DMIC] = {
6168 .type = ALC_FIXUP_PINS,
6169 .v.pins = (const struct alc_pincfg[]) {
6170 { 0x12, 0x99a3092f }, /* int-mic */
6171 { 0x14, 0x99130110 }, /* speaker */
6172 { 0x15, 0x0121401f }, /* HP out */
6173 { 0x18, 0x01a19c20 }, /* mic */
6174 { }
6175 },
6176 },
6177 [ALC269VB_FIXUP_AMIC] = {
6178 .type = ALC_FIXUP_PINS,
6179 .v.pins = (const struct alc_pincfg[]) {
6180 { 0x14, 0x99130110 }, /* speaker */
6181 { 0x18, 0x01a19c20 }, /* mic */
6182 { 0x19, 0x99a3092f }, /* int-mic */
6183 { 0x21, 0x0121401f }, /* HP out */
6184 { }
6185 },
6186 },
David Henningsson2267ea92012-01-03 08:45:56 +01006187 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006188 .type = ALC_FIXUP_PINS,
6189 .v.pins = (const struct alc_pincfg[]) {
6190 { 0x12, 0x99a3092f }, /* int-mic */
6191 { 0x14, 0x99130110 }, /* speaker */
6192 { 0x18, 0x01a19c20 }, /* mic */
6193 { 0x21, 0x0121401f }, /* HP out */
6194 { }
6195 },
6196 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006197 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6198 .type = ALC_FIXUP_FUNC,
6199 .v.func = alc269_fixup_mic1_mute,
6200 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006201 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6202 .type = ALC_FIXUP_FUNC,
6203 .v.func = alc269_fixup_mic2_mute,
6204 },
David Henningsson693b6132012-06-22 19:12:10 +02006205 [ALC269_FIXUP_INV_DMIC] = {
6206 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006207 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006208 },
David Henningsson108cc102012-07-20 10:37:25 +02006209 [ALC269_FIXUP_LENOVO_DOCK] = {
6210 .type = ALC_FIXUP_PINS,
6211 .v.pins = (const struct alc_pincfg[]) {
6212 { 0x19, 0x23a11040 }, /* dock mic */
6213 { 0x1b, 0x2121103f }, /* dock headphone */
6214 { }
6215 },
6216 .chained = true,
6217 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6218 },
6219 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6220 .type = ALC_FIXUP_FUNC,
6221 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6222 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006223 [ALC271_FIXUP_AMIC_MIC2] = {
6224 .type = ALC_FIXUP_PINS,
6225 .v.pins = (const struct alc_pincfg[]) {
6226 { 0x14, 0x99130110 }, /* speaker */
6227 { 0x19, 0x01a19c20 }, /* mic */
6228 { 0x1b, 0x99a7012f }, /* int-mic */
6229 { 0x21, 0x0121401f }, /* HP out */
6230 { }
6231 },
6232 },
6233 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6234 .type = ALC_FIXUP_FUNC,
6235 .v.func = alc271_hp_gate_mic_jack,
6236 .chained = true,
6237 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6238 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006239};
6240
6241static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006242 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6243 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006244 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006245 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006246 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006247 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006248 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006249 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006250 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6251 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6252 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6253 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6254 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006255 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6256 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6257 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6258 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6259 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006260 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006261 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006262 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006263 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6264 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6265 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6266 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6267 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006268 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006269 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006270 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006271 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006272 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006273 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006274 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006275
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006276#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006277 /* Below is a quirk table taken from the old code.
6278 * Basically the device should work as is without the fixup table.
6279 * If BIOS doesn't give a proper info, enable the corresponding
6280 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006281 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006282 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6283 ALC269_FIXUP_AMIC),
6284 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006285 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6286 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6287 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6288 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6289 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6290 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6291 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6292 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6293 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6294 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6295 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6296 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6297 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6298 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6299 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6300 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6301 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6302 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6303 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6304 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6305 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6306 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6307 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6308 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6309 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6310 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6311 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6312 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6313 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6314 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6315 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6316 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6317 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6318 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6319 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6320 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6321 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6322 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6323#endif
6324 {}
6325};
6326
6327static const struct alc_model_fixup alc269_fixup_models[] = {
6328 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6329 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006330 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6331 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6332 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006333 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006334 {}
6335};
6336
6337
Takashi Iwai546bb672012-03-07 08:37:19 +01006338static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006339{
Kailang Yang526af6e2012-03-07 08:25:20 +01006340 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006341 int val;
6342
Kailang Yang526af6e2012-03-07 08:25:20 +01006343 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006344 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006345
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006346 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006347 alc_write_coef_idx(codec, 0xf, 0x960b);
6348 alc_write_coef_idx(codec, 0xe, 0x8817);
6349 }
6350
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006351 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006352 alc_write_coef_idx(codec, 0xf, 0x960b);
6353 alc_write_coef_idx(codec, 0xe, 0x8814);
6354 }
6355
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006356 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006357 val = alc_read_coef_idx(codec, 0x04);
6358 /* Power up output pin */
6359 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6360 }
6361
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006362 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006363 val = alc_read_coef_idx(codec, 0xd);
6364 if ((val & 0x0c00) >> 10 != 0x1) {
6365 /* Capless ramp up clock control */
6366 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6367 }
6368 val = alc_read_coef_idx(codec, 0x17);
6369 if ((val & 0x01c0) >> 6 != 0x4) {
6370 /* Class D power on reset */
6371 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6372 }
6373 }
6374
6375 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6376 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6377
6378 val = alc_read_coef_idx(codec, 0x4); /* HP */
6379 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006380}
6381
6382/*
6383 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006384static int patch_alc269(struct hda_codec *codec)
6385{
6386 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006387 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006388
Takashi Iwai3de95172012-05-07 18:03:15 +02006389 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006390 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006391 return err;
6392
6393 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01006394 spec->shared_mic_vref_pin = 0x18;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006395
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006396 alc_pick_fixup(codec, alc269_fixup_models,
6397 alc269_fixup_tbl, alc269_fixups);
6398 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6399
6400 alc_auto_parse_customize_define(codec);
6401
Kailang Yang065380f2013-01-10 10:25:48 +01006402 switch (codec->vendor_id) {
6403 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006404 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006405 switch (alc_get_coef0(codec) & 0x00f0) {
6406 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006407 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006408 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006409 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006410 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006411 break;
6412 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006413 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6414 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006415 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006416 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006417 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006418 case 0x0030:
6419 spec->codec_variant = ALC269_TYPE_ALC269VD;
6420 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006421 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006422 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006423 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006424 if (err < 0)
6425 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006426 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006427 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006428 break;
6429
6430 case 0x10ec0280:
6431 case 0x10ec0290:
6432 spec->codec_variant = ALC269_TYPE_ALC280;
6433 break;
6434 case 0x10ec0282:
6435 case 0x10ec0283:
6436 spec->codec_variant = ALC269_TYPE_ALC282;
6437 break;
6438 case 0x10ec0284:
6439 case 0x10ec0292:
6440 spec->codec_variant = ALC269_TYPE_ALC284;
6441 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006442 }
6443
Takashi Iwaia4297b52011-08-23 18:40:12 +02006444 /* automatic parse from the BIOS config */
6445 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006446 if (err < 0)
6447 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006448
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006449 if (!spec->no_analog && has_cdefine_beep(codec)) {
6450 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006451 if (err < 0)
6452 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006453 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006454 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006455
Takashi Iwai1d045db2011-07-07 18:23:21 +02006456 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006457#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006458 codec->patch_ops.resume = alc269_resume;
6459#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006460 spec->shutup = alc269_shutup;
6461
Takashi Iwai589876e2012-02-20 15:47:55 +01006462 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6463
Takashi Iwai1d045db2011-07-07 18:23:21 +02006464 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006465
6466 error:
6467 alc_free(codec);
6468 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006469}
6470
6471/*
6472 * ALC861
6473 */
6474
Takashi Iwai1d045db2011-07-07 18:23:21 +02006475static int alc861_parse_auto_config(struct hda_codec *codec)
6476{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006477 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006478 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6479 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006480}
6481
Takashi Iwai1d045db2011-07-07 18:23:21 +02006482/* Pin config fixes */
6483enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006484 ALC861_FIXUP_FSC_AMILO_PI1505,
6485 ALC861_FIXUP_AMP_VREF_0F,
6486 ALC861_FIXUP_NO_JACK_DETECT,
6487 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006488};
6489
Takashi Iwai31150f22012-01-30 10:54:08 +01006490/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6491static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6492 const struct alc_fixup *fix, int action)
6493{
6494 struct alc_spec *spec = codec->spec;
6495 unsigned int val;
6496
6497 if (action != ALC_FIXUP_ACT_INIT)
6498 return;
6499 val = snd_hda_codec_read(codec, 0x0f, 0,
6500 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6501 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6502 val |= AC_PINCTL_IN_EN;
6503 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006504 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006505 spec->keep_vref_in_automute = 1;
6506}
6507
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006508/* suppress the jack-detection */
6509static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6510 const struct alc_fixup *fix, int action)
6511{
6512 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6513 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006514}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006515
Takashi Iwai1d045db2011-07-07 18:23:21 +02006516static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006517 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006518 .type = ALC_FIXUP_PINS,
6519 .v.pins = (const struct alc_pincfg[]) {
6520 { 0x0b, 0x0221101f }, /* HP */
6521 { 0x0f, 0x90170310 }, /* speaker */
6522 { }
6523 }
6524 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006525 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006526 .type = ALC_FIXUP_FUNC,
6527 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006528 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006529 [ALC861_FIXUP_NO_JACK_DETECT] = {
6530 .type = ALC_FIXUP_FUNC,
6531 .v.func = alc_fixup_no_jack_detect,
6532 },
6533 [ALC861_FIXUP_ASUS_A6RP] = {
6534 .type = ALC_FIXUP_FUNC,
6535 .v.func = alc861_fixup_asus_amp_vref_0f,
6536 .chained = true,
6537 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6538 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006539};
6540
6541static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006542 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6543 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6544 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6545 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6546 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6547 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006548 {}
6549};
6550
6551/*
6552 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006553static int patch_alc861(struct hda_codec *codec)
6554{
6555 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006556 int err;
6557
Takashi Iwai3de95172012-05-07 18:03:15 +02006558 err = alc_alloc_spec(codec, 0x15);
6559 if (err < 0)
6560 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006561
Takashi Iwai3de95172012-05-07 18:03:15 +02006562 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006563
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006564 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6565 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006566
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006567 /* automatic parse from the BIOS config */
6568 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006569 if (err < 0)
6570 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006571
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006572 if (!spec->no_analog) {
6573 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006574 if (err < 0)
6575 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006576 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6577 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006578
Takashi Iwai1d045db2011-07-07 18:23:21 +02006579 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006580#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006581 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006582#endif
6583
Takashi Iwai589876e2012-02-20 15:47:55 +01006584 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6585
Takashi Iwai1d045db2011-07-07 18:23:21 +02006586 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006587
6588 error:
6589 alc_free(codec);
6590 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006591}
6592
6593/*
6594 * ALC861-VD support
6595 *
6596 * Based on ALC882
6597 *
6598 * In addition, an independent DAC
6599 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006600static int alc861vd_parse_auto_config(struct hda_codec *codec)
6601{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006602 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006603 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6604 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006605}
6606
Takashi Iwai1d045db2011-07-07 18:23:21 +02006607enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006608 ALC660VD_FIX_ASUS_GPIO1,
6609 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006610};
6611
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006612/* exclude VREF80 */
6613static void alc861vd_fixup_dallas(struct hda_codec *codec,
6614 const struct alc_fixup *fix, int action)
6615{
6616 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006617 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6618 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006619 }
6620}
6621
Takashi Iwai1d045db2011-07-07 18:23:21 +02006622static const struct alc_fixup alc861vd_fixups[] = {
6623 [ALC660VD_FIX_ASUS_GPIO1] = {
6624 .type = ALC_FIXUP_VERBS,
6625 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006626 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006627 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6628 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6629 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6630 { }
6631 }
6632 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006633 [ALC861VD_FIX_DALLAS] = {
6634 .type = ALC_FIXUP_FUNC,
6635 .v.func = alc861vd_fixup_dallas,
6636 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006637};
6638
6639static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006640 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006641 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006642 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006643 {}
6644};
6645
Takashi Iwai1d045db2011-07-07 18:23:21 +02006646/*
6647 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006648static int patch_alc861vd(struct hda_codec *codec)
6649{
6650 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006651 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006652
Takashi Iwai3de95172012-05-07 18:03:15 +02006653 err = alc_alloc_spec(codec, 0x0b);
6654 if (err < 0)
6655 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006656
Takashi Iwai3de95172012-05-07 18:03:15 +02006657 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006658
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006659 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6660 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006661
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006662 /* automatic parse from the BIOS config */
6663 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006664 if (err < 0)
6665 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006666
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006667 if (!spec->no_analog) {
6668 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006669 if (err < 0)
6670 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006671 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6672 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006673
Takashi Iwai1d045db2011-07-07 18:23:21 +02006674 codec->patch_ops = alc_patch_ops;
6675
Takashi Iwai1d045db2011-07-07 18:23:21 +02006676 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006677
Takashi Iwai589876e2012-02-20 15:47:55 +01006678 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6679
Takashi Iwai1d045db2011-07-07 18:23:21 +02006680 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006681
6682 error:
6683 alc_free(codec);
6684 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006685}
6686
6687/*
6688 * ALC662 support
6689 *
6690 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6691 * configuration. Each pin widget can choose any input DACs and a mixer.
6692 * Each ADC is connected from a mixer of all inputs. This makes possible
6693 * 6-channel independent captures.
6694 *
6695 * In addition, an independent DAC for the multi-playback (not used in this
6696 * driver yet).
6697 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006698
6699/*
6700 * BIOS auto configuration
6701 */
6702
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006703static int alc662_parse_auto_config(struct hda_codec *codec)
6704{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006705 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006706 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6707 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6708 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006709
Kailang Yang6227cdc2010-02-25 08:36:52 +01006710 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6711 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006712 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006713 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006714 ssids = alc662_ssids;
6715 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006716}
6717
Todd Broch6be79482010-12-07 16:51:05 -08006718static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006719 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006720{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006721 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006722 return;
Todd Broch6be79482010-12-07 16:51:05 -08006723 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6724 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6725 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6726 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6727 (0 << AC_AMPCAP_MUTE_SHIFT)))
6728 printk(KERN_WARNING
6729 "hda_codec: failed to override amp caps for NID 0x2\n");
6730}
6731
David Henningsson6cb3b702010-09-09 08:51:44 +02006732enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006733 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006734 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006735 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006736 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006737 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006738 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006739 ALC662_FIXUP_ASUS_MODE1,
6740 ALC662_FIXUP_ASUS_MODE2,
6741 ALC662_FIXUP_ASUS_MODE3,
6742 ALC662_FIXUP_ASUS_MODE4,
6743 ALC662_FIXUP_ASUS_MODE5,
6744 ALC662_FIXUP_ASUS_MODE6,
6745 ALC662_FIXUP_ASUS_MODE7,
6746 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006747 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006748 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006749 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006750};
6751
6752static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006753 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006754 .type = ALC_FIXUP_PINS,
6755 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006756 { 0x15, 0x99130112 }, /* subwoofer */
6757 { }
6758 }
6759 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006760 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006761 .type = ALC_FIXUP_PINS,
6762 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006763 { 0x17, 0x99130112 }, /* subwoofer */
6764 { }
6765 }
6766 },
Todd Broch6be79482010-12-07 16:51:05 -08006767 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006768 .type = ALC_FIXUP_FUNC,
6769 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006770 },
6771 [ALC662_FIXUP_CZC_P10T] = {
6772 .type = ALC_FIXUP_VERBS,
6773 .v.verbs = (const struct hda_verb[]) {
6774 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6775 {}
6776 }
6777 },
David Henningsson94024cd2011-04-29 14:10:55 +02006778 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006779 .type = ALC_FIXUP_FUNC,
6780 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006781 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006782 [ALC662_FIXUP_HP_RP5800] = {
6783 .type = ALC_FIXUP_PINS,
6784 .v.pins = (const struct alc_pincfg[]) {
6785 { 0x14, 0x0221201f }, /* HP out */
6786 { }
6787 },
6788 .chained = true,
6789 .chain_id = ALC662_FIXUP_SKU_IGNORE
6790 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006791 [ALC662_FIXUP_ASUS_MODE1] = {
6792 .type = ALC_FIXUP_PINS,
6793 .v.pins = (const struct alc_pincfg[]) {
6794 { 0x14, 0x99130110 }, /* speaker */
6795 { 0x18, 0x01a19c20 }, /* mic */
6796 { 0x19, 0x99a3092f }, /* int-mic */
6797 { 0x21, 0x0121401f }, /* HP out */
6798 { }
6799 },
6800 .chained = true,
6801 .chain_id = ALC662_FIXUP_SKU_IGNORE
6802 },
6803 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006804 .type = ALC_FIXUP_PINS,
6805 .v.pins = (const struct alc_pincfg[]) {
6806 { 0x14, 0x99130110 }, /* speaker */
6807 { 0x18, 0x01a19820 }, /* mic */
6808 { 0x19, 0x99a3092f }, /* int-mic */
6809 { 0x1b, 0x0121401f }, /* HP out */
6810 { }
6811 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006812 .chained = true,
6813 .chain_id = ALC662_FIXUP_SKU_IGNORE
6814 },
6815 [ALC662_FIXUP_ASUS_MODE3] = {
6816 .type = ALC_FIXUP_PINS,
6817 .v.pins = (const struct alc_pincfg[]) {
6818 { 0x14, 0x99130110 }, /* speaker */
6819 { 0x15, 0x0121441f }, /* HP */
6820 { 0x18, 0x01a19840 }, /* mic */
6821 { 0x19, 0x99a3094f }, /* int-mic */
6822 { 0x21, 0x01211420 }, /* HP2 */
6823 { }
6824 },
6825 .chained = true,
6826 .chain_id = ALC662_FIXUP_SKU_IGNORE
6827 },
6828 [ALC662_FIXUP_ASUS_MODE4] = {
6829 .type = ALC_FIXUP_PINS,
6830 .v.pins = (const struct alc_pincfg[]) {
6831 { 0x14, 0x99130110 }, /* speaker */
6832 { 0x16, 0x99130111 }, /* speaker */
6833 { 0x18, 0x01a19840 }, /* mic */
6834 { 0x19, 0x99a3094f }, /* int-mic */
6835 { 0x21, 0x0121441f }, /* HP */
6836 { }
6837 },
6838 .chained = true,
6839 .chain_id = ALC662_FIXUP_SKU_IGNORE
6840 },
6841 [ALC662_FIXUP_ASUS_MODE5] = {
6842 .type = ALC_FIXUP_PINS,
6843 .v.pins = (const struct alc_pincfg[]) {
6844 { 0x14, 0x99130110 }, /* speaker */
6845 { 0x15, 0x0121441f }, /* HP */
6846 { 0x16, 0x99130111 }, /* speaker */
6847 { 0x18, 0x01a19840 }, /* mic */
6848 { 0x19, 0x99a3094f }, /* int-mic */
6849 { }
6850 },
6851 .chained = true,
6852 .chain_id = ALC662_FIXUP_SKU_IGNORE
6853 },
6854 [ALC662_FIXUP_ASUS_MODE6] = {
6855 .type = ALC_FIXUP_PINS,
6856 .v.pins = (const struct alc_pincfg[]) {
6857 { 0x14, 0x99130110 }, /* speaker */
6858 { 0x15, 0x01211420 }, /* HP2 */
6859 { 0x18, 0x01a19840 }, /* mic */
6860 { 0x19, 0x99a3094f }, /* int-mic */
6861 { 0x1b, 0x0121441f }, /* HP */
6862 { }
6863 },
6864 .chained = true,
6865 .chain_id = ALC662_FIXUP_SKU_IGNORE
6866 },
6867 [ALC662_FIXUP_ASUS_MODE7] = {
6868 .type = ALC_FIXUP_PINS,
6869 .v.pins = (const struct alc_pincfg[]) {
6870 { 0x14, 0x99130110 }, /* speaker */
6871 { 0x17, 0x99130111 }, /* speaker */
6872 { 0x18, 0x01a19840 }, /* mic */
6873 { 0x19, 0x99a3094f }, /* int-mic */
6874 { 0x1b, 0x01214020 }, /* HP */
6875 { 0x21, 0x0121401f }, /* HP */
6876 { }
6877 },
6878 .chained = true,
6879 .chain_id = ALC662_FIXUP_SKU_IGNORE
6880 },
6881 [ALC662_FIXUP_ASUS_MODE8] = {
6882 .type = ALC_FIXUP_PINS,
6883 .v.pins = (const struct alc_pincfg[]) {
6884 { 0x14, 0x99130110 }, /* speaker */
6885 { 0x12, 0x99a30970 }, /* int-mic */
6886 { 0x15, 0x01214020 }, /* HP */
6887 { 0x17, 0x99130111 }, /* speaker */
6888 { 0x18, 0x01a19840 }, /* mic */
6889 { 0x21, 0x0121401f }, /* HP */
6890 { }
6891 },
6892 .chained = true,
6893 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006894 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006895 [ALC662_FIXUP_NO_JACK_DETECT] = {
6896 .type = ALC_FIXUP_FUNC,
6897 .v.func = alc_fixup_no_jack_detect,
6898 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006899 [ALC662_FIXUP_ZOTAC_Z68] = {
6900 .type = ALC_FIXUP_PINS,
6901 .v.pins = (const struct alc_pincfg[]) {
6902 { 0x1b, 0x02214020 }, /* Front HP */
6903 { }
6904 }
6905 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006906 [ALC662_FIXUP_INV_DMIC] = {
6907 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006908 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006909 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006910};
6911
Takashi Iwaia9111322011-05-02 11:30:18 +02006912static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006913 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006914 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006915 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006916 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006917 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006918 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006919 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006920 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006921 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006922 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006923 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006924 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006925 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006926
6927#if 0
6928 /* Below is a quirk table taken from the old code.
6929 * Basically the device should work as is without the fixup table.
6930 * If BIOS doesn't give a proper info, enable the corresponding
6931 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006932 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006933 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6934 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6935 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6936 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6937 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6938 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6939 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6940 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6941 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6942 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6943 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6944 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6945 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6946 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6947 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6948 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6949 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6950 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6951 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6952 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6953 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6954 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6955 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6956 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6957 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6958 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6959 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6960 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6961 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6962 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6963 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6964 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6965 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6966 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6967 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6968 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6969 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6970 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6971 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6972 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6973 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6974 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6975 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6976 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6977 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6978 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6979 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6980 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6981 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6982 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6983#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006984 {}
6985};
6986
Todd Broch6be79482010-12-07 16:51:05 -08006987static const struct alc_model_fixup alc662_fixup_models[] = {
6988 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006989 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6990 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6991 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6992 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6993 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6994 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6995 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6996 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006997 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08006998 {}
6999};
David Henningsson6cb3b702010-09-09 08:51:44 +02007000
Kailang Yang8663ff72012-06-29 09:35:52 +02007001static void alc662_fill_coef(struct hda_codec *codec)
7002{
7003 int val, coef;
7004
7005 coef = alc_get_coef0(codec);
7006
7007 switch (codec->vendor_id) {
7008 case 0x10ec0662:
7009 if ((coef & 0x00f0) == 0x0030) {
7010 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7011 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7012 }
7013 break;
7014 case 0x10ec0272:
7015 case 0x10ec0273:
7016 case 0x10ec0663:
7017 case 0x10ec0665:
7018 case 0x10ec0670:
7019 case 0x10ec0671:
7020 case 0x10ec0672:
7021 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7022 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7023 break;
7024 }
7025}
David Henningsson6cb3b702010-09-09 08:51:44 +02007026
Takashi Iwai1d045db2011-07-07 18:23:21 +02007027/*
7028 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007029static int patch_alc662(struct hda_codec *codec)
7030{
7031 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007032 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007033
Takashi Iwai3de95172012-05-07 18:03:15 +02007034 err = alc_alloc_spec(codec, 0x0b);
7035 if (err < 0)
7036 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007037
Takashi Iwai3de95172012-05-07 18:03:15 +02007038 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007039
Takashi Iwai53c334a2011-08-23 18:27:14 +02007040 /* handle multiple HPs as is */
7041 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7042
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007043 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7044
Kailang Yang8663ff72012-06-29 09:35:52 +02007045 spec->init_hook = alc662_fill_coef;
7046 alc662_fill_coef(codec);
7047
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007048 alc_pick_fixup(codec, alc662_fixup_models,
7049 alc662_fixup_tbl, alc662_fixups);
7050 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7051
7052 alc_auto_parse_customize_define(codec);
7053
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007054 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007055 codec->bus->pci->subsystem_vendor == 0x1025 &&
7056 spec->cdefine.platform_type == 1) {
7057 if (alc_codec_rename(codec, "ALC272X") < 0)
7058 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007059 }
Kailang Yang274693f2009-12-03 10:07:50 +01007060
Takashi Iwaib9c51062011-08-24 18:08:07 +02007061 /* automatic parse from the BIOS config */
7062 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007063 if (err < 0)
7064 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007065
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007066 if (!spec->no_analog && has_cdefine_beep(codec)) {
7067 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007068 if (err < 0)
7069 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007070 switch (codec->vendor_id) {
7071 case 0x10ec0662:
7072 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7073 break;
7074 case 0x10ec0272:
7075 case 0x10ec0663:
7076 case 0x10ec0665:
7077 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7078 break;
7079 case 0x10ec0273:
7080 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7081 break;
7082 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007083 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007084
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007085 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007086 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007087
Takashi Iwai589876e2012-02-20 15:47:55 +01007088 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7089
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007090 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007091
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007092 error:
7093 alc_free(codec);
7094 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007095}
7096
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007097/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007098 * ALC680 support
7099 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007100
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007101static int alc680_parse_auto_config(struct hda_codec *codec)
7102{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007103 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007104}
7105
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007106/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007107 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007108static int patch_alc680(struct hda_codec *codec)
7109{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007110 int err;
7111
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007112 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007113 err = alc_alloc_spec(codec, 0);
7114 if (err < 0)
7115 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007116
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007117 /* automatic parse from the BIOS config */
7118 err = alc680_parse_auto_config(codec);
7119 if (err < 0) {
7120 alc_free(codec);
7121 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007122 }
7123
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007124 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007125
7126 return 0;
7127}
7128
7129/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007130 * patch entries
7131 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007132static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007133 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007134 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007135 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007136 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007137 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007138 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007139 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007140 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007141 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007142 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007143 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007144 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007145 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007146 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007147 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007148 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007149 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007150 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007151 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7152 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7153 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007154 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007155 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007156 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7157 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007158 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7159 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007160 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007161 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007162 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007163 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007164 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007165 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007166 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007167 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007168 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007169 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007170 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007171 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007172 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007173 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007174 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007175 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007176 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007177 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007178 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007179 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007180 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007181 {} /* terminator */
7182};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007183
7184MODULE_ALIAS("snd-hda-codec-id:10ec*");
7185
7186MODULE_LICENSE("GPL");
7187MODULE_DESCRIPTION("Realtek HD-audio codec");
7188
7189static struct hda_codec_preset_list realtek_list = {
7190 .preset = snd_hda_preset_realtek,
7191 .owner = THIS_MODULE,
7192};
7193
7194static int __init patch_realtek_init(void)
7195{
7196 return snd_hda_add_codec_preset(&realtek_list);
7197}
7198
7199static void __exit patch_realtek_exit(void)
7200{
7201 snd_hda_delete_codec_preset(&realtek_list);
7202}
7203
7204module_init(patch_realtek_init)
7205module_exit(patch_realtek_exit)