blob: 6fb39221aac41ff4c9e5d501a76f28b6082b872f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe409a3e92012-03-27 13:01:01 +10309 * Jonathan Woithe <jwoithe@just42.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Takashi Iwai23d30f22012-05-07 17:17:32 +020035#include "hda_auto_parser.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090036#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020037#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Takashi Iwai1d045db2011-07-07 18:23:21 +020039/* unsol event tags */
40#define ALC_FRONT_EVENT 0x01
41#define ALC_DCVOL_EVENT 0x02
42#define ALC_HP_EVENT 0x04
43#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020044
Kailang Yangdf694da2005-12-05 19:42:22 +010045/* for GPIO Poll */
46#define GPIO_MASK 0x03
47
Takashi Iwai4a79ba32009-04-22 16:31:35 +020048/* extra amp-initialization sequence types */
49enum {
50 ALC_INIT_NONE,
51 ALC_INIT_DEFAULT,
52 ALC_INIT_GPIO1,
53 ALC_INIT_GPIO2,
54 ALC_INIT_GPIO3,
55};
56
Kailang Yangda00c242010-03-19 11:23:45 +010057struct alc_customize_define {
58 unsigned int sku_cfg;
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
65 unsigned int swap:1;
66 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020067 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010068};
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwai23d30f22012-05-07 17:17:32 +020076/* make compatible with old code */
77#define alc_apply_pincfgs snd_hda_apply_pincfgs
78#define alc_apply_fixup snd_hda_apply_fixup
79#define alc_pick_fixup snd_hda_pick_fixup
80#define alc_fixup hda_fixup
81#define alc_pincfg hda_pintbl
82#define alc_model_fixup hda_model_fixup
83
84#define ALC_FIXUP_PINS HDA_FIXUP_PINS
85#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
86#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
87
88#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
89#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
90#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
91#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
92
93
Takashi Iwai30dcd3b2012-12-06 15:45:38 +010094#define MAX_NID_PATH_DEPTH 5
95
Takashi Iwai8dd48672012-12-14 18:19:04 +010096enum {
97 NID_PATH_VOL_CTL,
98 NID_PATH_MUTE_CTL,
99 NID_PATH_BOOST_CTL,
100 NID_PATH_NUM_CTLS
101};
102
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100103/* Widget connection path
104 *
105 * For output, stored in the order of DAC -> ... -> pin,
106 * for input, pin -> ... -> ADC.
107 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100108 * idx[i] contains the source index number to select on of the widget path[i];
109 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100110 * multi[] indicates whether it's a selector widget with multi-connectors
111 * (i.e. the connection selection is mandatory)
112 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
113 */
114struct nid_path {
115 int depth;
116 hda_nid_t path[MAX_NID_PATH_DEPTH];
117 unsigned char idx[MAX_NID_PATH_DEPTH];
118 unsigned char multi[MAX_NID_PATH_DEPTH];
Takashi Iwai8dd48672012-12-14 18:19:04 +0100119 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
Takashi Iwai130e5f02012-12-14 16:09:29 +0100120 bool active;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100121};
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200124 struct hda_gen_spec gen;
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200127 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 unsigned int num_mixers;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100129 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200131 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200132 const struct hda_pcm_stream *stream_analog_playback;
133 const struct hda_pcm_stream *stream_analog_capture;
134 const struct hda_pcm_stream *stream_analog_alt_playback;
135 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200137 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200138 const struct hda_pcm_stream *stream_digital_playback;
139 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200142 struct hda_multi_out multiout; /* playback set-up
143 * max_channels, dacs must be set
144 * dig_out_nid and hp_nid are optional
145 */
Takashi Iwai63300792008-01-24 15:31:36 +0100146 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100147 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100148 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 /* capture */
151 unsigned int num_adc_nids;
Takashi Iwai27d31532012-12-18 08:57:05 +0100152 hda_nid_t adc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai16ded522005-06-10 19:58:24 +0200153 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200154 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Takashi Iwai840b64c2010-07-13 22:49:01 +0200156 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200157 hda_nid_t cur_adc;
158 unsigned int cur_adc_stream_tag;
159 unsigned int cur_adc_format;
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 /* capture source */
Takashi Iwai27d31532012-12-18 08:57:05 +0100162 struct hda_input_mux input_mux;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200164 hda_nid_t ext_mic_pin;
165 hda_nid_t dock_mic_pin;
166 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100169 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 int num_channel_mode;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100171 int const_channel_count; /* min. channel count (for speakers) */
172 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100175 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200176
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200177 /* dynamic controls, init_verbs and input_mux */
178 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100179 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200180 struct snd_array kctls;
Takashi Iwai41923e42007-10-22 17:20:10 +0200181 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200182 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
183 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
184 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200185 hda_nid_t inv_dmic_pin;
Takashi Iwai37c04202012-12-18 14:22:45 +0100186 hda_nid_t shared_mic_vref_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100187
Takashi Iwai463419d2012-12-05 14:17:37 +0100188 /* DAC list */
189 int num_all_dacs;
190 hda_nid_t all_dacs[16];
191
Takashi Iwaic9967f12012-12-14 16:39:22 +0100192 /* path list */
193 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100194
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100195 /* hooks */
196 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200197#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500198 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100199#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200200 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200201 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100202
Takashi Iwai834be882006-03-01 14:16:17 +0100203 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200204 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200205 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200206 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200207 unsigned int auto_mic:1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200208 unsigned int automute_speaker:1; /* automute speaker outputs */
209 unsigned int automute_lo:1; /* automute LO outputs */
210 unsigned int detect_hp:1; /* Headphone detection enabled */
211 unsigned int detect_lo:1; /* Line-out detection enabled */
212 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
213 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100214 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200215
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100216 /* other flags */
Takashi Iwai20c18f52012-12-18 14:33:21 +0100217 unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100218 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200219 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai24de1832011-11-07 17:13:39 +0100220 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200221 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
222 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200223 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwai9bf387b2012-12-18 17:18:21 +0100224 unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */
Takashi Iwaid922b512011-04-28 12:18:53 +0200225
Takashi Iwai20c18f52012-12-18 14:33:21 +0100226 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwaid922b512011-04-28 12:18:53 +0200227
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200228 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200229 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100230
Takashi Iwai2134ea42008-01-10 16:53:55 +0100231 /* for virtual master */
232 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100233 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200234#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200235 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100236 int num_loopbacks;
237 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200238#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200239
240 /* for PLL fix */
241 hda_nid_t pll_nid;
242 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200243 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100244
Takashi Iwaice764ab2011-04-27 16:35:23 +0200245 /* multi-io */
246 int multi_ios;
247 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200248
249 /* bind volumes */
250 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100251};
252
Takashi Iwai44c02402011-07-08 15:14:19 +0200253static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
254 int dir, unsigned int bits)
255{
256 if (!nid)
257 return false;
258 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
259 if (query_amp_caps(codec, nid, dir) & bits)
260 return true;
261 return false;
262}
263
264#define nid_has_mute(codec, nid, dir) \
265 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
266#define nid_has_volume(codec, nid, dir) \
267 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
268
Takashi Iwai666a70d2012-12-17 20:29:29 +0100269static struct nid_path *
270get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid);
271static void activate_path(struct hda_codec *codec, struct nid_path *path,
272 bool enable, bool add_aamix);
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274/*
275 * input MUX handling
276 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200277static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
278 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
280 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
281 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +0100282 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200285static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
289 struct alc_spec *spec = codec->spec;
290 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
291
292 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
293 return 0;
294}
295
Takashi Iwai666a70d2012-12-17 20:29:29 +0100296static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
297{
298 struct alc_spec *spec = codec->spec;
299 if (spec->dyn_adc_switch)
300 adc_idx = spec->dyn_adc_idx[imux_idx];
301 return spec->adc_nids[adc_idx];
302}
303
Takashi Iwai21268962011-07-07 15:01:13 +0200304static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Takashi Iwai21268962011-07-07 15:01:13 +0200306 struct alc_spec *spec = codec->spec;
307 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
308
309 if (spec->cur_adc && spec->cur_adc != new_adc) {
310 /* stream is running, let's swap the current ADC */
311 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
312 spec->cur_adc = new_adc;
313 snd_hda_codec_setup_stream(codec, new_adc,
314 spec->cur_adc_stream_tag, 0,
315 spec->cur_adc_format);
316 return true;
317 }
318 return false;
319}
320
Takashi Iwai24de1832011-11-07 17:13:39 +0100321static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200322static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100323static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx);
Takashi Iwai24de1832011-11-07 17:13:39 +0100324
David Henningsson00227f12012-06-27 18:45:44 +0200325/* for shared I/O, change the pin-control accordingly */
326static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
327{
328 struct alc_spec *spec = codec->spec;
329 unsigned int val;
330 hda_nid_t pin = spec->autocfg.inputs[1].pin;
331 /* NOTE: this assumes that there are only two inputs, the
332 * first is the real internal mic and the second is HP/mic jack.
333 */
334
335 val = snd_hda_get_default_vref(codec, pin);
336
337 /* This pin does not have vref caps - let's enable vref on pin 0x18
338 instead, as suggested by Realtek */
Takashi Iwai37c04202012-12-18 14:22:45 +0100339 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
340 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
341 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
342 if (vref_val != AC_PINCTL_VREF_HIZ)
343 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
David Henningsson00227f12012-06-27 18:45:44 +0200344 }
345
346 val = set_as_mic ? val | PIN_IN : PIN_HP;
347 snd_hda_set_pin_ctl(codec, pin, val);
348
349 spec->automute_speaker = !set_as_mic;
350 call_update_outputs(codec);
351}
Takashi Iwai21268962011-07-07 15:01:13 +0200352
353/* select the given imux item; either unmute exclusively or select the route */
354static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
355 unsigned int idx, bool force)
356{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100358 const struct hda_input_mux *imux;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100359 struct nid_path *path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Takashi Iwai27d31532012-12-18 08:57:05 +0100361 imux = &spec->input_mux;
362 if (!imux->num_items)
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100363 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100364
Takashi Iwai21268962011-07-07 15:01:13 +0200365 if (idx >= imux->num_items)
366 idx = imux->num_items - 1;
367 if (spec->cur_mux[adc_idx] == idx && !force)
368 return 0;
Takashi Iwai666a70d2012-12-17 20:29:29 +0100369
370 path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]],
371 spec->adc_nids[adc_idx]);
372 if (!path)
373 return 0;
374 if (path->active)
375 activate_path(codec, path, false, false);
376
Takashi Iwai21268962011-07-07 15:01:13 +0200377 spec->cur_mux[adc_idx] = idx;
378
David Henningsson00227f12012-06-27 18:45:44 +0200379 if (spec->shared_mic_hp)
380 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100381
Takashi Iwai666a70d2012-12-17 20:29:29 +0100382 if (spec->dyn_adc_switch)
Takashi Iwai21268962011-07-07 15:01:13 +0200383 alc_dyn_adc_pcm_resetup(codec, idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200384
Takashi Iwai666a70d2012-12-17 20:29:29 +0100385 path = get_nid_path(codec, spec->imux_pins[idx],
386 get_adc_nid(codec, adc_idx, idx));
387 if (!path)
388 return 0;
389 if (path->active)
390 return 0;
391 activate_path(codec, path, true, false);
Takashi Iwai125821a2012-06-22 14:30:29 +0200392 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200393 return 1;
394}
395
396static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
397 struct snd_ctl_elem_value *ucontrol)
398{
399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
400 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
401 return alc_mux_select(codec, adc_idx,
402 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100403}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100406 * set up the input pin config (depending on the given auto-pin type)
407 */
408static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
409 int auto_pin_type)
410{
411 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200412 if (auto_pin_type == AUTO_PIN_MIC)
413 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200414 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100415}
416
417/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200418 * Append the given mixer and verb elements for the later use
419 * The mixer array is referred in build_controls(), and init_verbs are
420 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100421 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200422static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100423{
424 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
425 return;
426 spec->mixers[spec->num_mixers++] = mix;
427}
428
Takashi Iwaid88897e2008-10-31 15:01:37 +0100429/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200430 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100431 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200432/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200433static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200434 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
435 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
436 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
437 { }
438};
439
Takashi Iwaia9111322011-05-02 11:30:18 +0200440static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200441 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
442 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
443 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
444 { }
445};
446
Takashi Iwaia9111322011-05-02 11:30:18 +0200447static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200448 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
449 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
450 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
451 { }
452};
453
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200454/*
455 * Fix hardware PLL issue
456 * On some codecs, the analog PLL gating control must be off while
457 * the default value is 1.
458 */
459static void alc_fix_pll(struct hda_codec *codec)
460{
461 struct alc_spec *spec = codec->spec;
462 unsigned int val;
463
464 if (!spec->pll_nid)
465 return;
466 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
467 spec->pll_coef_idx);
468 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
469 AC_VERB_GET_PROC_COEF, 0);
470 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
471 spec->pll_coef_idx);
472 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
473 val & ~(1 << spec->pll_coef_bit));
474}
475
476static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
477 unsigned int coef_idx, unsigned int coef_bit)
478{
479 struct alc_spec *spec = codec->spec;
480 spec->pll_nid = nid;
481 spec->pll_coef_idx = coef_idx;
482 spec->pll_coef_bit = coef_bit;
483 alc_fix_pll(codec);
484}
485
Takashi Iwai1d045db2011-07-07 18:23:21 +0200486/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200487 * Jack detections for HP auto-mute and mic-switch
488 */
489
490/* check each pin in the given array; returns true if any of them is plugged */
491static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200492{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200493 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200494
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495 for (i = 0; i < num_pins; i++) {
496 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200497 if (!nid)
498 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200499 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200500 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 return present;
502}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200503
Takashi Iwai1d045db2011-07-07 18:23:21 +0200504/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200505static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200506 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507{
508 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200509 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200510 int i;
511
512 for (i = 0; i < num_pins; i++) {
513 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100514 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200515 if (!nid)
516 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100517 /* don't reset VREF value in case it's controlling
518 * the amp (see alc861_fixup_asus_amp_vref_0f())
519 */
520 if (spec->keep_vref_in_automute) {
521 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100522 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100523 val &= ~PIN_HP;
524 } else
525 val = 0;
526 val |= pin_bits;
527 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200528 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200529}
530
David Henningsson42cf0d02011-09-20 12:04:56 +0200531/* Toggle outputs muting */
532static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200533{
534 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200535 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200536
Takashi Iwaic0a20262011-06-10 15:28:15 +0200537 /* Control HP pins/amps depending on master_mute state;
538 * in general, HP pins/amps control should be enabled in all cases,
539 * but currently set only for master_mute, just to be safe
540 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100541 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
542 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200543 spec->autocfg.hp_pins, spec->master_mute, true);
544
David Henningsson42cf0d02011-09-20 12:04:56 +0200545 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200546 on = 0;
547 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200548 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200549 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200550 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200551 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200552
553 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200554 /* if LO is a copy of either HP or Speaker, don't need to handle it */
555 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
556 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200557 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200558 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200559 on = 0;
560 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200561 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200562 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200563 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200564 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200565}
566
David Henningsson42cf0d02011-09-20 12:04:56 +0200567static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200568{
569 struct alc_spec *spec = codec->spec;
570 if (spec->automute_hook)
571 spec->automute_hook(codec);
572 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200573 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200574}
575
Takashi Iwai1d045db2011-07-07 18:23:21 +0200576/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200577static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200578{
579 struct alc_spec *spec = codec->spec;
580
David Henningsson42cf0d02011-09-20 12:04:56 +0200581 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
583 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200584 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200585 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200586 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200587}
588
Takashi Iwai1d045db2011-07-07 18:23:21 +0200589/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200590static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591{
592 struct alc_spec *spec = codec->spec;
593
David Henningssonf7f4b232012-10-10 16:32:09 +0200594 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
595 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200596 /* check LO jack only when it's different from HP */
597 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
598 return;
599
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200600 spec->line_jack_present =
601 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
602 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200603 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200604 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200605 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200606}
607
Takashi Iwai1d045db2011-07-07 18:23:21 +0200608/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200609static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200610{
611 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200612 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200613
Takashi Iwai480967d2012-12-18 14:29:52 +0100614 if (!spec->auto_mic)
Takashi Iwai6c819492009-08-10 18:47:44 +0200615 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200616 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200617 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200618
Takashi Iwai21268962011-07-07 15:01:13 +0200619 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
620 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
621 else if (spec->dock_mic_idx >= 0 &&
622 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
623 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
624 else
625 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200626}
627
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100628/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200629static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100630{
631 unsigned int val;
632 struct snd_kcontrol *kctl;
633 struct snd_ctl_elem_value *uctl;
634
635 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
636 if (!kctl)
637 return;
638 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
639 if (!uctl)
640 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200641 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100642 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
643 val &= HDA_AMP_VOLMASK;
644 uctl->value.integer.value[0] = val;
645 uctl->value.integer.value[1] = val;
646 kctl->put(kctl, uctl);
647 kfree(uctl);
648}
649
David Henningsson29adc4b2012-09-25 11:31:00 +0200650static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100651{
David Henningsson29adc4b2012-09-25 11:31:00 +0200652 /* For some reason, the res given from ALC880 is broken.
653 Here we adjust it properly. */
654 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100655}
656
Kailang Yangf9423e72008-05-27 12:32:25 +0200657/* additional initialization for ALC888 variants */
658static void alc888_coef_init(struct hda_codec *codec)
659{
660 unsigned int tmp;
661
662 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
663 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
664 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100665 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200666 /* alc888S-VC */
667 snd_hda_codec_read(codec, 0x20, 0,
668 AC_VERB_SET_PROC_COEF, 0x830);
669 else
670 /* alc888-VB */
671 snd_hda_codec_read(codec, 0x20, 0,
672 AC_VERB_SET_PROC_COEF, 0x3030);
673}
674
Takashi Iwai1d045db2011-07-07 18:23:21 +0200675/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200676static void alc889_coef_init(struct hda_codec *codec)
677{
678 unsigned int tmp;
679
680 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
681 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
682 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
683 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
684}
685
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100686/* turn on/off EAPD control (only if available) */
687static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
688{
689 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
690 return;
691 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
692 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
693 on ? 2 : 0);
694}
695
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200696/* turn on/off EAPD controls of the codec */
697static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
698{
699 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200700 static hda_nid_t pins[] = {
701 0x0f, 0x10, 0x14, 0x15, 0
702 };
703 hda_nid_t *p;
704 for (p = pins; *p; p++)
705 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200706}
707
Takashi Iwai1c716152011-04-07 10:37:16 +0200708/* generic shutup callback;
709 * just turning off EPAD and a little pause for avoiding pop-noise
710 */
711static void alc_eapd_shutup(struct hda_codec *codec)
712{
713 alc_auto_setup_eapd(codec, false);
714 msleep(200);
715}
716
Takashi Iwai1d045db2011-07-07 18:23:21 +0200717/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200718static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200719{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200720 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200721
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200722 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200723 switch (type) {
724 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200725 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
726 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200727 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200728 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
729 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200730 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200731 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
732 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200733 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200734 switch (codec->vendor_id) {
735 case 0x10ec0260:
736 snd_hda_codec_write(codec, 0x1a, 0,
737 AC_VERB_SET_COEF_INDEX, 7);
738 tmp = snd_hda_codec_read(codec, 0x1a, 0,
739 AC_VERB_GET_PROC_COEF, 0);
740 snd_hda_codec_write(codec, 0x1a, 0,
741 AC_VERB_SET_COEF_INDEX, 7);
742 snd_hda_codec_write(codec, 0x1a, 0,
743 AC_VERB_SET_PROC_COEF,
744 tmp | 0x2010);
745 break;
746 case 0x10ec0262:
747 case 0x10ec0880:
748 case 0x10ec0882:
749 case 0x10ec0883:
750 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100751 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100752 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200753 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200754 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200755 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200756 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200757 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100758#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200759 case 0x10ec0267:
760 case 0x10ec0268:
761 snd_hda_codec_write(codec, 0x20, 0,
762 AC_VERB_SET_COEF_INDEX, 7);
763 tmp = snd_hda_codec_read(codec, 0x20, 0,
764 AC_VERB_GET_PROC_COEF, 0);
765 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200766 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200767 snd_hda_codec_write(codec, 0x20, 0,
768 AC_VERB_SET_PROC_COEF,
769 tmp | 0x3000);
770 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100771#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200772 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200773 break;
774 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200775}
Kailang Yangea1fb292008-08-26 12:58:38 +0200776
Takashi Iwai1d045db2011-07-07 18:23:21 +0200777/*
778 * Auto-Mute mode mixer enum support
779 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200780static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
781 struct snd_ctl_elem_info *uinfo)
782{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200783 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
784 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200785 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100786 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200787 };
788
Takashi Iwaidda415d2012-11-30 18:34:38 +0100789 if (spec->automute_speaker_possible && spec->automute_lo_possible)
790 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
791 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200792}
793
794static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_value *ucontrol)
796{
797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200799 unsigned int val = 0;
800 if (spec->automute_speaker)
801 val++;
802 if (spec->automute_lo)
803 val++;
804
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200805 ucontrol->value.enumerated.item[0] = val;
806 return 0;
807}
808
809static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
810 struct snd_ctl_elem_value *ucontrol)
811{
812 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
813 struct alc_spec *spec = codec->spec;
814
815 switch (ucontrol->value.enumerated.item[0]) {
816 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200817 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200818 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200819 spec->automute_speaker = 0;
820 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200821 break;
822 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200823 if (spec->automute_speaker_possible) {
824 if (!spec->automute_lo && spec->automute_speaker)
825 return 0;
826 spec->automute_speaker = 1;
827 spec->automute_lo = 0;
828 } else if (spec->automute_lo_possible) {
829 if (spec->automute_lo)
830 return 0;
831 spec->automute_lo = 1;
832 } else
833 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200834 break;
835 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200836 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200837 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200838 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200839 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200840 spec->automute_speaker = 1;
841 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200842 break;
843 default:
844 return -EINVAL;
845 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200846 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200847 return 1;
848}
849
Takashi Iwaia9111322011-05-02 11:30:18 +0200850static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200851 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
852 .name = "Auto-Mute Mode",
853 .info = alc_automute_mode_info,
854 .get = alc_automute_mode_get,
855 .put = alc_automute_mode_put,
856};
857
Takashi Iwai668d1e92012-11-29 14:10:17 +0100858static struct snd_kcontrol_new *
859alc_kcontrol_new(struct alc_spec *spec, const char *name,
860 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200861{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100862 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
863 if (!knew)
864 return NULL;
865 *knew = *temp;
Takashi Iwaibc549762012-12-18 15:35:11 +0100866 if (name)
867 knew->name = kstrdup(name, GFP_KERNEL);
868 else if (knew->name)
869 knew->name = kstrdup(knew->name, GFP_KERNEL);
Takashi Iwai668d1e92012-11-29 14:10:17 +0100870 if (!knew->name)
871 return NULL;
872 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200873}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200874
875static int alc_add_automute_mode_enum(struct hda_codec *codec)
876{
877 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200878
Takashi Iwaibc549762012-12-18 15:35:11 +0100879 if (!alc_kcontrol_new(spec, NULL, &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 return -ENOMEM;
881 return 0;
882}
883
Takashi Iwai1d045db2011-07-07 18:23:21 +0200884/*
885 * Check the availability of HP/line-out auto-mute;
886 * Set up appropriately if really supported
887 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100888static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200889{
890 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200891 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200892 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100893 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200894
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200895 if (cfg->hp_pins[0])
896 present++;
897 if (cfg->line_out_pins[0])
898 present++;
899 if (cfg->speaker_pins[0])
900 present++;
901 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100902 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200903
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200904 if (!cfg->speaker_pins[0] &&
905 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200906 memcpy(cfg->speaker_pins, cfg->line_out_pins,
907 sizeof(cfg->speaker_pins));
908 cfg->speaker_outs = cfg->line_outs;
909 }
910
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200911 if (!cfg->hp_pins[0] &&
912 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200913 memcpy(cfg->hp_pins, cfg->line_out_pins,
914 sizeof(cfg->hp_pins));
915 cfg->hp_outs = cfg->line_outs;
916 }
917
918 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200919 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200920 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200921 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200922 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200923 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200924 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
925 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200926 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200927 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200928
David Henningsson42cf0d02011-09-20 12:04:56 +0200929 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
930 if (cfg->speaker_outs)
931 for (i = 0; i < cfg->line_outs; i++) {
932 hda_nid_t nid = cfg->line_out_pins[i];
933 if (!is_jack_detectable(codec, nid))
934 continue;
935 snd_printdd("realtek: Enable Line-Out "
936 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200937 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
938 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200939 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200940 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200941 spec->automute_lo_possible = spec->detect_hp;
942 }
943
944 spec->automute_speaker_possible = cfg->speaker_outs &&
945 (spec->detect_hp || spec->detect_lo);
946
947 spec->automute_lo = spec->automute_lo_possible;
948 spec->automute_speaker = spec->automute_speaker_possible;
949
Takashi Iwai475c3d22012-11-30 08:31:30 +0100950 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200951 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100952 err = alc_add_automute_mode_enum(codec);
953 if (err < 0)
954 return err;
955 }
956 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200957}
958
Takashi Iwai1d045db2011-07-07 18:23:21 +0200959/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200960static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
961{
962 int i;
963 for (i = 0; i < nums; i++)
964 if (list[i] == nid)
965 return i;
966 return -1;
967}
968
Takashi Iwai21268962011-07-07 15:01:13 +0200969/* check whether all auto-mic pins are valid; setup indices if OK */
970static bool alc_auto_mic_check_imux(struct hda_codec *codec)
971{
972 struct alc_spec *spec = codec->spec;
973 const struct hda_input_mux *imux;
974
Takashi Iwai27d31532012-12-18 08:57:05 +0100975 imux = &spec->input_mux;
Takashi Iwai21268962011-07-07 15:01:13 +0200976 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
977 spec->imux_pins, imux->num_items);
978 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
979 spec->imux_pins, imux->num_items);
980 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
981 spec->imux_pins, imux->num_items);
Takashi Iwai666a70d2012-12-17 20:29:29 +0100982 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0)
Takashi Iwai21268962011-07-07 15:01:13 +0200983 return false; /* no corresponding imux */
Takashi Iwai21268962011-07-07 15:01:13 +0200984
David Henningsson29adc4b2012-09-25 11:31:00 +0200985 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
986 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200987 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +0200988 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
989 ALC_MIC_EVENT,
990 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +0200991 return true;
992}
993
Takashi Iwai1d045db2011-07-07 18:23:21 +0200994/*
995 * Check the availability of auto-mic switch;
996 * Set up if really supported
997 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100998static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +0200999{
1000 struct alc_spec *spec = codec->spec;
1001 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001002 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001003 int i;
1004
Takashi Iwai21268962011-07-07 15:01:13 +02001005 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1006
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001007 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001008 for (i = 0; i < cfg->num_inputs; i++) {
1009 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001010 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001011 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001012 switch (snd_hda_get_input_pin_attr(defcfg)) {
1013 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001014 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001015 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001016 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001017 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001018 fixed = nid;
1019 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001020 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001021 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001022 case INPUT_PIN_ATTR_DOCK:
1023 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001024 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001025 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001026 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001027 dock = nid;
1028 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001029 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001030 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001031 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001032 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001033 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001034 ext = nid;
1035 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001036 }
1037 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001038 if (!ext && dock) {
1039 ext = dock;
1040 dock = 0;
1041 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001042 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001043 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001044 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001045 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001046 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001047 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001048
1049 /* check imux indices */
1050 spec->ext_mic_pin = ext;
1051 spec->int_mic_pin = fixed;
1052 spec->dock_mic_pin = dock;
1053
Takashi Iwai21268962011-07-07 15:01:13 +02001054 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001055 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001056
Takashi Iwai666a70d2012-12-17 20:29:29 +01001057 spec->auto_mic = 1;
1058 spec->num_adc_nids = 1;
1059 spec->cur_mux[0] = spec->int_mic_idx;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001060 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1061 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001062
1063 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001064}
1065
Takashi Iwai1d045db2011-07-07 18:23:21 +02001066/*
1067 * Realtek SSID verification
1068 */
1069
David Henningsson90622912010-10-14 14:50:18 +02001070/* Could be any non-zero and even value. When used as fixup, tells
1071 * the driver to ignore any present sku defines.
1072 */
1073#define ALC_FIXUP_SKU_IGNORE (2)
1074
Takashi Iwai23d30f22012-05-07 17:17:32 +02001075static void alc_fixup_sku_ignore(struct hda_codec *codec,
1076 const struct hda_fixup *fix, int action)
1077{
1078 struct alc_spec *spec = codec->spec;
1079 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1080 spec->cdefine.fixup = 1;
1081 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1082 }
1083}
1084
Kailang Yangda00c242010-03-19 11:23:45 +01001085static int alc_auto_parse_customize_define(struct hda_codec *codec)
1086{
1087 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001088 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001089 struct alc_spec *spec = codec->spec;
1090
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001091 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1092
David Henningsson90622912010-10-14 14:50:18 +02001093 if (spec->cdefine.fixup) {
1094 ass = spec->cdefine.sku_cfg;
1095 if (ass == ALC_FIXUP_SKU_IGNORE)
1096 return -1;
1097 goto do_sku;
1098 }
1099
Kailang Yangda00c242010-03-19 11:23:45 +01001100 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001101 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001102 goto do_sku;
1103
1104 nid = 0x1d;
1105 if (codec->vendor_id == 0x10ec0260)
1106 nid = 0x17;
1107 ass = snd_hda_codec_get_pincfg(codec, nid);
1108
1109 if (!(ass & 1)) {
1110 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1111 codec->chip_name, ass);
1112 return -1;
1113 }
1114
1115 /* check sum */
1116 tmp = 0;
1117 for (i = 1; i < 16; i++) {
1118 if ((ass >> i) & 1)
1119 tmp++;
1120 }
1121 if (((ass >> 16) & 0xf) != tmp)
1122 return -1;
1123
1124 spec->cdefine.port_connectivity = ass >> 30;
1125 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1126 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1127 spec->cdefine.customization = ass >> 8;
1128do_sku:
1129 spec->cdefine.sku_cfg = ass;
1130 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1131 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1132 spec->cdefine.swap = (ass & 0x2) >> 1;
1133 spec->cdefine.override = ass & 0x1;
1134
1135 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1136 nid, spec->cdefine.sku_cfg);
1137 snd_printd("SKU: port_connectivity=0x%x\n",
1138 spec->cdefine.port_connectivity);
1139 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1140 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1141 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1142 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1143 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1144 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1145 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1146
1147 return 0;
1148}
1149
Takashi Iwai1d045db2011-07-07 18:23:21 +02001150/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001151static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1152{
Takashi Iwai21268962011-07-07 15:01:13 +02001153 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001154}
1155
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001156/* check subsystem ID and set up device-specific initialization;
1157 * return 1 if initialized, 0 if invalid SSID
1158 */
1159/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1160 * 31 ~ 16 : Manufacture ID
1161 * 15 ~ 8 : SKU ID
1162 * 7 ~ 0 : Assembly ID
1163 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1164 */
1165static int alc_subsystem_id(struct hda_codec *codec,
1166 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001167 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001168{
1169 unsigned int ass, tmp, i;
1170 unsigned nid;
1171 struct alc_spec *spec = codec->spec;
1172
David Henningsson90622912010-10-14 14:50:18 +02001173 if (spec->cdefine.fixup) {
1174 ass = spec->cdefine.sku_cfg;
1175 if (ass == ALC_FIXUP_SKU_IGNORE)
1176 return 0;
1177 goto do_sku;
1178 }
1179
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001180 ass = codec->subsystem_id & 0xffff;
1181 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1182 goto do_sku;
1183
1184 /* invalid SSID, check the special NID pin defcfg instead */
1185 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001186 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001187 * 29~21 : reserve
1188 * 20 : PCBEEP input
1189 * 19~16 : Check sum (15:1)
1190 * 15~1 : Custom
1191 * 0 : override
1192 */
1193 nid = 0x1d;
1194 if (codec->vendor_id == 0x10ec0260)
1195 nid = 0x17;
1196 ass = snd_hda_codec_get_pincfg(codec, nid);
1197 snd_printd("realtek: No valid SSID, "
1198 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001199 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001200 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001201 return 0;
1202 if ((ass >> 30) != 1) /* no physical connection */
1203 return 0;
1204
1205 /* check sum */
1206 tmp = 0;
1207 for (i = 1; i < 16; i++) {
1208 if ((ass >> i) & 1)
1209 tmp++;
1210 }
1211 if (((ass >> 16) & 0xf) != tmp)
1212 return 0;
1213do_sku:
1214 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1215 ass & 0xffff, codec->vendor_id);
1216 /*
1217 * 0 : override
1218 * 1 : Swap Jack
1219 * 2 : 0 --> Desktop, 1 --> Laptop
1220 * 3~5 : External Amplifier control
1221 * 7~6 : Reserved
1222 */
1223 tmp = (ass & 0x38) >> 3; /* external Amp control */
1224 switch (tmp) {
1225 case 1:
1226 spec->init_amp = ALC_INIT_GPIO1;
1227 break;
1228 case 3:
1229 spec->init_amp = ALC_INIT_GPIO2;
1230 break;
1231 case 7:
1232 spec->init_amp = ALC_INIT_GPIO3;
1233 break;
1234 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001235 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001236 spec->init_amp = ALC_INIT_DEFAULT;
1237 break;
1238 }
1239
1240 /* is laptop or Desktop and enable the function "Mute internal speaker
1241 * when the external headphone out jack is plugged"
1242 */
1243 if (!(ass & 0x8000))
1244 return 1;
1245 /*
1246 * 10~8 : Jack location
1247 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1248 * 14~13: Resvered
1249 * 15 : 1 --> enable the function "Mute internal speaker
1250 * when the external headphone out jack is plugged"
1251 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001252 if (!spec->autocfg.hp_pins[0] &&
1253 !(spec->autocfg.line_out_pins[0] &&
1254 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001255 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001256 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1257 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001258 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001259 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001260 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001261 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001262 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001263 else if (tmp == 3)
1264 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001265 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001266 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001267 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1268 spec->autocfg.line_outs))
1269 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001270 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001271 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001272 return 1;
1273}
Kailang Yangea1fb292008-08-26 12:58:38 +02001274
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001275/* Check the validity of ALC subsystem-id
1276 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1277static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001278{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001279 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001280 struct alc_spec *spec = codec->spec;
1281 snd_printd("realtek: "
1282 "Enable default setup for auto mode as fallback\n");
1283 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001284 }
Takashi Iwai21268962011-07-07 15:01:13 +02001285}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001286
Takashi Iwai41e41f12005-06-08 14:48:49 +02001287/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001288 * COEF access helper functions
1289 */
Kailang Yang274693f2009-12-03 10:07:50 +01001290static int alc_read_coef_idx(struct hda_codec *codec,
1291 unsigned int coef_idx)
1292{
1293 unsigned int val;
1294 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1295 coef_idx);
1296 val = snd_hda_codec_read(codec, 0x20, 0,
1297 AC_VERB_GET_PROC_COEF, 0);
1298 return val;
1299}
1300
Kailang Yang977ddd62010-09-15 10:02:29 +02001301static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1302 unsigned int coef_val)
1303{
1304 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1305 coef_idx);
1306 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1307 coef_val);
1308}
1309
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001310/* a special bypass for COEF 0; read the cached value at the second time */
1311static unsigned int alc_get_coef0(struct hda_codec *codec)
1312{
1313 struct alc_spec *spec = codec->spec;
1314 if (!spec->coef0)
1315 spec->coef0 = alc_read_coef_idx(codec, 0);
1316 return spec->coef0;
1317}
1318
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001319static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1320 hda_nid_t pin, int pin_type,
1321 hda_nid_t dac);
1322static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1323 bool is_digital);
Takashi Iwai965cceb2012-12-18 11:46:37 +01001324static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
1325 hda_nid_t to_nid, int with_aa_mix,
1326 struct nid_path *path);
1327static struct nid_path *add_new_nid_path(struct hda_codec *codec,
1328 hda_nid_t from_nid, hda_nid_t to_nid,
1329 int with_aa_mix);
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001330
Takashi Iwai1d045db2011-07-07 18:23:21 +02001331/*
1332 * Digital I/O handling
1333 */
1334
Takashi Iwai757899a2010-07-30 10:48:14 +02001335/* set right pin controls for digital I/O */
1336static void alc_auto_init_digital(struct hda_codec *codec)
1337{
1338 struct alc_spec *spec = codec->spec;
1339 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001340 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001341
1342 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1343 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001344 if (!pin)
1345 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001346 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001347 }
1348 pin = spec->autocfg.dig_in_pin;
1349 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001350 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001351}
1352
1353/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1354static void alc_auto_parse_digital(struct hda_codec *codec)
1355{
1356 struct alc_spec *spec = codec->spec;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001357 int i, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001358 hda_nid_t dig_nid;
1359
1360 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001361 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001362 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001363 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1364 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1365 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001366 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01001367 if (!add_new_nid_path(codec, dig_nid, pin, 2))
1368 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001369 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001370 spec->multiout.dig_out_nid = dig_nid;
1371 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1372 } else {
1373 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001374 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001375 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001376 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001377 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001378 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001379 }
1380
1381 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001382 dig_nid = codec->start_nid;
1383 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001384 struct nid_path *path;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001385 unsigned int wcaps = get_wcaps(codec, dig_nid);
1386 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1387 continue;
1388 if (!(wcaps & AC_WCAP_DIGITAL))
1389 continue;
Takashi Iwaidf1d1fb2012-12-18 11:55:53 +01001390 path = add_new_nid_path(codec, spec->autocfg.dig_in_pin,
1391 dig_nid, 2);
1392 if (path) {
1393 path->active = true;
Takashi Iwai01fdf182010-09-24 09:09:42 +02001394 spec->dig_in_nid = dig_nid;
1395 break;
1396 }
1397 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001398 }
1399}
1400
Takashi Iwaif95474e2007-07-10 00:47:43 +02001401/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001402 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001403 */
Takashi Iwai666a70d2012-12-17 20:29:29 +01001404#define alc_cap_vol_info snd_hda_mixer_amp_volume_info
1405#define alc_cap_vol_get snd_hda_mixer_amp_volume_get
1406#define alc_cap_vol_tlv snd_hda_mixer_amp_tlv
1407
1408typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
1409 struct snd_ctl_elem_value *ucontrol);
1410
1411static int alc_cap_put_caller(struct snd_kcontrol *kcontrol,
1412 struct snd_ctl_elem_value *ucontrol,
1413 put_call_t func, int type)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001414{
1415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1416 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001417 const struct hda_input_mux *imux;
1418 struct nid_path *path;
1419 int i, adc_idx, err = 0;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001420
Takashi Iwai27d31532012-12-18 08:57:05 +01001421 imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001422 adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001423 mutex_lock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001424 codec->cached_write = 1;
1425 for (i = 0; i < imux->num_items; i++) {
1426 path = get_nid_path(codec, spec->imux_pins[i],
1427 get_adc_nid(codec, adc_idx, i));
1428 if (!path->ctls[type])
1429 continue;
1430 kcontrol->private_value = path->ctls[type];
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001431 err = func(kcontrol, ucontrol);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001432 if (err < 0)
1433 goto error;
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001434 }
1435 error:
Takashi Iwai666a70d2012-12-17 20:29:29 +01001436 codec->cached_write = 0;
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001437 mutex_unlock(&codec->control_mutex);
Takashi Iwai666a70d2012-12-17 20:29:29 +01001438 snd_hda_codec_resume_amp(codec);
1439 if (err >= 0 && type == NID_PATH_MUTE_CTL &&
1440 spec->inv_dmic_fixup && spec->inv_dmic_muted)
1441 alc_inv_dmic_sync_adc(codec, adc_idx);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001442 return err;
1443}
1444
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001445static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1446 struct snd_ctl_elem_value *ucontrol)
1447{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001448 return alc_cap_put_caller(kcontrol, ucontrol,
1449 snd_hda_mixer_amp_volume_put,
1450 NID_PATH_VOL_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001451}
1452
1453/* capture mixer elements */
1454#define alc_cap_sw_info snd_ctl_boolean_stereo_info
Takashi Iwai666a70d2012-12-17 20:29:29 +01001455#define alc_cap_sw_get snd_hda_mixer_amp_switch_get
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001456
1457static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1458 struct snd_ctl_elem_value *ucontrol)
1459{
Takashi Iwai666a70d2012-12-17 20:29:29 +01001460 return alc_cap_put_caller(kcontrol, ucontrol,
1461 snd_hda_mixer_amp_switch_put,
1462 NID_PATH_MUTE_CTL);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001463}
1464
Takashi Iwai666a70d2012-12-17 20:29:29 +01001465static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1466{
1467 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01001468 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001469 struct nid_path *path;
1470 hda_nid_t nid;
1471 int i, dir, parm;
1472 unsigned int val;
1473
1474 for (i = 0; i < imux->num_items; i++) {
1475 if (spec->imux_pins[i] == spec->inv_dmic_pin)
1476 break;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001477 }
Takashi Iwai666a70d2012-12-17 20:29:29 +01001478 if (i >= imux->num_items)
1479 return;
Takashi Iwaia23b6882009-03-23 15:21:36 +01001480
Takashi Iwai666a70d2012-12-17 20:29:29 +01001481 path = get_nid_path(codec, spec->inv_dmic_pin,
1482 get_adc_nid(codec, adc_idx, i));
1483 val = path->ctls[NID_PATH_MUTE_CTL];
1484 if (!val)
1485 return;
1486 nid = get_amp_nid_(val);
1487 dir = get_amp_direction_(val);
1488 parm = AC_AMP_SET_RIGHT |
1489 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001490
Takashi Iwai666a70d2012-12-17 20:29:29 +01001491 /* we care only right channel */
1492 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1493 if (val & 0x80) /* if already muted, we don't need to touch */
1494 return;
1495 val |= 0x80;
1496 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1497 parm | val);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001498}
1499
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001500/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001501 * Inverted digital-mic handling
1502 *
1503 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1504 * gives the additional mute only to the right channel of the digital mic
1505 * capture stream. This is a workaround for avoiding the almost silence
1506 * by summing the stereo stream from some (known to be ForteMedia)
1507 * digital mic unit.
1508 *
1509 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1510 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1511 * without caching so that the cache can still keep the original value.
1512 * The cached value is then restored when the flag is set off or any other
1513 * than d-mic is used as the current input source.
1514 */
1515static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1516{
1517 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001518 int src, nums;
Takashi Iwai125821a2012-06-22 14:30:29 +02001519
1520 if (!spec->inv_dmic_fixup)
1521 return;
1522 if (!spec->inv_dmic_muted && !force)
1523 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001524 nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids;
1525 for (src = 0; src < nums; src++) {
Takashi Iwai125821a2012-06-22 14:30:29 +02001526 bool dmic_fixup = false;
Takashi Iwai125821a2012-06-22 14:30:29 +02001527
1528 if (spec->inv_dmic_muted &&
1529 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1530 dmic_fixup = true;
1531 if (!dmic_fixup && !force)
1532 continue;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001533 alc_inv_dmic_sync_adc(codec, src);
Takashi Iwai125821a2012-06-22 14:30:29 +02001534 }
1535}
1536
1537static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1538 struct snd_ctl_elem_value *ucontrol)
1539{
1540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1541 struct alc_spec *spec = codec->spec;
1542
1543 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1544 return 0;
1545}
1546
1547static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1548 struct snd_ctl_elem_value *ucontrol)
1549{
1550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1551 struct alc_spec *spec = codec->spec;
1552 unsigned int val = !ucontrol->value.integer.value[0];
1553
1554 if (val == spec->inv_dmic_muted)
1555 return 0;
1556 spec->inv_dmic_muted = val;
1557 alc_inv_dmic_sync(codec, true);
1558 return 0;
1559}
1560
1561static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1562 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwaibc549762012-12-18 15:35:11 +01001563 .name = "Inverted Internal Mic Capture Switch",
Takashi Iwai125821a2012-06-22 14:30:29 +02001564 .info = snd_ctl_boolean_mono_info,
1565 .get = alc_inv_dmic_sw_get,
1566 .put = alc_inv_dmic_sw_put,
1567};
1568
1569static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1570{
1571 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001572
Takashi Iwaibc549762012-12-18 15:35:11 +01001573 if (!alc_kcontrol_new(spec, NULL, &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001574 return -ENOMEM;
1575 spec->inv_dmic_fixup = 1;
1576 spec->inv_dmic_muted = 0;
1577 spec->inv_dmic_pin = nid;
1578 return 0;
1579}
1580
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001581/* typically the digital mic is put at node 0x12 */
1582static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1583 const struct alc_fixup *fix, int action)
1584{
1585 if (action == ALC_FIXUP_ACT_PROBE)
1586 alc_add_inv_dmic_mixer(codec, 0x12);
1587}
1588
Takashi Iwai125821a2012-06-22 14:30:29 +02001589/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001590 * virtual master controls
1591 */
1592
1593/*
1594 * slave controls for virtual master
1595 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001596static const char * const alc_slave_pfxs[] = {
1597 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001598 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001599 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001600 NULL,
1601};
1602
1603/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001604 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001606
1607static void alc_free_kctls(struct hda_codec *codec);
1608
Takashi Iwai67d634c2009-11-16 15:35:59 +01001609#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001610/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001611static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001612 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001613 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001614 { } /* end */
1615};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001616#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001617
Takashi Iwai2eab6942012-12-18 15:30:41 +01001618static int alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
1620 struct alc_spec *spec = codec->spec;
Takashi Iwai666a70d2012-12-17 20:29:29 +01001621 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623 for (i = 0; i < spec->num_mixers; i++) {
1624 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1625 if (err < 0)
1626 return err;
1627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001629 err = snd_hda_create_dig_out_ctls(codec,
1630 spec->multiout.dig_out_nid,
1631 spec->multiout.dig_out_nid,
1632 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 if (err < 0)
1634 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001635 if (!spec->no_analog) {
1636 err = snd_hda_create_spdif_share_sw(codec,
1637 &spec->multiout);
1638 if (err < 0)
1639 return err;
1640 spec->multiout.share_spdif = 1;
1641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 }
1643 if (spec->dig_in_nid) {
1644 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1645 if (err < 0)
1646 return err;
1647 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001648
Takashi Iwai67d634c2009-11-16 15:35:59 +01001649#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001650 /* create beep controls if needed */
1651 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001652 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001653 for (knew = alc_beep_mixer; knew->name; knew++) {
1654 struct snd_kcontrol *kctl;
1655 kctl = snd_ctl_new1(knew, codec);
1656 if (!kctl)
1657 return -ENOMEM;
1658 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001659 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001660 if (err < 0)
1661 return err;
1662 }
1663 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001664#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001665
Takashi Iwai2134ea42008-01-10 16:53:55 +01001666 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001667 if (!spec->no_analog &&
1668 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001669 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001670 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001671 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001672 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001673 vmaster_tlv, alc_slave_pfxs,
1674 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001675 if (err < 0)
1676 return err;
1677 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001678 if (!spec->no_analog &&
1679 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001680 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1681 NULL, alc_slave_pfxs,
1682 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001683 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001684 if (err < 0)
1685 return err;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001686 if (spec->vmaster_mute.hook)
1687 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001688 }
1689
Takashi Iwaibae84e72010-03-22 08:30:20 +01001690 alc_free_kctls(codec); /* no longer needed */
1691
David Henningsson5780b622012-06-27 18:45:45 +02001692 if (spec->shared_mic_hp) {
1693 int err;
1694 int nid = spec->autocfg.inputs[1].pin;
1695 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1696 if (err < 0)
1697 return err;
1698 err = snd_hda_jack_detect_enable(codec, nid, 0);
1699 if (err < 0)
1700 return err;
1701 }
1702
Takashi Iwai2eab6942012-12-18 15:30:41 +01001703 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001704 if (err < 0)
1705 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001706
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001707 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1708 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709}
1710
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001713 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001714 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001715
Takashi Iwai070cff42012-02-21 12:54:17 +01001716static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718static int alc_init(struct hda_codec *codec)
1719{
1720 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001721
Takashi Iwai546bb672012-03-07 08:37:19 +01001722 if (spec->init_hook)
1723 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001724
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001725 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001726 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001727
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02001728 snd_hda_gen_apply_verbs(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001729 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001730
Takashi Iwai3bd7b642012-12-18 14:57:09 +01001731 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
1732 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
1733
Takashi Iwai58701122011-01-13 15:41:45 +01001734 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1735
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001736 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 return 0;
1738}
1739
Takashi Iwai83012a72012-08-24 18:38:08 +02001740#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001741static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1742{
1743 struct alc_spec *spec = codec->spec;
1744 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1745}
1746#endif
1747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748/*
1749 * Analog playback callbacks
1750 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001751static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001753 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{
1755 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001756 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1757 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758}
1759
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001760static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 struct hda_codec *codec,
1762 unsigned int stream_tag,
1763 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001764 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765{
1766 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001767 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1768 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769}
1770
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001771static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001773 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 struct alc_spec *spec = codec->spec;
1776 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1777}
1778
1779/*
1780 * Digital out
1781 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001782static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001784 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785{
1786 struct alc_spec *spec = codec->spec;
1787 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1788}
1789
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001790static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001791 struct hda_codec *codec,
1792 unsigned int stream_tag,
1793 unsigned int format,
1794 struct snd_pcm_substream *substream)
1795{
1796 struct alc_spec *spec = codec->spec;
1797 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1798 stream_tag, format, substream);
1799}
1800
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001801static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001802 struct hda_codec *codec,
1803 struct snd_pcm_substream *substream)
1804{
1805 struct alc_spec *spec = codec->spec;
1806 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1807}
1808
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001809static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001811 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812{
1813 struct alc_spec *spec = codec->spec;
1814 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1815}
1816
1817/*
1818 * Analog capture
1819 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001820static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 struct hda_codec *codec,
1822 unsigned int stream_tag,
1823 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001824 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
1826 struct alc_spec *spec = codec->spec;
1827
Takashi Iwai63300792008-01-24 15:31:36 +01001828 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 stream_tag, 0, format);
1830 return 0;
1831}
1832
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001833static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001835 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836{
1837 struct alc_spec *spec = codec->spec;
1838
Takashi Iwai888afa12008-03-18 09:57:50 +01001839 snd_hda_codec_cleanup_stream(codec,
1840 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 return 0;
1842}
1843
Takashi Iwai840b64c2010-07-13 22:49:01 +02001844/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02001845static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001846 struct hda_codec *codec,
1847 unsigned int stream_tag,
1848 unsigned int format,
1849 struct snd_pcm_substream *substream)
1850{
1851 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001852 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02001853 spec->cur_adc_stream_tag = stream_tag;
1854 spec->cur_adc_format = format;
1855 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1856 return 0;
1857}
1858
Takashi Iwai21268962011-07-07 15:01:13 +02001859static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02001860 struct hda_codec *codec,
1861 struct snd_pcm_substream *substream)
1862{
1863 struct alc_spec *spec = codec->spec;
1864 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1865 spec->cur_adc = 0;
1866 return 0;
1867}
1868
Takashi Iwai21268962011-07-07 15:01:13 +02001869static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02001870 .substreams = 1,
1871 .channels_min = 2,
1872 .channels_max = 2,
1873 .nid = 0, /* fill later */
1874 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02001875 .prepare = dyn_adc_capture_pcm_prepare,
1876 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02001877 },
1878};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
1880/*
1881 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001882static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 .substreams = 1,
1884 .channels_min = 2,
1885 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001886 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001888 .open = alc_playback_pcm_open,
1889 .prepare = alc_playback_pcm_prepare,
1890 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 },
1892};
1893
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001894static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001895 .substreams = 1,
1896 .channels_min = 2,
1897 .channels_max = 2,
1898 /* NID is set in alc_build_pcms */
1899};
1900
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001901static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01001902 .substreams = 1,
1903 .channels_min = 2,
1904 .channels_max = 2,
1905 /* NID is set in alc_build_pcms */
1906};
1907
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001908static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01001909 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 .channels_min = 2,
1911 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001912 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001914 .prepare = alc_alt_capture_pcm_prepare,
1915 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 },
1917};
1918
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001919static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 .substreams = 1,
1921 .channels_min = 2,
1922 .channels_max = 2,
1923 /* NID is set in alc_build_pcms */
1924 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001925 .open = alc_dig_playback_pcm_open,
1926 .close = alc_dig_playback_pcm_close,
1927 .prepare = alc_dig_playback_pcm_prepare,
1928 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 },
1930};
1931
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001932static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 .substreams = 1,
1934 .channels_min = 2,
1935 .channels_max = 2,
1936 /* NID is set in alc_build_pcms */
1937};
1938
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001939/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02001940static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01001941 .substreams = 0,
1942 .channels_min = 0,
1943 .channels_max = 0,
1944};
1945
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946static int alc_build_pcms(struct hda_codec *codec)
1947{
1948 struct alc_spec *spec = codec->spec;
1949 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001950 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01001951 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 int i;
1953
1954 codec->num_pcms = 1;
1955 codec->pcm_info = info;
1956
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001957 if (spec->no_analog)
1958 goto skip_analog;
1959
Takashi Iwai812a2cc2009-05-16 10:00:49 +02001960 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1961 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01001963
Takashi Iwaieedec3d2012-02-06 10:24:04 +01001964 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001965 p = spec->stream_analog_playback;
1966 if (!p)
1967 p = &alc_pcm_analog_playback;
1968 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001969 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02001970 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1971 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01001972 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
1973 spec->autocfg.line_outs == 2)
1974 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1975 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001976 }
Takashi Iwai27d31532012-12-18 08:57:05 +01001977 if (spec->num_adc_nids) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001978 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02001979 if (!p) {
1980 if (spec->dyn_adc_switch)
1981 p = &dyn_adc_pcm_analog_capture;
1982 else
1983 p = &alc_pcm_analog_capture;
1984 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001985 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01001986 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Takashi Iwai4a471b72005-12-07 13:56:29 +01001989 if (spec->channel_mode) {
1990 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
1991 for (i = 0; i < spec->num_channel_mode; i++) {
1992 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
1993 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
1994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 }
1996 }
1997
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001998 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02001999 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002001 snprintf(spec->stream_name_digital,
2002 sizeof(spec->stream_name_digital),
2003 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002004 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002005 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002006 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002008 if (spec->dig_out_type)
2009 info->pcm_type = spec->dig_out_type;
2010 else
2011 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002012 if (spec->multiout.dig_out_nid) {
2013 p = spec->stream_digital_playback;
2014 if (!p)
2015 p = &alc_pcm_digital_playback;
2016 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2018 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002019 if (spec->dig_in_nid) {
2020 p = spec->stream_digital_capture;
2021 if (!p)
2022 p = &alc_pcm_digital_capture;
2023 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2025 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002026 /* FIXME: do we need this for all Realtek codec models? */
2027 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 }
2029
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002030 if (spec->no_analog)
2031 return 0;
2032
Takashi Iwaie08a0072006-09-07 17:52:14 +02002033 /* If the use of more than one ADC is requested for the current
2034 * model, configure a second analog capture-only PCM.
2035 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002036 have_multi_adcs = (spec->num_adc_nids > 1) &&
Takashi Iwai27d31532012-12-18 08:57:05 +01002037 !spec->dyn_adc_switch && !spec->auto_mic;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002038 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002039 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002040 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002041 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002042 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002043 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002044 p = spec->stream_analog_alt_playback;
2045 if (!p)
2046 p = &alc_pcm_analog_alt_playback;
2047 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002048 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2049 spec->alt_dac_nid;
2050 } else {
2051 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2052 alc_pcm_null_stream;
2053 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2054 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002055 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002056 p = spec->stream_analog_alt_capture;
2057 if (!p)
2058 p = &alc_pcm_analog_alt_capture;
2059 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002060 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2061 spec->adc_nids[1];
2062 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2063 spec->num_adc_nids - 1;
2064 } else {
2065 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2066 alc_pcm_null_stream;
2067 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002068 }
2069 }
2070
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 return 0;
2072}
2073
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002074static inline void alc_shutup(struct hda_codec *codec)
2075{
Takashi Iwai1c716152011-04-07 10:37:16 +02002076 struct alc_spec *spec = codec->spec;
2077
2078 if (spec && spec->shutup)
2079 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002080 snd_hda_shutup_pins(codec);
2081}
2082
Takashi Iwai603c4012008-07-30 15:01:44 +02002083static void alc_free_kctls(struct hda_codec *codec)
2084{
2085 struct alc_spec *spec = codec->spec;
2086
2087 if (spec->kctls.list) {
2088 struct snd_kcontrol_new *kctl = spec->kctls.list;
2089 int i;
2090 for (i = 0; i < spec->kctls.used; i++)
2091 kfree(kctl[i].name);
2092 }
2093 snd_array_free(&spec->kctls);
2094}
2095
Takashi Iwai23c09b02011-08-19 09:05:35 +02002096static void alc_free_bind_ctls(struct hda_codec *codec)
2097{
2098 struct alc_spec *spec = codec->spec;
2099 if (spec->bind_ctls.list) {
2100 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2101 int i;
2102 for (i = 0; i < spec->bind_ctls.used; i++)
2103 kfree(ctl[i]);
2104 }
2105 snd_array_free(&spec->bind_ctls);
2106}
2107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108static void alc_free(struct hda_codec *codec)
2109{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002110 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002111
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002112 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002113 return;
2114
Takashi Iwai603c4012008-07-30 15:01:44 +02002115 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002116 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002117 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002118 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002119 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002120 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121}
2122
Takashi Iwai83012a72012-08-24 18:38:08 +02002123#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002124static void alc_power_eapd(struct hda_codec *codec)
2125{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002126 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002127}
2128
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002129static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002130{
2131 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002132 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002133 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002134 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002135 return 0;
2136}
2137#endif
2138
Takashi Iwai2a439522011-07-26 09:52:50 +02002139#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002140static int alc_resume(struct hda_codec *codec)
2141{
Takashi Iwai1c716152011-04-07 10:37:16 +02002142 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002143 codec->patch_ops.init(codec);
2144 snd_hda_codec_resume_amp(codec);
2145 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002146 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002147 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002148 return 0;
2149}
Takashi Iwaie044c392008-10-27 16:56:24 +01002150#endif
2151
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152/*
2153 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002154static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 .build_controls = alc_build_controls,
2156 .build_pcms = alc_build_pcms,
2157 .init = alc_init,
2158 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002159 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002160#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002161 .resume = alc_resume,
2162#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002163#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002164 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002165 .check_power_status = alc_check_power_status,
2166#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002167 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168};
2169
David Henningsson29adc4b2012-09-25 11:31:00 +02002170
Kailang Yangc027ddc2010-03-19 11:33:06 +01002171/* replace the codec chip_name with the given string */
2172static int alc_codec_rename(struct hda_codec *codec, const char *name)
2173{
2174 kfree(codec->chip_name);
2175 codec->chip_name = kstrdup(name, GFP_KERNEL);
2176 if (!codec->chip_name) {
2177 alc_free(codec);
2178 return -ENOMEM;
2179 }
2180 return 0;
2181}
2182
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002183/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002184 * Rename codecs appropriately from COEF value
2185 */
2186struct alc_codec_rename_table {
2187 unsigned int vendor_id;
2188 unsigned short coef_mask;
2189 unsigned short coef_bits;
2190 const char *name;
2191};
2192
2193static struct alc_codec_rename_table rename_tbl[] = {
2194 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2195 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2196 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2197 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2198 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2199 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2200 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002201 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002202 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2203 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2204 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2205 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2206 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2207 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2208 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2209 { } /* terminator */
2210};
2211
2212static int alc_codec_rename_from_preset(struct hda_codec *codec)
2213{
2214 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002215
2216 for (p = rename_tbl; p->vendor_id; p++) {
2217 if (p->vendor_id != codec->vendor_id)
2218 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002219 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002220 return alc_codec_rename(codec, p->name);
2221 }
2222 return 0;
2223}
2224
2225/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002226 * Automatic parse of I/O pins from the BIOS configuration
2227 */
2228
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002229enum {
2230 ALC_CTL_WIDGET_VOL,
2231 ALC_CTL_WIDGET_MUTE,
2232 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002233 ALC_CTL_BIND_VOL,
2234 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002235};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002236static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002237 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2238 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002239 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002240 HDA_BIND_VOL(NULL, 0),
2241 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002242};
2243
2244/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002245static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002246 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002247{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002248 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002249
Takashi Iwai668d1e92012-11-29 14:10:17 +01002250 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002251 if (!knew)
2252 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002253 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002254 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002255 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002256 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002257 return 0;
2258}
2259
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002260static int add_control_with_pfx(struct alc_spec *spec, int type,
2261 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002262 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002263{
2264 char name[32];
2265 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002266 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002267}
2268
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002269#define add_pb_vol_ctrl(spec, type, pfx, val) \
2270 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2271#define add_pb_sw_ctrl(spec, type, pfx, val) \
2272 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2273#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2274 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2275#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2276 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002277
Takashi Iwai23c09b02011-08-19 09:05:35 +02002278static const char * const channel_name[4] = {
2279 "Front", "Surround", "CLFE", "Side"
2280};
2281
Takashi Iwai6843ca12011-06-24 11:03:58 +02002282static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2283 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002284{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002285 struct auto_pin_cfg *cfg = &spec->autocfg;
2286
Takashi Iwai6843ca12011-06-24 11:03:58 +02002287 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002288 if (cfg->line_outs == 1 && !spec->multi_ios &&
2289 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwai52a8efa2012-12-18 17:33:04 +01002290 return spec->vmaster_mute.hook ? "PCM" : "Master";
2291
2292 /* if there is really a single DAC used in the whole output paths,
2293 * use it master (or "PCM" if a vmaster hook is present)
2294 */
2295 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
2296 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
2297 return spec->vmaster_mute.hook ? "PCM" : "Master";
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002298
2299 switch (cfg->line_out_type) {
2300 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002301 if (cfg->line_outs == 1)
2302 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002303 if (cfg->line_outs == 2)
2304 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002305 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002306 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002307 /* for multi-io case, only the primary out */
2308 if (ch && spec->multi_ios)
2309 break;
2310 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002311 return "Headphone";
2312 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002313 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002314 return "PCM";
2315 break;
2316 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002317 if (ch >= ARRAY_SIZE(channel_name)) {
2318 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002319 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002320 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002321
2322 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002323}
2324
Takashi Iwai83012a72012-08-24 18:38:08 +02002325#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002326/* add the powersave loopback-list entry */
2327static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2328{
2329 struct hda_amp_list *list;
2330
2331 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2332 return;
2333 list = spec->loopback_list + spec->num_loopbacks;
2334 list->nid = mix;
2335 list->dir = HDA_INPUT;
2336 list->idx = idx;
2337 spec->num_loopbacks++;
2338 spec->loopback.amplist = spec->loopback_list;
2339}
2340#else
2341#define add_loopback_list(spec, mix, idx) /* NOP */
2342#endif
2343
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002344/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002345static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002346 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002347 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002348{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002349 struct alc_spec *spec = codec->spec;
2350 struct nid_path *path;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002351 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002352 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002353
Takashi Iwaibd32f782012-12-12 18:08:52 +01002354 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2355 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2356 return 0; /* no need for analog loopback */
2357
Takashi Iwai965cceb2012-12-18 11:46:37 +01002358 path = add_new_nid_path(codec, pin, mix_nid, 2);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002359 if (!path)
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002360 return -EINVAL;
2361
2362 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002363 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002364 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2365 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002366 if (err < 0)
2367 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002368 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002369 }
2370
2371 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002372 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2373 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002374 if (err < 0)
2375 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002376 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002377 }
2378
Takashi Iwai829f69e2012-12-14 18:26:02 +01002379 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002380 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002381 return 0;
2382}
2383
Takashi Iwai05f5f472009-08-25 13:10:18 +02002384static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002385{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002386 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2387 return (pincap & AC_PINCAP_IN) != 0;
2388}
2389
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002390/* check whether the given two widgets can be connected */
2391static bool is_reachable_path(struct hda_codec *codec,
2392 hda_nid_t from_nid, hda_nid_t to_nid)
2393{
2394 if (!from_nid || !to_nid)
2395 return false;
2396 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2397}
2398
Takashi Iwai666a70d2012-12-17 20:29:29 +01002399/* Parse the codec tree and retrieve ADCs */
2400static int alc_auto_fill_adc_nids(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002401{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002402 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002403 hda_nid_t nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002404 hda_nid_t *adc_nids = spec->adc_nids;
2405 int max_nums = ARRAY_SIZE(spec->adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002406 int i, nums = 0;
2407
2408 nid = codec->start_nid;
2409 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwaib7821702011-07-06 15:12:46 +02002410 unsigned int caps = get_wcaps(codec, nid);
2411 int type = get_wcaps_type(caps);
2412
2413 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2414 continue;
2415 adc_nids[nums] = nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002416 if (++nums >= max_nums)
2417 break;
2418 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002419 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002420 return nums;
2421}
2422
Takashi Iwai666a70d2012-12-17 20:29:29 +01002423/* filter out invalid adc_nids that don't give all active input pins;
2424 * if needed, check whether dynamic ADC-switching is available
2425 */
2426static int check_dyn_adc_switch(struct hda_codec *codec)
2427{
2428 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002429 struct hda_input_mux *imux = &spec->input_mux;
2430 hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)];
Takashi Iwai666a70d2012-12-17 20:29:29 +01002431 int i, n, nums;
2432 hda_nid_t pin, adc;
2433
2434 again:
2435 nums = 0;
2436 for (n = 0; n < spec->num_adc_nids; n++) {
2437 adc = spec->adc_nids[n];
2438 for (i = 0; i < imux->num_items; i++) {
2439 pin = spec->imux_pins[i];
2440 if (!is_reachable_path(codec, pin, adc))
2441 break;
2442 }
2443 if (i >= imux->num_items)
2444 adc_nids[nums++] = adc;
2445 }
2446
2447 if (!nums) {
2448 if (spec->shared_mic_hp) {
2449 spec->shared_mic_hp = 0;
Takashi Iwai27d31532012-12-18 08:57:05 +01002450 imux->num_items = 1;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002451 goto again;
2452 }
2453
2454 /* check whether ADC-switch is possible */
2455 for (i = 0; i < imux->num_items; i++) {
2456 pin = spec->imux_pins[i];
2457 for (n = 0; n < spec->num_adc_nids; n++) {
2458 adc = spec->adc_nids[n];
2459 if (is_reachable_path(codec, pin, adc)) {
2460 spec->dyn_adc_idx[i] = n;
2461 break;
2462 }
2463 }
2464 }
2465
2466 snd_printdd("realtek: enabling ADC switching\n");
2467 spec->dyn_adc_switch = 1;
2468 } else if (nums != spec->num_adc_nids) {
Takashi Iwai27d31532012-12-18 08:57:05 +01002469 memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t));
Takashi Iwai666a70d2012-12-17 20:29:29 +01002470 spec->num_adc_nids = nums;
2471 }
2472
Takashi Iwai27d31532012-12-18 08:57:05 +01002473 if (imux->num_items == 1 || spec->shared_mic_hp) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002474 snd_printdd("realtek: reducing to a single ADC\n");
2475 spec->num_adc_nids = 1; /* reduce to a single ADC */
2476 }
2477
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002478 /* single index for individual volumes ctls */
2479 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
2480 spec->num_adc_nids = 1;
2481
Takashi Iwai666a70d2012-12-17 20:29:29 +01002482 return 0;
2483}
2484
2485/* templates for capture controls */
2486static const struct snd_kcontrol_new cap_src_temp = {
2487 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2488 .name = "Input Source",
2489 .info = alc_mux_enum_info,
2490 .get = alc_mux_enum_get,
2491 .put = alc_mux_enum_put,
2492};
2493
2494static const struct snd_kcontrol_new cap_vol_temp = {
2495 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2496 .name = "Capture Volume",
2497 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2498 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2499 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2500 .info = alc_cap_vol_info,
2501 .get = alc_cap_vol_get,
2502 .put = alc_cap_vol_put,
2503 .tlv = { .c = alc_cap_vol_tlv },
2504};
2505
2506static const struct snd_kcontrol_new cap_sw_temp = {
2507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2508 .name = "Capture Switch",
2509 .info = alc_cap_sw_info,
2510 .get = alc_cap_sw_get,
2511 .put = alc_cap_sw_put,
2512};
2513
2514static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2515{
2516 hda_nid_t nid;
2517 int i, depth;
2518
2519 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2520 for (depth = 0; depth < 3; depth++) {
2521 if (depth >= path->depth)
2522 return -EINVAL;
2523 i = path->depth - depth - 1;
2524 nid = path->path[i];
2525 if (!path->ctls[NID_PATH_VOL_CTL]) {
2526 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2527 path->ctls[NID_PATH_VOL_CTL] =
2528 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2529 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2530 int idx = path->idx[i];
2531 if (!depth && codec->single_adc_amp)
2532 idx = 0;
2533 path->ctls[NID_PATH_VOL_CTL] =
2534 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2535 }
2536 }
2537 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2538 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2539 path->ctls[NID_PATH_MUTE_CTL] =
2540 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2541 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2542 int idx = path->idx[i];
2543 if (!depth && codec->single_adc_amp)
2544 idx = 0;
2545 path->ctls[NID_PATH_MUTE_CTL] =
2546 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2547 }
2548 }
2549 }
2550 return 0;
2551}
2552
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002553static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
2554 int idx, bool is_switch, unsigned int ctl)
2555{
2556 struct alc_spec *spec = codec->spec;
2557 char tmpname[44];
2558 int type = is_switch ? ALC_CTL_WIDGET_MUTE : ALC_CTL_WIDGET_VOL;
2559 const char *sfx = is_switch ? "Switch" : "Volume";
2560
2561 if (!ctl)
2562 return 0;
2563
2564 if (label)
2565 snprintf(tmpname, sizeof(tmpname),
2566 "%s Capture %s", label, sfx);
2567 else
2568 snprintf(tmpname, sizeof(tmpname),
2569 "Capture %s", sfx);
2570 return add_control(spec, type, tmpname, idx, ctl);
2571}
2572
2573/* create single (and simple) capture volume and switch controls */
2574static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
2575 unsigned int vol_ctl, unsigned int sw_ctl)
2576{
2577 int err;
2578 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl);
2579 if (err < 0)
2580 return err;
2581 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl);
2582 if (err < 0)
2583 return err;
2584 return 0;
2585}
2586
2587/* create bound capture volume and switch controls */
2588static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
2589 unsigned int vol_ctl, unsigned int sw_ctl)
2590{
2591 struct alc_spec *spec = codec->spec;
2592 struct snd_kcontrol_new *knew;
2593
2594 if (vol_ctl) {
2595 knew = alc_kcontrol_new(spec, NULL, &cap_vol_temp);
2596 if (!knew)
2597 return -ENOMEM;
2598 knew->index = idx;
2599 knew->private_value = vol_ctl;
2600 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2601 }
2602 if (sw_ctl) {
2603 knew = alc_kcontrol_new(spec, NULL, &cap_sw_temp);
2604 if (!knew)
2605 return -ENOMEM;
2606 knew->index = idx;
2607 knew->private_value = sw_ctl;
2608 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2609 }
2610 return 0;
2611}
2612
2613/* return the vol ctl when used first in the imux list */
2614static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
2615{
2616 struct alc_spec *spec = codec->spec;
2617 struct nid_path *path;
2618 unsigned int ctl;
2619 int i;
2620
2621 path = get_nid_path(codec, spec->imux_pins[idx],
2622 get_adc_nid(codec, 0, idx));
2623 if (!path)
2624 return 0;
2625 ctl = path->ctls[type];
2626 if (!ctl)
2627 return 0;
2628 for (i = 0; i < idx - 1; i++) {
2629 path = get_nid_path(codec, spec->imux_pins[i],
2630 get_adc_nid(codec, 0, i));
2631 if (path && path->ctls[type] == ctl)
2632 return 0;
2633 }
2634 return ctl;
2635}
2636
2637/* create individual capture volume and switch controls per input */
2638static int create_multi_cap_vol_ctl(struct hda_codec *codec)
2639{
2640 struct alc_spec *spec = codec->spec;
2641 struct hda_input_mux *imux = &spec->input_mux;
2642 int i, err, type, type_idx = 0;
2643 const char *prev_label = NULL;
2644
2645 for (i = 0; i < imux->num_items; i++) {
2646 const char *label;
2647 label = hda_get_autocfg_input_label(codec, &spec->autocfg, i);
2648 if (prev_label && !strcmp(label, prev_label))
2649 type_idx++;
2650 else
2651 type_idx = 0;
2652 prev_label = label;
2653
2654 for (type = 0; type < 2; type++) {
2655 err = add_single_cap_ctl(codec, label, type_idx, type,
2656 get_first_cap_ctl(codec, i, type));
2657 if (err < 0)
2658 return err;
2659 }
2660 }
2661 return 0;
2662}
2663
Takashi Iwai666a70d2012-12-17 20:29:29 +01002664static int create_capture_mixers(struct hda_codec *codec)
2665{
2666 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01002667 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002668 int i, n, nums, err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002669
2670 if (spec->dyn_adc_switch)
2671 nums = 1;
2672 else
2673 nums = spec->num_adc_nids;
2674
2675 if (!spec->auto_mic && imux->num_items > 1) {
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002676 struct snd_kcontrol_new *knew;
Takashi Iwaibc549762012-12-18 15:35:11 +01002677 knew = alc_kcontrol_new(spec, NULL, &cap_src_temp);
Takashi Iwai666a70d2012-12-17 20:29:29 +01002678 if (!knew)
2679 return -ENOMEM;
2680 knew->count = nums;
2681 }
2682
2683 for (n = 0; n < nums; n++) {
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002684 bool multi = false;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002685 int vol, sw;
2686
2687 vol = sw = 0;
2688 for (i = 0; i < imux->num_items; i++) {
2689 struct nid_path *path;
2690 path = get_nid_path(codec, spec->imux_pins[i],
2691 get_adc_nid(codec, n, i));
2692 if (!path)
2693 continue;
2694 parse_capvol_in_path(codec, path);
2695 if (!vol)
2696 vol = path->ctls[NID_PATH_VOL_CTL];
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002697 else if (vol != path->ctls[NID_PATH_VOL_CTL])
2698 multi = true;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002699 if (!sw)
2700 sw = path->ctls[NID_PATH_MUTE_CTL];
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002701 else if (sw != path->ctls[NID_PATH_MUTE_CTL])
2702 multi = true;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002703 }
2704
Takashi Iwai9bf387b2012-12-18 17:18:21 +01002705 if (!multi)
2706 err = create_single_cap_vol_ctl(codec, n, vol, sw);
2707 else if (!spec->multi_cap_vol)
2708 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
2709 else
2710 err = create_multi_cap_vol_ctl(codec);
2711 if (err < 0)
2712 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002713 }
2714
2715 return 0;
2716}
2717
Takashi Iwai05f5f472009-08-25 13:10:18 +02002718/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002719static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002720{
2721 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002722 const struct auto_pin_cfg *cfg = &spec->autocfg;
2723 hda_nid_t mixer = spec->mixer_nid;
Takashi Iwai27d31532012-12-18 08:57:05 +01002724 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwaib7821702011-07-06 15:12:46 +02002725 int num_adcs;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002726 int i, c, err, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002727 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002728
Takashi Iwai666a70d2012-12-17 20:29:29 +01002729 num_adcs = alc_auto_fill_adc_nids(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002730 if (num_adcs < 0)
2731 return 0;
2732
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002733 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002734 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002735 const char *label;
Takashi Iwai666a70d2012-12-17 20:29:29 +01002736 bool imux_added;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002737
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002738 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002739 if (!alc_is_input_pin(codec, pin))
2740 continue;
2741
David Henningsson5322bf22011-01-05 11:03:56 +01002742 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002743 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2744 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002745 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002746 type_idx++;
2747 else
2748 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002749 prev_label = label;
2750
Takashi Iwai05f5f472009-08-25 13:10:18 +02002751 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002752 if (is_reachable_path(codec, pin, mixer)) {
2753 err = new_analog_input(codec, pin,
2754 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002755 if (err < 0)
2756 return err;
2757 }
2758 }
2759
Takashi Iwai666a70d2012-12-17 20:29:29 +01002760 imux_added = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002761 for (c = 0; c < num_adcs; c++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01002762 struct nid_path *path;
2763 hda_nid_t adc = spec->adc_nids[c];
2764
2765 if (!is_reachable_path(codec, pin, adc))
2766 continue;
2767 path = snd_array_new(&spec->paths);
2768 if (!path)
2769 return -ENOMEM;
2770 memset(path, 0, sizeof(*path));
2771 if (!parse_nid_path(codec, pin, adc, 2, path)) {
2772 snd_printd(KERN_ERR
2773 "invalid input path 0x%x -> 0x%x\n",
2774 pin, adc);
2775 spec->paths.used--;
2776 continue;
2777 }
2778
2779 if (!imux_added) {
2780 spec->imux_pins[imux->num_items] = pin;
2781 snd_hda_add_imux_item(imux, label,
2782 imux->num_items, NULL);
2783 imux_added = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002784 }
2785 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002786 }
Takashi Iwai21268962011-07-07 15:01:13 +02002787
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002788 return 0;
2789}
2790
Takashi Iwai24de1832011-11-07 17:13:39 +01002791/* create a shared input with the headphone out */
2792static int alc_auto_create_shared_input(struct hda_codec *codec)
2793{
2794 struct alc_spec *spec = codec->spec;
2795 struct auto_pin_cfg *cfg = &spec->autocfg;
2796 unsigned int defcfg;
2797 hda_nid_t nid;
2798
2799 /* only one internal input pin? */
2800 if (cfg->num_inputs != 1)
2801 return 0;
2802 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2803 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2804 return 0;
2805
2806 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2807 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2808 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2809 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2810 else
2811 return 0; /* both not available */
2812
2813 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2814 return 0; /* no input */
2815
2816 cfg->inputs[1].pin = nid;
2817 cfg->inputs[1].type = AUTO_PIN_MIC;
2818 cfg->num_inputs = 2;
2819 spec->shared_mic_hp = 1;
2820 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2821 return 0;
2822}
2823
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002824static int get_pin_type(int line_out_type)
2825{
2826 if (line_out_type == AUTO_PIN_HP_OUT)
2827 return PIN_HP;
2828 else
2829 return PIN_OUT;
2830}
2831
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002832static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002833{
2834 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002835 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002836 int i;
2837
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002838 for (i = 0; i < cfg->num_inputs; i++) {
2839 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai62343992012-12-18 09:06:01 +01002840 if (alc_is_input_pin(codec, nid))
Takashi Iwai30ea0982010-09-16 18:47:56 +02002841 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002842
Takashi Iwai829f69e2012-12-14 18:26:02 +01002843 /* mute loopback inputs */
2844 if (spec->mixer_nid) {
2845 struct nid_path *path;
2846 path = get_nid_path(codec, nid, spec->mixer_nid);
2847 if (path)
Takashi Iwai666a70d2012-12-17 20:29:29 +01002848 activate_path(codec, path, path->active, false);
Takashi Iwai829f69e2012-12-14 18:26:02 +01002849 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002850 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002851}
2852
Takashi Iwai185d99f2012-02-16 18:39:45 +01002853static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2854{
2855 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002856 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002857
Takashi Iwaic9967f12012-12-14 16:39:22 +01002858 for (i = 0; i < spec->paths.used; i++) {
2859 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002860 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002861 return true;
2862 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002863 return false;
2864}
2865
Takashi Iwai463419d2012-12-05 14:17:37 +01002866/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002867static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2868 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002869{
2870 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002871 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002872 int i;
2873
2874 for (i = 0; i < spec->num_all_dacs; i++) {
2875 hda_nid_t nid = spec->all_dacs[i];
2876 if (!nid || alc_is_dac_already_used(codec, nid))
2877 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002878 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2879 if (is_digital != cap_digital)
2880 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002881 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002882 return nid;
2883 }
2884 return 0;
2885}
2886
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002887/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002888static bool __parse_nid_path(struct hda_codec *codec,
2889 hda_nid_t from_nid, hda_nid_t to_nid,
2890 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002891{
2892 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002893 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002894 int i, nums;
2895
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002896 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002897 if (!with_aa_mix)
2898 return false;
2899 with_aa_mix = 2; /* mark aa-mix is included */
2900 }
2901
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002902 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002903 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002904 if (conn[i] != from_nid) {
2905 /* special case: when from_nid is 0,
2906 * try to find an empty DAC
2907 */
2908 if (from_nid ||
2909 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2910 alc_is_dac_already_used(codec, conn[i]))
2911 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002912 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002913 /* aa-mix is requested but not included? */
2914 if (!(spec->mixer_nid && with_aa_mix == 1))
2915 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002916 }
2917 if (depth >= MAX_NID_PATH_DEPTH)
2918 return false;
2919 for (i = 0; i < nums; i++) {
2920 unsigned int type;
2921 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002922 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2923 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002924 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002925 if (__parse_nid_path(codec, from_nid, conn[i],
2926 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002927 goto found;
2928 }
2929 return false;
2930
2931 found:
2932 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002933 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002934 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002935 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002936 path->depth++;
2937 return true;
2938}
2939
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002940/* parse the widget path from the given nid to the target nid;
2941 * when @from_nid is 0, try to find an empty DAC;
2942 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2943 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2944 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002945 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002946static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2947 hda_nid_t to_nid, int with_aa_mix,
2948 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002949{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002950 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2951 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002952 path->depth++;
2953#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002954 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002955 path->depth, path->path[0], path->path[1],
2956 path->path[2], path->path[3], path->path[4]);
2957#endif
2958 return true;
2959 }
2960 return false;
2961}
2962
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002963static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2964{
Takashi Iwai140547e2012-02-16 17:23:46 +01002965 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002966 int i;
2967 hda_nid_t nid_found = 0;
2968
2969 for (i = 0; i < spec->num_all_dacs; i++) {
2970 hda_nid_t nid = spec->all_dacs[i];
2971 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002972 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002973 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01002974 if (nid_found)
2975 return 0;
2976 nid_found = nid;
2977 }
2978 }
2979 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002980}
2981
Takashi Iwaiba8111272012-12-06 18:06:23 +01002982static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002983{
Takashi Iwaiba8111272012-12-06 18:06:23 +01002984 struct alc_spec *spec = codec->spec;
2985 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002986
Takashi Iwaic9967f12012-12-14 16:39:22 +01002987 for (i = 0; i < spec->paths.used; i++) {
2988 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01002989 if (path->ctls[type] == val)
2990 return true;
2991 }
2992 return false;
2993}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002994
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002995/* badness definition */
2996enum {
2997 /* No primary DAC is found for the main output */
2998 BAD_NO_PRIMARY_DAC = 0x10000,
2999 /* No DAC is found for the extra output */
3000 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003001 /* No possible multi-ios */
3002 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003003 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003004 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003005 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003006 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003007 /* Primary DAC shared with main surrounds */
3008 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003009 /* Primary DAC shared with main CLFE */
3010 BAD_SHARED_CLFE = 0x10,
3011 /* Primary DAC shared with extra surrounds */
3012 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003013 /* Volume widget is shared */
3014 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003015};
3016
3017static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003018 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003019static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003020 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003021
Takashi Iwai965cceb2012-12-18 11:46:37 +01003022static struct nid_path *add_new_nid_path(struct hda_codec *codec,
3023 hda_nid_t from_nid, hda_nid_t to_nid,
3024 int with_aa_mix)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003025{
3026 struct alc_spec *spec = codec->spec;
3027 struct nid_path *path;
3028
Takashi Iwai965cceb2012-12-18 11:46:37 +01003029 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
3030 return NULL;
3031
Takashi Iwaic9967f12012-12-14 16:39:22 +01003032 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003033 if (!path)
Takashi Iwai965cceb2012-12-18 11:46:37 +01003034 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003035 memset(path, 0, sizeof(*path));
Takashi Iwai965cceb2012-12-18 11:46:37 +01003036 if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path))
3037 return path;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003038 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01003039 spec->paths.used--;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003040 return NULL;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003041}
3042
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003043/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003044 * passing 0 to either @pin or @dac behaves as a wildcard
3045 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003046static struct nid_path *
3047get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01003048{
3049 struct alc_spec *spec = codec->spec;
3050 int i;
3051
Takashi Iwaic9967f12012-12-14 16:39:22 +01003052 for (i = 0; i < spec->paths.used; i++) {
3053 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003054 if (path->depth <= 0)
3055 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003056 if ((!from_nid || path->path[0] == from_nid) &&
3057 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01003058 return path;
3059 }
3060 return NULL;
3061}
3062
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003063/* look for widgets in the path between the given NIDs appropriate for
3064 * volume and mute controls, and assign the values to ctls[].
3065 *
3066 * When no appropriate widget is found in the path, the badness value
3067 * is incremented depending on the situation. The function returns the
3068 * total badness for both volume and mute controls.
3069 */
3070static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3071 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003072{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003073 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003074 hda_nid_t nid;
3075 unsigned int val;
3076 int badness = 0;
3077
Takashi Iwaiba8111272012-12-06 18:06:23 +01003078 if (!path)
3079 return BAD_SHARED_VOL * 2;
3080 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003081 if (nid) {
3082 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003083 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003084 badness += BAD_SHARED_VOL;
3085 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003086 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003087 } else
3088 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003089 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003090 if (nid) {
3091 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003092 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3093 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003094 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3095 else
3096 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003097 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003098 badness += BAD_SHARED_VOL;
3099 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003100 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003101 } else
3102 badness += BAD_SHARED_VOL;
3103 return badness;
3104}
3105
Takashi Iwaidc31b582012-02-17 17:27:53 +01003106struct badness_table {
3107 int no_primary_dac; /* no primary DAC */
3108 int no_dac; /* no secondary DACs */
3109 int shared_primary; /* primary DAC is shared with main output */
3110 int shared_surr; /* secondary DAC shared with main or primary */
3111 int shared_clfe; /* third DAC shared with main or primary */
3112 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3113};
3114
3115static struct badness_table main_out_badness = {
3116 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3117 .no_dac = BAD_NO_DAC,
3118 .shared_primary = BAD_NO_PRIMARY_DAC,
3119 .shared_surr = BAD_SHARED_SURROUND,
3120 .shared_clfe = BAD_SHARED_CLFE,
3121 .shared_surr_main = BAD_SHARED_SURROUND,
3122};
3123
3124static struct badness_table extra_out_badness = {
3125 .no_primary_dac = BAD_NO_DAC,
3126 .no_dac = BAD_NO_DAC,
3127 .shared_primary = BAD_NO_EXTRA_DAC,
3128 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3129 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3130 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3131};
3132
3133/* try to assign DACs to pins and return the resultant badness */
3134static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3135 const hda_nid_t *pins, hda_nid_t *dacs,
3136 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003137{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003138 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003139 struct auto_pin_cfg *cfg = &spec->autocfg;
3140 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003141 int badness = 0;
3142 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003143
Takashi Iwai185d99f2012-02-16 18:39:45 +01003144 if (!num_outs)
3145 return 0;
3146
Takashi Iwaidc31b582012-02-17 17:27:53 +01003147 for (i = 0; i < num_outs; i++) {
3148 hda_nid_t pin = pins[i];
3149 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003150 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003151 if (!dacs[i] && !i) {
3152 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003153 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003154 dacs[0] = dacs[j];
3155 dacs[j] = 0;
3156 break;
3157 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003158 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003159 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003160 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003161 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003162 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003163 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003164 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003165 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003166 dac = spec->private_dac_nids[i];
3167 if (dac) {
3168 if (!i)
3169 badness += bad->shared_primary;
3170 else if (i == 1)
3171 badness += bad->shared_surr;
3172 else
3173 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003174 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003175 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003176 badness += bad->shared_surr_main;
3177 } else if (!i)
3178 badness += bad->no_primary_dac;
3179 else
3180 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003181 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01003182 if (!add_new_nid_path(codec, dac, pin, 0))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003183 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003184 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003185 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003186 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003187
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003188 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003189}
3190
3191static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003192 hda_nid_t reference_pin,
3193 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003194
Takashi Iwai185d99f2012-02-16 18:39:45 +01003195static bool alc_map_singles(struct hda_codec *codec, int outs,
3196 const hda_nid_t *pins, hda_nid_t *dacs)
3197{
3198 int i;
3199 bool found = false;
3200 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003201 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003202 if (dacs[i])
3203 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003204 dac = get_dac_if_single(codec, pins[i]);
3205 if (!dac)
3206 continue;
Takashi Iwai965cceb2012-12-18 11:46:37 +01003207 if (add_new_nid_path(codec, dac, pins[i], 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003208 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003209 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003210 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003211 }
3212 return found;
3213}
3214
Takashi Iwai7085ec12009-10-02 09:03:58 +02003215/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003216static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003217 bool fill_hardwired,
3218 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003219{
3220 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003221 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003222 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003223
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003224 /* set num_dacs once to full for alc_auto_look_for_dac() */
3225 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003226 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003227 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3228 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3229 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003230 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003231 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003232 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003233
3234 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003235 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003236 bool mapped;
3237 do {
3238 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003239 cfg->line_out_pins,
3240 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003241 mapped |= alc_map_singles(codec, cfg->hp_outs,
3242 cfg->hp_pins,
3243 spec->multiout.hp_out_nid);
3244 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3245 cfg->speaker_pins,
3246 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003247 if (fill_mio_first && cfg->line_outs == 1 &&
3248 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3249 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3250 if (!err)
3251 mapped = true;
3252 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003253 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003254 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003255
Takashi Iwaidc31b582012-02-17 17:27:53 +01003256 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3257 spec->private_dac_nids,
3258 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003259
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003260 /* re-count num_dacs and squash invalid entries */
3261 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003262 for (i = 0; i < cfg->line_outs; i++) {
3263 if (spec->private_dac_nids[i])
3264 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003265 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003266 memmove(spec->private_dac_nids + i,
3267 spec->private_dac_nids + i + 1,
3268 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003269 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3270 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003271 }
3272
Takashi Iwai276dd702012-02-17 16:17:03 +01003273 if (fill_mio_first &&
3274 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003275 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003276 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003277 if (err < 0)
3278 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003279 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003280 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003281
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003282 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003283 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3284 spec->multiout.hp_out_nid,
3285 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003286 if (err < 0)
3287 return err;
3288 badness += err;
3289 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003290 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003291 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3292 cfg->speaker_pins,
3293 spec->multiout.extra_out_nid,
3294 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003295 if (err < 0)
3296 return err;
3297 badness += err;
3298 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003299 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3300 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003301 if (err < 0)
3302 return err;
3303 badness += err;
3304 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003305 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3306 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003307 int offset = 0;
3308 if (cfg->line_outs >= 3)
3309 offset = 1;
3310 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3311 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003312 if (err < 0)
3313 return err;
3314 badness += err;
3315 }
3316
3317 if (spec->multi_ios == 2) {
3318 for (i = 0; i < 2; i++)
3319 spec->private_dac_nids[spec->multiout.num_dacs++] =
3320 spec->multi_io[i].dac;
3321 spec->ext_channel_count = 2;
3322 } else if (spec->multi_ios) {
3323 spec->multi_ios = 0;
3324 badness += BAD_MULTI_IO;
3325 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003326
3327 return badness;
3328}
3329
3330#define DEBUG_BADNESS
3331
3332#ifdef DEBUG_BADNESS
3333#define debug_badness snd_printdd
3334#else
3335#define debug_badness(...)
3336#endif
3337
3338static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3339{
3340 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3341 cfg->line_out_pins[0], cfg->line_out_pins[1],
3342 cfg->line_out_pins[2], cfg->line_out_pins[2],
3343 spec->multiout.dac_nids[0],
3344 spec->multiout.dac_nids[1],
3345 spec->multiout.dac_nids[2],
3346 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003347 if (spec->multi_ios > 0)
3348 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3349 spec->multi_ios,
3350 spec->multi_io[0].pin, spec->multi_io[1].pin,
3351 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003352 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3353 cfg->hp_pins[0], cfg->hp_pins[1],
3354 cfg->hp_pins[2], cfg->hp_pins[2],
3355 spec->multiout.hp_out_nid[0],
3356 spec->multiout.hp_out_nid[1],
3357 spec->multiout.hp_out_nid[2],
3358 spec->multiout.hp_out_nid[3]);
3359 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3360 cfg->speaker_pins[0], cfg->speaker_pins[1],
3361 cfg->speaker_pins[2], cfg->speaker_pins[3],
3362 spec->multiout.extra_out_nid[0],
3363 spec->multiout.extra_out_nid[1],
3364 spec->multiout.extra_out_nid[2],
3365 spec->multiout.extra_out_nid[3]);
3366}
3367
Takashi Iwai463419d2012-12-05 14:17:37 +01003368/* find all available DACs of the codec */
3369static void alc_fill_all_nids(struct hda_codec *codec)
3370{
3371 struct alc_spec *spec = codec->spec;
3372 int i;
3373 hda_nid_t nid = codec->start_nid;
3374
3375 spec->num_all_dacs = 0;
3376 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3377 for (i = 0; i < codec->num_nodes; i++, nid++) {
3378 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3379 continue;
3380 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3381 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3382 break;
3383 }
3384 spec->all_dacs[spec->num_all_dacs++] = nid;
3385 }
3386}
3387
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003388static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3389{
3390 struct alc_spec *spec = codec->spec;
3391 struct auto_pin_cfg *cfg = &spec->autocfg;
3392 struct auto_pin_cfg *best_cfg;
3393 int best_badness = INT_MAX;
3394 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003395 bool fill_hardwired = true, fill_mio_first = true;
3396 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003397 bool hp_spk_swapped = false;
3398
Takashi Iwai463419d2012-12-05 14:17:37 +01003399 alc_fill_all_nids(codec);
3400
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003401 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3402 if (!best_cfg)
3403 return -ENOMEM;
3404 *best_cfg = *cfg;
3405
3406 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003407 badness = fill_and_eval_dacs(codec, fill_hardwired,
3408 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003409 if (badness < 0) {
3410 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003411 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003412 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003413 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3414 cfg->line_out_type, fill_hardwired, fill_mio_first,
3415 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003416 debug_show_configs(spec, cfg);
3417 if (badness < best_badness) {
3418 best_badness = badness;
3419 *best_cfg = *cfg;
3420 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003421 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003422 }
3423 if (!badness)
3424 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003425 fill_mio_first = !fill_mio_first;
3426 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003427 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003428 fill_hardwired = !fill_hardwired;
3429 if (!fill_hardwired)
3430 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003431 if (hp_spk_swapped)
3432 break;
3433 hp_spk_swapped = true;
3434 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003435 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3436 cfg->hp_outs = cfg->line_outs;
3437 memcpy(cfg->hp_pins, cfg->line_out_pins,
3438 sizeof(cfg->hp_pins));
3439 cfg->line_outs = cfg->speaker_outs;
3440 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3441 sizeof(cfg->speaker_pins));
3442 cfg->speaker_outs = 0;
3443 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3444 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003445 fill_hardwired = true;
3446 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003447 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003448 if (cfg->hp_outs > 0 &&
3449 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3450 cfg->speaker_outs = cfg->line_outs;
3451 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3452 sizeof(cfg->speaker_pins));
3453 cfg->line_outs = cfg->hp_outs;
3454 memcpy(cfg->line_out_pins, cfg->hp_pins,
3455 sizeof(cfg->hp_pins));
3456 cfg->hp_outs = 0;
3457 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3458 cfg->line_out_type = AUTO_PIN_HP_OUT;
3459 fill_hardwired = true;
3460 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003461 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003462 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003463 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003464
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003465 if (badness) {
3466 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003467 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003468 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003469 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3470 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003471 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003472
Takashi Iwaiba8111272012-12-06 18:06:23 +01003473 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003474 struct nid_path *path = get_nid_path(codec,
3475 spec->multiout.dac_nids[0],
3476 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003477 if (path)
3478 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3479 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003480
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003481 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003482 return 0;
3483}
3484
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003485/* replace the channels in the composed amp value with the given number */
3486static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3487{
3488 val &= ~(0x3U << 16);
3489 val |= chs << 16;
3490 return val;
3491}
3492
Takashi Iwai343a04b2011-07-06 14:28:39 +02003493static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003494 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003495 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003496 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003497{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003498 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003499 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003500 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003501 val = path->ctls[NID_PATH_VOL_CTL];
3502 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003503 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003504 val = amp_val_replace_channels(val, chs);
3505 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3506}
3507
3508/* return the channel bits suitable for the given path->ctls[] */
3509static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3510 int type)
3511{
3512 int chs = 1; /* mono (left only) */
3513 if (path) {
3514 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3515 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3516 chs = 3; /* stereo */
3517 }
3518 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003519}
3520
Takashi Iwaie29d3772011-11-14 17:13:23 +01003521static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3522 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003523 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003524{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003525 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3526 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003527}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003528
3529/* create a mute-switch for the given mixer widget;
3530 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3531 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003532static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003533 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003534 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003535 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003536{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003537 unsigned int val;
3538 int type = ALC_CTL_WIDGET_MUTE;
3539
3540 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003541 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003542 val = path->ctls[NID_PATH_MUTE_CTL];
3543 if (!val)
3544 return 0;
3545 val = amp_val_replace_channels(val, chs);
3546 if (get_amp_direction_(val) == HDA_INPUT) {
3547 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003548 int nums = snd_hda_get_num_conns(codec, nid);
3549 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003550 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003551 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003552 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003553 }
3554 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003555}
3556
Takashi Iwaie29d3772011-11-14 17:13:23 +01003557static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003558 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003559{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003560 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3561 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003562}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003563
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003564static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003565 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003566{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003567 int i;
3568
3569 for (i = path->depth - 1; i >= 0; i--) {
3570 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3571 return path->path[i];
3572 if (i != path->depth - 1 && i != 0 &&
3573 nid_has_mute(codec, path->path[i], HDA_INPUT))
3574 return path->path[i];
3575 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003576 return 0;
3577}
3578
3579static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003580 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003581{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003582 int i;
3583
3584 for (i = path->depth - 1; i >= 0; i--) {
3585 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3586 return path->path[i];
3587 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003588 return 0;
3589}
3590
Takashi Iwai7085ec12009-10-02 09:03:58 +02003591/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003592static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003593 const struct auto_pin_cfg *cfg)
3594{
3595 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003596 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003597
Takashi Iwaice764ab2011-04-27 16:35:23 +02003598 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003599 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003600 noutputs += spec->multi_ios;
3601
3602 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003603 const char *name;
3604 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003605 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003606 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003607
3608 dac = spec->multiout.dac_nids[i];
3609 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003610 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003611 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003612 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003613 index = 0;
3614 name = channel_name[i];
3615 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003616 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003617 name = alc_get_line_out_pfx(spec, i, true, &index);
3618 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003619
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003620 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003621 if (!path)
3622 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003623 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003624 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003625 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003626 if (err < 0)
3627 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003628 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003629 if (err < 0)
3630 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003631 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003632 if (err < 0)
3633 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003634 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003635 if (err < 0)
3636 return err;
3637 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003638 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003639 if (err < 0)
3640 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003641 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003642 if (err < 0)
3643 return err;
3644 }
3645 }
3646 return 0;
3647}
3648
Takashi Iwai343a04b2011-07-06 14:28:39 +02003649static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003650 hda_nid_t dac, const char *pfx,
3651 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003652{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003653 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003654 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003655
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003656 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003657 if (!path)
3658 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003659 /* bind volume control will be created in the case of dac = 0 */
3660 if (dac) {
3661 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3662 if (err < 0)
3663 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003664 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003665 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003666 if (err < 0)
3667 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003668 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003669}
3670
Takashi Iwai23c09b02011-08-19 09:05:35 +02003671static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3672 unsigned int nums,
3673 struct hda_ctl_ops *ops)
3674{
3675 struct alc_spec *spec = codec->spec;
3676 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003677 ctlp = snd_array_new(&spec->bind_ctls);
3678 if (!ctlp)
3679 return NULL;
3680 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3681 *ctlp = ctl;
3682 if (ctl)
3683 ctl->ops = ops;
3684 return ctl;
3685}
3686
3687/* add playback controls for speaker and HP outputs */
3688static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3689 const hda_nid_t *pins,
3690 const hda_nid_t *dacs,
3691 const char *pfx)
3692{
3693 struct alc_spec *spec = codec->spec;
3694 struct hda_bind_ctls *ctl;
3695 char name[32];
3696 int i, n, err;
3697
3698 if (!num_pins || !pins[0])
3699 return 0;
3700
Takashi Iwai527e4d72011-10-27 16:33:27 +02003701 if (num_pins == 1) {
3702 hda_nid_t dac = *dacs;
3703 if (!dac)
3704 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003705 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003706 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003707
Takashi Iwai23c09b02011-08-19 09:05:35 +02003708 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003709 hda_nid_t dac;
3710 if (dacs[num_pins - 1])
3711 dac = dacs[i]; /* with individual volumes */
3712 else
3713 dac = 0;
3714 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3715 err = alc_auto_create_extra_out(codec, pins[i], dac,
3716 "Bass Speaker", 0);
3717 } else if (num_pins >= 3) {
3718 snprintf(name, sizeof(name), "%s %s",
3719 pfx, channel_name[i]);
3720 err = alc_auto_create_extra_out(codec, pins[i], dac,
3721 name, 0);
3722 } else {
3723 err = alc_auto_create_extra_out(codec, pins[i], dac,
3724 pfx, i);
3725 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003726 if (err < 0)
3727 return err;
3728 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003729 if (dacs[num_pins - 1])
3730 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003731
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003732 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003733 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3734 if (!ctl)
3735 return -ENOMEM;
3736 n = 0;
3737 for (i = 0; i < num_pins; i++) {
3738 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003739 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003740 if (!pins[i] || !dacs[i])
3741 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003742 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003743 if (!path)
3744 continue;
3745 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003746 if (vol)
3747 ctl->values[n++] =
3748 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3749 }
3750 if (n) {
3751 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3752 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3753 if (err < 0)
3754 return err;
3755 }
3756 return 0;
3757}
3758
Takashi Iwai343a04b2011-07-06 14:28:39 +02003759static int alc_auto_create_hp_out(struct hda_codec *codec)
3760{
3761 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003762 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3763 spec->autocfg.hp_pins,
3764 spec->multiout.hp_out_nid,
3765 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003766}
3767
3768static int alc_auto_create_speaker_out(struct hda_codec *codec)
3769{
3770 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003771 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3772 spec->autocfg.speaker_pins,
3773 spec->multiout.extra_out_nid,
3774 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003775}
3776
Takashi Iwai130e5f02012-12-14 16:09:29 +01003777/* check whether a control with the given (nid, dir, idx) was assigned */
3778static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3779 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003780{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003781 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003782 int i, type;
3783
3784 for (i = 0; i < spec->paths.used; i++) {
3785 struct nid_path *p = snd_array_elem(&spec->paths, i);
3786 if (p->depth <= 0)
3787 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003788 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003789 unsigned int val = p->ctls[type];
3790 if (get_amp_nid_(val) == nid &&
3791 get_amp_direction_(val) == dir &&
3792 get_amp_index_(val) == idx)
3793 return true;
3794 }
3795 }
3796 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003797}
3798
3799/* can have the amp-in capability? */
3800static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3801{
3802 hda_nid_t nid = path->path[idx];
3803 unsigned int caps = get_wcaps(codec, nid);
3804 unsigned int type = get_wcaps_type(caps);
3805
3806 if (!(caps & AC_WCAP_IN_AMP))
3807 return false;
3808 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3809 return false;
3810 return true;
3811}
3812
3813/* can have the amp-out capability? */
3814static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3815{
3816 hda_nid_t nid = path->path[idx];
3817 unsigned int caps = get_wcaps(codec, nid);
3818 unsigned int type = get_wcaps_type(caps);
3819
3820 if (!(caps & AC_WCAP_OUT_AMP))
3821 return false;
3822 if (type == AC_WID_PIN && !idx) /* only for output pins */
3823 return false;
3824 return true;
3825}
3826
Takashi Iwaic9967f12012-12-14 16:39:22 +01003827/* check whether the given (nid,dir,idx) is active */
3828static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3829 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003830{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003831 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003832 int i, n;
3833
Takashi Iwaic9967f12012-12-14 16:39:22 +01003834 for (n = 0; n < spec->paths.used; n++) {
3835 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003836 if (!path->active)
3837 continue;
3838 for (i = 0; i < path->depth; i++) {
3839 if (path->path[i] == nid) {
3840 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3841 return true;
3842 break;
3843 }
3844 }
3845 }
3846 return false;
3847}
3848
Takashi Iwai130e5f02012-12-14 16:09:29 +01003849/* get the default amp value for the target state */
3850static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3851 int dir, bool enable)
3852{
3853 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003854 unsigned int val = 0;
3855
3856 caps = query_amp_caps(codec, nid, dir);
3857 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003858 /* set to 0dB */
3859 if (enable)
3860 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003861 }
3862 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003863 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003864 val |= HDA_AMP_MUTE;
3865 }
3866 return val;
3867}
3868
Takashi Iwai130e5f02012-12-14 16:09:29 +01003869/* initialize the amp value (only at the first time) */
3870static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3871{
3872 int val = get_amp_val_to_activate(codec, nid, dir, false);
3873 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3874}
3875
3876static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3877 int idx, bool enable)
3878{
3879 int val;
3880 if (is_ctl_associated(codec, nid, dir, idx) ||
3881 is_active_nid(codec, nid, dir, idx))
3882 return;
3883 val = get_amp_val_to_activate(codec, nid, dir, enable);
3884 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3885}
3886
3887static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3888 int i, bool enable)
3889{
3890 hda_nid_t nid = path->path[i];
3891 init_amp(codec, nid, HDA_OUTPUT, 0);
3892 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3893}
3894
3895static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003896 int i, bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003897{
3898 struct alc_spec *spec = codec->spec;
3899 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003900 int n, nums, idx;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003901 int type;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003902 hda_nid_t nid = path->path[i];
3903
3904 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai666a70d2012-12-17 20:29:29 +01003905 type = get_wcaps_type(get_wcaps(codec, nid));
3906 if (type == AC_WID_PIN ||
3907 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003908 nums = 1;
3909 idx = 0;
3910 } else
3911 idx = path->idx[i];
3912
Takashi Iwai130e5f02012-12-14 16:09:29 +01003913 for (n = 0; n < nums; n++)
3914 init_amp(codec, nid, HDA_INPUT, n);
3915
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003916 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003917 return;
3918
3919 /* here is a little bit tricky in comparison with activate_amp_out();
3920 * when aa-mixer is available, we need to enable the path as well
3921 */
3922 for (n = 0; n < nums; n++) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01003923 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003924 continue;
3925 activate_amp(codec, nid, HDA_INPUT, n, enable);
3926 }
3927}
3928
3929static void activate_path(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai666a70d2012-12-17 20:29:29 +01003930 bool enable, bool add_aamix)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003931{
3932 int i;
3933
Takashi Iwai130e5f02012-12-14 16:09:29 +01003934 if (!enable)
3935 path->active = false;
3936
3937 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003938 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003939 snd_hda_codec_write_cache(codec, path->path[i], 0,
3940 AC_VERB_SET_CONNECT_SEL,
3941 path->idx[i]);
3942 if (has_amp_in(codec, path, i))
Takashi Iwai666a70d2012-12-17 20:29:29 +01003943 activate_amp_in(codec, path, i, enable, add_aamix);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003944 if (has_amp_out(codec, path, i))
3945 activate_amp_out(codec, path, i, enable);
3946 }
3947
3948 if (enable)
3949 path->active = true;
3950}
3951
Takashi Iwai78e635c2012-12-10 17:07:16 +01003952/* configure the path from the given dac to the pin as the proper output */
3953static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3954 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003955 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003956{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003957 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003958
Takashi Iwai130e5f02012-12-14 16:09:29 +01003959 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003960 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003961 if (!path)
3962 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003963 if (path->active)
3964 return;
Takashi Iwai666a70d2012-12-17 20:29:29 +01003965 activate_path(codec, path, true, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003966}
3967
Takashi Iwai343a04b2011-07-06 14:28:39 +02003968static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003969{
3970 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003971 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003972 int i;
3973
3974 for (i = 0; i <= HDA_SIDE; i++) {
3975 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3976 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003977 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003978 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003979
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003980 }
3981}
3982
Takashi Iwai343a04b2011-07-06 14:28:39 +02003983static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003984{
3985 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003986 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003987 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003988
David Henningsson636030e2011-10-12 19:26:03 +02003989 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003990 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3991 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003992 pin = spec->autocfg.hp_pins[i];
3993 if (!pin)
3994 break;
3995 dac = spec->multiout.hp_out_nid[i];
3996 if (!dac) {
3997 if (i > 0 && spec->multiout.hp_out_nid[0])
3998 dac = spec->multiout.hp_out_nid[0];
3999 else
4000 dac = spec->multiout.dac_nids[0];
4001 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004002 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004003 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02004004 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004005 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4006 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004007 pin = spec->autocfg.speaker_pins[i];
4008 if (!pin)
4009 break;
4010 dac = spec->multiout.extra_out_nid[i];
4011 if (!dac) {
4012 if (i > 0 && spec->multiout.extra_out_nid[0])
4013 dac = spec->multiout.extra_out_nid[0];
4014 else
4015 dac = spec->multiout.dac_nids[0];
4016 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004017 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004018 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004019}
4020
Takashi Iwai276dd702012-02-17 16:17:03 +01004021/* check whether the given pin can be a multi-io pin */
4022static bool can_be_multiio_pin(struct hda_codec *codec,
4023 unsigned int location, hda_nid_t nid)
4024{
4025 unsigned int defcfg, caps;
4026
4027 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4028 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4029 return false;
4030 if (location && get_defcfg_location(defcfg) != location)
4031 return false;
4032 caps = snd_hda_query_pin_caps(codec, nid);
4033 if (!(caps & AC_PINCAP_OUT))
4034 return false;
4035 return true;
4036}
4037
Takashi Iwaice764ab2011-04-27 16:35:23 +02004038/*
4039 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004040 *
4041 * When hardwired is set, try to fill ony hardwired pins, and returns
4042 * zero if any pins are filled, non-zero if nothing found.
4043 * When hardwired is off, try to fill possible input pins, and returns
4044 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004045 */
4046static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004047 hda_nid_t reference_pin,
4048 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004049{
4050 struct alc_spec *spec = codec->spec;
4051 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004052 int type, i, j, dacs, num_pins, old_pins;
4053 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4054 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004055 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004056
Takashi Iwai276dd702012-02-17 16:17:03 +01004057 old_pins = spec->multi_ios;
4058 if (old_pins >= 2)
4059 goto end_fill;
4060
4061 num_pins = 0;
4062 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4063 for (i = 0; i < cfg->num_inputs; i++) {
4064 if (cfg->inputs[i].type != type)
4065 continue;
4066 if (can_be_multiio_pin(codec, location,
4067 cfg->inputs[i].pin))
4068 num_pins++;
4069 }
4070 }
4071 if (num_pins < 2)
4072 goto end_fill;
4073
Takashi Iwai07b18f62011-11-10 15:42:54 +01004074 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004075 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4076 for (i = 0; i < cfg->num_inputs; i++) {
4077 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004078 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004079
Takashi Iwaice764ab2011-04-27 16:35:23 +02004080 if (cfg->inputs[i].type != type)
4081 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004082 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004083 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004084 for (j = 0; j < spec->multi_ios; j++) {
4085 if (nid == spec->multi_io[j].pin)
4086 break;
4087 }
4088 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004089 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004090
4091 if (offset && offset + spec->multi_ios < dacs) {
4092 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004093 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004094 dac = 0;
4095 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004096 if (hardwired)
4097 dac = get_dac_if_single(codec, nid);
4098 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004099 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004100 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004101 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004102 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004103 }
Takashi Iwai965cceb2012-12-18 11:46:37 +01004104 if (!add_new_nid_path(codec, dac, nid, 0)) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004105 badness++;
4106 continue;
4107 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004108 spec->multi_io[spec->multi_ios].pin = nid;
4109 spec->multi_io[spec->multi_ios].dac = dac;
4110 spec->multi_ios++;
4111 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004112 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004113 }
4114 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004115 end_fill:
4116 if (badness)
4117 badness = BAD_MULTI_IO;
4118 if (old_pins == spec->multi_ios) {
4119 if (hardwired)
4120 return 1; /* nothing found */
4121 else
4122 return badness; /* no badness if nothing found */
4123 }
4124 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004125 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004126 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004127 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004128 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004129 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004130
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004131 /* assign volume and mute controls */
4132 for (i = old_pins; i < spec->multi_ios; i++)
4133 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4134 spec->multi_io[i].dac);
4135
4136 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004137}
4138
4139static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4140 struct snd_ctl_elem_info *uinfo)
4141{
4142 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4143 struct alc_spec *spec = codec->spec;
4144
4145 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4146 uinfo->count = 1;
4147 uinfo->value.enumerated.items = spec->multi_ios + 1;
4148 if (uinfo->value.enumerated.item > spec->multi_ios)
4149 uinfo->value.enumerated.item = spec->multi_ios;
4150 sprintf(uinfo->value.enumerated.name, "%dch",
4151 (uinfo->value.enumerated.item + 1) * 2);
4152 return 0;
4153}
4154
4155static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4156 struct snd_ctl_elem_value *ucontrol)
4157{
4158 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4159 struct alc_spec *spec = codec->spec;
4160 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4161 return 0;
4162}
4163
4164static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4165{
4166 struct alc_spec *spec = codec->spec;
4167 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004168 struct nid_path *path;
4169
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004170 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004171 if (!path)
4172 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004173
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004174 if (path->active == output)
4175 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004176
Takashi Iwaice764ab2011-04-27 16:35:23 +02004177 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004178 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004179 activate_path(codec, path, true, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004180 } else {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004181 activate_path(codec, path, false, true);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004182 snd_hda_set_pin_ctl_cache(codec, nid,
4183 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004184 }
4185 return 0;
4186}
4187
4188static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4189 struct snd_ctl_elem_value *ucontrol)
4190{
4191 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4192 struct alc_spec *spec = codec->spec;
4193 int i, ch;
4194
4195 ch = ucontrol->value.enumerated.item[0];
4196 if (ch < 0 || ch > spec->multi_ios)
4197 return -EINVAL;
4198 if (ch == (spec->ext_channel_count - 1) / 2)
4199 return 0;
4200 spec->ext_channel_count = (ch + 1) * 2;
4201 for (i = 0; i < spec->multi_ios; i++)
4202 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004203 spec->multiout.max_channels = max(spec->ext_channel_count,
4204 spec->const_channel_count);
4205 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004206 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004207 return 1;
4208}
4209
Takashi Iwaia9111322011-05-02 11:30:18 +02004210static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004211 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4212 .name = "Channel Mode",
4213 .info = alc_auto_ch_mode_info,
4214 .get = alc_auto_ch_mode_get,
4215 .put = alc_auto_ch_mode_put,
4216};
4217
Takashi Iwai23c09b02011-08-19 09:05:35 +02004218static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004219{
4220 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004221
Takashi Iwaic2674682011-08-24 17:57:44 +02004222 if (spec->multi_ios > 0) {
Takashi Iwaibc549762012-12-18 15:35:11 +01004223 if (!alc_kcontrol_new(spec, NULL, &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004224 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004225 }
4226 return 0;
4227}
4228
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004229static void alc_auto_init_multi_io(struct hda_codec *codec)
4230{
4231 struct alc_spec *spec = codec->spec;
4232 int i;
4233
4234 for (i = 0; i < spec->multi_ios; i++) {
4235 hda_nid_t pin = spec->multi_io[i].pin;
4236 struct nid_path *path;
4237 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4238 if (!path)
4239 continue;
4240 if (!spec->multi_io[i].ctl_in)
4241 spec->multi_io[i].ctl_in =
4242 snd_hda_codec_update_cache(codec, pin, 0,
4243 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai666a70d2012-12-17 20:29:29 +01004244 activate_path(codec, path, path->active, true);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004245 }
4246}
4247
Takashi Iwai1d045db2011-07-07 18:23:21 +02004248/*
4249 * initialize ADC paths
4250 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004251static void alc_auto_init_input_src(struct hda_codec *codec)
4252{
4253 struct alc_spec *spec = codec->spec;
Takashi Iwai27d31532012-12-18 08:57:05 +01004254 struct hda_input_mux *imux = &spec->input_mux;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004255 struct nid_path *path;
4256 int i, c, nums;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004257
Takashi Iwai1d045db2011-07-07 18:23:21 +02004258 if (spec->dyn_adc_switch)
4259 nums = 1;
4260 else
4261 nums = spec->num_adc_nids;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004262
4263 for (c = 0; c < nums; c++) {
4264 for (i = 0; i < imux->num_items; i++) {
4265 path = get_nid_path(codec, spec->imux_pins[i],
4266 get_adc_nid(codec, c, i));
4267 if (path) {
4268 bool active = path->active;
4269 if (i == spec->cur_mux[c])
4270 active = true;
4271 activate_path(codec, path, active, false);
4272 }
4273 }
4274 }
4275
4276 alc_inv_dmic_sync(codec, true);
4277 if (spec->shared_mic_hp)
4278 update_shared_mic_hp(codec, spec->cur_mux[0]);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004279}
4280
4281/* add mic boosts if needed */
4282static int alc_auto_add_mic_boost(struct hda_codec *codec)
4283{
4284 struct alc_spec *spec = codec->spec;
4285 struct auto_pin_cfg *cfg = &spec->autocfg;
4286 int i, err;
4287 int type_idx = 0;
4288 hda_nid_t nid;
4289 const char *prev_label = NULL;
4290
4291 for (i = 0; i < cfg->num_inputs; i++) {
4292 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4293 break;
4294 nid = cfg->inputs[i].pin;
4295 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4296 const char *label;
4297 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004298 struct nid_path *path;
4299 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004300
4301 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004302 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4303 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004304 if (prev_label && !strcmp(label, prev_label))
4305 type_idx++;
4306 else
4307 type_idx = 0;
4308 prev_label = label;
4309
4310 snprintf(boost_label, sizeof(boost_label),
4311 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004312 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004313 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004314 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004315 if (err < 0)
4316 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004317
4318 path = get_nid_path(codec, nid, 0);
4319 if (path)
4320 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004321 }
4322 }
4323 return 0;
4324}
4325
Takashi Iwai1d045db2011-07-07 18:23:21 +02004326/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004327 * standard auto-parser initializations
4328 */
4329static void alc_auto_init_std(struct hda_codec *codec)
4330{
Takashi Iwaie4770622011-07-08 11:11:35 +02004331 alc_auto_init_multi_out(codec);
4332 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004333 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004334 alc_auto_init_analog_input(codec);
4335 alc_auto_init_input_src(codec);
4336 alc_auto_init_digital(codec);
Takashi Iwai2eab6942012-12-18 15:30:41 +01004337 /* call init functions of standard auto-mute helpers */
4338 alc_hp_automute(codec, NULL);
4339 alc_line_automute(codec, NULL);
4340 alc_mic_automute(codec, NULL);
Takashi Iwaie4770622011-07-08 11:11:35 +02004341}
4342
4343/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004344 * Digital-beep handlers
4345 */
4346#ifdef CONFIG_SND_HDA_INPUT_BEEP
4347#define set_beep_amp(spec, nid, idx, dir) \
4348 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4349
4350static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004351 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004352 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4353 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4354 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4355 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004356 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004357 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4358 {}
4359};
4360
4361static inline int has_cdefine_beep(struct hda_codec *codec)
4362{
4363 struct alc_spec *spec = codec->spec;
4364 const struct snd_pci_quirk *q;
4365 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4366 if (q)
4367 return q->value;
4368 return spec->cdefine.enable_pcbeep;
4369}
4370#else
4371#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4372#define has_cdefine_beep(codec) 0
4373#endif
4374
4375/* parse the BIOS configuration and set up the alc_spec */
4376/* return 1 if successful, 0 if the proper config is not found,
4377 * or a negative error code
4378 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004379static int alc_parse_auto_config(struct hda_codec *codec,
4380 const hda_nid_t *ignore_nids,
4381 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004382{
4383 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004384 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004386
Takashi Iwai53c334a2011-08-23 18:27:14 +02004387 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4388 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004389 if (err < 0)
4390 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004391 if (!cfg->line_outs) {
4392 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004393 spec->multiout.max_channels = 2;
4394 spec->no_analog = 1;
4395 goto dig_only;
4396 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004397 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004398 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004399
Takashi Iwaie427c232012-07-29 10:04:08 +02004400 if (!spec->no_primary_hp &&
4401 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004402 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004403 /* use HP as primary out */
4404 cfg->speaker_outs = cfg->line_outs;
4405 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4406 sizeof(cfg->speaker_pins));
4407 cfg->line_outs = cfg->hp_outs;
4408 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4409 cfg->hp_outs = 0;
4410 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4411 cfg->line_out_type = AUTO_PIN_HP_OUT;
4412 }
4413
Takashi Iwai1d045db2011-07-07 18:23:21 +02004414 err = alc_auto_fill_dac_nids(codec);
4415 if (err < 0)
4416 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004417 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004418 if (err < 0)
4419 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004420 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004421 if (err < 0)
4422 return err;
4423 err = alc_auto_create_hp_out(codec);
4424 if (err < 0)
4425 return err;
4426 err = alc_auto_create_speaker_out(codec);
4427 if (err < 0)
4428 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004429 err = alc_auto_create_shared_input(codec);
4430 if (err < 0)
4431 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004432 err = alc_auto_create_input_ctls(codec);
4433 if (err < 0)
4434 return err;
4435
Takashi Iwaib6adb572012-12-03 10:30:58 +01004436 /* check the multiple speaker pins */
4437 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4438 spec->const_channel_count = cfg->line_outs * 2;
4439 else
4440 spec->const_channel_count = cfg->speaker_outs * 2;
4441
4442 if (spec->multi_ios > 0)
4443 spec->multiout.max_channels = max(spec->ext_channel_count,
4444 spec->const_channel_count);
4445 else
4446 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004447
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004448 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004449 alc_auto_parse_digital(codec);
4450
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004451 if (ssid_nids)
4452 alc_ssid_check(codec, ssid_nids);
4453
4454 if (!spec->no_analog) {
Takashi Iwai666a70d2012-12-17 20:29:29 +01004455 err = alc_init_automute(codec);
Takashi Iwai475c3d22012-11-30 08:31:30 +01004456 if (err < 0)
4457 return err;
Takashi Iwai666a70d2012-12-17 20:29:29 +01004458
4459 err = check_dyn_adc_switch(codec);
4460 if (err < 0)
4461 return err;
4462
4463 if (!spec->shared_mic_hp) {
4464 err = alc_init_auto_mic(codec);
4465 if (err < 0)
4466 return err;
4467 }
4468
4469 err = create_capture_mixers(codec);
4470 if (err < 0)
4471 return err;
4472
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004473 err = alc_auto_add_mic_boost(codec);
4474 if (err < 0)
4475 return err;
4476 }
4477
Takashi Iwai1d045db2011-07-07 18:23:21 +02004478 if (spec->kctls.list)
4479 add_mixer(spec, spec->kctls.list);
4480
Takashi Iwai1d045db2011-07-07 18:23:21 +02004481 return 1;
4482}
4483
Takashi Iwai3de95172012-05-07 18:03:15 +02004484/* common preparation job for alc_spec */
4485static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4486{
4487 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4488 int err;
4489
4490 if (!spec)
4491 return -ENOMEM;
4492 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004493 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004494 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004495 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004496 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4497 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004498 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004499
4500 err = alc_codec_rename_from_preset(codec);
4501 if (err < 0) {
4502 kfree(spec);
4503 return err;
4504 }
4505 return 0;
4506}
4507
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004508static int alc880_parse_auto_config(struct hda_codec *codec)
4509{
4510 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004511 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004512 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4513}
4514
Takashi Iwai1d045db2011-07-07 18:23:21 +02004515/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004516 * ALC880 fix-ups
4517 */
4518enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004519 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004520 ALC880_FIXUP_GPIO2,
4521 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004522 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004523 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004524 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004525 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004526 ALC880_FIXUP_VOL_KNOB,
4527 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004528 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004529 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004530 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004531 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004532 ALC880_FIXUP_3ST_BASE,
4533 ALC880_FIXUP_3ST,
4534 ALC880_FIXUP_3ST_DIG,
4535 ALC880_FIXUP_5ST_BASE,
4536 ALC880_FIXUP_5ST,
4537 ALC880_FIXUP_5ST_DIG,
4538 ALC880_FIXUP_6ST_BASE,
4539 ALC880_FIXUP_6ST,
4540 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004541};
4542
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004543/* enable the volume-knob widget support on NID 0x21 */
4544static void alc880_fixup_vol_knob(struct hda_codec *codec,
4545 const struct alc_fixup *fix, int action)
4546{
4547 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004548 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004549}
4550
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004551static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004552 [ALC880_FIXUP_GPIO1] = {
4553 .type = ALC_FIXUP_VERBS,
4554 .v.verbs = alc_gpio1_init_verbs,
4555 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004556 [ALC880_FIXUP_GPIO2] = {
4557 .type = ALC_FIXUP_VERBS,
4558 .v.verbs = alc_gpio2_init_verbs,
4559 },
4560 [ALC880_FIXUP_MEDION_RIM] = {
4561 .type = ALC_FIXUP_VERBS,
4562 .v.verbs = (const struct hda_verb[]) {
4563 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4564 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4565 { }
4566 },
4567 .chained = true,
4568 .chain_id = ALC880_FIXUP_GPIO2,
4569 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004570 [ALC880_FIXUP_LG] = {
4571 .type = ALC_FIXUP_PINS,
4572 .v.pins = (const struct alc_pincfg[]) {
4573 /* disable bogus unused pins */
4574 { 0x16, 0x411111f0 },
4575 { 0x18, 0x411111f0 },
4576 { 0x1a, 0x411111f0 },
4577 { }
4578 }
4579 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004580 [ALC880_FIXUP_W810] = {
4581 .type = ALC_FIXUP_PINS,
4582 .v.pins = (const struct alc_pincfg[]) {
4583 /* disable bogus unused pins */
4584 { 0x17, 0x411111f0 },
4585 { }
4586 },
4587 .chained = true,
4588 .chain_id = ALC880_FIXUP_GPIO2,
4589 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004590 [ALC880_FIXUP_EAPD_COEF] = {
4591 .type = ALC_FIXUP_VERBS,
4592 .v.verbs = (const struct hda_verb[]) {
4593 /* change to EAPD mode */
4594 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4595 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4596 {}
4597 },
4598 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004599 [ALC880_FIXUP_TCL_S700] = {
4600 .type = ALC_FIXUP_VERBS,
4601 .v.verbs = (const struct hda_verb[]) {
4602 /* change to EAPD mode */
4603 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4604 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4605 {}
4606 },
4607 .chained = true,
4608 .chain_id = ALC880_FIXUP_GPIO2,
4609 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004610 [ALC880_FIXUP_VOL_KNOB] = {
4611 .type = ALC_FIXUP_FUNC,
4612 .v.func = alc880_fixup_vol_knob,
4613 },
4614 [ALC880_FIXUP_FUJITSU] = {
4615 /* override all pins as BIOS on old Amilo is broken */
4616 .type = ALC_FIXUP_PINS,
4617 .v.pins = (const struct alc_pincfg[]) {
4618 { 0x14, 0x0121411f }, /* HP */
4619 { 0x15, 0x99030120 }, /* speaker */
4620 { 0x16, 0x99030130 }, /* bass speaker */
4621 { 0x17, 0x411111f0 }, /* N/A */
4622 { 0x18, 0x411111f0 }, /* N/A */
4623 { 0x19, 0x01a19950 }, /* mic-in */
4624 { 0x1a, 0x411111f0 }, /* N/A */
4625 { 0x1b, 0x411111f0 }, /* N/A */
4626 { 0x1c, 0x411111f0 }, /* N/A */
4627 { 0x1d, 0x411111f0 }, /* N/A */
4628 { 0x1e, 0x01454140 }, /* SPDIF out */
4629 { }
4630 },
4631 .chained = true,
4632 .chain_id = ALC880_FIXUP_VOL_KNOB,
4633 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004634 [ALC880_FIXUP_F1734] = {
4635 /* almost compatible with FUJITSU, but no bass and SPDIF */
4636 .type = ALC_FIXUP_PINS,
4637 .v.pins = (const struct alc_pincfg[]) {
4638 { 0x14, 0x0121411f }, /* HP */
4639 { 0x15, 0x99030120 }, /* speaker */
4640 { 0x16, 0x411111f0 }, /* N/A */
4641 { 0x17, 0x411111f0 }, /* N/A */
4642 { 0x18, 0x411111f0 }, /* N/A */
4643 { 0x19, 0x01a19950 }, /* mic-in */
4644 { 0x1a, 0x411111f0 }, /* N/A */
4645 { 0x1b, 0x411111f0 }, /* N/A */
4646 { 0x1c, 0x411111f0 }, /* N/A */
4647 { 0x1d, 0x411111f0 }, /* N/A */
4648 { 0x1e, 0x411111f0 }, /* N/A */
4649 { }
4650 },
4651 .chained = true,
4652 .chain_id = ALC880_FIXUP_VOL_KNOB,
4653 },
Takashi Iwai817de922012-02-20 17:20:48 +01004654 [ALC880_FIXUP_UNIWILL] = {
4655 /* need to fix HP and speaker pins to be parsed correctly */
4656 .type = ALC_FIXUP_PINS,
4657 .v.pins = (const struct alc_pincfg[]) {
4658 { 0x14, 0x0121411f }, /* HP */
4659 { 0x15, 0x99030120 }, /* speaker */
4660 { 0x16, 0x99030130 }, /* bass speaker */
4661 { }
4662 },
4663 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004664 [ALC880_FIXUP_UNIWILL_DIG] = {
4665 .type = ALC_FIXUP_PINS,
4666 .v.pins = (const struct alc_pincfg[]) {
4667 /* disable bogus unused pins */
4668 { 0x17, 0x411111f0 },
4669 { 0x19, 0x411111f0 },
4670 { 0x1b, 0x411111f0 },
4671 { 0x1f, 0x411111f0 },
4672 { }
4673 }
4674 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004675 [ALC880_FIXUP_Z71V] = {
4676 .type = ALC_FIXUP_PINS,
4677 .v.pins = (const struct alc_pincfg[]) {
4678 /* set up the whole pins as BIOS is utterly broken */
4679 { 0x14, 0x99030120 }, /* speaker */
4680 { 0x15, 0x0121411f }, /* HP */
4681 { 0x16, 0x411111f0 }, /* N/A */
4682 { 0x17, 0x411111f0 }, /* N/A */
4683 { 0x18, 0x01a19950 }, /* mic-in */
4684 { 0x19, 0x411111f0 }, /* N/A */
4685 { 0x1a, 0x01813031 }, /* line-in */
4686 { 0x1b, 0x411111f0 }, /* N/A */
4687 { 0x1c, 0x411111f0 }, /* N/A */
4688 { 0x1d, 0x411111f0 }, /* N/A */
4689 { 0x1e, 0x0144111e }, /* SPDIF */
4690 { }
4691 }
4692 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004693 [ALC880_FIXUP_3ST_BASE] = {
4694 .type = ALC_FIXUP_PINS,
4695 .v.pins = (const struct alc_pincfg[]) {
4696 { 0x14, 0x01014010 }, /* line-out */
4697 { 0x15, 0x411111f0 }, /* N/A */
4698 { 0x16, 0x411111f0 }, /* N/A */
4699 { 0x17, 0x411111f0 }, /* N/A */
4700 { 0x18, 0x01a19c30 }, /* mic-in */
4701 { 0x19, 0x0121411f }, /* HP */
4702 { 0x1a, 0x01813031 }, /* line-in */
4703 { 0x1b, 0x02a19c40 }, /* front-mic */
4704 { 0x1c, 0x411111f0 }, /* N/A */
4705 { 0x1d, 0x411111f0 }, /* N/A */
4706 /* 0x1e is filled in below */
4707 { 0x1f, 0x411111f0 }, /* N/A */
4708 { }
4709 }
4710 },
4711 [ALC880_FIXUP_3ST] = {
4712 .type = ALC_FIXUP_PINS,
4713 .v.pins = (const struct alc_pincfg[]) {
4714 { 0x1e, 0x411111f0 }, /* N/A */
4715 { }
4716 },
4717 .chained = true,
4718 .chain_id = ALC880_FIXUP_3ST_BASE,
4719 },
4720 [ALC880_FIXUP_3ST_DIG] = {
4721 .type = ALC_FIXUP_PINS,
4722 .v.pins = (const struct alc_pincfg[]) {
4723 { 0x1e, 0x0144111e }, /* SPDIF */
4724 { }
4725 },
4726 .chained = true,
4727 .chain_id = ALC880_FIXUP_3ST_BASE,
4728 },
4729 [ALC880_FIXUP_5ST_BASE] = {
4730 .type = ALC_FIXUP_PINS,
4731 .v.pins = (const struct alc_pincfg[]) {
4732 { 0x14, 0x01014010 }, /* front */
4733 { 0x15, 0x411111f0 }, /* N/A */
4734 { 0x16, 0x01011411 }, /* CLFE */
4735 { 0x17, 0x01016412 }, /* surr */
4736 { 0x18, 0x01a19c30 }, /* mic-in */
4737 { 0x19, 0x0121411f }, /* HP */
4738 { 0x1a, 0x01813031 }, /* line-in */
4739 { 0x1b, 0x02a19c40 }, /* front-mic */
4740 { 0x1c, 0x411111f0 }, /* N/A */
4741 { 0x1d, 0x411111f0 }, /* N/A */
4742 /* 0x1e is filled in below */
4743 { 0x1f, 0x411111f0 }, /* N/A */
4744 { }
4745 }
4746 },
4747 [ALC880_FIXUP_5ST] = {
4748 .type = ALC_FIXUP_PINS,
4749 .v.pins = (const struct alc_pincfg[]) {
4750 { 0x1e, 0x411111f0 }, /* N/A */
4751 { }
4752 },
4753 .chained = true,
4754 .chain_id = ALC880_FIXUP_5ST_BASE,
4755 },
4756 [ALC880_FIXUP_5ST_DIG] = {
4757 .type = ALC_FIXUP_PINS,
4758 .v.pins = (const struct alc_pincfg[]) {
4759 { 0x1e, 0x0144111e }, /* SPDIF */
4760 { }
4761 },
4762 .chained = true,
4763 .chain_id = ALC880_FIXUP_5ST_BASE,
4764 },
4765 [ALC880_FIXUP_6ST_BASE] = {
4766 .type = ALC_FIXUP_PINS,
4767 .v.pins = (const struct alc_pincfg[]) {
4768 { 0x14, 0x01014010 }, /* front */
4769 { 0x15, 0x01016412 }, /* surr */
4770 { 0x16, 0x01011411 }, /* CLFE */
4771 { 0x17, 0x01012414 }, /* side */
4772 { 0x18, 0x01a19c30 }, /* mic-in */
4773 { 0x19, 0x02a19c40 }, /* front-mic */
4774 { 0x1a, 0x01813031 }, /* line-in */
4775 { 0x1b, 0x0121411f }, /* HP */
4776 { 0x1c, 0x411111f0 }, /* N/A */
4777 { 0x1d, 0x411111f0 }, /* N/A */
4778 /* 0x1e is filled in below */
4779 { 0x1f, 0x411111f0 }, /* N/A */
4780 { }
4781 }
4782 },
4783 [ALC880_FIXUP_6ST] = {
4784 .type = ALC_FIXUP_PINS,
4785 .v.pins = (const struct alc_pincfg[]) {
4786 { 0x1e, 0x411111f0 }, /* N/A */
4787 { }
4788 },
4789 .chained = true,
4790 .chain_id = ALC880_FIXUP_6ST_BASE,
4791 },
4792 [ALC880_FIXUP_6ST_DIG] = {
4793 .type = ALC_FIXUP_PINS,
4794 .v.pins = (const struct alc_pincfg[]) {
4795 { 0x1e, 0x0144111e }, /* SPDIF */
4796 { }
4797 },
4798 .chained = true,
4799 .chain_id = ALC880_FIXUP_6ST_BASE,
4800 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004801};
4802
4803static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004804 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004805 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004806 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4807 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004808 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004809 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004810 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004811 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004812 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004813 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004814 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004815 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004816 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004817 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004818 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004819 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4820 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4821 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004822 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004823
4824 /* Below is the copied entries from alc880_quirks.c.
4825 * It's not quite sure whether BIOS sets the correct pin-config table
4826 * on these machines, thus they are kept to be compatible with
4827 * the old static quirks. Once when it's confirmed to work without
4828 * these overrides, it'd be better to remove.
4829 */
4830 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4831 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4832 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4833 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4834 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4835 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4836 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4837 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4838 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4839 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4840 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4841 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4842 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4843 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4844 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4845 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4846 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4847 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4848 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4849 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4850 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4851 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4852 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4853 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4854 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4855 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4856 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4857 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4858 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4859 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4860 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4861 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4862 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4863 /* default Intel */
4864 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4865 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4866 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4867 {}
4868};
4869
4870static const struct alc_model_fixup alc880_fixup_models[] = {
4871 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4872 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4873 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4874 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4875 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4876 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004877 {}
4878};
4879
4880
4881/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004882 * OK, here we have finally the patch for ALC880
4883 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004884static int patch_alc880(struct hda_codec *codec)
4885{
4886 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004887 int err;
4888
Takashi Iwai3de95172012-05-07 18:03:15 +02004889 err = alc_alloc_spec(codec, 0x0b);
4890 if (err < 0)
4891 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004892
Takashi Iwai3de95172012-05-07 18:03:15 +02004893 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004894 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004895
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004896 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4897 alc880_fixups);
4898 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004899
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004900 /* automatic parse from the BIOS config */
4901 err = alc880_parse_auto_config(codec);
4902 if (err < 0)
4903 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004904
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004905 if (!spec->no_analog) {
4906 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004907 if (err < 0)
4908 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004909 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4910 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004911
Takashi Iwai1d045db2011-07-07 18:23:21 +02004912 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004913 codec->patch_ops.unsol_event = alc880_unsol_event;
4914
Takashi Iwai1d045db2011-07-07 18:23:21 +02004915
Takashi Iwai589876e2012-02-20 15:47:55 +01004916 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4917
Takashi Iwai1d045db2011-07-07 18:23:21 +02004918 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004919
4920 error:
4921 alc_free(codec);
4922 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004923}
4924
4925
4926/*
4927 * ALC260 support
4928 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004929static int alc260_parse_auto_config(struct hda_codec *codec)
4930{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004931 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004932 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4933 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004934}
4935
Takashi Iwai1d045db2011-07-07 18:23:21 +02004936/*
4937 * Pin config fixes
4938 */
4939enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004940 ALC260_FIXUP_HP_DC5750,
4941 ALC260_FIXUP_HP_PIN_0F,
4942 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004943 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004944 ALC260_FIXUP_GPIO1_TOGGLE,
4945 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004946 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004947 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004948};
4949
Takashi Iwai20f7d922012-02-16 12:35:16 +01004950static void alc260_gpio1_automute(struct hda_codec *codec)
4951{
4952 struct alc_spec *spec = codec->spec;
4953 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4954 spec->hp_jack_present);
4955}
4956
4957static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4958 const struct alc_fixup *fix, int action)
4959{
4960 struct alc_spec *spec = codec->spec;
4961 if (action == ALC_FIXUP_ACT_PROBE) {
4962 /* although the machine has only one output pin, we need to
4963 * toggle GPIO1 according to the jack state
4964 */
4965 spec->automute_hook = alc260_gpio1_automute;
4966 spec->detect_hp = 1;
4967 spec->automute_speaker = 1;
4968 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004969 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4970 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004971 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004972 }
4973}
4974
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004975static void alc260_fixup_kn1(struct hda_codec *codec,
4976 const struct alc_fixup *fix, int action)
4977{
4978 struct alc_spec *spec = codec->spec;
4979 static const struct alc_pincfg pincfgs[] = {
4980 { 0x0f, 0x02214000 }, /* HP/speaker */
4981 { 0x12, 0x90a60160 }, /* int mic */
4982 { 0x13, 0x02a19000 }, /* ext mic */
4983 { 0x18, 0x01446000 }, /* SPDIF out */
4984 /* disable bogus I/O pins */
4985 { 0x10, 0x411111f0 },
4986 { 0x11, 0x411111f0 },
4987 { 0x14, 0x411111f0 },
4988 { 0x15, 0x411111f0 },
4989 { 0x16, 0x411111f0 },
4990 { 0x17, 0x411111f0 },
4991 { 0x19, 0x411111f0 },
4992 { }
4993 };
4994
4995 switch (action) {
4996 case ALC_FIXUP_ACT_PRE_PROBE:
4997 alc_apply_pincfgs(codec, pincfgs);
4998 break;
4999 case ALC_FIXUP_ACT_PROBE:
5000 spec->init_amp = ALC_INIT_NONE;
5001 break;
5002 }
5003}
5004
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005006 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005007 .type = ALC_FIXUP_PINS,
5008 .v.pins = (const struct alc_pincfg[]) {
5009 { 0x11, 0x90130110 }, /* speaker */
5010 { }
5011 }
5012 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005013 [ALC260_FIXUP_HP_PIN_0F] = {
5014 .type = ALC_FIXUP_PINS,
5015 .v.pins = (const struct alc_pincfg[]) {
5016 { 0x0f, 0x01214000 }, /* HP */
5017 { }
5018 }
5019 },
5020 [ALC260_FIXUP_COEF] = {
5021 .type = ALC_FIXUP_VERBS,
5022 .v.verbs = (const struct hda_verb[]) {
5023 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5024 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5025 { }
5026 },
5027 .chained = true,
5028 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5029 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005030 [ALC260_FIXUP_GPIO1] = {
5031 .type = ALC_FIXUP_VERBS,
5032 .v.verbs = alc_gpio1_init_verbs,
5033 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005034 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5035 .type = ALC_FIXUP_FUNC,
5036 .v.func = alc260_fixup_gpio1_toggle,
5037 .chained = true,
5038 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5039 },
5040 [ALC260_FIXUP_REPLACER] = {
5041 .type = ALC_FIXUP_VERBS,
5042 .v.verbs = (const struct hda_verb[]) {
5043 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5044 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5045 { }
5046 },
5047 .chained = true,
5048 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5049 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005050 [ALC260_FIXUP_HP_B1900] = {
5051 .type = ALC_FIXUP_FUNC,
5052 .v.func = alc260_fixup_gpio1_toggle,
5053 .chained = true,
5054 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005055 },
5056 [ALC260_FIXUP_KN1] = {
5057 .type = ALC_FIXUP_FUNC,
5058 .v.func = alc260_fixup_kn1,
5059 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005060};
5061
5062static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005063 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005064 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005065 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005066 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005067 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005068 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005069 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005070 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005071 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005072 {}
5073};
5074
5075/*
5076 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005077static int patch_alc260(struct hda_codec *codec)
5078{
5079 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005080 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081
Takashi Iwai3de95172012-05-07 18:03:15 +02005082 err = alc_alloc_spec(codec, 0x07);
5083 if (err < 0)
5084 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005085
Takashi Iwai3de95172012-05-07 18:03:15 +02005086 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005087
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005088 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5089 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005090
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005091 /* automatic parse from the BIOS config */
5092 err = alc260_parse_auto_config(codec);
5093 if (err < 0)
5094 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005095
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005096 if (!spec->no_analog) {
5097 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005098 if (err < 0)
5099 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005100 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5101 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005102
Takashi Iwai1d045db2011-07-07 18:23:21 +02005103 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005104 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005105
Takashi Iwai589876e2012-02-20 15:47:55 +01005106 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5107
Takashi Iwai1d045db2011-07-07 18:23:21 +02005108 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005109
5110 error:
5111 alc_free(codec);
5112 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005113}
5114
5115
5116/*
5117 * ALC882/883/885/888/889 support
5118 *
5119 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5120 * configuration. Each pin widget can choose any input DACs and a mixer.
5121 * Each ADC is connected from a mixer of all inputs. This makes possible
5122 * 6-channel independent captures.
5123 *
5124 * In addition, an independent DAC for the multi-playback (not used in this
5125 * driver yet).
5126 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005127
5128/*
5129 * Pin config fixes
5130 */
5131enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005132 ALC882_FIXUP_ABIT_AW9D_MAX,
5133 ALC882_FIXUP_LENOVO_Y530,
5134 ALC882_FIXUP_PB_M5210,
5135 ALC882_FIXUP_ACER_ASPIRE_7736,
5136 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005137 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005138 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005139 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005140 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005141 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005142 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005143 ALC882_FIXUP_GPIO1,
5144 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005145 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005146 ALC889_FIXUP_COEF,
5147 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005148 ALC882_FIXUP_ACER_ASPIRE_4930G,
5149 ALC882_FIXUP_ACER_ASPIRE_8930G,
5150 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005151 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005152 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005153 ALC889_FIXUP_MBP_VREF,
5154 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005155 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005156 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005157};
5158
Takashi Iwai68ef0562011-11-09 18:24:44 +01005159static void alc889_fixup_coef(struct hda_codec *codec,
5160 const struct alc_fixup *fix, int action)
5161{
5162 if (action != ALC_FIXUP_ACT_INIT)
5163 return;
5164 alc889_coef_init(codec);
5165}
5166
Takashi Iwai56710872011-11-14 17:42:11 +01005167/* toggle speaker-output according to the hp-jack state */
5168static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5169{
5170 unsigned int gpiostate, gpiomask, gpiodir;
5171
5172 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5173 AC_VERB_GET_GPIO_DATA, 0);
5174
5175 if (!muted)
5176 gpiostate |= (1 << pin);
5177 else
5178 gpiostate &= ~(1 << pin);
5179
5180 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5181 AC_VERB_GET_GPIO_MASK, 0);
5182 gpiomask |= (1 << pin);
5183
5184 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5185 AC_VERB_GET_GPIO_DIRECTION, 0);
5186 gpiodir |= (1 << pin);
5187
5188
5189 snd_hda_codec_write(codec, codec->afg, 0,
5190 AC_VERB_SET_GPIO_MASK, gpiomask);
5191 snd_hda_codec_write(codec, codec->afg, 0,
5192 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5193
5194 msleep(1);
5195
5196 snd_hda_codec_write(codec, codec->afg, 0,
5197 AC_VERB_SET_GPIO_DATA, gpiostate);
5198}
5199
5200/* set up GPIO at initialization */
5201static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5202 const struct alc_fixup *fix, int action)
5203{
5204 if (action != ALC_FIXUP_ACT_INIT)
5205 return;
5206 alc882_gpio_mute(codec, 0, 0);
5207 alc882_gpio_mute(codec, 1, 0);
5208}
5209
Takashi Iwai02a237b2012-02-13 15:25:07 +01005210/* Fix the connection of some pins for ALC889:
5211 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5212 * work correctly (bko#42740)
5213 */
5214static void alc889_fixup_dac_route(struct hda_codec *codec,
5215 const struct alc_fixup *fix, int action)
5216{
5217 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005218 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005219 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5220 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5221 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5222 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5223 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5224 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005225 } else if (action == ALC_FIXUP_ACT_PROBE) {
5226 /* restore the connections */
5227 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5228 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5229 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5230 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5231 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005232 }
5233}
5234
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005235/* Set VREF on HP pin */
5236static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5237 const struct alc_fixup *fix, int action)
5238{
5239 struct alc_spec *spec = codec->spec;
5240 static hda_nid_t nids[2] = { 0x14, 0x15 };
5241 int i;
5242
5243 if (action != ALC_FIXUP_ACT_INIT)
5244 return;
5245 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5246 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5247 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5248 continue;
5249 val = snd_hda_codec_read(codec, nids[i], 0,
5250 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5251 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005252 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005253 spec->keep_vref_in_automute = 1;
5254 break;
5255 }
5256}
5257
5258/* Set VREF on speaker pins on imac91 */
5259static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5260 const struct alc_fixup *fix, int action)
5261{
5262 struct alc_spec *spec = codec->spec;
5263 static hda_nid_t nids[2] = { 0x18, 0x1a };
5264 int i;
5265
5266 if (action != ALC_FIXUP_ACT_INIT)
5267 return;
5268 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5269 unsigned int val;
5270 val = snd_hda_codec_read(codec, nids[i], 0,
5271 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5272 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005273 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005274 }
5275 spec->keep_vref_in_automute = 1;
5276}
5277
Takashi Iwaie427c232012-07-29 10:04:08 +02005278/* Don't take HP output as primary
5279 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5280 */
5281static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5282 const struct alc_fixup *fix, int action)
5283{
5284 struct alc_spec *spec = codec->spec;
5285 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5286 spec->no_primary_hp = 1;
5287}
5288
Takashi Iwai1d045db2011-07-07 18:23:21 +02005289static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005290 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005291 .type = ALC_FIXUP_PINS,
5292 .v.pins = (const struct alc_pincfg[]) {
5293 { 0x15, 0x01080104 }, /* side */
5294 { 0x16, 0x01011012 }, /* rear */
5295 { 0x17, 0x01016011 }, /* clfe */
5296 { }
5297 }
5298 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005299 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005300 .type = ALC_FIXUP_PINS,
5301 .v.pins = (const struct alc_pincfg[]) {
5302 { 0x15, 0x99130112 }, /* rear int speakers */
5303 { 0x16, 0x99130111 }, /* subwoofer */
5304 { }
5305 }
5306 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005307 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005308 .type = ALC_FIXUP_VERBS,
5309 .v.verbs = (const struct hda_verb[]) {
5310 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5311 {}
5312 }
5313 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005314 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005315 .type = ALC_FIXUP_FUNC,
5316 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005317 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005318 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005319 .type = ALC_FIXUP_PINS,
5320 .v.pins = (const struct alc_pincfg[]) {
5321 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5322 { }
5323 }
5324 },
Marton Balint8f239212012-03-05 21:33:23 +01005325 [ALC889_FIXUP_CD] = {
5326 .type = ALC_FIXUP_PINS,
5327 .v.pins = (const struct alc_pincfg[]) {
5328 { 0x1c, 0x993301f0 }, /* CD */
5329 { }
5330 }
5331 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005332 [ALC889_FIXUP_VAIO_TT] = {
5333 .type = ALC_FIXUP_PINS,
5334 .v.pins = (const struct alc_pincfg[]) {
5335 { 0x17, 0x90170111 }, /* hidden surround speaker */
5336 { }
5337 }
5338 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005339 [ALC888_FIXUP_EEE1601] = {
5340 .type = ALC_FIXUP_VERBS,
5341 .v.verbs = (const struct hda_verb[]) {
5342 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5343 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5344 { }
5345 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005346 },
5347 [ALC882_FIXUP_EAPD] = {
5348 .type = ALC_FIXUP_VERBS,
5349 .v.verbs = (const struct hda_verb[]) {
5350 /* change to EAPD mode */
5351 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5352 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5353 { }
5354 }
5355 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005356 [ALC883_FIXUP_EAPD] = {
5357 .type = ALC_FIXUP_VERBS,
5358 .v.verbs = (const struct hda_verb[]) {
5359 /* change to EAPD mode */
5360 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5361 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5362 { }
5363 }
5364 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005365 [ALC883_FIXUP_ACER_EAPD] = {
5366 .type = ALC_FIXUP_VERBS,
5367 .v.verbs = (const struct hda_verb[]) {
5368 /* eanable EAPD on Acer laptops */
5369 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5370 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5371 { }
5372 }
5373 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005374 [ALC882_FIXUP_GPIO1] = {
5375 .type = ALC_FIXUP_VERBS,
5376 .v.verbs = alc_gpio1_init_verbs,
5377 },
5378 [ALC882_FIXUP_GPIO2] = {
5379 .type = ALC_FIXUP_VERBS,
5380 .v.verbs = alc_gpio2_init_verbs,
5381 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005382 [ALC882_FIXUP_GPIO3] = {
5383 .type = ALC_FIXUP_VERBS,
5384 .v.verbs = alc_gpio3_init_verbs,
5385 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005386 [ALC882_FIXUP_ASUS_W2JC] = {
5387 .type = ALC_FIXUP_VERBS,
5388 .v.verbs = alc_gpio1_init_verbs,
5389 .chained = true,
5390 .chain_id = ALC882_FIXUP_EAPD,
5391 },
5392 [ALC889_FIXUP_COEF] = {
5393 .type = ALC_FIXUP_FUNC,
5394 .v.func = alc889_fixup_coef,
5395 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005396 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5397 .type = ALC_FIXUP_PINS,
5398 .v.pins = (const struct alc_pincfg[]) {
5399 { 0x16, 0x99130111 }, /* CLFE speaker */
5400 { 0x17, 0x99130112 }, /* surround speaker */
5401 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005402 },
5403 .chained = true,
5404 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005405 },
5406 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5407 .type = ALC_FIXUP_PINS,
5408 .v.pins = (const struct alc_pincfg[]) {
5409 { 0x16, 0x99130111 }, /* CLFE speaker */
5410 { 0x1b, 0x99130112 }, /* surround speaker */
5411 { }
5412 },
5413 .chained = true,
5414 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5415 },
5416 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5417 /* additional init verbs for Acer Aspire 8930G */
5418 .type = ALC_FIXUP_VERBS,
5419 .v.verbs = (const struct hda_verb[]) {
5420 /* Enable all DACs */
5421 /* DAC DISABLE/MUTE 1? */
5422 /* setting bits 1-5 disables DAC nids 0x02-0x06
5423 * apparently. Init=0x38 */
5424 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5425 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5426 /* DAC DISABLE/MUTE 2? */
5427 /* some bit here disables the other DACs.
5428 * Init=0x4900 */
5429 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5430 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5431 /* DMIC fix
5432 * This laptop has a stereo digital microphone.
5433 * The mics are only 1cm apart which makes the stereo
5434 * useless. However, either the mic or the ALC889
5435 * makes the signal become a difference/sum signal
5436 * instead of standard stereo, which is annoying.
5437 * So instead we flip this bit which makes the
5438 * codec replicate the sum signal to both channels,
5439 * turning it into a normal mono mic.
5440 */
5441 /* DMIC_CONTROL? Init value = 0x0001 */
5442 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5443 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5444 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5445 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5446 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005447 },
5448 .chained = true,
5449 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005450 },
Takashi Iwai56710872011-11-14 17:42:11 +01005451 [ALC885_FIXUP_MACPRO_GPIO] = {
5452 .type = ALC_FIXUP_FUNC,
5453 .v.func = alc885_fixup_macpro_gpio,
5454 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005455 [ALC889_FIXUP_DAC_ROUTE] = {
5456 .type = ALC_FIXUP_FUNC,
5457 .v.func = alc889_fixup_dac_route,
5458 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005459 [ALC889_FIXUP_MBP_VREF] = {
5460 .type = ALC_FIXUP_FUNC,
5461 .v.func = alc889_fixup_mbp_vref,
5462 .chained = true,
5463 .chain_id = ALC882_FIXUP_GPIO1,
5464 },
5465 [ALC889_FIXUP_IMAC91_VREF] = {
5466 .type = ALC_FIXUP_FUNC,
5467 .v.func = alc889_fixup_imac91_vref,
5468 .chained = true,
5469 .chain_id = ALC882_FIXUP_GPIO1,
5470 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005471 [ALC882_FIXUP_INV_DMIC] = {
5472 .type = ALC_FIXUP_FUNC,
5473 .v.func = alc_fixup_inv_dmic_0x12,
5474 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005475 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5476 .type = ALC_FIXUP_FUNC,
5477 .v.func = alc882_fixup_no_primary_hp,
5478 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005479};
5480
5481static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005482 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5483 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5484 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5485 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5486 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5487 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005488 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5489 ALC882_FIXUP_ACER_ASPIRE_4930G),
5490 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5491 ALC882_FIXUP_ACER_ASPIRE_4930G),
5492 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5493 ALC882_FIXUP_ACER_ASPIRE_8930G),
5494 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5495 ALC882_FIXUP_ACER_ASPIRE_8930G),
5496 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5497 ALC882_FIXUP_ACER_ASPIRE_4930G),
5498 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5499 ALC882_FIXUP_ACER_ASPIRE_4930G),
5500 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5501 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005502 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005503 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5504 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005505 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005506 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005507 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005508 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005509 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005510 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005511 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005512 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005513 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005514
5515 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005516 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5517 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5518 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005519 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5520 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5521 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005522 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5523 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005524 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005525 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5526 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5527 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5528 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005529 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005530 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5531 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5532 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005533 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005534 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005535 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5536 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5537 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005538
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005539 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005540 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005541 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005542 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005543 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005544 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5545 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005546 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005547 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005548 {}
5549};
5550
Takashi Iwai912093b2012-04-11 14:03:41 +02005551static const struct alc_model_fixup alc882_fixup_models[] = {
5552 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5553 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5554 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005555 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005556 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005557 {}
5558};
5559
Takashi Iwai1d045db2011-07-07 18:23:21 +02005560/*
5561 * BIOS auto configuration
5562 */
5563/* almost identical with ALC880 parser... */
5564static int alc882_parse_auto_config(struct hda_codec *codec)
5565{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005566 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005567 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5568 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005569}
5570
Takashi Iwai1d045db2011-07-07 18:23:21 +02005571/*
5572 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005573static int patch_alc882(struct hda_codec *codec)
5574{
5575 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005576 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005577
Takashi Iwai3de95172012-05-07 18:03:15 +02005578 err = alc_alloc_spec(codec, 0x0b);
5579 if (err < 0)
5580 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005581
Takashi Iwai3de95172012-05-07 18:03:15 +02005582 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005583
5584 switch (codec->vendor_id) {
5585 case 0x10ec0882:
5586 case 0x10ec0885:
5587 break;
5588 default:
5589 /* ALC883 and variants */
5590 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5591 break;
5592 }
5593
Takashi Iwai912093b2012-04-11 14:03:41 +02005594 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5595 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005596 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005597
5598 alc_auto_parse_customize_define(codec);
5599
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005600 /* automatic parse from the BIOS config */
5601 err = alc882_parse_auto_config(codec);
5602 if (err < 0)
5603 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005605 if (!spec->no_analog && has_cdefine_beep(codec)) {
5606 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005607 if (err < 0)
5608 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005609 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005610 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005611
Takashi Iwai1d045db2011-07-07 18:23:21 +02005612 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005613
Takashi Iwai589876e2012-02-20 15:47:55 +01005614 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5615
Takashi Iwai1d045db2011-07-07 18:23:21 +02005616 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005617
5618 error:
5619 alc_free(codec);
5620 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005621}
5622
5623
5624/*
5625 * ALC262 support
5626 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005627static int alc262_parse_auto_config(struct hda_codec *codec)
5628{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005629 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005630 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5631 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005632}
5633
5634/*
5635 * Pin config fixes
5636 */
5637enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005638 ALC262_FIXUP_FSC_H270,
5639 ALC262_FIXUP_HP_Z200,
5640 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005641 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005642 ALC262_FIXUP_BENQ,
5643 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005644 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645};
5646
5647static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005648 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649 .type = ALC_FIXUP_PINS,
5650 .v.pins = (const struct alc_pincfg[]) {
5651 { 0x14, 0x99130110 }, /* speaker */
5652 { 0x15, 0x0221142f }, /* front HP */
5653 { 0x1b, 0x0121141f }, /* rear HP */
5654 { }
5655 }
5656 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005657 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005658 .type = ALC_FIXUP_PINS,
5659 .v.pins = (const struct alc_pincfg[]) {
5660 { 0x16, 0x99130120 }, /* internal speaker */
5661 { }
5662 }
5663 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005664 [ALC262_FIXUP_TYAN] = {
5665 .type = ALC_FIXUP_PINS,
5666 .v.pins = (const struct alc_pincfg[]) {
5667 { 0x14, 0x1993e1f0 }, /* int AUX */
5668 { }
5669 }
5670 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005671 [ALC262_FIXUP_LENOVO_3000] = {
5672 .type = ALC_FIXUP_VERBS,
5673 .v.verbs = (const struct hda_verb[]) {
5674 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005675 {}
5676 },
5677 .chained = true,
5678 .chain_id = ALC262_FIXUP_BENQ,
5679 },
5680 [ALC262_FIXUP_BENQ] = {
5681 .type = ALC_FIXUP_VERBS,
5682 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005683 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5684 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5685 {}
5686 }
5687 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005688 [ALC262_FIXUP_BENQ_T31] = {
5689 .type = ALC_FIXUP_VERBS,
5690 .v.verbs = (const struct hda_verb[]) {
5691 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5692 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5693 {}
5694 }
5695 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005696 [ALC262_FIXUP_INV_DMIC] = {
5697 .type = ALC_FIXUP_FUNC,
5698 .v.func = alc_fixup_inv_dmic_0x12,
5699 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005700};
5701
5702static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005703 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005704 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5705 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005706 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5707 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005708 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005709 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5710 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005711 {}
5712};
5713
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005714static const struct alc_model_fixup alc262_fixup_models[] = {
5715 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5716 {}
5717};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005718
Takashi Iwai1d045db2011-07-07 18:23:21 +02005719/*
5720 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721static int patch_alc262(struct hda_codec *codec)
5722{
5723 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005724 int err;
5725
Takashi Iwai3de95172012-05-07 18:03:15 +02005726 err = alc_alloc_spec(codec, 0x0b);
5727 if (err < 0)
5728 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005729
Takashi Iwai3de95172012-05-07 18:03:15 +02005730 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01005731 spec->shared_mic_vref_pin = 0x18;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005732
5733#if 0
5734 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5735 * under-run
5736 */
5737 {
5738 int tmp;
5739 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5740 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5741 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5742 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5743 }
5744#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5746
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005747 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5748 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005749 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005751 alc_auto_parse_customize_define(codec);
5752
Takashi Iwai42399f72011-11-07 17:18:44 +01005753 /* automatic parse from the BIOS config */
5754 err = alc262_parse_auto_config(codec);
5755 if (err < 0)
5756 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005757
Takashi Iwai1d045db2011-07-07 18:23:21 +02005758 if (!spec->no_analog && has_cdefine_beep(codec)) {
5759 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005760 if (err < 0)
5761 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005762 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005763 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005764
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005766 spec->shutup = alc_eapd_shutup;
5767
Takashi Iwai589876e2012-02-20 15:47:55 +01005768 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5769
Takashi Iwai1d045db2011-07-07 18:23:21 +02005770 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005771
5772 error:
5773 alc_free(codec);
5774 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005775}
5776
5777/*
5778 * ALC268
5779 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005780/* bind Beep switches of both NID 0x0f and 0x10 */
5781static const struct hda_bind_ctls alc268_bind_beep_sw = {
5782 .ops = &snd_hda_bind_sw,
5783 .values = {
5784 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5785 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5786 0
5787 },
5788};
5789
5790static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5791 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5792 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5793 { }
5794};
5795
5796/* set PCBEEP vol = 0, mute connections */
5797static const struct hda_verb alc268_beep_init_verbs[] = {
5798 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5799 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5800 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5801 { }
5802};
5803
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005804enum {
5805 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005806 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005807};
5808
5809static const struct alc_fixup alc268_fixups[] = {
5810 [ALC268_FIXUP_INV_DMIC] = {
5811 .type = ALC_FIXUP_FUNC,
5812 .v.func = alc_fixup_inv_dmic_0x12,
5813 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005814 [ALC268_FIXUP_HP_EAPD] = {
5815 .type = ALC_FIXUP_VERBS,
5816 .v.verbs = (const struct hda_verb[]) {
5817 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5818 {}
5819 }
5820 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005821};
5822
5823static const struct alc_model_fixup alc268_fixup_models[] = {
5824 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005825 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5826 {}
5827};
5828
5829static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5830 /* below is codec SSID since multiple Toshiba laptops have the
5831 * same PCI SSID 1179:ff00
5832 */
5833 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005834 {}
5835};
5836
Takashi Iwai1d045db2011-07-07 18:23:21 +02005837/*
5838 * BIOS auto configuration
5839 */
5840static int alc268_parse_auto_config(struct hda_codec *codec)
5841{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005842 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005843 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005844 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5845 if (err > 0) {
5846 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5847 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005848 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005849 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005850 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005851 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005852}
5853
Takashi Iwai1d045db2011-07-07 18:23:21 +02005854/*
5855 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005856static int patch_alc268(struct hda_codec *codec)
5857{
5858 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005859 int i, has_beep, err;
5860
Takashi Iwai1d045db2011-07-07 18:23:21 +02005861 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005862 err = alc_alloc_spec(codec, 0);
5863 if (err < 0)
5864 return err;
5865
5866 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005867
Takashi Iwaicb766402012-10-20 10:55:21 +02005868 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005869 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5870
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005871 /* automatic parse from the BIOS config */
5872 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005873 if (err < 0)
5874 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005875
Takashi Iwai1d045db2011-07-07 18:23:21 +02005876 has_beep = 0;
5877 for (i = 0; i < spec->num_mixers; i++) {
5878 if (spec->mixers[i] == alc268_beep_mixer) {
5879 has_beep = 1;
5880 break;
5881 }
5882 }
5883
5884 if (has_beep) {
5885 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005886 if (err < 0)
5887 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005888 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5889 /* override the amp caps for beep generator */
5890 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5891 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5892 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5893 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5894 (0 << AC_AMPCAP_MUTE_SHIFT));
5895 }
5896
Takashi Iwai1d045db2011-07-07 18:23:21 +02005897 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005898 spec->shutup = alc_eapd_shutup;
5899
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005900 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5901
Takashi Iwai1d045db2011-07-07 18:23:21 +02005902 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005903
5904 error:
5905 alc_free(codec);
5906 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005907}
5908
5909/*
5910 * ALC269
5911 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005912static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5913 .substreams = 1,
5914 .channels_min = 2,
5915 .channels_max = 8,
5916 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5917 /* NID is set in alc_build_pcms */
5918 .ops = {
5919 .open = alc_playback_pcm_open,
5920 .prepare = alc_playback_pcm_prepare,
5921 .cleanup = alc_playback_pcm_cleanup
5922 },
5923};
5924
5925static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5926 .substreams = 1,
5927 .channels_min = 2,
5928 .channels_max = 2,
5929 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5930 /* NID is set in alc_build_pcms */
5931};
5932
Takashi Iwai1d045db2011-07-07 18:23:21 +02005933/* different alc269-variants */
5934enum {
5935 ALC269_TYPE_ALC269VA,
5936 ALC269_TYPE_ALC269VB,
5937 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005938 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01005939 ALC269_TYPE_ALC280,
5940 ALC269_TYPE_ALC282,
5941 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005942};
5943
5944/*
5945 * BIOS auto configuration
5946 */
5947static int alc269_parse_auto_config(struct hda_codec *codec)
5948{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005949 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005950 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5951 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5952 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005953 const hda_nid_t *ssids;
5954
5955 switch (spec->codec_variant) {
5956 case ALC269_TYPE_ALC269VA:
5957 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01005958 case ALC269_TYPE_ALC280:
5959 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005960 ssids = alc269va_ssids;
5961 break;
5962 case ALC269_TYPE_ALC269VB:
5963 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01005964 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02005965 ssids = alc269_ssids;
5966 break;
5967 default:
5968 ssids = alc269_ssids;
5969 break;
5970 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005971
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005972 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005973}
5974
Kailang Yang1387e2d2012-11-08 10:23:18 +01005975static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005976{
5977 int val = alc_read_coef_idx(codec, 0x04);
5978 if (power_up)
5979 val |= 1 << 11;
5980 else
5981 val &= ~(1 << 11);
5982 alc_write_coef_idx(codec, 0x04, val);
5983}
5984
5985static void alc269_shutup(struct hda_codec *codec)
5986{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005987 struct alc_spec *spec = codec->spec;
5988
5989 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5990 return;
5991
Kailang Yang1387e2d2012-11-08 10:23:18 +01005992 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5993 alc269vb_toggle_power_output(codec, 0);
5994 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5995 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005996 msleep(150);
5997 }
5998}
5999
Takashi Iwai2a439522011-07-26 09:52:50 +02006000#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006001static int alc269_resume(struct hda_codec *codec)
6002{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006003 struct alc_spec *spec = codec->spec;
6004
Kailang Yang1387e2d2012-11-08 10:23:18 +01006005 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6006 alc269vb_toggle_power_output(codec, 0);
6007 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006008 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006009 msleep(150);
6010 }
6011
6012 codec->patch_ops.init(codec);
6013
Kailang Yang1387e2d2012-11-08 10:23:18 +01006014 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6015 alc269vb_toggle_power_output(codec, 1);
6016 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006017 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006018 msleep(200);
6019 }
6020
Takashi Iwai1d045db2011-07-07 18:23:21 +02006021 snd_hda_codec_resume_amp(codec);
6022 snd_hda_codec_resume_cache(codec);
6023 hda_call_check_power_status(codec, 0x01);
6024 return 0;
6025}
Takashi Iwai2a439522011-07-26 09:52:50 +02006026#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006027
David Henningsson108cc102012-07-20 10:37:25 +02006028static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6029 const struct alc_fixup *fix, int action)
6030{
6031 struct alc_spec *spec = codec->spec;
6032
6033 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6034 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6035}
6036
Takashi Iwai1d045db2011-07-07 18:23:21 +02006037static void alc269_fixup_hweq(struct hda_codec *codec,
6038 const struct alc_fixup *fix, int action)
6039{
6040 int coef;
6041
6042 if (action != ALC_FIXUP_ACT_INIT)
6043 return;
6044 coef = alc_read_coef_idx(codec, 0x1e);
6045 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6046}
6047
6048static void alc271_fixup_dmic(struct hda_codec *codec,
6049 const struct alc_fixup *fix, int action)
6050{
6051 static const struct hda_verb verbs[] = {
6052 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6053 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6054 {}
6055 };
6056 unsigned int cfg;
6057
6058 if (strcmp(codec->chip_name, "ALC271X"))
6059 return;
6060 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6061 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6062 snd_hda_sequence_write(codec, verbs);
6063}
6064
Takashi Iwai017f2a12011-07-09 14:42:25 +02006065static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6066 const struct alc_fixup *fix, int action)
6067{
6068 struct alc_spec *spec = codec->spec;
6069
6070 if (action != ALC_FIXUP_ACT_PROBE)
6071 return;
6072
6073 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6074 * fix the sample rate of analog I/O to 44.1kHz
6075 */
6076 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6077 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6078}
6079
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006080static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6081 const struct alc_fixup *fix, int action)
6082{
6083 int coef;
6084
6085 if (action != ALC_FIXUP_ACT_INIT)
6086 return;
6087 /* The digital-mic unit sends PDM (differential signal) instead of
6088 * the standard PCM, thus you can't record a valid mono stream as is.
6089 * Below is a workaround specific to ALC269 to control the dmic
6090 * signal source as mono.
6091 */
6092 coef = alc_read_coef_idx(codec, 0x07);
6093 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6094}
6095
Takashi Iwai24519912011-08-16 15:08:49 +02006096static void alc269_quanta_automute(struct hda_codec *codec)
6097{
David Henningsson42cf0d02011-09-20 12:04:56 +02006098 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006099
6100 snd_hda_codec_write(codec, 0x20, 0,
6101 AC_VERB_SET_COEF_INDEX, 0x0c);
6102 snd_hda_codec_write(codec, 0x20, 0,
6103 AC_VERB_SET_PROC_COEF, 0x680);
6104
6105 snd_hda_codec_write(codec, 0x20, 0,
6106 AC_VERB_SET_COEF_INDEX, 0x0c);
6107 snd_hda_codec_write(codec, 0x20, 0,
6108 AC_VERB_SET_PROC_COEF, 0x480);
6109}
6110
6111static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6112 const struct alc_fixup *fix, int action)
6113{
6114 struct alc_spec *spec = codec->spec;
6115 if (action != ALC_FIXUP_ACT_PROBE)
6116 return;
6117 spec->automute_hook = alc269_quanta_automute;
6118}
6119
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006120/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6121static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6122{
6123 struct hda_codec *codec = private_data;
6124 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6125 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6126 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6127}
6128
6129static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6130 const struct alc_fixup *fix, int action)
6131{
6132 struct alc_spec *spec = codec->spec;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01006133 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006134 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006135}
6136
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006137/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6138static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6139{
6140 struct hda_codec *codec = private_data;
6141 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006142 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006143}
6144
6145static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6146 const struct alc_fixup *fix, int action)
6147{
6148 struct alc_spec *spec = codec->spec;
Takashi Iwai3bd7b642012-12-18 14:57:09 +01006149 if (action == ALC_FIXUP_ACT_PROBE)
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006150 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006151}
6152
Dylan Reid08a978d2012-11-18 22:56:40 -08006153static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6154 const struct alc_fixup *fix,
6155 int action)
6156{
6157 struct alc_spec *spec = codec->spec;
6158
6159 if (action == ALC_FIXUP_ACT_PROBE)
6160 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6161 spec->autocfg.hp_pins[0]);
6162}
David Henningsson693b6132012-06-22 19:12:10 +02006163
Takashi Iwai1d045db2011-07-07 18:23:21 +02006164enum {
6165 ALC269_FIXUP_SONY_VAIO,
6166 ALC275_FIXUP_SONY_VAIO_GPIO2,
6167 ALC269_FIXUP_DELL_M101Z,
6168 ALC269_FIXUP_SKU_IGNORE,
6169 ALC269_FIXUP_ASUS_G73JW,
6170 ALC269_FIXUP_LENOVO_EAPD,
6171 ALC275_FIXUP_SONY_HWEQ,
6172 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006173 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006174 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006175 ALC269_FIXUP_QUANTA_MUTE,
6176 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006177 ALC269_FIXUP_AMIC,
6178 ALC269_FIXUP_DMIC,
6179 ALC269VB_FIXUP_AMIC,
6180 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006181 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006182 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006183 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006184 ALC269_FIXUP_LENOVO_DOCK,
6185 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006186 ALC271_FIXUP_AMIC_MIC2,
6187 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006188};
6189
6190static const struct alc_fixup alc269_fixups[] = {
6191 [ALC269_FIXUP_SONY_VAIO] = {
6192 .type = ALC_FIXUP_VERBS,
6193 .v.verbs = (const struct hda_verb[]) {
6194 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6195 {}
6196 }
6197 },
6198 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6199 .type = ALC_FIXUP_VERBS,
6200 .v.verbs = (const struct hda_verb[]) {
6201 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6202 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6203 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6204 { }
6205 },
6206 .chained = true,
6207 .chain_id = ALC269_FIXUP_SONY_VAIO
6208 },
6209 [ALC269_FIXUP_DELL_M101Z] = {
6210 .type = ALC_FIXUP_VERBS,
6211 .v.verbs = (const struct hda_verb[]) {
6212 /* Enables internal speaker */
6213 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6214 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6215 {}
6216 }
6217 },
6218 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006219 .type = ALC_FIXUP_FUNC,
6220 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006221 },
6222 [ALC269_FIXUP_ASUS_G73JW] = {
6223 .type = ALC_FIXUP_PINS,
6224 .v.pins = (const struct alc_pincfg[]) {
6225 { 0x17, 0x99130111 }, /* subwoofer */
6226 { }
6227 }
6228 },
6229 [ALC269_FIXUP_LENOVO_EAPD] = {
6230 .type = ALC_FIXUP_VERBS,
6231 .v.verbs = (const struct hda_verb[]) {
6232 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6233 {}
6234 }
6235 },
6236 [ALC275_FIXUP_SONY_HWEQ] = {
6237 .type = ALC_FIXUP_FUNC,
6238 .v.func = alc269_fixup_hweq,
6239 .chained = true,
6240 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6241 },
6242 [ALC271_FIXUP_DMIC] = {
6243 .type = ALC_FIXUP_FUNC,
6244 .v.func = alc271_fixup_dmic,
6245 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006246 [ALC269_FIXUP_PCM_44K] = {
6247 .type = ALC_FIXUP_FUNC,
6248 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006249 .chained = true,
6250 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006251 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006252 [ALC269_FIXUP_STEREO_DMIC] = {
6253 .type = ALC_FIXUP_FUNC,
6254 .v.func = alc269_fixup_stereo_dmic,
6255 },
Takashi Iwai24519912011-08-16 15:08:49 +02006256 [ALC269_FIXUP_QUANTA_MUTE] = {
6257 .type = ALC_FIXUP_FUNC,
6258 .v.func = alc269_fixup_quanta_mute,
6259 },
6260 [ALC269_FIXUP_LIFEBOOK] = {
6261 .type = ALC_FIXUP_PINS,
6262 .v.pins = (const struct alc_pincfg[]) {
6263 { 0x1a, 0x2101103f }, /* dock line-out */
6264 { 0x1b, 0x23a11040 }, /* dock mic-in */
6265 { }
6266 },
6267 .chained = true,
6268 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6269 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006270 [ALC269_FIXUP_AMIC] = {
6271 .type = ALC_FIXUP_PINS,
6272 .v.pins = (const struct alc_pincfg[]) {
6273 { 0x14, 0x99130110 }, /* speaker */
6274 { 0x15, 0x0121401f }, /* HP out */
6275 { 0x18, 0x01a19c20 }, /* mic */
6276 { 0x19, 0x99a3092f }, /* int-mic */
6277 { }
6278 },
6279 },
6280 [ALC269_FIXUP_DMIC] = {
6281 .type = ALC_FIXUP_PINS,
6282 .v.pins = (const struct alc_pincfg[]) {
6283 { 0x12, 0x99a3092f }, /* int-mic */
6284 { 0x14, 0x99130110 }, /* speaker */
6285 { 0x15, 0x0121401f }, /* HP out */
6286 { 0x18, 0x01a19c20 }, /* mic */
6287 { }
6288 },
6289 },
6290 [ALC269VB_FIXUP_AMIC] = {
6291 .type = ALC_FIXUP_PINS,
6292 .v.pins = (const struct alc_pincfg[]) {
6293 { 0x14, 0x99130110 }, /* speaker */
6294 { 0x18, 0x01a19c20 }, /* mic */
6295 { 0x19, 0x99a3092f }, /* int-mic */
6296 { 0x21, 0x0121401f }, /* HP out */
6297 { }
6298 },
6299 },
David Henningsson2267ea92012-01-03 08:45:56 +01006300 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006301 .type = ALC_FIXUP_PINS,
6302 .v.pins = (const struct alc_pincfg[]) {
6303 { 0x12, 0x99a3092f }, /* int-mic */
6304 { 0x14, 0x99130110 }, /* speaker */
6305 { 0x18, 0x01a19c20 }, /* mic */
6306 { 0x21, 0x0121401f }, /* HP out */
6307 { }
6308 },
6309 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006310 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6311 .type = ALC_FIXUP_FUNC,
6312 .v.func = alc269_fixup_mic1_mute,
6313 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006314 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6315 .type = ALC_FIXUP_FUNC,
6316 .v.func = alc269_fixup_mic2_mute,
6317 },
David Henningsson693b6132012-06-22 19:12:10 +02006318 [ALC269_FIXUP_INV_DMIC] = {
6319 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006320 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006321 },
David Henningsson108cc102012-07-20 10:37:25 +02006322 [ALC269_FIXUP_LENOVO_DOCK] = {
6323 .type = ALC_FIXUP_PINS,
6324 .v.pins = (const struct alc_pincfg[]) {
6325 { 0x19, 0x23a11040 }, /* dock mic */
6326 { 0x1b, 0x2121103f }, /* dock headphone */
6327 { }
6328 },
6329 .chained = true,
6330 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6331 },
6332 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6333 .type = ALC_FIXUP_FUNC,
6334 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6335 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006336 [ALC271_FIXUP_AMIC_MIC2] = {
6337 .type = ALC_FIXUP_PINS,
6338 .v.pins = (const struct alc_pincfg[]) {
6339 { 0x14, 0x99130110 }, /* speaker */
6340 { 0x19, 0x01a19c20 }, /* mic */
6341 { 0x1b, 0x99a7012f }, /* int-mic */
6342 { 0x21, 0x0121401f }, /* HP out */
6343 { }
6344 },
6345 },
6346 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6347 .type = ALC_FIXUP_FUNC,
6348 .v.func = alc271_hp_gate_mic_jack,
6349 .chained = true,
6350 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6351 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006352};
6353
6354static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006355 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6356 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006357 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006358 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006359 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006360 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006361 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006362 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006363 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6364 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6365 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6366 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6367 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006368 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6369 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6370 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6371 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6372 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006373 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006374 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006375 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006376 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6377 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6378 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6379 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6380 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006381 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006382 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006383 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006384 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006385 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006386 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006387 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006388
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006389#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006390 /* Below is a quirk table taken from the old code.
6391 * Basically the device should work as is without the fixup table.
6392 * If BIOS doesn't give a proper info, enable the corresponding
6393 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006394 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006395 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6396 ALC269_FIXUP_AMIC),
6397 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006398 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6399 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6400 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6401 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6402 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6403 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6404 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6405 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6406 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6407 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6408 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6409 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6410 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6411 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6412 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6413 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6414 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6415 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6416 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6417 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6418 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6419 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6420 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6421 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6422 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6423 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6424 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6425 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6426 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6427 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6428 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6429 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6430 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6431 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6432 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6433 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6434 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6435 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6436#endif
6437 {}
6438};
6439
6440static const struct alc_model_fixup alc269_fixup_models[] = {
6441 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6442 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006443 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6444 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6445 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006446 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006447 {}
6448};
6449
6450
Takashi Iwai546bb672012-03-07 08:37:19 +01006451static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006452{
Kailang Yang526af6e2012-03-07 08:25:20 +01006453 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006454 int val;
6455
Kailang Yang526af6e2012-03-07 08:25:20 +01006456 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006457 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006458
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006459 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006460 alc_write_coef_idx(codec, 0xf, 0x960b);
6461 alc_write_coef_idx(codec, 0xe, 0x8817);
6462 }
6463
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006464 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006465 alc_write_coef_idx(codec, 0xf, 0x960b);
6466 alc_write_coef_idx(codec, 0xe, 0x8814);
6467 }
6468
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006469 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006470 val = alc_read_coef_idx(codec, 0x04);
6471 /* Power up output pin */
6472 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6473 }
6474
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006475 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006476 val = alc_read_coef_idx(codec, 0xd);
6477 if ((val & 0x0c00) >> 10 != 0x1) {
6478 /* Capless ramp up clock control */
6479 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6480 }
6481 val = alc_read_coef_idx(codec, 0x17);
6482 if ((val & 0x01c0) >> 6 != 0x4) {
6483 /* Class D power on reset */
6484 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6485 }
6486 }
6487
6488 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6489 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6490
6491 val = alc_read_coef_idx(codec, 0x4); /* HP */
6492 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006493}
6494
6495/*
6496 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006497static int patch_alc269(struct hda_codec *codec)
6498{
6499 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006500 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006501
Takashi Iwai3de95172012-05-07 18:03:15 +02006502 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006503 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006504 return err;
6505
6506 spec = codec->spec;
Takashi Iwai37c04202012-12-18 14:22:45 +01006507 spec->shared_mic_vref_pin = 0x18;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006508
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006509 alc_pick_fixup(codec, alc269_fixup_models,
6510 alc269_fixup_tbl, alc269_fixups);
6511 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6512
6513 alc_auto_parse_customize_define(codec);
6514
Kailang Yang065380f2013-01-10 10:25:48 +01006515 switch (codec->vendor_id) {
6516 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006517 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006518 switch (alc_get_coef0(codec) & 0x00f0) {
6519 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006520 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006521 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006522 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006523 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006524 break;
6525 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006526 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6527 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006528 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006529 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006530 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006531 case 0x0030:
6532 spec->codec_variant = ALC269_TYPE_ALC269VD;
6533 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006534 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006535 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006536 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006537 if (err < 0)
6538 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006539 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006540 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006541 break;
6542
6543 case 0x10ec0280:
6544 case 0x10ec0290:
6545 spec->codec_variant = ALC269_TYPE_ALC280;
6546 break;
6547 case 0x10ec0282:
6548 case 0x10ec0283:
6549 spec->codec_variant = ALC269_TYPE_ALC282;
6550 break;
6551 case 0x10ec0284:
6552 case 0x10ec0292:
6553 spec->codec_variant = ALC269_TYPE_ALC284;
6554 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006555 }
6556
Takashi Iwaia4297b52011-08-23 18:40:12 +02006557 /* automatic parse from the BIOS config */
6558 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006559 if (err < 0)
6560 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006561
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006562 if (!spec->no_analog && has_cdefine_beep(codec)) {
6563 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006564 if (err < 0)
6565 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006566 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006567 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006568
Takashi Iwai1d045db2011-07-07 18:23:21 +02006569 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006570#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006571 codec->patch_ops.resume = alc269_resume;
6572#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006573 spec->shutup = alc269_shutup;
6574
Takashi Iwai589876e2012-02-20 15:47:55 +01006575 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6576
Takashi Iwai1d045db2011-07-07 18:23:21 +02006577 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006578
6579 error:
6580 alc_free(codec);
6581 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006582}
6583
6584/*
6585 * ALC861
6586 */
6587
Takashi Iwai1d045db2011-07-07 18:23:21 +02006588static int alc861_parse_auto_config(struct hda_codec *codec)
6589{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006590 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006591 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6592 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006593}
6594
Takashi Iwai1d045db2011-07-07 18:23:21 +02006595/* Pin config fixes */
6596enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006597 ALC861_FIXUP_FSC_AMILO_PI1505,
6598 ALC861_FIXUP_AMP_VREF_0F,
6599 ALC861_FIXUP_NO_JACK_DETECT,
6600 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006601};
6602
Takashi Iwai31150f22012-01-30 10:54:08 +01006603/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6604static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6605 const struct alc_fixup *fix, int action)
6606{
6607 struct alc_spec *spec = codec->spec;
6608 unsigned int val;
6609
6610 if (action != ALC_FIXUP_ACT_INIT)
6611 return;
6612 val = snd_hda_codec_read(codec, 0x0f, 0,
6613 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6614 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6615 val |= AC_PINCTL_IN_EN;
6616 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006617 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006618 spec->keep_vref_in_automute = 1;
6619}
6620
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006621/* suppress the jack-detection */
6622static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6623 const struct alc_fixup *fix, int action)
6624{
6625 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6626 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006627}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006628
Takashi Iwai1d045db2011-07-07 18:23:21 +02006629static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006630 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006631 .type = ALC_FIXUP_PINS,
6632 .v.pins = (const struct alc_pincfg[]) {
6633 { 0x0b, 0x0221101f }, /* HP */
6634 { 0x0f, 0x90170310 }, /* speaker */
6635 { }
6636 }
6637 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006638 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006639 .type = ALC_FIXUP_FUNC,
6640 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006641 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006642 [ALC861_FIXUP_NO_JACK_DETECT] = {
6643 .type = ALC_FIXUP_FUNC,
6644 .v.func = alc_fixup_no_jack_detect,
6645 },
6646 [ALC861_FIXUP_ASUS_A6RP] = {
6647 .type = ALC_FIXUP_FUNC,
6648 .v.func = alc861_fixup_asus_amp_vref_0f,
6649 .chained = true,
6650 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6651 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006652};
6653
6654static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006655 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6656 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6657 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6658 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6659 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6660 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006661 {}
6662};
6663
6664/*
6665 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006666static int patch_alc861(struct hda_codec *codec)
6667{
6668 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006669 int err;
6670
Takashi Iwai3de95172012-05-07 18:03:15 +02006671 err = alc_alloc_spec(codec, 0x15);
6672 if (err < 0)
6673 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006674
Takashi Iwai3de95172012-05-07 18:03:15 +02006675 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006676
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006677 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6678 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006679
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006680 /* automatic parse from the BIOS config */
6681 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006682 if (err < 0)
6683 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006684
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006685 if (!spec->no_analog) {
6686 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006687 if (err < 0)
6688 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006689 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6690 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006691
Takashi Iwai1d045db2011-07-07 18:23:21 +02006692 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006693#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006694 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006695#endif
6696
Takashi Iwai589876e2012-02-20 15:47:55 +01006697 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6698
Takashi Iwai1d045db2011-07-07 18:23:21 +02006699 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006700
6701 error:
6702 alc_free(codec);
6703 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006704}
6705
6706/*
6707 * ALC861-VD support
6708 *
6709 * Based on ALC882
6710 *
6711 * In addition, an independent DAC
6712 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006713static int alc861vd_parse_auto_config(struct hda_codec *codec)
6714{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006715 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006716 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6717 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006718}
6719
Takashi Iwai1d045db2011-07-07 18:23:21 +02006720enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006721 ALC660VD_FIX_ASUS_GPIO1,
6722 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006723};
6724
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006725/* exclude VREF80 */
6726static void alc861vd_fixup_dallas(struct hda_codec *codec,
6727 const struct alc_fixup *fix, int action)
6728{
6729 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006730 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6731 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006732 }
6733}
6734
Takashi Iwai1d045db2011-07-07 18:23:21 +02006735static const struct alc_fixup alc861vd_fixups[] = {
6736 [ALC660VD_FIX_ASUS_GPIO1] = {
6737 .type = ALC_FIXUP_VERBS,
6738 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006739 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006740 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6741 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6742 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6743 { }
6744 }
6745 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006746 [ALC861VD_FIX_DALLAS] = {
6747 .type = ALC_FIXUP_FUNC,
6748 .v.func = alc861vd_fixup_dallas,
6749 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006750};
6751
6752static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006753 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006754 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006755 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006756 {}
6757};
6758
Takashi Iwai1d045db2011-07-07 18:23:21 +02006759/*
6760 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006761static int patch_alc861vd(struct hda_codec *codec)
6762{
6763 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006764 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006765
Takashi Iwai3de95172012-05-07 18:03:15 +02006766 err = alc_alloc_spec(codec, 0x0b);
6767 if (err < 0)
6768 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006769
Takashi Iwai3de95172012-05-07 18:03:15 +02006770 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006771
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006772 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6773 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006774
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006775 /* automatic parse from the BIOS config */
6776 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006777 if (err < 0)
6778 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006779
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006780 if (!spec->no_analog) {
6781 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006782 if (err < 0)
6783 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006784 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6785 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006786
Takashi Iwai1d045db2011-07-07 18:23:21 +02006787 codec->patch_ops = alc_patch_ops;
6788
Takashi Iwai1d045db2011-07-07 18:23:21 +02006789 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006790
Takashi Iwai589876e2012-02-20 15:47:55 +01006791 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6792
Takashi Iwai1d045db2011-07-07 18:23:21 +02006793 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006794
6795 error:
6796 alc_free(codec);
6797 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006798}
6799
6800/*
6801 * ALC662 support
6802 *
6803 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6804 * configuration. Each pin widget can choose any input DACs and a mixer.
6805 * Each ADC is connected from a mixer of all inputs. This makes possible
6806 * 6-channel independent captures.
6807 *
6808 * In addition, an independent DAC for the multi-playback (not used in this
6809 * driver yet).
6810 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006811
6812/*
6813 * BIOS auto configuration
6814 */
6815
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006816static int alc662_parse_auto_config(struct hda_codec *codec)
6817{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006818 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006819 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6820 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6821 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006822
Kailang Yang6227cdc2010-02-25 08:36:52 +01006823 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6824 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006825 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006826 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006827 ssids = alc662_ssids;
6828 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006829}
6830
Todd Broch6be79482010-12-07 16:51:05 -08006831static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006832 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006833{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006834 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006835 return;
Todd Broch6be79482010-12-07 16:51:05 -08006836 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6837 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6838 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6839 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6840 (0 << AC_AMPCAP_MUTE_SHIFT)))
6841 printk(KERN_WARNING
6842 "hda_codec: failed to override amp caps for NID 0x2\n");
6843}
6844
David Henningsson6cb3b702010-09-09 08:51:44 +02006845enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006846 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006847 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006848 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006849 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006850 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006851 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006852 ALC662_FIXUP_ASUS_MODE1,
6853 ALC662_FIXUP_ASUS_MODE2,
6854 ALC662_FIXUP_ASUS_MODE3,
6855 ALC662_FIXUP_ASUS_MODE4,
6856 ALC662_FIXUP_ASUS_MODE5,
6857 ALC662_FIXUP_ASUS_MODE6,
6858 ALC662_FIXUP_ASUS_MODE7,
6859 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006860 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006861 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006862 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006863};
6864
6865static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006866 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006867 .type = ALC_FIXUP_PINS,
6868 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006869 { 0x15, 0x99130112 }, /* subwoofer */
6870 { }
6871 }
6872 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006873 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006874 .type = ALC_FIXUP_PINS,
6875 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006876 { 0x17, 0x99130112 }, /* subwoofer */
6877 { }
6878 }
6879 },
Todd Broch6be79482010-12-07 16:51:05 -08006880 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006881 .type = ALC_FIXUP_FUNC,
6882 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006883 },
6884 [ALC662_FIXUP_CZC_P10T] = {
6885 .type = ALC_FIXUP_VERBS,
6886 .v.verbs = (const struct hda_verb[]) {
6887 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6888 {}
6889 }
6890 },
David Henningsson94024cd2011-04-29 14:10:55 +02006891 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006892 .type = ALC_FIXUP_FUNC,
6893 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006894 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006895 [ALC662_FIXUP_HP_RP5800] = {
6896 .type = ALC_FIXUP_PINS,
6897 .v.pins = (const struct alc_pincfg[]) {
6898 { 0x14, 0x0221201f }, /* HP out */
6899 { }
6900 },
6901 .chained = true,
6902 .chain_id = ALC662_FIXUP_SKU_IGNORE
6903 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006904 [ALC662_FIXUP_ASUS_MODE1] = {
6905 .type = ALC_FIXUP_PINS,
6906 .v.pins = (const struct alc_pincfg[]) {
6907 { 0x14, 0x99130110 }, /* speaker */
6908 { 0x18, 0x01a19c20 }, /* mic */
6909 { 0x19, 0x99a3092f }, /* int-mic */
6910 { 0x21, 0x0121401f }, /* HP out */
6911 { }
6912 },
6913 .chained = true,
6914 .chain_id = ALC662_FIXUP_SKU_IGNORE
6915 },
6916 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006917 .type = ALC_FIXUP_PINS,
6918 .v.pins = (const struct alc_pincfg[]) {
6919 { 0x14, 0x99130110 }, /* speaker */
6920 { 0x18, 0x01a19820 }, /* mic */
6921 { 0x19, 0x99a3092f }, /* int-mic */
6922 { 0x1b, 0x0121401f }, /* HP out */
6923 { }
6924 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006925 .chained = true,
6926 .chain_id = ALC662_FIXUP_SKU_IGNORE
6927 },
6928 [ALC662_FIXUP_ASUS_MODE3] = {
6929 .type = ALC_FIXUP_PINS,
6930 .v.pins = (const struct alc_pincfg[]) {
6931 { 0x14, 0x99130110 }, /* speaker */
6932 { 0x15, 0x0121441f }, /* HP */
6933 { 0x18, 0x01a19840 }, /* mic */
6934 { 0x19, 0x99a3094f }, /* int-mic */
6935 { 0x21, 0x01211420 }, /* HP2 */
6936 { }
6937 },
6938 .chained = true,
6939 .chain_id = ALC662_FIXUP_SKU_IGNORE
6940 },
6941 [ALC662_FIXUP_ASUS_MODE4] = {
6942 .type = ALC_FIXUP_PINS,
6943 .v.pins = (const struct alc_pincfg[]) {
6944 { 0x14, 0x99130110 }, /* speaker */
6945 { 0x16, 0x99130111 }, /* speaker */
6946 { 0x18, 0x01a19840 }, /* mic */
6947 { 0x19, 0x99a3094f }, /* int-mic */
6948 { 0x21, 0x0121441f }, /* HP */
6949 { }
6950 },
6951 .chained = true,
6952 .chain_id = ALC662_FIXUP_SKU_IGNORE
6953 },
6954 [ALC662_FIXUP_ASUS_MODE5] = {
6955 .type = ALC_FIXUP_PINS,
6956 .v.pins = (const struct alc_pincfg[]) {
6957 { 0x14, 0x99130110 }, /* speaker */
6958 { 0x15, 0x0121441f }, /* HP */
6959 { 0x16, 0x99130111 }, /* speaker */
6960 { 0x18, 0x01a19840 }, /* mic */
6961 { 0x19, 0x99a3094f }, /* int-mic */
6962 { }
6963 },
6964 .chained = true,
6965 .chain_id = ALC662_FIXUP_SKU_IGNORE
6966 },
6967 [ALC662_FIXUP_ASUS_MODE6] = {
6968 .type = ALC_FIXUP_PINS,
6969 .v.pins = (const struct alc_pincfg[]) {
6970 { 0x14, 0x99130110 }, /* speaker */
6971 { 0x15, 0x01211420 }, /* HP2 */
6972 { 0x18, 0x01a19840 }, /* mic */
6973 { 0x19, 0x99a3094f }, /* int-mic */
6974 { 0x1b, 0x0121441f }, /* HP */
6975 { }
6976 },
6977 .chained = true,
6978 .chain_id = ALC662_FIXUP_SKU_IGNORE
6979 },
6980 [ALC662_FIXUP_ASUS_MODE7] = {
6981 .type = ALC_FIXUP_PINS,
6982 .v.pins = (const struct alc_pincfg[]) {
6983 { 0x14, 0x99130110 }, /* speaker */
6984 { 0x17, 0x99130111 }, /* speaker */
6985 { 0x18, 0x01a19840 }, /* mic */
6986 { 0x19, 0x99a3094f }, /* int-mic */
6987 { 0x1b, 0x01214020 }, /* HP */
6988 { 0x21, 0x0121401f }, /* HP */
6989 { }
6990 },
6991 .chained = true,
6992 .chain_id = ALC662_FIXUP_SKU_IGNORE
6993 },
6994 [ALC662_FIXUP_ASUS_MODE8] = {
6995 .type = ALC_FIXUP_PINS,
6996 .v.pins = (const struct alc_pincfg[]) {
6997 { 0x14, 0x99130110 }, /* speaker */
6998 { 0x12, 0x99a30970 }, /* int-mic */
6999 { 0x15, 0x01214020 }, /* HP */
7000 { 0x17, 0x99130111 }, /* speaker */
7001 { 0x18, 0x01a19840 }, /* mic */
7002 { 0x21, 0x0121401f }, /* HP */
7003 { }
7004 },
7005 .chained = true,
7006 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007007 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007008 [ALC662_FIXUP_NO_JACK_DETECT] = {
7009 .type = ALC_FIXUP_FUNC,
7010 .v.func = alc_fixup_no_jack_detect,
7011 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007012 [ALC662_FIXUP_ZOTAC_Z68] = {
7013 .type = ALC_FIXUP_PINS,
7014 .v.pins = (const struct alc_pincfg[]) {
7015 { 0x1b, 0x02214020 }, /* Front HP */
7016 { }
7017 }
7018 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007019 [ALC662_FIXUP_INV_DMIC] = {
7020 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007021 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007022 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007023};
7024
Takashi Iwaia9111322011-05-02 11:30:18 +02007025static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007026 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007027 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007028 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007029 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007030 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007031 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007032 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007033 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007034 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007035 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007036 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007037 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007038 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007039
7040#if 0
7041 /* Below is a quirk table taken from the old code.
7042 * Basically the device should work as is without the fixup table.
7043 * If BIOS doesn't give a proper info, enable the corresponding
7044 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007045 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007046 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7047 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7048 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7049 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7050 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7051 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7052 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7053 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7054 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7055 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7056 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7057 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7058 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7059 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7060 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7061 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7062 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7063 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7064 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7065 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7066 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7067 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7068 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7069 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7070 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7071 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7072 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7073 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7074 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7075 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7076 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7077 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7078 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7079 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7080 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7081 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7082 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7083 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7084 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7085 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7086 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7087 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7088 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7089 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7090 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7091 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7092 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7093 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7094 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7095 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7096#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007097 {}
7098};
7099
Todd Broch6be79482010-12-07 16:51:05 -08007100static const struct alc_model_fixup alc662_fixup_models[] = {
7101 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007102 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7103 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7104 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7105 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7106 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7107 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7108 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7109 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007110 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007111 {}
7112};
David Henningsson6cb3b702010-09-09 08:51:44 +02007113
Kailang Yang8663ff72012-06-29 09:35:52 +02007114static void alc662_fill_coef(struct hda_codec *codec)
7115{
7116 int val, coef;
7117
7118 coef = alc_get_coef0(codec);
7119
7120 switch (codec->vendor_id) {
7121 case 0x10ec0662:
7122 if ((coef & 0x00f0) == 0x0030) {
7123 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7124 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7125 }
7126 break;
7127 case 0x10ec0272:
7128 case 0x10ec0273:
7129 case 0x10ec0663:
7130 case 0x10ec0665:
7131 case 0x10ec0670:
7132 case 0x10ec0671:
7133 case 0x10ec0672:
7134 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7135 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7136 break;
7137 }
7138}
David Henningsson6cb3b702010-09-09 08:51:44 +02007139
Takashi Iwai1d045db2011-07-07 18:23:21 +02007140/*
7141 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007142static int patch_alc662(struct hda_codec *codec)
7143{
7144 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007145 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007146
Takashi Iwai3de95172012-05-07 18:03:15 +02007147 err = alc_alloc_spec(codec, 0x0b);
7148 if (err < 0)
7149 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007150
Takashi Iwai3de95172012-05-07 18:03:15 +02007151 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007152
Takashi Iwai53c334a2011-08-23 18:27:14 +02007153 /* handle multiple HPs as is */
7154 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7155
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007156 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7157
Kailang Yang8663ff72012-06-29 09:35:52 +02007158 spec->init_hook = alc662_fill_coef;
7159 alc662_fill_coef(codec);
7160
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007161 alc_pick_fixup(codec, alc662_fixup_models,
7162 alc662_fixup_tbl, alc662_fixups);
7163 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7164
7165 alc_auto_parse_customize_define(codec);
7166
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007167 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007168 codec->bus->pci->subsystem_vendor == 0x1025 &&
7169 spec->cdefine.platform_type == 1) {
7170 if (alc_codec_rename(codec, "ALC272X") < 0)
7171 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007172 }
Kailang Yang274693f2009-12-03 10:07:50 +01007173
Takashi Iwaib9c51062011-08-24 18:08:07 +02007174 /* automatic parse from the BIOS config */
7175 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007176 if (err < 0)
7177 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007178
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007179 if (!spec->no_analog && has_cdefine_beep(codec)) {
7180 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007181 if (err < 0)
7182 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007183 switch (codec->vendor_id) {
7184 case 0x10ec0662:
7185 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7186 break;
7187 case 0x10ec0272:
7188 case 0x10ec0663:
7189 case 0x10ec0665:
7190 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7191 break;
7192 case 0x10ec0273:
7193 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7194 break;
7195 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007196 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007197
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007198 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007199 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007200
Takashi Iwai589876e2012-02-20 15:47:55 +01007201 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7202
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007203 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007204
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007205 error:
7206 alc_free(codec);
7207 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007208}
7209
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007210/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007211 * ALC680 support
7212 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007213
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007214static int alc680_parse_auto_config(struct hda_codec *codec)
7215{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007216 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007217}
7218
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007219/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007220 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007221static int patch_alc680(struct hda_codec *codec)
7222{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007223 int err;
7224
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007225 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007226 err = alc_alloc_spec(codec, 0);
7227 if (err < 0)
7228 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007229
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007230 /* automatic parse from the BIOS config */
7231 err = alc680_parse_auto_config(codec);
7232 if (err < 0) {
7233 alc_free(codec);
7234 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007235 }
7236
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007237 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007238
7239 return 0;
7240}
7241
7242/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007243 * patch entries
7244 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007245static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007246 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007247 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007248 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007249 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007250 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007251 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007252 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007253 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007254 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007255 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007256 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007257 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007258 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007259 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007260 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007261 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007262 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007263 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007264 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7265 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7266 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007267 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007268 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007269 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7270 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007271 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7272 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007273 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007274 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007275 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007276 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007277 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007278 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007279 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007280 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007281 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007282 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007283 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007284 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007285 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007286 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007287 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007288 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007289 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007290 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007291 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007292 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007293 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007294 {} /* terminator */
7295};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007296
7297MODULE_ALIAS("snd-hda-codec-id:10ec*");
7298
7299MODULE_LICENSE("GPL");
7300MODULE_DESCRIPTION("Realtek HD-audio codec");
7301
7302static struct hda_codec_preset_list realtek_list = {
7303 .preset = snd_hda_preset_realtek,
7304 .owner = THIS_MODULE,
7305};
7306
7307static int __init patch_realtek_init(void)
7308{
7309 return snd_hda_add_codec_preset(&realtek_list);
7310}
7311
7312static void __exit patch_realtek_exit(void)
7313{
7314 snd_hda_delete_codec_preset(&realtek_list);
7315}
7316
7317module_init(patch_realtek_init)
7318module_exit(patch_realtek_exit)