blob: 25c0fc911666d2fb4e10674f12846b72521e43fe [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 Iwai4a79ba342009-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 Iwai1c7161532011-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 Iwai4a79ba342009-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 Iwai1c7161532011-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 Iwai4a79ba342009-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 Iwai4a79ba342009-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 Iwai4a79ba342009-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 Iwai4a79ba342009-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 Iwai4a79ba342009-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 Iwai4a79ba342009-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 Iwai4a79ba342009-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 Iwai4a79ba342009-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;
865 knew->name = kstrdup(name, GFP_KERNEL);
866 if (!knew->name)
867 return NULL;
868 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200869}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200870
871static int alc_add_automute_mode_enum(struct hda_codec *codec)
872{
873 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200874
Takashi Iwai668d1e92012-11-29 14:10:17 +0100875 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200876 return -ENOMEM;
877 return 0;
878}
879
Takashi Iwai1d045db2011-07-07 18:23:21 +0200880/*
881 * Check the availability of HP/line-out auto-mute;
882 * Set up appropriately if really supported
883 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100884static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba342009-04-22 16:31:35 +0200885{
886 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200887 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200888 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100889 int i, err;
Takashi Iwai4a79ba342009-04-22 16:31:35 +0200890
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200891 if (cfg->hp_pins[0])
892 present++;
893 if (cfg->line_out_pins[0])
894 present++;
895 if (cfg->speaker_pins[0])
896 present++;
897 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100898 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200899
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200900 if (!cfg->speaker_pins[0] &&
901 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200902 memcpy(cfg->speaker_pins, cfg->line_out_pins,
903 sizeof(cfg->speaker_pins));
904 cfg->speaker_outs = cfg->line_outs;
905 }
906
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200907 if (!cfg->hp_pins[0] &&
908 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200909 memcpy(cfg->hp_pins, cfg->line_out_pins,
910 sizeof(cfg->hp_pins));
911 cfg->hp_outs = cfg->line_outs;
912 }
913
914 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200915 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200916 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200917 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200918 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200919 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200920 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
921 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200922 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200923 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200924
David Henningsson42cf0d02011-09-20 12:04:56 +0200925 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
926 if (cfg->speaker_outs)
927 for (i = 0; i < cfg->line_outs; i++) {
928 hda_nid_t nid = cfg->line_out_pins[i];
929 if (!is_jack_detectable(codec, nid))
930 continue;
931 snd_printdd("realtek: Enable Line-Out "
932 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200933 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
934 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200935 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200936 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200937 spec->automute_lo_possible = spec->detect_hp;
938 }
939
940 spec->automute_speaker_possible = cfg->speaker_outs &&
941 (spec->detect_hp || spec->detect_lo);
942
943 spec->automute_lo = spec->automute_lo_possible;
944 spec->automute_speaker = spec->automute_speaker_possible;
945
Takashi Iwai475c3d22012-11-30 08:31:30 +0100946 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200947 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100948 err = alc_add_automute_mode_enum(codec);
949 if (err < 0)
950 return err;
951 }
952 return 0;
Takashi Iwai4a79ba342009-04-22 16:31:35 +0200953}
954
Takashi Iwai1d045db2011-07-07 18:23:21 +0200955/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200956static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
957{
958 int i;
959 for (i = 0; i < nums; i++)
960 if (list[i] == nid)
961 return i;
962 return -1;
963}
964
Takashi Iwai21268962011-07-07 15:01:13 +0200965/* check whether all auto-mic pins are valid; setup indices if OK */
966static bool alc_auto_mic_check_imux(struct hda_codec *codec)
967{
968 struct alc_spec *spec = codec->spec;
969 const struct hda_input_mux *imux;
970
Takashi Iwai27d31532012-12-18 08:57:05 +0100971 imux = &spec->input_mux;
Takashi Iwai21268962011-07-07 15:01:13 +0200972 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
973 spec->imux_pins, imux->num_items);
974 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
975 spec->imux_pins, imux->num_items);
976 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
977 spec->imux_pins, imux->num_items);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100978 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0)
Takashi Iwai21268962011-07-07 15:01:13 +0200979 return false; /* no corresponding imux */
Takashi Iwai21268962011-07-07 15:01:13 +0200980
David Henningsson29adc4b2012-09-25 11:31:00 +0200981 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
982 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200983 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +0200984 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
985 ALC_MIC_EVENT,
986 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200987 return true;
988}
989
Takashi Iwai1d045db2011-07-07 18:23:21 +0200990/*
991 * Check the availability of auto-mic switch;
992 * Set up if really supported
993 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100994static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +0200995{
996 struct alc_spec *spec = codec->spec;
997 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200998 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +0200999 int i;
1000
Takashi Iwai21268962011-07-07 15:01:13 +02001001 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1002
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001003 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001004 for (i = 0; i < cfg->num_inputs; i++) {
1005 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001006 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001007 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001008 switch (snd_hda_get_input_pin_attr(defcfg)) {
1009 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001010 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001011 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001012 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001013 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001014 fixed = nid;
1015 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001016 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001017 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001018 case INPUT_PIN_ATTR_DOCK:
1019 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001020 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001021 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001022 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001023 dock = nid;
1024 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001025 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001026 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001027 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001028 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001029 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001030 ext = nid;
1031 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001032 }
1033 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001034 if (!ext && dock) {
1035 ext = dock;
1036 dock = 0;
1037 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001038 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001039 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001040 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001041 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001042 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001043 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001044
1045 /* check imux indices */
1046 spec->ext_mic_pin = ext;
1047 spec->int_mic_pin = fixed;
1048 spec->dock_mic_pin = dock;
1049
Takashi Iwai21268962011-07-07 15:01:13 +02001050 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001051 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001052
Takashi Iwai666a70d2012-12-17 20:29:29 +01001053 spec->auto_mic = 1;
1054 spec->num_adc_nids = 1;
1055 spec->cur_mux[0] = spec->int_mic_idx;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001056 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1057 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001058
1059 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001060}
1061
Takashi Iwai1d045db2011-07-07 18:23:21 +02001062/*
1063 * Realtek SSID verification
1064 */
1065
David Henningsson90622912010-10-14 14:50:18 +02001066/* Could be any non-zero and even value. When used as fixup, tells
1067 * the driver to ignore any present sku defines.
1068 */
1069#define ALC_FIXUP_SKU_IGNORE (2)
1070
Takashi Iwai23d30f22012-05-07 17:17:32 +02001071static void alc_fixup_sku_ignore(struct hda_codec *codec,
1072 const struct hda_fixup *fix, int action)
1073{
1074 struct alc_spec *spec = codec->spec;
1075 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1076 spec->cdefine.fixup = 1;
1077 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1078 }
1079}
1080
Kailang Yangda00c242010-03-19 11:23:45 +01001081static int alc_auto_parse_customize_define(struct hda_codec *codec)
1082{
1083 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001084 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001085 struct alc_spec *spec = codec->spec;
1086
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001087 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1088
David Henningsson90622912010-10-14 14:50:18 +02001089 if (spec->cdefine.fixup) {
1090 ass = spec->cdefine.sku_cfg;
1091 if (ass == ALC_FIXUP_SKU_IGNORE)
1092 return -1;
1093 goto do_sku;
1094 }
1095
Kailang Yangda00c242010-03-19 11:23:45 +01001096 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001097 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001098 goto do_sku;
1099
1100 nid = 0x1d;
1101 if (codec->vendor_id == 0x10ec0260)
1102 nid = 0x17;
1103 ass = snd_hda_codec_get_pincfg(codec, nid);
1104
1105 if (!(ass & 1)) {
1106 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1107 codec->chip_name, ass);
1108 return -1;
1109 }
1110
1111 /* check sum */
1112 tmp = 0;
1113 for (i = 1; i < 16; i++) {
1114 if ((ass >> i) & 1)
1115 tmp++;
1116 }
1117 if (((ass >> 16) & 0xf) != tmp)
1118 return -1;
1119
1120 spec->cdefine.port_connectivity = ass >> 30;
1121 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1122 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1123 spec->cdefine.customization = ass >> 8;
1124do_sku:
1125 spec->cdefine.sku_cfg = ass;
1126 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1127 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1128 spec->cdefine.swap = (ass & 0x2) >> 1;
1129 spec->cdefine.override = ass & 0x1;
1130
1131 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1132 nid, spec->cdefine.sku_cfg);
1133 snd_printd("SKU: port_connectivity=0x%x\n",
1134 spec->cdefine.port_connectivity);
1135 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1136 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1137 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1138 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1139 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1140 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1141 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1142
1143 return 0;
1144}
1145
Takashi Iwai1d045db2011-07-07 18:23:21 +02001146/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001147static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1148{
Takashi Iwai21268962011-07-07 15:01:13 +02001149 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001150}
1151
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001152/* check subsystem ID and set up device-specific initialization;
1153 * return 1 if initialized, 0 if invalid SSID
1154 */
1155/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1156 * 31 ~ 16 : Manufacture ID
1157 * 15 ~ 8 : SKU ID
1158 * 7 ~ 0 : Assembly ID
1159 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1160 */
1161static int alc_subsystem_id(struct hda_codec *codec,
1162 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001163 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001164{
1165 unsigned int ass, tmp, i;
1166 unsigned nid;
1167 struct alc_spec *spec = codec->spec;
1168
David Henningsson90622912010-10-14 14:50:18 +02001169 if (spec->cdefine.fixup) {
1170 ass = spec->cdefine.sku_cfg;
1171 if (ass == ALC_FIXUP_SKU_IGNORE)
1172 return 0;
1173 goto do_sku;
1174 }
1175
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001176 ass = codec->subsystem_id & 0xffff;
1177 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1178 goto do_sku;
1179
1180 /* invalid SSID, check the special NID pin defcfg instead */
1181 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001182 * 31~30 : port connectivity
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001183 * 29~21 : reserve
1184 * 20 : PCBEEP input
1185 * 19~16 : Check sum (15:1)
1186 * 15~1 : Custom
1187 * 0 : override
1188 */
1189 nid = 0x1d;
1190 if (codec->vendor_id == 0x10ec0260)
1191 nid = 0x17;
1192 ass = snd_hda_codec_get_pincfg(codec, nid);
1193 snd_printd("realtek: No valid SSID, "
1194 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001195 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001196 if (!(ass & 1))
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001197 return 0;
1198 if ((ass >> 30) != 1) /* no physical connection */
1199 return 0;
1200
1201 /* check sum */
1202 tmp = 0;
1203 for (i = 1; i < 16; i++) {
1204 if ((ass >> i) & 1)
1205 tmp++;
1206 }
1207 if (((ass >> 16) & 0xf) != tmp)
1208 return 0;
1209do_sku:
1210 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1211 ass & 0xffff, codec->vendor_id);
1212 /*
1213 * 0 : override
1214 * 1 : Swap Jack
1215 * 2 : 0 --> Desktop, 1 --> Laptop
1216 * 3~5 : External Amplifier control
1217 * 7~6 : Reserved
1218 */
1219 tmp = (ass & 0x38) >> 3; /* external Amp control */
1220 switch (tmp) {
1221 case 1:
1222 spec->init_amp = ALC_INIT_GPIO1;
1223 break;
1224 case 3:
1225 spec->init_amp = ALC_INIT_GPIO2;
1226 break;
1227 case 7:
1228 spec->init_amp = ALC_INIT_GPIO3;
1229 break;
1230 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001231 default:
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001232 spec->init_amp = ALC_INIT_DEFAULT;
1233 break;
1234 }
1235
1236 /* is laptop or Desktop and enable the function "Mute internal speaker
1237 * when the external headphone out jack is plugged"
1238 */
1239 if (!(ass & 0x8000))
1240 return 1;
1241 /*
1242 * 10~8 : Jack location
1243 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1244 * 14~13: Resvered
1245 * 15 : 1 --> enable the function "Mute internal speaker
1246 * when the external headphone out jack is plugged"
1247 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001248 if (!spec->autocfg.hp_pins[0] &&
1249 !(spec->autocfg.line_out_pins[0] &&
1250 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001251 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001252 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1253 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001254 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001255 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001256 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001257 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001258 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001259 else if (tmp == 3)
1260 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001261 else
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001262 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001263 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1264 spec->autocfg.line_outs))
1265 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001266 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001267 }
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001268 return 1;
1269}
Kailang Yangea1fb292008-08-26 12:58:38 +02001270
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001271/* Check the validity of ALC subsystem-id
1272 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1273static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001274{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001275 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001276 struct alc_spec *spec = codec->spec;
1277 snd_printd("realtek: "
1278 "Enable default setup for auto mode as fallback\n");
1279 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001280 }
Takashi Iwai21268962011-07-07 15:01:13 +02001281}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001282
Takashi Iwai41e41f12005-06-08 14:48:49 +02001283/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001284 * COEF access helper functions
1285 */
Kailang Yang274693f2009-12-03 10:07:50 +01001286static int alc_read_coef_idx(struct hda_codec *codec,
1287 unsigned int coef_idx)
1288{
1289 unsigned int val;
1290 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1291 coef_idx);
1292 val = snd_hda_codec_read(codec, 0x20, 0,
1293 AC_VERB_GET_PROC_COEF, 0);
1294 return val;
1295}
1296
Kailang Yang977ddd62010-09-15 10:02:29 +02001297static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1298 unsigned int coef_val)
1299{
1300 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1301 coef_idx);
1302 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1303 coef_val);
1304}
1305
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001306/* a special bypass for COEF 0; read the cached value at the second time */
1307static unsigned int alc_get_coef0(struct hda_codec *codec)
1308{
1309 struct alc_spec *spec = codec->spec;
1310 if (!spec->coef0)
1311 spec->coef0 = alc_read_coef_idx(codec, 0);
1312 return spec->coef0;
1313}
1314
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001315static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1316 hda_nid_t pin, int pin_type,
1317 hda_nid_t dac);
1318static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1319 bool is_digital);
Takashi Iwai965cceb2012-12-18 11:46:37 +01001320static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
1321 hda_nid_t to_nid, int with_aa_mix,
1322 struct nid_path *path);
1323static struct nid_path *add_new_nid_path(struct hda_codec *codec,
1324 hda_nid_t from_nid, hda_nid_t to_nid,
1325 int with_aa_mix);
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001326
Takashi Iwai1d045db2011-07-07 18:23:21 +02001327/*
1328 * Digital I/O handling
1329 */
1330
Takashi Iwai757899a2010-07-30 10:48:14 +02001331/* set right pin controls for digital I/O */
1332static void alc_auto_init_digital(struct hda_codec *codec)
1333{
1334 struct alc_spec *spec = codec->spec;
1335 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001336 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001337
1338 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1339 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001340 if (!pin)
1341 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001342 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001343 }
1344 pin = spec->autocfg.dig_in_pin;
1345 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001346 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001347}
1348
1349/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1350static void alc_auto_parse_digital(struct hda_codec *codec)
1351{
1352 struct alc_spec *spec = codec->spec;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001353 int i, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001354 hda_nid_t dig_nid;
1355
1356 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001357 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001358 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001359 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1360 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1361 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001362 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001363 if (!add_new_nid_path(codec, dig_nid, pin, 2))
1364 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001365 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001366 spec->multiout.dig_out_nid = dig_nid;
1367 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1368 } else {
1369 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001370 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001371 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001372 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001373 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001374 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001375 }
1376
1377 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001378 dig_nid = codec->start_nid;
1379 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001380 struct nid_path *path;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001381 unsigned int wcaps = get_wcaps(codec, dig_nid);
1382 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1383 continue;
1384 if (!(wcaps & AC_WCAP_DIGITAL))
1385 continue;
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001386 path = add_new_nid_path(codec, spec->autocfg.dig_in_pin,
1387 dig_nid, 2);
1388 if (path) {
1389 path->active = true;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001390 spec->dig_in_nid = dig_nid;
1391 break;
1392 }
1393 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001394 }
1395}
1396
Takashi Iwaif95474e2007-07-10 00:47:43 +02001397/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001398 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001399 */
Takashi Iwai666a70d2012-12-17 20:29:29 +01001400#define alc_cap_vol_info snd_hda_mixer_amp_volume_info
1401#define alc_cap_vol_get snd_hda_mixer_amp_volume_get
1402#define alc_cap_vol_tlv snd_hda_mixer_amp_tlv
1403
1404typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
1405 struct snd_ctl_elem_value *ucontrol);
1406
1407static int alc_cap_put_caller(struct snd_kcontrol *kcontrol,
1408 struct snd_ctl_elem_value *ucontrol,
1409 put_call_t func, int type)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001410{
1411 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1412 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001413 const struct hda_input_mux *imux;
1414 struct nid_path *path;
1415 int i, adc_idx, err = 0;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001416
Takashi Iwai27d31532012-12-18 08:57:05 +01001417 imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001418 adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001419 mutex_lock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001420 codec->cached_write = 1;
1421 for (i = 0; i < imux->num_items; i++) {
1422 path = get_nid_path(codec, spec->imux_pins[i],
1423 get_adc_nid(codec, adc_idx, i));
1424 if (!path->ctls[type])
1425 continue;
1426 kcontrol->private_value = path->ctls[type];
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001427 err = func(kcontrol, ucontrol);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001428 if (err < 0)
1429 goto error;
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001430 }
1431 error:
Takashi Iwai666a70d2012-12-17 20:29:29 +01001432 codec->cached_write = 0;
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001433 mutex_unlock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001434 snd_hda_codec_resume_amp(codec);
1435 if (err >= 0 && type == NID_PATH_MUTE_CTL &&
1436 spec->inv_dmic_fixup && spec->inv_dmic_muted)
1437 alc_inv_dmic_sync_adc(codec, adc_idx);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001438 return err;
1439}
1440
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001441static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1442 struct snd_ctl_elem_value *ucontrol)
1443{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001444 return alc_cap_put_caller(kcontrol, ucontrol,
1445 snd_hda_mixer_amp_volume_put,
1446 NID_PATH_VOL_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001447}
1448
1449/* capture mixer elements */
1450#define alc_cap_sw_info snd_ctl_boolean_stereo_info
Takashi Iwai666a70d2012-12-17 20:29:29 +01001451#define alc_cap_sw_get snd_hda_mixer_amp_switch_get
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001452
1453static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1454 struct snd_ctl_elem_value *ucontrol)
1455{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001456 return alc_cap_put_caller(kcontrol, ucontrol,
1457 snd_hda_mixer_amp_switch_put,
1458 NID_PATH_MUTE_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001459}
1460
Takashi Iwai666a70d2012-12-17 20:29:29 +01001461static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1462{
1463 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01001464 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001465 struct nid_path *path;
1466 hda_nid_t nid;
1467 int i, dir, parm;
1468 unsigned int val;
1469
1470 for (i = 0; i < imux->num_items; i++) {
1471 if (spec->imux_pins[i] == spec->inv_dmic_pin)
1472 break;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001473 }
Takashi Iwai666a70d2012-12-17 20:29:29 +01001474 if (i >= imux->num_items)
1475 return;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001476
Takashi Iwai666a70d2012-12-17 20:29:29 +01001477 path = get_nid_path(codec, spec->inv_dmic_pin,
1478 get_adc_nid(codec, adc_idx, i));
1479 val = path->ctls[NID_PATH_MUTE_CTL];
1480 if (!val)
1481 return;
1482 nid = get_amp_nid_(val);
1483 dir = get_amp_direction_(val);
1484 parm = AC_AMP_SET_RIGHT |
1485 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001486
Takashi Iwai666a70d2012-12-17 20:29:29 +01001487 /* we care only right channel */
1488 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1489 if (val & 0x80) /* if already muted, we don't need to touch */
1490 return;
1491 val |= 0x80;
1492 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1493 parm | val);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001494}
1495
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001496/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001497 * Inverted digital-mic handling
1498 *
1499 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1500 * gives the additional mute only to the right channel of the digital mic
1501 * capture stream. This is a workaround for avoiding the almost silence
1502 * by summing the stereo stream from some (known to be ForteMedia)
1503 * digital mic unit.
1504 *
1505 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1506 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1507 * without caching so that the cache can still keep the original value.
1508 * The cached value is then restored when the flag is set off or any other
1509 * than d-mic is used as the current input source.
1510 */
1511static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1512{
1513 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001514 int src, nums;
Takashi Iwai125821a2012-06-22 14:30:29 +02001515
1516 if (!spec->inv_dmic_fixup)
1517 return;
1518 if (!spec->inv_dmic_muted && !force)
1519 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001520 nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids;
1521 for (src = 0; src < nums; src++) {
Takashi Iwai125821a2012-06-22 14:30:29 +02001522 bool dmic_fixup = false;
Takashi Iwai125821a2012-06-22 14:30:29 +02001523
1524 if (spec->inv_dmic_muted &&
1525 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1526 dmic_fixup = true;
1527 if (!dmic_fixup && !force)
1528 continue;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001529 alc_inv_dmic_sync_adc(codec, src);
Takashi Iwai125821a2012-06-22 14:30:29 +02001530 }
1531}
1532
1533static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1534 struct snd_ctl_elem_value *ucontrol)
1535{
1536 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1537 struct alc_spec *spec = codec->spec;
1538
1539 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1540 return 0;
1541}
1542
1543static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1544 struct snd_ctl_elem_value *ucontrol)
1545{
1546 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1547 struct alc_spec *spec = codec->spec;
1548 unsigned int val = !ucontrol->value.integer.value[0];
1549
1550 if (val == spec->inv_dmic_muted)
1551 return 0;
1552 spec->inv_dmic_muted = val;
1553 alc_inv_dmic_sync(codec, true);
1554 return 0;
1555}
1556
1557static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1558 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1559 .info = snd_ctl_boolean_mono_info,
1560 .get = alc_inv_dmic_sw_get,
1561 .put = alc_inv_dmic_sw_put,
1562};
1563
1564static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1565{
1566 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001567
1568 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1569 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001570 return -ENOMEM;
1571 spec->inv_dmic_fixup = 1;
1572 spec->inv_dmic_muted = 0;
1573 spec->inv_dmic_pin = nid;
1574 return 0;
1575}
1576
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001577/* typically the digital mic is put at node 0x12 */
1578static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1579 const struct alc_fixup *fix, int action)
1580{
1581 if (action == ALC_FIXUP_ACT_PROBE)
1582 alc_add_inv_dmic_mixer(codec, 0x12);
1583}
1584
Takashi Iwai125821a2012-06-22 14:30:29 +02001585/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001586 * virtual master controls
1587 */
1588
1589/*
1590 * slave controls for virtual master
1591 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001592static const char * const alc_slave_pfxs[] = {
1593 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001594 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001595 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001596 NULL,
1597};
1598
1599/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001600 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001602
1603static void alc_free_kctls(struct hda_codec *codec);
1604
Takashi Iwai67d634c2009-11-16 15:35:59 +01001605#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001606/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001607static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001608 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001609 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001610 { } /* end */
1611};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001612#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001613
Takashi Iwai2eab6942012-12-18 15:30:41 +01001614static int alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615{
1616 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001617 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
1619 for (i = 0; i < spec->num_mixers; i++) {
1620 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1621 if (err < 0)
1622 return err;
1623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001625 err = snd_hda_create_dig_out_ctls(codec,
1626 spec->multiout.dig_out_nid,
1627 spec->multiout.dig_out_nid,
1628 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 if (err < 0)
1630 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001631 if (!spec->no_analog) {
1632 err = snd_hda_create_spdif_share_sw(codec,
1633 &spec->multiout);
1634 if (err < 0)
1635 return err;
1636 spec->multiout.share_spdif = 1;
1637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 }
1639 if (spec->dig_in_nid) {
1640 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1641 if (err < 0)
1642 return err;
1643 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001644
Takashi Iwai67d634c2009-11-16 15:35:59 +01001645#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001646 /* create beep controls if needed */
1647 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001648 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001649 for (knew = alc_beep_mixer; knew->name; knew++) {
1650 struct snd_kcontrol *kctl;
1651 kctl = snd_ctl_new1(knew, codec);
1652 if (!kctl)
1653 return -ENOMEM;
1654 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001655 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001656 if (err < 0)
1657 return err;
1658 }
1659 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001660#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001661
Takashi Iwai2134ea42008-01-10 16:53:55 +01001662 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001663 if (!spec->no_analog &&
1664 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001665 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001666 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001667 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001668 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001669 vmaster_tlv, alc_slave_pfxs,
1670 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001671 if (err < 0)
1672 return err;
1673 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001674 if (!spec->no_analog &&
1675 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001676 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1677 NULL, alc_slave_pfxs,
1678 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001679 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001680 if (err < 0)
1681 return err;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001682 if (spec->vmaster_mute.hook)
1683 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001684 }
1685
Takashi Iwaibae84e72010-03-22 08:30:20 +01001686 alc_free_kctls(codec); /* no longer needed */
1687
David Henningsson5780b622012-06-27 18:45:45 +02001688 if (spec->shared_mic_hp) {
1689 int err;
1690 int nid = spec->autocfg.inputs[1].pin;
1691 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1692 if (err < 0)
1693 return err;
1694 err = snd_hda_jack_detect_enable(codec, nid, 0);
1695 if (err < 0)
1696 return err;
1697 }
1698
Takashi Iwai2eab6942012-12-18 15:30:41 +01001699 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001700 if (err < 0)
1701 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001702
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001703 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1704 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
1706
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001707
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001709 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001710 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001711
Takashi Iwai070cff42012-02-21 12:54:17 +01001712static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001713
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714static int alc_init(struct hda_codec *codec)
1715{
1716 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001717
Takashi Iwai546bb672012-03-07 08:37:19 +01001718 if (spec->init_hook)
1719 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001720
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001721 alc_fix_pll(codec);
Takashi Iwai4a79ba342009-04-22 16:31:35 +02001722 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001723
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02001724 snd_hda_gen_apply_verbs(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001725 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001726
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001727 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
1728 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
1729
Takashi Iwai58701122011-01-13 15:41:45 +01001730 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1731
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001732 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 return 0;
1734}
1735
Takashi Iwai83012a72012-08-24 18:38:08 +02001736#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001737static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1738{
1739 struct alc_spec *spec = codec->spec;
1740 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1741}
1742#endif
1743
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744/*
1745 * Analog playback callbacks
1746 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001747static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001749 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750{
1751 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001752 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1753 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754}
1755
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001756static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 struct hda_codec *codec,
1758 unsigned int stream_tag,
1759 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001760 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761{
1762 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001763 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1764 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765}
1766
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001767static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001769 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770{
1771 struct alc_spec *spec = codec->spec;
1772 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1773}
1774
1775/*
1776 * Digital out
1777 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001778static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001780 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
1782 struct alc_spec *spec = codec->spec;
1783 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1784}
1785
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001786static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001787 struct hda_codec *codec,
1788 unsigned int stream_tag,
1789 unsigned int format,
1790 struct snd_pcm_substream *substream)
1791{
1792 struct alc_spec *spec = codec->spec;
1793 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1794 stream_tag, format, substream);
1795}
1796
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001797static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001798 struct hda_codec *codec,
1799 struct snd_pcm_substream *substream)
1800{
1801 struct alc_spec *spec = codec->spec;
1802 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1803}
1804
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001805static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001807 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808{
1809 struct alc_spec *spec = codec->spec;
1810 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1811}
1812
1813/*
1814 * Analog capture
1815 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001816static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 struct hda_codec *codec,
1818 unsigned int stream_tag,
1819 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001820 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821{
1822 struct alc_spec *spec = codec->spec;
1823
Takashi Iwai63300792008-01-24 15:31:36 +01001824 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 stream_tag, 0, format);
1826 return 0;
1827}
1828
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001829static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001831 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832{
1833 struct alc_spec *spec = codec->spec;
1834
Takashi Iwai888afa12008-03-18 09:57:50 +01001835 snd_hda_codec_cleanup_stream(codec,
1836 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 return 0;
1838}
1839
Takashi Iwai840b64c2010-07-13 22:49:01 +02001840/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02001841static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001842 struct hda_codec *codec,
1843 unsigned int stream_tag,
1844 unsigned int format,
1845 struct snd_pcm_substream *substream)
1846{
1847 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001848 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02001849 spec->cur_adc_stream_tag = stream_tag;
1850 spec->cur_adc_format = format;
1851 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1852 return 0;
1853}
1854
Takashi Iwai21268962011-07-07 15:01:13 +02001855static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001856 struct hda_codec *codec,
1857 struct snd_pcm_substream *substream)
1858{
1859 struct alc_spec *spec = codec->spec;
1860 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1861 spec->cur_adc = 0;
1862 return 0;
1863}
1864
Takashi Iwai21268962011-07-07 15:01:13 +02001865static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02001866 .substreams = 1,
1867 .channels_min = 2,
1868 .channels_max = 2,
1869 .nid = 0, /* fill later */
1870 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02001871 .prepare = dyn_adc_capture_pcm_prepare,
1872 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02001873 },
1874};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
1876/*
1877 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001878static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 .substreams = 1,
1880 .channels_min = 2,
1881 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001882 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001884 .open = alc_playback_pcm_open,
1885 .prepare = alc_playback_pcm_prepare,
1886 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 },
1888};
1889
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001890static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001891 .substreams = 1,
1892 .channels_min = 2,
1893 .channels_max = 2,
1894 /* NID is set in alc_build_pcms */
1895};
1896
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001897static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01001898 .substreams = 1,
1899 .channels_min = 2,
1900 .channels_max = 2,
1901 /* NID is set in alc_build_pcms */
1902};
1903
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001904static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001905 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 .channels_min = 2,
1907 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001908 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001910 .prepare = alc_alt_capture_pcm_prepare,
1911 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 },
1913};
1914
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001915static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 .substreams = 1,
1917 .channels_min = 2,
1918 .channels_max = 2,
1919 /* NID is set in alc_build_pcms */
1920 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001921 .open = alc_dig_playback_pcm_open,
1922 .close = alc_dig_playback_pcm_close,
1923 .prepare = alc_dig_playback_pcm_prepare,
1924 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 },
1926};
1927
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001928static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 .substreams = 1,
1930 .channels_min = 2,
1931 .channels_max = 2,
1932 /* NID is set in alc_build_pcms */
1933};
1934
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001935/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02001936static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001937 .substreams = 0,
1938 .channels_min = 0,
1939 .channels_max = 0,
1940};
1941
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942static int alc_build_pcms(struct hda_codec *codec)
1943{
1944 struct alc_spec *spec = codec->spec;
1945 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001946 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01001947 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 int i;
1949
1950 codec->num_pcms = 1;
1951 codec->pcm_info = info;
1952
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001953 if (spec->no_analog)
1954 goto skip_analog;
1955
Takashi Iwai812a2cc2009-05-16 10:00:49 +02001956 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1957 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01001959
Takashi Iwaieedec3d2012-02-06 10:24:04 +01001960 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001961 p = spec->stream_analog_playback;
1962 if (!p)
1963 p = &alc_pcm_analog_playback;
1964 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001965 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02001966 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1967 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01001968 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
1969 spec->autocfg.line_outs == 2)
1970 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1971 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001972 }
Takashi Iwai27d31532012-12-18 08:57:05 +01001973 if (spec->num_adc_nids) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001974 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02001975 if (!p) {
1976 if (spec->dyn_adc_switch)
1977 p = &dyn_adc_pcm_analog_capture;
1978 else
1979 p = &alc_pcm_analog_capture;
1980 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001981 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001982 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1983 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
Takashi Iwai4a471b72005-12-07 13:56:29 +01001985 if (spec->channel_mode) {
1986 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
1987 for (i = 0; i < spec->num_channel_mode; i++) {
1988 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
1989 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
1990 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 }
1992 }
1993
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001994 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02001995 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02001997 snprintf(spec->stream_name_digital,
1998 sizeof(spec->stream_name_digital),
1999 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002000 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002001 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002002 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002004 if (spec->dig_out_type)
2005 info->pcm_type = spec->dig_out_type;
2006 else
2007 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002008 if (spec->multiout.dig_out_nid) {
2009 p = spec->stream_digital_playback;
2010 if (!p)
2011 p = &alc_pcm_digital_playback;
2012 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2014 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002015 if (spec->dig_in_nid) {
2016 p = spec->stream_digital_capture;
2017 if (!p)
2018 p = &alc_pcm_digital_capture;
2019 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2021 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002022 /* FIXME: do we need this for all Realtek codec models? */
2023 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 }
2025
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002026 if (spec->no_analog)
2027 return 0;
2028
Takashi Iwaie08a0072006-09-07 17:52:14 +02002029 /* If the use of more than one ADC is requested for the current
2030 * model, configure a second analog capture-only PCM.
2031 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002032 have_multi_adcs = (spec->num_adc_nids > 1) &&
Takashi Iwai27d31532012-12-18 08:57:05 +01002033 !spec->dyn_adc_switch && !spec->auto_mic;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002034 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002035 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002036 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002037 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002038 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002039 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002040 p = spec->stream_analog_alt_playback;
2041 if (!p)
2042 p = &alc_pcm_analog_alt_playback;
2043 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002044 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2045 spec->alt_dac_nid;
2046 } else {
2047 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2048 alc_pcm_null_stream;
2049 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2050 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002051 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002052 p = spec->stream_analog_alt_capture;
2053 if (!p)
2054 p = &alc_pcm_analog_alt_capture;
2055 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002056 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2057 spec->adc_nids[1];
2058 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2059 spec->num_adc_nids - 1;
2060 } else {
2061 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2062 alc_pcm_null_stream;
2063 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002064 }
2065 }
2066
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 return 0;
2068}
2069
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002070static inline void alc_shutup(struct hda_codec *codec)
2071{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002072 struct alc_spec *spec = codec->spec;
2073
2074 if (spec && spec->shutup)
2075 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002076 snd_hda_shutup_pins(codec);
2077}
2078
Takashi Iwai603c4012008-07-30 15:01:44 +02002079static void alc_free_kctls(struct hda_codec *codec)
2080{
2081 struct alc_spec *spec = codec->spec;
2082
2083 if (spec->kctls.list) {
2084 struct snd_kcontrol_new *kctl = spec->kctls.list;
2085 int i;
2086 for (i = 0; i < spec->kctls.used; i++)
2087 kfree(kctl[i].name);
2088 }
2089 snd_array_free(&spec->kctls);
2090}
2091
Takashi Iwai23c09b02011-08-19 09:05:35 +02002092static void alc_free_bind_ctls(struct hda_codec *codec)
2093{
2094 struct alc_spec *spec = codec->spec;
2095 if (spec->bind_ctls.list) {
2096 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2097 int i;
2098 for (i = 0; i < spec->bind_ctls.used; i++)
2099 kfree(ctl[i]);
2100 }
2101 snd_array_free(&spec->bind_ctls);
2102}
2103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104static void alc_free(struct hda_codec *codec)
2105{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002106 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002107
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002108 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002109 return;
2110
Takashi Iwai603c4012008-07-30 15:01:44 +02002111 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002112 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002113 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002114 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002115 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002116 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117}
2118
Takashi Iwai83012a72012-08-24 18:38:08 +02002119#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002120static void alc_power_eapd(struct hda_codec *codec)
2121{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002122 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002123}
2124
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002125static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002126{
2127 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002128 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002129 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002130 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002131 return 0;
2132}
2133#endif
2134
Takashi Iwai2a439522011-07-26 09:52:50 +02002135#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002136static int alc_resume(struct hda_codec *codec)
2137{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002138 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002139 codec->patch_ops.init(codec);
2140 snd_hda_codec_resume_amp(codec);
2141 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002142 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002143 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002144 return 0;
2145}
Takashi Iwaie044c392008-10-27 16:56:24 +01002146#endif
2147
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148/*
2149 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002150static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 .build_controls = alc_build_controls,
2152 .build_pcms = alc_build_pcms,
2153 .init = alc_init,
2154 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002155 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002156#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002157 .resume = alc_resume,
2158#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002159#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002160 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002161 .check_power_status = alc_check_power_status,
2162#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002163 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164};
2165
David Henningsson29adc4b2012-09-25 11:31:00 +02002166
Kailang Yangc027ddc2010-03-19 11:33:06 +01002167/* replace the codec chip_name with the given string */
2168static int alc_codec_rename(struct hda_codec *codec, const char *name)
2169{
2170 kfree(codec->chip_name);
2171 codec->chip_name = kstrdup(name, GFP_KERNEL);
2172 if (!codec->chip_name) {
2173 alc_free(codec);
2174 return -ENOMEM;
2175 }
2176 return 0;
2177}
2178
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002179/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002180 * Rename codecs appropriately from COEF value
2181 */
2182struct alc_codec_rename_table {
2183 unsigned int vendor_id;
2184 unsigned short coef_mask;
2185 unsigned short coef_bits;
2186 const char *name;
2187};
2188
2189static struct alc_codec_rename_table rename_tbl[] = {
2190 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2191 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2192 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2193 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2194 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2195 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2196 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002197 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002198 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2199 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2200 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2201 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2202 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2203 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2204 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2205 { } /* terminator */
2206};
2207
2208static int alc_codec_rename_from_preset(struct hda_codec *codec)
2209{
2210 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002211
2212 for (p = rename_tbl; p->vendor_id; p++) {
2213 if (p->vendor_id != codec->vendor_id)
2214 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002215 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002216 return alc_codec_rename(codec, p->name);
2217 }
2218 return 0;
2219}
2220
2221/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002222 * Automatic parse of I/O pins from the BIOS configuration
2223 */
2224
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002225enum {
2226 ALC_CTL_WIDGET_VOL,
2227 ALC_CTL_WIDGET_MUTE,
2228 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002229 ALC_CTL_BIND_VOL,
2230 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002231};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002232static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002233 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2234 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002235 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002236 HDA_BIND_VOL(NULL, 0),
2237 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002238};
2239
2240/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002241static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002242 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002243{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002244 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002245
Takashi Iwai668d1e92012-11-29 14:10:17 +01002246 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002247 if (!knew)
2248 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002249 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002250 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002251 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002252 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002253 return 0;
2254}
2255
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002256static int add_control_with_pfx(struct alc_spec *spec, int type,
2257 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002258 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002259{
2260 char name[32];
2261 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002262 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002263}
2264
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002265#define add_pb_vol_ctrl(spec, type, pfx, val) \
2266 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2267#define add_pb_sw_ctrl(spec, type, pfx, val) \
2268 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2269#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2270 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2271#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2272 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002273
Takashi Iwai23c09b02011-08-19 09:05:35 +02002274static const char * const channel_name[4] = {
2275 "Front", "Surround", "CLFE", "Side"
2276};
2277
Takashi Iwai6843ca12011-06-24 11:03:58 +02002278static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2279 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002280{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002281 struct auto_pin_cfg *cfg = &spec->autocfg;
2282
Takashi Iwai6843ca12011-06-24 11:03:58 +02002283 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002284 if (cfg->line_outs == 1 && !spec->multi_ios &&
2285 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwai52a8efa2012-12-18 17:33:04 +01002286 return spec->vmaster_mute.hook ? "PCM" : "Master";
2287
2288 /* if there is really a single DAC used in the whole output paths,
2289 * use it master (or "PCM" if a vmaster hook is present)
2290 */
2291 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
2292 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
2293 return spec->vmaster_mute.hook ? "PCM" : "Master";
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002294
2295 switch (cfg->line_out_type) {
2296 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002297 if (cfg->line_outs == 1)
2298 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002299 if (cfg->line_outs == 2)
2300 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002301 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002302 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002303 /* for multi-io case, only the primary out */
2304 if (ch && spec->multi_ios)
2305 break;
2306 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002307 return "Headphone";
2308 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002309 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002310 return "PCM";
2311 break;
2312 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002313 if (ch >= ARRAY_SIZE(channel_name)) {
2314 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002315 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002316 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002317
2318 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002319}
2320
Takashi Iwai83012a72012-08-24 18:38:08 +02002321#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002322/* add the powersave loopback-list entry */
2323static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2324{
2325 struct hda_amp_list *list;
2326
2327 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2328 return;
2329 list = spec->loopback_list + spec->num_loopbacks;
2330 list->nid = mix;
2331 list->dir = HDA_INPUT;
2332 list->idx = idx;
2333 spec->num_loopbacks++;
2334 spec->loopback.amplist = spec->loopback_list;
2335}
2336#else
2337#define add_loopback_list(spec, mix, idx) /* NOP */
2338#endif
2339
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002340/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002341static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002342 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002343 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002344{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002345 struct alc_spec *spec = codec->spec;
2346 struct nid_path *path;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002347 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002348 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002349
Takashi Iwaibd32f782012-12-12 18:08:52 +01002350 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2351 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2352 return 0; /* no need for analog loopback */
2353
Takashi Iwai965cceb2012-12-18 11:46:37 +01002354 path = add_new_nid_path(codec, pin, mix_nid, 2);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002355 if (!path)
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002356 return -EINVAL;
2357
2358 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002359 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002360 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2361 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002362 if (err < 0)
2363 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002364 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002365 }
2366
2367 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002368 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2369 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002370 if (err < 0)
2371 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002372 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002373 }
2374
Takashi Iwai829f69e2012-12-14 18:26:02 +01002375 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002376 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002377 return 0;
2378}
2379
Takashi Iwai05f5f472009-08-25 13:10:18 +02002380static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002381{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002382 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2383 return (pincap & AC_PINCAP_IN) != 0;
2384}
2385
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002386/* check whether the given two widgets can be connected */
2387static bool is_reachable_path(struct hda_codec *codec,
2388 hda_nid_t from_nid, hda_nid_t to_nid)
2389{
2390 if (!from_nid || !to_nid)
2391 return false;
2392 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2393}
2394
Takashi Iwai666a70d2012-12-17 20:29:29 +01002395/* Parse the codec tree and retrieve ADCs */
2396static int alc_auto_fill_adc_nids(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002397{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002398 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002399 hda_nid_t nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002400 hda_nid_t *adc_nids = spec->adc_nids;
2401 int max_nums = ARRAY_SIZE(spec->adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002402 int i, nums = 0;
2403
2404 nid = codec->start_nid;
2405 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwaib7821702011-07-06 15:12:46 +02002406 unsigned int caps = get_wcaps(codec, nid);
2407 int type = get_wcaps_type(caps);
2408
2409 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2410 continue;
2411 adc_nids[nums] = nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002412 if (++nums >= max_nums)
2413 break;
2414 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002415 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002416 return nums;
2417}
2418
Takashi Iwai666a70d2012-12-17 20:29:29 +01002419/* filter out invalid adc_nids that don't give all active input pins;
2420 * if needed, check whether dynamic ADC-switching is available
2421 */
2422static int check_dyn_adc_switch(struct hda_codec *codec)
2423{
2424 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002425 struct hda_input_mux *imux = &spec->input_mux;
2426 hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)];
Takashi Iwai666a70d2012-12-17 20:29:29 +01002427 int i, n, nums;
2428 hda_nid_t pin, adc;
2429
2430 again:
2431 nums = 0;
2432 for (n = 0; n < spec->num_adc_nids; n++) {
2433 adc = spec->adc_nids[n];
2434 for (i = 0; i < imux->num_items; i++) {
2435 pin = spec->imux_pins[i];
2436 if (!is_reachable_path(codec, pin, adc))
2437 break;
2438 }
2439 if (i >= imux->num_items)
2440 adc_nids[nums++] = adc;
2441 }
2442
2443 if (!nums) {
2444 if (spec->shared_mic_hp) {
2445 spec->shared_mic_hp = 0;
Takashi Iwai27d31532012-12-18 08:57:05 +01002446 imux->num_items = 1;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002447 goto again;
2448 }
2449
2450 /* check whether ADC-switch is possible */
2451 for (i = 0; i < imux->num_items; i++) {
2452 pin = spec->imux_pins[i];
2453 for (n = 0; n < spec->num_adc_nids; n++) {
2454 adc = spec->adc_nids[n];
2455 if (is_reachable_path(codec, pin, adc)) {
2456 spec->dyn_adc_idx[i] = n;
2457 break;
2458 }
2459 }
2460 }
2461
2462 snd_printdd("realtek: enabling ADC switching\n");
2463 spec->dyn_adc_switch = 1;
2464 } else if (nums != spec->num_adc_nids) {
Takashi Iwai27d31532012-12-18 08:57:05 +01002465 memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t));
Takashi Iwai666a70d2012-12-17 20:29:29 +01002466 spec->num_adc_nids = nums;
2467 }
2468
Takashi Iwai27d31532012-12-18 08:57:05 +01002469 if (imux->num_items == 1 || spec->shared_mic_hp) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002470 snd_printdd("realtek: reducing to a single ADC\n");
2471 spec->num_adc_nids = 1; /* reduce to a single ADC */
2472 }
2473
2474 return 0;
2475}
2476
2477/* templates for capture controls */
2478static const struct snd_kcontrol_new cap_src_temp = {
2479 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2480 .name = "Input Source",
2481 .info = alc_mux_enum_info,
2482 .get = alc_mux_enum_get,
2483 .put = alc_mux_enum_put,
2484};
2485
2486static const struct snd_kcontrol_new cap_vol_temp = {
2487 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2488 .name = "Capture Volume",
2489 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2490 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2491 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2492 .info = alc_cap_vol_info,
2493 .get = alc_cap_vol_get,
2494 .put = alc_cap_vol_put,
2495 .tlv = { .c = alc_cap_vol_tlv },
2496};
2497
2498static const struct snd_kcontrol_new cap_sw_temp = {
2499 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2500 .name = "Capture Switch",
2501 .info = alc_cap_sw_info,
2502 .get = alc_cap_sw_get,
2503 .put = alc_cap_sw_put,
2504};
2505
2506static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2507{
2508 hda_nid_t nid;
2509 int i, depth;
2510
2511 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2512 for (depth = 0; depth < 3; depth++) {
2513 if (depth >= path->depth)
2514 return -EINVAL;
2515 i = path->depth - depth - 1;
2516 nid = path->path[i];
2517 if (!path->ctls[NID_PATH_VOL_CTL]) {
2518 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2519 path->ctls[NID_PATH_VOL_CTL] =
2520 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2521 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2522 int idx = path->idx[i];
2523 if (!depth && codec->single_adc_amp)
2524 idx = 0;
2525 path->ctls[NID_PATH_VOL_CTL] =
2526 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2527 }
2528 }
2529 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2530 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2531 path->ctls[NID_PATH_MUTE_CTL] =
2532 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2533 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2534 int idx = path->idx[i];
2535 if (!depth && codec->single_adc_amp)
2536 idx = 0;
2537 path->ctls[NID_PATH_MUTE_CTL] =
2538 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2539 }
2540 }
2541 }
2542 return 0;
2543}
2544
2545static int create_capture_mixers(struct hda_codec *codec)
2546{
2547 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002548 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002549 struct snd_kcontrol_new *knew;
2550 int i, n, nums;
2551
2552 if (spec->dyn_adc_switch)
2553 nums = 1;
2554 else
2555 nums = spec->num_adc_nids;
2556
2557 if (!spec->auto_mic && imux->num_items > 1) {
2558 knew = alc_kcontrol_new(spec, "Input Source", &cap_src_temp);
2559 if (!knew)
2560 return -ENOMEM;
2561 knew->count = nums;
2562 }
2563
2564 for (n = 0; n < nums; n++) {
2565 int vol, sw;
2566
2567 vol = sw = 0;
2568 for (i = 0; i < imux->num_items; i++) {
2569 struct nid_path *path;
2570 path = get_nid_path(codec, spec->imux_pins[i],
2571 get_adc_nid(codec, n, i));
2572 if (!path)
2573 continue;
2574 parse_capvol_in_path(codec, path);
2575 if (!vol)
2576 vol = path->ctls[NID_PATH_VOL_CTL];
2577 if (!sw)
2578 sw = path->ctls[NID_PATH_MUTE_CTL];
2579 }
2580
2581 if (vol) {
2582 knew = alc_kcontrol_new(spec, "Capture Volume",
2583 &cap_vol_temp);
2584 if (!knew)
2585 return -ENOMEM;
2586 knew->index = n;
2587 knew->private_value = vol;
2588 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2589 }
2590 if (sw) {
2591 knew = alc_kcontrol_new(spec, "Capture Switch",
2592 &cap_sw_temp);
2593 if (!knew)
2594 return -ENOMEM;
2595 knew->index = n;
2596 knew->private_value = sw;
2597 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2598 }
2599 }
2600
2601 return 0;
2602}
2603
Takashi Iwai05f5f472009-08-25 13:10:18 +02002604/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002605static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002606{
2607 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002608 const struct auto_pin_cfg *cfg = &spec->autocfg;
2609 hda_nid_t mixer = spec->mixer_nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002610 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwaib7821702011-07-06 15:12:46 +02002611 int num_adcs;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002612 int i, c, err, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002613 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002614
Takashi Iwai666a70d2012-12-17 20:29:29 +01002615 num_adcs = alc_auto_fill_adc_nids(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002616 if (num_adcs < 0)
2617 return 0;
2618
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002619 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002620 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002621 const char *label;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002622 bool imux_added;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002623
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002624 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002625 if (!alc_is_input_pin(codec, pin))
2626 continue;
2627
David Henningsson5322bf22011-01-05 11:03:56 +01002628 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002629 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2630 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002631 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002632 type_idx++;
2633 else
2634 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002635 prev_label = label;
2636
Takashi Iwai05f5f472009-08-25 13:10:18 +02002637 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002638 if (is_reachable_path(codec, pin, mixer)) {
2639 err = new_analog_input(codec, pin,
2640 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002641 if (err < 0)
2642 return err;
2643 }
2644 }
2645
Takashi Iwai666a70d2012-12-17 20:29:29 +01002646 imux_added = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002647 for (c = 0; c < num_adcs; c++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002648 struct nid_path *path;
2649 hda_nid_t adc = spec->adc_nids[c];
2650
2651 if (!is_reachable_path(codec, pin, adc))
2652 continue;
2653 path = snd_array_new(&spec->paths);
2654 if (!path)
2655 return -ENOMEM;
2656 memset(path, 0, sizeof(*path));
2657 if (!parse_nid_path(codec, pin, adc, 2, path)) {
2658 snd_printd(KERN_ERR
2659 "invalid input path 0x%x -> 0x%x\n",
2660 pin, adc);
2661 spec->paths.used--;
2662 continue;
2663 }
2664
2665 if (!imux_added) {
2666 spec->imux_pins[imux->num_items] = pin;
2667 snd_hda_add_imux_item(imux, label,
2668 imux->num_items, NULL);
2669 imux_added = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002670 }
2671 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002672 }
Takashi Iwai21268962011-07-07 15:01:13 +02002673
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002674 return 0;
2675}
2676
Takashi Iwai24de1832011-11-07 17:13:39 +01002677/* create a shared input with the headphone out */
2678static int alc_auto_create_shared_input(struct hda_codec *codec)
2679{
2680 struct alc_spec *spec = codec->spec;
2681 struct auto_pin_cfg *cfg = &spec->autocfg;
2682 unsigned int defcfg;
2683 hda_nid_t nid;
2684
2685 /* only one internal input pin? */
2686 if (cfg->num_inputs != 1)
2687 return 0;
2688 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2689 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2690 return 0;
2691
2692 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2693 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2694 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2695 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2696 else
2697 return 0; /* both not available */
2698
2699 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2700 return 0; /* no input */
2701
2702 cfg->inputs[1].pin = nid;
2703 cfg->inputs[1].type = AUTO_PIN_MIC;
2704 cfg->num_inputs = 2;
2705 spec->shared_mic_hp = 1;
2706 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2707 return 0;
2708}
2709
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002710static int get_pin_type(int line_out_type)
2711{
2712 if (line_out_type == AUTO_PIN_HP_OUT)
2713 return PIN_HP;
2714 else
2715 return PIN_OUT;
2716}
2717
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002718static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002719{
2720 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002721 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002722 int i;
2723
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002724 for (i = 0; i < cfg->num_inputs; i++) {
2725 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai62343992012-12-18 09:06:01 +01002726 if (alc_is_input_pin(codec, nid))
Takashi Iwai30ea0982010-09-16 18:47:56 +02002727 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002728
Takashi Iwai829f69e2012-12-14 18:26:02 +01002729 /* mute loopback inputs */
2730 if (spec->mixer_nid) {
2731 struct nid_path *path;
2732 path = get_nid_path(codec, nid, spec->mixer_nid);
2733 if (path)
Takashi Iwai666a70d2012-12-17 20:29:29 +01002734 activate_path(codec, path, path->active, false);
Takashi Iwai829f69e2012-12-14 18:26:02 +01002735 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002736 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002737}
2738
Takashi Iwai185d99f2012-02-16 18:39:45 +01002739static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2740{
2741 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002742 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002743
Takashi Iwaic9967f12012-12-14 16:39:22 +01002744 for (i = 0; i < spec->paths.used; i++) {
2745 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002746 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002747 return true;
2748 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002749 return false;
2750}
2751
Takashi Iwai463419d2012-12-05 14:17:37 +01002752/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002753static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2754 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002755{
2756 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002757 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002758 int i;
2759
2760 for (i = 0; i < spec->num_all_dacs; i++) {
2761 hda_nid_t nid = spec->all_dacs[i];
2762 if (!nid || alc_is_dac_already_used(codec, nid))
2763 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002764 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2765 if (is_digital != cap_digital)
2766 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002767 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002768 return nid;
2769 }
2770 return 0;
2771}
2772
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002773/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002774static bool __parse_nid_path(struct hda_codec *codec,
2775 hda_nid_t from_nid, hda_nid_t to_nid,
2776 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002777{
2778 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002779 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002780 int i, nums;
2781
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002782 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002783 if (!with_aa_mix)
2784 return false;
2785 with_aa_mix = 2; /* mark aa-mix is included */
2786 }
2787
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002788 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002789 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002790 if (conn[i] != from_nid) {
2791 /* special case: when from_nid is 0,
2792 * try to find an empty DAC
2793 */
2794 if (from_nid ||
2795 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2796 alc_is_dac_already_used(codec, conn[i]))
2797 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002798 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002799 /* aa-mix is requested but not included? */
2800 if (!(spec->mixer_nid && with_aa_mix == 1))
2801 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002802 }
2803 if (depth >= MAX_NID_PATH_DEPTH)
2804 return false;
2805 for (i = 0; i < nums; i++) {
2806 unsigned int type;
2807 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002808 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2809 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002810 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002811 if (__parse_nid_path(codec, from_nid, conn[i],
2812 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002813 goto found;
2814 }
2815 return false;
2816
2817 found:
2818 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002819 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002820 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002821 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002822 path->depth++;
2823 return true;
2824}
2825
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002826/* parse the widget path from the given nid to the target nid;
2827 * when @from_nid is 0, try to find an empty DAC;
2828 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2829 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2830 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002831 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002832static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2833 hda_nid_t to_nid, int with_aa_mix,
2834 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002835{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002836 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2837 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002838 path->depth++;
2839#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002840 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002841 path->depth, path->path[0], path->path[1],
2842 path->path[2], path->path[3], path->path[4]);
2843#endif
2844 return true;
2845 }
2846 return false;
2847}
2848
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002849static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2850{
Takashi Iwai140547e2012-02-16 17:23:46 +01002851 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002852 int i;
2853 hda_nid_t nid_found = 0;
2854
2855 for (i = 0; i < spec->num_all_dacs; i++) {
2856 hda_nid_t nid = spec->all_dacs[i];
2857 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002858 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002859 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01002860 if (nid_found)
2861 return 0;
2862 nid_found = nid;
2863 }
2864 }
2865 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002866}
2867
Takashi Iwaiba8111272012-12-06 18:06:23 +01002868static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002869{
Takashi Iwaiba8111272012-12-06 18:06:23 +01002870 struct alc_spec *spec = codec->spec;
2871 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002872
Takashi Iwaic9967f12012-12-14 16:39:22 +01002873 for (i = 0; i < spec->paths.used; i++) {
2874 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002875 if (path->ctls[type] == val)
2876 return true;
2877 }
2878 return false;
2879}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002880
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002881/* badness definition */
2882enum {
2883 /* No primary DAC is found for the main output */
2884 BAD_NO_PRIMARY_DAC = 0x10000,
2885 /* No DAC is found for the extra output */
2886 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01002887 /* No possible multi-ios */
2888 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002889 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01002890 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002891 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01002892 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002893 /* Primary DAC shared with main surrounds */
2894 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002895 /* Primary DAC shared with main CLFE */
2896 BAD_SHARED_CLFE = 0x10,
2897 /* Primary DAC shared with extra surrounds */
2898 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01002899 /* Volume widget is shared */
2900 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002901};
2902
2903static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002904 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002905static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01002906 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002907
Takashi Iwai965cceb2012-12-18 11:46:37 +01002908static struct nid_path *add_new_nid_path(struct hda_codec *codec,
2909 hda_nid_t from_nid, hda_nid_t to_nid,
2910 int with_aa_mix)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002911{
2912 struct alc_spec *spec = codec->spec;
2913 struct nid_path *path;
2914
Takashi Iwai965cceb2012-12-18 11:46:37 +01002915 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
2916 return NULL;
2917
Takashi Iwaic9967f12012-12-14 16:39:22 +01002918 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002919 if (!path)
Takashi Iwai965cceb2012-12-18 11:46:37 +01002920 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002921 memset(path, 0, sizeof(*path));
Takashi Iwai965cceb2012-12-18 11:46:37 +01002922 if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path))
2923 return path;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002924 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01002925 spec->paths.used--;
Takashi Iwai965cceb2012-12-18 11:46:37 +01002926 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002927}
2928
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002929/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01002930 * passing 0 to either @pin or @dac behaves as a wildcard
2931 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002932static struct nid_path *
2933get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01002934{
2935 struct alc_spec *spec = codec->spec;
2936 int i;
2937
Takashi Iwaic9967f12012-12-14 16:39:22 +01002938 for (i = 0; i < spec->paths.used; i++) {
2939 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002940 if (path->depth <= 0)
2941 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002942 if ((!from_nid || path->path[0] == from_nid) &&
2943 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01002944 return path;
2945 }
2946 return NULL;
2947}
2948
Takashi Iwai792cf2f2012-12-10 16:04:30 +01002949/* look for widgets in the path between the given NIDs appropriate for
2950 * volume and mute controls, and assign the values to ctls[].
2951 *
2952 * When no appropriate widget is found in the path, the badness value
2953 * is incremented depending on the situation. The function returns the
2954 * total badness for both volume and mute controls.
2955 */
2956static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
2957 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002958{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01002959 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002960 hda_nid_t nid;
2961 unsigned int val;
2962 int badness = 0;
2963
Takashi Iwaiba8111272012-12-06 18:06:23 +01002964 if (!path)
2965 return BAD_SHARED_VOL * 2;
2966 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002967 if (nid) {
2968 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002969 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002970 badness += BAD_SHARED_VOL;
2971 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01002972 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002973 } else
2974 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01002975 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002976 if (nid) {
2977 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01002978 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
2979 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002980 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2981 else
2982 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002983 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002984 badness += BAD_SHARED_VOL;
2985 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01002986 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002987 } else
2988 badness += BAD_SHARED_VOL;
2989 return badness;
2990}
2991
Takashi Iwaidc31b582012-02-17 17:27:53 +01002992struct badness_table {
2993 int no_primary_dac; /* no primary DAC */
2994 int no_dac; /* no secondary DACs */
2995 int shared_primary; /* primary DAC is shared with main output */
2996 int shared_surr; /* secondary DAC shared with main or primary */
2997 int shared_clfe; /* third DAC shared with main or primary */
2998 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
2999};
3000
3001static struct badness_table main_out_badness = {
3002 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3003 .no_dac = BAD_NO_DAC,
3004 .shared_primary = BAD_NO_PRIMARY_DAC,
3005 .shared_surr = BAD_SHARED_SURROUND,
3006 .shared_clfe = BAD_SHARED_CLFE,
3007 .shared_surr_main = BAD_SHARED_SURROUND,
3008};
3009
3010static struct badness_table extra_out_badness = {
3011 .no_primary_dac = BAD_NO_DAC,
3012 .no_dac = BAD_NO_DAC,
3013 .shared_primary = BAD_NO_EXTRA_DAC,
3014 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3015 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3016 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3017};
3018
3019/* try to assign DACs to pins and return the resultant badness */
3020static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3021 const hda_nid_t *pins, hda_nid_t *dacs,
3022 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003023{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003024 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003025 struct auto_pin_cfg *cfg = &spec->autocfg;
3026 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003027 int badness = 0;
3028 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003029
Takashi Iwai185d99f2012-02-16 18:39:45 +01003030 if (!num_outs)
3031 return 0;
3032
Takashi Iwaidc31b582012-02-17 17:27:53 +01003033 for (i = 0; i < num_outs; i++) {
3034 hda_nid_t pin = pins[i];
3035 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003036 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003037 if (!dacs[i] && !i) {
3038 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003039 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003040 dacs[0] = dacs[j];
3041 dacs[j] = 0;
3042 break;
3043 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003044 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003045 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003046 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003047 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003048 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003049 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003050 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003051 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003052 dac = spec->private_dac_nids[i];
3053 if (dac) {
3054 if (!i)
3055 badness += bad->shared_primary;
3056 else if (i == 1)
3057 badness += bad->shared_surr;
3058 else
3059 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003060 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003061 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003062 badness += bad->shared_surr_main;
3063 } else if (!i)
3064 badness += bad->no_primary_dac;
3065 else
3066 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003067 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003068 if (!add_new_nid_path(codec, dac, pin, 0))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003069 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003070 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003071 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003072 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003073
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003074 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003075}
3076
3077static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003078 hda_nid_t reference_pin,
3079 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003080
Takashi Iwai185d99f2012-02-16 18:39:45 +01003081static bool alc_map_singles(struct hda_codec *codec, int outs,
3082 const hda_nid_t *pins, hda_nid_t *dacs)
3083{
3084 int i;
3085 bool found = false;
3086 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003087 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003088 if (dacs[i])
3089 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003090 dac = get_dac_if_single(codec, pins[i]);
3091 if (!dac)
3092 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003093 if (add_new_nid_path(codec, dac, pins[i], 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003094 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003095 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003096 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003097 }
3098 return found;
3099}
3100
Takashi Iwai7085ec12009-10-02 09:03:58 +02003101/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003102static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003103 bool fill_hardwired,
3104 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003105{
3106 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003107 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003108 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003109
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003110 /* set num_dacs once to full for alc_auto_look_for_dac() */
3111 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003112 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003113 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3114 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3115 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003116 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003117 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003118 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003119
3120 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003121 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003122 bool mapped;
3123 do {
3124 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003125 cfg->line_out_pins,
3126 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003127 mapped |= alc_map_singles(codec, cfg->hp_outs,
3128 cfg->hp_pins,
3129 spec->multiout.hp_out_nid);
3130 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3131 cfg->speaker_pins,
3132 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003133 if (fill_mio_first && cfg->line_outs == 1 &&
3134 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3135 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3136 if (!err)
3137 mapped = true;
3138 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003139 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003140 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003141
Takashi Iwaidc31b582012-02-17 17:27:53 +01003142 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3143 spec->private_dac_nids,
3144 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003145
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003146 /* re-count num_dacs and squash invalid entries */
3147 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003148 for (i = 0; i < cfg->line_outs; i++) {
3149 if (spec->private_dac_nids[i])
3150 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003151 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003152 memmove(spec->private_dac_nids + i,
3153 spec->private_dac_nids + i + 1,
3154 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003155 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3156 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003157 }
3158
Takashi Iwai276dd702012-02-17 16:17:03 +01003159 if (fill_mio_first &&
3160 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003161 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003162 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003163 if (err < 0)
3164 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003165 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003166 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003167
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003168 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003169 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3170 spec->multiout.hp_out_nid,
3171 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003172 if (err < 0)
3173 return err;
3174 badness += err;
3175 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003176 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003177 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3178 cfg->speaker_pins,
3179 spec->multiout.extra_out_nid,
3180 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003181 if (err < 0)
3182 return err;
3183 badness += err;
3184 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003185 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3186 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003187 if (err < 0)
3188 return err;
3189 badness += err;
3190 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003191 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3192 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003193 int offset = 0;
3194 if (cfg->line_outs >= 3)
3195 offset = 1;
3196 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3197 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003198 if (err < 0)
3199 return err;
3200 badness += err;
3201 }
3202
3203 if (spec->multi_ios == 2) {
3204 for (i = 0; i < 2; i++)
3205 spec->private_dac_nids[spec->multiout.num_dacs++] =
3206 spec->multi_io[i].dac;
3207 spec->ext_channel_count = 2;
3208 } else if (spec->multi_ios) {
3209 spec->multi_ios = 0;
3210 badness += BAD_MULTI_IO;
3211 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003212
3213 return badness;
3214}
3215
3216#define DEBUG_BADNESS
3217
3218#ifdef DEBUG_BADNESS
3219#define debug_badness snd_printdd
3220#else
3221#define debug_badness(...)
3222#endif
3223
3224static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3225{
3226 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3227 cfg->line_out_pins[0], cfg->line_out_pins[1],
3228 cfg->line_out_pins[2], cfg->line_out_pins[2],
3229 spec->multiout.dac_nids[0],
3230 spec->multiout.dac_nids[1],
3231 spec->multiout.dac_nids[2],
3232 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003233 if (spec->multi_ios > 0)
3234 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3235 spec->multi_ios,
3236 spec->multi_io[0].pin, spec->multi_io[1].pin,
3237 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003238 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3239 cfg->hp_pins[0], cfg->hp_pins[1],
3240 cfg->hp_pins[2], cfg->hp_pins[2],
3241 spec->multiout.hp_out_nid[0],
3242 spec->multiout.hp_out_nid[1],
3243 spec->multiout.hp_out_nid[2],
3244 spec->multiout.hp_out_nid[3]);
3245 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3246 cfg->speaker_pins[0], cfg->speaker_pins[1],
3247 cfg->speaker_pins[2], cfg->speaker_pins[3],
3248 spec->multiout.extra_out_nid[0],
3249 spec->multiout.extra_out_nid[1],
3250 spec->multiout.extra_out_nid[2],
3251 spec->multiout.extra_out_nid[3]);
3252}
3253
Takashi Iwai463419d2012-12-05 14:17:37 +01003254/* find all available DACs of the codec */
3255static void alc_fill_all_nids(struct hda_codec *codec)
3256{
3257 struct alc_spec *spec = codec->spec;
3258 int i;
3259 hda_nid_t nid = codec->start_nid;
3260
3261 spec->num_all_dacs = 0;
3262 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3263 for (i = 0; i < codec->num_nodes; i++, nid++) {
3264 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3265 continue;
3266 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3267 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3268 break;
3269 }
3270 spec->all_dacs[spec->num_all_dacs++] = nid;
3271 }
3272}
3273
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003274static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3275{
3276 struct alc_spec *spec = codec->spec;
3277 struct auto_pin_cfg *cfg = &spec->autocfg;
3278 struct auto_pin_cfg *best_cfg;
3279 int best_badness = INT_MAX;
3280 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003281 bool fill_hardwired = true, fill_mio_first = true;
3282 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003283 bool hp_spk_swapped = false;
3284
Takashi Iwai463419d2012-12-05 14:17:37 +01003285 alc_fill_all_nids(codec);
3286
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003287 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3288 if (!best_cfg)
3289 return -ENOMEM;
3290 *best_cfg = *cfg;
3291
3292 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003293 badness = fill_and_eval_dacs(codec, fill_hardwired,
3294 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003295 if (badness < 0) {
3296 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003297 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003298 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003299 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3300 cfg->line_out_type, fill_hardwired, fill_mio_first,
3301 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003302 debug_show_configs(spec, cfg);
3303 if (badness < best_badness) {
3304 best_badness = badness;
3305 *best_cfg = *cfg;
3306 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003307 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003308 }
3309 if (!badness)
3310 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003311 fill_mio_first = !fill_mio_first;
3312 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003313 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003314 fill_hardwired = !fill_hardwired;
3315 if (!fill_hardwired)
3316 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003317 if (hp_spk_swapped)
3318 break;
3319 hp_spk_swapped = true;
3320 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003321 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3322 cfg->hp_outs = cfg->line_outs;
3323 memcpy(cfg->hp_pins, cfg->line_out_pins,
3324 sizeof(cfg->hp_pins));
3325 cfg->line_outs = cfg->speaker_outs;
3326 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3327 sizeof(cfg->speaker_pins));
3328 cfg->speaker_outs = 0;
3329 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3330 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003331 fill_hardwired = true;
3332 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003333 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003334 if (cfg->hp_outs > 0 &&
3335 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3336 cfg->speaker_outs = cfg->line_outs;
3337 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3338 sizeof(cfg->speaker_pins));
3339 cfg->line_outs = cfg->hp_outs;
3340 memcpy(cfg->line_out_pins, cfg->hp_pins,
3341 sizeof(cfg->hp_pins));
3342 cfg->hp_outs = 0;
3343 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3344 cfg->line_out_type = AUTO_PIN_HP_OUT;
3345 fill_hardwired = true;
3346 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003347 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003348 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003349 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003350
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003351 if (badness) {
3352 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003353 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003354 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003355 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3356 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003357 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003358
Takashi Iwaiba8111272012-12-06 18:06:23 +01003359 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003360 struct nid_path *path = get_nid_path(codec,
3361 spec->multiout.dac_nids[0],
3362 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003363 if (path)
3364 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3365 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003366
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003367 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003368 return 0;
3369}
3370
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003371/* replace the channels in the composed amp value with the given number */
3372static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3373{
3374 val &= ~(0x3U << 16);
3375 val |= chs << 16;
3376 return val;
3377}
3378
Takashi Iwai343a04b2011-07-06 14:28:39 +02003379static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003380 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003381 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003382 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003383{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003384 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003385 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003386 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003387 val = path->ctls[NID_PATH_VOL_CTL];
3388 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003389 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003390 val = amp_val_replace_channels(val, chs);
3391 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3392}
3393
3394/* return the channel bits suitable for the given path->ctls[] */
3395static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3396 int type)
3397{
3398 int chs = 1; /* mono (left only) */
3399 if (path) {
3400 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3401 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3402 chs = 3; /* stereo */
3403 }
3404 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003405}
3406
Takashi Iwaie29d3772011-11-14 17:13:23 +01003407static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3408 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003409 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003410{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003411 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3412 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003413}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003414
3415/* create a mute-switch for the given mixer widget;
3416 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3417 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003418static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003419 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003420 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003421 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003422{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003423 unsigned int val;
3424 int type = ALC_CTL_WIDGET_MUTE;
3425
3426 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003427 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003428 val = path->ctls[NID_PATH_MUTE_CTL];
3429 if (!val)
3430 return 0;
3431 val = amp_val_replace_channels(val, chs);
3432 if (get_amp_direction_(val) == HDA_INPUT) {
3433 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003434 int nums = snd_hda_get_num_conns(codec, nid);
3435 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003436 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003437 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003438 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003439 }
3440 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003441}
3442
Takashi Iwaie29d3772011-11-14 17:13:23 +01003443static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003444 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003445{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003446 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3447 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003448}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003449
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003450static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003451 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003452{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003453 int i;
3454
3455 for (i = path->depth - 1; i >= 0; i--) {
3456 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3457 return path->path[i];
3458 if (i != path->depth - 1 && i != 0 &&
3459 nid_has_mute(codec, path->path[i], HDA_INPUT))
3460 return path->path[i];
3461 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003462 return 0;
3463}
3464
3465static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003466 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003467{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003468 int i;
3469
3470 for (i = path->depth - 1; i >= 0; i--) {
3471 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3472 return path->path[i];
3473 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003474 return 0;
3475}
3476
Takashi Iwai7085ec12009-10-02 09:03:58 +02003477/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003478static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003479 const struct auto_pin_cfg *cfg)
3480{
3481 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003482 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003483
Takashi Iwaice764ab2011-04-27 16:35:23 +02003484 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003485 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003486 noutputs += spec->multi_ios;
3487
3488 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003489 const char *name;
3490 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003491 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003492 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003493
3494 dac = spec->multiout.dac_nids[i];
3495 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003496 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003497 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003498 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003499 index = 0;
3500 name = channel_name[i];
3501 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003502 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003503 name = alc_get_line_out_pfx(spec, i, true, &index);
3504 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003505
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003506 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003507 if (!path)
3508 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003509 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003510 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003511 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003512 if (err < 0)
3513 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003514 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003515 if (err < 0)
3516 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003517 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003518 if (err < 0)
3519 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003520 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003521 if (err < 0)
3522 return err;
3523 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003524 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003525 if (err < 0)
3526 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003527 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003528 if (err < 0)
3529 return err;
3530 }
3531 }
3532 return 0;
3533}
3534
Takashi Iwai343a04b2011-07-06 14:28:39 +02003535static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003536 hda_nid_t dac, const char *pfx,
3537 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003538{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003539 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003540 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003541
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003542 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003543 if (!path)
3544 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003545 /* bind volume control will be created in the case of dac = 0 */
3546 if (dac) {
3547 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3548 if (err < 0)
3549 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003550 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003551 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003552 if (err < 0)
3553 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003554 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003555}
3556
Takashi Iwai23c09b02011-08-19 09:05:35 +02003557static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3558 unsigned int nums,
3559 struct hda_ctl_ops *ops)
3560{
3561 struct alc_spec *spec = codec->spec;
3562 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003563 ctlp = snd_array_new(&spec->bind_ctls);
3564 if (!ctlp)
3565 return NULL;
3566 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3567 *ctlp = ctl;
3568 if (ctl)
3569 ctl->ops = ops;
3570 return ctl;
3571}
3572
3573/* add playback controls for speaker and HP outputs */
3574static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3575 const hda_nid_t *pins,
3576 const hda_nid_t *dacs,
3577 const char *pfx)
3578{
3579 struct alc_spec *spec = codec->spec;
3580 struct hda_bind_ctls *ctl;
3581 char name[32];
3582 int i, n, err;
3583
3584 if (!num_pins || !pins[0])
3585 return 0;
3586
Takashi Iwai527e4d72011-10-27 16:33:27 +02003587 if (num_pins == 1) {
3588 hda_nid_t dac = *dacs;
3589 if (!dac)
3590 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003591 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003592 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003593
Takashi Iwai23c09b02011-08-19 09:05:35 +02003594 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003595 hda_nid_t dac;
3596 if (dacs[num_pins - 1])
3597 dac = dacs[i]; /* with individual volumes */
3598 else
3599 dac = 0;
3600 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3601 err = alc_auto_create_extra_out(codec, pins[i], dac,
3602 "Bass Speaker", 0);
3603 } else if (num_pins >= 3) {
3604 snprintf(name, sizeof(name), "%s %s",
3605 pfx, channel_name[i]);
3606 err = alc_auto_create_extra_out(codec, pins[i], dac,
3607 name, 0);
3608 } else {
3609 err = alc_auto_create_extra_out(codec, pins[i], dac,
3610 pfx, i);
3611 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003612 if (err < 0)
3613 return err;
3614 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003615 if (dacs[num_pins - 1])
3616 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003617
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003618 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003619 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3620 if (!ctl)
3621 return -ENOMEM;
3622 n = 0;
3623 for (i = 0; i < num_pins; i++) {
3624 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003625 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003626 if (!pins[i] || !dacs[i])
3627 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003628 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003629 if (!path)
3630 continue;
3631 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003632 if (vol)
3633 ctl->values[n++] =
3634 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3635 }
3636 if (n) {
3637 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3638 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3639 if (err < 0)
3640 return err;
3641 }
3642 return 0;
3643}
3644
Takashi Iwai343a04b2011-07-06 14:28:39 +02003645static int alc_auto_create_hp_out(struct hda_codec *codec)
3646{
3647 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003648 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3649 spec->autocfg.hp_pins,
3650 spec->multiout.hp_out_nid,
3651 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003652}
3653
3654static int alc_auto_create_speaker_out(struct hda_codec *codec)
3655{
3656 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003657 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3658 spec->autocfg.speaker_pins,
3659 spec->multiout.extra_out_nid,
3660 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003661}
3662
Takashi Iwai130e5f02012-12-14 16:09:29 +01003663/* check whether a control with the given (nid, dir, idx) was assigned */
3664static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3665 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003666{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003667 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003668 int i, type;
3669
3670 for (i = 0; i < spec->paths.used; i++) {
3671 struct nid_path *p = snd_array_elem(&spec->paths, i);
3672 if (p->depth <= 0)
3673 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003674 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003675 unsigned int val = p->ctls[type];
3676 if (get_amp_nid_(val) == nid &&
3677 get_amp_direction_(val) == dir &&
3678 get_amp_index_(val) == idx)
3679 return true;
3680 }
3681 }
3682 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003683}
3684
3685/* can have the amp-in capability? */
3686static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3687{
3688 hda_nid_t nid = path->path[idx];
3689 unsigned int caps = get_wcaps(codec, nid);
3690 unsigned int type = get_wcaps_type(caps);
3691
3692 if (!(caps & AC_WCAP_IN_AMP))
3693 return false;
3694 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3695 return false;
3696 return true;
3697}
3698
3699/* can have the amp-out capability? */
3700static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3701{
3702 hda_nid_t nid = path->path[idx];
3703 unsigned int caps = get_wcaps(codec, nid);
3704 unsigned int type = get_wcaps_type(caps);
3705
3706 if (!(caps & AC_WCAP_OUT_AMP))
3707 return false;
3708 if (type == AC_WID_PIN && !idx) /* only for output pins */
3709 return false;
3710 return true;
3711}
3712
Takashi Iwaic9967f12012-12-14 16:39:22 +01003713/* check whether the given (nid,dir,idx) is active */
3714static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3715 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003716{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003717 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003718 int i, n;
3719
Takashi Iwaic9967f12012-12-14 16:39:22 +01003720 for (n = 0; n < spec->paths.used; n++) {
3721 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003722 if (!path->active)
3723 continue;
3724 for (i = 0; i < path->depth; i++) {
3725 if (path->path[i] == nid) {
3726 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3727 return true;
3728 break;
3729 }
3730 }
3731 }
3732 return false;
3733}
3734
Takashi Iwai130e5f02012-12-14 16:09:29 +01003735/* get the default amp value for the target state */
3736static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3737 int dir, bool enable)
3738{
3739 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003740 unsigned int val = 0;
3741
3742 caps = query_amp_caps(codec, nid, dir);
3743 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003744 /* set to 0dB */
3745 if (enable)
3746 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003747 }
3748 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003749 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003750 val |= HDA_AMP_MUTE;
3751 }
3752 return val;
3753}
3754
Takashi Iwai130e5f02012-12-14 16:09:29 +01003755/* initialize the amp value (only at the first time) */
3756static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3757{
3758 int val = get_amp_val_to_activate(codec, nid, dir, false);
3759 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3760}
3761
3762static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3763 int idx, bool enable)
3764{
3765 int val;
3766 if (is_ctl_associated(codec, nid, dir, idx) ||
3767 is_active_nid(codec, nid, dir, idx))
3768 return;
3769 val = get_amp_val_to_activate(codec, nid, dir, enable);
3770 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3771}
3772
3773static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3774 int i, bool enable)
3775{
3776 hda_nid_t nid = path->path[i];
3777 init_amp(codec, nid, HDA_OUTPUT, 0);
3778 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3779}
3780
3781static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003782 int i, bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003783{
3784 struct alc_spec *spec = codec->spec;
3785 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003786 int n, nums, idx;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003787 int type;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003788 hda_nid_t nid = path->path[i];
3789
3790 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai666a70d2012-12-17 20:29:29 +01003791 type = get_wcaps_type(get_wcaps(codec, nid));
3792 if (type == AC_WID_PIN ||
3793 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003794 nums = 1;
3795 idx = 0;
3796 } else
3797 idx = path->idx[i];
3798
Takashi Iwai130e5f02012-12-14 16:09:29 +01003799 for (n = 0; n < nums; n++)
3800 init_amp(codec, nid, HDA_INPUT, n);
3801
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003802 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003803 return;
3804
3805 /* here is a little bit tricky in comparison with activate_amp_out();
3806 * when aa-mixer is available, we need to enable the path as well
3807 */
3808 for (n = 0; n < nums; n++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01003809 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003810 continue;
3811 activate_amp(codec, nid, HDA_INPUT, n, enable);
3812 }
3813}
3814
3815static void activate_path(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003816 bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003817{
3818 int i;
3819
Takashi Iwai130e5f02012-12-14 16:09:29 +01003820 if (!enable)
3821 path->active = false;
3822
3823 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003824 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003825 snd_hda_codec_write_cache(codec, path->path[i], 0,
3826 AC_VERB_SET_CONNECT_SEL,
3827 path->idx[i]);
3828 if (has_amp_in(codec, path, i))
Takashi Iwai666a70d2012-12-17 20:29:29 +01003829 activate_amp_in(codec, path, i, enable, add_aamix);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003830 if (has_amp_out(codec, path, i))
3831 activate_amp_out(codec, path, i, enable);
3832 }
3833
3834 if (enable)
3835 path->active = true;
3836}
3837
Takashi Iwai78e635c2012-12-10 17:07:16 +01003838/* configure the path from the given dac to the pin as the proper output */
3839static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3840 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003841 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003842{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003843 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003844
Takashi Iwai130e5f02012-12-14 16:09:29 +01003845 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003846 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003847 if (!path)
3848 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003849 if (path->active)
3850 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003851 activate_path(codec, path, true, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003852}
3853
Takashi Iwai343a04b2011-07-06 14:28:39 +02003854static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003855{
3856 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003857 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003858 int i;
3859
3860 for (i = 0; i <= HDA_SIDE; i++) {
3861 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3862 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003863 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003864 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003865
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003866 }
3867}
3868
Takashi Iwai343a04b2011-07-06 14:28:39 +02003869static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003870{
3871 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003872 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003873 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003874
David Henningsson636030e2011-10-12 19:26:03 +02003875 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003876 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3877 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003878 pin = spec->autocfg.hp_pins[i];
3879 if (!pin)
3880 break;
3881 dac = spec->multiout.hp_out_nid[i];
3882 if (!dac) {
3883 if (i > 0 && spec->multiout.hp_out_nid[0])
3884 dac = spec->multiout.hp_out_nid[0];
3885 else
3886 dac = spec->multiout.dac_nids[0];
3887 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003888 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003889 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003890 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003891 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3892 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003893 pin = spec->autocfg.speaker_pins[i];
3894 if (!pin)
3895 break;
3896 dac = spec->multiout.extra_out_nid[i];
3897 if (!dac) {
3898 if (i > 0 && spec->multiout.extra_out_nid[0])
3899 dac = spec->multiout.extra_out_nid[0];
3900 else
3901 dac = spec->multiout.dac_nids[0];
3902 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01003903 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003904 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003905}
3906
Takashi Iwai276dd702012-02-17 16:17:03 +01003907/* check whether the given pin can be a multi-io pin */
3908static bool can_be_multiio_pin(struct hda_codec *codec,
3909 unsigned int location, hda_nid_t nid)
3910{
3911 unsigned int defcfg, caps;
3912
3913 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3914 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3915 return false;
3916 if (location && get_defcfg_location(defcfg) != location)
3917 return false;
3918 caps = snd_hda_query_pin_caps(codec, nid);
3919 if (!(caps & AC_PINCAP_OUT))
3920 return false;
3921 return true;
3922}
3923
Takashi Iwaice764ab2011-04-27 16:35:23 +02003924/*
3925 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003926 *
3927 * When hardwired is set, try to fill ony hardwired pins, and returns
3928 * zero if any pins are filled, non-zero if nothing found.
3929 * When hardwired is off, try to fill possible input pins, and returns
3930 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003931 */
3932static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003933 hda_nid_t reference_pin,
3934 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003935{
3936 struct alc_spec *spec = codec->spec;
3937 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003938 int type, i, j, dacs, num_pins, old_pins;
3939 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3940 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003941 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003942
Takashi Iwai276dd702012-02-17 16:17:03 +01003943 old_pins = spec->multi_ios;
3944 if (old_pins >= 2)
3945 goto end_fill;
3946
3947 num_pins = 0;
3948 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3949 for (i = 0; i < cfg->num_inputs; i++) {
3950 if (cfg->inputs[i].type != type)
3951 continue;
3952 if (can_be_multiio_pin(codec, location,
3953 cfg->inputs[i].pin))
3954 num_pins++;
3955 }
3956 }
3957 if (num_pins < 2)
3958 goto end_fill;
3959
Takashi Iwai07b18f62011-11-10 15:42:54 +01003960 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003961 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3962 for (i = 0; i < cfg->num_inputs; i++) {
3963 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003964 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003965
Takashi Iwaice764ab2011-04-27 16:35:23 +02003966 if (cfg->inputs[i].type != type)
3967 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003968 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003969 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003970 for (j = 0; j < spec->multi_ios; j++) {
3971 if (nid == spec->multi_io[j].pin)
3972 break;
3973 }
3974 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003975 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003976
3977 if (offset && offset + spec->multi_ios < dacs) {
3978 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01003979 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01003980 dac = 0;
3981 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003982 if (hardwired)
3983 dac = get_dac_if_single(codec, nid);
3984 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003985 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003986 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003987 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003988 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003989 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003990 if (!add_new_nid_path(codec, dac, nid, 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003991 badness++;
3992 continue;
3993 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003994 spec->multi_io[spec->multi_ios].pin = nid;
3995 spec->multi_io[spec->multi_ios].dac = dac;
3996 spec->multi_ios++;
3997 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003998 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003999 }
4000 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004001 end_fill:
4002 if (badness)
4003 badness = BAD_MULTI_IO;
4004 if (old_pins == spec->multi_ios) {
4005 if (hardwired)
4006 return 1; /* nothing found */
4007 else
4008 return badness; /* no badness if nothing found */
4009 }
4010 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004011 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004012 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004013 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004014 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004015 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004016
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004017 /* assign volume and mute controls */
4018 for (i = old_pins; i < spec->multi_ios; i++)
4019 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4020 spec->multi_io[i].dac);
4021
4022 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004023}
4024
4025static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4026 struct snd_ctl_elem_info *uinfo)
4027{
4028 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4029 struct alc_spec *spec = codec->spec;
4030
4031 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4032 uinfo->count = 1;
4033 uinfo->value.enumerated.items = spec->multi_ios + 1;
4034 if (uinfo->value.enumerated.item > spec->multi_ios)
4035 uinfo->value.enumerated.item = spec->multi_ios;
4036 sprintf(uinfo->value.enumerated.name, "%dch",
4037 (uinfo->value.enumerated.item + 1) * 2);
4038 return 0;
4039}
4040
4041static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4042 struct snd_ctl_elem_value *ucontrol)
4043{
4044 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4045 struct alc_spec *spec = codec->spec;
4046 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4047 return 0;
4048}
4049
4050static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4051{
4052 struct alc_spec *spec = codec->spec;
4053 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004054 struct nid_path *path;
4055
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004056 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004057 if (!path)
4058 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004059
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004060 if (path->active == output)
4061 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004062
Takashi Iwaice764ab2011-04-27 16:35:23 +02004063 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004064 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004065 activate_path(codec, path, true, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004066 } else {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004067 activate_path(codec, path, false, true);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004068 snd_hda_set_pin_ctl_cache(codec, nid,
4069 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004070 }
4071 return 0;
4072}
4073
4074static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4075 struct snd_ctl_elem_value *ucontrol)
4076{
4077 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4078 struct alc_spec *spec = codec->spec;
4079 int i, ch;
4080
4081 ch = ucontrol->value.enumerated.item[0];
4082 if (ch < 0 || ch > spec->multi_ios)
4083 return -EINVAL;
4084 if (ch == (spec->ext_channel_count - 1) / 2)
4085 return 0;
4086 spec->ext_channel_count = (ch + 1) * 2;
4087 for (i = 0; i < spec->multi_ios; i++)
4088 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004089 spec->multiout.max_channels = max(spec->ext_channel_count,
4090 spec->const_channel_count);
4091 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004092 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004093 return 1;
4094}
4095
Takashi Iwaia9111322011-05-02 11:30:18 +02004096static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4098 .name = "Channel Mode",
4099 .info = alc_auto_ch_mode_info,
4100 .get = alc_auto_ch_mode_get,
4101 .put = alc_auto_ch_mode_put,
4102};
4103
Takashi Iwai23c09b02011-08-19 09:05:35 +02004104static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004105{
4106 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004107
Takashi Iwaic2674682011-08-24 17:57:44 +02004108 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004109 if (!alc_kcontrol_new(spec, "Channel Mode",
4110 &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 Iwai177943a32011-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 Iwai177943a32011-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 Iwai177943a32011-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 Krzesinski9f720bb92012-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 Iwai1c7161532011-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)