blob: 89737ae491527963d57d3f002729040680aba629 [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);
Takashi Iwai83012a72012-08-24 18:38:08 +0200177#ifdef CONFIG_PM
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 Iwai1c716152011-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 Iwaie427c232012-07-29 10:04:08 +0200206 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200207
208 /* auto-mute control */
209 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200210 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200211
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200212 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200213 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100214
Takashi Iwai2134ea42008-01-10 16:53:55 +0100215 /* for virtual master */
216 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100217 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200218#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200219 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100220 int num_loopbacks;
221 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200222#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200223
224 /* for PLL fix */
225 hda_nid_t pll_nid;
226 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200227 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100228
Takashi Iwaice764ab2011-04-27 16:35:23 +0200229 /* multi-io */
230 int multi_ios;
231 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200232
233 /* bind volumes */
234 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100235};
236
Takashi Iwai44c02402011-07-08 15:14:19 +0200237static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
238 int dir, unsigned int bits)
239{
240 if (!nid)
241 return false;
242 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
243 if (query_amp_caps(codec, nid, dir) & bits)
244 return true;
245 return false;
246}
247
248#define nid_has_mute(codec, nid, dir) \
249 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
250#define nid_has_volume(codec, nid, dir) \
251 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253/*
254 * input MUX handling
255 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200256static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
260 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200261 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
262 if (mux_idx >= spec->num_mux_defs)
263 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100264 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
265 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200266 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200269static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
270 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
272 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
273 struct alc_spec *spec = codec->spec;
274 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
275
276 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
277 return 0;
278}
279
Takashi Iwai21268962011-07-07 15:01:13 +0200280static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Takashi Iwai21268962011-07-07 15:01:13 +0200282 struct alc_spec *spec = codec->spec;
283 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
284
285 if (spec->cur_adc && spec->cur_adc != new_adc) {
286 /* stream is running, let's swap the current ADC */
287 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
288 spec->cur_adc = new_adc;
289 snd_hda_codec_setup_stream(codec, new_adc,
290 spec->cur_adc_stream_tag, 0,
291 spec->cur_adc_format);
292 return true;
293 }
294 return false;
295}
296
Takashi Iwai61071592011-11-23 07:52:15 +0100297static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
298{
299 return spec->capsrc_nids ?
300 spec->capsrc_nids[idx] : spec->adc_nids[idx];
301}
302
Takashi Iwai24de1832011-11-07 17:13:39 +0100303static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200304static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100305
David Henningsson00227f12012-06-27 18:45:44 +0200306/* for shared I/O, change the pin-control accordingly */
307static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
308{
309 struct alc_spec *spec = codec->spec;
310 unsigned int val;
311 hda_nid_t pin = spec->autocfg.inputs[1].pin;
312 /* NOTE: this assumes that there are only two inputs, the
313 * first is the real internal mic and the second is HP/mic jack.
314 */
315
316 val = snd_hda_get_default_vref(codec, pin);
317
318 /* This pin does not have vref caps - let's enable vref on pin 0x18
319 instead, as suggested by Realtek */
320 if (val == AC_PINCTL_VREF_HIZ) {
321 const hda_nid_t vref_pin = 0x18;
322 /* Sanity check pin 0x18 */
323 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
324 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
325 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
326 if (vref_val != AC_PINCTL_VREF_HIZ)
327 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
328 }
329 }
330
331 val = set_as_mic ? val | PIN_IN : PIN_HP;
332 snd_hda_set_pin_ctl(codec, pin, val);
333
334 spec->automute_speaker = !set_as_mic;
335 call_update_outputs(codec);
336}
Takashi Iwai21268962011-07-07 15:01:13 +0200337
338/* select the given imux item; either unmute exclusively or select the route */
339static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
340 unsigned int idx, bool force)
341{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100343 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100344 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100345 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200346 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Takashi Iwai5803a322012-02-21 11:59:45 +0100348 if (!spec->input_mux)
349 return 0;
350
Takashi Iwaicd896c32008-11-18 12:36:33 +0100351 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
352 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100353 if (!imux->num_items && mux_idx > 0)
354 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100355 if (!imux->num_items)
356 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100357
Takashi Iwai21268962011-07-07 15:01:13 +0200358 if (idx >= imux->num_items)
359 idx = imux->num_items - 1;
360 if (spec->cur_mux[adc_idx] == idx && !force)
361 return 0;
362 spec->cur_mux[adc_idx] = idx;
363
David Henningsson00227f12012-06-27 18:45:44 +0200364 if (spec->shared_mic_hp)
365 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100366
Takashi Iwai21268962011-07-07 15:01:13 +0200367 if (spec->dyn_adc_switch) {
368 alc_dyn_adc_pcm_resetup(codec, idx);
369 adc_idx = spec->dyn_adc_idx[idx];
370 }
371
Takashi Iwai61071592011-11-23 07:52:15 +0100372 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200373
374 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200375 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100376 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200377 return 1;
378
Takashi Iwaia22d5432009-07-27 12:54:26 +0200379 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200380 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100381 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100382 int active = imux->items[idx].index;
383 for (i = 0; i < num_conns; i++) {
384 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
385 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100386 HDA_AMP_MUTE, v);
387 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100388 } else {
389 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200390 snd_hda_codec_write_cache(codec, nid, 0,
391 AC_VERB_SET_CONNECT_SEL,
392 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100393 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200394 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200395 return 1;
396}
397
398static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403 return alc_mux_select(codec, adc_idx,
404 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100405}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100408 * set up the input pin config (depending on the given auto-pin type)
409 */
410static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
411 int auto_pin_type)
412{
413 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200414 if (auto_pin_type == AUTO_PIN_MIC)
415 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200416 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100417}
418
419/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200420 * Append the given mixer and verb elements for the later use
421 * The mixer array is referred in build_controls(), and init_verbs are
422 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100423 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200424static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100425{
426 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
427 return;
428 spec->mixers[spec->num_mixers++] = mix;
429}
430
Takashi Iwaid88897e2008-10-31 15:01:37 +0100431/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200432 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100433 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200434/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200435static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200436 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
437 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
438 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
439 { }
440};
441
Takashi Iwaia9111322011-05-02 11:30:18 +0200442static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200443 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
444 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
445 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
446 { }
447};
448
Takashi Iwaia9111322011-05-02 11:30:18 +0200449static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200450 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
451 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
452 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
453 { }
454};
455
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200456/*
457 * Fix hardware PLL issue
458 * On some codecs, the analog PLL gating control must be off while
459 * the default value is 1.
460 */
461static void alc_fix_pll(struct hda_codec *codec)
462{
463 struct alc_spec *spec = codec->spec;
464 unsigned int val;
465
466 if (!spec->pll_nid)
467 return;
468 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
469 spec->pll_coef_idx);
470 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
471 AC_VERB_GET_PROC_COEF, 0);
472 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
473 spec->pll_coef_idx);
474 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
475 val & ~(1 << spec->pll_coef_bit));
476}
477
478static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
479 unsigned int coef_idx, unsigned int coef_bit)
480{
481 struct alc_spec *spec = codec->spec;
482 spec->pll_nid = nid;
483 spec->pll_coef_idx = coef_idx;
484 spec->pll_coef_bit = coef_bit;
485 alc_fix_pll(codec);
486}
487
Takashi Iwai1d045db2011-07-07 18:23:21 +0200488/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200489 * Jack detections for HP auto-mute and mic-switch
490 */
491
492/* check each pin in the given array; returns true if any of them is plugged */
493static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200494{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200496
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200499 if (!nid)
500 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200502 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200503 return present;
504}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200505
Takashi Iwai1d045db2011-07-07 18:23:21 +0200506/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200508 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200509{
510 struct alc_spec *spec = codec->spec;
511 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200512 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200513 int i;
514
515 for (i = 0; i < num_pins; i++) {
516 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100517 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200518 if (!nid)
519 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200520 switch (spec->automute_mode) {
521 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100522 /* don't reset VREF value in case it's controlling
523 * the amp (see alc861_fixup_asus_amp_vref_0f())
524 */
525 if (spec->keep_vref_in_automute) {
526 val = snd_hda_codec_read(codec, nid, 0,
527 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
528 val &= ~PIN_HP;
529 } else
530 val = 0;
531 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200532 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200533 break;
534 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200535 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200536 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200537 break;
538 case ALC_AUTOMUTE_MIXER:
539 nid = spec->automute_mixer_nid[i];
540 if (!nid)
541 break;
542 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200544 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200545 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200546 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200547 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200548 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200549}
550
David Henningsson42cf0d02011-09-20 12:04:56 +0200551/* Toggle outputs muting */
552static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200553{
554 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556
Takashi Iwaic0a20262011-06-10 15:28:15 +0200557 /* Control HP pins/amps depending on master_mute state;
558 * in general, HP pins/amps control should be enabled in all cases,
559 * but currently set only for master_mute, just to be safe
560 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100561 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
562 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200563 spec->autocfg.hp_pins, spec->master_mute, true);
564
David Henningsson42cf0d02011-09-20 12:04:56 +0200565 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 on = 0;
567 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200568 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200569 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200570 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200571 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200572
573 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200574 /* if LO is a copy of either HP or Speaker, don't need to handle it */
575 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
576 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200578 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200579 on = 0;
580 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200581 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200582 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200584 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200585}
586
David Henningsson42cf0d02011-09-20 12:04:56 +0200587static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200588{
589 struct alc_spec *spec = codec->spec;
590 if (spec->automute_hook)
591 spec->automute_hook(codec);
592 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200593 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200594}
595
Takashi Iwai1d045db2011-07-07 18:23:21 +0200596/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200597static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200598{
599 struct alc_spec *spec = codec->spec;
600
David Henningsson42cf0d02011-09-20 12:04:56 +0200601 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
603 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200604 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200605 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200606 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607}
608
Takashi Iwai1d045db2011-07-07 18:23:21 +0200609/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200610static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200611{
612 struct alc_spec *spec = codec->spec;
613
David Henningssonf7f4b2322012-10-10 16:32:09 +0200614 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
615 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200616 /* check LO jack only when it's different from HP */
617 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
618 return;
619
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200620 spec->line_jack_present =
621 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
622 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200623 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200624 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200625 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200626}
627
Takashi Iwai8d087c72011-06-28 12:45:47 +0200628#define get_connection_index(codec, mux, nid) \
629 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200630
Takashi Iwai1d045db2011-07-07 18:23:21 +0200631/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200632static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200633{
634 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200635 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200636
Takashi Iwai21268962011-07-07 15:01:13 +0200637 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200638 return;
639 if (snd_BUG_ON(!spec->adc_nids))
640 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200641 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200642 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200643
Takashi Iwai21268962011-07-07 15:01:13 +0200644 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
645 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
646 else if (spec->dock_mic_idx >= 0 &&
647 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
648 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
649 else
650 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200651}
652
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100653/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200654static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100655{
656 unsigned int val;
657 struct snd_kcontrol *kctl;
658 struct snd_ctl_elem_value *uctl;
659
660 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
661 if (!kctl)
662 return;
663 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
664 if (!uctl)
665 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200666 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100667 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
668 val &= HDA_AMP_VOLMASK;
669 uctl->value.integer.value[0] = val;
670 uctl->value.integer.value[1] = val;
671 kctl->put(kctl, uctl);
672 kfree(uctl);
673}
674
David Henningsson29adc4b2012-09-25 11:31:00 +0200675static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100676{
David Henningsson29adc4b2012-09-25 11:31:00 +0200677 /* For some reason, the res given from ALC880 is broken.
678 Here we adjust it properly. */
679 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100680}
681
Takashi Iwai1d045db2011-07-07 18:23:21 +0200682/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200683static void alc_inithook(struct hda_codec *codec)
684{
David Henningsson29adc4b2012-09-25 11:31:00 +0200685 alc_hp_automute(codec, NULL);
686 alc_line_automute(codec, NULL);
687 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200688}
689
Kailang Yangf9423e72008-05-27 12:32:25 +0200690/* additional initialization for ALC888 variants */
691static void alc888_coef_init(struct hda_codec *codec)
692{
693 unsigned int tmp;
694
695 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
696 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100698 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200699 /* alc888S-VC */
700 snd_hda_codec_read(codec, 0x20, 0,
701 AC_VERB_SET_PROC_COEF, 0x830);
702 else
703 /* alc888-VB */
704 snd_hda_codec_read(codec, 0x20, 0,
705 AC_VERB_SET_PROC_COEF, 0x3030);
706}
707
Takashi Iwai1d045db2011-07-07 18:23:21 +0200708/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200709static void alc889_coef_init(struct hda_codec *codec)
710{
711 unsigned int tmp;
712
713 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
714 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
715 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
716 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
717}
718
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100719/* turn on/off EAPD control (only if available) */
720static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
721{
722 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
723 return;
724 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
725 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
726 on ? 2 : 0);
727}
728
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200729/* turn on/off EAPD controls of the codec */
730static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
731{
732 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200733 static hda_nid_t pins[] = {
734 0x0f, 0x10, 0x14, 0x15, 0
735 };
736 hda_nid_t *p;
737 for (p = pins; *p; p++)
738 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200739}
740
Takashi Iwai1c716152011-04-07 10:37:16 +0200741/* generic shutup callback;
742 * just turning off EPAD and a little pause for avoiding pop-noise
743 */
744static void alc_eapd_shutup(struct hda_codec *codec)
745{
746 alc_auto_setup_eapd(codec, false);
747 msleep(200);
748}
749
Takashi Iwai1d045db2011-07-07 18:23:21 +0200750/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200751static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200752{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200753 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200754
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200755 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200756 switch (type) {
757 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200758 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
759 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200760 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200761 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
762 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200763 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200764 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
765 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200766 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200767 switch (codec->vendor_id) {
768 case 0x10ec0260:
769 snd_hda_codec_write(codec, 0x1a, 0,
770 AC_VERB_SET_COEF_INDEX, 7);
771 tmp = snd_hda_codec_read(codec, 0x1a, 0,
772 AC_VERB_GET_PROC_COEF, 0);
773 snd_hda_codec_write(codec, 0x1a, 0,
774 AC_VERB_SET_COEF_INDEX, 7);
775 snd_hda_codec_write(codec, 0x1a, 0,
776 AC_VERB_SET_PROC_COEF,
777 tmp | 0x2010);
778 break;
779 case 0x10ec0262:
780 case 0x10ec0880:
781 case 0x10ec0882:
782 case 0x10ec0883:
783 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100784 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100785 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200786 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200787 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200788 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200789 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200790 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100791#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200792 case 0x10ec0267:
793 case 0x10ec0268:
794 snd_hda_codec_write(codec, 0x20, 0,
795 AC_VERB_SET_COEF_INDEX, 7);
796 tmp = snd_hda_codec_read(codec, 0x20, 0,
797 AC_VERB_GET_PROC_COEF, 0);
798 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200799 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200800 snd_hda_codec_write(codec, 0x20, 0,
801 AC_VERB_SET_PROC_COEF,
802 tmp | 0x3000);
803 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100804#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200805 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200806 break;
807 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200808}
Kailang Yangea1fb292008-08-26 12:58:38 +0200809
Takashi Iwai1d045db2011-07-07 18:23:21 +0200810/*
811 * Auto-Mute mode mixer enum support
812 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200813static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_info *uinfo)
815{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct alc_spec *spec = codec->spec;
818 static const char * const texts2[] = {
819 "Disabled", "Enabled"
820 };
821 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100822 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200823 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200824 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200825
826 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
827 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200828 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200829 uinfo->value.enumerated.items = 3;
830 texts = texts3;
831 } else {
832 uinfo->value.enumerated.items = 2;
833 texts = texts2;
834 }
835 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
836 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200837 strcpy(uinfo->value.enumerated.name,
838 texts[uinfo->value.enumerated.item]);
839 return 0;
840}
841
842static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
843 struct snd_ctl_elem_value *ucontrol)
844{
845 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
846 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200847 unsigned int val = 0;
848 if (spec->automute_speaker)
849 val++;
850 if (spec->automute_lo)
851 val++;
852
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200853 ucontrol->value.enumerated.item[0] = val;
854 return 0;
855}
856
857static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
858 struct snd_ctl_elem_value *ucontrol)
859{
860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
861 struct alc_spec *spec = codec->spec;
862
863 switch (ucontrol->value.enumerated.item[0]) {
864 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200865 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200866 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200867 spec->automute_speaker = 0;
868 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200869 break;
870 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200871 if (spec->automute_speaker_possible) {
872 if (!spec->automute_lo && spec->automute_speaker)
873 return 0;
874 spec->automute_speaker = 1;
875 spec->automute_lo = 0;
876 } else if (spec->automute_lo_possible) {
877 if (spec->automute_lo)
878 return 0;
879 spec->automute_lo = 1;
880 } else
881 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200882 break;
883 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200885 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200886 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200887 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200888 spec->automute_speaker = 1;
889 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200890 break;
891 default:
892 return -EINVAL;
893 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200894 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200895 return 1;
896}
897
Takashi Iwaia9111322011-05-02 11:30:18 +0200898static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
900 .name = "Auto-Mute Mode",
901 .info = alc_automute_mode_info,
902 .get = alc_automute_mode_get,
903 .put = alc_automute_mode_put,
904};
905
Takashi Iwai1d045db2011-07-07 18:23:21 +0200906static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
907{
908 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
909 return snd_array_new(&spec->kctls);
910}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200911
912static int alc_add_automute_mode_enum(struct hda_codec *codec)
913{
914 struct alc_spec *spec = codec->spec;
915 struct snd_kcontrol_new *knew;
916
917 knew = alc_kcontrol_new(spec);
918 if (!knew)
919 return -ENOMEM;
920 *knew = alc_automute_mode_enum;
921 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
922 if (!knew->name)
923 return -ENOMEM;
924 return 0;
925}
926
Takashi Iwai1d045db2011-07-07 18:23:21 +0200927/*
928 * Check the availability of HP/line-out auto-mute;
929 * Set up appropriately if really supported
930 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200931static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200932{
933 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200934 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200935 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200936 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200937
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200938 if (cfg->hp_pins[0])
939 present++;
940 if (cfg->line_out_pins[0])
941 present++;
942 if (cfg->speaker_pins[0])
943 present++;
944 if (present < 2) /* need two different output types */
945 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200946
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200947 if (!cfg->speaker_pins[0] &&
948 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200949 memcpy(cfg->speaker_pins, cfg->line_out_pins,
950 sizeof(cfg->speaker_pins));
951 cfg->speaker_outs = cfg->line_outs;
952 }
953
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200954 if (!cfg->hp_pins[0] &&
955 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200956 memcpy(cfg->hp_pins, cfg->line_out_pins,
957 sizeof(cfg->hp_pins));
958 cfg->hp_outs = cfg->line_outs;
959 }
960
David Henningsson42cf0d02011-09-20 12:04:56 +0200961 spec->automute_mode = ALC_AUTOMUTE_PIN;
962
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200963 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200964 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200965 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200966 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200967 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200968 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200969 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
970 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200971 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200972 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200973
David Henningsson42cf0d02011-09-20 12:04:56 +0200974 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
975 if (cfg->speaker_outs)
976 for (i = 0; i < cfg->line_outs; i++) {
977 hda_nid_t nid = cfg->line_out_pins[i];
978 if (!is_jack_detectable(codec, nid))
979 continue;
980 snd_printdd("realtek: Enable Line-Out "
981 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200982 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
983 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200984 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200985 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200986 spec->automute_lo_possible = spec->detect_hp;
987 }
988
989 spec->automute_speaker_possible = cfg->speaker_outs &&
990 (spec->detect_hp || spec->detect_lo);
991
992 spec->automute_lo = spec->automute_lo_possible;
993 spec->automute_speaker = spec->automute_speaker_possible;
994
David Henningssona7a0a642012-07-05 12:00:12 +0200995 if (spec->automute_speaker_possible || spec->automute_lo_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200996 /* create a control for automute mode */
997 alc_add_automute_mode_enum(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200998}
999
Takashi Iwai1d045db2011-07-07 18:23:21 +02001000/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001001static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1002{
1003 int i;
1004 for (i = 0; i < nums; i++)
1005 if (list[i] == nid)
1006 return i;
1007 return -1;
1008}
1009
Takashi Iwai1d045db2011-07-07 18:23:21 +02001010/* check whether dynamic ADC-switching is available */
1011static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1012{
1013 struct alc_spec *spec = codec->spec;
1014 struct hda_input_mux *imux = &spec->private_imux[0];
1015 int i, n, idx;
1016 hda_nid_t cap, pin;
1017
1018 if (imux != spec->input_mux) /* no dynamic imux? */
1019 return false;
1020
1021 for (n = 0; n < spec->num_adc_nids; n++) {
1022 cap = spec->private_capsrc_nids[n];
1023 for (i = 0; i < imux->num_items; i++) {
1024 pin = spec->imux_pins[i];
1025 if (!pin)
1026 return false;
1027 if (get_connection_index(codec, cap, pin) < 0)
1028 break;
1029 }
1030 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001031 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001032 }
1033
1034 for (i = 0; i < imux->num_items; i++) {
1035 pin = spec->imux_pins[i];
1036 for (n = 0; n < spec->num_adc_nids; n++) {
1037 cap = spec->private_capsrc_nids[n];
1038 idx = get_connection_index(codec, cap, pin);
1039 if (idx >= 0) {
1040 imux->items[i].index = idx;
1041 spec->dyn_adc_idx[i] = n;
1042 break;
1043 }
1044 }
1045 }
1046
1047 snd_printdd("realtek: enabling ADC switching\n");
1048 spec->dyn_adc_switch = 1;
1049 return true;
1050}
Takashi Iwai21268962011-07-07 15:01:13 +02001051
Takashi Iwai21268962011-07-07 15:01:13 +02001052/* check whether all auto-mic pins are valid; setup indices if OK */
1053static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1054{
1055 struct alc_spec *spec = codec->spec;
1056 const struct hda_input_mux *imux;
1057
1058 if (!spec->auto_mic)
1059 return false;
1060 if (spec->auto_mic_valid_imux)
1061 return true; /* already checked */
1062
1063 /* fill up imux indices */
1064 if (!alc_check_dyn_adc_switch(codec)) {
1065 spec->auto_mic = 0;
1066 return false;
1067 }
1068
1069 imux = spec->input_mux;
1070 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1071 spec->imux_pins, imux->num_items);
1072 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1073 spec->imux_pins, imux->num_items);
1074 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1075 spec->imux_pins, imux->num_items);
1076 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1077 spec->auto_mic = 0;
1078 return false; /* no corresponding imux */
1079 }
1080
David Henningsson29adc4b2012-09-25 11:31:00 +02001081 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1082 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001083 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001084 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1085 ALC_MIC_EVENT,
1086 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001087
1088 spec->auto_mic_valid_imux = 1;
1089 spec->auto_mic = 1;
1090 return true;
1091}
1092
Takashi Iwai1d045db2011-07-07 18:23:21 +02001093/*
1094 * Check the availability of auto-mic switch;
1095 * Set up if really supported
1096 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001097static void alc_init_auto_mic(struct hda_codec *codec)
1098{
1099 struct alc_spec *spec = codec->spec;
1100 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001101 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001102 int i;
1103
Takashi Iwai24de1832011-11-07 17:13:39 +01001104 if (spec->shared_mic_hp)
1105 return; /* no auto-mic for the shared I/O */
1106
Takashi Iwai21268962011-07-07 15:01:13 +02001107 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1108
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001109 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001110 for (i = 0; i < cfg->num_inputs; i++) {
1111 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001112 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001113 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001114 switch (snd_hda_get_input_pin_attr(defcfg)) {
1115 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001116 if (fixed)
1117 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001118 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1119 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001120 fixed = nid;
1121 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001122 case INPUT_PIN_ATTR_UNUSED:
1123 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001124 case INPUT_PIN_ATTR_DOCK:
1125 if (dock)
1126 return; /* already occupied */
1127 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1128 return; /* invalid type */
1129 dock = nid;
1130 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001131 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001132 if (ext)
1133 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001134 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1135 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001136 ext = nid;
1137 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001138 }
1139 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001140 if (!ext && dock) {
1141 ext = dock;
1142 dock = 0;
1143 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001144 if (!ext || !fixed)
1145 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001146 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001147 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001148 if (dock && !is_jack_detectable(codec, dock))
1149 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001150
1151 /* check imux indices */
1152 spec->ext_mic_pin = ext;
1153 spec->int_mic_pin = fixed;
1154 spec->dock_mic_pin = dock;
1155
1156 spec->auto_mic = 1;
1157 if (!alc_auto_mic_check_imux(codec))
1158 return;
1159
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001160 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1161 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001162}
1163
Takashi Iwai1d045db2011-07-07 18:23:21 +02001164/* check the availabilities of auto-mute and auto-mic switches */
1165static void alc_auto_check_switches(struct hda_codec *codec)
1166{
David Henningsson42cf0d02011-09-20 12:04:56 +02001167 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001168 alc_init_auto_mic(codec);
1169}
1170
1171/*
1172 * Realtek SSID verification
1173 */
1174
David Henningsson90622912010-10-14 14:50:18 +02001175/* Could be any non-zero and even value. When used as fixup, tells
1176 * the driver to ignore any present sku defines.
1177 */
1178#define ALC_FIXUP_SKU_IGNORE (2)
1179
Takashi Iwai23d30f22012-05-07 17:17:32 +02001180static void alc_fixup_sku_ignore(struct hda_codec *codec,
1181 const struct hda_fixup *fix, int action)
1182{
1183 struct alc_spec *spec = codec->spec;
1184 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1185 spec->cdefine.fixup = 1;
1186 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1187 }
1188}
1189
Kailang Yangda00c242010-03-19 11:23:45 +01001190static int alc_auto_parse_customize_define(struct hda_codec *codec)
1191{
1192 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001193 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001194 struct alc_spec *spec = codec->spec;
1195
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001196 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1197
David Henningsson90622912010-10-14 14:50:18 +02001198 if (spec->cdefine.fixup) {
1199 ass = spec->cdefine.sku_cfg;
1200 if (ass == ALC_FIXUP_SKU_IGNORE)
1201 return -1;
1202 goto do_sku;
1203 }
1204
Kailang Yangda00c242010-03-19 11:23:45 +01001205 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001206 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001207 goto do_sku;
1208
1209 nid = 0x1d;
1210 if (codec->vendor_id == 0x10ec0260)
1211 nid = 0x17;
1212 ass = snd_hda_codec_get_pincfg(codec, nid);
1213
1214 if (!(ass & 1)) {
1215 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1216 codec->chip_name, ass);
1217 return -1;
1218 }
1219
1220 /* check sum */
1221 tmp = 0;
1222 for (i = 1; i < 16; i++) {
1223 if ((ass >> i) & 1)
1224 tmp++;
1225 }
1226 if (((ass >> 16) & 0xf) != tmp)
1227 return -1;
1228
1229 spec->cdefine.port_connectivity = ass >> 30;
1230 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1231 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1232 spec->cdefine.customization = ass >> 8;
1233do_sku:
1234 spec->cdefine.sku_cfg = ass;
1235 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1236 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1237 spec->cdefine.swap = (ass & 0x2) >> 1;
1238 spec->cdefine.override = ass & 0x1;
1239
1240 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1241 nid, spec->cdefine.sku_cfg);
1242 snd_printd("SKU: port_connectivity=0x%x\n",
1243 spec->cdefine.port_connectivity);
1244 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1245 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1246 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1247 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1248 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1249 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1250 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1251
1252 return 0;
1253}
1254
Takashi Iwai1d045db2011-07-07 18:23:21 +02001255/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001256static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1257{
Takashi Iwai21268962011-07-07 15:01:13 +02001258 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001259}
1260
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001261/* check subsystem ID and set up device-specific initialization;
1262 * return 1 if initialized, 0 if invalid SSID
1263 */
1264/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1265 * 31 ~ 16 : Manufacture ID
1266 * 15 ~ 8 : SKU ID
1267 * 7 ~ 0 : Assembly ID
1268 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1269 */
1270static int alc_subsystem_id(struct hda_codec *codec,
1271 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001272 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001273{
1274 unsigned int ass, tmp, i;
1275 unsigned nid;
1276 struct alc_spec *spec = codec->spec;
1277
David Henningsson90622912010-10-14 14:50:18 +02001278 if (spec->cdefine.fixup) {
1279 ass = spec->cdefine.sku_cfg;
1280 if (ass == ALC_FIXUP_SKU_IGNORE)
1281 return 0;
1282 goto do_sku;
1283 }
1284
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001285 ass = codec->subsystem_id & 0xffff;
1286 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1287 goto do_sku;
1288
1289 /* invalid SSID, check the special NID pin defcfg instead */
1290 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001291 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001292 * 29~21 : reserve
1293 * 20 : PCBEEP input
1294 * 19~16 : Check sum (15:1)
1295 * 15~1 : Custom
1296 * 0 : override
1297 */
1298 nid = 0x1d;
1299 if (codec->vendor_id == 0x10ec0260)
1300 nid = 0x17;
1301 ass = snd_hda_codec_get_pincfg(codec, nid);
1302 snd_printd("realtek: No valid SSID, "
1303 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001304 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001305 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001306 return 0;
1307 if ((ass >> 30) != 1) /* no physical connection */
1308 return 0;
1309
1310 /* check sum */
1311 tmp = 0;
1312 for (i = 1; i < 16; i++) {
1313 if ((ass >> i) & 1)
1314 tmp++;
1315 }
1316 if (((ass >> 16) & 0xf) != tmp)
1317 return 0;
1318do_sku:
1319 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1320 ass & 0xffff, codec->vendor_id);
1321 /*
1322 * 0 : override
1323 * 1 : Swap Jack
1324 * 2 : 0 --> Desktop, 1 --> Laptop
1325 * 3~5 : External Amplifier control
1326 * 7~6 : Reserved
1327 */
1328 tmp = (ass & 0x38) >> 3; /* external Amp control */
1329 switch (tmp) {
1330 case 1:
1331 spec->init_amp = ALC_INIT_GPIO1;
1332 break;
1333 case 3:
1334 spec->init_amp = ALC_INIT_GPIO2;
1335 break;
1336 case 7:
1337 spec->init_amp = ALC_INIT_GPIO3;
1338 break;
1339 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001340 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001341 spec->init_amp = ALC_INIT_DEFAULT;
1342 break;
1343 }
1344
1345 /* is laptop or Desktop and enable the function "Mute internal speaker
1346 * when the external headphone out jack is plugged"
1347 */
1348 if (!(ass & 0x8000))
1349 return 1;
1350 /*
1351 * 10~8 : Jack location
1352 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1353 * 14~13: Resvered
1354 * 15 : 1 --> enable the function "Mute internal speaker
1355 * when the external headphone out jack is plugged"
1356 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001357 if (!spec->autocfg.hp_pins[0] &&
1358 !(spec->autocfg.line_out_pins[0] &&
1359 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001360 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001361 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1362 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001363 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001364 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001365 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001366 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001367 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001368 else if (tmp == 3)
1369 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001370 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001371 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001372 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1373 spec->autocfg.line_outs))
1374 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001375 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001376 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001377 return 1;
1378}
Kailang Yangea1fb292008-08-26 12:58:38 +02001379
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001380/* Check the validity of ALC subsystem-id
1381 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1382static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001383{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001384 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001385 struct alc_spec *spec = codec->spec;
1386 snd_printd("realtek: "
1387 "Enable default setup for auto mode as fallback\n");
1388 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001389 }
Takashi Iwai21268962011-07-07 15:01:13 +02001390}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001391
Takashi Iwai41e41f12005-06-08 14:48:49 +02001392/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001393 * COEF access helper functions
1394 */
Kailang Yang274693f2009-12-03 10:07:50 +01001395static int alc_read_coef_idx(struct hda_codec *codec,
1396 unsigned int coef_idx)
1397{
1398 unsigned int val;
1399 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1400 coef_idx);
1401 val = snd_hda_codec_read(codec, 0x20, 0,
1402 AC_VERB_GET_PROC_COEF, 0);
1403 return val;
1404}
1405
Kailang Yang977ddd62010-09-15 10:02:29 +02001406static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1407 unsigned int coef_val)
1408{
1409 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1410 coef_idx);
1411 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1412 coef_val);
1413}
1414
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001415/* a special bypass for COEF 0; read the cached value at the second time */
1416static unsigned int alc_get_coef0(struct hda_codec *codec)
1417{
1418 struct alc_spec *spec = codec->spec;
1419 if (!spec->coef0)
1420 spec->coef0 = alc_read_coef_idx(codec, 0);
1421 return spec->coef0;
1422}
1423
Takashi Iwai1d045db2011-07-07 18:23:21 +02001424/*
1425 * Digital I/O handling
1426 */
1427
Takashi Iwai757899a2010-07-30 10:48:14 +02001428/* set right pin controls for digital I/O */
1429static void alc_auto_init_digital(struct hda_codec *codec)
1430{
1431 struct alc_spec *spec = codec->spec;
1432 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001433 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001434
1435 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1436 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001437 if (!pin)
1438 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001439 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001440 if (!i)
1441 dac = spec->multiout.dig_out_nid;
1442 else
1443 dac = spec->slave_dig_outs[i - 1];
1444 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1445 continue;
1446 snd_hda_codec_write(codec, dac, 0,
1447 AC_VERB_SET_AMP_GAIN_MUTE,
1448 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001449 }
1450 pin = spec->autocfg.dig_in_pin;
1451 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001452 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001453}
1454
1455/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1456static void alc_auto_parse_digital(struct hda_codec *codec)
1457{
1458 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001459 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001460 hda_nid_t dig_nid;
1461
1462 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001463 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001464 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001465 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001466 err = snd_hda_get_connections(codec,
1467 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001468 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001469 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001470 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001471 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001472 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001473 spec->multiout.dig_out_nid = dig_nid;
1474 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1475 } else {
1476 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001477 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001478 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001479 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001480 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001481 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001482 }
1483
1484 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001485 dig_nid = codec->start_nid;
1486 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1487 unsigned int wcaps = get_wcaps(codec, dig_nid);
1488 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1489 continue;
1490 if (!(wcaps & AC_WCAP_DIGITAL))
1491 continue;
1492 if (!(wcaps & AC_WCAP_CONN_LIST))
1493 continue;
1494 err = get_connection_index(codec, dig_nid,
1495 spec->autocfg.dig_in_pin);
1496 if (err >= 0) {
1497 spec->dig_in_nid = dig_nid;
1498 break;
1499 }
1500 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001501 }
1502}
1503
Takashi Iwaif95474e2007-07-10 00:47:43 +02001504/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001505 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001506 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001507static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1508 struct snd_ctl_elem_info *uinfo)
1509{
1510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1511 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001512 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001513 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001514
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001515 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001516 if (spec->vol_in_capsrc)
1517 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1518 else
1519 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1520 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001521 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001522 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001523 return err;
1524}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001526static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1527 unsigned int size, unsigned int __user *tlv)
1528{
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001531 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001532 int err;
1533
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001534 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001535 if (spec->vol_in_capsrc)
1536 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1537 else
1538 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1539 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001540 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001541 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001542 return err;
1543}
1544
1545typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1546 struct snd_ctl_elem_value *ucontrol);
1547
1548static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1549 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001550 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001551{
1552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1553 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001554 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001555
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001556 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001557 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001558 for (i = 0; i < spec->num_adc_nids; i++) {
1559 kcontrol->private_value =
1560 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1561 3, 0, HDA_INPUT);
1562 err = func(kcontrol, ucontrol);
1563 if (err < 0)
1564 goto error;
1565 }
1566 } else {
1567 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001568 if (spec->vol_in_capsrc)
1569 kcontrol->private_value =
1570 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1571 3, 0, HDA_OUTPUT);
1572 else
1573 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001574 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1575 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001576 err = func(kcontrol, ucontrol);
1577 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001578 if (err >= 0 && is_put)
1579 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001580 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001581 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001582 return err;
1583}
1584
1585static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1586 struct snd_ctl_elem_value *ucontrol)
1587{
1588 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001589 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001590}
1591
1592static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1594{
1595 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001596 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001597}
1598
1599/* capture mixer elements */
1600#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1601
1602static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1603 struct snd_ctl_elem_value *ucontrol)
1604{
1605 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001606 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001607}
1608
1609static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1611{
1612 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001613 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001614}
1615
Takashi Iwaia23b6882009-03-23 15:21:36 +01001616#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001617 { \
1618 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1619 .name = "Capture Switch", \
1620 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1621 .count = num, \
1622 .info = alc_cap_sw_info, \
1623 .get = alc_cap_sw_get, \
1624 .put = alc_cap_sw_put, \
1625 }, \
1626 { \
1627 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1628 .name = "Capture Volume", \
1629 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1630 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1631 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1632 .count = num, \
1633 .info = alc_cap_vol_info, \
1634 .get = alc_cap_vol_get, \
1635 .put = alc_cap_vol_put, \
1636 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001637 }
1638
1639#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001640 { \
1641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1642 /* .name = "Capture Source", */ \
1643 .name = "Input Source", \
1644 .count = num, \
1645 .info = alc_mux_enum_info, \
1646 .get = alc_mux_enum_get, \
1647 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001648 }
1649
1650#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001651static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001652 _DEFINE_CAPMIX(num), \
1653 _DEFINE_CAPSRC(num), \
1654 { } /* end */ \
1655}
1656
1657#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001658static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001659 _DEFINE_CAPMIX(num), \
1660 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001661}
1662
1663/* up to three ADCs */
1664DEFINE_CAPMIX(1);
1665DEFINE_CAPMIX(2);
1666DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001667DEFINE_CAPMIX_NOSRC(1);
1668DEFINE_CAPMIX_NOSRC(2);
1669DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001670
1671/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001672 * Inverted digital-mic handling
1673 *
1674 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1675 * gives the additional mute only to the right channel of the digital mic
1676 * capture stream. This is a workaround for avoiding the almost silence
1677 * by summing the stereo stream from some (known to be ForteMedia)
1678 * digital mic unit.
1679 *
1680 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1681 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1682 * without caching so that the cache can still keep the original value.
1683 * The cached value is then restored when the flag is set off or any other
1684 * than d-mic is used as the current input source.
1685 */
1686static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1687{
1688 struct alc_spec *spec = codec->spec;
1689 int i;
1690
1691 if (!spec->inv_dmic_fixup)
1692 return;
1693 if (!spec->inv_dmic_muted && !force)
1694 return;
1695 for (i = 0; i < spec->num_adc_nids; i++) {
1696 int src = spec->dyn_adc_switch ? 0 : i;
1697 bool dmic_fixup = false;
1698 hda_nid_t nid;
1699 int parm, dir, v;
1700
1701 if (spec->inv_dmic_muted &&
1702 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1703 dmic_fixup = true;
1704 if (!dmic_fixup && !force)
1705 continue;
1706 if (spec->vol_in_capsrc) {
1707 nid = spec->capsrc_nids[i];
1708 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1709 dir = HDA_OUTPUT;
1710 } else {
1711 nid = spec->adc_nids[i];
1712 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1713 dir = HDA_INPUT;
1714 }
1715 /* we care only right channel */
1716 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1717 if (v & 0x80) /* if already muted, we don't need to touch */
1718 continue;
1719 if (dmic_fixup) /* add mute for d-mic */
1720 v |= 0x80;
1721 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1722 parm | v);
1723 }
1724}
1725
1726static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol)
1728{
1729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1730 struct alc_spec *spec = codec->spec;
1731
1732 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1733 return 0;
1734}
1735
1736static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_value *ucontrol)
1738{
1739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1740 struct alc_spec *spec = codec->spec;
1741 unsigned int val = !ucontrol->value.integer.value[0];
1742
1743 if (val == spec->inv_dmic_muted)
1744 return 0;
1745 spec->inv_dmic_muted = val;
1746 alc_inv_dmic_sync(codec, true);
1747 return 0;
1748}
1749
1750static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1752 .info = snd_ctl_boolean_mono_info,
1753 .get = alc_inv_dmic_sw_get,
1754 .put = alc_inv_dmic_sw_put,
1755};
1756
1757static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1758{
1759 struct alc_spec *spec = codec->spec;
1760 struct snd_kcontrol_new *knew = alc_kcontrol_new(spec);
1761 if (!knew)
1762 return -ENOMEM;
1763 *knew = alc_inv_dmic_sw;
1764 knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL);
1765 if (!knew->name)
1766 return -ENOMEM;
1767 spec->inv_dmic_fixup = 1;
1768 spec->inv_dmic_muted = 0;
1769 spec->inv_dmic_pin = nid;
1770 return 0;
1771}
1772
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001773/* typically the digital mic is put at node 0x12 */
1774static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1775 const struct alc_fixup *fix, int action)
1776{
1777 if (action == ALC_FIXUP_ACT_PROBE)
1778 alc_add_inv_dmic_mixer(codec, 0x12);
1779}
1780
Takashi Iwai125821a2012-06-22 14:30:29 +02001781/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001782 * virtual master controls
1783 */
1784
1785/*
1786 * slave controls for virtual master
1787 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001788static const char * const alc_slave_pfxs[] = {
1789 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001790 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001791 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001792 NULL,
1793};
1794
1795/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001796 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001798
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001799#define NID_MAPPING (-1)
1800
1801#define SUBDEV_SPEAKER_ (0 << 6)
1802#define SUBDEV_HP_ (1 << 6)
1803#define SUBDEV_LINE_ (2 << 6)
1804#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1805#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1806#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1807
Takashi Iwai603c4012008-07-30 15:01:44 +02001808static void alc_free_kctls(struct hda_codec *codec);
1809
Takashi Iwai67d634c2009-11-16 15:35:59 +01001810#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001811/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001812static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001813 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001814 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001815 { } /* end */
1816};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001817#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001818
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001819static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820{
1821 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001822 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001823 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001824 int i, j, err;
1825 unsigned int u;
1826 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
1828 for (i = 0; i < spec->num_mixers; i++) {
1829 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1830 if (err < 0)
1831 return err;
1832 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001833 if (spec->cap_mixer) {
1834 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1835 if (err < 0)
1836 return err;
1837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001839 err = snd_hda_create_dig_out_ctls(codec,
1840 spec->multiout.dig_out_nid,
1841 spec->multiout.dig_out_nid,
1842 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 if (err < 0)
1844 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001845 if (!spec->no_analog) {
1846 err = snd_hda_create_spdif_share_sw(codec,
1847 &spec->multiout);
1848 if (err < 0)
1849 return err;
1850 spec->multiout.share_spdif = 1;
1851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 }
1853 if (spec->dig_in_nid) {
1854 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1855 if (err < 0)
1856 return err;
1857 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001858
Takashi Iwai67d634c2009-11-16 15:35:59 +01001859#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001860 /* create beep controls if needed */
1861 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001862 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001863 for (knew = alc_beep_mixer; knew->name; knew++) {
1864 struct snd_kcontrol *kctl;
1865 kctl = snd_ctl_new1(knew, codec);
1866 if (!kctl)
1867 return -ENOMEM;
1868 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001869 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001870 if (err < 0)
1871 return err;
1872 }
1873 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001874#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001875
Takashi Iwai2134ea42008-01-10 16:53:55 +01001876 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001877 if (!spec->no_analog &&
1878 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001879 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001880 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001881 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001882 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001883 vmaster_tlv, alc_slave_pfxs,
1884 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001885 if (err < 0)
1886 return err;
1887 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001888 if (!spec->no_analog &&
1889 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001890 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1891 NULL, alc_slave_pfxs,
1892 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001893 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001894 if (err < 0)
1895 return err;
1896 }
1897
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001898 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001899 if (spec->capsrc_nids || spec->adc_nids) {
1900 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1901 if (!kctl)
1902 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1903 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001904 err = snd_hda_add_nid(codec, kctl, i,
1905 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001906 if (err < 0)
1907 return err;
1908 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001909 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001910 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001911 const char *kname = kctl ? kctl->id.name : NULL;
1912 for (knew = spec->cap_mixer; knew->name; knew++) {
1913 if (kname && strcmp(knew->name, kname) == 0)
1914 continue;
1915 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1916 for (i = 0; kctl && i < kctl->count; i++) {
1917 err = snd_hda_add_nid(codec, kctl, i,
1918 spec->adc_nids[i]);
1919 if (err < 0)
1920 return err;
1921 }
1922 }
1923 }
1924
1925 /* other nid->control mapping */
1926 for (i = 0; i < spec->num_mixers; i++) {
1927 for (knew = spec->mixers[i]; knew->name; knew++) {
1928 if (knew->iface != NID_MAPPING)
1929 continue;
1930 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1931 if (kctl == NULL)
1932 continue;
1933 u = knew->subdevice;
1934 for (j = 0; j < 4; j++, u >>= 8) {
1935 nid = u & 0x3f;
1936 if (nid == 0)
1937 continue;
1938 switch (u & 0xc0) {
1939 case SUBDEV_SPEAKER_:
1940 nid = spec->autocfg.speaker_pins[nid];
1941 break;
1942 case SUBDEV_LINE_:
1943 nid = spec->autocfg.line_out_pins[nid];
1944 break;
1945 case SUBDEV_HP_:
1946 nid = spec->autocfg.hp_pins[nid];
1947 break;
1948 default:
1949 continue;
1950 }
1951 err = snd_hda_add_nid(codec, kctl, 0, nid);
1952 if (err < 0)
1953 return err;
1954 }
1955 u = knew->private_value;
1956 for (j = 0; j < 4; j++, u >>= 8) {
1957 nid = u & 0xff;
1958 if (nid == 0)
1959 continue;
1960 err = snd_hda_add_nid(codec, kctl, 0, nid);
1961 if (err < 0)
1962 return err;
1963 }
1964 }
1965 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001966
1967 alc_free_kctls(codec); /* no longer needed */
1968
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001969 return 0;
1970}
1971
David Henningsson5780b622012-06-27 18:45:45 +02001972static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001973{
1974 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001975
1976 if (spec->shared_mic_hp) {
1977 int err;
1978 int nid = spec->autocfg.inputs[1].pin;
1979 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1980 if (err < 0)
1981 return err;
1982 err = snd_hda_jack_detect_enable(codec, nid, 0);
1983 if (err < 0)
1984 return err;
1985 }
1986
1987 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1988}
1989
1990static int alc_build_controls(struct hda_codec *codec)
1991{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001992 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001993 if (err < 0)
1994 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001995
1996 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001997 if (err < 0)
1998 return err;
1999 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2000 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002003
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002005 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002006 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002007
Takashi Iwai584c0c42011-03-10 12:51:11 +01002008static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002009static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002010
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011static int alc_init(struct hda_codec *codec)
2012{
2013 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002014
Takashi Iwai546bb672012-03-07 08:37:19 +01002015 if (spec->init_hook)
2016 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002017
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002018 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002019 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002020
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002021 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002022 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002023 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002024
Takashi Iwai58701122011-01-13 15:41:45 +01002025 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2026
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002027 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 return 0;
2029}
2030
Takashi Iwai83012a72012-08-24 18:38:08 +02002031#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002032static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2033{
2034 struct alc_spec *spec = codec->spec;
2035 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2036}
2037#endif
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039/*
2040 * Analog playback callbacks
2041 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002042static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002044 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045{
2046 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002047 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2048 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002051static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 struct hda_codec *codec,
2053 unsigned int stream_tag,
2054 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002055 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056{
2057 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002058 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2059 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002062static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002064 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065{
2066 struct alc_spec *spec = codec->spec;
2067 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2068}
2069
2070/*
2071 * Digital out
2072 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002073static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002075 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
2077 struct alc_spec *spec = codec->spec;
2078 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2079}
2080
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002081static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002082 struct hda_codec *codec,
2083 unsigned int stream_tag,
2084 unsigned int format,
2085 struct snd_pcm_substream *substream)
2086{
2087 struct alc_spec *spec = codec->spec;
2088 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2089 stream_tag, format, substream);
2090}
2091
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002092static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002093 struct hda_codec *codec,
2094 struct snd_pcm_substream *substream)
2095{
2096 struct alc_spec *spec = codec->spec;
2097 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2098}
2099
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002100static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002102 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
2104 struct alc_spec *spec = codec->spec;
2105 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2106}
2107
2108/*
2109 * Analog capture
2110 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002111static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 struct hda_codec *codec,
2113 unsigned int stream_tag,
2114 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002115 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
2117 struct alc_spec *spec = codec->spec;
2118
Takashi Iwai63300792008-01-24 15:31:36 +01002119 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 stream_tag, 0, format);
2121 return 0;
2122}
2123
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002124static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002126 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127{
2128 struct alc_spec *spec = codec->spec;
2129
Takashi Iwai888afa12008-03-18 09:57:50 +01002130 snd_hda_codec_cleanup_stream(codec,
2131 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 return 0;
2133}
2134
Takashi Iwai840b64c2010-07-13 22:49:01 +02002135/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002136static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002137 struct hda_codec *codec,
2138 unsigned int stream_tag,
2139 unsigned int format,
2140 struct snd_pcm_substream *substream)
2141{
2142 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002143 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002144 spec->cur_adc_stream_tag = stream_tag;
2145 spec->cur_adc_format = format;
2146 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2147 return 0;
2148}
2149
Takashi Iwai21268962011-07-07 15:01:13 +02002150static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002151 struct hda_codec *codec,
2152 struct snd_pcm_substream *substream)
2153{
2154 struct alc_spec *spec = codec->spec;
2155 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2156 spec->cur_adc = 0;
2157 return 0;
2158}
2159
Takashi Iwai21268962011-07-07 15:01:13 +02002160static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002161 .substreams = 1,
2162 .channels_min = 2,
2163 .channels_max = 2,
2164 .nid = 0, /* fill later */
2165 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002166 .prepare = dyn_adc_capture_pcm_prepare,
2167 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002168 },
2169};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
2171/*
2172 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002173static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 .substreams = 1,
2175 .channels_min = 2,
2176 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002177 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002179 .open = alc_playback_pcm_open,
2180 .prepare = alc_playback_pcm_prepare,
2181 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 },
2183};
2184
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002185static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002186 .substreams = 1,
2187 .channels_min = 2,
2188 .channels_max = 2,
2189 /* NID is set in alc_build_pcms */
2190};
2191
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002192static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002193 .substreams = 1,
2194 .channels_min = 2,
2195 .channels_max = 2,
2196 /* NID is set in alc_build_pcms */
2197};
2198
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002199static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002200 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 .channels_min = 2,
2202 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002203 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002205 .prepare = alc_alt_capture_pcm_prepare,
2206 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 },
2208};
2209
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002210static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 .substreams = 1,
2212 .channels_min = 2,
2213 .channels_max = 2,
2214 /* NID is set in alc_build_pcms */
2215 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002216 .open = alc_dig_playback_pcm_open,
2217 .close = alc_dig_playback_pcm_close,
2218 .prepare = alc_dig_playback_pcm_prepare,
2219 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 },
2221};
2222
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002223static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 .substreams = 1,
2225 .channels_min = 2,
2226 .channels_max = 2,
2227 /* NID is set in alc_build_pcms */
2228};
2229
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002230/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002231static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002232 .substreams = 0,
2233 .channels_min = 0,
2234 .channels_max = 0,
2235};
2236
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237static int alc_build_pcms(struct hda_codec *codec)
2238{
2239 struct alc_spec *spec = codec->spec;
2240 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002241 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002242 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 int i;
2244
2245 codec->num_pcms = 1;
2246 codec->pcm_info = info;
2247
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002248 if (spec->no_analog)
2249 goto skip_analog;
2250
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002251 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2252 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002254
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002255 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002256 p = spec->stream_analog_playback;
2257 if (!p)
2258 p = &alc_pcm_analog_playback;
2259 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002260 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002261 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2262 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002263 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2264 spec->autocfg.line_outs == 2)
2265 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2266 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002267 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002268 if (spec->adc_nids) {
2269 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002270 if (!p) {
2271 if (spec->dyn_adc_switch)
2272 p = &dyn_adc_pcm_analog_capture;
2273 else
2274 p = &alc_pcm_analog_capture;
2275 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002276 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002277 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Takashi Iwai4a471b72005-12-07 13:56:29 +01002280 if (spec->channel_mode) {
2281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2282 for (i = 0; i < spec->num_channel_mode; i++) {
2283 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2284 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 }
2287 }
2288
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002289 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002290 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002292 snprintf(spec->stream_name_digital,
2293 sizeof(spec->stream_name_digital),
2294 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002295 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002296 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002297 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002299 if (spec->dig_out_type)
2300 info->pcm_type = spec->dig_out_type;
2301 else
2302 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002303 if (spec->multiout.dig_out_nid) {
2304 p = spec->stream_digital_playback;
2305 if (!p)
2306 p = &alc_pcm_digital_playback;
2307 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2309 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002310 if (spec->dig_in_nid) {
2311 p = spec->stream_digital_capture;
2312 if (!p)
2313 p = &alc_pcm_digital_capture;
2314 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2316 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002317 /* FIXME: do we need this for all Realtek codec models? */
2318 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002321 if (spec->no_analog)
2322 return 0;
2323
Takashi Iwaie08a0072006-09-07 17:52:14 +02002324 /* If the use of more than one ADC is requested for the current
2325 * model, configure a second analog capture-only PCM.
2326 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002327 have_multi_adcs = (spec->num_adc_nids > 1) &&
2328 !spec->dyn_adc_switch && !spec->auto_mic &&
2329 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002330 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002331 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002332 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002333 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002334 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002335 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002336 p = spec->stream_analog_alt_playback;
2337 if (!p)
2338 p = &alc_pcm_analog_alt_playback;
2339 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002340 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2341 spec->alt_dac_nid;
2342 } else {
2343 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2344 alc_pcm_null_stream;
2345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2346 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002347 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002348 p = spec->stream_analog_alt_capture;
2349 if (!p)
2350 p = &alc_pcm_analog_alt_capture;
2351 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002352 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2353 spec->adc_nids[1];
2354 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2355 spec->num_adc_nids - 1;
2356 } else {
2357 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2358 alc_pcm_null_stream;
2359 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002360 }
2361 }
2362
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 return 0;
2364}
2365
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002366static inline void alc_shutup(struct hda_codec *codec)
2367{
Takashi Iwai1c716152011-04-07 10:37:16 +02002368 struct alc_spec *spec = codec->spec;
2369
2370 if (spec && spec->shutup)
2371 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002372 snd_hda_shutup_pins(codec);
2373}
2374
Takashi Iwai603c4012008-07-30 15:01:44 +02002375static void alc_free_kctls(struct hda_codec *codec)
2376{
2377 struct alc_spec *spec = codec->spec;
2378
2379 if (spec->kctls.list) {
2380 struct snd_kcontrol_new *kctl = spec->kctls.list;
2381 int i;
2382 for (i = 0; i < spec->kctls.used; i++)
2383 kfree(kctl[i].name);
2384 }
2385 snd_array_free(&spec->kctls);
2386}
2387
Takashi Iwai23c09b02011-08-19 09:05:35 +02002388static void alc_free_bind_ctls(struct hda_codec *codec)
2389{
2390 struct alc_spec *spec = codec->spec;
2391 if (spec->bind_ctls.list) {
2392 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2393 int i;
2394 for (i = 0; i < spec->bind_ctls.used; i++)
2395 kfree(ctl[i]);
2396 }
2397 snd_array_free(&spec->bind_ctls);
2398}
2399
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400static void alc_free(struct hda_codec *codec)
2401{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002402 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002403
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002404 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002405 return;
2406
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002407 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002408 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002409 alc_free_bind_ctls(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002410 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002411 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002412 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413}
2414
Takashi Iwai83012a72012-08-24 18:38:08 +02002415#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002416static void alc_power_eapd(struct hda_codec *codec)
2417{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002418 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002419}
2420
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002421static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002422{
2423 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002424 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002425 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002426 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002427 return 0;
2428}
2429#endif
2430
Takashi Iwai2a439522011-07-26 09:52:50 +02002431#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002432static int alc_resume(struct hda_codec *codec)
2433{
Takashi Iwai1c716152011-04-07 10:37:16 +02002434 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002435 codec->patch_ops.init(codec);
2436 snd_hda_codec_resume_amp(codec);
2437 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002438 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002439 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002440 return 0;
2441}
Takashi Iwaie044c392008-10-27 16:56:24 +01002442#endif
2443
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444/*
2445 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002446static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 .build_controls = alc_build_controls,
2448 .build_pcms = alc_build_pcms,
2449 .init = alc_init,
2450 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002451 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002452#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002453 .resume = alc_resume,
2454#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002455#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002456 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002457 .check_power_status = alc_check_power_status,
2458#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002459 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460};
2461
David Henningsson29adc4b2012-09-25 11:31:00 +02002462
Kailang Yangc027ddc2010-03-19 11:33:06 +01002463/* replace the codec chip_name with the given string */
2464static int alc_codec_rename(struct hda_codec *codec, const char *name)
2465{
2466 kfree(codec->chip_name);
2467 codec->chip_name = kstrdup(name, GFP_KERNEL);
2468 if (!codec->chip_name) {
2469 alc_free(codec);
2470 return -ENOMEM;
2471 }
2472 return 0;
2473}
2474
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002475/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002476 * Rename codecs appropriately from COEF value
2477 */
2478struct alc_codec_rename_table {
2479 unsigned int vendor_id;
2480 unsigned short coef_mask;
2481 unsigned short coef_bits;
2482 const char *name;
2483};
2484
2485static struct alc_codec_rename_table rename_tbl[] = {
2486 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2487 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2488 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2489 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2490 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2491 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2492 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002493 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002494 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2495 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2496 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2497 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2498 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2499 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2500 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2501 { } /* terminator */
2502};
2503
2504static int alc_codec_rename_from_preset(struct hda_codec *codec)
2505{
2506 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002507
2508 for (p = rename_tbl; p->vendor_id; p++) {
2509 if (p->vendor_id != codec->vendor_id)
2510 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002511 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002512 return alc_codec_rename(codec, p->name);
2513 }
2514 return 0;
2515}
2516
2517/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002518 * Automatic parse of I/O pins from the BIOS configuration
2519 */
2520
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002521enum {
2522 ALC_CTL_WIDGET_VOL,
2523 ALC_CTL_WIDGET_MUTE,
2524 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002525 ALC_CTL_BIND_VOL,
2526 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002527};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002528static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002529 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2530 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002531 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002532 HDA_BIND_VOL(NULL, 0),
2533 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002534};
2535
2536/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002537static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002538 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002539{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002540 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002541
Takashi Iwaice764ab2011-04-27 16:35:23 +02002542 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002543 if (!knew)
2544 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002545 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002546 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002547 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002548 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002549 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002550 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002551 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002552 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002553 return 0;
2554}
2555
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002556static int add_control_with_pfx(struct alc_spec *spec, int type,
2557 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002558 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002559{
2560 char name[32];
2561 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002562 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002563}
2564
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002565#define add_pb_vol_ctrl(spec, type, pfx, val) \
2566 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2567#define add_pb_sw_ctrl(spec, type, pfx, val) \
2568 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2569#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2570 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2571#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2572 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002573
Takashi Iwai23c09b02011-08-19 09:05:35 +02002574static const char * const channel_name[4] = {
2575 "Front", "Surround", "CLFE", "Side"
2576};
2577
Takashi Iwai6843ca12011-06-24 11:03:58 +02002578static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2579 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002580{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002581 struct auto_pin_cfg *cfg = &spec->autocfg;
2582
Takashi Iwai6843ca12011-06-24 11:03:58 +02002583 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002584 if (cfg->line_outs == 1 && !spec->multi_ios &&
2585 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002586 return "Master";
2587
2588 switch (cfg->line_out_type) {
2589 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002590 if (cfg->line_outs == 1)
2591 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002592 if (cfg->line_outs == 2)
2593 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002594 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002595 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002596 /* for multi-io case, only the primary out */
2597 if (ch && spec->multi_ios)
2598 break;
2599 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002600 return "Headphone";
2601 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002602 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002603 return "PCM";
2604 break;
2605 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002606 if (ch >= ARRAY_SIZE(channel_name)) {
2607 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002608 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002609 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002610
2611 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002612}
2613
Takashi Iwai83012a72012-08-24 18:38:08 +02002614#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002615/* add the powersave loopback-list entry */
2616static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2617{
2618 struct hda_amp_list *list;
2619
2620 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2621 return;
2622 list = spec->loopback_list + spec->num_loopbacks;
2623 list->nid = mix;
2624 list->dir = HDA_INPUT;
2625 list->idx = idx;
2626 spec->num_loopbacks++;
2627 spec->loopback.amplist = spec->loopback_list;
2628}
2629#else
2630#define add_loopback_list(spec, mix, idx) /* NOP */
2631#endif
2632
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002633/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002634static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002635 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002636 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002637{
Kailang Yangdf694da2005-12-05 19:42:22 +01002638 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002639
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002640 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002641 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2642 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002643 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002644 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002645 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2646 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002647 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002648 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002649 return 0;
2650}
2651
Takashi Iwai05f5f472009-08-25 13:10:18 +02002652static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002653{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002654 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2655 return (pincap & AC_PINCAP_IN) != 0;
2656}
2657
Takashi Iwai1d045db2011-07-07 18:23:21 +02002658/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002659static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002660{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002661 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002662 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002663 hda_nid_t *adc_nids = spec->private_adc_nids;
2664 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2665 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002666 int i, nums = 0;
2667
2668 nid = codec->start_nid;
2669 for (i = 0; i < codec->num_nodes; i++, nid++) {
2670 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002671 unsigned int caps = get_wcaps(codec, nid);
2672 int type = get_wcaps_type(caps);
2673
2674 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2675 continue;
2676 adc_nids[nums] = nid;
2677 cap_nids[nums] = nid;
2678 src = nid;
2679 for (;;) {
2680 int n;
2681 type = get_wcaps_type(get_wcaps(codec, src));
2682 if (type == AC_WID_PIN)
2683 break;
2684 if (type == AC_WID_AUD_SEL) {
2685 cap_nids[nums] = src;
2686 break;
2687 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002688 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002689 if (n > 1) {
2690 cap_nids[nums] = src;
2691 break;
2692 } else if (n != 1)
2693 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002694 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2695 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002696 }
2697 if (++nums >= max_nums)
2698 break;
2699 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002700 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002701 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002702 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002703 return nums;
2704}
2705
Takashi Iwai05f5f472009-08-25 13:10:18 +02002706/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002707static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002708{
2709 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002710 const struct auto_pin_cfg *cfg = &spec->autocfg;
2711 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002712 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002713 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002714 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002715 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002716
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002717 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002718 if (num_adcs < 0)
2719 return 0;
2720
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002721 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002722 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002723 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002724
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002725 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002726 if (!alc_is_input_pin(codec, pin))
2727 continue;
2728
David Henningsson5322bf22011-01-05 11:03:56 +01002729 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002730 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2731 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002732 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002733 type_idx++;
2734 else
2735 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002736 prev_label = label;
2737
Takashi Iwai05f5f472009-08-25 13:10:18 +02002738 if (mixer) {
2739 idx = get_connection_index(codec, mixer, pin);
2740 if (idx >= 0) {
2741 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002742 label, type_idx,
2743 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002744 if (err < 0)
2745 return err;
2746 }
2747 }
2748
Takashi Iwaib7821702011-07-06 15:12:46 +02002749 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002750 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002751 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002752 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002753 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002754 snd_hda_add_imux_item(imux, label, idx, NULL);
2755 break;
2756 }
2757 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002758 }
Takashi Iwai21268962011-07-07 15:01:13 +02002759
2760 spec->num_mux_defs = 1;
2761 spec->input_mux = imux;
2762
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002763 return 0;
2764}
2765
Takashi Iwai24de1832011-11-07 17:13:39 +01002766/* create a shared input with the headphone out */
2767static int alc_auto_create_shared_input(struct hda_codec *codec)
2768{
2769 struct alc_spec *spec = codec->spec;
2770 struct auto_pin_cfg *cfg = &spec->autocfg;
2771 unsigned int defcfg;
2772 hda_nid_t nid;
2773
2774 /* only one internal input pin? */
2775 if (cfg->num_inputs != 1)
2776 return 0;
2777 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2778 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2779 return 0;
2780
2781 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2782 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2783 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2784 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2785 else
2786 return 0; /* both not available */
2787
2788 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2789 return 0; /* no input */
2790
2791 cfg->inputs[1].pin = nid;
2792 cfg->inputs[1].type = AUTO_PIN_MIC;
2793 cfg->num_inputs = 2;
2794 spec->shared_mic_hp = 1;
2795 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2796 return 0;
2797}
2798
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002799static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2800 unsigned int pin_type)
2801{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002802 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002803 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002804 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2805 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002806 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002807}
2808
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002809static int get_pin_type(int line_out_type)
2810{
2811 if (line_out_type == AUTO_PIN_HP_OUT)
2812 return PIN_HP;
2813 else
2814 return PIN_OUT;
2815}
2816
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002817static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002818{
2819 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002820 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002821 int i;
2822
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002823 for (i = 0; i < cfg->num_inputs; i++) {
2824 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002825 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002826 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002827 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002828 snd_hda_codec_write(codec, nid, 0,
2829 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002830 AMP_OUT_MUTE);
2831 }
2832 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002833
2834 /* mute all loopback inputs */
2835 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002836 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002837 for (i = 0; i < nums; i++)
2838 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2839 AC_VERB_SET_AMP_GAIN_MUTE,
2840 AMP_IN_MUTE(i));
2841 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002842}
2843
Takashi Iwai7085ec12009-10-02 09:03:58 +02002844/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002845static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002846{
Takashi Iwai604401a2011-04-27 15:14:23 +02002847 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002848 int i, num;
2849
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002850 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2851 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002852 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2853 for (i = 0; i < num; i++) {
2854 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2855 return list[i];
2856 }
2857 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002858}
2859
Takashi Iwai604401a2011-04-27 15:14:23 +02002860/* go down to the selector widget before the mixer */
2861static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2862{
2863 hda_nid_t srcs[5];
2864 int num = snd_hda_get_connections(codec, pin, srcs,
2865 ARRAY_SIZE(srcs));
2866 if (num != 1 ||
2867 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2868 return pin;
2869 return srcs[0];
2870}
2871
Takashi Iwai7085ec12009-10-02 09:03:58 +02002872/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002873static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002874 hda_nid_t dac)
2875{
David Henningssoncc1c4522010-11-24 14:17:47 +01002876 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002877 int i, num;
2878
Takashi Iwai604401a2011-04-27 15:14:23 +02002879 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002880 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2881 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002882 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002883 return mix[i];
2884 }
2885 return 0;
2886}
2887
Takashi Iwaice764ab2011-04-27 16:35:23 +02002888/* select the connection from pin to DAC if needed */
2889static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2890 hda_nid_t dac)
2891{
2892 hda_nid_t mix[5];
2893 int i, num;
2894
2895 pin = alc_go_down_to_selector(codec, pin);
2896 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2897 if (num < 2)
2898 return 0;
2899 for (i = 0; i < num; i++) {
2900 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2901 snd_hda_codec_update_cache(codec, pin, 0,
2902 AC_VERB_SET_CONNECT_SEL, i);
2903 return 0;
2904 }
2905 }
2906 return 0;
2907}
2908
Takashi Iwai185d99f2012-02-16 18:39:45 +01002909static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2910{
2911 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002912 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002913 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2914 ARRAY_SIZE(spec->private_dac_nids)) ||
2915 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2916 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2917 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2918 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2919 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002920 for (i = 0; i < spec->multi_ios; i++) {
2921 if (spec->multi_io[i].dac == nid)
2922 return true;
2923 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002924 return false;
2925}
2926
Takashi Iwai7085ec12009-10-02 09:03:58 +02002927/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002928static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002929{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002930 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002931 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002932
Takashi Iwai604401a2011-04-27 15:14:23 +02002933 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002934 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002935 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002936 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002937 if (!nid)
2938 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002939 if (!alc_is_dac_already_used(codec, nid))
2940 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002941 }
2942 return 0;
2943}
2944
Takashi Iwai07b18f62011-11-10 15:42:54 +01002945/* check whether the DAC is reachable from the pin */
2946static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2947 hda_nid_t pin, hda_nid_t dac)
2948{
2949 hda_nid_t srcs[5];
2950 int i, num;
2951
Takashi Iwaidc31b582012-02-17 17:27:53 +01002952 if (!pin || !dac)
2953 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002954 pin = alc_go_down_to_selector(codec, pin);
2955 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2956 for (i = 0; i < num; i++) {
2957 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2958 if (nid == dac)
2959 return true;
2960 }
2961 return false;
2962}
2963
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002964static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2965{
Takashi Iwai140547e2012-02-16 17:23:46 +01002966 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002967 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002968 hda_nid_t nid, nid_found, srcs[5];
2969 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01002970 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01002971 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002972 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002973 nid_found = 0;
2974 for (i = 0; i < num; i++) {
2975 if (srcs[i] == spec->mixer_nid)
2976 continue;
2977 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2978 if (nid && !alc_is_dac_already_used(codec, nid)) {
2979 if (nid_found)
2980 return 0;
2981 nid_found = nid;
2982 }
2983 }
2984 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002985}
2986
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002987/* mark up volume and mute control NIDs: used during badness parsing and
2988 * at creating actual controls
2989 */
2990static inline unsigned int get_ctl_pos(unsigned int data)
2991{
2992 hda_nid_t nid = get_amp_nid_(data);
2993 unsigned int dir;
2994 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
2995 return 0;
2996 dir = get_amp_direction_(data);
2997 return (nid << 1) | dir;
2998}
2999
3000#define is_ctl_used(bits, data) \
3001 test_bit(get_ctl_pos(data), bits)
3002#define mark_ctl_usage(bits, data) \
3003 set_bit(get_ctl_pos(data), bits)
3004
3005static void clear_vol_marks(struct hda_codec *codec)
3006{
3007 struct alc_spec *spec = codec->spec;
3008 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3009 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3010}
3011
3012/* badness definition */
3013enum {
3014 /* No primary DAC is found for the main output */
3015 BAD_NO_PRIMARY_DAC = 0x10000,
3016 /* No DAC is found for the extra output */
3017 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003018 /* No possible multi-ios */
3019 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003020 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003021 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003022 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003023 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003024 /* Primary DAC shared with main surrounds */
3025 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003026 /* Primary DAC shared with main CLFE */
3027 BAD_SHARED_CLFE = 0x10,
3028 /* Primary DAC shared with extra surrounds */
3029 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003030 /* Volume widget is shared */
3031 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003032};
3033
3034static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3035 hda_nid_t pin, hda_nid_t dac);
3036static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3037 hda_nid_t pin, hda_nid_t dac);
3038
3039static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3040 hda_nid_t dac)
3041{
3042 struct alc_spec *spec = codec->spec;
3043 hda_nid_t nid;
3044 unsigned int val;
3045 int badness = 0;
3046
3047 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3048 if (nid) {
3049 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3050 if (is_ctl_used(spec->vol_ctls, nid))
3051 badness += BAD_SHARED_VOL;
3052 else
3053 mark_ctl_usage(spec->vol_ctls, val);
3054 } else
3055 badness += BAD_SHARED_VOL;
3056 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3057 if (nid) {
3058 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3059 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3060 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3061 else
3062 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3063 if (is_ctl_used(spec->sw_ctls, val))
3064 badness += BAD_SHARED_VOL;
3065 else
3066 mark_ctl_usage(spec->sw_ctls, val);
3067 } else
3068 badness += BAD_SHARED_VOL;
3069 return badness;
3070}
3071
Takashi Iwaidc31b582012-02-17 17:27:53 +01003072struct badness_table {
3073 int no_primary_dac; /* no primary DAC */
3074 int no_dac; /* no secondary DACs */
3075 int shared_primary; /* primary DAC is shared with main output */
3076 int shared_surr; /* secondary DAC shared with main or primary */
3077 int shared_clfe; /* third DAC shared with main or primary */
3078 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3079};
3080
3081static struct badness_table main_out_badness = {
3082 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3083 .no_dac = BAD_NO_DAC,
3084 .shared_primary = BAD_NO_PRIMARY_DAC,
3085 .shared_surr = BAD_SHARED_SURROUND,
3086 .shared_clfe = BAD_SHARED_CLFE,
3087 .shared_surr_main = BAD_SHARED_SURROUND,
3088};
3089
3090static struct badness_table extra_out_badness = {
3091 .no_primary_dac = BAD_NO_DAC,
3092 .no_dac = BAD_NO_DAC,
3093 .shared_primary = BAD_NO_EXTRA_DAC,
3094 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3095 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3096 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3097};
3098
3099/* try to assign DACs to pins and return the resultant badness */
3100static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3101 const hda_nid_t *pins, hda_nid_t *dacs,
3102 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003103{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003104 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003105 struct auto_pin_cfg *cfg = &spec->autocfg;
3106 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003107 int badness = 0;
3108 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003109
Takashi Iwai185d99f2012-02-16 18:39:45 +01003110 if (!num_outs)
3111 return 0;
3112
Takashi Iwaidc31b582012-02-17 17:27:53 +01003113 for (i = 0; i < num_outs; i++) {
3114 hda_nid_t pin = pins[i];
3115 if (!dacs[i])
3116 dacs[i] = alc_auto_look_for_dac(codec, pin);
3117 if (!dacs[i] && !i) {
3118 for (j = 1; j < num_outs; j++) {
3119 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3120 dacs[0] = dacs[j];
3121 dacs[j] = 0;
3122 break;
3123 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003124 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003125 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003126 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003127 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003128 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003129 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003130 else if (cfg->line_outs > i &&
3131 alc_auto_is_dac_reachable(codec, pin,
3132 spec->private_dac_nids[i]))
3133 dac = spec->private_dac_nids[i];
3134 if (dac) {
3135 if (!i)
3136 badness += bad->shared_primary;
3137 else if (i == 1)
3138 badness += bad->shared_surr;
3139 else
3140 badness += bad->shared_clfe;
3141 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003142 spec->private_dac_nids[0])) {
3143 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003144 badness += bad->shared_surr_main;
3145 } else if (!i)
3146 badness += bad->no_primary_dac;
3147 else
3148 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003149 }
3150 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003151 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003152 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003153
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003154 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003155}
3156
3157static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003158 hda_nid_t reference_pin,
3159 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003160
Takashi Iwai185d99f2012-02-16 18:39:45 +01003161static bool alc_map_singles(struct hda_codec *codec, int outs,
3162 const hda_nid_t *pins, hda_nid_t *dacs)
3163{
3164 int i;
3165 bool found = false;
3166 for (i = 0; i < outs; i++) {
3167 if (dacs[i])
3168 continue;
3169 dacs[i] = get_dac_if_single(codec, pins[i]);
3170 if (dacs[i])
3171 found = true;
3172 }
3173 return found;
3174}
3175
Takashi Iwai7085ec12009-10-02 09:03:58 +02003176/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003177static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003178 bool fill_hardwired,
3179 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003180{
3181 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003182 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003183 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003184
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003185 /* set num_dacs once to full for alc_auto_look_for_dac() */
3186 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003187 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003188 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3189 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3190 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003191 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003192 clear_vol_marks(codec);
3193 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003194
3195 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003196 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003197 bool mapped;
3198 do {
3199 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003200 cfg->line_out_pins,
3201 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003202 mapped |= alc_map_singles(codec, cfg->hp_outs,
3203 cfg->hp_pins,
3204 spec->multiout.hp_out_nid);
3205 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3206 cfg->speaker_pins,
3207 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003208 if (fill_mio_first && cfg->line_outs == 1 &&
3209 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3210 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3211 if (!err)
3212 mapped = true;
3213 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003214 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003215 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003216
Takashi Iwaidc31b582012-02-17 17:27:53 +01003217 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3218 spec->private_dac_nids,
3219 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003220
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003221 /* re-count num_dacs and squash invalid entries */
3222 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003223 for (i = 0; i < cfg->line_outs; i++) {
3224 if (spec->private_dac_nids[i])
3225 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003226 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003227 memmove(spec->private_dac_nids + i,
3228 spec->private_dac_nids + i + 1,
3229 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003230 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3231 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003232 }
3233
Takashi Iwai276dd702012-02-17 16:17:03 +01003234 if (fill_mio_first &&
3235 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003236 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003237 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003238 if (err < 0)
3239 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003240 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003241 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003242
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003243 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003244 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3245 spec->multiout.hp_out_nid,
3246 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003247 if (err < 0)
3248 return err;
3249 badness += err;
3250 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003251 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003252 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3253 cfg->speaker_pins,
3254 spec->multiout.extra_out_nid,
3255 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003256 if (err < 0)
3257 return err;
3258 badness += err;
3259 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003260 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3261 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003262 if (err < 0)
3263 return err;
3264 badness += err;
3265 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003266 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3267 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003268 int offset = 0;
3269 if (cfg->line_outs >= 3)
3270 offset = 1;
3271 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3272 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003273 if (err < 0)
3274 return err;
3275 badness += err;
3276 }
3277
3278 if (spec->multi_ios == 2) {
3279 for (i = 0; i < 2; i++)
3280 spec->private_dac_nids[spec->multiout.num_dacs++] =
3281 spec->multi_io[i].dac;
3282 spec->ext_channel_count = 2;
3283 } else if (spec->multi_ios) {
3284 spec->multi_ios = 0;
3285 badness += BAD_MULTI_IO;
3286 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003287
3288 return badness;
3289}
3290
3291#define DEBUG_BADNESS
3292
3293#ifdef DEBUG_BADNESS
3294#define debug_badness snd_printdd
3295#else
3296#define debug_badness(...)
3297#endif
3298
3299static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3300{
3301 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3302 cfg->line_out_pins[0], cfg->line_out_pins[1],
3303 cfg->line_out_pins[2], cfg->line_out_pins[2],
3304 spec->multiout.dac_nids[0],
3305 spec->multiout.dac_nids[1],
3306 spec->multiout.dac_nids[2],
3307 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003308 if (spec->multi_ios > 0)
3309 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3310 spec->multi_ios,
3311 spec->multi_io[0].pin, spec->multi_io[1].pin,
3312 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003313 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3314 cfg->hp_pins[0], cfg->hp_pins[1],
3315 cfg->hp_pins[2], cfg->hp_pins[2],
3316 spec->multiout.hp_out_nid[0],
3317 spec->multiout.hp_out_nid[1],
3318 spec->multiout.hp_out_nid[2],
3319 spec->multiout.hp_out_nid[3]);
3320 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3321 cfg->speaker_pins[0], cfg->speaker_pins[1],
3322 cfg->speaker_pins[2], cfg->speaker_pins[3],
3323 spec->multiout.extra_out_nid[0],
3324 spec->multiout.extra_out_nid[1],
3325 spec->multiout.extra_out_nid[2],
3326 spec->multiout.extra_out_nid[3]);
3327}
3328
3329static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3330{
3331 struct alc_spec *spec = codec->spec;
3332 struct auto_pin_cfg *cfg = &spec->autocfg;
3333 struct auto_pin_cfg *best_cfg;
3334 int best_badness = INT_MAX;
3335 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003336 bool fill_hardwired = true, fill_mio_first = true;
3337 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003338 bool hp_spk_swapped = false;
3339
3340 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3341 if (!best_cfg)
3342 return -ENOMEM;
3343 *best_cfg = *cfg;
3344
3345 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003346 badness = fill_and_eval_dacs(codec, fill_hardwired,
3347 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003348 if (badness < 0) {
3349 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003350 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003351 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003352 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3353 cfg->line_out_type, fill_hardwired, fill_mio_first,
3354 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003355 debug_show_configs(spec, cfg);
3356 if (badness < best_badness) {
3357 best_badness = badness;
3358 *best_cfg = *cfg;
3359 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003360 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003361 }
3362 if (!badness)
3363 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003364 fill_mio_first = !fill_mio_first;
3365 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003366 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003367 fill_hardwired = !fill_hardwired;
3368 if (!fill_hardwired)
3369 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003370 if (hp_spk_swapped)
3371 break;
3372 hp_spk_swapped = true;
3373 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003374 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3375 cfg->hp_outs = cfg->line_outs;
3376 memcpy(cfg->hp_pins, cfg->line_out_pins,
3377 sizeof(cfg->hp_pins));
3378 cfg->line_outs = cfg->speaker_outs;
3379 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3380 sizeof(cfg->speaker_pins));
3381 cfg->speaker_outs = 0;
3382 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3383 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003384 fill_hardwired = true;
3385 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003386 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003387 if (cfg->hp_outs > 0 &&
3388 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3389 cfg->speaker_outs = cfg->line_outs;
3390 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3391 sizeof(cfg->speaker_pins));
3392 cfg->line_outs = cfg->hp_outs;
3393 memcpy(cfg->line_out_pins, cfg->hp_pins,
3394 sizeof(cfg->hp_pins));
3395 cfg->hp_outs = 0;
3396 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3397 cfg->line_out_type = AUTO_PIN_HP_OUT;
3398 fill_hardwired = true;
3399 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003400 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003401 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003402 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003403
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003404 if (badness) {
3405 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003406 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003407 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003408 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3409 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003410 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003411
David Henningssonfde48a12011-12-09 18:27:42 +08003412 if (cfg->line_out_pins[0])
3413 spec->vmaster_nid =
3414 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3415 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003416
3417 /* clear the bitmap flags for creating controls */
3418 clear_vol_marks(codec);
3419 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003420 return 0;
3421}
3422
Takashi Iwai343a04b2011-07-06 14:28:39 +02003423static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003424 const char *pfx, int cidx,
3425 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003426{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003427 struct alc_spec *spec = codec->spec;
3428 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003429 if (!nid)
3430 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003431 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3432 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3433 return 0;
3434 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003435 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003436 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003437}
3438
Takashi Iwaie29d3772011-11-14 17:13:23 +01003439static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3440 const char *pfx, int cidx,
3441 hda_nid_t nid)
3442{
3443 int chs = 1;
3444 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3445 chs = 3;
3446 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3447}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003448
3449/* create a mute-switch for the given mixer widget;
3450 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3451 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003452static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003453 const char *pfx, int cidx,
3454 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003455{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003456 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003457 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003458 int type;
3459 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003460 if (!nid)
3461 return 0;
3462 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3463 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3464 type = ALC_CTL_WIDGET_MUTE;
3465 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003466 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003467 type = ALC_CTL_WIDGET_MUTE;
3468 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3469 } else {
3470 type = ALC_CTL_BIND_MUTE;
3471 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3472 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003473 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3474 return 0;
3475 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003476 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003477}
3478
Takashi Iwaie29d3772011-11-14 17:13:23 +01003479static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3480 int cidx, hda_nid_t nid)
3481{
3482 int chs = 1;
3483 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3484 chs = 3;
3485 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3486}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003487
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003488static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3489 hda_nid_t pin, hda_nid_t dac)
3490{
3491 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3492 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3493 return pin;
3494 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3495 return mix;
3496 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3497 return dac;
3498 return 0;
3499}
3500
3501static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3502 hda_nid_t pin, hda_nid_t dac)
3503{
3504 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3505 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3506 return dac;
3507 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3508 return mix;
3509 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3510 return pin;
3511 return 0;
3512}
3513
Takashi Iwai7085ec12009-10-02 09:03:58 +02003514/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003515static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003516 const struct auto_pin_cfg *cfg)
3517{
3518 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003519 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003520
Takashi Iwaice764ab2011-04-27 16:35:23 +02003521 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003522 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003523 noutputs += spec->multi_ios;
3524
3525 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003526 const char *name;
3527 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003528 hda_nid_t dac, pin;
3529 hda_nid_t sw, vol;
3530
3531 dac = spec->multiout.dac_nids[i];
3532 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003533 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003534 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003535 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003536 index = 0;
3537 name = channel_name[i];
3538 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003539 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003540 name = alc_get_line_out_pfx(spec, i, true, &index);
3541 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003542
3543 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3544 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003545 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003546 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003547 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003548 if (err < 0)
3549 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003550 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003551 if (err < 0)
3552 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003553 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003554 if (err < 0)
3555 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003556 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003557 if (err < 0)
3558 return err;
3559 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003560 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003561 if (err < 0)
3562 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003563 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003564 if (err < 0)
3565 return err;
3566 }
3567 }
3568 return 0;
3569}
3570
Takashi Iwai343a04b2011-07-06 14:28:39 +02003571static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003572 hda_nid_t dac, const char *pfx,
3573 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003574{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003575 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003576 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003577 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003578
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003579 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003580 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003581 /* the corresponding DAC is already occupied */
3582 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3583 return 0; /* no way */
3584 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003585 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3586 if (is_ctl_used(spec->sw_ctls, val))
3587 return 0; /* already created */
3588 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003589 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003590 }
3591
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003592 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3593 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003594 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003595 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003596 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003597 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003598 if (err < 0)
3599 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003600 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003601}
3602
Takashi Iwai23c09b02011-08-19 09:05:35 +02003603static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3604 unsigned int nums,
3605 struct hda_ctl_ops *ops)
3606{
3607 struct alc_spec *spec = codec->spec;
3608 struct hda_bind_ctls **ctlp, *ctl;
3609 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3610 ctlp = snd_array_new(&spec->bind_ctls);
3611 if (!ctlp)
3612 return NULL;
3613 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3614 *ctlp = ctl;
3615 if (ctl)
3616 ctl->ops = ops;
3617 return ctl;
3618}
3619
3620/* add playback controls for speaker and HP outputs */
3621static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3622 const hda_nid_t *pins,
3623 const hda_nid_t *dacs,
3624 const char *pfx)
3625{
3626 struct alc_spec *spec = codec->spec;
3627 struct hda_bind_ctls *ctl;
3628 char name[32];
3629 int i, n, err;
3630
3631 if (!num_pins || !pins[0])
3632 return 0;
3633
Takashi Iwai527e4d72011-10-27 16:33:27 +02003634 if (num_pins == 1) {
3635 hda_nid_t dac = *dacs;
3636 if (!dac)
3637 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003638 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003639 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003640
Takashi Iwai23c09b02011-08-19 09:05:35 +02003641 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003642 hda_nid_t dac;
3643 if (dacs[num_pins - 1])
3644 dac = dacs[i]; /* with individual volumes */
3645 else
3646 dac = 0;
3647 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3648 err = alc_auto_create_extra_out(codec, pins[i], dac,
3649 "Bass Speaker", 0);
3650 } else if (num_pins >= 3) {
3651 snprintf(name, sizeof(name), "%s %s",
3652 pfx, channel_name[i]);
3653 err = alc_auto_create_extra_out(codec, pins[i], dac,
3654 name, 0);
3655 } else {
3656 err = alc_auto_create_extra_out(codec, pins[i], dac,
3657 pfx, i);
3658 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003659 if (err < 0)
3660 return err;
3661 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003662 if (dacs[num_pins - 1])
3663 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003664
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003665 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003666 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3667 if (!ctl)
3668 return -ENOMEM;
3669 n = 0;
3670 for (i = 0; i < num_pins; i++) {
3671 hda_nid_t vol;
3672 if (!pins[i] || !dacs[i])
3673 continue;
3674 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3675 if (vol)
3676 ctl->values[n++] =
3677 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3678 }
3679 if (n) {
3680 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3681 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3682 if (err < 0)
3683 return err;
3684 }
3685 return 0;
3686}
3687
Takashi Iwai343a04b2011-07-06 14:28:39 +02003688static int alc_auto_create_hp_out(struct hda_codec *codec)
3689{
3690 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003691 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3692 spec->autocfg.hp_pins,
3693 spec->multiout.hp_out_nid,
3694 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003695}
3696
3697static int alc_auto_create_speaker_out(struct hda_codec *codec)
3698{
3699 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003700 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3701 spec->autocfg.speaker_pins,
3702 spec->multiout.extra_out_nid,
3703 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003704}
3705
Takashi Iwai343a04b2011-07-06 14:28:39 +02003706static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003707 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003708 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003709{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003710 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003711 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003712 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003713
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003714 alc_set_pin_output(codec, pin, pin_type);
3715 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003716 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003717 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003718 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003719 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003720 mix = srcs[i];
3721 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003722 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003723 if (!mix)
3724 return;
3725
3726 /* need the manual connection? */
3727 if (num > 1)
3728 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3729 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003730 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3731 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003732 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003733 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003734 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003735 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003736 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003737 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3738 if (nid)
3739 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3740 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003741
3742 /* unmute DAC if it's not assigned to a mixer */
3743 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3744 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3745 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3746 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003747}
3748
Takashi Iwai343a04b2011-07-06 14:28:39 +02003749static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003750{
3751 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003752 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003753 int i;
3754
3755 for (i = 0; i <= HDA_SIDE; i++) {
3756 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3757 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003758 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003759 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003760 }
3761}
3762
Takashi Iwai343a04b2011-07-06 14:28:39 +02003763static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003764{
3765 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003766 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003767 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003768
David Henningsson636030e2011-10-12 19:26:03 +02003769 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003770 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3771 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003772 pin = spec->autocfg.hp_pins[i];
3773 if (!pin)
3774 break;
3775 dac = spec->multiout.hp_out_nid[i];
3776 if (!dac) {
3777 if (i > 0 && spec->multiout.hp_out_nid[0])
3778 dac = spec->multiout.hp_out_nid[0];
3779 else
3780 dac = spec->multiout.dac_nids[0];
3781 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003782 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3783 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003784 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003785 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3786 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003787 pin = spec->autocfg.speaker_pins[i];
3788 if (!pin)
3789 break;
3790 dac = spec->multiout.extra_out_nid[i];
3791 if (!dac) {
3792 if (i > 0 && spec->multiout.extra_out_nid[0])
3793 dac = spec->multiout.extra_out_nid[0];
3794 else
3795 dac = spec->multiout.dac_nids[0];
3796 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003797 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3798 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003799}
3800
Takashi Iwai276dd702012-02-17 16:17:03 +01003801/* check whether the given pin can be a multi-io pin */
3802static bool can_be_multiio_pin(struct hda_codec *codec,
3803 unsigned int location, hda_nid_t nid)
3804{
3805 unsigned int defcfg, caps;
3806
3807 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3808 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3809 return false;
3810 if (location && get_defcfg_location(defcfg) != location)
3811 return false;
3812 caps = snd_hda_query_pin_caps(codec, nid);
3813 if (!(caps & AC_PINCAP_OUT))
3814 return false;
3815 return true;
3816}
3817
Takashi Iwaice764ab2011-04-27 16:35:23 +02003818/*
3819 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003820 *
3821 * When hardwired is set, try to fill ony hardwired pins, and returns
3822 * zero if any pins are filled, non-zero if nothing found.
3823 * When hardwired is off, try to fill possible input pins, and returns
3824 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003825 */
3826static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003827 hda_nid_t reference_pin,
3828 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003829{
3830 struct alc_spec *spec = codec->spec;
3831 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003832 int type, i, j, dacs, num_pins, old_pins;
3833 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3834 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003835 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003836
Takashi Iwai276dd702012-02-17 16:17:03 +01003837 old_pins = spec->multi_ios;
3838 if (old_pins >= 2)
3839 goto end_fill;
3840
3841 num_pins = 0;
3842 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3843 for (i = 0; i < cfg->num_inputs; i++) {
3844 if (cfg->inputs[i].type != type)
3845 continue;
3846 if (can_be_multiio_pin(codec, location,
3847 cfg->inputs[i].pin))
3848 num_pins++;
3849 }
3850 }
3851 if (num_pins < 2)
3852 goto end_fill;
3853
Takashi Iwai07b18f62011-11-10 15:42:54 +01003854 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003855 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3856 for (i = 0; i < cfg->num_inputs; i++) {
3857 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003858 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003859
Takashi Iwaice764ab2011-04-27 16:35:23 +02003860 if (cfg->inputs[i].type != type)
3861 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003862 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003863 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003864 for (j = 0; j < spec->multi_ios; j++) {
3865 if (nid == spec->multi_io[j].pin)
3866 break;
3867 }
3868 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003869 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003870
3871 if (offset && offset + spec->multi_ios < dacs) {
3872 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003873 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3874 dac = 0;
3875 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003876 if (hardwired)
3877 dac = get_dac_if_single(codec, nid);
3878 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003879 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003880 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003881 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003882 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003883 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003884 spec->multi_io[spec->multi_ios].pin = nid;
3885 spec->multi_io[spec->multi_ios].dac = dac;
3886 spec->multi_ios++;
3887 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003888 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003889 }
3890 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003891 end_fill:
3892 if (badness)
3893 badness = BAD_MULTI_IO;
3894 if (old_pins == spec->multi_ios) {
3895 if (hardwired)
3896 return 1; /* nothing found */
3897 else
3898 return badness; /* no badness if nothing found */
3899 }
3900 if (!hardwired && spec->multi_ios < 2) {
3901 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003902 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003903 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003904
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003905 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003906}
3907
3908static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3909 struct snd_ctl_elem_info *uinfo)
3910{
3911 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3912 struct alc_spec *spec = codec->spec;
3913
3914 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3915 uinfo->count = 1;
3916 uinfo->value.enumerated.items = spec->multi_ios + 1;
3917 if (uinfo->value.enumerated.item > spec->multi_ios)
3918 uinfo->value.enumerated.item = spec->multi_ios;
3919 sprintf(uinfo->value.enumerated.name, "%dch",
3920 (uinfo->value.enumerated.item + 1) * 2);
3921 return 0;
3922}
3923
3924static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3925 struct snd_ctl_elem_value *ucontrol)
3926{
3927 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3928 struct alc_spec *spec = codec->spec;
3929 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3930 return 0;
3931}
3932
3933static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3934{
3935 struct alc_spec *spec = codec->spec;
3936 hda_nid_t nid = spec->multi_io[idx].pin;
3937
3938 if (!spec->multi_io[idx].ctl_in)
3939 spec->multi_io[idx].ctl_in =
3940 snd_hda_codec_read(codec, nid, 0,
3941 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3942 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003943 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003944 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3945 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3946 HDA_AMP_MUTE, 0);
3947 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3948 } else {
3949 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3950 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3951 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003952 snd_hda_set_pin_ctl_cache(codec, nid,
3953 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003954 }
3955 return 0;
3956}
3957
3958static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3959 struct snd_ctl_elem_value *ucontrol)
3960{
3961 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3962 struct alc_spec *spec = codec->spec;
3963 int i, ch;
3964
3965 ch = ucontrol->value.enumerated.item[0];
3966 if (ch < 0 || ch > spec->multi_ios)
3967 return -EINVAL;
3968 if (ch == (spec->ext_channel_count - 1) / 2)
3969 return 0;
3970 spec->ext_channel_count = (ch + 1) * 2;
3971 for (i = 0; i < spec->multi_ios; i++)
3972 alc_set_multi_io(codec, i, i < ch);
3973 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003974 if (spec->need_dac_fix && !spec->const_channel_count)
3975 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003976 return 1;
3977}
3978
Takashi Iwaia9111322011-05-02 11:30:18 +02003979static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003980 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3981 .name = "Channel Mode",
3982 .info = alc_auto_ch_mode_info,
3983 .get = alc_auto_ch_mode_get,
3984 .put = alc_auto_ch_mode_put,
3985};
3986
Takashi Iwai23c09b02011-08-19 09:05:35 +02003987static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003988{
3989 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003990
Takashi Iwaic2674682011-08-24 17:57:44 +02003991 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003992 struct snd_kcontrol_new *knew;
3993
3994 knew = alc_kcontrol_new(spec);
3995 if (!knew)
3996 return -ENOMEM;
3997 *knew = alc_auto_channel_mode_enum;
3998 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3999 if (!knew->name)
4000 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004001 }
4002 return 0;
4003}
4004
Takashi Iwai1d045db2011-07-07 18:23:21 +02004005/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4006 * active input pins
4007 */
4008static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4009{
4010 struct alc_spec *spec = codec->spec;
4011 const struct hda_input_mux *imux;
4012 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4013 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4014 int i, n, nums;
4015
4016 imux = spec->input_mux;
4017 if (!imux)
4018 return;
4019 if (spec->dyn_adc_switch)
4020 return;
4021
Takashi Iwai26acaf02012-03-22 14:36:50 +01004022 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004023 nums = 0;
4024 for (n = 0; n < spec->num_adc_nids; n++) {
4025 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004026 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004027 for (i = 0; i < imux->num_items; i++) {
4028 hda_nid_t pin = spec->imux_pins[i];
4029 if (pin) {
4030 if (get_connection_index(codec, cap, pin) < 0)
4031 break;
4032 } else if (num_conns <= imux->items[i].index)
4033 break;
4034 }
4035 if (i >= imux->num_items) {
4036 adc_nids[nums] = spec->private_adc_nids[n];
4037 capsrc_nids[nums++] = cap;
4038 }
4039 }
4040 if (!nums) {
4041 /* check whether ADC-switch is possible */
4042 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004043 if (spec->shared_mic_hp) {
4044 spec->shared_mic_hp = 0;
4045 spec->private_imux[0].num_items = 1;
4046 goto again;
4047 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004048 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4049 " using fallback 0x%x\n",
4050 codec->chip_name, spec->private_adc_nids[0]);
4051 spec->num_adc_nids = 1;
4052 spec->auto_mic = 0;
4053 return;
4054 }
4055 } else if (nums != spec->num_adc_nids) {
4056 memcpy(spec->private_adc_nids, adc_nids,
4057 nums * sizeof(hda_nid_t));
4058 memcpy(spec->private_capsrc_nids, capsrc_nids,
4059 nums * sizeof(hda_nid_t));
4060 spec->num_adc_nids = nums;
4061 }
4062
4063 if (spec->auto_mic)
4064 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004065 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004066 spec->num_adc_nids = 1; /* reduce to a single ADC */
4067}
4068
4069/*
4070 * initialize ADC paths
4071 */
4072static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4073{
4074 struct alc_spec *spec = codec->spec;
4075 hda_nid_t nid;
4076
4077 nid = spec->adc_nids[adc_idx];
4078 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004079 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004080 snd_hda_codec_write(codec, nid, 0,
4081 AC_VERB_SET_AMP_GAIN_MUTE,
4082 AMP_IN_MUTE(0));
4083 return;
4084 }
4085 if (!spec->capsrc_nids)
4086 return;
4087 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004088 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004089 snd_hda_codec_write(codec, nid, 0,
4090 AC_VERB_SET_AMP_GAIN_MUTE,
4091 AMP_OUT_MUTE);
4092}
4093
4094static void alc_auto_init_input_src(struct hda_codec *codec)
4095{
4096 struct alc_spec *spec = codec->spec;
4097 int c, nums;
4098
4099 for (c = 0; c < spec->num_adc_nids; c++)
4100 alc_auto_init_adc(codec, c);
4101 if (spec->dyn_adc_switch)
4102 nums = 1;
4103 else
4104 nums = spec->num_adc_nids;
4105 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004106 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004107}
4108
4109/* add mic boosts if needed */
4110static int alc_auto_add_mic_boost(struct hda_codec *codec)
4111{
4112 struct alc_spec *spec = codec->spec;
4113 struct auto_pin_cfg *cfg = &spec->autocfg;
4114 int i, err;
4115 int type_idx = 0;
4116 hda_nid_t nid;
4117 const char *prev_label = NULL;
4118
4119 for (i = 0; i < cfg->num_inputs; i++) {
4120 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4121 break;
4122 nid = cfg->inputs[i].pin;
4123 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4124 const char *label;
4125 char boost_label[32];
4126
4127 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004128 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4129 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004130 if (prev_label && !strcmp(label, prev_label))
4131 type_idx++;
4132 else
4133 type_idx = 0;
4134 prev_label = label;
4135
4136 snprintf(boost_label, sizeof(boost_label),
4137 "%s Boost Volume", label);
4138 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4139 boost_label, type_idx,
4140 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4141 if (err < 0)
4142 return err;
4143 }
4144 }
4145 return 0;
4146}
4147
4148/* select or unmute the given capsrc route */
4149static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4150 int idx)
4151{
4152 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4153 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4154 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004155 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004156 snd_hda_codec_write_cache(codec, cap, 0,
4157 AC_VERB_SET_CONNECT_SEL, idx);
4158 }
4159}
4160
4161/* set the default connection to that pin */
4162static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4163{
4164 struct alc_spec *spec = codec->spec;
4165 int i;
4166
4167 if (!pin)
4168 return 0;
4169 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004170 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004171 int idx;
4172
4173 idx = get_connection_index(codec, cap, pin);
4174 if (idx < 0)
4175 continue;
4176 select_or_unmute_capsrc(codec, cap, idx);
4177 return i; /* return the found index */
4178 }
4179 return -1; /* not found */
4180}
4181
4182/* initialize some special cases for input sources */
4183static void alc_init_special_input_src(struct hda_codec *codec)
4184{
4185 struct alc_spec *spec = codec->spec;
4186 int i;
4187
4188 for (i = 0; i < spec->autocfg.num_inputs; i++)
4189 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4190}
4191
4192/* assign appropriate capture mixers */
4193static void set_capture_mixer(struct hda_codec *codec)
4194{
4195 struct alc_spec *spec = codec->spec;
4196 static const struct snd_kcontrol_new *caps[2][3] = {
4197 { alc_capture_mixer_nosrc1,
4198 alc_capture_mixer_nosrc2,
4199 alc_capture_mixer_nosrc3 },
4200 { alc_capture_mixer1,
4201 alc_capture_mixer2,
4202 alc_capture_mixer3 },
4203 };
4204
4205 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004206 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004207 if (!spec->capsrc_nids)
4208 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004209 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004210 return; /* no volume in capsrc, too */
4211 spec->vol_in_capsrc = 1;
4212 }
4213
4214 if (spec->num_adc_nids > 0) {
4215 int mux = 0;
4216 int num_adcs = 0;
4217
4218 if (spec->input_mux && spec->input_mux->num_items > 1)
4219 mux = 1;
4220 if (spec->auto_mic) {
4221 num_adcs = 1;
4222 mux = 0;
4223 } else if (spec->dyn_adc_switch)
4224 num_adcs = 1;
4225 if (!num_adcs) {
4226 if (spec->num_adc_nids > 3)
4227 spec->num_adc_nids = 3;
4228 else if (!spec->num_adc_nids)
4229 return;
4230 num_adcs = spec->num_adc_nids;
4231 }
4232 spec->cap_mixer = caps[mux][num_adcs - 1];
4233 }
4234}
4235
4236/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004237 * standard auto-parser initializations
4238 */
4239static void alc_auto_init_std(struct hda_codec *codec)
4240{
Takashi Iwaie4770622011-07-08 11:11:35 +02004241 alc_auto_init_multi_out(codec);
4242 alc_auto_init_extra_out(codec);
4243 alc_auto_init_analog_input(codec);
4244 alc_auto_init_input_src(codec);
4245 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004246 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004247}
4248
4249/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004250 * Digital-beep handlers
4251 */
4252#ifdef CONFIG_SND_HDA_INPUT_BEEP
4253#define set_beep_amp(spec, nid, idx, dir) \
4254 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4255
4256static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004257 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004258 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4259 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4260 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4261 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004262 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004263 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4264 {}
4265};
4266
4267static inline int has_cdefine_beep(struct hda_codec *codec)
4268{
4269 struct alc_spec *spec = codec->spec;
4270 const struct snd_pci_quirk *q;
4271 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4272 if (q)
4273 return q->value;
4274 return spec->cdefine.enable_pcbeep;
4275}
4276#else
4277#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4278#define has_cdefine_beep(codec) 0
4279#endif
4280
4281/* parse the BIOS configuration and set up the alc_spec */
4282/* return 1 if successful, 0 if the proper config is not found,
4283 * or a negative error code
4284 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004285static int alc_parse_auto_config(struct hda_codec *codec,
4286 const hda_nid_t *ignore_nids,
4287 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004288{
4289 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004290 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004291 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004292
Takashi Iwai53c334a2011-08-23 18:27:14 +02004293 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4294 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004295 if (err < 0)
4296 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004297 if (!cfg->line_outs) {
4298 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004299 spec->multiout.max_channels = 2;
4300 spec->no_analog = 1;
4301 goto dig_only;
4302 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004303 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004304 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004305
Takashi Iwaie427c232012-07-29 10:04:08 +02004306 if (!spec->no_primary_hp &&
4307 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004308 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004309 /* use HP as primary out */
4310 cfg->speaker_outs = cfg->line_outs;
4311 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4312 sizeof(cfg->speaker_pins));
4313 cfg->line_outs = cfg->hp_outs;
4314 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4315 cfg->hp_outs = 0;
4316 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4317 cfg->line_out_type = AUTO_PIN_HP_OUT;
4318 }
4319
Takashi Iwai1d045db2011-07-07 18:23:21 +02004320 err = alc_auto_fill_dac_nids(codec);
4321 if (err < 0)
4322 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004323 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004324 if (err < 0)
4325 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004326 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004327 if (err < 0)
4328 return err;
4329 err = alc_auto_create_hp_out(codec);
4330 if (err < 0)
4331 return err;
4332 err = alc_auto_create_speaker_out(codec);
4333 if (err < 0)
4334 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004335 err = alc_auto_create_shared_input(codec);
4336 if (err < 0)
4337 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004338 err = alc_auto_create_input_ctls(codec);
4339 if (err < 0)
4340 return err;
4341
4342 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4343
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004344 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004345 alc_auto_parse_digital(codec);
4346
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004347 if (!spec->no_analog)
4348 alc_remove_invalid_adc_nids(codec);
4349
4350 if (ssid_nids)
4351 alc_ssid_check(codec, ssid_nids);
4352
4353 if (!spec->no_analog) {
4354 alc_auto_check_switches(codec);
4355 err = alc_auto_add_mic_boost(codec);
4356 if (err < 0)
4357 return err;
4358 }
4359
Takashi Iwai1d045db2011-07-07 18:23:21 +02004360 if (spec->kctls.list)
4361 add_mixer(spec, spec->kctls.list);
4362
Takashi Iwai070cff42012-02-21 12:54:17 +01004363 if (!spec->no_analog && !spec->cap_mixer)
4364 set_capture_mixer(codec);
4365
Takashi Iwai1d045db2011-07-07 18:23:21 +02004366 return 1;
4367}
4368
Takashi Iwai3de95172012-05-07 18:03:15 +02004369/* common preparation job for alc_spec */
4370static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4371{
4372 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4373 int err;
4374
4375 if (!spec)
4376 return -ENOMEM;
4377 codec->spec = spec;
4378 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004379 snd_hda_gen_init(&spec->gen);
Takashi Iwai3de95172012-05-07 18:03:15 +02004380
4381 err = alc_codec_rename_from_preset(codec);
4382 if (err < 0) {
4383 kfree(spec);
4384 return err;
4385 }
4386 return 0;
4387}
4388
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004389static int alc880_parse_auto_config(struct hda_codec *codec)
4390{
4391 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004392 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004393 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4394}
4395
Takashi Iwai1d045db2011-07-07 18:23:21 +02004396/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004397 * ALC880 fix-ups
4398 */
4399enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004400 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004401 ALC880_FIXUP_GPIO2,
4402 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004403 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004404 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004405 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004406 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004407 ALC880_FIXUP_VOL_KNOB,
4408 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004409 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004410 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004411 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004412 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004413 ALC880_FIXUP_3ST_BASE,
4414 ALC880_FIXUP_3ST,
4415 ALC880_FIXUP_3ST_DIG,
4416 ALC880_FIXUP_5ST_BASE,
4417 ALC880_FIXUP_5ST,
4418 ALC880_FIXUP_5ST_DIG,
4419 ALC880_FIXUP_6ST_BASE,
4420 ALC880_FIXUP_6ST,
4421 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004422};
4423
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004424/* enable the volume-knob widget support on NID 0x21 */
4425static void alc880_fixup_vol_knob(struct hda_codec *codec,
4426 const struct alc_fixup *fix, int action)
4427{
4428 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004429 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004430}
4431
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004432static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004433 [ALC880_FIXUP_GPIO1] = {
4434 .type = ALC_FIXUP_VERBS,
4435 .v.verbs = alc_gpio1_init_verbs,
4436 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004437 [ALC880_FIXUP_GPIO2] = {
4438 .type = ALC_FIXUP_VERBS,
4439 .v.verbs = alc_gpio2_init_verbs,
4440 },
4441 [ALC880_FIXUP_MEDION_RIM] = {
4442 .type = ALC_FIXUP_VERBS,
4443 .v.verbs = (const struct hda_verb[]) {
4444 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4445 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4446 { }
4447 },
4448 .chained = true,
4449 .chain_id = ALC880_FIXUP_GPIO2,
4450 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004451 [ALC880_FIXUP_LG] = {
4452 .type = ALC_FIXUP_PINS,
4453 .v.pins = (const struct alc_pincfg[]) {
4454 /* disable bogus unused pins */
4455 { 0x16, 0x411111f0 },
4456 { 0x18, 0x411111f0 },
4457 { 0x1a, 0x411111f0 },
4458 { }
4459 }
4460 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004461 [ALC880_FIXUP_W810] = {
4462 .type = ALC_FIXUP_PINS,
4463 .v.pins = (const struct alc_pincfg[]) {
4464 /* disable bogus unused pins */
4465 { 0x17, 0x411111f0 },
4466 { }
4467 },
4468 .chained = true,
4469 .chain_id = ALC880_FIXUP_GPIO2,
4470 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004471 [ALC880_FIXUP_EAPD_COEF] = {
4472 .type = ALC_FIXUP_VERBS,
4473 .v.verbs = (const struct hda_verb[]) {
4474 /* change to EAPD mode */
4475 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4476 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4477 {}
4478 },
4479 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004480 [ALC880_FIXUP_TCL_S700] = {
4481 .type = ALC_FIXUP_VERBS,
4482 .v.verbs = (const struct hda_verb[]) {
4483 /* change to EAPD mode */
4484 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4485 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4486 {}
4487 },
4488 .chained = true,
4489 .chain_id = ALC880_FIXUP_GPIO2,
4490 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004491 [ALC880_FIXUP_VOL_KNOB] = {
4492 .type = ALC_FIXUP_FUNC,
4493 .v.func = alc880_fixup_vol_knob,
4494 },
4495 [ALC880_FIXUP_FUJITSU] = {
4496 /* override all pins as BIOS on old Amilo is broken */
4497 .type = ALC_FIXUP_PINS,
4498 .v.pins = (const struct alc_pincfg[]) {
4499 { 0x14, 0x0121411f }, /* HP */
4500 { 0x15, 0x99030120 }, /* speaker */
4501 { 0x16, 0x99030130 }, /* bass speaker */
4502 { 0x17, 0x411111f0 }, /* N/A */
4503 { 0x18, 0x411111f0 }, /* N/A */
4504 { 0x19, 0x01a19950 }, /* mic-in */
4505 { 0x1a, 0x411111f0 }, /* N/A */
4506 { 0x1b, 0x411111f0 }, /* N/A */
4507 { 0x1c, 0x411111f0 }, /* N/A */
4508 { 0x1d, 0x411111f0 }, /* N/A */
4509 { 0x1e, 0x01454140 }, /* SPDIF out */
4510 { }
4511 },
4512 .chained = true,
4513 .chain_id = ALC880_FIXUP_VOL_KNOB,
4514 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004515 [ALC880_FIXUP_F1734] = {
4516 /* almost compatible with FUJITSU, but no bass and SPDIF */
4517 .type = ALC_FIXUP_PINS,
4518 .v.pins = (const struct alc_pincfg[]) {
4519 { 0x14, 0x0121411f }, /* HP */
4520 { 0x15, 0x99030120 }, /* speaker */
4521 { 0x16, 0x411111f0 }, /* N/A */
4522 { 0x17, 0x411111f0 }, /* N/A */
4523 { 0x18, 0x411111f0 }, /* N/A */
4524 { 0x19, 0x01a19950 }, /* mic-in */
4525 { 0x1a, 0x411111f0 }, /* N/A */
4526 { 0x1b, 0x411111f0 }, /* N/A */
4527 { 0x1c, 0x411111f0 }, /* N/A */
4528 { 0x1d, 0x411111f0 }, /* N/A */
4529 { 0x1e, 0x411111f0 }, /* N/A */
4530 { }
4531 },
4532 .chained = true,
4533 .chain_id = ALC880_FIXUP_VOL_KNOB,
4534 },
Takashi Iwai817de922012-02-20 17:20:48 +01004535 [ALC880_FIXUP_UNIWILL] = {
4536 /* need to fix HP and speaker pins to be parsed correctly */
4537 .type = ALC_FIXUP_PINS,
4538 .v.pins = (const struct alc_pincfg[]) {
4539 { 0x14, 0x0121411f }, /* HP */
4540 { 0x15, 0x99030120 }, /* speaker */
4541 { 0x16, 0x99030130 }, /* bass speaker */
4542 { }
4543 },
4544 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004545 [ALC880_FIXUP_UNIWILL_DIG] = {
4546 .type = ALC_FIXUP_PINS,
4547 .v.pins = (const struct alc_pincfg[]) {
4548 /* disable bogus unused pins */
4549 { 0x17, 0x411111f0 },
4550 { 0x19, 0x411111f0 },
4551 { 0x1b, 0x411111f0 },
4552 { 0x1f, 0x411111f0 },
4553 { }
4554 }
4555 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004556 [ALC880_FIXUP_Z71V] = {
4557 .type = ALC_FIXUP_PINS,
4558 .v.pins = (const struct alc_pincfg[]) {
4559 /* set up the whole pins as BIOS is utterly broken */
4560 { 0x14, 0x99030120 }, /* speaker */
4561 { 0x15, 0x0121411f }, /* HP */
4562 { 0x16, 0x411111f0 }, /* N/A */
4563 { 0x17, 0x411111f0 }, /* N/A */
4564 { 0x18, 0x01a19950 }, /* mic-in */
4565 { 0x19, 0x411111f0 }, /* N/A */
4566 { 0x1a, 0x01813031 }, /* line-in */
4567 { 0x1b, 0x411111f0 }, /* N/A */
4568 { 0x1c, 0x411111f0 }, /* N/A */
4569 { 0x1d, 0x411111f0 }, /* N/A */
4570 { 0x1e, 0x0144111e }, /* SPDIF */
4571 { }
4572 }
4573 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004574 [ALC880_FIXUP_3ST_BASE] = {
4575 .type = ALC_FIXUP_PINS,
4576 .v.pins = (const struct alc_pincfg[]) {
4577 { 0x14, 0x01014010 }, /* line-out */
4578 { 0x15, 0x411111f0 }, /* N/A */
4579 { 0x16, 0x411111f0 }, /* N/A */
4580 { 0x17, 0x411111f0 }, /* N/A */
4581 { 0x18, 0x01a19c30 }, /* mic-in */
4582 { 0x19, 0x0121411f }, /* HP */
4583 { 0x1a, 0x01813031 }, /* line-in */
4584 { 0x1b, 0x02a19c40 }, /* front-mic */
4585 { 0x1c, 0x411111f0 }, /* N/A */
4586 { 0x1d, 0x411111f0 }, /* N/A */
4587 /* 0x1e is filled in below */
4588 { 0x1f, 0x411111f0 }, /* N/A */
4589 { }
4590 }
4591 },
4592 [ALC880_FIXUP_3ST] = {
4593 .type = ALC_FIXUP_PINS,
4594 .v.pins = (const struct alc_pincfg[]) {
4595 { 0x1e, 0x411111f0 }, /* N/A */
4596 { }
4597 },
4598 .chained = true,
4599 .chain_id = ALC880_FIXUP_3ST_BASE,
4600 },
4601 [ALC880_FIXUP_3ST_DIG] = {
4602 .type = ALC_FIXUP_PINS,
4603 .v.pins = (const struct alc_pincfg[]) {
4604 { 0x1e, 0x0144111e }, /* SPDIF */
4605 { }
4606 },
4607 .chained = true,
4608 .chain_id = ALC880_FIXUP_3ST_BASE,
4609 },
4610 [ALC880_FIXUP_5ST_BASE] = {
4611 .type = ALC_FIXUP_PINS,
4612 .v.pins = (const struct alc_pincfg[]) {
4613 { 0x14, 0x01014010 }, /* front */
4614 { 0x15, 0x411111f0 }, /* N/A */
4615 { 0x16, 0x01011411 }, /* CLFE */
4616 { 0x17, 0x01016412 }, /* surr */
4617 { 0x18, 0x01a19c30 }, /* mic-in */
4618 { 0x19, 0x0121411f }, /* HP */
4619 { 0x1a, 0x01813031 }, /* line-in */
4620 { 0x1b, 0x02a19c40 }, /* front-mic */
4621 { 0x1c, 0x411111f0 }, /* N/A */
4622 { 0x1d, 0x411111f0 }, /* N/A */
4623 /* 0x1e is filled in below */
4624 { 0x1f, 0x411111f0 }, /* N/A */
4625 { }
4626 }
4627 },
4628 [ALC880_FIXUP_5ST] = {
4629 .type = ALC_FIXUP_PINS,
4630 .v.pins = (const struct alc_pincfg[]) {
4631 { 0x1e, 0x411111f0 }, /* N/A */
4632 { }
4633 },
4634 .chained = true,
4635 .chain_id = ALC880_FIXUP_5ST_BASE,
4636 },
4637 [ALC880_FIXUP_5ST_DIG] = {
4638 .type = ALC_FIXUP_PINS,
4639 .v.pins = (const struct alc_pincfg[]) {
4640 { 0x1e, 0x0144111e }, /* SPDIF */
4641 { }
4642 },
4643 .chained = true,
4644 .chain_id = ALC880_FIXUP_5ST_BASE,
4645 },
4646 [ALC880_FIXUP_6ST_BASE] = {
4647 .type = ALC_FIXUP_PINS,
4648 .v.pins = (const struct alc_pincfg[]) {
4649 { 0x14, 0x01014010 }, /* front */
4650 { 0x15, 0x01016412 }, /* surr */
4651 { 0x16, 0x01011411 }, /* CLFE */
4652 { 0x17, 0x01012414 }, /* side */
4653 { 0x18, 0x01a19c30 }, /* mic-in */
4654 { 0x19, 0x02a19c40 }, /* front-mic */
4655 { 0x1a, 0x01813031 }, /* line-in */
4656 { 0x1b, 0x0121411f }, /* HP */
4657 { 0x1c, 0x411111f0 }, /* N/A */
4658 { 0x1d, 0x411111f0 }, /* N/A */
4659 /* 0x1e is filled in below */
4660 { 0x1f, 0x411111f0 }, /* N/A */
4661 { }
4662 }
4663 },
4664 [ALC880_FIXUP_6ST] = {
4665 .type = ALC_FIXUP_PINS,
4666 .v.pins = (const struct alc_pincfg[]) {
4667 { 0x1e, 0x411111f0 }, /* N/A */
4668 { }
4669 },
4670 .chained = true,
4671 .chain_id = ALC880_FIXUP_6ST_BASE,
4672 },
4673 [ALC880_FIXUP_6ST_DIG] = {
4674 .type = ALC_FIXUP_PINS,
4675 .v.pins = (const struct alc_pincfg[]) {
4676 { 0x1e, 0x0144111e }, /* SPDIF */
4677 { }
4678 },
4679 .chained = true,
4680 .chain_id = ALC880_FIXUP_6ST_BASE,
4681 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004682};
4683
4684static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004685 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004686 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004687 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4688 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004689 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004690 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004691 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004692 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004693 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004694 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004695 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004696 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004697 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004698 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004699 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004700 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4701 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4702 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004703 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004704
4705 /* Below is the copied entries from alc880_quirks.c.
4706 * It's not quite sure whether BIOS sets the correct pin-config table
4707 * on these machines, thus they are kept to be compatible with
4708 * the old static quirks. Once when it's confirmed to work without
4709 * these overrides, it'd be better to remove.
4710 */
4711 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4712 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4713 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4714 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4715 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4716 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4717 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4718 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4719 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4720 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4721 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4722 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4723 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4724 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4725 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4726 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4727 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4728 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4729 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4730 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4731 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4732 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4733 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4734 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4735 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4736 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4737 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4738 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4739 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4740 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4741 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4742 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4743 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4744 /* default Intel */
4745 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4746 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4747 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4748 {}
4749};
4750
4751static const struct alc_model_fixup alc880_fixup_models[] = {
4752 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4753 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4754 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4755 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4756 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4757 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004758 {}
4759};
4760
4761
4762/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004763 * OK, here we have finally the patch for ALC880
4764 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004765static int patch_alc880(struct hda_codec *codec)
4766{
4767 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004768 int err;
4769
Takashi Iwai3de95172012-05-07 18:03:15 +02004770 err = alc_alloc_spec(codec, 0x0b);
4771 if (err < 0)
4772 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004773
Takashi Iwai3de95172012-05-07 18:03:15 +02004774 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004775 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004776
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004777 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4778 alc880_fixups);
4779 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004780
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004781 /* automatic parse from the BIOS config */
4782 err = alc880_parse_auto_config(codec);
4783 if (err < 0)
4784 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004785
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004786 if (!spec->no_analog) {
4787 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004788 if (err < 0)
4789 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004790 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4791 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004792
Takashi Iwai1d045db2011-07-07 18:23:21 +02004793 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004794 codec->patch_ops.unsol_event = alc880_unsol_event;
4795
Takashi Iwai1d045db2011-07-07 18:23:21 +02004796
Takashi Iwai589876e2012-02-20 15:47:55 +01004797 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4798
Takashi Iwai1d045db2011-07-07 18:23:21 +02004799 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004800
4801 error:
4802 alc_free(codec);
4803 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004804}
4805
4806
4807/*
4808 * ALC260 support
4809 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004810static int alc260_parse_auto_config(struct hda_codec *codec)
4811{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004812 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004813 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4814 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004815}
4816
Takashi Iwai1d045db2011-07-07 18:23:21 +02004817/*
4818 * Pin config fixes
4819 */
4820enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004821 ALC260_FIXUP_HP_DC5750,
4822 ALC260_FIXUP_HP_PIN_0F,
4823 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004824 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004825 ALC260_FIXUP_GPIO1_TOGGLE,
4826 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004827 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004828 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004829};
4830
Takashi Iwai20f7d922012-02-16 12:35:16 +01004831static void alc260_gpio1_automute(struct hda_codec *codec)
4832{
4833 struct alc_spec *spec = codec->spec;
4834 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4835 spec->hp_jack_present);
4836}
4837
4838static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4839 const struct alc_fixup *fix, int action)
4840{
4841 struct alc_spec *spec = codec->spec;
4842 if (action == ALC_FIXUP_ACT_PROBE) {
4843 /* although the machine has only one output pin, we need to
4844 * toggle GPIO1 according to the jack state
4845 */
4846 spec->automute_hook = alc260_gpio1_automute;
4847 spec->detect_hp = 1;
4848 spec->automute_speaker = 1;
4849 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02004850 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
4851 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02004852 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004853 }
4854}
4855
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004856static void alc260_fixup_kn1(struct hda_codec *codec,
4857 const struct alc_fixup *fix, int action)
4858{
4859 struct alc_spec *spec = codec->spec;
4860 static const struct alc_pincfg pincfgs[] = {
4861 { 0x0f, 0x02214000 }, /* HP/speaker */
4862 { 0x12, 0x90a60160 }, /* int mic */
4863 { 0x13, 0x02a19000 }, /* ext mic */
4864 { 0x18, 0x01446000 }, /* SPDIF out */
4865 /* disable bogus I/O pins */
4866 { 0x10, 0x411111f0 },
4867 { 0x11, 0x411111f0 },
4868 { 0x14, 0x411111f0 },
4869 { 0x15, 0x411111f0 },
4870 { 0x16, 0x411111f0 },
4871 { 0x17, 0x411111f0 },
4872 { 0x19, 0x411111f0 },
4873 { }
4874 };
4875
4876 switch (action) {
4877 case ALC_FIXUP_ACT_PRE_PROBE:
4878 alc_apply_pincfgs(codec, pincfgs);
4879 break;
4880 case ALC_FIXUP_ACT_PROBE:
4881 spec->init_amp = ALC_INIT_NONE;
4882 break;
4883 }
4884}
4885
Takashi Iwai1d045db2011-07-07 18:23:21 +02004886static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004887 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004888 .type = ALC_FIXUP_PINS,
4889 .v.pins = (const struct alc_pincfg[]) {
4890 { 0x11, 0x90130110 }, /* speaker */
4891 { }
4892 }
4893 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004894 [ALC260_FIXUP_HP_PIN_0F] = {
4895 .type = ALC_FIXUP_PINS,
4896 .v.pins = (const struct alc_pincfg[]) {
4897 { 0x0f, 0x01214000 }, /* HP */
4898 { }
4899 }
4900 },
4901 [ALC260_FIXUP_COEF] = {
4902 .type = ALC_FIXUP_VERBS,
4903 .v.verbs = (const struct hda_verb[]) {
4904 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4905 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4906 { }
4907 },
4908 .chained = true,
4909 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4910 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004911 [ALC260_FIXUP_GPIO1] = {
4912 .type = ALC_FIXUP_VERBS,
4913 .v.verbs = alc_gpio1_init_verbs,
4914 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004915 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4916 .type = ALC_FIXUP_FUNC,
4917 .v.func = alc260_fixup_gpio1_toggle,
4918 .chained = true,
4919 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4920 },
4921 [ALC260_FIXUP_REPLACER] = {
4922 .type = ALC_FIXUP_VERBS,
4923 .v.verbs = (const struct hda_verb[]) {
4924 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4925 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4926 { }
4927 },
4928 .chained = true,
4929 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4930 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004931 [ALC260_FIXUP_HP_B1900] = {
4932 .type = ALC_FIXUP_FUNC,
4933 .v.func = alc260_fixup_gpio1_toggle,
4934 .chained = true,
4935 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004936 },
4937 [ALC260_FIXUP_KN1] = {
4938 .type = ALC_FIXUP_FUNC,
4939 .v.func = alc260_fixup_kn1,
4940 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004941};
4942
4943static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004944 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004945 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004946 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004947 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004948 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004949 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004950 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004951 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004952 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004953 {}
4954};
4955
4956/*
4957 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004958static int patch_alc260(struct hda_codec *codec)
4959{
4960 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004961 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004962
Takashi Iwai3de95172012-05-07 18:03:15 +02004963 err = alc_alloc_spec(codec, 0x07);
4964 if (err < 0)
4965 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004966
Takashi Iwai3de95172012-05-07 18:03:15 +02004967 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004968
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004969 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4970 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004971
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004972 /* automatic parse from the BIOS config */
4973 err = alc260_parse_auto_config(codec);
4974 if (err < 0)
4975 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004976
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004977 if (!spec->no_analog) {
4978 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004979 if (err < 0)
4980 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004981 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4982 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004983
Takashi Iwai1d045db2011-07-07 18:23:21 +02004984 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004985 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004986
Takashi Iwai589876e2012-02-20 15:47:55 +01004987 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4988
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004990
4991 error:
4992 alc_free(codec);
4993 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004994}
4995
4996
4997/*
4998 * ALC882/883/885/888/889 support
4999 *
5000 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5001 * configuration. Each pin widget can choose any input DACs and a mixer.
5002 * Each ADC is connected from a mixer of all inputs. This makes possible
5003 * 6-channel independent captures.
5004 *
5005 * In addition, an independent DAC for the multi-playback (not used in this
5006 * driver yet).
5007 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005008
5009/*
5010 * Pin config fixes
5011 */
5012enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005013 ALC882_FIXUP_ABIT_AW9D_MAX,
5014 ALC882_FIXUP_LENOVO_Y530,
5015 ALC882_FIXUP_PB_M5210,
5016 ALC882_FIXUP_ACER_ASPIRE_7736,
5017 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005018 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005019 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005020 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005021 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005022 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005023 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005024 ALC882_FIXUP_GPIO1,
5025 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005026 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005027 ALC889_FIXUP_COEF,
5028 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005029 ALC882_FIXUP_ACER_ASPIRE_4930G,
5030 ALC882_FIXUP_ACER_ASPIRE_8930G,
5031 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005032 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005033 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005034 ALC889_FIXUP_MBP_VREF,
5035 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005036 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005037 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005038};
5039
Takashi Iwai68ef0562011-11-09 18:24:44 +01005040static void alc889_fixup_coef(struct hda_codec *codec,
5041 const struct alc_fixup *fix, int action)
5042{
5043 if (action != ALC_FIXUP_ACT_INIT)
5044 return;
5045 alc889_coef_init(codec);
5046}
5047
Takashi Iwai56710872011-11-14 17:42:11 +01005048/* toggle speaker-output according to the hp-jack state */
5049static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5050{
5051 unsigned int gpiostate, gpiomask, gpiodir;
5052
5053 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5054 AC_VERB_GET_GPIO_DATA, 0);
5055
5056 if (!muted)
5057 gpiostate |= (1 << pin);
5058 else
5059 gpiostate &= ~(1 << pin);
5060
5061 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5062 AC_VERB_GET_GPIO_MASK, 0);
5063 gpiomask |= (1 << pin);
5064
5065 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5066 AC_VERB_GET_GPIO_DIRECTION, 0);
5067 gpiodir |= (1 << pin);
5068
5069
5070 snd_hda_codec_write(codec, codec->afg, 0,
5071 AC_VERB_SET_GPIO_MASK, gpiomask);
5072 snd_hda_codec_write(codec, codec->afg, 0,
5073 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5074
5075 msleep(1);
5076
5077 snd_hda_codec_write(codec, codec->afg, 0,
5078 AC_VERB_SET_GPIO_DATA, gpiostate);
5079}
5080
5081/* set up GPIO at initialization */
5082static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5083 const struct alc_fixup *fix, int action)
5084{
5085 if (action != ALC_FIXUP_ACT_INIT)
5086 return;
5087 alc882_gpio_mute(codec, 0, 0);
5088 alc882_gpio_mute(codec, 1, 0);
5089}
5090
Takashi Iwai02a237b2012-02-13 15:25:07 +01005091/* Fix the connection of some pins for ALC889:
5092 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5093 * work correctly (bko#42740)
5094 */
5095static void alc889_fixup_dac_route(struct hda_codec *codec,
5096 const struct alc_fixup *fix, int action)
5097{
5098 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005099 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005100 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5101 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5102 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5103 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5104 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5105 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005106 } else if (action == ALC_FIXUP_ACT_PROBE) {
5107 /* restore the connections */
5108 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5109 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5110 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5111 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5112 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005113 }
5114}
5115
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005116/* Set VREF on HP pin */
5117static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5118 const struct alc_fixup *fix, int action)
5119{
5120 struct alc_spec *spec = codec->spec;
5121 static hda_nid_t nids[2] = { 0x14, 0x15 };
5122 int i;
5123
5124 if (action != ALC_FIXUP_ACT_INIT)
5125 return;
5126 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5127 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5128 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5129 continue;
5130 val = snd_hda_codec_read(codec, nids[i], 0,
5131 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5132 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005133 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005134 spec->keep_vref_in_automute = 1;
5135 break;
5136 }
5137}
5138
5139/* Set VREF on speaker pins on imac91 */
5140static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5141 const struct alc_fixup *fix, int action)
5142{
5143 struct alc_spec *spec = codec->spec;
5144 static hda_nid_t nids[2] = { 0x18, 0x1a };
5145 int i;
5146
5147 if (action != ALC_FIXUP_ACT_INIT)
5148 return;
5149 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5150 unsigned int val;
5151 val = snd_hda_codec_read(codec, nids[i], 0,
5152 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5153 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005154 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005155 }
5156 spec->keep_vref_in_automute = 1;
5157}
5158
Takashi Iwaie427c232012-07-29 10:04:08 +02005159/* Don't take HP output as primary
5160 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5161 */
5162static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5163 const struct alc_fixup *fix, int action)
5164{
5165 struct alc_spec *spec = codec->spec;
5166 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5167 spec->no_primary_hp = 1;
5168}
5169
Takashi Iwai1d045db2011-07-07 18:23:21 +02005170static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005171 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005172 .type = ALC_FIXUP_PINS,
5173 .v.pins = (const struct alc_pincfg[]) {
5174 { 0x15, 0x01080104 }, /* side */
5175 { 0x16, 0x01011012 }, /* rear */
5176 { 0x17, 0x01016011 }, /* clfe */
5177 { }
5178 }
5179 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005180 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005181 .type = ALC_FIXUP_PINS,
5182 .v.pins = (const struct alc_pincfg[]) {
5183 { 0x15, 0x99130112 }, /* rear int speakers */
5184 { 0x16, 0x99130111 }, /* subwoofer */
5185 { }
5186 }
5187 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005188 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005189 .type = ALC_FIXUP_VERBS,
5190 .v.verbs = (const struct hda_verb[]) {
5191 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5192 {}
5193 }
5194 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005195 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005196 .type = ALC_FIXUP_FUNC,
5197 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005198 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005199 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005200 .type = ALC_FIXUP_PINS,
5201 .v.pins = (const struct alc_pincfg[]) {
5202 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5203 { }
5204 }
5205 },
Marton Balint8f239212012-03-05 21:33:23 +01005206 [ALC889_FIXUP_CD] = {
5207 .type = ALC_FIXUP_PINS,
5208 .v.pins = (const struct alc_pincfg[]) {
5209 { 0x1c, 0x993301f0 }, /* CD */
5210 { }
5211 }
5212 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005213 [ALC889_FIXUP_VAIO_TT] = {
5214 .type = ALC_FIXUP_PINS,
5215 .v.pins = (const struct alc_pincfg[]) {
5216 { 0x17, 0x90170111 }, /* hidden surround speaker */
5217 { }
5218 }
5219 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005220 [ALC888_FIXUP_EEE1601] = {
5221 .type = ALC_FIXUP_VERBS,
5222 .v.verbs = (const struct hda_verb[]) {
5223 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5224 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5225 { }
5226 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005227 },
5228 [ALC882_FIXUP_EAPD] = {
5229 .type = ALC_FIXUP_VERBS,
5230 .v.verbs = (const struct hda_verb[]) {
5231 /* change to EAPD mode */
5232 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5233 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5234 { }
5235 }
5236 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005237 [ALC883_FIXUP_EAPD] = {
5238 .type = ALC_FIXUP_VERBS,
5239 .v.verbs = (const struct hda_verb[]) {
5240 /* change to EAPD mode */
5241 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5242 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5243 { }
5244 }
5245 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005246 [ALC883_FIXUP_ACER_EAPD] = {
5247 .type = ALC_FIXUP_VERBS,
5248 .v.verbs = (const struct hda_verb[]) {
5249 /* eanable EAPD on Acer laptops */
5250 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5251 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5252 { }
5253 }
5254 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005255 [ALC882_FIXUP_GPIO1] = {
5256 .type = ALC_FIXUP_VERBS,
5257 .v.verbs = alc_gpio1_init_verbs,
5258 },
5259 [ALC882_FIXUP_GPIO2] = {
5260 .type = ALC_FIXUP_VERBS,
5261 .v.verbs = alc_gpio2_init_verbs,
5262 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005263 [ALC882_FIXUP_GPIO3] = {
5264 .type = ALC_FIXUP_VERBS,
5265 .v.verbs = alc_gpio3_init_verbs,
5266 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005267 [ALC882_FIXUP_ASUS_W2JC] = {
5268 .type = ALC_FIXUP_VERBS,
5269 .v.verbs = alc_gpio1_init_verbs,
5270 .chained = true,
5271 .chain_id = ALC882_FIXUP_EAPD,
5272 },
5273 [ALC889_FIXUP_COEF] = {
5274 .type = ALC_FIXUP_FUNC,
5275 .v.func = alc889_fixup_coef,
5276 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005277 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5278 .type = ALC_FIXUP_PINS,
5279 .v.pins = (const struct alc_pincfg[]) {
5280 { 0x16, 0x99130111 }, /* CLFE speaker */
5281 { 0x17, 0x99130112 }, /* surround speaker */
5282 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005283 },
5284 .chained = true,
5285 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005286 },
5287 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5288 .type = ALC_FIXUP_PINS,
5289 .v.pins = (const struct alc_pincfg[]) {
5290 { 0x16, 0x99130111 }, /* CLFE speaker */
5291 { 0x1b, 0x99130112 }, /* surround speaker */
5292 { }
5293 },
5294 .chained = true,
5295 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5296 },
5297 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5298 /* additional init verbs for Acer Aspire 8930G */
5299 .type = ALC_FIXUP_VERBS,
5300 .v.verbs = (const struct hda_verb[]) {
5301 /* Enable all DACs */
5302 /* DAC DISABLE/MUTE 1? */
5303 /* setting bits 1-5 disables DAC nids 0x02-0x06
5304 * apparently. Init=0x38 */
5305 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5306 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5307 /* DAC DISABLE/MUTE 2? */
5308 /* some bit here disables the other DACs.
5309 * Init=0x4900 */
5310 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5311 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5312 /* DMIC fix
5313 * This laptop has a stereo digital microphone.
5314 * The mics are only 1cm apart which makes the stereo
5315 * useless. However, either the mic or the ALC889
5316 * makes the signal become a difference/sum signal
5317 * instead of standard stereo, which is annoying.
5318 * So instead we flip this bit which makes the
5319 * codec replicate the sum signal to both channels,
5320 * turning it into a normal mono mic.
5321 */
5322 /* DMIC_CONTROL? Init value = 0x0001 */
5323 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5324 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5325 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5326 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5327 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005328 },
5329 .chained = true,
5330 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005331 },
Takashi Iwai56710872011-11-14 17:42:11 +01005332 [ALC885_FIXUP_MACPRO_GPIO] = {
5333 .type = ALC_FIXUP_FUNC,
5334 .v.func = alc885_fixup_macpro_gpio,
5335 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005336 [ALC889_FIXUP_DAC_ROUTE] = {
5337 .type = ALC_FIXUP_FUNC,
5338 .v.func = alc889_fixup_dac_route,
5339 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005340 [ALC889_FIXUP_MBP_VREF] = {
5341 .type = ALC_FIXUP_FUNC,
5342 .v.func = alc889_fixup_mbp_vref,
5343 .chained = true,
5344 .chain_id = ALC882_FIXUP_GPIO1,
5345 },
5346 [ALC889_FIXUP_IMAC91_VREF] = {
5347 .type = ALC_FIXUP_FUNC,
5348 .v.func = alc889_fixup_imac91_vref,
5349 .chained = true,
5350 .chain_id = ALC882_FIXUP_GPIO1,
5351 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005352 [ALC882_FIXUP_INV_DMIC] = {
5353 .type = ALC_FIXUP_FUNC,
5354 .v.func = alc_fixup_inv_dmic_0x12,
5355 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005356 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5357 .type = ALC_FIXUP_FUNC,
5358 .v.func = alc882_fixup_no_primary_hp,
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 Iwaie427c232012-07-29 10:04:08 +02005394 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005395
5396 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005397 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5398 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5399 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005400 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5401 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5402 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005403 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5404 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005405 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005406 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5407 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5408 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5409 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005410 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005411 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5412 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5413 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005414 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005415 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5416 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5417 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005418
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005419 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005420 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005421 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005422 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005423 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005424 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5425 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005426 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005427 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005428 {}
5429};
5430
Takashi Iwai912093b2012-04-11 14:03:41 +02005431static const struct alc_model_fixup alc882_fixup_models[] = {
5432 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5433 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5434 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005435 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005436 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005437 {}
5438};
5439
Takashi Iwai1d045db2011-07-07 18:23:21 +02005440/*
5441 * BIOS auto configuration
5442 */
5443/* almost identical with ALC880 parser... */
5444static int alc882_parse_auto_config(struct hda_codec *codec)
5445{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005446 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005447 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5448 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005449}
5450
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451/*
5452 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005453static int patch_alc882(struct hda_codec *codec)
5454{
5455 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005456 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005457
Takashi Iwai3de95172012-05-07 18:03:15 +02005458 err = alc_alloc_spec(codec, 0x0b);
5459 if (err < 0)
5460 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005461
Takashi Iwai3de95172012-05-07 18:03:15 +02005462 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005463
5464 switch (codec->vendor_id) {
5465 case 0x10ec0882:
5466 case 0x10ec0885:
5467 break;
5468 default:
5469 /* ALC883 and variants */
5470 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5471 break;
5472 }
5473
Takashi Iwai912093b2012-04-11 14:03:41 +02005474 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5475 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005476 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005477
5478 alc_auto_parse_customize_define(codec);
5479
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005480 /* automatic parse from the BIOS config */
5481 err = alc882_parse_auto_config(codec);
5482 if (err < 0)
5483 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005484
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005485 if (!spec->no_analog && has_cdefine_beep(codec)) {
5486 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005487 if (err < 0)
5488 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005490 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005491
Takashi Iwai1d045db2011-07-07 18:23:21 +02005492 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005493
Takashi Iwai589876e2012-02-20 15:47:55 +01005494 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5495
Takashi Iwai1d045db2011-07-07 18:23:21 +02005496 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005497
5498 error:
5499 alc_free(codec);
5500 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005501}
5502
5503
5504/*
5505 * ALC262 support
5506 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005507static int alc262_parse_auto_config(struct hda_codec *codec)
5508{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005509 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005510 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5511 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512}
5513
5514/*
5515 * Pin config fixes
5516 */
5517enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005518 ALC262_FIXUP_FSC_H270,
5519 ALC262_FIXUP_HP_Z200,
5520 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005521 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005522 ALC262_FIXUP_BENQ,
5523 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005524 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005525};
5526
5527static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005528 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005529 .type = ALC_FIXUP_PINS,
5530 .v.pins = (const struct alc_pincfg[]) {
5531 { 0x14, 0x99130110 }, /* speaker */
5532 { 0x15, 0x0221142f }, /* front HP */
5533 { 0x1b, 0x0121141f }, /* rear HP */
5534 { }
5535 }
5536 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005537 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005538 .type = ALC_FIXUP_PINS,
5539 .v.pins = (const struct alc_pincfg[]) {
5540 { 0x16, 0x99130120 }, /* internal speaker */
5541 { }
5542 }
5543 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005544 [ALC262_FIXUP_TYAN] = {
5545 .type = ALC_FIXUP_PINS,
5546 .v.pins = (const struct alc_pincfg[]) {
5547 { 0x14, 0x1993e1f0 }, /* int AUX */
5548 { }
5549 }
5550 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005551 [ALC262_FIXUP_LENOVO_3000] = {
5552 .type = ALC_FIXUP_VERBS,
5553 .v.verbs = (const struct hda_verb[]) {
5554 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005555 {}
5556 },
5557 .chained = true,
5558 .chain_id = ALC262_FIXUP_BENQ,
5559 },
5560 [ALC262_FIXUP_BENQ] = {
5561 .type = ALC_FIXUP_VERBS,
5562 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005563 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5564 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5565 {}
5566 }
5567 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005568 [ALC262_FIXUP_BENQ_T31] = {
5569 .type = ALC_FIXUP_VERBS,
5570 .v.verbs = (const struct hda_verb[]) {
5571 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5572 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5573 {}
5574 }
5575 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005576 [ALC262_FIXUP_INV_DMIC] = {
5577 .type = ALC_FIXUP_FUNC,
5578 .v.func = alc_fixup_inv_dmic_0x12,
5579 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005580};
5581
5582static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005583 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005584 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5585 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005586 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5587 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005588 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005589 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5590 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005591 {}
5592};
5593
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005594static const struct alc_model_fixup alc262_fixup_models[] = {
5595 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5596 {}
5597};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005598
Takashi Iwai1d045db2011-07-07 18:23:21 +02005599/*
5600 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005601static int patch_alc262(struct hda_codec *codec)
5602{
5603 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604 int err;
5605
Takashi Iwai3de95172012-05-07 18:03:15 +02005606 err = alc_alloc_spec(codec, 0x0b);
5607 if (err < 0)
5608 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005609
Takashi Iwai3de95172012-05-07 18:03:15 +02005610 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005611
5612#if 0
5613 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5614 * under-run
5615 */
5616 {
5617 int tmp;
5618 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5619 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5620 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5621 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5622 }
5623#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005624 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5625
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005626 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5627 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005628 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005629
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005630 alc_auto_parse_customize_define(codec);
5631
Takashi Iwai42399f72011-11-07 17:18:44 +01005632 /* automatic parse from the BIOS config */
5633 err = alc262_parse_auto_config(codec);
5634 if (err < 0)
5635 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005636
Takashi Iwai1d045db2011-07-07 18:23:21 +02005637 if (!spec->no_analog && has_cdefine_beep(codec)) {
5638 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005639 if (err < 0)
5640 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005641 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005642 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643
Takashi Iwai1d045db2011-07-07 18:23:21 +02005644 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645 spec->shutup = alc_eapd_shutup;
5646
Takashi Iwai589876e2012-02-20 15:47:55 +01005647 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5648
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005650
5651 error:
5652 alc_free(codec);
5653 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005654}
5655
5656/*
5657 * ALC268
5658 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005659/* bind Beep switches of both NID 0x0f and 0x10 */
5660static const struct hda_bind_ctls alc268_bind_beep_sw = {
5661 .ops = &snd_hda_bind_sw,
5662 .values = {
5663 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5664 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5665 0
5666 },
5667};
5668
5669static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5670 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5671 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5672 { }
5673};
5674
5675/* set PCBEEP vol = 0, mute connections */
5676static const struct hda_verb alc268_beep_init_verbs[] = {
5677 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5678 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5679 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5680 { }
5681};
5682
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005683enum {
5684 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005685 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005686};
5687
5688static const struct alc_fixup alc268_fixups[] = {
5689 [ALC268_FIXUP_INV_DMIC] = {
5690 .type = ALC_FIXUP_FUNC,
5691 .v.func = alc_fixup_inv_dmic_0x12,
5692 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005693 [ALC268_FIXUP_HP_EAPD] = {
5694 .type = ALC_FIXUP_VERBS,
5695 .v.verbs = (const struct hda_verb[]) {
5696 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5697 {}
5698 }
5699 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005700};
5701
5702static const struct alc_model_fixup alc268_fixup_models[] = {
5703 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005704 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5705 {}
5706};
5707
5708static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5709 /* below is codec SSID since multiple Toshiba laptops have the
5710 * same PCI SSID 1179:ff00
5711 */
5712 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005713 {}
5714};
5715
Takashi Iwai1d045db2011-07-07 18:23:21 +02005716/*
5717 * BIOS auto configuration
5718 */
5719static int alc268_parse_auto_config(struct hda_codec *codec)
5720{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005721 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005722 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005723 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5724 if (err > 0) {
5725 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5726 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005727 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005728 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005729 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005730 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005731}
5732
Takashi Iwai1d045db2011-07-07 18:23:21 +02005733/*
5734 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005735static int patch_alc268(struct hda_codec *codec)
5736{
5737 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005738 int i, has_beep, err;
5739
Takashi Iwai1d045db2011-07-07 18:23:21 +02005740 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005741 err = alc_alloc_spec(codec, 0);
5742 if (err < 0)
5743 return err;
5744
5745 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005746
Takashi Iwaicb766402012-10-20 10:55:21 +02005747 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005748 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5749
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005750 /* automatic parse from the BIOS config */
5751 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005752 if (err < 0)
5753 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754
Takashi Iwai1d045db2011-07-07 18:23:21 +02005755 has_beep = 0;
5756 for (i = 0; i < spec->num_mixers; i++) {
5757 if (spec->mixers[i] == alc268_beep_mixer) {
5758 has_beep = 1;
5759 break;
5760 }
5761 }
5762
5763 if (has_beep) {
5764 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005765 if (err < 0)
5766 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5768 /* override the amp caps for beep generator */
5769 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5770 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5771 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5772 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5773 (0 << AC_AMPCAP_MUTE_SHIFT));
5774 }
5775
Takashi Iwai1d045db2011-07-07 18:23:21 +02005776 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005777 spec->shutup = alc_eapd_shutup;
5778
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005779 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5780
Takashi Iwai1d045db2011-07-07 18:23:21 +02005781 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005782
5783 error:
5784 alc_free(codec);
5785 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786}
5787
5788/*
5789 * ALC269
5790 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005791static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5792 .substreams = 1,
5793 .channels_min = 2,
5794 .channels_max = 8,
5795 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5796 /* NID is set in alc_build_pcms */
5797 .ops = {
5798 .open = alc_playback_pcm_open,
5799 .prepare = alc_playback_pcm_prepare,
5800 .cleanup = alc_playback_pcm_cleanup
5801 },
5802};
5803
5804static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5805 .substreams = 1,
5806 .channels_min = 2,
5807 .channels_max = 2,
5808 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5809 /* NID is set in alc_build_pcms */
5810};
5811
Takashi Iwai1d045db2011-07-07 18:23:21 +02005812/* different alc269-variants */
5813enum {
5814 ALC269_TYPE_ALC269VA,
5815 ALC269_TYPE_ALC269VB,
5816 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005817 ALC269_TYPE_ALC269VD,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005818};
5819
5820/*
5821 * BIOS auto configuration
5822 */
5823static int alc269_parse_auto_config(struct hda_codec *codec)
5824{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005825 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005826 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5827 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5828 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005829 const hda_nid_t *ssids;
5830
5831 switch (spec->codec_variant) {
5832 case ALC269_TYPE_ALC269VA:
5833 case ALC269_TYPE_ALC269VC:
5834 ssids = alc269va_ssids;
5835 break;
5836 case ALC269_TYPE_ALC269VB:
5837 case ALC269_TYPE_ALC269VD:
5838 ssids = alc269_ssids;
5839 break;
5840 default:
5841 ssids = alc269_ssids;
5842 break;
5843 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005844
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005845 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005846}
5847
Kailang Yang1387e2d2012-11-08 10:23:18 +01005848static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005849{
5850 int val = alc_read_coef_idx(codec, 0x04);
5851 if (power_up)
5852 val |= 1 << 11;
5853 else
5854 val &= ~(1 << 11);
5855 alc_write_coef_idx(codec, 0x04, val);
5856}
5857
5858static void alc269_shutup(struct hda_codec *codec)
5859{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005860 struct alc_spec *spec = codec->spec;
5861
5862 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5863 return;
5864
Kailang Yang1387e2d2012-11-08 10:23:18 +01005865 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5866 alc269vb_toggle_power_output(codec, 0);
5867 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
5868 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005869 msleep(150);
5870 }
5871}
5872
Takashi Iwai2a439522011-07-26 09:52:50 +02005873#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005874static int alc269_resume(struct hda_codec *codec)
5875{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005876 struct alc_spec *spec = codec->spec;
5877
Kailang Yang1387e2d2012-11-08 10:23:18 +01005878 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5879 alc269vb_toggle_power_output(codec, 0);
5880 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005881 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005882 msleep(150);
5883 }
5884
5885 codec->patch_ops.init(codec);
5886
Kailang Yang1387e2d2012-11-08 10:23:18 +01005887 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
5888 alc269vb_toggle_power_output(codec, 1);
5889 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02005890 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005891 msleep(200);
5892 }
5893
Takashi Iwai1d045db2011-07-07 18:23:21 +02005894 snd_hda_codec_resume_amp(codec);
5895 snd_hda_codec_resume_cache(codec);
5896 hda_call_check_power_status(codec, 0x01);
5897 return 0;
5898}
Takashi Iwai2a439522011-07-26 09:52:50 +02005899#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005900
David Henningsson108cc102012-07-20 10:37:25 +02005901static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5902 const struct alc_fixup *fix, int action)
5903{
5904 struct alc_spec *spec = codec->spec;
5905
5906 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5907 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5908}
5909
Takashi Iwai1d045db2011-07-07 18:23:21 +02005910static void alc269_fixup_hweq(struct hda_codec *codec,
5911 const struct alc_fixup *fix, int action)
5912{
5913 int coef;
5914
5915 if (action != ALC_FIXUP_ACT_INIT)
5916 return;
5917 coef = alc_read_coef_idx(codec, 0x1e);
5918 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5919}
5920
5921static void alc271_fixup_dmic(struct hda_codec *codec,
5922 const struct alc_fixup *fix, int action)
5923{
5924 static const struct hda_verb verbs[] = {
5925 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5926 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5927 {}
5928 };
5929 unsigned int cfg;
5930
5931 if (strcmp(codec->chip_name, "ALC271X"))
5932 return;
5933 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5934 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5935 snd_hda_sequence_write(codec, verbs);
5936}
5937
Takashi Iwai017f2a12011-07-09 14:42:25 +02005938static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5939 const struct alc_fixup *fix, int action)
5940{
5941 struct alc_spec *spec = codec->spec;
5942
5943 if (action != ALC_FIXUP_ACT_PROBE)
5944 return;
5945
5946 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5947 * fix the sample rate of analog I/O to 44.1kHz
5948 */
5949 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5950 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5951}
5952
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005953static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5954 const struct alc_fixup *fix, int action)
5955{
5956 int coef;
5957
5958 if (action != ALC_FIXUP_ACT_INIT)
5959 return;
5960 /* The digital-mic unit sends PDM (differential signal) instead of
5961 * the standard PCM, thus you can't record a valid mono stream as is.
5962 * Below is a workaround specific to ALC269 to control the dmic
5963 * signal source as mono.
5964 */
5965 coef = alc_read_coef_idx(codec, 0x07);
5966 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5967}
5968
Takashi Iwai24519912011-08-16 15:08:49 +02005969static void alc269_quanta_automute(struct hda_codec *codec)
5970{
David Henningsson42cf0d02011-09-20 12:04:56 +02005971 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005972
5973 snd_hda_codec_write(codec, 0x20, 0,
5974 AC_VERB_SET_COEF_INDEX, 0x0c);
5975 snd_hda_codec_write(codec, 0x20, 0,
5976 AC_VERB_SET_PROC_COEF, 0x680);
5977
5978 snd_hda_codec_write(codec, 0x20, 0,
5979 AC_VERB_SET_COEF_INDEX, 0x0c);
5980 snd_hda_codec_write(codec, 0x20, 0,
5981 AC_VERB_SET_PROC_COEF, 0x480);
5982}
5983
5984static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5985 const struct alc_fixup *fix, int action)
5986{
5987 struct alc_spec *spec = codec->spec;
5988 if (action != ALC_FIXUP_ACT_PROBE)
5989 return;
5990 spec->automute_hook = alc269_quanta_automute;
5991}
5992
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005993/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5994static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5995{
5996 struct hda_codec *codec = private_data;
5997 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005998 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005999}
6000
6001static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6002 const struct alc_fixup *fix, int action)
6003{
6004 struct alc_spec *spec = codec->spec;
6005 switch (action) {
6006 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006007 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006008 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006009 /* fallthru */
6010 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006011 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006012 break;
6013 }
6014}
6015
David Henningsson693b6132012-06-22 19:12:10 +02006016
Takashi Iwai1d045db2011-07-07 18:23:21 +02006017enum {
6018 ALC269_FIXUP_SONY_VAIO,
6019 ALC275_FIXUP_SONY_VAIO_GPIO2,
6020 ALC269_FIXUP_DELL_M101Z,
6021 ALC269_FIXUP_SKU_IGNORE,
6022 ALC269_FIXUP_ASUS_G73JW,
6023 ALC269_FIXUP_LENOVO_EAPD,
6024 ALC275_FIXUP_SONY_HWEQ,
6025 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006026 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006027 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006028 ALC269_FIXUP_QUANTA_MUTE,
6029 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006030 ALC269_FIXUP_AMIC,
6031 ALC269_FIXUP_DMIC,
6032 ALC269VB_FIXUP_AMIC,
6033 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006034 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006035 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006036 ALC269_FIXUP_LENOVO_DOCK,
6037 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006038};
6039
6040static const struct alc_fixup alc269_fixups[] = {
6041 [ALC269_FIXUP_SONY_VAIO] = {
6042 .type = ALC_FIXUP_VERBS,
6043 .v.verbs = (const struct hda_verb[]) {
6044 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6045 {}
6046 }
6047 },
6048 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6049 .type = ALC_FIXUP_VERBS,
6050 .v.verbs = (const struct hda_verb[]) {
6051 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6052 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6053 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6054 { }
6055 },
6056 .chained = true,
6057 .chain_id = ALC269_FIXUP_SONY_VAIO
6058 },
6059 [ALC269_FIXUP_DELL_M101Z] = {
6060 .type = ALC_FIXUP_VERBS,
6061 .v.verbs = (const struct hda_verb[]) {
6062 /* Enables internal speaker */
6063 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6064 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6065 {}
6066 }
6067 },
6068 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006069 .type = ALC_FIXUP_FUNC,
6070 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006071 },
6072 [ALC269_FIXUP_ASUS_G73JW] = {
6073 .type = ALC_FIXUP_PINS,
6074 .v.pins = (const struct alc_pincfg[]) {
6075 { 0x17, 0x99130111 }, /* subwoofer */
6076 { }
6077 }
6078 },
6079 [ALC269_FIXUP_LENOVO_EAPD] = {
6080 .type = ALC_FIXUP_VERBS,
6081 .v.verbs = (const struct hda_verb[]) {
6082 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6083 {}
6084 }
6085 },
6086 [ALC275_FIXUP_SONY_HWEQ] = {
6087 .type = ALC_FIXUP_FUNC,
6088 .v.func = alc269_fixup_hweq,
6089 .chained = true,
6090 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6091 },
6092 [ALC271_FIXUP_DMIC] = {
6093 .type = ALC_FIXUP_FUNC,
6094 .v.func = alc271_fixup_dmic,
6095 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006096 [ALC269_FIXUP_PCM_44K] = {
6097 .type = ALC_FIXUP_FUNC,
6098 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006099 .chained = true,
6100 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006101 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006102 [ALC269_FIXUP_STEREO_DMIC] = {
6103 .type = ALC_FIXUP_FUNC,
6104 .v.func = alc269_fixup_stereo_dmic,
6105 },
Takashi Iwai24519912011-08-16 15:08:49 +02006106 [ALC269_FIXUP_QUANTA_MUTE] = {
6107 .type = ALC_FIXUP_FUNC,
6108 .v.func = alc269_fixup_quanta_mute,
6109 },
6110 [ALC269_FIXUP_LIFEBOOK] = {
6111 .type = ALC_FIXUP_PINS,
6112 .v.pins = (const struct alc_pincfg[]) {
6113 { 0x1a, 0x2101103f }, /* dock line-out */
6114 { 0x1b, 0x23a11040 }, /* dock mic-in */
6115 { }
6116 },
6117 .chained = true,
6118 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6119 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006120 [ALC269_FIXUP_AMIC] = {
6121 .type = ALC_FIXUP_PINS,
6122 .v.pins = (const struct alc_pincfg[]) {
6123 { 0x14, 0x99130110 }, /* speaker */
6124 { 0x15, 0x0121401f }, /* HP out */
6125 { 0x18, 0x01a19c20 }, /* mic */
6126 { 0x19, 0x99a3092f }, /* int-mic */
6127 { }
6128 },
6129 },
6130 [ALC269_FIXUP_DMIC] = {
6131 .type = ALC_FIXUP_PINS,
6132 .v.pins = (const struct alc_pincfg[]) {
6133 { 0x12, 0x99a3092f }, /* int-mic */
6134 { 0x14, 0x99130110 }, /* speaker */
6135 { 0x15, 0x0121401f }, /* HP out */
6136 { 0x18, 0x01a19c20 }, /* mic */
6137 { }
6138 },
6139 },
6140 [ALC269VB_FIXUP_AMIC] = {
6141 .type = ALC_FIXUP_PINS,
6142 .v.pins = (const struct alc_pincfg[]) {
6143 { 0x14, 0x99130110 }, /* speaker */
6144 { 0x18, 0x01a19c20 }, /* mic */
6145 { 0x19, 0x99a3092f }, /* int-mic */
6146 { 0x21, 0x0121401f }, /* HP out */
6147 { }
6148 },
6149 },
David Henningsson2267ea92012-01-03 08:45:56 +01006150 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006151 .type = ALC_FIXUP_PINS,
6152 .v.pins = (const struct alc_pincfg[]) {
6153 { 0x12, 0x99a3092f }, /* int-mic */
6154 { 0x14, 0x99130110 }, /* speaker */
6155 { 0x18, 0x01a19c20 }, /* mic */
6156 { 0x21, 0x0121401f }, /* HP out */
6157 { }
6158 },
6159 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006160 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6161 .type = ALC_FIXUP_FUNC,
6162 .v.func = alc269_fixup_mic2_mute,
6163 },
David Henningsson693b6132012-06-22 19:12:10 +02006164 [ALC269_FIXUP_INV_DMIC] = {
6165 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006166 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006167 },
David Henningsson108cc102012-07-20 10:37:25 +02006168 [ALC269_FIXUP_LENOVO_DOCK] = {
6169 .type = ALC_FIXUP_PINS,
6170 .v.pins = (const struct alc_pincfg[]) {
6171 { 0x19, 0x23a11040 }, /* dock mic */
6172 { 0x1b, 0x2121103f }, /* dock headphone */
6173 { }
6174 },
6175 .chained = true,
6176 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6177 },
6178 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6179 .type = ALC_FIXUP_FUNC,
6180 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6181 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006182};
6183
6184static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006185 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6186 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006187 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006188 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006189 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006190 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006191 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006192 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6193 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6194 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6195 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6196 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006197 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6198 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6199 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6200 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6201 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6202 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006203 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006204 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6205 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6206 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6207 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6208 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006209 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006210 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006211 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006212 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006213 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006214 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006215 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006216
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006217#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006218 /* Below is a quirk table taken from the old code.
6219 * Basically the device should work as is without the fixup table.
6220 * If BIOS doesn't give a proper info, enable the corresponding
6221 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006222 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006223 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6224 ALC269_FIXUP_AMIC),
6225 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006226 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6227 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6228 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6229 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6230 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6231 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6232 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6233 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6234 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6235 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6236 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6237 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6238 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6239 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6240 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6241 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6242 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6243 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6244 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6245 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6246 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6247 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6248 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6249 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6250 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6251 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6252 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6253 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6254 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6255 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6256 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6257 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6258 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6259 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6260 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6261 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6262 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6263 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6264#endif
6265 {}
6266};
6267
6268static const struct alc_model_fixup alc269_fixup_models[] = {
6269 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6270 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006271 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6272 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6273 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006274 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006275 {}
6276};
6277
6278
Takashi Iwai546bb672012-03-07 08:37:19 +01006279static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006280{
Kailang Yang526af6e2012-03-07 08:25:20 +01006281 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006282 int val;
6283
Kailang Yang526af6e2012-03-07 08:25:20 +01006284 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006285 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006286
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006287 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006288 alc_write_coef_idx(codec, 0xf, 0x960b);
6289 alc_write_coef_idx(codec, 0xe, 0x8817);
6290 }
6291
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006292 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006293 alc_write_coef_idx(codec, 0xf, 0x960b);
6294 alc_write_coef_idx(codec, 0xe, 0x8814);
6295 }
6296
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006297 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006298 val = alc_read_coef_idx(codec, 0x04);
6299 /* Power up output pin */
6300 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6301 }
6302
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006303 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006304 val = alc_read_coef_idx(codec, 0xd);
6305 if ((val & 0x0c00) >> 10 != 0x1) {
6306 /* Capless ramp up clock control */
6307 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6308 }
6309 val = alc_read_coef_idx(codec, 0x17);
6310 if ((val & 0x01c0) >> 6 != 0x4) {
6311 /* Class D power on reset */
6312 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6313 }
6314 }
6315
6316 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6317 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6318
6319 val = alc_read_coef_idx(codec, 0x4); /* HP */
6320 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006321}
6322
6323/*
6324 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006325static int patch_alc269(struct hda_codec *codec)
6326{
6327 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006328 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006329
Takashi Iwai3de95172012-05-07 18:03:15 +02006330 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006331 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006332 return err;
6333
6334 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006335
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006336 alc_pick_fixup(codec, alc269_fixup_models,
6337 alc269_fixup_tbl, alc269_fixups);
6338 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6339
6340 alc_auto_parse_customize_define(codec);
6341
Takashi Iwai1d045db2011-07-07 18:23:21 +02006342 if (codec->vendor_id == 0x10ec0269) {
6343 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006344 switch (alc_get_coef0(codec) & 0x00f0) {
6345 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006346 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006347 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006348 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006349 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006350 break;
6351 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006352 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6353 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006354 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006355 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006356 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006357 case 0x0030:
6358 spec->codec_variant = ALC269_TYPE_ALC269VD;
6359 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006360 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006361 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006362 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006363 if (err < 0)
6364 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006365 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006366 alc269_fill_coef(codec);
6367 }
6368
Takashi Iwaia4297b52011-08-23 18:40:12 +02006369 /* automatic parse from the BIOS config */
6370 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006371 if (err < 0)
6372 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006373
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006374 if (!spec->no_analog && has_cdefine_beep(codec)) {
6375 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006376 if (err < 0)
6377 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006378 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006379 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006380
Takashi Iwai1d045db2011-07-07 18:23:21 +02006381 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006382#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006383 codec->patch_ops.resume = alc269_resume;
6384#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006385 spec->shutup = alc269_shutup;
6386
Takashi Iwai589876e2012-02-20 15:47:55 +01006387 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6388
Takashi Iwai1d045db2011-07-07 18:23:21 +02006389 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006390
6391 error:
6392 alc_free(codec);
6393 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006394}
6395
6396/*
6397 * ALC861
6398 */
6399
Takashi Iwai1d045db2011-07-07 18:23:21 +02006400static int alc861_parse_auto_config(struct hda_codec *codec)
6401{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006402 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006403 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6404 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006405}
6406
Takashi Iwai1d045db2011-07-07 18:23:21 +02006407/* Pin config fixes */
6408enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006409 ALC861_FIXUP_FSC_AMILO_PI1505,
6410 ALC861_FIXUP_AMP_VREF_0F,
6411 ALC861_FIXUP_NO_JACK_DETECT,
6412 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006413};
6414
Takashi Iwai31150f22012-01-30 10:54:08 +01006415/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6416static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6417 const struct alc_fixup *fix, int action)
6418{
6419 struct alc_spec *spec = codec->spec;
6420 unsigned int val;
6421
6422 if (action != ALC_FIXUP_ACT_INIT)
6423 return;
6424 val = snd_hda_codec_read(codec, 0x0f, 0,
6425 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6426 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6427 val |= AC_PINCTL_IN_EN;
6428 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006429 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006430 spec->keep_vref_in_automute = 1;
6431}
6432
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006433/* suppress the jack-detection */
6434static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6435 const struct alc_fixup *fix, int action)
6436{
6437 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6438 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006439}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006440
Takashi Iwai1d045db2011-07-07 18:23:21 +02006441static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006442 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006443 .type = ALC_FIXUP_PINS,
6444 .v.pins = (const struct alc_pincfg[]) {
6445 { 0x0b, 0x0221101f }, /* HP */
6446 { 0x0f, 0x90170310 }, /* speaker */
6447 { }
6448 }
6449 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006450 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006451 .type = ALC_FIXUP_FUNC,
6452 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006453 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006454 [ALC861_FIXUP_NO_JACK_DETECT] = {
6455 .type = ALC_FIXUP_FUNC,
6456 .v.func = alc_fixup_no_jack_detect,
6457 },
6458 [ALC861_FIXUP_ASUS_A6RP] = {
6459 .type = ALC_FIXUP_FUNC,
6460 .v.func = alc861_fixup_asus_amp_vref_0f,
6461 .chained = true,
6462 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6463 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006464};
6465
6466static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006467 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6468 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6469 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6470 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6471 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6472 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006473 {}
6474};
6475
6476/*
6477 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006478static int patch_alc861(struct hda_codec *codec)
6479{
6480 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006481 int err;
6482
Takashi Iwai3de95172012-05-07 18:03:15 +02006483 err = alc_alloc_spec(codec, 0x15);
6484 if (err < 0)
6485 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006486
Takashi Iwai3de95172012-05-07 18:03:15 +02006487 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006488
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006489 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6490 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006491
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006492 /* automatic parse from the BIOS config */
6493 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006494 if (err < 0)
6495 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006496
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006497 if (!spec->no_analog) {
6498 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006499 if (err < 0)
6500 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006501 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6502 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006503
Takashi Iwai1d045db2011-07-07 18:23:21 +02006504 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006505#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006506 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006507#endif
6508
Takashi Iwai589876e2012-02-20 15:47:55 +01006509 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6510
Takashi Iwai1d045db2011-07-07 18:23:21 +02006511 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006512
6513 error:
6514 alc_free(codec);
6515 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006516}
6517
6518/*
6519 * ALC861-VD support
6520 *
6521 * Based on ALC882
6522 *
6523 * In addition, an independent DAC
6524 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006525static int alc861vd_parse_auto_config(struct hda_codec *codec)
6526{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006527 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006528 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6529 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006530}
6531
Takashi Iwai1d045db2011-07-07 18:23:21 +02006532enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006533 ALC660VD_FIX_ASUS_GPIO1,
6534 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006535};
6536
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006537/* exclude VREF80 */
6538static void alc861vd_fixup_dallas(struct hda_codec *codec,
6539 const struct alc_fixup *fix, int action)
6540{
6541 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6542 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6543 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6544 }
6545}
6546
Takashi Iwai1d045db2011-07-07 18:23:21 +02006547static const struct alc_fixup alc861vd_fixups[] = {
6548 [ALC660VD_FIX_ASUS_GPIO1] = {
6549 .type = ALC_FIXUP_VERBS,
6550 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006551 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006552 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6553 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6554 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6555 { }
6556 }
6557 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006558 [ALC861VD_FIX_DALLAS] = {
6559 .type = ALC_FIXUP_FUNC,
6560 .v.func = alc861vd_fixup_dallas,
6561 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006562};
6563
6564static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006565 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006566 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006567 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006568 {}
6569};
6570
Takashi Iwai1d045db2011-07-07 18:23:21 +02006571/*
6572 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006573static int patch_alc861vd(struct hda_codec *codec)
6574{
6575 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006576 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006577
Takashi Iwai3de95172012-05-07 18:03:15 +02006578 err = alc_alloc_spec(codec, 0x0b);
6579 if (err < 0)
6580 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006581
Takashi Iwai3de95172012-05-07 18:03:15 +02006582 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006583
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006584 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6585 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006586
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006587 /* automatic parse from the BIOS config */
6588 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006589 if (err < 0)
6590 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006591
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006592 if (!spec->no_analog) {
6593 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006594 if (err < 0)
6595 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006596 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6597 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006598
Takashi Iwai1d045db2011-07-07 18:23:21 +02006599 codec->patch_ops = alc_patch_ops;
6600
Takashi Iwai1d045db2011-07-07 18:23:21 +02006601 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006602
Takashi Iwai589876e2012-02-20 15:47:55 +01006603 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6604
Takashi Iwai1d045db2011-07-07 18:23:21 +02006605 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006606
6607 error:
6608 alc_free(codec);
6609 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006610}
6611
6612/*
6613 * ALC662 support
6614 *
6615 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6616 * configuration. Each pin widget can choose any input DACs and a mixer.
6617 * Each ADC is connected from a mixer of all inputs. This makes possible
6618 * 6-channel independent captures.
6619 *
6620 * In addition, an independent DAC for the multi-playback (not used in this
6621 * driver yet).
6622 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006623
6624/*
6625 * BIOS auto configuration
6626 */
6627
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006628static int alc662_parse_auto_config(struct hda_codec *codec)
6629{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006630 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006631 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6632 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6633 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006634
Kailang Yang6227cdc2010-02-25 08:36:52 +01006635 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6636 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006637 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006638 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006639 ssids = alc662_ssids;
6640 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006641}
6642
Todd Broch6be79482010-12-07 16:51:05 -08006643static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006644 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006645{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006646 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006647 return;
Todd Broch6be79482010-12-07 16:51:05 -08006648 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6649 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6650 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6651 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6652 (0 << AC_AMPCAP_MUTE_SHIFT)))
6653 printk(KERN_WARNING
6654 "hda_codec: failed to override amp caps for NID 0x2\n");
6655}
6656
David Henningsson6cb3b702010-09-09 08:51:44 +02006657enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006658 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006659 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006660 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006661 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006662 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006663 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006664 ALC662_FIXUP_ASUS_MODE1,
6665 ALC662_FIXUP_ASUS_MODE2,
6666 ALC662_FIXUP_ASUS_MODE3,
6667 ALC662_FIXUP_ASUS_MODE4,
6668 ALC662_FIXUP_ASUS_MODE5,
6669 ALC662_FIXUP_ASUS_MODE6,
6670 ALC662_FIXUP_ASUS_MODE7,
6671 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006672 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006673 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006674 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006675};
6676
6677static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006678 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006679 .type = ALC_FIXUP_PINS,
6680 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006681 { 0x15, 0x99130112 }, /* subwoofer */
6682 { }
6683 }
6684 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006685 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006686 .type = ALC_FIXUP_PINS,
6687 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006688 { 0x17, 0x99130112 }, /* subwoofer */
6689 { }
6690 }
6691 },
Todd Broch6be79482010-12-07 16:51:05 -08006692 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006693 .type = ALC_FIXUP_FUNC,
6694 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006695 },
6696 [ALC662_FIXUP_CZC_P10T] = {
6697 .type = ALC_FIXUP_VERBS,
6698 .v.verbs = (const struct hda_verb[]) {
6699 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6700 {}
6701 }
6702 },
David Henningsson94024cd2011-04-29 14:10:55 +02006703 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006704 .type = ALC_FIXUP_FUNC,
6705 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006706 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006707 [ALC662_FIXUP_HP_RP5800] = {
6708 .type = ALC_FIXUP_PINS,
6709 .v.pins = (const struct alc_pincfg[]) {
6710 { 0x14, 0x0221201f }, /* HP out */
6711 { }
6712 },
6713 .chained = true,
6714 .chain_id = ALC662_FIXUP_SKU_IGNORE
6715 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006716 [ALC662_FIXUP_ASUS_MODE1] = {
6717 .type = ALC_FIXUP_PINS,
6718 .v.pins = (const struct alc_pincfg[]) {
6719 { 0x14, 0x99130110 }, /* speaker */
6720 { 0x18, 0x01a19c20 }, /* mic */
6721 { 0x19, 0x99a3092f }, /* int-mic */
6722 { 0x21, 0x0121401f }, /* HP out */
6723 { }
6724 },
6725 .chained = true,
6726 .chain_id = ALC662_FIXUP_SKU_IGNORE
6727 },
6728 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006729 .type = ALC_FIXUP_PINS,
6730 .v.pins = (const struct alc_pincfg[]) {
6731 { 0x14, 0x99130110 }, /* speaker */
6732 { 0x18, 0x01a19820 }, /* mic */
6733 { 0x19, 0x99a3092f }, /* int-mic */
6734 { 0x1b, 0x0121401f }, /* HP out */
6735 { }
6736 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006737 .chained = true,
6738 .chain_id = ALC662_FIXUP_SKU_IGNORE
6739 },
6740 [ALC662_FIXUP_ASUS_MODE3] = {
6741 .type = ALC_FIXUP_PINS,
6742 .v.pins = (const struct alc_pincfg[]) {
6743 { 0x14, 0x99130110 }, /* speaker */
6744 { 0x15, 0x0121441f }, /* HP */
6745 { 0x18, 0x01a19840 }, /* mic */
6746 { 0x19, 0x99a3094f }, /* int-mic */
6747 { 0x21, 0x01211420 }, /* HP2 */
6748 { }
6749 },
6750 .chained = true,
6751 .chain_id = ALC662_FIXUP_SKU_IGNORE
6752 },
6753 [ALC662_FIXUP_ASUS_MODE4] = {
6754 .type = ALC_FIXUP_PINS,
6755 .v.pins = (const struct alc_pincfg[]) {
6756 { 0x14, 0x99130110 }, /* speaker */
6757 { 0x16, 0x99130111 }, /* speaker */
6758 { 0x18, 0x01a19840 }, /* mic */
6759 { 0x19, 0x99a3094f }, /* int-mic */
6760 { 0x21, 0x0121441f }, /* HP */
6761 { }
6762 },
6763 .chained = true,
6764 .chain_id = ALC662_FIXUP_SKU_IGNORE
6765 },
6766 [ALC662_FIXUP_ASUS_MODE5] = {
6767 .type = ALC_FIXUP_PINS,
6768 .v.pins = (const struct alc_pincfg[]) {
6769 { 0x14, 0x99130110 }, /* speaker */
6770 { 0x15, 0x0121441f }, /* HP */
6771 { 0x16, 0x99130111 }, /* speaker */
6772 { 0x18, 0x01a19840 }, /* mic */
6773 { 0x19, 0x99a3094f }, /* int-mic */
6774 { }
6775 },
6776 .chained = true,
6777 .chain_id = ALC662_FIXUP_SKU_IGNORE
6778 },
6779 [ALC662_FIXUP_ASUS_MODE6] = {
6780 .type = ALC_FIXUP_PINS,
6781 .v.pins = (const struct alc_pincfg[]) {
6782 { 0x14, 0x99130110 }, /* speaker */
6783 { 0x15, 0x01211420 }, /* HP2 */
6784 { 0x18, 0x01a19840 }, /* mic */
6785 { 0x19, 0x99a3094f }, /* int-mic */
6786 { 0x1b, 0x0121441f }, /* HP */
6787 { }
6788 },
6789 .chained = true,
6790 .chain_id = ALC662_FIXUP_SKU_IGNORE
6791 },
6792 [ALC662_FIXUP_ASUS_MODE7] = {
6793 .type = ALC_FIXUP_PINS,
6794 .v.pins = (const struct alc_pincfg[]) {
6795 { 0x14, 0x99130110 }, /* speaker */
6796 { 0x17, 0x99130111 }, /* speaker */
6797 { 0x18, 0x01a19840 }, /* mic */
6798 { 0x19, 0x99a3094f }, /* int-mic */
6799 { 0x1b, 0x01214020 }, /* HP */
6800 { 0x21, 0x0121401f }, /* HP */
6801 { }
6802 },
6803 .chained = true,
6804 .chain_id = ALC662_FIXUP_SKU_IGNORE
6805 },
6806 [ALC662_FIXUP_ASUS_MODE8] = {
6807 .type = ALC_FIXUP_PINS,
6808 .v.pins = (const struct alc_pincfg[]) {
6809 { 0x14, 0x99130110 }, /* speaker */
6810 { 0x12, 0x99a30970 }, /* int-mic */
6811 { 0x15, 0x01214020 }, /* HP */
6812 { 0x17, 0x99130111 }, /* speaker */
6813 { 0x18, 0x01a19840 }, /* mic */
6814 { 0x21, 0x0121401f }, /* HP */
6815 { }
6816 },
6817 .chained = true,
6818 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006819 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006820 [ALC662_FIXUP_NO_JACK_DETECT] = {
6821 .type = ALC_FIXUP_FUNC,
6822 .v.func = alc_fixup_no_jack_detect,
6823 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006824 [ALC662_FIXUP_ZOTAC_Z68] = {
6825 .type = ALC_FIXUP_PINS,
6826 .v.pins = (const struct alc_pincfg[]) {
6827 { 0x1b, 0x02214020 }, /* Front HP */
6828 { }
6829 }
6830 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006831 [ALC662_FIXUP_INV_DMIC] = {
6832 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006833 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006834 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006835};
6836
Takashi Iwaia9111322011-05-02 11:30:18 +02006837static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006838 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006839 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006840 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006841 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006842 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006843 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006844 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006845 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006846 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006847 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006848 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006849 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006850 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006851
6852#if 0
6853 /* Below is a quirk table taken from the old code.
6854 * Basically the device should work as is without the fixup table.
6855 * If BIOS doesn't give a proper info, enable the corresponding
6856 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006857 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006858 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6859 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6860 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6861 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6862 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6863 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6864 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6865 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6866 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6867 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6868 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6869 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6870 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6871 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6872 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6873 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6874 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6875 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6876 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6877 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6878 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6879 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6880 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6881 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6882 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6883 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6884 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6885 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6886 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6887 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6888 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6889 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6890 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6891 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6892 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6893 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6894 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6895 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6896 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6897 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6898 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6899 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6900 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6901 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6902 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6903 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6904 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6905 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6906 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6907 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6908#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006909 {}
6910};
6911
Todd Broch6be79482010-12-07 16:51:05 -08006912static const struct alc_model_fixup alc662_fixup_models[] = {
6913 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006914 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6915 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6916 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6917 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6918 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6919 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6920 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6921 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006922 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08006923 {}
6924};
David Henningsson6cb3b702010-09-09 08:51:44 +02006925
Kailang Yang8663ff72012-06-29 09:35:52 +02006926static void alc662_fill_coef(struct hda_codec *codec)
6927{
6928 int val, coef;
6929
6930 coef = alc_get_coef0(codec);
6931
6932 switch (codec->vendor_id) {
6933 case 0x10ec0662:
6934 if ((coef & 0x00f0) == 0x0030) {
6935 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
6936 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
6937 }
6938 break;
6939 case 0x10ec0272:
6940 case 0x10ec0273:
6941 case 0x10ec0663:
6942 case 0x10ec0665:
6943 case 0x10ec0670:
6944 case 0x10ec0671:
6945 case 0x10ec0672:
6946 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
6947 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6948 break;
6949 }
6950}
David Henningsson6cb3b702010-09-09 08:51:44 +02006951
Takashi Iwai1d045db2011-07-07 18:23:21 +02006952/*
6953 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006954static int patch_alc662(struct hda_codec *codec)
6955{
6956 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006957 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006958
Takashi Iwai3de95172012-05-07 18:03:15 +02006959 err = alc_alloc_spec(codec, 0x0b);
6960 if (err < 0)
6961 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006962
Takashi Iwai3de95172012-05-07 18:03:15 +02006963 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006964
Takashi Iwai53c334a2011-08-23 18:27:14 +02006965 /* handle multiple HPs as is */
6966 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6967
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006968 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6969
Kailang Yang8663ff72012-06-29 09:35:52 +02006970 spec->init_hook = alc662_fill_coef;
6971 alc662_fill_coef(codec);
6972
Takashi Iwai8e5a0502012-06-21 15:49:33 +02006973 alc_pick_fixup(codec, alc662_fixup_models,
6974 alc662_fixup_tbl, alc662_fixups);
6975 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6976
6977 alc_auto_parse_customize_define(codec);
6978
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006979 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006980 codec->bus->pci->subsystem_vendor == 0x1025 &&
6981 spec->cdefine.platform_type == 1) {
6982 if (alc_codec_rename(codec, "ALC272X") < 0)
6983 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006984 }
Kailang Yang274693f2009-12-03 10:07:50 +01006985
Takashi Iwaib9c51062011-08-24 18:08:07 +02006986 /* automatic parse from the BIOS config */
6987 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006988 if (err < 0)
6989 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006990
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006991 if (!spec->no_analog && has_cdefine_beep(codec)) {
6992 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006993 if (err < 0)
6994 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006995 switch (codec->vendor_id) {
6996 case 0x10ec0662:
6997 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6998 break;
6999 case 0x10ec0272:
7000 case 0x10ec0663:
7001 case 0x10ec0665:
7002 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7003 break;
7004 case 0x10ec0273:
7005 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7006 break;
7007 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007008 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007009
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007010 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007011 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007012
Takashi Iwai589876e2012-02-20 15:47:55 +01007013 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7014
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007015 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007016
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007017 error:
7018 alc_free(codec);
7019 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007020}
7021
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007022/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007023 * ALC680 support
7024 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007025
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007026static int alc680_parse_auto_config(struct hda_codec *codec)
7027{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007028 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007029}
7030
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007031/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007032 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007033static int patch_alc680(struct hda_codec *codec)
7034{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007035 int err;
7036
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007037 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007038 err = alc_alloc_spec(codec, 0);
7039 if (err < 0)
7040 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007041
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007042 /* automatic parse from the BIOS config */
7043 err = alc680_parse_auto_config(codec);
7044 if (err < 0) {
7045 alc_free(codec);
7046 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007047 }
7048
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007049 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007050
7051 return 0;
7052}
7053
7054/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007055 * patch entries
7056 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007057static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007058 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007060 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007061 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007062 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007063 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007064 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007065 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007066 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007067 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007068 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007069 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007070 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
7071 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007072 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007073 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007074 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7075 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7076 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007077 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007078 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007079 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7080 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007081 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7082 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007083 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007084 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007085 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007086 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007087 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007088 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007089 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007090 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007091 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007092 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007093 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007094 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007095 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007096 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007097 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007098 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007099 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007100 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007101 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007102 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007103 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007104 {} /* terminator */
7105};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007106
7107MODULE_ALIAS("snd-hda-codec-id:10ec*");
7108
7109MODULE_LICENSE("GPL");
7110MODULE_DESCRIPTION("Realtek HD-audio codec");
7111
7112static struct hda_codec_preset_list realtek_list = {
7113 .preset = snd_hda_preset_realtek,
7114 .owner = THIS_MODULE,
7115};
7116
7117static int __init patch_realtek_init(void)
7118{
7119 return snd_hda_add_codec_preset(&realtek_list);
7120}
7121
7122static void __exit patch_realtek_exit(void)
7123{
7124 snd_hda_delete_codec_preset(&realtek_list);
7125}
7126
7127module_init(patch_realtek_init)
7128module_exit(patch_realtek_exit)