blob: aef31392aee1b5ea4bbc8552156eea9f98a2226e [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 Iwaid922b512011-04-28 12:18:53 +020076enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020077 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020080};
81
Takashi Iwaic14c95f2012-02-16 16:38:07 +010082#define MAX_VOL_NIDS 0x40
83
Takashi Iwai23d30f22012-05-07 17:17:32 +020084/* make compatible with old code */
85#define alc_apply_pincfgs snd_hda_apply_pincfgs
86#define alc_apply_fixup snd_hda_apply_fixup
87#define alc_pick_fixup snd_hda_pick_fixup
88#define alc_fixup hda_fixup
89#define alc_pincfg hda_pintbl
90#define alc_model_fixup hda_model_fixup
91
92#define ALC_FIXUP_PINS HDA_FIXUP_PINS
93#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
95
96#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
100
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200103 struct hda_gen_spec gen;
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200106 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +0200108 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100109 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200111 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200112 const struct hda_pcm_stream *stream_analog_playback;
113 const struct hda_pcm_stream *stream_analog_capture;
114 const struct hda_pcm_stream *stream_analog_alt_playback;
115 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200117 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200118 const struct hda_pcm_stream *stream_digital_playback;
119 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200122 struct hda_multi_out multiout; /* playback set-up
123 * max_channels, dacs must be set
124 * dig_out_nid and hp_nid are optional
125 */
Takashi Iwai63300792008-01-24 15:31:36 +0100126 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100127 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100128 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 /* capture */
131 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200132 const hda_nid_t *adc_nids;
133 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200134 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200135 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwaic14c95f2012-02-16 16:38:07 +0100136 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
137 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Takashi Iwai840b64c2010-07-13 22:49:01 +0200139 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200140 hda_nid_t cur_adc;
141 unsigned int cur_adc_stream_tag;
142 unsigned int cur_adc_format;
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200145 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 const struct hda_input_mux *input_mux;
147 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200148 hda_nid_t ext_mic_pin;
149 hda_nid_t dock_mic_pin;
150 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100153 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200155 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200156 int const_channel_count;
157 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100160 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200161
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200162 /* dynamic controls, init_verbs and input_mux */
163 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100164 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200165 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200166 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200167 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200168 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
169 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200170 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
171 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
172 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200173 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100174
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100175 /* hooks */
176 void (*init_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100177#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500178 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100179#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200180 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200181 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100182
Takashi Iwai834be882006-03-01 14:16:17 +0100183 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200184 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200185 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200186 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200187 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200188 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200189 unsigned int automute_speaker:1; /* automute speaker outputs */
190 unsigned int automute_lo:1; /* automute LO outputs */
191 unsigned int detect_hp:1; /* Headphone detection enabled */
192 unsigned int detect_lo:1; /* Line-out detection enabled */
193 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
194 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100195 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200196
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100197 /* other flags */
198 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200199 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100200 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200201 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200202 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100203 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200204 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
205 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaid922b512011-04-28 12:18:53 +0200206
207 /* auto-mute control */
208 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200209 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200210
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200211 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200212 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100213
Takashi Iwai2134ea42008-01-10 16:53:55 +0100214 /* for virtual master */
215 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100216 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200217#ifdef CONFIG_SND_HDA_POWER_SAVE
218 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100219 int num_loopbacks;
220 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200221#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200222
223 /* for PLL fix */
224 hda_nid_t pll_nid;
225 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200226 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100227
Takashi Iwaice764ab2011-04-27 16:35:23 +0200228 /* multi-io */
229 int multi_ios;
230 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200231
232 /* bind volumes */
233 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100234};
235
Takashi Iwai44c02402011-07-08 15:14:19 +0200236static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
237 int dir, unsigned int bits)
238{
239 if (!nid)
240 return false;
241 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
242 if (query_amp_caps(codec, nid, dir) & bits)
243 return true;
244 return false;
245}
246
247#define nid_has_mute(codec, nid, dir) \
248 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
249#define nid_has_volume(codec, nid, dir) \
250 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252/*
253 * input MUX handling
254 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200255static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200260 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
261 if (mux_idx >= spec->num_mux_defs)
262 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100263 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
264 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200265 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
267
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200268static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
269 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
271 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
272 struct alc_spec *spec = codec->spec;
273 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
274
275 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
276 return 0;
277}
278
Takashi Iwai21268962011-07-07 15:01:13 +0200279static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Takashi Iwai21268962011-07-07 15:01:13 +0200281 struct alc_spec *spec = codec->spec;
282 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
283
284 if (spec->cur_adc && spec->cur_adc != new_adc) {
285 /* stream is running, let's swap the current ADC */
286 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
287 spec->cur_adc = new_adc;
288 snd_hda_codec_setup_stream(codec, new_adc,
289 spec->cur_adc_stream_tag, 0,
290 spec->cur_adc_format);
291 return true;
292 }
293 return false;
294}
295
Takashi Iwai61071592011-11-23 07:52:15 +0100296static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
297{
298 return spec->capsrc_nids ?
299 spec->capsrc_nids[idx] : spec->adc_nids[idx];
300}
301
Takashi Iwai24de1832011-11-07 17:13:39 +0100302static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200303static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100304
David Henningsson00227f12012-06-27 18:45:44 +0200305/* for shared I/O, change the pin-control accordingly */
306static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
307{
308 struct alc_spec *spec = codec->spec;
309 unsigned int val;
310 hda_nid_t pin = spec->autocfg.inputs[1].pin;
311 /* NOTE: this assumes that there are only two inputs, the
312 * first is the real internal mic and the second is HP/mic jack.
313 */
314
315 val = snd_hda_get_default_vref(codec, pin);
316
317 /* This pin does not have vref caps - let's enable vref on pin 0x18
318 instead, as suggested by Realtek */
319 if (val == AC_PINCTL_VREF_HIZ) {
320 const hda_nid_t vref_pin = 0x18;
321 /* Sanity check pin 0x18 */
322 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
323 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
324 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
325 if (vref_val != AC_PINCTL_VREF_HIZ)
326 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
327 }
328 }
329
330 val = set_as_mic ? val | PIN_IN : PIN_HP;
331 snd_hda_set_pin_ctl(codec, pin, val);
332
333 spec->automute_speaker = !set_as_mic;
334 call_update_outputs(codec);
335}
336
Takashi Iwai21268962011-07-07 15:01:13 +0200337/* select the given imux item; either unmute exclusively or select the route */
338static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
339 unsigned int idx, bool force)
340{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100342 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100343 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100344 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200345 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Takashi Iwai5803a322012-02-21 11:59:45 +0100347 if (!spec->input_mux)
348 return 0;
349
Takashi Iwaicd896c32008-11-18 12:36:33 +0100350 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
351 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100352 if (!imux->num_items && mux_idx > 0)
353 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100354 if (!imux->num_items)
355 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100356
Takashi Iwai21268962011-07-07 15:01:13 +0200357 if (idx >= imux->num_items)
358 idx = imux->num_items - 1;
359 if (spec->cur_mux[adc_idx] == idx && !force)
360 return 0;
361 spec->cur_mux[adc_idx] = idx;
362
David Henningsson00227f12012-06-27 18:45:44 +0200363 if (spec->shared_mic_hp)
364 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100365
Takashi Iwai21268962011-07-07 15:01:13 +0200366 if (spec->dyn_adc_switch) {
367 alc_dyn_adc_pcm_resetup(codec, idx);
368 adc_idx = spec->dyn_adc_idx[idx];
369 }
370
Takashi Iwai61071592011-11-23 07:52:15 +0100371 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200372
373 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200374 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100375 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200376 return 1;
377
Takashi Iwaia22d5432009-07-27 12:54:26 +0200378 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200379 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100380 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100381 int active = imux->items[idx].index;
382 for (i = 0; i < num_conns; i++) {
383 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
384 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100385 HDA_AMP_MUTE, v);
386 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100387 } else {
388 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200389 snd_hda_codec_write_cache(codec, nid, 0,
390 AC_VERB_SET_CONNECT_SEL,
391 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100392 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200393 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200394 return 1;
395}
396
397static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
398 struct snd_ctl_elem_value *ucontrol)
399{
400 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
401 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
402 return alc_mux_select(codec, adc_idx,
403 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100404}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100407 * set up the input pin config (depending on the given auto-pin type)
408 */
409static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
410 int auto_pin_type)
411{
412 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200413 if (auto_pin_type == AUTO_PIN_MIC)
414 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200415 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100416}
417
418/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200419 * Append the given mixer and verb elements for the later use
420 * The mixer array is referred in build_controls(), and init_verbs are
421 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100422 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200423static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100424{
425 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
426 return;
427 spec->mixers[spec->num_mixers++] = mix;
428}
429
Takashi Iwaid88897e2008-10-31 15:01:37 +0100430/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200431 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100432 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200433/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200434static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200435 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
436 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
437 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
438 { }
439};
440
Takashi Iwaia9111322011-05-02 11:30:18 +0200441static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200442 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
443 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
444 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
445 { }
446};
447
Takashi Iwaia9111322011-05-02 11:30:18 +0200448static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200449 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
450 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
451 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
452 { }
453};
454
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200455/*
456 * Fix hardware PLL issue
457 * On some codecs, the analog PLL gating control must be off while
458 * the default value is 1.
459 */
460static void alc_fix_pll(struct hda_codec *codec)
461{
462 struct alc_spec *spec = codec->spec;
463 unsigned int val;
464
465 if (!spec->pll_nid)
466 return;
467 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
468 spec->pll_coef_idx);
469 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
470 AC_VERB_GET_PROC_COEF, 0);
471 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
472 spec->pll_coef_idx);
473 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
474 val & ~(1 << spec->pll_coef_bit));
475}
476
477static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
478 unsigned int coef_idx, unsigned int coef_bit)
479{
480 struct alc_spec *spec = codec->spec;
481 spec->pll_nid = nid;
482 spec->pll_coef_idx = coef_idx;
483 spec->pll_coef_bit = coef_bit;
484 alc_fix_pll(codec);
485}
486
Takashi Iwai1d045db2011-07-07 18:23:21 +0200487/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200488 * Jack detections for HP auto-mute and mic-switch
489 */
490
491/* check each pin in the given array; returns true if any of them is plugged */
492static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200493{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200494 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200495
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200496 for (i = 0; i < num_pins; i++) {
497 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200498 if (!nid)
499 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200500 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200501 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200502 return present;
503}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200504
Takashi Iwai1d045db2011-07-07 18:23:21 +0200505/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200506static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200507 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200508{
509 struct alc_spec *spec = codec->spec;
510 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200511 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200512 int i;
513
514 for (i = 0; i < num_pins; i++) {
515 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100516 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200517 if (!nid)
518 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200519 switch (spec->automute_mode) {
520 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100521 /* don't reset VREF value in case it's controlling
522 * the amp (see alc861_fixup_asus_amp_vref_0f())
523 */
524 if (spec->keep_vref_in_automute) {
525 val = snd_hda_codec_read(codec, nid, 0,
526 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
527 val &= ~PIN_HP;
528 } else
529 val = 0;
530 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200531 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200532 break;
533 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200534 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200535 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200536 break;
537 case ALC_AUTOMUTE_MIXER:
538 nid = spec->automute_mixer_nid[i];
539 if (!nid)
540 break;
541 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200542 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200543 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200544 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200545 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200546 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200547 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200548}
549
David Henningsson42cf0d02011-09-20 12:04:56 +0200550/* Toggle outputs muting */
551static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200552{
553 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200554 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200555
Takashi Iwaic0a20262011-06-10 15:28:15 +0200556 /* Control HP pins/amps depending on master_mute state;
557 * in general, HP pins/amps control should be enabled in all cases,
558 * but currently set only for master_mute, just to be safe
559 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100560 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
561 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200562 spec->autocfg.hp_pins, spec->master_mute, true);
563
David Henningsson42cf0d02011-09-20 12:04:56 +0200564 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 on = 0;
566 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200567 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200568 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200569 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200571
572 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200573 /* if LO is a copy of either HP or Speaker, don't need to handle it */
574 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
575 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200576 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200577 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200578 on = 0;
579 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200580 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200581 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200583 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200584}
585
David Henningsson42cf0d02011-09-20 12:04:56 +0200586static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200587{
588 struct alc_spec *spec = codec->spec;
589 if (spec->automute_hook)
590 spec->automute_hook(codec);
591 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200593}
594
Takashi Iwai1d045db2011-07-07 18:23:21 +0200595/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200596static void alc_hp_automute(struct hda_codec *codec)
597{
598 struct alc_spec *spec = codec->spec;
599
David Henningsson42cf0d02011-09-20 12:04:56 +0200600 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200601 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
602 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200603 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_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 line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200609static void alc_line_automute(struct hda_codec *codec)
610{
611 struct alc_spec *spec = codec->spec;
612
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200613 /* check LO jack only when it's different from HP */
614 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
615 return;
616
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200617 spec->line_jack_present =
618 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
619 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200620 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200621 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200622 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200623}
624
Takashi Iwai8d087c72011-06-28 12:45:47 +0200625#define get_connection_index(codec, mux, nid) \
626 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200627
Takashi Iwai1d045db2011-07-07 18:23:21 +0200628/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200629static void alc_mic_automute(struct hda_codec *codec)
630{
631 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200632 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200633
Takashi Iwai21268962011-07-07 15:01:13 +0200634 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200635 return;
636 if (snd_BUG_ON(!spec->adc_nids))
637 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200638 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200639 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200640
Takashi Iwai21268962011-07-07 15:01:13 +0200641 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
642 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
643 else if (spec->dock_mic_idx >= 0 &&
644 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
645 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
646 else
647 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200648}
649
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100650/* handle the specified unsol action (ALC_XXX_EVENT) */
651static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200652{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100653 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200654 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200655 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200656 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200657 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200658 alc_line_automute(codec);
659 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200660 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200661 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200662 break;
663 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200664 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200665}
666
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100667/* update the master volume per volume-knob's unsol event */
668static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
669{
670 unsigned int val;
671 struct snd_kcontrol *kctl;
672 struct snd_ctl_elem_value *uctl;
673
674 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
675 if (!kctl)
676 return;
677 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
678 if (!uctl)
679 return;
680 val = snd_hda_codec_read(codec, nid, 0,
681 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
682 val &= HDA_AMP_VOLMASK;
683 uctl->value.integer.value[0] = val;
684 uctl->value.integer.value[1] = val;
685 kctl->put(kctl, uctl);
686 kfree(uctl);
687}
688
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100689/* unsolicited event for HP jack sensing */
David Henningssona7a0a642012-07-05 12:00:12 +0200690static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100691{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100692 int action;
693
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100694 if (codec->vendor_id == 0x10ec0880)
695 res >>= 28;
696 else
697 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100698 action = snd_hda_jack_get_action(codec, res);
David Henningssone21af482012-03-05 11:38:46 +0100699 if (action == ALC_DCVOL_EVENT) {
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100700 /* Execute the dc-vol event here as it requires the NID
701 * but we don't pass NID to alc_exec_unsol_event().
702 * Once when we convert all static quirks to the auto-parser,
703 * this can be integerated into there.
704 */
705 struct hda_jack_tbl *jack;
706 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
707 if (jack)
708 alc_update_knob_master(codec, jack->nid);
709 return;
710 }
711 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100712}
713
Takashi Iwai1d045db2011-07-07 18:23:21 +0200714/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200715static void alc_inithook(struct hda_codec *codec)
716{
Takashi Iwaid922b512011-04-28 12:18:53 +0200717 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200718 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200719 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200720}
721
Kailang Yangf9423e72008-05-27 12:32:25 +0200722/* additional initialization for ALC888 variants */
723static void alc888_coef_init(struct hda_codec *codec)
724{
725 unsigned int tmp;
726
727 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
728 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
729 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100730 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200731 /* alc888S-VC */
732 snd_hda_codec_read(codec, 0x20, 0,
733 AC_VERB_SET_PROC_COEF, 0x830);
734 else
735 /* alc888-VB */
736 snd_hda_codec_read(codec, 0x20, 0,
737 AC_VERB_SET_PROC_COEF, 0x3030);
738}
739
Takashi Iwai1d045db2011-07-07 18:23:21 +0200740/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200741static void alc889_coef_init(struct hda_codec *codec)
742{
743 unsigned int tmp;
744
745 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
746 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
747 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
748 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
749}
750
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100751/* turn on/off EAPD control (only if available) */
752static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
753{
754 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
755 return;
756 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
757 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
758 on ? 2 : 0);
759}
760
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200761/* turn on/off EAPD controls of the codec */
762static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
763{
764 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200765 static hda_nid_t pins[] = {
766 0x0f, 0x10, 0x14, 0x15, 0
767 };
768 hda_nid_t *p;
769 for (p = pins; *p; p++)
770 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200771}
772
Takashi Iwai1c7161532011-04-07 10:37:16 +0200773/* generic shutup callback;
774 * just turning off EPAD and a little pause for avoiding pop-noise
775 */
776static void alc_eapd_shutup(struct hda_codec *codec)
777{
778 alc_auto_setup_eapd(codec, false);
779 msleep(200);
780}
781
Takashi Iwai1d045db2011-07-07 18:23:21 +0200782/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200783static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200784{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200785 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200786
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200787 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200788 switch (type) {
789 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200790 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
791 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200792 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200793 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
794 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200795 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200796 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
797 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200798 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200799 switch (codec->vendor_id) {
800 case 0x10ec0260:
801 snd_hda_codec_write(codec, 0x1a, 0,
802 AC_VERB_SET_COEF_INDEX, 7);
803 tmp = snd_hda_codec_read(codec, 0x1a, 0,
804 AC_VERB_GET_PROC_COEF, 0);
805 snd_hda_codec_write(codec, 0x1a, 0,
806 AC_VERB_SET_COEF_INDEX, 7);
807 snd_hda_codec_write(codec, 0x1a, 0,
808 AC_VERB_SET_PROC_COEF,
809 tmp | 0x2010);
810 break;
811 case 0x10ec0262:
812 case 0x10ec0880:
813 case 0x10ec0882:
814 case 0x10ec0883:
815 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100816 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100817 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200818 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200819 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200820 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200821 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200822 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100823#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200824 case 0x10ec0267:
825 case 0x10ec0268:
826 snd_hda_codec_write(codec, 0x20, 0,
827 AC_VERB_SET_COEF_INDEX, 7);
828 tmp = snd_hda_codec_read(codec, 0x20, 0,
829 AC_VERB_GET_PROC_COEF, 0);
830 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200831 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200832 snd_hda_codec_write(codec, 0x20, 0,
833 AC_VERB_SET_PROC_COEF,
834 tmp | 0x3000);
835 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100836#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200837 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200838 break;
839 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200840}
Kailang Yangea1fb292008-08-26 12:58:38 +0200841
Takashi Iwai1d045db2011-07-07 18:23:21 +0200842/*
843 * Auto-Mute mode mixer enum support
844 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200845static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
846 struct snd_ctl_elem_info *uinfo)
847{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200848 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
849 struct alc_spec *spec = codec->spec;
850 static const char * const texts2[] = {
851 "Disabled", "Enabled"
852 };
853 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100854 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200855 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200856 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200857
858 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
859 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200860 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200861 uinfo->value.enumerated.items = 3;
862 texts = texts3;
863 } else {
864 uinfo->value.enumerated.items = 2;
865 texts = texts2;
866 }
867 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
868 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200869 strcpy(uinfo->value.enumerated.name,
870 texts[uinfo->value.enumerated.item]);
871 return 0;
872}
873
874static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
875 struct snd_ctl_elem_value *ucontrol)
876{
877 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
878 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200879 unsigned int val = 0;
880 if (spec->automute_speaker)
881 val++;
882 if (spec->automute_lo)
883 val++;
884
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 ucontrol->value.enumerated.item[0] = val;
886 return 0;
887}
888
889static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
890 struct snd_ctl_elem_value *ucontrol)
891{
892 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
893 struct alc_spec *spec = codec->spec;
894
895 switch (ucontrol->value.enumerated.item[0]) {
896 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200897 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200898 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200899 spec->automute_speaker = 0;
900 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200901 break;
902 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200903 if (spec->automute_speaker_possible) {
904 if (!spec->automute_lo && spec->automute_speaker)
905 return 0;
906 spec->automute_speaker = 1;
907 spec->automute_lo = 0;
908 } else if (spec->automute_lo_possible) {
909 if (spec->automute_lo)
910 return 0;
911 spec->automute_lo = 1;
912 } else
913 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200914 break;
915 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200916 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200917 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200918 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200919 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200920 spec->automute_speaker = 1;
921 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200922 break;
923 default:
924 return -EINVAL;
925 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200926 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200927 return 1;
928}
929
Takashi Iwaia9111322011-05-02 11:30:18 +0200930static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200931 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
932 .name = "Auto-Mute Mode",
933 .info = alc_automute_mode_info,
934 .get = alc_automute_mode_get,
935 .put = alc_automute_mode_put,
936};
937
Takashi Iwai1d045db2011-07-07 18:23:21 +0200938static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
939{
940 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
941 return snd_array_new(&spec->kctls);
942}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200943
944static int alc_add_automute_mode_enum(struct hda_codec *codec)
945{
946 struct alc_spec *spec = codec->spec;
947 struct snd_kcontrol_new *knew;
948
949 knew = alc_kcontrol_new(spec);
950 if (!knew)
951 return -ENOMEM;
952 *knew = alc_automute_mode_enum;
953 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
954 if (!knew->name)
955 return -ENOMEM;
956 return 0;
957}
958
Takashi Iwai1d045db2011-07-07 18:23:21 +0200959/*
960 * Check the availability of HP/line-out auto-mute;
961 * Set up appropriately if really supported
962 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200963static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200964{
965 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200966 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200967 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200968 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200969
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200970 if (cfg->hp_pins[0])
971 present++;
972 if (cfg->line_out_pins[0])
973 present++;
974 if (cfg->speaker_pins[0])
975 present++;
976 if (present < 2) /* need two different output types */
977 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200978
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200979 if (!cfg->speaker_pins[0] &&
980 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200981 memcpy(cfg->speaker_pins, cfg->line_out_pins,
982 sizeof(cfg->speaker_pins));
983 cfg->speaker_outs = cfg->line_outs;
984 }
985
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200986 if (!cfg->hp_pins[0] &&
987 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200988 memcpy(cfg->hp_pins, cfg->line_out_pins,
989 sizeof(cfg->hp_pins));
990 cfg->hp_outs = cfg->line_outs;
991 }
992
David Henningsson42cf0d02011-09-20 12:04:56 +0200993 spec->automute_mode = ALC_AUTOMUTE_PIN;
994
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200995 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200996 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200997 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200998 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200999 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001000 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001001 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001002 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001003 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001004
David Henningsson42cf0d02011-09-20 12:04:56 +02001005 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
1006 if (cfg->speaker_outs)
1007 for (i = 0; i < cfg->line_outs; i++) {
1008 hda_nid_t nid = cfg->line_out_pins[i];
1009 if (!is_jack_detectable(codec, nid))
1010 continue;
1011 snd_printdd("realtek: Enable Line-Out "
1012 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001013 snd_hda_jack_detect_enable(codec, nid,
1014 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001015 spec->detect_lo = 1;
1016 }
1017 spec->automute_lo_possible = spec->detect_hp;
1018 }
1019
1020 spec->automute_speaker_possible = cfg->speaker_outs &&
1021 (spec->detect_hp || spec->detect_lo);
1022
1023 spec->automute_lo = spec->automute_lo_possible;
1024 spec->automute_speaker = spec->automute_speaker_possible;
1025
David Henningssona7a0a642012-07-05 12:00:12 +02001026 if (spec->automute_speaker_possible || spec->automute_lo_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001027 /* create a control for automute mode */
1028 alc_add_automute_mode_enum(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001029}
1030
Takashi Iwai1d045db2011-07-07 18:23:21 +02001031/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001032static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1033{
1034 int i;
1035 for (i = 0; i < nums; i++)
1036 if (list[i] == nid)
1037 return i;
1038 return -1;
1039}
1040
Takashi Iwai1d045db2011-07-07 18:23:21 +02001041/* check whether dynamic ADC-switching is available */
1042static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1043{
1044 struct alc_spec *spec = codec->spec;
1045 struct hda_input_mux *imux = &spec->private_imux[0];
1046 int i, n, idx;
1047 hda_nid_t cap, pin;
1048
1049 if (imux != spec->input_mux) /* no dynamic imux? */
1050 return false;
1051
1052 for (n = 0; n < spec->num_adc_nids; n++) {
1053 cap = spec->private_capsrc_nids[n];
1054 for (i = 0; i < imux->num_items; i++) {
1055 pin = spec->imux_pins[i];
1056 if (!pin)
1057 return false;
1058 if (get_connection_index(codec, cap, pin) < 0)
1059 break;
1060 }
1061 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001062 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001063 }
1064
1065 for (i = 0; i < imux->num_items; i++) {
1066 pin = spec->imux_pins[i];
1067 for (n = 0; n < spec->num_adc_nids; n++) {
1068 cap = spec->private_capsrc_nids[n];
1069 idx = get_connection_index(codec, cap, pin);
1070 if (idx >= 0) {
1071 imux->items[i].index = idx;
1072 spec->dyn_adc_idx[i] = n;
1073 break;
1074 }
1075 }
1076 }
1077
1078 snd_printdd("realtek: enabling ADC switching\n");
1079 spec->dyn_adc_switch = 1;
1080 return true;
1081}
Takashi Iwai21268962011-07-07 15:01:13 +02001082
Takashi Iwai21268962011-07-07 15:01:13 +02001083/* check whether all auto-mic pins are valid; setup indices if OK */
1084static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1085{
1086 struct alc_spec *spec = codec->spec;
1087 const struct hda_input_mux *imux;
1088
1089 if (!spec->auto_mic)
1090 return false;
1091 if (spec->auto_mic_valid_imux)
1092 return true; /* already checked */
1093
1094 /* fill up imux indices */
1095 if (!alc_check_dyn_adc_switch(codec)) {
1096 spec->auto_mic = 0;
1097 return false;
1098 }
1099
1100 imux = spec->input_mux;
1101 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1102 spec->imux_pins, imux->num_items);
1103 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1104 spec->imux_pins, imux->num_items);
1105 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1106 spec->imux_pins, imux->num_items);
1107 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1108 spec->auto_mic = 0;
1109 return false; /* no corresponding imux */
1110 }
1111
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001112 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001113 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001114 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1115 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001116
1117 spec->auto_mic_valid_imux = 1;
1118 spec->auto_mic = 1;
1119 return true;
1120}
1121
Takashi Iwai1d045db2011-07-07 18:23:21 +02001122/*
1123 * Check the availability of auto-mic switch;
1124 * Set up if really supported
1125 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001126static void alc_init_auto_mic(struct hda_codec *codec)
1127{
1128 struct alc_spec *spec = codec->spec;
1129 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001130 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001131 int i;
1132
Takashi Iwai24de1832011-11-07 17:13:39 +01001133 if (spec->shared_mic_hp)
1134 return; /* no auto-mic for the shared I/O */
1135
Takashi Iwai21268962011-07-07 15:01:13 +02001136 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1137
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001138 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001139 for (i = 0; i < cfg->num_inputs; i++) {
1140 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001141 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001142 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001143 switch (snd_hda_get_input_pin_attr(defcfg)) {
1144 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 if (fixed)
1146 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001147 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1148 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001149 fixed = nid;
1150 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001151 case INPUT_PIN_ATTR_UNUSED:
1152 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001153 case INPUT_PIN_ATTR_DOCK:
1154 if (dock)
1155 return; /* already occupied */
1156 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1157 return; /* invalid type */
1158 dock = nid;
1159 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001160 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001161 if (ext)
1162 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001163 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1164 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001165 ext = nid;
1166 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001167 }
1168 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001169 if (!ext && dock) {
1170 ext = dock;
1171 dock = 0;
1172 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001173 if (!ext || !fixed)
1174 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001175 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001176 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001177 if (dock && !is_jack_detectable(codec, dock))
1178 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001179
1180 /* check imux indices */
1181 spec->ext_mic_pin = ext;
1182 spec->int_mic_pin = fixed;
1183 spec->dock_mic_pin = dock;
1184
1185 spec->auto_mic = 1;
1186 if (!alc_auto_mic_check_imux(codec))
1187 return;
1188
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001189 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1190 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001191}
1192
Takashi Iwai1d045db2011-07-07 18:23:21 +02001193/* check the availabilities of auto-mute and auto-mic switches */
1194static void alc_auto_check_switches(struct hda_codec *codec)
1195{
David Henningsson42cf0d02011-09-20 12:04:56 +02001196 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001197 alc_init_auto_mic(codec);
1198}
1199
1200/*
1201 * Realtek SSID verification
1202 */
1203
David Henningsson90622912010-10-14 14:50:18 +02001204/* Could be any non-zero and even value. When used as fixup, tells
1205 * the driver to ignore any present sku defines.
1206 */
1207#define ALC_FIXUP_SKU_IGNORE (2)
1208
Takashi Iwai23d30f22012-05-07 17:17:32 +02001209static void alc_fixup_sku_ignore(struct hda_codec *codec,
1210 const struct hda_fixup *fix, int action)
1211{
1212 struct alc_spec *spec = codec->spec;
1213 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1214 spec->cdefine.fixup = 1;
1215 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1216 }
1217}
1218
Kailang Yangda00c242010-03-19 11:23:45 +01001219static int alc_auto_parse_customize_define(struct hda_codec *codec)
1220{
1221 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001222 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001223 struct alc_spec *spec = codec->spec;
1224
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001225 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1226
David Henningsson90622912010-10-14 14:50:18 +02001227 if (spec->cdefine.fixup) {
1228 ass = spec->cdefine.sku_cfg;
1229 if (ass == ALC_FIXUP_SKU_IGNORE)
1230 return -1;
1231 goto do_sku;
1232 }
1233
Kailang Yangda00c242010-03-19 11:23:45 +01001234 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001235 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001236 goto do_sku;
1237
1238 nid = 0x1d;
1239 if (codec->vendor_id == 0x10ec0260)
1240 nid = 0x17;
1241 ass = snd_hda_codec_get_pincfg(codec, nid);
1242
1243 if (!(ass & 1)) {
1244 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1245 codec->chip_name, ass);
1246 return -1;
1247 }
1248
1249 /* check sum */
1250 tmp = 0;
1251 for (i = 1; i < 16; i++) {
1252 if ((ass >> i) & 1)
1253 tmp++;
1254 }
1255 if (((ass >> 16) & 0xf) != tmp)
1256 return -1;
1257
1258 spec->cdefine.port_connectivity = ass >> 30;
1259 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1260 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1261 spec->cdefine.customization = ass >> 8;
1262do_sku:
1263 spec->cdefine.sku_cfg = ass;
1264 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1265 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1266 spec->cdefine.swap = (ass & 0x2) >> 1;
1267 spec->cdefine.override = ass & 0x1;
1268
1269 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1270 nid, spec->cdefine.sku_cfg);
1271 snd_printd("SKU: port_connectivity=0x%x\n",
1272 spec->cdefine.port_connectivity);
1273 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1274 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1275 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1276 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1277 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1278 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1279 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1280
1281 return 0;
1282}
1283
Takashi Iwai1d045db2011-07-07 18:23:21 +02001284/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001285static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1286{
Takashi Iwai21268962011-07-07 15:01:13 +02001287 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001288}
1289
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001290/* check subsystem ID and set up device-specific initialization;
1291 * return 1 if initialized, 0 if invalid SSID
1292 */
1293/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1294 * 31 ~ 16 : Manufacture ID
1295 * 15 ~ 8 : SKU ID
1296 * 7 ~ 0 : Assembly ID
1297 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1298 */
1299static int alc_subsystem_id(struct hda_codec *codec,
1300 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001301 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001302{
1303 unsigned int ass, tmp, i;
1304 unsigned nid;
1305 struct alc_spec *spec = codec->spec;
1306
David Henningsson90622912010-10-14 14:50:18 +02001307 if (spec->cdefine.fixup) {
1308 ass = spec->cdefine.sku_cfg;
1309 if (ass == ALC_FIXUP_SKU_IGNORE)
1310 return 0;
1311 goto do_sku;
1312 }
1313
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001314 ass = codec->subsystem_id & 0xffff;
1315 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1316 goto do_sku;
1317
1318 /* invalid SSID, check the special NID pin defcfg instead */
1319 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001320 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001321 * 29~21 : reserve
1322 * 20 : PCBEEP input
1323 * 19~16 : Check sum (15:1)
1324 * 15~1 : Custom
1325 * 0 : override
1326 */
1327 nid = 0x1d;
1328 if (codec->vendor_id == 0x10ec0260)
1329 nid = 0x17;
1330 ass = snd_hda_codec_get_pincfg(codec, nid);
1331 snd_printd("realtek: No valid SSID, "
1332 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001333 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001334 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001335 return 0;
1336 if ((ass >> 30) != 1) /* no physical connection */
1337 return 0;
1338
1339 /* check sum */
1340 tmp = 0;
1341 for (i = 1; i < 16; i++) {
1342 if ((ass >> i) & 1)
1343 tmp++;
1344 }
1345 if (((ass >> 16) & 0xf) != tmp)
1346 return 0;
1347do_sku:
1348 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1349 ass & 0xffff, codec->vendor_id);
1350 /*
1351 * 0 : override
1352 * 1 : Swap Jack
1353 * 2 : 0 --> Desktop, 1 --> Laptop
1354 * 3~5 : External Amplifier control
1355 * 7~6 : Reserved
1356 */
1357 tmp = (ass & 0x38) >> 3; /* external Amp control */
1358 switch (tmp) {
1359 case 1:
1360 spec->init_amp = ALC_INIT_GPIO1;
1361 break;
1362 case 3:
1363 spec->init_amp = ALC_INIT_GPIO2;
1364 break;
1365 case 7:
1366 spec->init_amp = ALC_INIT_GPIO3;
1367 break;
1368 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001369 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001370 spec->init_amp = ALC_INIT_DEFAULT;
1371 break;
1372 }
1373
1374 /* is laptop or Desktop and enable the function "Mute internal speaker
1375 * when the external headphone out jack is plugged"
1376 */
1377 if (!(ass & 0x8000))
1378 return 1;
1379 /*
1380 * 10~8 : Jack location
1381 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1382 * 14~13: Resvered
1383 * 15 : 1 --> enable the function "Mute internal speaker
1384 * when the external headphone out jack is plugged"
1385 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001386 if (!spec->autocfg.hp_pins[0] &&
1387 !(spec->autocfg.line_out_pins[0] &&
1388 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001389 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001390 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1391 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001392 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001393 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001394 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001395 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001396 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001397 else if (tmp == 3)
1398 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001399 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001400 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001401 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1402 spec->autocfg.line_outs))
1403 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001404 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001405 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001406 return 1;
1407}
Kailang Yangea1fb292008-08-26 12:58:38 +02001408
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001409/* Check the validity of ALC subsystem-id
1410 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1411static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001412{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001413 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001414 struct alc_spec *spec = codec->spec;
1415 snd_printd("realtek: "
1416 "Enable default setup for auto mode as fallback\n");
1417 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001418 }
Takashi Iwai21268962011-07-07 15:01:13 +02001419}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001420
Takashi Iwai41e41f12005-06-08 14:48:49 +02001421/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001422 * COEF access helper functions
1423 */
Kailang Yang274693f2009-12-03 10:07:50 +01001424static int alc_read_coef_idx(struct hda_codec *codec,
1425 unsigned int coef_idx)
1426{
1427 unsigned int val;
1428 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1429 coef_idx);
1430 val = snd_hda_codec_read(codec, 0x20, 0,
1431 AC_VERB_GET_PROC_COEF, 0);
1432 return val;
1433}
1434
Kailang Yang977ddd62010-09-15 10:02:29 +02001435static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1436 unsigned int coef_val)
1437{
1438 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1439 coef_idx);
1440 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1441 coef_val);
1442}
1443
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001444/* a special bypass for COEF 0; read the cached value at the second time */
1445static unsigned int alc_get_coef0(struct hda_codec *codec)
1446{
1447 struct alc_spec *spec = codec->spec;
1448 if (!spec->coef0)
1449 spec->coef0 = alc_read_coef_idx(codec, 0);
1450 return spec->coef0;
1451}
1452
Takashi Iwai1d045db2011-07-07 18:23:21 +02001453/*
1454 * Digital I/O handling
1455 */
1456
Takashi Iwai757899a2010-07-30 10:48:14 +02001457/* set right pin controls for digital I/O */
1458static void alc_auto_init_digital(struct hda_codec *codec)
1459{
1460 struct alc_spec *spec = codec->spec;
1461 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001462 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001463
1464 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1465 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001466 if (!pin)
1467 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001468 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001469 if (!i)
1470 dac = spec->multiout.dig_out_nid;
1471 else
1472 dac = spec->slave_dig_outs[i - 1];
1473 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1474 continue;
1475 snd_hda_codec_write(codec, dac, 0,
1476 AC_VERB_SET_AMP_GAIN_MUTE,
1477 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001478 }
1479 pin = spec->autocfg.dig_in_pin;
1480 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001481 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001482}
1483
1484/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1485static void alc_auto_parse_digital(struct hda_codec *codec)
1486{
1487 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001488 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001489 hda_nid_t dig_nid;
1490
1491 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001492 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001493 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001494 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001495 err = snd_hda_get_connections(codec,
1496 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001497 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001498 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001499 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001500 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001501 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001502 spec->multiout.dig_out_nid = dig_nid;
1503 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1504 } else {
1505 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001506 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001507 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001508 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001509 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001510 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001511 }
1512
1513 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001514 dig_nid = codec->start_nid;
1515 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1516 unsigned int wcaps = get_wcaps(codec, dig_nid);
1517 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1518 continue;
1519 if (!(wcaps & AC_WCAP_DIGITAL))
1520 continue;
1521 if (!(wcaps & AC_WCAP_CONN_LIST))
1522 continue;
1523 err = get_connection_index(codec, dig_nid,
1524 spec->autocfg.dig_in_pin);
1525 if (err >= 0) {
1526 spec->dig_in_nid = dig_nid;
1527 break;
1528 }
1529 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001530 }
1531}
1532
Takashi Iwaif95474e2007-07-10 00:47:43 +02001533/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001534 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001535 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001536static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1537 struct snd_ctl_elem_info *uinfo)
1538{
1539 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1540 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001541 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001542 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001543
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001544 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001545 if (spec->vol_in_capsrc)
1546 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1547 else
1548 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1549 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001550 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001551 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001552 return err;
1553}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001555static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1556 unsigned int size, unsigned int __user *tlv)
1557{
1558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1559 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001560 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001561 int err;
1562
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001563 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001564 if (spec->vol_in_capsrc)
1565 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1566 else
1567 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1568 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001569 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001570 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001571 return err;
1572}
1573
1574typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1575 struct snd_ctl_elem_value *ucontrol);
1576
1577static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1578 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001579 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001580{
1581 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1582 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001583 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001584
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001585 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001586 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001587 for (i = 0; i < spec->num_adc_nids; i++) {
1588 kcontrol->private_value =
1589 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1590 3, 0, HDA_INPUT);
1591 err = func(kcontrol, ucontrol);
1592 if (err < 0)
1593 goto error;
1594 }
1595 } else {
1596 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001597 if (spec->vol_in_capsrc)
1598 kcontrol->private_value =
1599 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1600 3, 0, HDA_OUTPUT);
1601 else
1602 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001603 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1604 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001605 err = func(kcontrol, ucontrol);
1606 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001607 if (err >= 0 && is_put)
1608 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001609 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001610 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001611 return err;
1612}
1613
1614static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1615 struct snd_ctl_elem_value *ucontrol)
1616{
1617 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001618 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001619}
1620
1621static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1622 struct snd_ctl_elem_value *ucontrol)
1623{
1624 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001625 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001626}
1627
1628/* capture mixer elements */
1629#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1630
1631static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1632 struct snd_ctl_elem_value *ucontrol)
1633{
1634 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001635 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001636}
1637
1638static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1639 struct snd_ctl_elem_value *ucontrol)
1640{
1641 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001642 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001643}
1644
Takashi Iwaia23b6882009-03-23 15:21:36 +01001645#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001646 { \
1647 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1648 .name = "Capture Switch", \
1649 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1650 .count = num, \
1651 .info = alc_cap_sw_info, \
1652 .get = alc_cap_sw_get, \
1653 .put = alc_cap_sw_put, \
1654 }, \
1655 { \
1656 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1657 .name = "Capture Volume", \
1658 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1659 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1660 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1661 .count = num, \
1662 .info = alc_cap_vol_info, \
1663 .get = alc_cap_vol_get, \
1664 .put = alc_cap_vol_put, \
1665 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001666 }
1667
1668#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001669 { \
1670 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1671 /* .name = "Capture Source", */ \
1672 .name = "Input Source", \
1673 .count = num, \
1674 .info = alc_mux_enum_info, \
1675 .get = alc_mux_enum_get, \
1676 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001677 }
1678
1679#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001680static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001681 _DEFINE_CAPMIX(num), \
1682 _DEFINE_CAPSRC(num), \
1683 { } /* end */ \
1684}
1685
1686#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001687static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001688 _DEFINE_CAPMIX(num), \
1689 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001690}
1691
1692/* up to three ADCs */
1693DEFINE_CAPMIX(1);
1694DEFINE_CAPMIX(2);
1695DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001696DEFINE_CAPMIX_NOSRC(1);
1697DEFINE_CAPMIX_NOSRC(2);
1698DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001699
1700/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001701 * Inverted digital-mic handling
1702 *
1703 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1704 * gives the additional mute only to the right channel of the digital mic
1705 * capture stream. This is a workaround for avoiding the almost silence
1706 * by summing the stereo stream from some (known to be ForteMedia)
1707 * digital mic unit.
1708 *
1709 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1710 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1711 * without caching so that the cache can still keep the original value.
1712 * The cached value is then restored when the flag is set off or any other
1713 * than d-mic is used as the current input source.
1714 */
1715static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1716{
1717 struct alc_spec *spec = codec->spec;
1718 int i;
1719
1720 if (!spec->inv_dmic_fixup)
1721 return;
1722 if (!spec->inv_dmic_muted && !force)
1723 return;
1724 for (i = 0; i < spec->num_adc_nids; i++) {
1725 int src = spec->dyn_adc_switch ? 0 : i;
1726 bool dmic_fixup = false;
1727 hda_nid_t nid;
1728 int parm, dir, v;
1729
1730 if (spec->inv_dmic_muted &&
1731 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1732 dmic_fixup = true;
1733 if (!dmic_fixup && !force)
1734 continue;
1735 if (spec->vol_in_capsrc) {
1736 nid = spec->capsrc_nids[i];
1737 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1738 dir = HDA_OUTPUT;
1739 } else {
1740 nid = spec->adc_nids[i];
1741 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1742 dir = HDA_INPUT;
1743 }
1744 /* we care only right channel */
1745 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1746 if (v & 0x80) /* if already muted, we don't need to touch */
1747 continue;
1748 if (dmic_fixup) /* add mute for d-mic */
1749 v |= 0x80;
1750 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1751 parm | v);
1752 }
1753}
1754
1755static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol)
1757{
1758 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1759 struct alc_spec *spec = codec->spec;
1760
1761 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1762 return 0;
1763}
1764
1765static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1766 struct snd_ctl_elem_value *ucontrol)
1767{
1768 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1769 struct alc_spec *spec = codec->spec;
1770 unsigned int val = !ucontrol->value.integer.value[0];
1771
1772 if (val == spec->inv_dmic_muted)
1773 return 0;
1774 spec->inv_dmic_muted = val;
1775 alc_inv_dmic_sync(codec, true);
1776 return 0;
1777}
1778
1779static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1780 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1781 .info = snd_ctl_boolean_mono_info,
1782 .get = alc_inv_dmic_sw_get,
1783 .put = alc_inv_dmic_sw_put,
1784};
1785
1786static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1787{
1788 struct alc_spec *spec = codec->spec;
1789 struct snd_kcontrol_new *knew = alc_kcontrol_new(spec);
1790 if (!knew)
1791 return -ENOMEM;
1792 *knew = alc_inv_dmic_sw;
1793 knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL);
1794 if (!knew->name)
1795 return -ENOMEM;
1796 spec->inv_dmic_fixup = 1;
1797 spec->inv_dmic_muted = 0;
1798 spec->inv_dmic_pin = nid;
1799 return 0;
1800}
1801
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001802/* typically the digital mic is put at node 0x12 */
1803static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1804 const struct alc_fixup *fix, int action)
1805{
1806 if (action == ALC_FIXUP_ACT_PROBE)
1807 alc_add_inv_dmic_mixer(codec, 0x12);
1808}
1809
Takashi Iwai125821a2012-06-22 14:30:29 +02001810/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001811 * virtual master controls
1812 */
1813
1814/*
1815 * slave controls for virtual master
1816 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001817static const char * const alc_slave_pfxs[] = {
1818 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001819 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001820 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001821 NULL,
1822};
1823
1824/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001825 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001827
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001828#define NID_MAPPING (-1)
1829
1830#define SUBDEV_SPEAKER_ (0 << 6)
1831#define SUBDEV_HP_ (1 << 6)
1832#define SUBDEV_LINE_ (2 << 6)
1833#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1834#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1835#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1836
Takashi Iwai603c4012008-07-30 15:01:44 +02001837static void alc_free_kctls(struct hda_codec *codec);
1838
Takashi Iwai67d634c2009-11-16 15:35:59 +01001839#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001840/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001841static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001842 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001843 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001844 { } /* end */
1845};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001846#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001847
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001848static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849{
1850 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001851 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001852 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001853 int i, j, err;
1854 unsigned int u;
1855 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
1857 for (i = 0; i < spec->num_mixers; i++) {
1858 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1859 if (err < 0)
1860 return err;
1861 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001862 if (spec->cap_mixer) {
1863 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1864 if (err < 0)
1865 return err;
1866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001868 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001869 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001870 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 if (err < 0)
1872 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001873 if (!spec->no_analog) {
1874 err = snd_hda_create_spdif_share_sw(codec,
1875 &spec->multiout);
1876 if (err < 0)
1877 return err;
1878 spec->multiout.share_spdif = 1;
1879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 }
1881 if (spec->dig_in_nid) {
1882 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1883 if (err < 0)
1884 return err;
1885 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001886
Takashi Iwai67d634c2009-11-16 15:35:59 +01001887#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001888 /* create beep controls if needed */
1889 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001890 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001891 for (knew = alc_beep_mixer; knew->name; knew++) {
1892 struct snd_kcontrol *kctl;
1893 kctl = snd_ctl_new1(knew, codec);
1894 if (!kctl)
1895 return -ENOMEM;
1896 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001897 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001898 if (err < 0)
1899 return err;
1900 }
1901 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001902#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001903
Takashi Iwai2134ea42008-01-10 16:53:55 +01001904 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001905 if (!spec->no_analog &&
1906 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001907 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001908 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001909 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001910 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001911 vmaster_tlv, alc_slave_pfxs,
1912 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001913 if (err < 0)
1914 return err;
1915 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001916 if (!spec->no_analog &&
1917 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001918 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1919 NULL, alc_slave_pfxs,
1920 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001921 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001922 if (err < 0)
1923 return err;
1924 }
1925
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001926 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001927 if (spec->capsrc_nids || spec->adc_nids) {
1928 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1929 if (!kctl)
1930 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1931 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001932 err = snd_hda_add_nid(codec, kctl, i,
1933 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001934 if (err < 0)
1935 return err;
1936 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001937 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001938 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001939 const char *kname = kctl ? kctl->id.name : NULL;
1940 for (knew = spec->cap_mixer; knew->name; knew++) {
1941 if (kname && strcmp(knew->name, kname) == 0)
1942 continue;
1943 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1944 for (i = 0; kctl && i < kctl->count; i++) {
1945 err = snd_hda_add_nid(codec, kctl, i,
1946 spec->adc_nids[i]);
1947 if (err < 0)
1948 return err;
1949 }
1950 }
1951 }
1952
1953 /* other nid->control mapping */
1954 for (i = 0; i < spec->num_mixers; i++) {
1955 for (knew = spec->mixers[i]; knew->name; knew++) {
1956 if (knew->iface != NID_MAPPING)
1957 continue;
1958 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1959 if (kctl == NULL)
1960 continue;
1961 u = knew->subdevice;
1962 for (j = 0; j < 4; j++, u >>= 8) {
1963 nid = u & 0x3f;
1964 if (nid == 0)
1965 continue;
1966 switch (u & 0xc0) {
1967 case SUBDEV_SPEAKER_:
1968 nid = spec->autocfg.speaker_pins[nid];
1969 break;
1970 case SUBDEV_LINE_:
1971 nid = spec->autocfg.line_out_pins[nid];
1972 break;
1973 case SUBDEV_HP_:
1974 nid = spec->autocfg.hp_pins[nid];
1975 break;
1976 default:
1977 continue;
1978 }
1979 err = snd_hda_add_nid(codec, kctl, 0, nid);
1980 if (err < 0)
1981 return err;
1982 }
1983 u = knew->private_value;
1984 for (j = 0; j < 4; j++, u >>= 8) {
1985 nid = u & 0xff;
1986 if (nid == 0)
1987 continue;
1988 err = snd_hda_add_nid(codec, kctl, 0, nid);
1989 if (err < 0)
1990 return err;
1991 }
1992 }
1993 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001994
1995 alc_free_kctls(codec); /* no longer needed */
1996
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001997 return 0;
1998}
1999
David Henningsson5780b622012-06-27 18:45:45 +02002000static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002001{
2002 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02002003
2004 if (spec->shared_mic_hp) {
2005 int err;
2006 int nid = spec->autocfg.inputs[1].pin;
2007 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
2008 if (err < 0)
2009 return err;
2010 err = snd_hda_jack_detect_enable(codec, nid, 0);
2011 if (err < 0)
2012 return err;
2013 }
2014
2015 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2016}
2017
2018static int alc_build_controls(struct hda_codec *codec)
2019{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002020 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002021 if (err < 0)
2022 return err;
David Henningsson5780b622012-06-27 18:45:45 +02002023
2024 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002025 if (err < 0)
2026 return err;
2027 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2028 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029}
2030
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002031
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002033 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002034 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002035
Takashi Iwai584c0c42011-03-10 12:51:11 +01002036static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002037static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039static int alc_init(struct hda_codec *codec)
2040{
2041 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002042
Takashi Iwai546bb672012-03-07 08:37:19 +01002043 if (spec->init_hook)
2044 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002045
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002046 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002047 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002048
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002049 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002050 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002051 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002052
Takashi Iwai58701122011-01-13 15:41:45 +01002053 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2054
Takashi Iwai01a61e12011-10-28 00:03:22 +02002055 snd_hda_jack_report_sync(codec);
2056
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002057 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 return 0;
2059}
2060
Takashi Iwaicb53c622007-08-10 17:21:45 +02002061#ifdef CONFIG_SND_HDA_POWER_SAVE
2062static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2063{
2064 struct alc_spec *spec = codec->spec;
2065 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2066}
2067#endif
2068
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069/*
2070 * Analog playback callbacks
2071 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002072static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002074 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
2076 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002077 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2078 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079}
2080
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002081static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 struct hda_codec *codec,
2083 unsigned int stream_tag,
2084 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002085 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
2087 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002088 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2089 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090}
2091
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002092static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002094 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
2096 struct alc_spec *spec = codec->spec;
2097 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2098}
2099
2100/*
2101 * Digital out
2102 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002103static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002105 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106{
2107 struct alc_spec *spec = codec->spec;
2108 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2109}
2110
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002111static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002112 struct hda_codec *codec,
2113 unsigned int stream_tag,
2114 unsigned int format,
2115 struct snd_pcm_substream *substream)
2116{
2117 struct alc_spec *spec = codec->spec;
2118 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2119 stream_tag, format, substream);
2120}
2121
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002122static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002123 struct hda_codec *codec,
2124 struct snd_pcm_substream *substream)
2125{
2126 struct alc_spec *spec = codec->spec;
2127 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2128}
2129
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002130static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002132 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
2134 struct alc_spec *spec = codec->spec;
2135 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2136}
2137
2138/*
2139 * Analog capture
2140 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002141static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 struct hda_codec *codec,
2143 unsigned int stream_tag,
2144 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002145 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146{
2147 struct alc_spec *spec = codec->spec;
2148
Takashi Iwai63300792008-01-24 15:31:36 +01002149 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 stream_tag, 0, format);
2151 return 0;
2152}
2153
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002154static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002156 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
2158 struct alc_spec *spec = codec->spec;
2159
Takashi Iwai888afa12008-03-18 09:57:50 +01002160 snd_hda_codec_cleanup_stream(codec,
2161 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 return 0;
2163}
2164
Takashi Iwai840b64c2010-07-13 22:49:01 +02002165/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002166static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002167 struct hda_codec *codec,
2168 unsigned int stream_tag,
2169 unsigned int format,
2170 struct snd_pcm_substream *substream)
2171{
2172 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002173 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002174 spec->cur_adc_stream_tag = stream_tag;
2175 spec->cur_adc_format = format;
2176 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2177 return 0;
2178}
2179
Takashi Iwai21268962011-07-07 15:01:13 +02002180static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002181 struct hda_codec *codec,
2182 struct snd_pcm_substream *substream)
2183{
2184 struct alc_spec *spec = codec->spec;
2185 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2186 spec->cur_adc = 0;
2187 return 0;
2188}
2189
Takashi Iwai21268962011-07-07 15:01:13 +02002190static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002191 .substreams = 1,
2192 .channels_min = 2,
2193 .channels_max = 2,
2194 .nid = 0, /* fill later */
2195 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002196 .prepare = dyn_adc_capture_pcm_prepare,
2197 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002198 },
2199};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
2201/*
2202 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002203static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 .substreams = 1,
2205 .channels_min = 2,
2206 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002207 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002209 .open = alc_playback_pcm_open,
2210 .prepare = alc_playback_pcm_prepare,
2211 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 },
2213};
2214
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002215static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002216 .substreams = 1,
2217 .channels_min = 2,
2218 .channels_max = 2,
2219 /* NID is set in alc_build_pcms */
2220};
2221
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002222static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002223 .substreams = 1,
2224 .channels_min = 2,
2225 .channels_max = 2,
2226 /* NID is set in alc_build_pcms */
2227};
2228
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002229static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002230 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 .channels_min = 2,
2232 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002233 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002235 .prepare = alc_alt_capture_pcm_prepare,
2236 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 },
2238};
2239
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002240static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 .substreams = 1,
2242 .channels_min = 2,
2243 .channels_max = 2,
2244 /* NID is set in alc_build_pcms */
2245 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002246 .open = alc_dig_playback_pcm_open,
2247 .close = alc_dig_playback_pcm_close,
2248 .prepare = alc_dig_playback_pcm_prepare,
2249 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 },
2251};
2252
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002253static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 .substreams = 1,
2255 .channels_min = 2,
2256 .channels_max = 2,
2257 /* NID is set in alc_build_pcms */
2258};
2259
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002260/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002261static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002262 .substreams = 0,
2263 .channels_min = 0,
2264 .channels_max = 0,
2265};
2266
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267static int alc_build_pcms(struct hda_codec *codec)
2268{
2269 struct alc_spec *spec = codec->spec;
2270 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002271 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002272 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 int i;
2274
2275 codec->num_pcms = 1;
2276 codec->pcm_info = info;
2277
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002278 if (spec->no_analog)
2279 goto skip_analog;
2280
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002281 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2282 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002284
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002285 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002286 p = spec->stream_analog_playback;
2287 if (!p)
2288 p = &alc_pcm_analog_playback;
2289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2291 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002292 if (spec->adc_nids) {
2293 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002294 if (!p) {
2295 if (spec->dyn_adc_switch)
2296 p = &dyn_adc_pcm_analog_capture;
2297 else
2298 p = &alc_pcm_analog_capture;
2299 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002300 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002301 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
Takashi Iwai4a471b72005-12-07 13:56:29 +01002304 if (spec->channel_mode) {
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2306 for (i = 0; i < spec->num_channel_mode; i++) {
2307 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2308 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 }
2311 }
2312
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002313 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002314 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002316 snprintf(spec->stream_name_digital,
2317 sizeof(spec->stream_name_digital),
2318 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002319 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002320 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002321 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002323 if (spec->dig_out_type)
2324 info->pcm_type = spec->dig_out_type;
2325 else
2326 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002327 if (spec->multiout.dig_out_nid) {
2328 p = spec->stream_digital_playback;
2329 if (!p)
2330 p = &alc_pcm_digital_playback;
2331 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2333 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002334 if (spec->dig_in_nid) {
2335 p = spec->stream_digital_capture;
2336 if (!p)
2337 p = &alc_pcm_digital_capture;
2338 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2340 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002341 /* FIXME: do we need this for all Realtek codec models? */
2342 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 }
2344
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002345 if (spec->no_analog)
2346 return 0;
2347
Takashi Iwaie08a0072006-09-07 17:52:14 +02002348 /* If the use of more than one ADC is requested for the current
2349 * model, configure a second analog capture-only PCM.
2350 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002351 have_multi_adcs = (spec->num_adc_nids > 1) &&
2352 !spec->dyn_adc_switch && !spec->auto_mic &&
2353 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002354 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002355 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002356 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002357 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002358 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002359 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002360 p = spec->stream_analog_alt_playback;
2361 if (!p)
2362 p = &alc_pcm_analog_alt_playback;
2363 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002364 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2365 spec->alt_dac_nid;
2366 } else {
2367 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2368 alc_pcm_null_stream;
2369 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2370 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002371 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002372 p = spec->stream_analog_alt_capture;
2373 if (!p)
2374 p = &alc_pcm_analog_alt_capture;
2375 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002376 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2377 spec->adc_nids[1];
2378 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2379 spec->num_adc_nids - 1;
2380 } else {
2381 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2382 alc_pcm_null_stream;
2383 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002384 }
2385 }
2386
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 return 0;
2388}
2389
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002390static inline void alc_shutup(struct hda_codec *codec)
2391{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002392 struct alc_spec *spec = codec->spec;
2393
2394 if (spec && spec->shutup)
2395 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002396 snd_hda_shutup_pins(codec);
2397}
2398
Takashi Iwai603c4012008-07-30 15:01:44 +02002399static void alc_free_kctls(struct hda_codec *codec)
2400{
2401 struct alc_spec *spec = codec->spec;
2402
2403 if (spec->kctls.list) {
2404 struct snd_kcontrol_new *kctl = spec->kctls.list;
2405 int i;
2406 for (i = 0; i < spec->kctls.used; i++)
2407 kfree(kctl[i].name);
2408 }
2409 snd_array_free(&spec->kctls);
2410}
2411
Takashi Iwai23c09b02011-08-19 09:05:35 +02002412static void alc_free_bind_ctls(struct hda_codec *codec)
2413{
2414 struct alc_spec *spec = codec->spec;
2415 if (spec->bind_ctls.list) {
2416 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2417 int i;
2418 for (i = 0; i < spec->bind_ctls.used; i++)
2419 kfree(ctl[i]);
2420 }
2421 snd_array_free(&spec->bind_ctls);
2422}
2423
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424static void alc_free(struct hda_codec *codec)
2425{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002426 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002427
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002428 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002429 return;
2430
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002431 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002432 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002433 alc_free_bind_ctls(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002434 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002435 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002436 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437}
2438
Hector Martinf5de24b2009-12-20 22:51:31 +01002439#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002440static void alc_power_eapd(struct hda_codec *codec)
2441{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002442 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002443}
2444
Hector Martinf5de24b2009-12-20 22:51:31 +01002445static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2446{
2447 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002448 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002449 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002450 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002451 return 0;
2452}
2453#endif
2454
Takashi Iwai2a439522011-07-26 09:52:50 +02002455#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002456static int alc_resume(struct hda_codec *codec)
2457{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002458 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002459 codec->patch_ops.init(codec);
2460 snd_hda_codec_resume_amp(codec);
2461 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002462 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002463 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002464 return 0;
2465}
Takashi Iwaie044c392008-10-27 16:56:24 +01002466#endif
2467
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468/*
2469 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002470static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 .build_controls = alc_build_controls,
2472 .build_pcms = alc_build_pcms,
2473 .init = alc_init,
2474 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002475 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002476#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002477 .resume = alc_resume,
2478#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002479#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002480 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002481 .check_power_status = alc_check_power_status,
2482#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002483 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484};
2485
Kailang Yangc027ddc2010-03-19 11:33:06 +01002486/* replace the codec chip_name with the given string */
2487static int alc_codec_rename(struct hda_codec *codec, const char *name)
2488{
2489 kfree(codec->chip_name);
2490 codec->chip_name = kstrdup(name, GFP_KERNEL);
2491 if (!codec->chip_name) {
2492 alc_free(codec);
2493 return -ENOMEM;
2494 }
2495 return 0;
2496}
2497
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002498/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002499 * Rename codecs appropriately from COEF value
2500 */
2501struct alc_codec_rename_table {
2502 unsigned int vendor_id;
2503 unsigned short coef_mask;
2504 unsigned short coef_bits;
2505 const char *name;
2506};
2507
2508static struct alc_codec_rename_table rename_tbl[] = {
2509 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2510 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2511 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2512 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2513 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2514 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2515 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002516 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002517 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2518 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2519 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2520 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2521 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2522 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2523 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2524 { } /* terminator */
2525};
2526
2527static int alc_codec_rename_from_preset(struct hda_codec *codec)
2528{
2529 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002530
2531 for (p = rename_tbl; p->vendor_id; p++) {
2532 if (p->vendor_id != codec->vendor_id)
2533 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002534 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002535 return alc_codec_rename(codec, p->name);
2536 }
2537 return 0;
2538}
2539
2540/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002541 * Automatic parse of I/O pins from the BIOS configuration
2542 */
2543
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002544enum {
2545 ALC_CTL_WIDGET_VOL,
2546 ALC_CTL_WIDGET_MUTE,
2547 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002548 ALC_CTL_BIND_VOL,
2549 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002550};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002551static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002552 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2553 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002554 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002555 HDA_BIND_VOL(NULL, 0),
2556 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002557};
2558
2559/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002560static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002561 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002562{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002563 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002564
Takashi Iwaice764ab2011-04-27 16:35:23 +02002565 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002566 if (!knew)
2567 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002568 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002569 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002570 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002571 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002572 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002573 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002574 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002575 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002576 return 0;
2577}
2578
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002579static int add_control_with_pfx(struct alc_spec *spec, int type,
2580 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002581 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002582{
2583 char name[32];
2584 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002585 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002586}
2587
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002588#define add_pb_vol_ctrl(spec, type, pfx, val) \
2589 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2590#define add_pb_sw_ctrl(spec, type, pfx, val) \
2591 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2592#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2593 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2594#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2595 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002596
Takashi Iwai23c09b02011-08-19 09:05:35 +02002597static const char * const channel_name[4] = {
2598 "Front", "Surround", "CLFE", "Side"
2599};
2600
Takashi Iwai6843ca12011-06-24 11:03:58 +02002601static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2602 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002603{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002604 struct auto_pin_cfg *cfg = &spec->autocfg;
2605
Takashi Iwai6843ca12011-06-24 11:03:58 +02002606 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002607 if (cfg->line_outs == 1 && !spec->multi_ios &&
2608 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002609 return "Master";
2610
2611 switch (cfg->line_out_type) {
2612 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002613 if (cfg->line_outs == 1)
2614 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002615 if (cfg->line_outs == 2)
2616 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002617 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002618 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002619 /* for multi-io case, only the primary out */
2620 if (ch && spec->multi_ios)
2621 break;
2622 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002623 return "Headphone";
2624 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002625 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002626 return "PCM";
2627 break;
2628 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002629 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2630 return "PCM";
2631
2632 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002633}
2634
Takashi Iwai164f73e2012-02-21 11:27:09 +01002635#ifdef CONFIG_SND_HDA_POWER_SAVE
2636/* add the powersave loopback-list entry */
2637static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2638{
2639 struct hda_amp_list *list;
2640
2641 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2642 return;
2643 list = spec->loopback_list + spec->num_loopbacks;
2644 list->nid = mix;
2645 list->dir = HDA_INPUT;
2646 list->idx = idx;
2647 spec->num_loopbacks++;
2648 spec->loopback.amplist = spec->loopback_list;
2649}
2650#else
2651#define add_loopback_list(spec, mix, idx) /* NOP */
2652#endif
2653
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002654/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002655static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002656 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002657 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002658{
Kailang Yangdf694da2005-12-05 19:42:22 +01002659 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002660
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002661 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002662 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2663 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002664 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002665 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002666 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2667 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002668 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002669 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002670 return 0;
2671}
2672
Takashi Iwai05f5f472009-08-25 13:10:18 +02002673static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002674{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002675 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2676 return (pincap & AC_PINCAP_IN) != 0;
2677}
2678
Takashi Iwai1d045db2011-07-07 18:23:21 +02002679/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002680static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002681{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002682 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002683 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002684 hda_nid_t *adc_nids = spec->private_adc_nids;
2685 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2686 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002687 int i, nums = 0;
2688
2689 nid = codec->start_nid;
2690 for (i = 0; i < codec->num_nodes; i++, nid++) {
2691 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002692 unsigned int caps = get_wcaps(codec, nid);
2693 int type = get_wcaps_type(caps);
2694
2695 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2696 continue;
2697 adc_nids[nums] = nid;
2698 cap_nids[nums] = nid;
2699 src = nid;
2700 for (;;) {
2701 int n;
2702 type = get_wcaps_type(get_wcaps(codec, src));
2703 if (type == AC_WID_PIN)
2704 break;
2705 if (type == AC_WID_AUD_SEL) {
2706 cap_nids[nums] = src;
2707 break;
2708 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002709 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002710 if (n > 1) {
2711 cap_nids[nums] = src;
2712 break;
2713 } else if (n != 1)
2714 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002715 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2716 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002717 }
2718 if (++nums >= max_nums)
2719 break;
2720 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002721 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002722 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002723 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002724 return nums;
2725}
2726
Takashi Iwai05f5f472009-08-25 13:10:18 +02002727/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002728static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002729{
2730 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002731 const struct auto_pin_cfg *cfg = &spec->autocfg;
2732 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002733 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002734 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002735 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002736 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002737
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002738 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002739 if (num_adcs < 0)
2740 return 0;
2741
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002742 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002743 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002744 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002745
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002746 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002747 if (!alc_is_input_pin(codec, pin))
2748 continue;
2749
David Henningsson5322bf22011-01-05 11:03:56 +01002750 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002751 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2752 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002753 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002754 type_idx++;
2755 else
2756 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002757 prev_label = label;
2758
Takashi Iwai05f5f472009-08-25 13:10:18 +02002759 if (mixer) {
2760 idx = get_connection_index(codec, mixer, pin);
2761 if (idx >= 0) {
2762 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002763 label, type_idx,
2764 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002765 if (err < 0)
2766 return err;
2767 }
2768 }
2769
Takashi Iwaib7821702011-07-06 15:12:46 +02002770 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002771 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002772 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002773 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002774 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002775 snd_hda_add_imux_item(imux, label, idx, NULL);
2776 break;
2777 }
2778 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002779 }
Takashi Iwai21268962011-07-07 15:01:13 +02002780
2781 spec->num_mux_defs = 1;
2782 spec->input_mux = imux;
2783
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002784 return 0;
2785}
2786
Takashi Iwai24de1832011-11-07 17:13:39 +01002787/* create a shared input with the headphone out */
2788static int alc_auto_create_shared_input(struct hda_codec *codec)
2789{
2790 struct alc_spec *spec = codec->spec;
2791 struct auto_pin_cfg *cfg = &spec->autocfg;
2792 unsigned int defcfg;
2793 hda_nid_t nid;
2794
2795 /* only one internal input pin? */
2796 if (cfg->num_inputs != 1)
2797 return 0;
2798 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2799 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2800 return 0;
2801
2802 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2803 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2804 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2805 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2806 else
2807 return 0; /* both not available */
2808
2809 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2810 return 0; /* no input */
2811
2812 cfg->inputs[1].pin = nid;
2813 cfg->inputs[1].type = AUTO_PIN_MIC;
2814 cfg->num_inputs = 2;
2815 spec->shared_mic_hp = 1;
2816 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2817 return 0;
2818}
2819
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002820static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2821 unsigned int pin_type)
2822{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002823 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002824 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002825 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2826 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002827 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002828}
2829
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002830static int get_pin_type(int line_out_type)
2831{
2832 if (line_out_type == AUTO_PIN_HP_OUT)
2833 return PIN_HP;
2834 else
2835 return PIN_OUT;
2836}
2837
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002838static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002839{
2840 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002841 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002842 int i;
2843
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002844 for (i = 0; i < cfg->num_inputs; i++) {
2845 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002846 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002847 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002848 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002849 snd_hda_codec_write(codec, nid, 0,
2850 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002851 AMP_OUT_MUTE);
2852 }
2853 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002854
2855 /* mute all loopback inputs */
2856 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002857 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002858 for (i = 0; i < nums; i++)
2859 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2860 AC_VERB_SET_AMP_GAIN_MUTE,
2861 AMP_IN_MUTE(i));
2862 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002863}
2864
Takashi Iwai7085ec12009-10-02 09:03:58 +02002865/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002866static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002867{
Takashi Iwai604401a2011-04-27 15:14:23 +02002868 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002869 int i, num;
2870
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002871 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2872 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002873 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2874 for (i = 0; i < num; i++) {
2875 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2876 return list[i];
2877 }
2878 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002879}
2880
Takashi Iwai604401a2011-04-27 15:14:23 +02002881/* go down to the selector widget before the mixer */
2882static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2883{
2884 hda_nid_t srcs[5];
2885 int num = snd_hda_get_connections(codec, pin, srcs,
2886 ARRAY_SIZE(srcs));
2887 if (num != 1 ||
2888 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2889 return pin;
2890 return srcs[0];
2891}
2892
Takashi Iwai7085ec12009-10-02 09:03:58 +02002893/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002894static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002895 hda_nid_t dac)
2896{
David Henningssoncc1c4522010-11-24 14:17:47 +01002897 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002898 int i, num;
2899
Takashi Iwai604401a2011-04-27 15:14:23 +02002900 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002901 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2902 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002903 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002904 return mix[i];
2905 }
2906 return 0;
2907}
2908
Takashi Iwaice764ab2011-04-27 16:35:23 +02002909/* select the connection from pin to DAC if needed */
2910static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2911 hda_nid_t dac)
2912{
2913 hda_nid_t mix[5];
2914 int i, num;
2915
2916 pin = alc_go_down_to_selector(codec, pin);
2917 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2918 if (num < 2)
2919 return 0;
2920 for (i = 0; i < num; i++) {
2921 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2922 snd_hda_codec_update_cache(codec, pin, 0,
2923 AC_VERB_SET_CONNECT_SEL, i);
2924 return 0;
2925 }
2926 }
2927 return 0;
2928}
2929
Takashi Iwai185d99f2012-02-16 18:39:45 +01002930static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2931{
2932 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002933 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002934 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2935 ARRAY_SIZE(spec->private_dac_nids)) ||
2936 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2937 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2938 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2939 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2940 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002941 for (i = 0; i < spec->multi_ios; i++) {
2942 if (spec->multi_io[i].dac == nid)
2943 return true;
2944 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002945 return false;
2946}
2947
Takashi Iwai7085ec12009-10-02 09:03:58 +02002948/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002949static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002950{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002951 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002952 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002953
Takashi Iwai604401a2011-04-27 15:14:23 +02002954 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002955 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002956 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002957 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002958 if (!nid)
2959 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002960 if (!alc_is_dac_already_used(codec, nid))
2961 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002962 }
2963 return 0;
2964}
2965
Takashi Iwai07b18f62011-11-10 15:42:54 +01002966/* check whether the DAC is reachable from the pin */
2967static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2968 hda_nid_t pin, hda_nid_t dac)
2969{
2970 hda_nid_t srcs[5];
2971 int i, num;
2972
Takashi Iwaidc31b582012-02-17 17:27:53 +01002973 if (!pin || !dac)
2974 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002975 pin = alc_go_down_to_selector(codec, pin);
2976 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2977 for (i = 0; i < num; i++) {
2978 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2979 if (nid == dac)
2980 return true;
2981 }
2982 return false;
2983}
2984
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002985static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2986{
Takashi Iwai140547e2012-02-16 17:23:46 +01002987 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002988 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002989 hda_nid_t nid, nid_found, srcs[5];
2990 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01002991 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01002992 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002993 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002994 nid_found = 0;
2995 for (i = 0; i < num; i++) {
2996 if (srcs[i] == spec->mixer_nid)
2997 continue;
2998 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2999 if (nid && !alc_is_dac_already_used(codec, nid)) {
3000 if (nid_found)
3001 return 0;
3002 nid_found = nid;
3003 }
3004 }
3005 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003006}
3007
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003008/* mark up volume and mute control NIDs: used during badness parsing and
3009 * at creating actual controls
3010 */
3011static inline unsigned int get_ctl_pos(unsigned int data)
3012{
3013 hda_nid_t nid = get_amp_nid_(data);
3014 unsigned int dir;
3015 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3016 return 0;
3017 dir = get_amp_direction_(data);
3018 return (nid << 1) | dir;
3019}
3020
3021#define is_ctl_used(bits, data) \
3022 test_bit(get_ctl_pos(data), bits)
3023#define mark_ctl_usage(bits, data) \
3024 set_bit(get_ctl_pos(data), bits)
3025
3026static void clear_vol_marks(struct hda_codec *codec)
3027{
3028 struct alc_spec *spec = codec->spec;
3029 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3030 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3031}
3032
3033/* badness definition */
3034enum {
3035 /* No primary DAC is found for the main output */
3036 BAD_NO_PRIMARY_DAC = 0x10000,
3037 /* No DAC is found for the extra output */
3038 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003039 /* No possible multi-ios */
3040 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003041 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003042 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003043 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003044 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003045 /* Primary DAC shared with main surrounds */
3046 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003047 /* Primary DAC shared with main CLFE */
3048 BAD_SHARED_CLFE = 0x10,
3049 /* Primary DAC shared with extra surrounds */
3050 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003051 /* Volume widget is shared */
3052 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003053};
3054
3055static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3056 hda_nid_t pin, hda_nid_t dac);
3057static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3058 hda_nid_t pin, hda_nid_t dac);
3059
3060static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3061 hda_nid_t dac)
3062{
3063 struct alc_spec *spec = codec->spec;
3064 hda_nid_t nid;
3065 unsigned int val;
3066 int badness = 0;
3067
3068 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3069 if (nid) {
3070 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3071 if (is_ctl_used(spec->vol_ctls, nid))
3072 badness += BAD_SHARED_VOL;
3073 else
3074 mark_ctl_usage(spec->vol_ctls, val);
3075 } else
3076 badness += BAD_SHARED_VOL;
3077 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3078 if (nid) {
3079 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3080 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3081 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3082 else
3083 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3084 if (is_ctl_used(spec->sw_ctls, val))
3085 badness += BAD_SHARED_VOL;
3086 else
3087 mark_ctl_usage(spec->sw_ctls, val);
3088 } else
3089 badness += BAD_SHARED_VOL;
3090 return badness;
3091}
3092
Takashi Iwaidc31b582012-02-17 17:27:53 +01003093struct badness_table {
3094 int no_primary_dac; /* no primary DAC */
3095 int no_dac; /* no secondary DACs */
3096 int shared_primary; /* primary DAC is shared with main output */
3097 int shared_surr; /* secondary DAC shared with main or primary */
3098 int shared_clfe; /* third DAC shared with main or primary */
3099 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3100};
3101
3102static struct badness_table main_out_badness = {
3103 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3104 .no_dac = BAD_NO_DAC,
3105 .shared_primary = BAD_NO_PRIMARY_DAC,
3106 .shared_surr = BAD_SHARED_SURROUND,
3107 .shared_clfe = BAD_SHARED_CLFE,
3108 .shared_surr_main = BAD_SHARED_SURROUND,
3109};
3110
3111static struct badness_table extra_out_badness = {
3112 .no_primary_dac = BAD_NO_DAC,
3113 .no_dac = BAD_NO_DAC,
3114 .shared_primary = BAD_NO_EXTRA_DAC,
3115 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3116 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3117 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3118};
3119
3120/* try to assign DACs to pins and return the resultant badness */
3121static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3122 const hda_nid_t *pins, hda_nid_t *dacs,
3123 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003124{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003125 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003126 struct auto_pin_cfg *cfg = &spec->autocfg;
3127 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003128 int badness = 0;
3129 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003130
Takashi Iwai185d99f2012-02-16 18:39:45 +01003131 if (!num_outs)
3132 return 0;
3133
Takashi Iwaidc31b582012-02-17 17:27:53 +01003134 for (i = 0; i < num_outs; i++) {
3135 hda_nid_t pin = pins[i];
3136 if (!dacs[i])
3137 dacs[i] = alc_auto_look_for_dac(codec, pin);
3138 if (!dacs[i] && !i) {
3139 for (j = 1; j < num_outs; j++) {
3140 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3141 dacs[0] = dacs[j];
3142 dacs[j] = 0;
3143 break;
3144 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003145 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003146 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003147 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003148 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003149 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003150 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003151 else if (cfg->line_outs > i &&
3152 alc_auto_is_dac_reachable(codec, pin,
3153 spec->private_dac_nids[i]))
3154 dac = spec->private_dac_nids[i];
3155 if (dac) {
3156 if (!i)
3157 badness += bad->shared_primary;
3158 else if (i == 1)
3159 badness += bad->shared_surr;
3160 else
3161 badness += bad->shared_clfe;
3162 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003163 spec->private_dac_nids[0])) {
3164 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003165 badness += bad->shared_surr_main;
3166 } else if (!i)
3167 badness += bad->no_primary_dac;
3168 else
3169 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003170 }
3171 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003172 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003173 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003174
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003175 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003176}
3177
3178static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003179 hda_nid_t reference_pin,
3180 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003181
Takashi Iwai185d99f2012-02-16 18:39:45 +01003182static bool alc_map_singles(struct hda_codec *codec, int outs,
3183 const hda_nid_t *pins, hda_nid_t *dacs)
3184{
3185 int i;
3186 bool found = false;
3187 for (i = 0; i < outs; i++) {
3188 if (dacs[i])
3189 continue;
3190 dacs[i] = get_dac_if_single(codec, pins[i]);
3191 if (dacs[i])
3192 found = true;
3193 }
3194 return found;
3195}
3196
Takashi Iwai7085ec12009-10-02 09:03:58 +02003197/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003198static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003199 bool fill_hardwired,
3200 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003201{
3202 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003203 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003204 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003205
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003206 /* set num_dacs once to full for alc_auto_look_for_dac() */
3207 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003208 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003209 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3210 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3211 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003212 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003213 clear_vol_marks(codec);
3214 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003215
3216 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003217 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003218 bool mapped;
3219 do {
3220 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003221 cfg->line_out_pins,
3222 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003223 mapped |= alc_map_singles(codec, cfg->hp_outs,
3224 cfg->hp_pins,
3225 spec->multiout.hp_out_nid);
3226 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3227 cfg->speaker_pins,
3228 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003229 if (fill_mio_first && cfg->line_outs == 1 &&
3230 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3231 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3232 if (!err)
3233 mapped = true;
3234 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003235 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003236 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003237
Takashi Iwaidc31b582012-02-17 17:27:53 +01003238 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3239 spec->private_dac_nids,
3240 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003241
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003242 /* re-count num_dacs and squash invalid entries */
3243 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003244 for (i = 0; i < cfg->line_outs; i++) {
3245 if (spec->private_dac_nids[i])
3246 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003247 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003248 memmove(spec->private_dac_nids + i,
3249 spec->private_dac_nids + i + 1,
3250 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003251 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3252 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003253 }
3254
Takashi Iwai276dd702012-02-17 16:17:03 +01003255 if (fill_mio_first &&
3256 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003257 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003258 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003259 if (err < 0)
3260 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003261 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003262 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003263
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003264 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003265 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3266 spec->multiout.hp_out_nid,
3267 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003268 if (err < 0)
3269 return err;
3270 badness += err;
3271 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003272 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003273 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3274 cfg->speaker_pins,
3275 spec->multiout.extra_out_nid,
3276 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003277 if (err < 0)
3278 return err;
3279 badness += err;
3280 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003281 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3282 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003283 if (err < 0)
3284 return err;
3285 badness += err;
3286 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003287 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3288 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003289 int offset = 0;
3290 if (cfg->line_outs >= 3)
3291 offset = 1;
3292 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3293 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003294 if (err < 0)
3295 return err;
3296 badness += err;
3297 }
3298
3299 if (spec->multi_ios == 2) {
3300 for (i = 0; i < 2; i++)
3301 spec->private_dac_nids[spec->multiout.num_dacs++] =
3302 spec->multi_io[i].dac;
3303 spec->ext_channel_count = 2;
3304 } else if (spec->multi_ios) {
3305 spec->multi_ios = 0;
3306 badness += BAD_MULTI_IO;
3307 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003308
3309 return badness;
3310}
3311
3312#define DEBUG_BADNESS
3313
3314#ifdef DEBUG_BADNESS
3315#define debug_badness snd_printdd
3316#else
3317#define debug_badness(...)
3318#endif
3319
3320static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3321{
3322 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3323 cfg->line_out_pins[0], cfg->line_out_pins[1],
3324 cfg->line_out_pins[2], cfg->line_out_pins[2],
3325 spec->multiout.dac_nids[0],
3326 spec->multiout.dac_nids[1],
3327 spec->multiout.dac_nids[2],
3328 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003329 if (spec->multi_ios > 0)
3330 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3331 spec->multi_ios,
3332 spec->multi_io[0].pin, spec->multi_io[1].pin,
3333 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003334 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3335 cfg->hp_pins[0], cfg->hp_pins[1],
3336 cfg->hp_pins[2], cfg->hp_pins[2],
3337 spec->multiout.hp_out_nid[0],
3338 spec->multiout.hp_out_nid[1],
3339 spec->multiout.hp_out_nid[2],
3340 spec->multiout.hp_out_nid[3]);
3341 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3342 cfg->speaker_pins[0], cfg->speaker_pins[1],
3343 cfg->speaker_pins[2], cfg->speaker_pins[3],
3344 spec->multiout.extra_out_nid[0],
3345 spec->multiout.extra_out_nid[1],
3346 spec->multiout.extra_out_nid[2],
3347 spec->multiout.extra_out_nid[3]);
3348}
3349
3350static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3351{
3352 struct alc_spec *spec = codec->spec;
3353 struct auto_pin_cfg *cfg = &spec->autocfg;
3354 struct auto_pin_cfg *best_cfg;
3355 int best_badness = INT_MAX;
3356 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003357 bool fill_hardwired = true, fill_mio_first = true;
3358 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003359 bool hp_spk_swapped = false;
3360
3361 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3362 if (!best_cfg)
3363 return -ENOMEM;
3364 *best_cfg = *cfg;
3365
3366 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003367 badness = fill_and_eval_dacs(codec, fill_hardwired,
3368 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003369 if (badness < 0) {
3370 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003371 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003372 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003373 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3374 cfg->line_out_type, fill_hardwired, fill_mio_first,
3375 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003376 debug_show_configs(spec, cfg);
3377 if (badness < best_badness) {
3378 best_badness = badness;
3379 *best_cfg = *cfg;
3380 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003381 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003382 }
3383 if (!badness)
3384 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003385 fill_mio_first = !fill_mio_first;
3386 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003387 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003388 fill_hardwired = !fill_hardwired;
3389 if (!fill_hardwired)
3390 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003391 if (hp_spk_swapped)
3392 break;
3393 hp_spk_swapped = true;
3394 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003395 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3396 cfg->hp_outs = cfg->line_outs;
3397 memcpy(cfg->hp_pins, cfg->line_out_pins,
3398 sizeof(cfg->hp_pins));
3399 cfg->line_outs = cfg->speaker_outs;
3400 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3401 sizeof(cfg->speaker_pins));
3402 cfg->speaker_outs = 0;
3403 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3404 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003405 fill_hardwired = true;
3406 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003407 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003408 if (cfg->hp_outs > 0 &&
3409 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3410 cfg->speaker_outs = cfg->line_outs;
3411 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3412 sizeof(cfg->speaker_pins));
3413 cfg->line_outs = cfg->hp_outs;
3414 memcpy(cfg->line_out_pins, cfg->hp_pins,
3415 sizeof(cfg->hp_pins));
3416 cfg->hp_outs = 0;
3417 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3418 cfg->line_out_type = AUTO_PIN_HP_OUT;
3419 fill_hardwired = true;
3420 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003421 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003422 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003423 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003424
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003425 if (badness) {
3426 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003427 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003428 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003429 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3430 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003431 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003432
David Henningssonfde48a12011-12-09 18:27:42 +08003433 if (cfg->line_out_pins[0])
3434 spec->vmaster_nid =
3435 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3436 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003437
3438 /* clear the bitmap flags for creating controls */
3439 clear_vol_marks(codec);
3440 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003441 return 0;
3442}
3443
Takashi Iwai343a04b2011-07-06 14:28:39 +02003444static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003445 const char *pfx, int cidx,
3446 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003447{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003448 struct alc_spec *spec = codec->spec;
3449 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003450 if (!nid)
3451 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003452 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3453 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3454 return 0;
3455 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003456 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003457 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003458}
3459
Takashi Iwaie29d3772011-11-14 17:13:23 +01003460static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3461 const char *pfx, int cidx,
3462 hda_nid_t nid)
3463{
3464 int chs = 1;
3465 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3466 chs = 3;
3467 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3468}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003469
3470/* create a mute-switch for the given mixer widget;
3471 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3472 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003473static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003474 const char *pfx, int cidx,
3475 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003476{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003477 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003478 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003479 int type;
3480 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003481 if (!nid)
3482 return 0;
3483 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3484 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3485 type = ALC_CTL_WIDGET_MUTE;
3486 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003487 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003488 type = ALC_CTL_WIDGET_MUTE;
3489 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3490 } else {
3491 type = ALC_CTL_BIND_MUTE;
3492 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3493 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003494 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3495 return 0;
3496 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003497 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003498}
3499
Takashi Iwaie29d3772011-11-14 17:13:23 +01003500static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3501 int cidx, hda_nid_t nid)
3502{
3503 int chs = 1;
3504 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3505 chs = 3;
3506 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3507}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003508
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003509static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3510 hda_nid_t pin, hda_nid_t dac)
3511{
3512 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3513 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3514 return pin;
3515 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3516 return mix;
3517 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3518 return dac;
3519 return 0;
3520}
3521
3522static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3523 hda_nid_t pin, hda_nid_t dac)
3524{
3525 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3526 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3527 return dac;
3528 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3529 return mix;
3530 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3531 return pin;
3532 return 0;
3533}
3534
Takashi Iwai7085ec12009-10-02 09:03:58 +02003535/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003536static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003537 const struct auto_pin_cfg *cfg)
3538{
3539 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003540 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003541
Takashi Iwaice764ab2011-04-27 16:35:23 +02003542 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003543 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003544 noutputs += spec->multi_ios;
3545
3546 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003547 const char *name;
3548 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003549 hda_nid_t dac, pin;
3550 hda_nid_t sw, vol;
3551
3552 dac = spec->multiout.dac_nids[i];
3553 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003554 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003555 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003556 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003557 index = 0;
3558 name = channel_name[i];
3559 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003560 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003561 name = alc_get_line_out_pfx(spec, i, true, &index);
3562 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003563
3564 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3565 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003566 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003567 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003568 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003569 if (err < 0)
3570 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003571 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003572 if (err < 0)
3573 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003574 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003575 if (err < 0)
3576 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003577 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003578 if (err < 0)
3579 return err;
3580 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003581 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003582 if (err < 0)
3583 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003584 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003585 if (err < 0)
3586 return err;
3587 }
3588 }
3589 return 0;
3590}
3591
Takashi Iwai343a04b2011-07-06 14:28:39 +02003592static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003593 hda_nid_t dac, const char *pfx,
3594 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003595{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003596 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003597 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003598 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003599
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003600 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003601 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003602 /* the corresponding DAC is already occupied */
3603 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3604 return 0; /* no way */
3605 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003606 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3607 if (is_ctl_used(spec->sw_ctls, val))
3608 return 0; /* already created */
3609 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003610 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003611 }
3612
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003613 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3614 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003615 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003616 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003617 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003618 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003619 if (err < 0)
3620 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003621 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003622}
3623
Takashi Iwai23c09b02011-08-19 09:05:35 +02003624static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3625 unsigned int nums,
3626 struct hda_ctl_ops *ops)
3627{
3628 struct alc_spec *spec = codec->spec;
3629 struct hda_bind_ctls **ctlp, *ctl;
3630 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3631 ctlp = snd_array_new(&spec->bind_ctls);
3632 if (!ctlp)
3633 return NULL;
3634 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3635 *ctlp = ctl;
3636 if (ctl)
3637 ctl->ops = ops;
3638 return ctl;
3639}
3640
3641/* add playback controls for speaker and HP outputs */
3642static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3643 const hda_nid_t *pins,
3644 const hda_nid_t *dacs,
3645 const char *pfx)
3646{
3647 struct alc_spec *spec = codec->spec;
3648 struct hda_bind_ctls *ctl;
3649 char name[32];
3650 int i, n, err;
3651
3652 if (!num_pins || !pins[0])
3653 return 0;
3654
Takashi Iwai527e4d72011-10-27 16:33:27 +02003655 if (num_pins == 1) {
3656 hda_nid_t dac = *dacs;
3657 if (!dac)
3658 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003659 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003660 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003661
Takashi Iwai23c09b02011-08-19 09:05:35 +02003662 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003663 hda_nid_t dac;
3664 if (dacs[num_pins - 1])
3665 dac = dacs[i]; /* with individual volumes */
3666 else
3667 dac = 0;
3668 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3669 err = alc_auto_create_extra_out(codec, pins[i], dac,
3670 "Bass Speaker", 0);
3671 } else if (num_pins >= 3) {
3672 snprintf(name, sizeof(name), "%s %s",
3673 pfx, channel_name[i]);
3674 err = alc_auto_create_extra_out(codec, pins[i], dac,
3675 name, 0);
3676 } else {
3677 err = alc_auto_create_extra_out(codec, pins[i], dac,
3678 pfx, i);
3679 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003680 if (err < 0)
3681 return err;
3682 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003683 if (dacs[num_pins - 1])
3684 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003685
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003686 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003687 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3688 if (!ctl)
3689 return -ENOMEM;
3690 n = 0;
3691 for (i = 0; i < num_pins; i++) {
3692 hda_nid_t vol;
3693 if (!pins[i] || !dacs[i])
3694 continue;
3695 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3696 if (vol)
3697 ctl->values[n++] =
3698 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3699 }
3700 if (n) {
3701 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3702 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3703 if (err < 0)
3704 return err;
3705 }
3706 return 0;
3707}
3708
Takashi Iwai343a04b2011-07-06 14:28:39 +02003709static int alc_auto_create_hp_out(struct hda_codec *codec)
3710{
3711 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003712 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3713 spec->autocfg.hp_pins,
3714 spec->multiout.hp_out_nid,
3715 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003716}
3717
3718static int alc_auto_create_speaker_out(struct hda_codec *codec)
3719{
3720 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003721 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3722 spec->autocfg.speaker_pins,
3723 spec->multiout.extra_out_nid,
3724 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003725}
3726
Takashi Iwai343a04b2011-07-06 14:28:39 +02003727static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003728 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003729 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003730{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003731 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003732 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003733 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003734
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003735 alc_set_pin_output(codec, pin, pin_type);
3736 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003737 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003738 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003739 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003740 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003741 mix = srcs[i];
3742 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003743 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003744 if (!mix)
3745 return;
3746
3747 /* need the manual connection? */
3748 if (num > 1)
3749 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3750 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003751 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3752 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003753 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003754 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003755 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003756 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003757 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003758 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3759 if (nid)
3760 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3761 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003762
3763 /* unmute DAC if it's not assigned to a mixer */
3764 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3765 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3766 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3767 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003768}
3769
Takashi Iwai343a04b2011-07-06 14:28:39 +02003770static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003771{
3772 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003773 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003774 int i;
3775
3776 for (i = 0; i <= HDA_SIDE; i++) {
3777 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3778 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003779 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003780 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003781 }
3782}
3783
Takashi Iwai343a04b2011-07-06 14:28:39 +02003784static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003785{
3786 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003787 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003788 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003789
David Henningsson636030e2011-10-12 19:26:03 +02003790 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003791 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3792 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003793 pin = spec->autocfg.hp_pins[i];
3794 if (!pin)
3795 break;
3796 dac = spec->multiout.hp_out_nid[i];
3797 if (!dac) {
3798 if (i > 0 && spec->multiout.hp_out_nid[0])
3799 dac = spec->multiout.hp_out_nid[0];
3800 else
3801 dac = spec->multiout.dac_nids[0];
3802 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003803 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3804 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003805 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003806 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3807 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003808 pin = spec->autocfg.speaker_pins[i];
3809 if (!pin)
3810 break;
3811 dac = spec->multiout.extra_out_nid[i];
3812 if (!dac) {
3813 if (i > 0 && spec->multiout.extra_out_nid[0])
3814 dac = spec->multiout.extra_out_nid[0];
3815 else
3816 dac = spec->multiout.dac_nids[0];
3817 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003818 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3819 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003820}
3821
Takashi Iwai276dd702012-02-17 16:17:03 +01003822/* check whether the given pin can be a multi-io pin */
3823static bool can_be_multiio_pin(struct hda_codec *codec,
3824 unsigned int location, hda_nid_t nid)
3825{
3826 unsigned int defcfg, caps;
3827
3828 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3829 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3830 return false;
3831 if (location && get_defcfg_location(defcfg) != location)
3832 return false;
3833 caps = snd_hda_query_pin_caps(codec, nid);
3834 if (!(caps & AC_PINCAP_OUT))
3835 return false;
3836 return true;
3837}
3838
Takashi Iwaice764ab2011-04-27 16:35:23 +02003839/*
3840 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003841 *
3842 * When hardwired is set, try to fill ony hardwired pins, and returns
3843 * zero if any pins are filled, non-zero if nothing found.
3844 * When hardwired is off, try to fill possible input pins, and returns
3845 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003846 */
3847static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003848 hda_nid_t reference_pin,
3849 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003850{
3851 struct alc_spec *spec = codec->spec;
3852 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003853 int type, i, j, dacs, num_pins, old_pins;
3854 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3855 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003856 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003857
Takashi Iwai276dd702012-02-17 16:17:03 +01003858 old_pins = spec->multi_ios;
3859 if (old_pins >= 2)
3860 goto end_fill;
3861
3862 num_pins = 0;
3863 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3864 for (i = 0; i < cfg->num_inputs; i++) {
3865 if (cfg->inputs[i].type != type)
3866 continue;
3867 if (can_be_multiio_pin(codec, location,
3868 cfg->inputs[i].pin))
3869 num_pins++;
3870 }
3871 }
3872 if (num_pins < 2)
3873 goto end_fill;
3874
Takashi Iwai07b18f62011-11-10 15:42:54 +01003875 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003876 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3877 for (i = 0; i < cfg->num_inputs; i++) {
3878 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003879 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003880
Takashi Iwaice764ab2011-04-27 16:35:23 +02003881 if (cfg->inputs[i].type != type)
3882 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003883 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003884 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003885 for (j = 0; j < spec->multi_ios; j++) {
3886 if (nid == spec->multi_io[j].pin)
3887 break;
3888 }
3889 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003890 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003891
3892 if (offset && offset + spec->multi_ios < dacs) {
3893 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003894 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3895 dac = 0;
3896 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003897 if (hardwired)
3898 dac = get_dac_if_single(codec, nid);
3899 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003900 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003901 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003902 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003903 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003904 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003905 spec->multi_io[spec->multi_ios].pin = nid;
3906 spec->multi_io[spec->multi_ios].dac = dac;
3907 spec->multi_ios++;
3908 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003909 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003910 }
3911 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003912 end_fill:
3913 if (badness)
3914 badness = BAD_MULTI_IO;
3915 if (old_pins == spec->multi_ios) {
3916 if (hardwired)
3917 return 1; /* nothing found */
3918 else
3919 return badness; /* no badness if nothing found */
3920 }
3921 if (!hardwired && spec->multi_ios < 2) {
3922 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003923 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003924 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003925
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003926 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003927}
3928
3929static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3930 struct snd_ctl_elem_info *uinfo)
3931{
3932 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3933 struct alc_spec *spec = codec->spec;
3934
3935 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3936 uinfo->count = 1;
3937 uinfo->value.enumerated.items = spec->multi_ios + 1;
3938 if (uinfo->value.enumerated.item > spec->multi_ios)
3939 uinfo->value.enumerated.item = spec->multi_ios;
3940 sprintf(uinfo->value.enumerated.name, "%dch",
3941 (uinfo->value.enumerated.item + 1) * 2);
3942 return 0;
3943}
3944
3945static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3946 struct snd_ctl_elem_value *ucontrol)
3947{
3948 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3949 struct alc_spec *spec = codec->spec;
3950 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3951 return 0;
3952}
3953
3954static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3955{
3956 struct alc_spec *spec = codec->spec;
3957 hda_nid_t nid = spec->multi_io[idx].pin;
3958
3959 if (!spec->multi_io[idx].ctl_in)
3960 spec->multi_io[idx].ctl_in =
3961 snd_hda_codec_read(codec, nid, 0,
3962 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3963 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003964 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003965 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3966 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3967 HDA_AMP_MUTE, 0);
3968 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3969 } else {
3970 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3971 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3972 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003973 snd_hda_set_pin_ctl_cache(codec, nid,
3974 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003975 }
3976 return 0;
3977}
3978
3979static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3980 struct snd_ctl_elem_value *ucontrol)
3981{
3982 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3983 struct alc_spec *spec = codec->spec;
3984 int i, ch;
3985
3986 ch = ucontrol->value.enumerated.item[0];
3987 if (ch < 0 || ch > spec->multi_ios)
3988 return -EINVAL;
3989 if (ch == (spec->ext_channel_count - 1) / 2)
3990 return 0;
3991 spec->ext_channel_count = (ch + 1) * 2;
3992 for (i = 0; i < spec->multi_ios; i++)
3993 alc_set_multi_io(codec, i, i < ch);
3994 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003995 if (spec->need_dac_fix && !spec->const_channel_count)
3996 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003997 return 1;
3998}
3999
Takashi Iwaia9111322011-05-02 11:30:18 +02004000static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004001 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4002 .name = "Channel Mode",
4003 .info = alc_auto_ch_mode_info,
4004 .get = alc_auto_ch_mode_get,
4005 .put = alc_auto_ch_mode_put,
4006};
4007
Takashi Iwai23c09b02011-08-19 09:05:35 +02004008static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004009{
4010 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004011
Takashi Iwaic2674682011-08-24 17:57:44 +02004012 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004013 struct snd_kcontrol_new *knew;
4014
4015 knew = alc_kcontrol_new(spec);
4016 if (!knew)
4017 return -ENOMEM;
4018 *knew = alc_auto_channel_mode_enum;
4019 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4020 if (!knew->name)
4021 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004022 }
4023 return 0;
4024}
4025
Takashi Iwai1d045db2011-07-07 18:23:21 +02004026/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4027 * active input pins
4028 */
4029static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4030{
4031 struct alc_spec *spec = codec->spec;
4032 const struct hda_input_mux *imux;
4033 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4034 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4035 int i, n, nums;
4036
4037 imux = spec->input_mux;
4038 if (!imux)
4039 return;
4040 if (spec->dyn_adc_switch)
4041 return;
4042
Takashi Iwai26acaf02012-03-22 14:36:50 +01004043 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004044 nums = 0;
4045 for (n = 0; n < spec->num_adc_nids; n++) {
4046 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004047 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004048 for (i = 0; i < imux->num_items; i++) {
4049 hda_nid_t pin = spec->imux_pins[i];
4050 if (pin) {
4051 if (get_connection_index(codec, cap, pin) < 0)
4052 break;
4053 } else if (num_conns <= imux->items[i].index)
4054 break;
4055 }
4056 if (i >= imux->num_items) {
4057 adc_nids[nums] = spec->private_adc_nids[n];
4058 capsrc_nids[nums++] = cap;
4059 }
4060 }
4061 if (!nums) {
4062 /* check whether ADC-switch is possible */
4063 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004064 if (spec->shared_mic_hp) {
4065 spec->shared_mic_hp = 0;
4066 spec->private_imux[0].num_items = 1;
4067 goto again;
4068 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004069 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4070 " using fallback 0x%x\n",
4071 codec->chip_name, spec->private_adc_nids[0]);
4072 spec->num_adc_nids = 1;
4073 spec->auto_mic = 0;
4074 return;
4075 }
4076 } else if (nums != spec->num_adc_nids) {
4077 memcpy(spec->private_adc_nids, adc_nids,
4078 nums * sizeof(hda_nid_t));
4079 memcpy(spec->private_capsrc_nids, capsrc_nids,
4080 nums * sizeof(hda_nid_t));
4081 spec->num_adc_nids = nums;
4082 }
4083
4084 if (spec->auto_mic)
4085 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004086 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004087 spec->num_adc_nids = 1; /* reduce to a single ADC */
4088}
4089
4090/*
4091 * initialize ADC paths
4092 */
4093static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4094{
4095 struct alc_spec *spec = codec->spec;
4096 hda_nid_t nid;
4097
4098 nid = spec->adc_nids[adc_idx];
4099 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004100 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004101 snd_hda_codec_write(codec, nid, 0,
4102 AC_VERB_SET_AMP_GAIN_MUTE,
4103 AMP_IN_MUTE(0));
4104 return;
4105 }
4106 if (!spec->capsrc_nids)
4107 return;
4108 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004109 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004110 snd_hda_codec_write(codec, nid, 0,
4111 AC_VERB_SET_AMP_GAIN_MUTE,
4112 AMP_OUT_MUTE);
4113}
4114
4115static void alc_auto_init_input_src(struct hda_codec *codec)
4116{
4117 struct alc_spec *spec = codec->spec;
4118 int c, nums;
4119
4120 for (c = 0; c < spec->num_adc_nids; c++)
4121 alc_auto_init_adc(codec, c);
4122 if (spec->dyn_adc_switch)
4123 nums = 1;
4124 else
4125 nums = spec->num_adc_nids;
4126 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004127 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004128}
4129
4130/* add mic boosts if needed */
4131static int alc_auto_add_mic_boost(struct hda_codec *codec)
4132{
4133 struct alc_spec *spec = codec->spec;
4134 struct auto_pin_cfg *cfg = &spec->autocfg;
4135 int i, err;
4136 int type_idx = 0;
4137 hda_nid_t nid;
4138 const char *prev_label = NULL;
4139
4140 for (i = 0; i < cfg->num_inputs; i++) {
4141 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4142 break;
4143 nid = cfg->inputs[i].pin;
4144 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4145 const char *label;
4146 char boost_label[32];
4147
4148 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004149 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4150 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004151 if (prev_label && !strcmp(label, prev_label))
4152 type_idx++;
4153 else
4154 type_idx = 0;
4155 prev_label = label;
4156
4157 snprintf(boost_label, sizeof(boost_label),
4158 "%s Boost Volume", label);
4159 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4160 boost_label, type_idx,
4161 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4162 if (err < 0)
4163 return err;
4164 }
4165 }
4166 return 0;
4167}
4168
4169/* select or unmute the given capsrc route */
4170static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4171 int idx)
4172{
4173 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4174 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4175 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004176 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004177 snd_hda_codec_write_cache(codec, cap, 0,
4178 AC_VERB_SET_CONNECT_SEL, idx);
4179 }
4180}
4181
4182/* set the default connection to that pin */
4183static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4184{
4185 struct alc_spec *spec = codec->spec;
4186 int i;
4187
4188 if (!pin)
4189 return 0;
4190 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004191 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004192 int idx;
4193
4194 idx = get_connection_index(codec, cap, pin);
4195 if (idx < 0)
4196 continue;
4197 select_or_unmute_capsrc(codec, cap, idx);
4198 return i; /* return the found index */
4199 }
4200 return -1; /* not found */
4201}
4202
4203/* initialize some special cases for input sources */
4204static void alc_init_special_input_src(struct hda_codec *codec)
4205{
4206 struct alc_spec *spec = codec->spec;
4207 int i;
4208
4209 for (i = 0; i < spec->autocfg.num_inputs; i++)
4210 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4211}
4212
4213/* assign appropriate capture mixers */
4214static void set_capture_mixer(struct hda_codec *codec)
4215{
4216 struct alc_spec *spec = codec->spec;
4217 static const struct snd_kcontrol_new *caps[2][3] = {
4218 { alc_capture_mixer_nosrc1,
4219 alc_capture_mixer_nosrc2,
4220 alc_capture_mixer_nosrc3 },
4221 { alc_capture_mixer1,
4222 alc_capture_mixer2,
4223 alc_capture_mixer3 },
4224 };
4225
4226 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004227 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004228 if (!spec->capsrc_nids)
4229 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004230 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004231 return; /* no volume in capsrc, too */
4232 spec->vol_in_capsrc = 1;
4233 }
4234
4235 if (spec->num_adc_nids > 0) {
4236 int mux = 0;
4237 int num_adcs = 0;
4238
4239 if (spec->input_mux && spec->input_mux->num_items > 1)
4240 mux = 1;
4241 if (spec->auto_mic) {
4242 num_adcs = 1;
4243 mux = 0;
4244 } else if (spec->dyn_adc_switch)
4245 num_adcs = 1;
4246 if (!num_adcs) {
4247 if (spec->num_adc_nids > 3)
4248 spec->num_adc_nids = 3;
4249 else if (!spec->num_adc_nids)
4250 return;
4251 num_adcs = spec->num_adc_nids;
4252 }
4253 spec->cap_mixer = caps[mux][num_adcs - 1];
4254 }
4255}
4256
4257/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004258 * standard auto-parser initializations
4259 */
4260static void alc_auto_init_std(struct hda_codec *codec)
4261{
Takashi Iwaie4770622011-07-08 11:11:35 +02004262 alc_auto_init_multi_out(codec);
4263 alc_auto_init_extra_out(codec);
4264 alc_auto_init_analog_input(codec);
4265 alc_auto_init_input_src(codec);
4266 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004267 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004268}
4269
4270/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004271 * Digital-beep handlers
4272 */
4273#ifdef CONFIG_SND_HDA_INPUT_BEEP
4274#define set_beep_amp(spec, nid, idx, dir) \
4275 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4276
4277static const struct snd_pci_quirk beep_white_list[] = {
4278 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4279 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4280 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4281 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004282 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004283 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4284 {}
4285};
4286
4287static inline int has_cdefine_beep(struct hda_codec *codec)
4288{
4289 struct alc_spec *spec = codec->spec;
4290 const struct snd_pci_quirk *q;
4291 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4292 if (q)
4293 return q->value;
4294 return spec->cdefine.enable_pcbeep;
4295}
4296#else
4297#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4298#define has_cdefine_beep(codec) 0
4299#endif
4300
4301/* parse the BIOS configuration and set up the alc_spec */
4302/* return 1 if successful, 0 if the proper config is not found,
4303 * or a negative error code
4304 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004305static int alc_parse_auto_config(struct hda_codec *codec,
4306 const hda_nid_t *ignore_nids,
4307 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004308{
4309 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004310 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004311 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004312
Takashi Iwai53c334a2011-08-23 18:27:14 +02004313 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4314 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004315 if (err < 0)
4316 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004317 if (!cfg->line_outs) {
4318 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004319 spec->multiout.max_channels = 2;
4320 spec->no_analog = 1;
4321 goto dig_only;
4322 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004323 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004324 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004325
Takashi Iwai06503672011-10-06 08:27:19 +02004326 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4327 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004328 /* use HP as primary out */
4329 cfg->speaker_outs = cfg->line_outs;
4330 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4331 sizeof(cfg->speaker_pins));
4332 cfg->line_outs = cfg->hp_outs;
4333 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4334 cfg->hp_outs = 0;
4335 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4336 cfg->line_out_type = AUTO_PIN_HP_OUT;
4337 }
4338
Takashi Iwai1d045db2011-07-07 18:23:21 +02004339 err = alc_auto_fill_dac_nids(codec);
4340 if (err < 0)
4341 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004342 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004343 if (err < 0)
4344 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004345 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004346 if (err < 0)
4347 return err;
4348 err = alc_auto_create_hp_out(codec);
4349 if (err < 0)
4350 return err;
4351 err = alc_auto_create_speaker_out(codec);
4352 if (err < 0)
4353 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004354 err = alc_auto_create_shared_input(codec);
4355 if (err < 0)
4356 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004357 err = alc_auto_create_input_ctls(codec);
4358 if (err < 0)
4359 return err;
4360
4361 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4362
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004363 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004364 alc_auto_parse_digital(codec);
4365
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004366 if (!spec->no_analog)
4367 alc_remove_invalid_adc_nids(codec);
4368
4369 if (ssid_nids)
4370 alc_ssid_check(codec, ssid_nids);
4371
4372 if (!spec->no_analog) {
4373 alc_auto_check_switches(codec);
4374 err = alc_auto_add_mic_boost(codec);
4375 if (err < 0)
4376 return err;
4377 }
4378
Takashi Iwai1d045db2011-07-07 18:23:21 +02004379 if (spec->kctls.list)
4380 add_mixer(spec, spec->kctls.list);
4381
Takashi Iwai070cff42012-02-21 12:54:17 +01004382 if (!spec->no_analog && !spec->cap_mixer)
4383 set_capture_mixer(codec);
4384
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385 return 1;
4386}
4387
Takashi Iwai3de95172012-05-07 18:03:15 +02004388/* common preparation job for alc_spec */
4389static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4390{
4391 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4392 int err;
4393
4394 if (!spec)
4395 return -ENOMEM;
4396 codec->spec = spec;
4397 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004398 snd_hda_gen_init(&spec->gen);
Takashi Iwai3de95172012-05-07 18:03:15 +02004399
4400 err = alc_codec_rename_from_preset(codec);
4401 if (err < 0) {
4402 kfree(spec);
4403 return err;
4404 }
4405 return 0;
4406}
4407
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004408static int alc880_parse_auto_config(struct hda_codec *codec)
4409{
4410 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004411 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004412 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4413}
4414
Takashi Iwai1d045db2011-07-07 18:23:21 +02004415/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004416 * ALC880 fix-ups
4417 */
4418enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004419 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004420 ALC880_FIXUP_GPIO2,
4421 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004422 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004423 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004424 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004425 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004426 ALC880_FIXUP_VOL_KNOB,
4427 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004428 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004429 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004430 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004431 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004432 ALC880_FIXUP_3ST_BASE,
4433 ALC880_FIXUP_3ST,
4434 ALC880_FIXUP_3ST_DIG,
4435 ALC880_FIXUP_5ST_BASE,
4436 ALC880_FIXUP_5ST,
4437 ALC880_FIXUP_5ST_DIG,
4438 ALC880_FIXUP_6ST_BASE,
4439 ALC880_FIXUP_6ST,
4440 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004441};
4442
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004443/* enable the volume-knob widget support on NID 0x21 */
4444static void alc880_fixup_vol_knob(struct hda_codec *codec,
4445 const struct alc_fixup *fix, int action)
4446{
4447 if (action == ALC_FIXUP_ACT_PROBE)
4448 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4449}
4450
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004451static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004452 [ALC880_FIXUP_GPIO1] = {
4453 .type = ALC_FIXUP_VERBS,
4454 .v.verbs = alc_gpio1_init_verbs,
4455 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004456 [ALC880_FIXUP_GPIO2] = {
4457 .type = ALC_FIXUP_VERBS,
4458 .v.verbs = alc_gpio2_init_verbs,
4459 },
4460 [ALC880_FIXUP_MEDION_RIM] = {
4461 .type = ALC_FIXUP_VERBS,
4462 .v.verbs = (const struct hda_verb[]) {
4463 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4464 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4465 { }
4466 },
4467 .chained = true,
4468 .chain_id = ALC880_FIXUP_GPIO2,
4469 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004470 [ALC880_FIXUP_LG] = {
4471 .type = ALC_FIXUP_PINS,
4472 .v.pins = (const struct alc_pincfg[]) {
4473 /* disable bogus unused pins */
4474 { 0x16, 0x411111f0 },
4475 { 0x18, 0x411111f0 },
4476 { 0x1a, 0x411111f0 },
4477 { }
4478 }
4479 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004480 [ALC880_FIXUP_W810] = {
4481 .type = ALC_FIXUP_PINS,
4482 .v.pins = (const struct alc_pincfg[]) {
4483 /* disable bogus unused pins */
4484 { 0x17, 0x411111f0 },
4485 { }
4486 },
4487 .chained = true,
4488 .chain_id = ALC880_FIXUP_GPIO2,
4489 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004490 [ALC880_FIXUP_EAPD_COEF] = {
4491 .type = ALC_FIXUP_VERBS,
4492 .v.verbs = (const struct hda_verb[]) {
4493 /* change to EAPD mode */
4494 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4495 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4496 {}
4497 },
4498 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004499 [ALC880_FIXUP_TCL_S700] = {
4500 .type = ALC_FIXUP_VERBS,
4501 .v.verbs = (const struct hda_verb[]) {
4502 /* change to EAPD mode */
4503 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4504 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4505 {}
4506 },
4507 .chained = true,
4508 .chain_id = ALC880_FIXUP_GPIO2,
4509 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004510 [ALC880_FIXUP_VOL_KNOB] = {
4511 .type = ALC_FIXUP_FUNC,
4512 .v.func = alc880_fixup_vol_knob,
4513 },
4514 [ALC880_FIXUP_FUJITSU] = {
4515 /* override all pins as BIOS on old Amilo is broken */
4516 .type = ALC_FIXUP_PINS,
4517 .v.pins = (const struct alc_pincfg[]) {
4518 { 0x14, 0x0121411f }, /* HP */
4519 { 0x15, 0x99030120 }, /* speaker */
4520 { 0x16, 0x99030130 }, /* bass speaker */
4521 { 0x17, 0x411111f0 }, /* N/A */
4522 { 0x18, 0x411111f0 }, /* N/A */
4523 { 0x19, 0x01a19950 }, /* mic-in */
4524 { 0x1a, 0x411111f0 }, /* N/A */
4525 { 0x1b, 0x411111f0 }, /* N/A */
4526 { 0x1c, 0x411111f0 }, /* N/A */
4527 { 0x1d, 0x411111f0 }, /* N/A */
4528 { 0x1e, 0x01454140 }, /* SPDIF out */
4529 { }
4530 },
4531 .chained = true,
4532 .chain_id = ALC880_FIXUP_VOL_KNOB,
4533 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004534 [ALC880_FIXUP_F1734] = {
4535 /* almost compatible with FUJITSU, but no bass and SPDIF */
4536 .type = ALC_FIXUP_PINS,
4537 .v.pins = (const struct alc_pincfg[]) {
4538 { 0x14, 0x0121411f }, /* HP */
4539 { 0x15, 0x99030120 }, /* speaker */
4540 { 0x16, 0x411111f0 }, /* N/A */
4541 { 0x17, 0x411111f0 }, /* N/A */
4542 { 0x18, 0x411111f0 }, /* N/A */
4543 { 0x19, 0x01a19950 }, /* mic-in */
4544 { 0x1a, 0x411111f0 }, /* N/A */
4545 { 0x1b, 0x411111f0 }, /* N/A */
4546 { 0x1c, 0x411111f0 }, /* N/A */
4547 { 0x1d, 0x411111f0 }, /* N/A */
4548 { 0x1e, 0x411111f0 }, /* N/A */
4549 { }
4550 },
4551 .chained = true,
4552 .chain_id = ALC880_FIXUP_VOL_KNOB,
4553 },
Takashi Iwai817de922012-02-20 17:20:48 +01004554 [ALC880_FIXUP_UNIWILL] = {
4555 /* need to fix HP and speaker pins to be parsed correctly */
4556 .type = ALC_FIXUP_PINS,
4557 .v.pins = (const struct alc_pincfg[]) {
4558 { 0x14, 0x0121411f }, /* HP */
4559 { 0x15, 0x99030120 }, /* speaker */
4560 { 0x16, 0x99030130 }, /* bass speaker */
4561 { }
4562 },
4563 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004564 [ALC880_FIXUP_UNIWILL_DIG] = {
4565 .type = ALC_FIXUP_PINS,
4566 .v.pins = (const struct alc_pincfg[]) {
4567 /* disable bogus unused pins */
4568 { 0x17, 0x411111f0 },
4569 { 0x19, 0x411111f0 },
4570 { 0x1b, 0x411111f0 },
4571 { 0x1f, 0x411111f0 },
4572 { }
4573 }
4574 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004575 [ALC880_FIXUP_Z71V] = {
4576 .type = ALC_FIXUP_PINS,
4577 .v.pins = (const struct alc_pincfg[]) {
4578 /* set up the whole pins as BIOS is utterly broken */
4579 { 0x14, 0x99030120 }, /* speaker */
4580 { 0x15, 0x0121411f }, /* HP */
4581 { 0x16, 0x411111f0 }, /* N/A */
4582 { 0x17, 0x411111f0 }, /* N/A */
4583 { 0x18, 0x01a19950 }, /* mic-in */
4584 { 0x19, 0x411111f0 }, /* N/A */
4585 { 0x1a, 0x01813031 }, /* line-in */
4586 { 0x1b, 0x411111f0 }, /* N/A */
4587 { 0x1c, 0x411111f0 }, /* N/A */
4588 { 0x1d, 0x411111f0 }, /* N/A */
4589 { 0x1e, 0x0144111e }, /* SPDIF */
4590 { }
4591 }
4592 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004593 [ALC880_FIXUP_3ST_BASE] = {
4594 .type = ALC_FIXUP_PINS,
4595 .v.pins = (const struct alc_pincfg[]) {
4596 { 0x14, 0x01014010 }, /* line-out */
4597 { 0x15, 0x411111f0 }, /* N/A */
4598 { 0x16, 0x411111f0 }, /* N/A */
4599 { 0x17, 0x411111f0 }, /* N/A */
4600 { 0x18, 0x01a19c30 }, /* mic-in */
4601 { 0x19, 0x0121411f }, /* HP */
4602 { 0x1a, 0x01813031 }, /* line-in */
4603 { 0x1b, 0x02a19c40 }, /* front-mic */
4604 { 0x1c, 0x411111f0 }, /* N/A */
4605 { 0x1d, 0x411111f0 }, /* N/A */
4606 /* 0x1e is filled in below */
4607 { 0x1f, 0x411111f0 }, /* N/A */
4608 { }
4609 }
4610 },
4611 [ALC880_FIXUP_3ST] = {
4612 .type = ALC_FIXUP_PINS,
4613 .v.pins = (const struct alc_pincfg[]) {
4614 { 0x1e, 0x411111f0 }, /* N/A */
4615 { }
4616 },
4617 .chained = true,
4618 .chain_id = ALC880_FIXUP_3ST_BASE,
4619 },
4620 [ALC880_FIXUP_3ST_DIG] = {
4621 .type = ALC_FIXUP_PINS,
4622 .v.pins = (const struct alc_pincfg[]) {
4623 { 0x1e, 0x0144111e }, /* SPDIF */
4624 { }
4625 },
4626 .chained = true,
4627 .chain_id = ALC880_FIXUP_3ST_BASE,
4628 },
4629 [ALC880_FIXUP_5ST_BASE] = {
4630 .type = ALC_FIXUP_PINS,
4631 .v.pins = (const struct alc_pincfg[]) {
4632 { 0x14, 0x01014010 }, /* front */
4633 { 0x15, 0x411111f0 }, /* N/A */
4634 { 0x16, 0x01011411 }, /* CLFE */
4635 { 0x17, 0x01016412 }, /* surr */
4636 { 0x18, 0x01a19c30 }, /* mic-in */
4637 { 0x19, 0x0121411f }, /* HP */
4638 { 0x1a, 0x01813031 }, /* line-in */
4639 { 0x1b, 0x02a19c40 }, /* front-mic */
4640 { 0x1c, 0x411111f0 }, /* N/A */
4641 { 0x1d, 0x411111f0 }, /* N/A */
4642 /* 0x1e is filled in below */
4643 { 0x1f, 0x411111f0 }, /* N/A */
4644 { }
4645 }
4646 },
4647 [ALC880_FIXUP_5ST] = {
4648 .type = ALC_FIXUP_PINS,
4649 .v.pins = (const struct alc_pincfg[]) {
4650 { 0x1e, 0x411111f0 }, /* N/A */
4651 { }
4652 },
4653 .chained = true,
4654 .chain_id = ALC880_FIXUP_5ST_BASE,
4655 },
4656 [ALC880_FIXUP_5ST_DIG] = {
4657 .type = ALC_FIXUP_PINS,
4658 .v.pins = (const struct alc_pincfg[]) {
4659 { 0x1e, 0x0144111e }, /* SPDIF */
4660 { }
4661 },
4662 .chained = true,
4663 .chain_id = ALC880_FIXUP_5ST_BASE,
4664 },
4665 [ALC880_FIXUP_6ST_BASE] = {
4666 .type = ALC_FIXUP_PINS,
4667 .v.pins = (const struct alc_pincfg[]) {
4668 { 0x14, 0x01014010 }, /* front */
4669 { 0x15, 0x01016412 }, /* surr */
4670 { 0x16, 0x01011411 }, /* CLFE */
4671 { 0x17, 0x01012414 }, /* side */
4672 { 0x18, 0x01a19c30 }, /* mic-in */
4673 { 0x19, 0x02a19c40 }, /* front-mic */
4674 { 0x1a, 0x01813031 }, /* line-in */
4675 { 0x1b, 0x0121411f }, /* HP */
4676 { 0x1c, 0x411111f0 }, /* N/A */
4677 { 0x1d, 0x411111f0 }, /* N/A */
4678 /* 0x1e is filled in below */
4679 { 0x1f, 0x411111f0 }, /* N/A */
4680 { }
4681 }
4682 },
4683 [ALC880_FIXUP_6ST] = {
4684 .type = ALC_FIXUP_PINS,
4685 .v.pins = (const struct alc_pincfg[]) {
4686 { 0x1e, 0x411111f0 }, /* N/A */
4687 { }
4688 },
4689 .chained = true,
4690 .chain_id = ALC880_FIXUP_6ST_BASE,
4691 },
4692 [ALC880_FIXUP_6ST_DIG] = {
4693 .type = ALC_FIXUP_PINS,
4694 .v.pins = (const struct alc_pincfg[]) {
4695 { 0x1e, 0x0144111e }, /* SPDIF */
4696 { }
4697 },
4698 .chained = true,
4699 .chain_id = ALC880_FIXUP_6ST_BASE,
4700 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004701};
4702
4703static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004704 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004705 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004706 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4707 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004708 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004709 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004710 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004711 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004712 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004713 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004714 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004715 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004716 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004717 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004718 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004719 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4720 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4721 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004722 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004723
4724 /* Below is the copied entries from alc880_quirks.c.
4725 * It's not quite sure whether BIOS sets the correct pin-config table
4726 * on these machines, thus they are kept to be compatible with
4727 * the old static quirks. Once when it's confirmed to work without
4728 * these overrides, it'd be better to remove.
4729 */
4730 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4731 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4732 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4733 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4734 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4735 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4736 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4737 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4738 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4739 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4740 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4741 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4742 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4743 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4744 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4745 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4746 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4747 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4748 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4749 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4750 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4751 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4752 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4753 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4754 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4755 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4756 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4757 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4758 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4759 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4760 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4761 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4762 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4763 /* default Intel */
4764 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4765 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4766 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4767 {}
4768};
4769
4770static const struct alc_model_fixup alc880_fixup_models[] = {
4771 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4772 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4773 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4774 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4775 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4776 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004777 {}
4778};
4779
4780
4781/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004782 * OK, here we have finally the patch for ALC880
4783 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004784static int patch_alc880(struct hda_codec *codec)
4785{
4786 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004787 int err;
4788
Takashi Iwai3de95172012-05-07 18:03:15 +02004789 err = alc_alloc_spec(codec, 0x0b);
4790 if (err < 0)
4791 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004792
Takashi Iwai3de95172012-05-07 18:03:15 +02004793 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004794 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004795
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004796 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4797 alc880_fixups);
4798 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004799
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004800 /* automatic parse from the BIOS config */
4801 err = alc880_parse_auto_config(codec);
4802 if (err < 0)
4803 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004804
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004805 if (!spec->no_analog) {
4806 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004807 if (err < 0)
4808 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004809 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4810 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004811
Takashi Iwai1d045db2011-07-07 18:23:21 +02004812 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004813
Takashi Iwai589876e2012-02-20 15:47:55 +01004814 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4815
Takashi Iwai1d045db2011-07-07 18:23:21 +02004816 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004817
4818 error:
4819 alc_free(codec);
4820 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004821}
4822
4823
4824/*
4825 * ALC260 support
4826 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004827static int alc260_parse_auto_config(struct hda_codec *codec)
4828{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004829 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004830 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4831 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004832}
4833
Takashi Iwai1d045db2011-07-07 18:23:21 +02004834/*
4835 * Pin config fixes
4836 */
4837enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004838 ALC260_FIXUP_HP_DC5750,
4839 ALC260_FIXUP_HP_PIN_0F,
4840 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004841 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004842 ALC260_FIXUP_GPIO1_TOGGLE,
4843 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004844 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004845 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004846};
4847
Takashi Iwai20f7d922012-02-16 12:35:16 +01004848static void alc260_gpio1_automute(struct hda_codec *codec)
4849{
4850 struct alc_spec *spec = codec->spec;
4851 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4852 spec->hp_jack_present);
4853}
4854
4855static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4856 const struct alc_fixup *fix, int action)
4857{
4858 struct alc_spec *spec = codec->spec;
4859 if (action == ALC_FIXUP_ACT_PROBE) {
4860 /* although the machine has only one output pin, we need to
4861 * toggle GPIO1 according to the jack state
4862 */
4863 spec->automute_hook = alc260_gpio1_automute;
4864 spec->detect_hp = 1;
4865 spec->automute_speaker = 1;
4866 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4867 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004868 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004869 }
4870}
4871
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004872static void alc260_fixup_kn1(struct hda_codec *codec,
4873 const struct alc_fixup *fix, int action)
4874{
4875 struct alc_spec *spec = codec->spec;
4876 static const struct alc_pincfg pincfgs[] = {
4877 { 0x0f, 0x02214000 }, /* HP/speaker */
4878 { 0x12, 0x90a60160 }, /* int mic */
4879 { 0x13, 0x02a19000 }, /* ext mic */
4880 { 0x18, 0x01446000 }, /* SPDIF out */
4881 /* disable bogus I/O pins */
4882 { 0x10, 0x411111f0 },
4883 { 0x11, 0x411111f0 },
4884 { 0x14, 0x411111f0 },
4885 { 0x15, 0x411111f0 },
4886 { 0x16, 0x411111f0 },
4887 { 0x17, 0x411111f0 },
4888 { 0x19, 0x411111f0 },
4889 { }
4890 };
4891
4892 switch (action) {
4893 case ALC_FIXUP_ACT_PRE_PROBE:
4894 alc_apply_pincfgs(codec, pincfgs);
4895 break;
4896 case ALC_FIXUP_ACT_PROBE:
4897 spec->init_amp = ALC_INIT_NONE;
4898 break;
4899 }
4900}
4901
Takashi Iwai1d045db2011-07-07 18:23:21 +02004902static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004903 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004904 .type = ALC_FIXUP_PINS,
4905 .v.pins = (const struct alc_pincfg[]) {
4906 { 0x11, 0x90130110 }, /* speaker */
4907 { }
4908 }
4909 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004910 [ALC260_FIXUP_HP_PIN_0F] = {
4911 .type = ALC_FIXUP_PINS,
4912 .v.pins = (const struct alc_pincfg[]) {
4913 { 0x0f, 0x01214000 }, /* HP */
4914 { }
4915 }
4916 },
4917 [ALC260_FIXUP_COEF] = {
4918 .type = ALC_FIXUP_VERBS,
4919 .v.verbs = (const struct hda_verb[]) {
4920 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4921 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4922 { }
4923 },
4924 .chained = true,
4925 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4926 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004927 [ALC260_FIXUP_GPIO1] = {
4928 .type = ALC_FIXUP_VERBS,
4929 .v.verbs = alc_gpio1_init_verbs,
4930 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004931 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4932 .type = ALC_FIXUP_FUNC,
4933 .v.func = alc260_fixup_gpio1_toggle,
4934 .chained = true,
4935 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4936 },
4937 [ALC260_FIXUP_REPLACER] = {
4938 .type = ALC_FIXUP_VERBS,
4939 .v.verbs = (const struct hda_verb[]) {
4940 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4941 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4942 { }
4943 },
4944 .chained = true,
4945 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4946 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004947 [ALC260_FIXUP_HP_B1900] = {
4948 .type = ALC_FIXUP_FUNC,
4949 .v.func = alc260_fixup_gpio1_toggle,
4950 .chained = true,
4951 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004952 },
4953 [ALC260_FIXUP_KN1] = {
4954 .type = ALC_FIXUP_FUNC,
4955 .v.func = alc260_fixup_kn1,
4956 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004957};
4958
4959static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004960 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004961 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004962 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004963 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004964 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004965 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004966 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004967 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004968 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004969 {}
4970};
4971
4972/*
4973 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004974static int patch_alc260(struct hda_codec *codec)
4975{
4976 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004977 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004978
Takashi Iwai3de95172012-05-07 18:03:15 +02004979 err = alc_alloc_spec(codec, 0x07);
4980 if (err < 0)
4981 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004982
Takashi Iwai3de95172012-05-07 18:03:15 +02004983 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004984
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004985 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4986 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004987
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004988 /* automatic parse from the BIOS config */
4989 err = alc260_parse_auto_config(codec);
4990 if (err < 0)
4991 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004992
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004993 if (!spec->no_analog) {
4994 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004995 if (err < 0)
4996 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004997 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4998 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004999
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005001 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005002
Takashi Iwai589876e2012-02-20 15:47:55 +01005003 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5004
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005006
5007 error:
5008 alc_free(codec);
5009 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005010}
5011
5012
5013/*
5014 * ALC882/883/885/888/889 support
5015 *
5016 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5017 * configuration. Each pin widget can choose any input DACs and a mixer.
5018 * Each ADC is connected from a mixer of all inputs. This makes possible
5019 * 6-channel independent captures.
5020 *
5021 * In addition, an independent DAC for the multi-playback (not used in this
5022 * driver yet).
5023 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005024
5025/*
5026 * Pin config fixes
5027 */
5028enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005029 ALC882_FIXUP_ABIT_AW9D_MAX,
5030 ALC882_FIXUP_LENOVO_Y530,
5031 ALC882_FIXUP_PB_M5210,
5032 ALC882_FIXUP_ACER_ASPIRE_7736,
5033 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005034 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005035 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005036 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005037 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005038 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005039 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005040 ALC882_FIXUP_GPIO1,
5041 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005042 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005043 ALC889_FIXUP_COEF,
5044 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005045 ALC882_FIXUP_ACER_ASPIRE_4930G,
5046 ALC882_FIXUP_ACER_ASPIRE_8930G,
5047 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005048 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005049 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005050 ALC889_FIXUP_MBP_VREF,
5051 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005052 ALC882_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005053};
5054
Takashi Iwai68ef0562011-11-09 18:24:44 +01005055static void alc889_fixup_coef(struct hda_codec *codec,
5056 const struct alc_fixup *fix, int action)
5057{
5058 if (action != ALC_FIXUP_ACT_INIT)
5059 return;
5060 alc889_coef_init(codec);
5061}
5062
Takashi Iwai56710872011-11-14 17:42:11 +01005063/* toggle speaker-output according to the hp-jack state */
5064static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5065{
5066 unsigned int gpiostate, gpiomask, gpiodir;
5067
5068 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5069 AC_VERB_GET_GPIO_DATA, 0);
5070
5071 if (!muted)
5072 gpiostate |= (1 << pin);
5073 else
5074 gpiostate &= ~(1 << pin);
5075
5076 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5077 AC_VERB_GET_GPIO_MASK, 0);
5078 gpiomask |= (1 << pin);
5079
5080 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5081 AC_VERB_GET_GPIO_DIRECTION, 0);
5082 gpiodir |= (1 << pin);
5083
5084
5085 snd_hda_codec_write(codec, codec->afg, 0,
5086 AC_VERB_SET_GPIO_MASK, gpiomask);
5087 snd_hda_codec_write(codec, codec->afg, 0,
5088 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5089
5090 msleep(1);
5091
5092 snd_hda_codec_write(codec, codec->afg, 0,
5093 AC_VERB_SET_GPIO_DATA, gpiostate);
5094}
5095
5096/* set up GPIO at initialization */
5097static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5098 const struct alc_fixup *fix, int action)
5099{
5100 if (action != ALC_FIXUP_ACT_INIT)
5101 return;
5102 alc882_gpio_mute(codec, 0, 0);
5103 alc882_gpio_mute(codec, 1, 0);
5104}
5105
Takashi Iwai02a237b2012-02-13 15:25:07 +01005106/* Fix the connection of some pins for ALC889:
5107 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5108 * work correctly (bko#42740)
5109 */
5110static void alc889_fixup_dac_route(struct hda_codec *codec,
5111 const struct alc_fixup *fix, int action)
5112{
5113 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005114 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005115 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5116 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5117 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5118 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5119 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5120 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005121 } else if (action == ALC_FIXUP_ACT_PROBE) {
5122 /* restore the connections */
5123 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5124 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5125 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5126 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5127 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005128 }
5129}
5130
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005131/* Set VREF on HP pin */
5132static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5133 const struct alc_fixup *fix, int action)
5134{
5135 struct alc_spec *spec = codec->spec;
5136 static hda_nid_t nids[2] = { 0x14, 0x15 };
5137 int i;
5138
5139 if (action != ALC_FIXUP_ACT_INIT)
5140 return;
5141 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5142 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5143 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5144 continue;
5145 val = snd_hda_codec_read(codec, nids[i], 0,
5146 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5147 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005148 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005149 spec->keep_vref_in_automute = 1;
5150 break;
5151 }
5152}
5153
5154/* Set VREF on speaker pins on imac91 */
5155static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5156 const struct alc_fixup *fix, int action)
5157{
5158 struct alc_spec *spec = codec->spec;
5159 static hda_nid_t nids[2] = { 0x18, 0x1a };
5160 int i;
5161
5162 if (action != ALC_FIXUP_ACT_INIT)
5163 return;
5164 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5165 unsigned int val;
5166 val = snd_hda_codec_read(codec, nids[i], 0,
5167 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5168 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005169 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005170 }
5171 spec->keep_vref_in_automute = 1;
5172}
5173
Takashi Iwai1d045db2011-07-07 18:23:21 +02005174static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005175 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005176 .type = ALC_FIXUP_PINS,
5177 .v.pins = (const struct alc_pincfg[]) {
5178 { 0x15, 0x01080104 }, /* side */
5179 { 0x16, 0x01011012 }, /* rear */
5180 { 0x17, 0x01016011 }, /* clfe */
5181 { }
5182 }
5183 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005184 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005185 .type = ALC_FIXUP_PINS,
5186 .v.pins = (const struct alc_pincfg[]) {
5187 { 0x15, 0x99130112 }, /* rear int speakers */
5188 { 0x16, 0x99130111 }, /* subwoofer */
5189 { }
5190 }
5191 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005192 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005193 .type = ALC_FIXUP_VERBS,
5194 .v.verbs = (const struct hda_verb[]) {
5195 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5196 {}
5197 }
5198 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005199 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005200 .type = ALC_FIXUP_FUNC,
5201 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005202 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005203 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005204 .type = ALC_FIXUP_PINS,
5205 .v.pins = (const struct alc_pincfg[]) {
5206 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5207 { }
5208 }
5209 },
Marton Balint8f239212012-03-05 21:33:23 +01005210 [ALC889_FIXUP_CD] = {
5211 .type = ALC_FIXUP_PINS,
5212 .v.pins = (const struct alc_pincfg[]) {
5213 { 0x1c, 0x993301f0 }, /* CD */
5214 { }
5215 }
5216 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005217 [ALC889_FIXUP_VAIO_TT] = {
5218 .type = ALC_FIXUP_PINS,
5219 .v.pins = (const struct alc_pincfg[]) {
5220 { 0x17, 0x90170111 }, /* hidden surround speaker */
5221 { }
5222 }
5223 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005224 [ALC888_FIXUP_EEE1601] = {
5225 .type = ALC_FIXUP_VERBS,
5226 .v.verbs = (const struct hda_verb[]) {
5227 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5228 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5229 { }
5230 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005231 },
5232 [ALC882_FIXUP_EAPD] = {
5233 .type = ALC_FIXUP_VERBS,
5234 .v.verbs = (const struct hda_verb[]) {
5235 /* change to EAPD mode */
5236 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5237 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5238 { }
5239 }
5240 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005241 [ALC883_FIXUP_EAPD] = {
5242 .type = ALC_FIXUP_VERBS,
5243 .v.verbs = (const struct hda_verb[]) {
5244 /* change to EAPD mode */
5245 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5246 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5247 { }
5248 }
5249 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005250 [ALC883_FIXUP_ACER_EAPD] = {
5251 .type = ALC_FIXUP_VERBS,
5252 .v.verbs = (const struct hda_verb[]) {
5253 /* eanable EAPD on Acer laptops */
5254 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5255 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5256 { }
5257 }
5258 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005259 [ALC882_FIXUP_GPIO1] = {
5260 .type = ALC_FIXUP_VERBS,
5261 .v.verbs = alc_gpio1_init_verbs,
5262 },
5263 [ALC882_FIXUP_GPIO2] = {
5264 .type = ALC_FIXUP_VERBS,
5265 .v.verbs = alc_gpio2_init_verbs,
5266 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005267 [ALC882_FIXUP_GPIO3] = {
5268 .type = ALC_FIXUP_VERBS,
5269 .v.verbs = alc_gpio3_init_verbs,
5270 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005271 [ALC882_FIXUP_ASUS_W2JC] = {
5272 .type = ALC_FIXUP_VERBS,
5273 .v.verbs = alc_gpio1_init_verbs,
5274 .chained = true,
5275 .chain_id = ALC882_FIXUP_EAPD,
5276 },
5277 [ALC889_FIXUP_COEF] = {
5278 .type = ALC_FIXUP_FUNC,
5279 .v.func = alc889_fixup_coef,
5280 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005281 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5282 .type = ALC_FIXUP_PINS,
5283 .v.pins = (const struct alc_pincfg[]) {
5284 { 0x16, 0x99130111 }, /* CLFE speaker */
5285 { 0x17, 0x99130112 }, /* surround speaker */
5286 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005287 },
5288 .chained = true,
5289 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005290 },
5291 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5292 .type = ALC_FIXUP_PINS,
5293 .v.pins = (const struct alc_pincfg[]) {
5294 { 0x16, 0x99130111 }, /* CLFE speaker */
5295 { 0x1b, 0x99130112 }, /* surround speaker */
5296 { }
5297 },
5298 .chained = true,
5299 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5300 },
5301 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5302 /* additional init verbs for Acer Aspire 8930G */
5303 .type = ALC_FIXUP_VERBS,
5304 .v.verbs = (const struct hda_verb[]) {
5305 /* Enable all DACs */
5306 /* DAC DISABLE/MUTE 1? */
5307 /* setting bits 1-5 disables DAC nids 0x02-0x06
5308 * apparently. Init=0x38 */
5309 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5310 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5311 /* DAC DISABLE/MUTE 2? */
5312 /* some bit here disables the other DACs.
5313 * Init=0x4900 */
5314 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5315 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5316 /* DMIC fix
5317 * This laptop has a stereo digital microphone.
5318 * The mics are only 1cm apart which makes the stereo
5319 * useless. However, either the mic or the ALC889
5320 * makes the signal become a difference/sum signal
5321 * instead of standard stereo, which is annoying.
5322 * So instead we flip this bit which makes the
5323 * codec replicate the sum signal to both channels,
5324 * turning it into a normal mono mic.
5325 */
5326 /* DMIC_CONTROL? Init value = 0x0001 */
5327 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5328 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5329 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5330 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5331 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005332 },
5333 .chained = true,
5334 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005335 },
Takashi Iwai56710872011-11-14 17:42:11 +01005336 [ALC885_FIXUP_MACPRO_GPIO] = {
5337 .type = ALC_FIXUP_FUNC,
5338 .v.func = alc885_fixup_macpro_gpio,
5339 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005340 [ALC889_FIXUP_DAC_ROUTE] = {
5341 .type = ALC_FIXUP_FUNC,
5342 .v.func = alc889_fixup_dac_route,
5343 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005344 [ALC889_FIXUP_MBP_VREF] = {
5345 .type = ALC_FIXUP_FUNC,
5346 .v.func = alc889_fixup_mbp_vref,
5347 .chained = true,
5348 .chain_id = ALC882_FIXUP_GPIO1,
5349 },
5350 [ALC889_FIXUP_IMAC91_VREF] = {
5351 .type = ALC_FIXUP_FUNC,
5352 .v.func = alc889_fixup_imac91_vref,
5353 .chained = true,
5354 .chain_id = ALC882_FIXUP_GPIO1,
5355 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005356 [ALC882_FIXUP_INV_DMIC] = {
5357 .type = ALC_FIXUP_FUNC,
5358 .v.func = alc_fixup_inv_dmic_0x12,
5359 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005360};
5361
5362static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005363 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5364 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5365 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5366 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5367 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5368 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005369 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5370 ALC882_FIXUP_ACER_ASPIRE_4930G),
5371 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5372 ALC882_FIXUP_ACER_ASPIRE_4930G),
5373 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5374 ALC882_FIXUP_ACER_ASPIRE_8930G),
5375 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5376 ALC882_FIXUP_ACER_ASPIRE_8930G),
5377 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5378 ALC882_FIXUP_ACER_ASPIRE_4930G),
5379 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5380 ALC882_FIXUP_ACER_ASPIRE_4930G),
5381 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5382 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005383 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005384 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5385 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005386 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005387 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005388 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005389 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005390 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005391 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005392 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005393 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005394
5395 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005396 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5397 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5398 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005399 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5400 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5401 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005402 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5403 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005404 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005405 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5406 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5407 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5408 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005409 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005410 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5411 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5412 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005413 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005414 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5415 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5416 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005417
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005418 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005419 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005420 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005421 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005422 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005423 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5424 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005425 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005426 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005427 {}
5428};
5429
Takashi Iwai912093b2012-04-11 14:03:41 +02005430static const struct alc_model_fixup alc882_fixup_models[] = {
5431 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5432 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5433 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005434 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005435 {}
5436};
5437
Takashi Iwai1d045db2011-07-07 18:23:21 +02005438/*
5439 * BIOS auto configuration
5440 */
5441/* almost identical with ALC880 parser... */
5442static int alc882_parse_auto_config(struct hda_codec *codec)
5443{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005444 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005445 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5446 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005447}
5448
Takashi Iwai1d045db2011-07-07 18:23:21 +02005449/*
5450 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451static int patch_alc882(struct hda_codec *codec)
5452{
5453 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005454 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005455
Takashi Iwai3de95172012-05-07 18:03:15 +02005456 err = alc_alloc_spec(codec, 0x0b);
5457 if (err < 0)
5458 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005459
Takashi Iwai3de95172012-05-07 18:03:15 +02005460 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005461
5462 switch (codec->vendor_id) {
5463 case 0x10ec0882:
5464 case 0x10ec0885:
5465 break;
5466 default:
5467 /* ALC883 and variants */
5468 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5469 break;
5470 }
5471
Takashi Iwai912093b2012-04-11 14:03:41 +02005472 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5473 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005474 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005475
5476 alc_auto_parse_customize_define(codec);
5477
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005478 /* automatic parse from the BIOS config */
5479 err = alc882_parse_auto_config(codec);
5480 if (err < 0)
5481 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005482
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005483 if (!spec->no_analog && has_cdefine_beep(codec)) {
5484 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005485 if (err < 0)
5486 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005487 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005488 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489
Takashi Iwai1d045db2011-07-07 18:23:21 +02005490 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005491
Takashi Iwai589876e2012-02-20 15:47:55 +01005492 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5493
Takashi Iwai1d045db2011-07-07 18:23:21 +02005494 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005495
5496 error:
5497 alc_free(codec);
5498 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499}
5500
5501
5502/*
5503 * ALC262 support
5504 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505static int alc262_parse_auto_config(struct hda_codec *codec)
5506{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005507 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005508 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5509 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005510}
5511
5512/*
5513 * Pin config fixes
5514 */
5515enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005516 ALC262_FIXUP_FSC_H270,
5517 ALC262_FIXUP_HP_Z200,
5518 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005519 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005520 ALC262_FIXUP_BENQ,
5521 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005522 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005523};
5524
5525static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005526 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005527 .type = ALC_FIXUP_PINS,
5528 .v.pins = (const struct alc_pincfg[]) {
5529 { 0x14, 0x99130110 }, /* speaker */
5530 { 0x15, 0x0221142f }, /* front HP */
5531 { 0x1b, 0x0121141f }, /* rear HP */
5532 { }
5533 }
5534 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005535 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005536 .type = ALC_FIXUP_PINS,
5537 .v.pins = (const struct alc_pincfg[]) {
5538 { 0x16, 0x99130120 }, /* internal speaker */
5539 { }
5540 }
5541 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005542 [ALC262_FIXUP_TYAN] = {
5543 .type = ALC_FIXUP_PINS,
5544 .v.pins = (const struct alc_pincfg[]) {
5545 { 0x14, 0x1993e1f0 }, /* int AUX */
5546 { }
5547 }
5548 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005549 [ALC262_FIXUP_LENOVO_3000] = {
5550 .type = ALC_FIXUP_VERBS,
5551 .v.verbs = (const struct hda_verb[]) {
5552 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005553 {}
5554 },
5555 .chained = true,
5556 .chain_id = ALC262_FIXUP_BENQ,
5557 },
5558 [ALC262_FIXUP_BENQ] = {
5559 .type = ALC_FIXUP_VERBS,
5560 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005561 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5562 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5563 {}
5564 }
5565 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005566 [ALC262_FIXUP_BENQ_T31] = {
5567 .type = ALC_FIXUP_VERBS,
5568 .v.verbs = (const struct hda_verb[]) {
5569 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5570 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5571 {}
5572 }
5573 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005574 [ALC262_FIXUP_INV_DMIC] = {
5575 .type = ALC_FIXUP_FUNC,
5576 .v.func = alc_fixup_inv_dmic_0x12,
5577 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005578};
5579
5580static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005581 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005582 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5583 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005584 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5585 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005586 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005587 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5588 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005589 {}
5590};
5591
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005592static const struct alc_model_fixup alc262_fixup_models[] = {
5593 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5594 {}
5595};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005596
Takashi Iwai1d045db2011-07-07 18:23:21 +02005597/*
5598 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005599static int patch_alc262(struct hda_codec *codec)
5600{
5601 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005602 int err;
5603
Takashi Iwai3de95172012-05-07 18:03:15 +02005604 err = alc_alloc_spec(codec, 0x0b);
5605 if (err < 0)
5606 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005607
Takashi Iwai3de95172012-05-07 18:03:15 +02005608 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005609
5610#if 0
5611 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5612 * under-run
5613 */
5614 {
5615 int tmp;
5616 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5617 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5618 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5619 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5620 }
5621#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005622 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5623
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005624 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5625 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005626 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005627
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005628 alc_auto_parse_customize_define(codec);
5629
Takashi Iwai42399f72011-11-07 17:18:44 +01005630 /* automatic parse from the BIOS config */
5631 err = alc262_parse_auto_config(codec);
5632 if (err < 0)
5633 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005634
Takashi Iwai1d045db2011-07-07 18:23:21 +02005635 if (!spec->no_analog && has_cdefine_beep(codec)) {
5636 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005637 if (err < 0)
5638 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005639 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005640 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005641
Takashi Iwai1d045db2011-07-07 18:23:21 +02005642 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643 spec->shutup = alc_eapd_shutup;
5644
Takashi Iwai589876e2012-02-20 15:47:55 +01005645 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5646
Takashi Iwai1d045db2011-07-07 18:23:21 +02005647 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005648
5649 error:
5650 alc_free(codec);
5651 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652}
5653
5654/*
5655 * ALC268
5656 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657/* bind Beep switches of both NID 0x0f and 0x10 */
5658static const struct hda_bind_ctls alc268_bind_beep_sw = {
5659 .ops = &snd_hda_bind_sw,
5660 .values = {
5661 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5662 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5663 0
5664 },
5665};
5666
5667static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5668 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5669 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5670 { }
5671};
5672
5673/* set PCBEEP vol = 0, mute connections */
5674static const struct hda_verb alc268_beep_init_verbs[] = {
5675 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5676 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5677 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5678 { }
5679};
5680
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005681enum {
5682 ALC268_FIXUP_INV_DMIC,
5683};
5684
5685static const struct alc_fixup alc268_fixups[] = {
5686 [ALC268_FIXUP_INV_DMIC] = {
5687 .type = ALC_FIXUP_FUNC,
5688 .v.func = alc_fixup_inv_dmic_0x12,
5689 },
5690};
5691
5692static const struct alc_model_fixup alc268_fixup_models[] = {
5693 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5694 {}
5695};
5696
Takashi Iwai1d045db2011-07-07 18:23:21 +02005697/*
5698 * BIOS auto configuration
5699 */
5700static int alc268_parse_auto_config(struct hda_codec *codec)
5701{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005702 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005703 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005704 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5705 if (err > 0) {
5706 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5707 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005708 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005709 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005710 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005711 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712}
5713
Takashi Iwai1d045db2011-07-07 18:23:21 +02005714/*
5715 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005716static int patch_alc268(struct hda_codec *codec)
5717{
5718 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005719 int i, has_beep, err;
5720
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005722 err = alc_alloc_spec(codec, 0);
5723 if (err < 0)
5724 return err;
5725
5726 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005728 alc_pick_fixup(codec, alc268_fixup_models, NULL, alc268_fixups);
5729 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5730
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005731 /* automatic parse from the BIOS config */
5732 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005733 if (err < 0)
5734 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005735
Takashi Iwai1d045db2011-07-07 18:23:21 +02005736 has_beep = 0;
5737 for (i = 0; i < spec->num_mixers; i++) {
5738 if (spec->mixers[i] == alc268_beep_mixer) {
5739 has_beep = 1;
5740 break;
5741 }
5742 }
5743
5744 if (has_beep) {
5745 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005746 if (err < 0)
5747 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5749 /* override the amp caps for beep generator */
5750 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5751 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5752 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5753 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5754 (0 << AC_AMPCAP_MUTE_SHIFT));
5755 }
5756
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005758 spec->shutup = alc_eapd_shutup;
5759
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005760 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5761
Takashi Iwai1d045db2011-07-07 18:23:21 +02005762 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005763
5764 error:
5765 alc_free(codec);
5766 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767}
5768
5769/*
5770 * ALC269
5771 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005772static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5773 .substreams = 1,
5774 .channels_min = 2,
5775 .channels_max = 8,
5776 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5777 /* NID is set in alc_build_pcms */
5778 .ops = {
5779 .open = alc_playback_pcm_open,
5780 .prepare = alc_playback_pcm_prepare,
5781 .cleanup = alc_playback_pcm_cleanup
5782 },
5783};
5784
5785static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5786 .substreams = 1,
5787 .channels_min = 2,
5788 .channels_max = 2,
5789 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5790 /* NID is set in alc_build_pcms */
5791};
5792
Takashi Iwai1d045db2011-07-07 18:23:21 +02005793/* different alc269-variants */
5794enum {
5795 ALC269_TYPE_ALC269VA,
5796 ALC269_TYPE_ALC269VB,
5797 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005798 ALC269_TYPE_ALC269VD,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005799};
5800
5801/*
5802 * BIOS auto configuration
5803 */
5804static int alc269_parse_auto_config(struct hda_codec *codec)
5805{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005806 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005807 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5808 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5809 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005810 const hda_nid_t *ssids;
5811
5812 switch (spec->codec_variant) {
5813 case ALC269_TYPE_ALC269VA:
5814 case ALC269_TYPE_ALC269VC:
5815 ssids = alc269va_ssids;
5816 break;
5817 case ALC269_TYPE_ALC269VB:
5818 case ALC269_TYPE_ALC269VD:
5819 ssids = alc269_ssids;
5820 break;
5821 default:
5822 ssids = alc269_ssids;
5823 break;
5824 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005825
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005826 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005827}
5828
Takashi Iwai1d045db2011-07-07 18:23:21 +02005829static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5830{
5831 int val = alc_read_coef_idx(codec, 0x04);
5832 if (power_up)
5833 val |= 1 << 11;
5834 else
5835 val &= ~(1 << 11);
5836 alc_write_coef_idx(codec, 0x04, val);
5837}
5838
5839static void alc269_shutup(struct hda_codec *codec)
5840{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005841 struct alc_spec *spec = codec->spec;
5842
5843 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5844 return;
5845
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005846 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005847 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005848 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005849 alc269_toggle_power_output(codec, 0);
5850 msleep(150);
5851 }
5852}
5853
Takashi Iwai2a439522011-07-26 09:52:50 +02005854#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005855static int alc269_resume(struct hda_codec *codec)
5856{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005857 struct alc_spec *spec = codec->spec;
5858
5859 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5860 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005861 alc269_toggle_power_output(codec, 0);
5862 msleep(150);
5863 }
5864
5865 codec->patch_ops.init(codec);
5866
Kailang Yangadcc70b2012-05-25 08:08:38 +02005867 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5868 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005869 alc269_toggle_power_output(codec, 1);
5870 msleep(200);
5871 }
5872
Kailang Yangadcc70b2012-05-25 08:08:38 +02005873 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5874 (alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005875 alc269_toggle_power_output(codec, 1);
5876
5877 snd_hda_codec_resume_amp(codec);
5878 snd_hda_codec_resume_cache(codec);
5879 hda_call_check_power_status(codec, 0x01);
5880 return 0;
5881}
Takashi Iwai2a439522011-07-26 09:52:50 +02005882#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005883
5884static void alc269_fixup_hweq(struct hda_codec *codec,
5885 const struct alc_fixup *fix, int action)
5886{
5887 int coef;
5888
5889 if (action != ALC_FIXUP_ACT_INIT)
5890 return;
5891 coef = alc_read_coef_idx(codec, 0x1e);
5892 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5893}
5894
5895static void alc271_fixup_dmic(struct hda_codec *codec,
5896 const struct alc_fixup *fix, int action)
5897{
5898 static const struct hda_verb verbs[] = {
5899 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5900 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5901 {}
5902 };
5903 unsigned int cfg;
5904
5905 if (strcmp(codec->chip_name, "ALC271X"))
5906 return;
5907 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5908 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5909 snd_hda_sequence_write(codec, verbs);
5910}
5911
Takashi Iwai017f2a12011-07-09 14:42:25 +02005912static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5913 const struct alc_fixup *fix, int action)
5914{
5915 struct alc_spec *spec = codec->spec;
5916
5917 if (action != ALC_FIXUP_ACT_PROBE)
5918 return;
5919
5920 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5921 * fix the sample rate of analog I/O to 44.1kHz
5922 */
5923 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5924 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5925}
5926
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005927static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5928 const struct alc_fixup *fix, int action)
5929{
5930 int coef;
5931
5932 if (action != ALC_FIXUP_ACT_INIT)
5933 return;
5934 /* The digital-mic unit sends PDM (differential signal) instead of
5935 * the standard PCM, thus you can't record a valid mono stream as is.
5936 * Below is a workaround specific to ALC269 to control the dmic
5937 * signal source as mono.
5938 */
5939 coef = alc_read_coef_idx(codec, 0x07);
5940 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5941}
5942
Takashi Iwai24519912011-08-16 15:08:49 +02005943static void alc269_quanta_automute(struct hda_codec *codec)
5944{
David Henningsson42cf0d02011-09-20 12:04:56 +02005945 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005946
5947 snd_hda_codec_write(codec, 0x20, 0,
5948 AC_VERB_SET_COEF_INDEX, 0x0c);
5949 snd_hda_codec_write(codec, 0x20, 0,
5950 AC_VERB_SET_PROC_COEF, 0x680);
5951
5952 snd_hda_codec_write(codec, 0x20, 0,
5953 AC_VERB_SET_COEF_INDEX, 0x0c);
5954 snd_hda_codec_write(codec, 0x20, 0,
5955 AC_VERB_SET_PROC_COEF, 0x480);
5956}
5957
5958static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5959 const struct alc_fixup *fix, int action)
5960{
5961 struct alc_spec *spec = codec->spec;
5962 if (action != ALC_FIXUP_ACT_PROBE)
5963 return;
5964 spec->automute_hook = alc269_quanta_automute;
5965}
5966
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005967/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5968static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5969{
5970 struct hda_codec *codec = private_data;
5971 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005972 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005973}
5974
5975static void alc269_fixup_mic2_mute(struct hda_codec *codec,
5976 const struct alc_fixup *fix, int action)
5977{
5978 struct alc_spec *spec = codec->spec;
5979 switch (action) {
5980 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005981 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735cb2012-03-13 07:55:10 +01005982 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005983 /* fallthru */
5984 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005985 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005986 break;
5987 }
5988}
5989
David Henningsson693b6132012-06-22 19:12:10 +02005990
Takashi Iwai1d045db2011-07-07 18:23:21 +02005991enum {
5992 ALC269_FIXUP_SONY_VAIO,
5993 ALC275_FIXUP_SONY_VAIO_GPIO2,
5994 ALC269_FIXUP_DELL_M101Z,
5995 ALC269_FIXUP_SKU_IGNORE,
5996 ALC269_FIXUP_ASUS_G73JW,
5997 ALC269_FIXUP_LENOVO_EAPD,
5998 ALC275_FIXUP_SONY_HWEQ,
5999 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006000 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006001 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006002 ALC269_FIXUP_QUANTA_MUTE,
6003 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006004 ALC269_FIXUP_AMIC,
6005 ALC269_FIXUP_DMIC,
6006 ALC269VB_FIXUP_AMIC,
6007 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006008 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006009 ALC269_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006010};
6011
6012static const struct alc_fixup alc269_fixups[] = {
6013 [ALC269_FIXUP_SONY_VAIO] = {
6014 .type = ALC_FIXUP_VERBS,
6015 .v.verbs = (const struct hda_verb[]) {
6016 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6017 {}
6018 }
6019 },
6020 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6021 .type = ALC_FIXUP_VERBS,
6022 .v.verbs = (const struct hda_verb[]) {
6023 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6024 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6025 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6026 { }
6027 },
6028 .chained = true,
6029 .chain_id = ALC269_FIXUP_SONY_VAIO
6030 },
6031 [ALC269_FIXUP_DELL_M101Z] = {
6032 .type = ALC_FIXUP_VERBS,
6033 .v.verbs = (const struct hda_verb[]) {
6034 /* Enables internal speaker */
6035 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6036 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6037 {}
6038 }
6039 },
6040 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006041 .type = ALC_FIXUP_FUNC,
6042 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006043 },
6044 [ALC269_FIXUP_ASUS_G73JW] = {
6045 .type = ALC_FIXUP_PINS,
6046 .v.pins = (const struct alc_pincfg[]) {
6047 { 0x17, 0x99130111 }, /* subwoofer */
6048 { }
6049 }
6050 },
6051 [ALC269_FIXUP_LENOVO_EAPD] = {
6052 .type = ALC_FIXUP_VERBS,
6053 .v.verbs = (const struct hda_verb[]) {
6054 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6055 {}
6056 }
6057 },
6058 [ALC275_FIXUP_SONY_HWEQ] = {
6059 .type = ALC_FIXUP_FUNC,
6060 .v.func = alc269_fixup_hweq,
6061 .chained = true,
6062 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6063 },
6064 [ALC271_FIXUP_DMIC] = {
6065 .type = ALC_FIXUP_FUNC,
6066 .v.func = alc271_fixup_dmic,
6067 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006068 [ALC269_FIXUP_PCM_44K] = {
6069 .type = ALC_FIXUP_FUNC,
6070 .v.func = alc269_fixup_pcm_44k,
6071 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006072 [ALC269_FIXUP_STEREO_DMIC] = {
6073 .type = ALC_FIXUP_FUNC,
6074 .v.func = alc269_fixup_stereo_dmic,
6075 },
Takashi Iwai24519912011-08-16 15:08:49 +02006076 [ALC269_FIXUP_QUANTA_MUTE] = {
6077 .type = ALC_FIXUP_FUNC,
6078 .v.func = alc269_fixup_quanta_mute,
6079 },
6080 [ALC269_FIXUP_LIFEBOOK] = {
6081 .type = ALC_FIXUP_PINS,
6082 .v.pins = (const struct alc_pincfg[]) {
6083 { 0x1a, 0x2101103f }, /* dock line-out */
6084 { 0x1b, 0x23a11040 }, /* dock mic-in */
6085 { }
6086 },
6087 .chained = true,
6088 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6089 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006090 [ALC269_FIXUP_AMIC] = {
6091 .type = ALC_FIXUP_PINS,
6092 .v.pins = (const struct alc_pincfg[]) {
6093 { 0x14, 0x99130110 }, /* speaker */
6094 { 0x15, 0x0121401f }, /* HP out */
6095 { 0x18, 0x01a19c20 }, /* mic */
6096 { 0x19, 0x99a3092f }, /* int-mic */
6097 { }
6098 },
6099 },
6100 [ALC269_FIXUP_DMIC] = {
6101 .type = ALC_FIXUP_PINS,
6102 .v.pins = (const struct alc_pincfg[]) {
6103 { 0x12, 0x99a3092f }, /* int-mic */
6104 { 0x14, 0x99130110 }, /* speaker */
6105 { 0x15, 0x0121401f }, /* HP out */
6106 { 0x18, 0x01a19c20 }, /* mic */
6107 { }
6108 },
6109 },
6110 [ALC269VB_FIXUP_AMIC] = {
6111 .type = ALC_FIXUP_PINS,
6112 .v.pins = (const struct alc_pincfg[]) {
6113 { 0x14, 0x99130110 }, /* speaker */
6114 { 0x18, 0x01a19c20 }, /* mic */
6115 { 0x19, 0x99a3092f }, /* int-mic */
6116 { 0x21, 0x0121401f }, /* HP out */
6117 { }
6118 },
6119 },
David Henningsson2267ea92012-01-03 08:45:56 +01006120 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006121 .type = ALC_FIXUP_PINS,
6122 .v.pins = (const struct alc_pincfg[]) {
6123 { 0x12, 0x99a3092f }, /* int-mic */
6124 { 0x14, 0x99130110 }, /* speaker */
6125 { 0x18, 0x01a19c20 }, /* mic */
6126 { 0x21, 0x0121401f }, /* HP out */
6127 { }
6128 },
6129 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006130 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6131 .type = ALC_FIXUP_FUNC,
6132 .v.func = alc269_fixup_mic2_mute,
6133 },
David Henningsson693b6132012-06-22 19:12:10 +02006134 [ALC269_FIXUP_INV_DMIC] = {
6135 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006136 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006137 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006138};
6139
6140static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006141 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6142 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006143 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006144 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006145 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006146 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006147 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6148 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6149 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6150 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6151 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006152 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6153 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6154 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6155 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6156 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6157 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006158 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006159 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6160 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6161 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6162 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6163 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006164 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006165 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006166 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006167
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006168#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006169 /* Below is a quirk table taken from the old code.
6170 * Basically the device should work as is without the fixup table.
6171 * If BIOS doesn't give a proper info, enable the corresponding
6172 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006173 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006174 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6175 ALC269_FIXUP_AMIC),
6176 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006177 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6178 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6179 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6180 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6181 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6182 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6183 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6184 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6185 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6186 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6187 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6188 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6189 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6190 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6191 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6192 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6193 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6194 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6195 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6196 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6197 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6198 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6199 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6200 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6201 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6202 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6203 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6204 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6205 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6206 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6207 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6208 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6209 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6210 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6211 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6212 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6213 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6214 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6215#endif
6216 {}
6217};
6218
6219static const struct alc_model_fixup alc269_fixup_models[] = {
6220 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6221 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006222 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6223 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6224 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006225 {}
6226};
6227
6228
Takashi Iwai546bb672012-03-07 08:37:19 +01006229static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006230{
Kailang Yang526af6e2012-03-07 08:25:20 +01006231 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006232 int val;
6233
Kailang Yang526af6e2012-03-07 08:25:20 +01006234 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006235 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006236
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006237 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006238 alc_write_coef_idx(codec, 0xf, 0x960b);
6239 alc_write_coef_idx(codec, 0xe, 0x8817);
6240 }
6241
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006242 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006243 alc_write_coef_idx(codec, 0xf, 0x960b);
6244 alc_write_coef_idx(codec, 0xe, 0x8814);
6245 }
6246
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006247 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006248 val = alc_read_coef_idx(codec, 0x04);
6249 /* Power up output pin */
6250 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6251 }
6252
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006253 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006254 val = alc_read_coef_idx(codec, 0xd);
6255 if ((val & 0x0c00) >> 10 != 0x1) {
6256 /* Capless ramp up clock control */
6257 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6258 }
6259 val = alc_read_coef_idx(codec, 0x17);
6260 if ((val & 0x01c0) >> 6 != 0x4) {
6261 /* Class D power on reset */
6262 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6263 }
6264 }
6265
6266 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6267 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6268
6269 val = alc_read_coef_idx(codec, 0x4); /* HP */
6270 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006271}
6272
6273/*
6274 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006275static int patch_alc269(struct hda_codec *codec)
6276{
6277 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006278 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006279
Takashi Iwai3de95172012-05-07 18:03:15 +02006280 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006281 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006282 return err;
6283
6284 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006285
Takashi Iwai1d045db2011-07-07 18:23:21 +02006286 if (codec->vendor_id == 0x10ec0269) {
6287 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006288 switch (alc_get_coef0(codec) & 0x00f0) {
6289 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006290 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006291 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006292 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006293 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006294 break;
6295 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006296 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6297 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006298 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006300 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006301 case 0x0030:
6302 spec->codec_variant = ALC269_TYPE_ALC269VD;
6303 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006304 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006305 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006306 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006307 if (err < 0)
6308 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006309 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006310 alc269_fill_coef(codec);
6311 }
6312
Takashi Iwaia4297b52011-08-23 18:40:12 +02006313 alc_pick_fixup(codec, alc269_fixup_models,
6314 alc269_fixup_tbl, alc269_fixups);
6315 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006316
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006317 alc_auto_parse_customize_define(codec);
6318
Takashi Iwaia4297b52011-08-23 18:40:12 +02006319 /* automatic parse from the BIOS config */
6320 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006321 if (err < 0)
6322 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006323
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006324 if (!spec->no_analog && has_cdefine_beep(codec)) {
6325 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006326 if (err < 0)
6327 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006328 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006329 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006330
Takashi Iwai1d045db2011-07-07 18:23:21 +02006331 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006332#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006333 codec->patch_ops.resume = alc269_resume;
6334#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006335 spec->shutup = alc269_shutup;
6336
Takashi Iwai589876e2012-02-20 15:47:55 +01006337 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6338
Takashi Iwai1d045db2011-07-07 18:23:21 +02006339 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006340
6341 error:
6342 alc_free(codec);
6343 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006344}
6345
6346/*
6347 * ALC861
6348 */
6349
Takashi Iwai1d045db2011-07-07 18:23:21 +02006350static int alc861_parse_auto_config(struct hda_codec *codec)
6351{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006352 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006353 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6354 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006355}
6356
Takashi Iwai1d045db2011-07-07 18:23:21 +02006357/* Pin config fixes */
6358enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006359 ALC861_FIXUP_FSC_AMILO_PI1505,
6360 ALC861_FIXUP_AMP_VREF_0F,
6361 ALC861_FIXUP_NO_JACK_DETECT,
6362 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006363};
6364
Takashi Iwai31150f22012-01-30 10:54:08 +01006365/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6366static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6367 const struct alc_fixup *fix, int action)
6368{
6369 struct alc_spec *spec = codec->spec;
6370 unsigned int val;
6371
6372 if (action != ALC_FIXUP_ACT_INIT)
6373 return;
6374 val = snd_hda_codec_read(codec, 0x0f, 0,
6375 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6376 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6377 val |= AC_PINCTL_IN_EN;
6378 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006379 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006380 spec->keep_vref_in_automute = 1;
6381}
6382
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006383/* suppress the jack-detection */
6384static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6385 const struct alc_fixup *fix, int action)
6386{
6387 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6388 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006389}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006390
Takashi Iwai1d045db2011-07-07 18:23:21 +02006391static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006392 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006393 .type = ALC_FIXUP_PINS,
6394 .v.pins = (const struct alc_pincfg[]) {
6395 { 0x0b, 0x0221101f }, /* HP */
6396 { 0x0f, 0x90170310 }, /* speaker */
6397 { }
6398 }
6399 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006400 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006401 .type = ALC_FIXUP_FUNC,
6402 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006403 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006404 [ALC861_FIXUP_NO_JACK_DETECT] = {
6405 .type = ALC_FIXUP_FUNC,
6406 .v.func = alc_fixup_no_jack_detect,
6407 },
6408 [ALC861_FIXUP_ASUS_A6RP] = {
6409 .type = ALC_FIXUP_FUNC,
6410 .v.func = alc861_fixup_asus_amp_vref_0f,
6411 .chained = true,
6412 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6413 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006414};
6415
6416static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006417 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6418 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6419 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6420 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6421 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6422 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006423 {}
6424};
6425
6426/*
6427 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006428static int patch_alc861(struct hda_codec *codec)
6429{
6430 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006431 int err;
6432
Takashi Iwai3de95172012-05-07 18:03:15 +02006433 err = alc_alloc_spec(codec, 0x15);
6434 if (err < 0)
6435 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006436
Takashi Iwai3de95172012-05-07 18:03:15 +02006437 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006438
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006439 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6440 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006441
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006442 /* automatic parse from the BIOS config */
6443 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006444 if (err < 0)
6445 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006446
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006447 if (!spec->no_analog) {
6448 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006449 if (err < 0)
6450 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006451 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6452 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006453
Takashi Iwai1d045db2011-07-07 18:23:21 +02006454 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006455#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006456 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006457#endif
6458
Takashi Iwai589876e2012-02-20 15:47:55 +01006459 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6460
Takashi Iwai1d045db2011-07-07 18:23:21 +02006461 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006462
6463 error:
6464 alc_free(codec);
6465 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006466}
6467
6468/*
6469 * ALC861-VD support
6470 *
6471 * Based on ALC882
6472 *
6473 * In addition, an independent DAC
6474 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006475static int alc861vd_parse_auto_config(struct hda_codec *codec)
6476{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006477 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006478 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6479 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006480}
6481
Takashi Iwai1d045db2011-07-07 18:23:21 +02006482enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006483 ALC660VD_FIX_ASUS_GPIO1,
6484 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006485};
6486
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006487/* exclude VREF80 */
6488static void alc861vd_fixup_dallas(struct hda_codec *codec,
6489 const struct alc_fixup *fix, int action)
6490{
6491 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6492 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6493 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6494 }
6495}
6496
Takashi Iwai1d045db2011-07-07 18:23:21 +02006497static const struct alc_fixup alc861vd_fixups[] = {
6498 [ALC660VD_FIX_ASUS_GPIO1] = {
6499 .type = ALC_FIXUP_VERBS,
6500 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006501 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006502 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6503 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6504 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6505 { }
6506 }
6507 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006508 [ALC861VD_FIX_DALLAS] = {
6509 .type = ALC_FIXUP_FUNC,
6510 .v.func = alc861vd_fixup_dallas,
6511 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006512};
6513
6514static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006515 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006516 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006517 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006518 {}
6519};
6520
Takashi Iwai1d045db2011-07-07 18:23:21 +02006521/*
6522 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006523static int patch_alc861vd(struct hda_codec *codec)
6524{
6525 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006526 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006527
Takashi Iwai3de95172012-05-07 18:03:15 +02006528 err = alc_alloc_spec(codec, 0x0b);
6529 if (err < 0)
6530 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006531
Takashi Iwai3de95172012-05-07 18:03:15 +02006532 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006533
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006534 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6535 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006536
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006537 /* automatic parse from the BIOS config */
6538 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006539 if (err < 0)
6540 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006541
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006542 if (!spec->no_analog) {
6543 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006544 if (err < 0)
6545 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006546 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6547 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006548
Takashi Iwai1d045db2011-07-07 18:23:21 +02006549 codec->patch_ops = alc_patch_ops;
6550
Takashi Iwai1d045db2011-07-07 18:23:21 +02006551 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006552
Takashi Iwai589876e2012-02-20 15:47:55 +01006553 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6554
Takashi Iwai1d045db2011-07-07 18:23:21 +02006555 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006556
6557 error:
6558 alc_free(codec);
6559 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006560}
6561
6562/*
6563 * ALC662 support
6564 *
6565 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6566 * configuration. Each pin widget can choose any input DACs and a mixer.
6567 * Each ADC is connected from a mixer of all inputs. This makes possible
6568 * 6-channel independent captures.
6569 *
6570 * In addition, an independent DAC for the multi-playback (not used in this
6571 * driver yet).
6572 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006573
6574/*
6575 * BIOS auto configuration
6576 */
6577
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006578static int alc662_parse_auto_config(struct hda_codec *codec)
6579{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006580 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006581 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6582 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6583 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006584
Kailang Yang6227cdc2010-02-25 08:36:52 +01006585 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6586 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006587 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006588 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006589 ssids = alc662_ssids;
6590 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006591}
6592
Todd Broch6be79482010-12-07 16:51:05 -08006593static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006594 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006595{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006596 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006597 return;
Todd Broch6be79482010-12-07 16:51:05 -08006598 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6599 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6600 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6601 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6602 (0 << AC_AMPCAP_MUTE_SHIFT)))
6603 printk(KERN_WARNING
6604 "hda_codec: failed to override amp caps for NID 0x2\n");
6605}
6606
David Henningsson6cb3b702010-09-09 08:51:44 +02006607enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006608 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006609 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006610 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006611 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006612 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006613 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006614 ALC662_FIXUP_ASUS_MODE1,
6615 ALC662_FIXUP_ASUS_MODE2,
6616 ALC662_FIXUP_ASUS_MODE3,
6617 ALC662_FIXUP_ASUS_MODE4,
6618 ALC662_FIXUP_ASUS_MODE5,
6619 ALC662_FIXUP_ASUS_MODE6,
6620 ALC662_FIXUP_ASUS_MODE7,
6621 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006622 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006623 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006624 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006625};
6626
6627static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006628 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006629 .type = ALC_FIXUP_PINS,
6630 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006631 { 0x15, 0x99130112 }, /* subwoofer */
6632 { }
6633 }
6634 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006635 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006636 .type = ALC_FIXUP_PINS,
6637 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006638 { 0x17, 0x99130112 }, /* subwoofer */
6639 { }
6640 }
6641 },
Todd Broch6be79482010-12-07 16:51:05 -08006642 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006643 .type = ALC_FIXUP_FUNC,
6644 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006645 },
6646 [ALC662_FIXUP_CZC_P10T] = {
6647 .type = ALC_FIXUP_VERBS,
6648 .v.verbs = (const struct hda_verb[]) {
6649 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6650 {}
6651 }
6652 },
David Henningsson94024cd2011-04-29 14:10:55 +02006653 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006654 .type = ALC_FIXUP_FUNC,
6655 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006656 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006657 [ALC662_FIXUP_HP_RP5800] = {
6658 .type = ALC_FIXUP_PINS,
6659 .v.pins = (const struct alc_pincfg[]) {
6660 { 0x14, 0x0221201f }, /* HP out */
6661 { }
6662 },
6663 .chained = true,
6664 .chain_id = ALC662_FIXUP_SKU_IGNORE
6665 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006666 [ALC662_FIXUP_ASUS_MODE1] = {
6667 .type = ALC_FIXUP_PINS,
6668 .v.pins = (const struct alc_pincfg[]) {
6669 { 0x14, 0x99130110 }, /* speaker */
6670 { 0x18, 0x01a19c20 }, /* mic */
6671 { 0x19, 0x99a3092f }, /* int-mic */
6672 { 0x21, 0x0121401f }, /* HP out */
6673 { }
6674 },
6675 .chained = true,
6676 .chain_id = ALC662_FIXUP_SKU_IGNORE
6677 },
6678 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006679 .type = ALC_FIXUP_PINS,
6680 .v.pins = (const struct alc_pincfg[]) {
6681 { 0x14, 0x99130110 }, /* speaker */
6682 { 0x18, 0x01a19820 }, /* mic */
6683 { 0x19, 0x99a3092f }, /* int-mic */
6684 { 0x1b, 0x0121401f }, /* HP out */
6685 { }
6686 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006687 .chained = true,
6688 .chain_id = ALC662_FIXUP_SKU_IGNORE
6689 },
6690 [ALC662_FIXUP_ASUS_MODE3] = {
6691 .type = ALC_FIXUP_PINS,
6692 .v.pins = (const struct alc_pincfg[]) {
6693 { 0x14, 0x99130110 }, /* speaker */
6694 { 0x15, 0x0121441f }, /* HP */
6695 { 0x18, 0x01a19840 }, /* mic */
6696 { 0x19, 0x99a3094f }, /* int-mic */
6697 { 0x21, 0x01211420 }, /* HP2 */
6698 { }
6699 },
6700 .chained = true,
6701 .chain_id = ALC662_FIXUP_SKU_IGNORE
6702 },
6703 [ALC662_FIXUP_ASUS_MODE4] = {
6704 .type = ALC_FIXUP_PINS,
6705 .v.pins = (const struct alc_pincfg[]) {
6706 { 0x14, 0x99130110 }, /* speaker */
6707 { 0x16, 0x99130111 }, /* speaker */
6708 { 0x18, 0x01a19840 }, /* mic */
6709 { 0x19, 0x99a3094f }, /* int-mic */
6710 { 0x21, 0x0121441f }, /* HP */
6711 { }
6712 },
6713 .chained = true,
6714 .chain_id = ALC662_FIXUP_SKU_IGNORE
6715 },
6716 [ALC662_FIXUP_ASUS_MODE5] = {
6717 .type = ALC_FIXUP_PINS,
6718 .v.pins = (const struct alc_pincfg[]) {
6719 { 0x14, 0x99130110 }, /* speaker */
6720 { 0x15, 0x0121441f }, /* HP */
6721 { 0x16, 0x99130111 }, /* speaker */
6722 { 0x18, 0x01a19840 }, /* mic */
6723 { 0x19, 0x99a3094f }, /* int-mic */
6724 { }
6725 },
6726 .chained = true,
6727 .chain_id = ALC662_FIXUP_SKU_IGNORE
6728 },
6729 [ALC662_FIXUP_ASUS_MODE6] = {
6730 .type = ALC_FIXUP_PINS,
6731 .v.pins = (const struct alc_pincfg[]) {
6732 { 0x14, 0x99130110 }, /* speaker */
6733 { 0x15, 0x01211420 }, /* HP2 */
6734 { 0x18, 0x01a19840 }, /* mic */
6735 { 0x19, 0x99a3094f }, /* int-mic */
6736 { 0x1b, 0x0121441f }, /* HP */
6737 { }
6738 },
6739 .chained = true,
6740 .chain_id = ALC662_FIXUP_SKU_IGNORE
6741 },
6742 [ALC662_FIXUP_ASUS_MODE7] = {
6743 .type = ALC_FIXUP_PINS,
6744 .v.pins = (const struct alc_pincfg[]) {
6745 { 0x14, 0x99130110 }, /* speaker */
6746 { 0x17, 0x99130111 }, /* speaker */
6747 { 0x18, 0x01a19840 }, /* mic */
6748 { 0x19, 0x99a3094f }, /* int-mic */
6749 { 0x1b, 0x01214020 }, /* HP */
6750 { 0x21, 0x0121401f }, /* HP */
6751 { }
6752 },
6753 .chained = true,
6754 .chain_id = ALC662_FIXUP_SKU_IGNORE
6755 },
6756 [ALC662_FIXUP_ASUS_MODE8] = {
6757 .type = ALC_FIXUP_PINS,
6758 .v.pins = (const struct alc_pincfg[]) {
6759 { 0x14, 0x99130110 }, /* speaker */
6760 { 0x12, 0x99a30970 }, /* int-mic */
6761 { 0x15, 0x01214020 }, /* HP */
6762 { 0x17, 0x99130111 }, /* speaker */
6763 { 0x18, 0x01a19840 }, /* mic */
6764 { 0x21, 0x0121401f }, /* HP */
6765 { }
6766 },
6767 .chained = true,
6768 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006769 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006770 [ALC662_FIXUP_NO_JACK_DETECT] = {
6771 .type = ALC_FIXUP_FUNC,
6772 .v.func = alc_fixup_no_jack_detect,
6773 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006774 [ALC662_FIXUP_ZOTAC_Z68] = {
6775 .type = ALC_FIXUP_PINS,
6776 .v.pins = (const struct alc_pincfg[]) {
6777 { 0x1b, 0x02214020 }, /* Front HP */
6778 { }
6779 }
6780 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006781 [ALC662_FIXUP_INV_DMIC] = {
6782 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006783 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006784 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006785};
6786
Takashi Iwaia9111322011-05-02 11:30:18 +02006787static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006788 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006789 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006790 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006791 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006792 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006793 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006794 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006795 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006796 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006797 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006798 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006799 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006800 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006801
6802#if 0
6803 /* Below is a quirk table taken from the old code.
6804 * Basically the device should work as is without the fixup table.
6805 * If BIOS doesn't give a proper info, enable the corresponding
6806 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006807 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006808 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6809 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6810 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6811 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6812 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6813 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6814 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6815 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6816 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6817 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6818 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6819 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6820 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6821 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6822 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6823 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6824 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6825 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6826 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6827 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6828 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6829 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6830 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6831 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6832 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6833 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6834 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6835 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6836 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6837 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6838 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6839 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6840 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6841 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6842 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6843 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6844 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6845 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6846 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6847 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6848 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6849 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6850 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6851 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6852 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6853 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6854 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6855 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6856 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6857 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6858#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006859 {}
6860};
6861
Todd Broch6be79482010-12-07 16:51:05 -08006862static const struct alc_model_fixup alc662_fixup_models[] = {
6863 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006864 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6865 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6866 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6867 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6868 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6869 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6870 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6871 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006872 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08006873 {}
6874};
David Henningsson6cb3b702010-09-09 08:51:44 +02006875
6876
Takashi Iwai1d045db2011-07-07 18:23:21 +02006877/*
6878 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006879static int patch_alc662(struct hda_codec *codec)
6880{
6881 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006882 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006883
Takashi Iwai3de95172012-05-07 18:03:15 +02006884 err = alc_alloc_spec(codec, 0x0b);
6885 if (err < 0)
6886 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006887
Takashi Iwai3de95172012-05-07 18:03:15 +02006888 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006889
Takashi Iwai53c334a2011-08-23 18:27:14 +02006890 /* handle multiple HPs as is */
6891 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6892
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006893 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6894
Takashi Iwai8e5a0502012-06-21 15:49:33 +02006895 alc_pick_fixup(codec, alc662_fixup_models,
6896 alc662_fixup_tbl, alc662_fixups);
6897 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6898
6899 alc_auto_parse_customize_define(codec);
6900
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006901 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006902 codec->bus->pci->subsystem_vendor == 0x1025 &&
6903 spec->cdefine.platform_type == 1) {
6904 if (alc_codec_rename(codec, "ALC272X") < 0)
6905 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006906 }
Kailang Yang274693f2009-12-03 10:07:50 +01006907
Takashi Iwaib9c51062011-08-24 18:08:07 +02006908 /* automatic parse from the BIOS config */
6909 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006910 if (err < 0)
6911 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006912
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006913 if (!spec->no_analog && has_cdefine_beep(codec)) {
6914 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006915 if (err < 0)
6916 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006917 switch (codec->vendor_id) {
6918 case 0x10ec0662:
6919 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6920 break;
6921 case 0x10ec0272:
6922 case 0x10ec0663:
6923 case 0x10ec0665:
6924 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6925 break;
6926 case 0x10ec0273:
6927 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6928 break;
6929 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006930 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006931
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006932 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02006933 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006934
Takashi Iwai589876e2012-02-20 15:47:55 +01006935 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6936
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006937 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006938
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006939 error:
6940 alc_free(codec);
6941 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006942}
6943
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006944/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006945 * ALC680 support
6946 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006947
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006948static int alc680_parse_auto_config(struct hda_codec *codec)
6949{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006950 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006951}
6952
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006953/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006954 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006955static int patch_alc680(struct hda_codec *codec)
6956{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006957 int err;
6958
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006959 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006960 err = alc_alloc_spec(codec, 0);
6961 if (err < 0)
6962 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006963
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006964 /* automatic parse from the BIOS config */
6965 err = alc680_parse_auto_config(codec);
6966 if (err < 0) {
6967 alc_free(codec);
6968 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006969 }
6970
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006971 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006972
6973 return 0;
6974}
6975
6976/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006977 * patch entries
6978 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006979static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006980 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006981 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006982 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006983 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006984 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006985 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006986 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006987 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006988 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006989 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02006990 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02006991 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006992 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006993 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006994 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6995 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6996 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006997 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006998 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006999 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7000 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007001 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7002 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007003 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007004 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007005 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007006 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007007 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007008 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007009 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007010 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007011 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007012 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007013 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007014 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007015 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007016 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007017 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007018 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007019 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007020 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007021 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007022 {} /* terminator */
7023};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007024
7025MODULE_ALIAS("snd-hda-codec-id:10ec*");
7026
7027MODULE_LICENSE("GPL");
7028MODULE_DESCRIPTION("Realtek HD-audio codec");
7029
7030static struct hda_codec_preset_list realtek_list = {
7031 .preset = snd_hda_preset_realtek,
7032 .owner = THIS_MODULE,
7033};
7034
7035static int __init patch_realtek_init(void)
7036{
7037 return snd_hda_add_codec_preset(&realtek_list);
7038}
7039
7040static void __exit patch_realtek_exit(void)
7041{
7042 snd_hda_delete_codec_preset(&realtek_list);
7043}
7044
7045module_init(patch_realtek_init)
7046module_exit(patch_realtek_exit)