blob: d11fd0160748889ac829f523fb9200a02af7eed2 [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);
177 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100178#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500179 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100180#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200181 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200182 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100183
Takashi Iwai834be882006-03-01 14:16:17 +0100184 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200185 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200186 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200187 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200188 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200189 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200190 unsigned int automute_speaker:1; /* automute speaker outputs */
191 unsigned int automute_lo:1; /* automute LO outputs */
192 unsigned int detect_hp:1; /* Headphone detection enabled */
193 unsigned int detect_lo:1; /* Line-out detection enabled */
194 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
195 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100196 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200197
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100198 /* other flags */
199 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200200 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100201 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200202 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200203 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100204 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200205 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
206 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
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 Iwaicb53c622007-08-10 17:21:45 +0200218#ifdef CONFIG_SND_HDA_POWER_SAVE
219 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
Takashi Iwai21268962011-07-07 15:01:13 +0200306/* select the given imux item; either unmute exclusively or select the route */
307static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
308 unsigned int idx, bool force)
309{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100311 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100312 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100313 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200314 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Takashi Iwai5803a322012-02-21 11:59:45 +0100316 if (!spec->input_mux)
317 return 0;
318
Takashi Iwaicd896c32008-11-18 12:36:33 +0100319 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
320 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100321 if (!imux->num_items && mux_idx > 0)
322 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100323 if (!imux->num_items)
324 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100325
Takashi Iwai21268962011-07-07 15:01:13 +0200326 if (idx >= imux->num_items)
327 idx = imux->num_items - 1;
328 if (spec->cur_mux[adc_idx] == idx && !force)
329 return 0;
330 spec->cur_mux[adc_idx] = idx;
331
Takashi Iwai24de1832011-11-07 17:13:39 +0100332 /* for shared I/O, change the pin-control accordingly */
333 if (spec->shared_mic_hp) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200334 unsigned int val;
335 hda_nid_t pin = spec->autocfg.inputs[1].pin;
Takashi Iwai24de1832011-11-07 17:13:39 +0100336 /* NOTE: this assumes that there are only two inputs, the
337 * first is the real internal mic and the second is HP jack.
338 */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200339 if (spec->cur_mux[adc_idx])
Takashi Iwai47408602012-04-20 13:06:53 +0200340 val = snd_hda_get_default_vref(codec, pin) | PIN_IN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200341 else
342 val = PIN_HP;
343 snd_hda_set_pin_ctl(codec, pin, val);
Takashi Iwai24de1832011-11-07 17:13:39 +0100344 spec->automute_speaker = !spec->cur_mux[adc_idx];
345 call_update_outputs(codec);
346 }
347
Takashi Iwai21268962011-07-07 15:01:13 +0200348 if (spec->dyn_adc_switch) {
349 alc_dyn_adc_pcm_resetup(codec, idx);
350 adc_idx = spec->dyn_adc_idx[idx];
351 }
352
Takashi Iwai61071592011-11-23 07:52:15 +0100353 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200354
355 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200356 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100357 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200358 return 1;
359
Takashi Iwaia22d5432009-07-27 12:54:26 +0200360 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200361 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100362 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100363 int active = imux->items[idx].index;
364 for (i = 0; i < num_conns; i++) {
365 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
366 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100367 HDA_AMP_MUTE, v);
368 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100369 } else {
370 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200371 snd_hda_codec_write_cache(codec, nid, 0,
372 AC_VERB_SET_CONNECT_SEL,
373 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100374 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200375 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200376 return 1;
377}
378
379static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
380 struct snd_ctl_elem_value *ucontrol)
381{
382 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
383 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
384 return alc_mux_select(codec, adc_idx,
385 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100386}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100389 * set up the input pin config (depending on the given auto-pin type)
390 */
391static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
392 int auto_pin_type)
393{
394 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200395 if (auto_pin_type == AUTO_PIN_MIC)
396 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200397 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100398}
399
400/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200401 * Append the given mixer and verb elements for the later use
402 * The mixer array is referred in build_controls(), and init_verbs are
403 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100404 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200405static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100406{
407 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
408 return;
409 spec->mixers[spec->num_mixers++] = mix;
410}
411
Takashi Iwaid88897e2008-10-31 15:01:37 +0100412/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200413 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100414 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200415/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200416static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200417 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
418 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
419 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
420 { }
421};
422
Takashi Iwaia9111322011-05-02 11:30:18 +0200423static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200424 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
425 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
426 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
427 { }
428};
429
Takashi Iwaia9111322011-05-02 11:30:18 +0200430static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200431 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
432 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
433 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
434 { }
435};
436
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200437/*
438 * Fix hardware PLL issue
439 * On some codecs, the analog PLL gating control must be off while
440 * the default value is 1.
441 */
442static void alc_fix_pll(struct hda_codec *codec)
443{
444 struct alc_spec *spec = codec->spec;
445 unsigned int val;
446
447 if (!spec->pll_nid)
448 return;
449 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
450 spec->pll_coef_idx);
451 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
452 AC_VERB_GET_PROC_COEF, 0);
453 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
454 spec->pll_coef_idx);
455 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
456 val & ~(1 << spec->pll_coef_bit));
457}
458
459static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
460 unsigned int coef_idx, unsigned int coef_bit)
461{
462 struct alc_spec *spec = codec->spec;
463 spec->pll_nid = nid;
464 spec->pll_coef_idx = coef_idx;
465 spec->pll_coef_bit = coef_bit;
466 alc_fix_pll(codec);
467}
468
Takashi Iwai1d045db2011-07-07 18:23:21 +0200469/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200470 * Jack detections for HP auto-mute and mic-switch
471 */
472
473/* check each pin in the given array; returns true if any of them is plugged */
474static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200475{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200476 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200477
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200478 for (i = 0; i < num_pins; i++) {
479 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200480 if (!nid)
481 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200482 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200483 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200484 return present;
485}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200486
Takashi Iwai1d045db2011-07-07 18:23:21 +0200487/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200488static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200489 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200490{
491 struct alc_spec *spec = codec->spec;
492 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200493 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200494 int i;
495
496 for (i = 0; i < num_pins; i++) {
497 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100498 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200499 if (!nid)
500 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200501 switch (spec->automute_mode) {
502 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100503 /* don't reset VREF value in case it's controlling
504 * the amp (see alc861_fixup_asus_amp_vref_0f())
505 */
506 if (spec->keep_vref_in_automute) {
507 val = snd_hda_codec_read(codec, nid, 0,
508 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
509 val &= ~PIN_HP;
510 } else
511 val = 0;
512 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200513 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200514 break;
515 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200516 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200518 break;
519 case ALC_AUTOMUTE_MIXER:
520 nid = spec->automute_mixer_nid[i];
521 if (!nid)
522 break;
523 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200524 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200525 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200527 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200528 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200529 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200530}
531
David Henningsson42cf0d02011-09-20 12:04:56 +0200532/* Toggle outputs muting */
533static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200534{
535 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200536 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537
Takashi Iwaic0a20262011-06-10 15:28:15 +0200538 /* Control HP pins/amps depending on master_mute state;
539 * in general, HP pins/amps control should be enabled in all cases,
540 * but currently set only for master_mute, just to be safe
541 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100542 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
543 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200544 spec->autocfg.hp_pins, spec->master_mute, true);
545
David Henningsson42cf0d02011-09-20 12:04:56 +0200546 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200547 on = 0;
548 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200549 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200550 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200551 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200552 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200553
554 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 /* if LO is a copy of either HP or Speaker, don't need to handle it */
556 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
557 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200559 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 on = 0;
561 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200562 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200563 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200564 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200566}
567
David Henningsson42cf0d02011-09-20 12:04:56 +0200568static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200569{
570 struct alc_spec *spec = codec->spec;
571 if (spec->automute_hook)
572 spec->automute_hook(codec);
573 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200574 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200575}
576
Takashi Iwai1d045db2011-07-07 18:23:21 +0200577/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200578static void alc_hp_automute(struct hda_codec *codec)
579{
580 struct alc_spec *spec = codec->spec;
581
David Henningsson42cf0d02011-09-20 12:04:56 +0200582 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
584 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200585 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200586 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200587 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588}
589
Takashi Iwai1d045db2011-07-07 18:23:21 +0200590/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591static void alc_line_automute(struct hda_codec *codec)
592{
593 struct alc_spec *spec = codec->spec;
594
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200595 /* check LO jack only when it's different from HP */
596 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
597 return;
598
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200599 spec->line_jack_present =
600 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
601 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200602 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200603 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200604 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200605}
606
Takashi Iwai8d087c72011-06-28 12:45:47 +0200607#define get_connection_index(codec, mux, nid) \
608 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200609
Takashi Iwai1d045db2011-07-07 18:23:21 +0200610/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200611static void alc_mic_automute(struct hda_codec *codec)
612{
613 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200614 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200615
Takashi Iwai21268962011-07-07 15:01:13 +0200616 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200617 return;
618 if (snd_BUG_ON(!spec->adc_nids))
619 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200620 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200621 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200622
Takashi Iwai21268962011-07-07 15:01:13 +0200623 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
624 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
625 else if (spec->dock_mic_idx >= 0 &&
626 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
627 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
628 else
629 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200630}
631
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100632/* handle the specified unsol action (ALC_XXX_EVENT) */
633static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200634{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100635 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200636 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200637 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200638 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200639 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200640 alc_line_automute(codec);
641 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200642 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200643 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200644 break;
645 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200646 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200647}
648
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100649/* update the master volume per volume-knob's unsol event */
650static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
651{
652 unsigned int val;
653 struct snd_kcontrol *kctl;
654 struct snd_ctl_elem_value *uctl;
655
656 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
657 if (!kctl)
658 return;
659 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
660 if (!uctl)
661 return;
662 val = snd_hda_codec_read(codec, nid, 0,
663 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
664 val &= HDA_AMP_VOLMASK;
665 uctl->value.integer.value[0] = val;
666 uctl->value.integer.value[1] = val;
667 kctl->put(kctl, uctl);
668 kfree(uctl);
669}
670
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100671/* unsolicited event for HP jack sensing */
672static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
673{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100674 int action;
675
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100676 if (codec->vendor_id == 0x10ec0880)
677 res >>= 28;
678 else
679 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100680 action = snd_hda_jack_get_action(codec, res);
David Henningssone21af482012-03-05 11:38:46 +0100681 if (action == ALC_DCVOL_EVENT) {
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100682 /* Execute the dc-vol event here as it requires the NID
683 * but we don't pass NID to alc_exec_unsol_event().
684 * Once when we convert all static quirks to the auto-parser,
685 * this can be integerated into there.
686 */
687 struct hda_jack_tbl *jack;
688 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
689 if (jack)
690 alc_update_knob_master(codec, jack->nid);
691 return;
692 }
693 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100694}
695
Takashi Iwai1d045db2011-07-07 18:23:21 +0200696/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200697static void alc_inithook(struct hda_codec *codec)
698{
Takashi Iwaid922b512011-04-28 12:18:53 +0200699 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200700 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200701 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200702}
703
Kailang Yangf9423e72008-05-27 12:32:25 +0200704/* additional initialization for ALC888 variants */
705static void alc888_coef_init(struct hda_codec *codec)
706{
707 unsigned int tmp;
708
709 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
710 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
711 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100712 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200713 /* alc888S-VC */
714 snd_hda_codec_read(codec, 0x20, 0,
715 AC_VERB_SET_PROC_COEF, 0x830);
716 else
717 /* alc888-VB */
718 snd_hda_codec_read(codec, 0x20, 0,
719 AC_VERB_SET_PROC_COEF, 0x3030);
720}
721
Takashi Iwai1d045db2011-07-07 18:23:21 +0200722/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200723static void alc889_coef_init(struct hda_codec *codec)
724{
725 unsigned int tmp;
726
727 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
728 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
729 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
730 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
731}
732
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100733/* turn on/off EAPD control (only if available) */
734static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
735{
736 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
737 return;
738 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
739 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
740 on ? 2 : 0);
741}
742
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200743/* turn on/off EAPD controls of the codec */
744static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
745{
746 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200747 static hda_nid_t pins[] = {
748 0x0f, 0x10, 0x14, 0x15, 0
749 };
750 hda_nid_t *p;
751 for (p = pins; *p; p++)
752 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200753}
754
Takashi Iwai1c716152011-04-07 10:37:16 +0200755/* generic shutup callback;
756 * just turning off EPAD and a little pause for avoiding pop-noise
757 */
758static void alc_eapd_shutup(struct hda_codec *codec)
759{
760 alc_auto_setup_eapd(codec, false);
761 msleep(200);
762}
763
Takashi Iwai1d045db2011-07-07 18:23:21 +0200764/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200765static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200766{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200767 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200768
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200769 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770 switch (type) {
771 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200772 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
773 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200774 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200775 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
776 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200778 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
779 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200780 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200781 switch (codec->vendor_id) {
782 case 0x10ec0260:
783 snd_hda_codec_write(codec, 0x1a, 0,
784 AC_VERB_SET_COEF_INDEX, 7);
785 tmp = snd_hda_codec_read(codec, 0x1a, 0,
786 AC_VERB_GET_PROC_COEF, 0);
787 snd_hda_codec_write(codec, 0x1a, 0,
788 AC_VERB_SET_COEF_INDEX, 7);
789 snd_hda_codec_write(codec, 0x1a, 0,
790 AC_VERB_SET_PROC_COEF,
791 tmp | 0x2010);
792 break;
793 case 0x10ec0262:
794 case 0x10ec0880:
795 case 0x10ec0882:
796 case 0x10ec0883:
797 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100798 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100799 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200800 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200801 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200802 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200803 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200804 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100805#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200806 case 0x10ec0267:
807 case 0x10ec0268:
808 snd_hda_codec_write(codec, 0x20, 0,
809 AC_VERB_SET_COEF_INDEX, 7);
810 tmp = snd_hda_codec_read(codec, 0x20, 0,
811 AC_VERB_GET_PROC_COEF, 0);
812 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200813 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200814 snd_hda_codec_write(codec, 0x20, 0,
815 AC_VERB_SET_PROC_COEF,
816 tmp | 0x3000);
817 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100818#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200819 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200820 break;
821 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200822}
Kailang Yangea1fb292008-08-26 12:58:38 +0200823
Takashi Iwai1d045db2011-07-07 18:23:21 +0200824/*
825 * Auto-Mute mode mixer enum support
826 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200827static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_info *uinfo)
829{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831 struct alc_spec *spec = codec->spec;
832 static const char * const texts2[] = {
833 "Disabled", "Enabled"
834 };
835 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100836 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200837 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200838 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200839
840 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
841 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200842 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200843 uinfo->value.enumerated.items = 3;
844 texts = texts3;
845 } else {
846 uinfo->value.enumerated.items = 2;
847 texts = texts2;
848 }
849 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
850 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200851 strcpy(uinfo->value.enumerated.name,
852 texts[uinfo->value.enumerated.item]);
853 return 0;
854}
855
856static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
857 struct snd_ctl_elem_value *ucontrol)
858{
859 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
860 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200861 unsigned int val = 0;
862 if (spec->automute_speaker)
863 val++;
864 if (spec->automute_lo)
865 val++;
866
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200867 ucontrol->value.enumerated.item[0] = val;
868 return 0;
869}
870
871static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
872 struct snd_ctl_elem_value *ucontrol)
873{
874 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
875 struct alc_spec *spec = codec->spec;
876
877 switch (ucontrol->value.enumerated.item[0]) {
878 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200879 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200881 spec->automute_speaker = 0;
882 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200883 break;
884 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200885 if (spec->automute_speaker_possible) {
886 if (!spec->automute_lo && spec->automute_speaker)
887 return 0;
888 spec->automute_speaker = 1;
889 spec->automute_lo = 0;
890 } else if (spec->automute_lo_possible) {
891 if (spec->automute_lo)
892 return 0;
893 spec->automute_lo = 1;
894 } else
895 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200896 break;
897 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200898 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200899 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200900 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200901 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200902 spec->automute_speaker = 1;
903 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200904 break;
905 default:
906 return -EINVAL;
907 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200908 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909 return 1;
910}
911
Takashi Iwaia9111322011-05-02 11:30:18 +0200912static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200913 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
914 .name = "Auto-Mute Mode",
915 .info = alc_automute_mode_info,
916 .get = alc_automute_mode_get,
917 .put = alc_automute_mode_put,
918};
919
Takashi Iwai1d045db2011-07-07 18:23:21 +0200920static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
921{
922 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
923 return snd_array_new(&spec->kctls);
924}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200925
926static int alc_add_automute_mode_enum(struct hda_codec *codec)
927{
928 struct alc_spec *spec = codec->spec;
929 struct snd_kcontrol_new *knew;
930
931 knew = alc_kcontrol_new(spec);
932 if (!knew)
933 return -ENOMEM;
934 *knew = alc_automute_mode_enum;
935 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
936 if (!knew->name)
937 return -ENOMEM;
938 return 0;
939}
940
Takashi Iwai1d045db2011-07-07 18:23:21 +0200941/*
942 * Check the availability of HP/line-out auto-mute;
943 * Set up appropriately if really supported
944 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200945static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200946{
947 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200948 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200949 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200950 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200951
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200952 if (cfg->hp_pins[0])
953 present++;
954 if (cfg->line_out_pins[0])
955 present++;
956 if (cfg->speaker_pins[0])
957 present++;
958 if (present < 2) /* need two different output types */
959 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200960
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200961 if (!cfg->speaker_pins[0] &&
962 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200963 memcpy(cfg->speaker_pins, cfg->line_out_pins,
964 sizeof(cfg->speaker_pins));
965 cfg->speaker_outs = cfg->line_outs;
966 }
967
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200968 if (!cfg->hp_pins[0] &&
969 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200970 memcpy(cfg->hp_pins, cfg->line_out_pins,
971 sizeof(cfg->hp_pins));
972 cfg->hp_outs = cfg->line_outs;
973 }
974
David Henningsson42cf0d02011-09-20 12:04:56 +0200975 spec->automute_mode = ALC_AUTOMUTE_PIN;
976
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200977 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200978 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200979 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200980 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200981 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200982 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200983 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200984 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200985 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200986
David Henningsson42cf0d02011-09-20 12:04:56 +0200987 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
988 if (cfg->speaker_outs)
989 for (i = 0; i < cfg->line_outs; i++) {
990 hda_nid_t nid = cfg->line_out_pins[i];
991 if (!is_jack_detectable(codec, nid))
992 continue;
993 snd_printdd("realtek: Enable Line-Out "
994 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200995 snd_hda_jack_detect_enable(codec, nid,
996 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200997 spec->detect_lo = 1;
998 }
999 spec->automute_lo_possible = spec->detect_hp;
1000 }
1001
1002 spec->automute_speaker_possible = cfg->speaker_outs &&
1003 (spec->detect_hp || spec->detect_lo);
1004
1005 spec->automute_lo = spec->automute_lo_possible;
1006 spec->automute_speaker = spec->automute_speaker_possible;
1007
1008 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001009 /* create a control for automute mode */
1010 alc_add_automute_mode_enum(codec);
1011 spec->unsol_event = alc_sku_unsol_event;
1012 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001013}
1014
Takashi Iwai1d045db2011-07-07 18:23:21 +02001015/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001016static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1017{
1018 int i;
1019 for (i = 0; i < nums; i++)
1020 if (list[i] == nid)
1021 return i;
1022 return -1;
1023}
1024
Takashi Iwai1d045db2011-07-07 18:23:21 +02001025/* check whether dynamic ADC-switching is available */
1026static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1027{
1028 struct alc_spec *spec = codec->spec;
1029 struct hda_input_mux *imux = &spec->private_imux[0];
1030 int i, n, idx;
1031 hda_nid_t cap, pin;
1032
1033 if (imux != spec->input_mux) /* no dynamic imux? */
1034 return false;
1035
1036 for (n = 0; n < spec->num_adc_nids; n++) {
1037 cap = spec->private_capsrc_nids[n];
1038 for (i = 0; i < imux->num_items; i++) {
1039 pin = spec->imux_pins[i];
1040 if (!pin)
1041 return false;
1042 if (get_connection_index(codec, cap, pin) < 0)
1043 break;
1044 }
1045 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001046 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001047 }
1048
1049 for (i = 0; i < imux->num_items; i++) {
1050 pin = spec->imux_pins[i];
1051 for (n = 0; n < spec->num_adc_nids; n++) {
1052 cap = spec->private_capsrc_nids[n];
1053 idx = get_connection_index(codec, cap, pin);
1054 if (idx >= 0) {
1055 imux->items[i].index = idx;
1056 spec->dyn_adc_idx[i] = n;
1057 break;
1058 }
1059 }
1060 }
1061
1062 snd_printdd("realtek: enabling ADC switching\n");
1063 spec->dyn_adc_switch = 1;
1064 return true;
1065}
Takashi Iwai21268962011-07-07 15:01:13 +02001066
Takashi Iwai21268962011-07-07 15:01:13 +02001067/* check whether all auto-mic pins are valid; setup indices if OK */
1068static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1069{
1070 struct alc_spec *spec = codec->spec;
1071 const struct hda_input_mux *imux;
1072
1073 if (!spec->auto_mic)
1074 return false;
1075 if (spec->auto_mic_valid_imux)
1076 return true; /* already checked */
1077
1078 /* fill up imux indices */
1079 if (!alc_check_dyn_adc_switch(codec)) {
1080 spec->auto_mic = 0;
1081 return false;
1082 }
1083
1084 imux = spec->input_mux;
1085 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1086 spec->imux_pins, imux->num_items);
1087 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1088 spec->imux_pins, imux->num_items);
1089 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1090 spec->imux_pins, imux->num_items);
1091 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1092 spec->auto_mic = 0;
1093 return false; /* no corresponding imux */
1094 }
1095
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001096 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001097 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001098 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1099 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001100
1101 spec->auto_mic_valid_imux = 1;
1102 spec->auto_mic = 1;
1103 return true;
1104}
1105
Takashi Iwai1d045db2011-07-07 18:23:21 +02001106/*
1107 * Check the availability of auto-mic switch;
1108 * Set up if really supported
1109 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001110static void alc_init_auto_mic(struct hda_codec *codec)
1111{
1112 struct alc_spec *spec = codec->spec;
1113 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001114 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001115 int i;
1116
Takashi Iwai24de1832011-11-07 17:13:39 +01001117 if (spec->shared_mic_hp)
1118 return; /* no auto-mic for the shared I/O */
1119
Takashi Iwai21268962011-07-07 15:01:13 +02001120 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1121
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001122 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001123 for (i = 0; i < cfg->num_inputs; i++) {
1124 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001125 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001126 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001127 switch (snd_hda_get_input_pin_attr(defcfg)) {
1128 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001129 if (fixed)
1130 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001131 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1132 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001133 fixed = nid;
1134 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001135 case INPUT_PIN_ATTR_UNUSED:
1136 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001137 case INPUT_PIN_ATTR_DOCK:
1138 if (dock)
1139 return; /* already occupied */
1140 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1141 return; /* invalid type */
1142 dock = nid;
1143 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001144 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 if (ext)
1146 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001147 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1148 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001149 ext = nid;
1150 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001151 }
1152 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001153 if (!ext && dock) {
1154 ext = dock;
1155 dock = 0;
1156 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001157 if (!ext || !fixed)
1158 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001159 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001160 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001161 if (dock && !is_jack_detectable(codec, dock))
1162 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001163
1164 /* check imux indices */
1165 spec->ext_mic_pin = ext;
1166 spec->int_mic_pin = fixed;
1167 spec->dock_mic_pin = dock;
1168
1169 spec->auto_mic = 1;
1170 if (!alc_auto_mic_check_imux(codec))
1171 return;
1172
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001173 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1174 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001175 spec->unsol_event = alc_sku_unsol_event;
1176}
1177
Takashi Iwai1d045db2011-07-07 18:23:21 +02001178/* check the availabilities of auto-mute and auto-mic switches */
1179static void alc_auto_check_switches(struct hda_codec *codec)
1180{
David Henningsson42cf0d02011-09-20 12:04:56 +02001181 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001182 alc_init_auto_mic(codec);
1183}
1184
1185/*
1186 * Realtek SSID verification
1187 */
1188
David Henningsson90622912010-10-14 14:50:18 +02001189/* Could be any non-zero and even value. When used as fixup, tells
1190 * the driver to ignore any present sku defines.
1191 */
1192#define ALC_FIXUP_SKU_IGNORE (2)
1193
Takashi Iwai23d30f22012-05-07 17:17:32 +02001194static void alc_fixup_sku_ignore(struct hda_codec *codec,
1195 const struct hda_fixup *fix, int action)
1196{
1197 struct alc_spec *spec = codec->spec;
1198 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1199 spec->cdefine.fixup = 1;
1200 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1201 }
1202}
1203
Kailang Yangda00c242010-03-19 11:23:45 +01001204static int alc_auto_parse_customize_define(struct hda_codec *codec)
1205{
1206 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001207 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001208 struct alc_spec *spec = codec->spec;
1209
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001210 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1211
David Henningsson90622912010-10-14 14:50:18 +02001212 if (spec->cdefine.fixup) {
1213 ass = spec->cdefine.sku_cfg;
1214 if (ass == ALC_FIXUP_SKU_IGNORE)
1215 return -1;
1216 goto do_sku;
1217 }
1218
Kailang Yangda00c242010-03-19 11:23:45 +01001219 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001220 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001221 goto do_sku;
1222
1223 nid = 0x1d;
1224 if (codec->vendor_id == 0x10ec0260)
1225 nid = 0x17;
1226 ass = snd_hda_codec_get_pincfg(codec, nid);
1227
1228 if (!(ass & 1)) {
1229 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1230 codec->chip_name, ass);
1231 return -1;
1232 }
1233
1234 /* check sum */
1235 tmp = 0;
1236 for (i = 1; i < 16; i++) {
1237 if ((ass >> i) & 1)
1238 tmp++;
1239 }
1240 if (((ass >> 16) & 0xf) != tmp)
1241 return -1;
1242
1243 spec->cdefine.port_connectivity = ass >> 30;
1244 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1245 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1246 spec->cdefine.customization = ass >> 8;
1247do_sku:
1248 spec->cdefine.sku_cfg = ass;
1249 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1250 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1251 spec->cdefine.swap = (ass & 0x2) >> 1;
1252 spec->cdefine.override = ass & 0x1;
1253
1254 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1255 nid, spec->cdefine.sku_cfg);
1256 snd_printd("SKU: port_connectivity=0x%x\n",
1257 spec->cdefine.port_connectivity);
1258 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1259 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1260 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1261 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1262 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1263 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1264 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1265
1266 return 0;
1267}
1268
Takashi Iwai1d045db2011-07-07 18:23:21 +02001269/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001270static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1271{
Takashi Iwai21268962011-07-07 15:01:13 +02001272 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001273}
1274
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001275/* check subsystem ID and set up device-specific initialization;
1276 * return 1 if initialized, 0 if invalid SSID
1277 */
1278/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1279 * 31 ~ 16 : Manufacture ID
1280 * 15 ~ 8 : SKU ID
1281 * 7 ~ 0 : Assembly ID
1282 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1283 */
1284static int alc_subsystem_id(struct hda_codec *codec,
1285 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001286 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001287{
1288 unsigned int ass, tmp, i;
1289 unsigned nid;
1290 struct alc_spec *spec = codec->spec;
1291
David Henningsson90622912010-10-14 14:50:18 +02001292 if (spec->cdefine.fixup) {
1293 ass = spec->cdefine.sku_cfg;
1294 if (ass == ALC_FIXUP_SKU_IGNORE)
1295 return 0;
1296 goto do_sku;
1297 }
1298
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001299 ass = codec->subsystem_id & 0xffff;
1300 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1301 goto do_sku;
1302
1303 /* invalid SSID, check the special NID pin defcfg instead */
1304 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001305 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001306 * 29~21 : reserve
1307 * 20 : PCBEEP input
1308 * 19~16 : Check sum (15:1)
1309 * 15~1 : Custom
1310 * 0 : override
1311 */
1312 nid = 0x1d;
1313 if (codec->vendor_id == 0x10ec0260)
1314 nid = 0x17;
1315 ass = snd_hda_codec_get_pincfg(codec, nid);
1316 snd_printd("realtek: No valid SSID, "
1317 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001318 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001319 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001320 return 0;
1321 if ((ass >> 30) != 1) /* no physical connection */
1322 return 0;
1323
1324 /* check sum */
1325 tmp = 0;
1326 for (i = 1; i < 16; i++) {
1327 if ((ass >> i) & 1)
1328 tmp++;
1329 }
1330 if (((ass >> 16) & 0xf) != tmp)
1331 return 0;
1332do_sku:
1333 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1334 ass & 0xffff, codec->vendor_id);
1335 /*
1336 * 0 : override
1337 * 1 : Swap Jack
1338 * 2 : 0 --> Desktop, 1 --> Laptop
1339 * 3~5 : External Amplifier control
1340 * 7~6 : Reserved
1341 */
1342 tmp = (ass & 0x38) >> 3; /* external Amp control */
1343 switch (tmp) {
1344 case 1:
1345 spec->init_amp = ALC_INIT_GPIO1;
1346 break;
1347 case 3:
1348 spec->init_amp = ALC_INIT_GPIO2;
1349 break;
1350 case 7:
1351 spec->init_amp = ALC_INIT_GPIO3;
1352 break;
1353 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001354 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001355 spec->init_amp = ALC_INIT_DEFAULT;
1356 break;
1357 }
1358
1359 /* is laptop or Desktop and enable the function "Mute internal speaker
1360 * when the external headphone out jack is plugged"
1361 */
1362 if (!(ass & 0x8000))
1363 return 1;
1364 /*
1365 * 10~8 : Jack location
1366 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1367 * 14~13: Resvered
1368 * 15 : 1 --> enable the function "Mute internal speaker
1369 * when the external headphone out jack is plugged"
1370 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001371 if (!spec->autocfg.hp_pins[0] &&
1372 !(spec->autocfg.line_out_pins[0] &&
1373 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001374 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001375 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1376 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001377 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001378 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001379 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001380 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001381 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001382 else if (tmp == 3)
1383 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001384 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001385 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001386 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1387 spec->autocfg.line_outs))
1388 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001389 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001390 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001391 return 1;
1392}
Kailang Yangea1fb292008-08-26 12:58:38 +02001393
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001394/* Check the validity of ALC subsystem-id
1395 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1396static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001397{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001398 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001399 struct alc_spec *spec = codec->spec;
1400 snd_printd("realtek: "
1401 "Enable default setup for auto mode as fallback\n");
1402 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001403 }
Takashi Iwai21268962011-07-07 15:01:13 +02001404}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001405
Takashi Iwai41e41f12005-06-08 14:48:49 +02001406/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001407 * COEF access helper functions
1408 */
Kailang Yang274693f2009-12-03 10:07:50 +01001409static int alc_read_coef_idx(struct hda_codec *codec,
1410 unsigned int coef_idx)
1411{
1412 unsigned int val;
1413 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1414 coef_idx);
1415 val = snd_hda_codec_read(codec, 0x20, 0,
1416 AC_VERB_GET_PROC_COEF, 0);
1417 return val;
1418}
1419
Kailang Yang977ddd62010-09-15 10:02:29 +02001420static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1421 unsigned int coef_val)
1422{
1423 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1424 coef_idx);
1425 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1426 coef_val);
1427}
1428
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001429/* a special bypass for COEF 0; read the cached value at the second time */
1430static unsigned int alc_get_coef0(struct hda_codec *codec)
1431{
1432 struct alc_spec *spec = codec->spec;
1433 if (!spec->coef0)
1434 spec->coef0 = alc_read_coef_idx(codec, 0);
1435 return spec->coef0;
1436}
1437
Takashi Iwai1d045db2011-07-07 18:23:21 +02001438/*
1439 * Digital I/O handling
1440 */
1441
Takashi Iwai757899a2010-07-30 10:48:14 +02001442/* set right pin controls for digital I/O */
1443static void alc_auto_init_digital(struct hda_codec *codec)
1444{
1445 struct alc_spec *spec = codec->spec;
1446 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001447 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001448
1449 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1450 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001451 if (!pin)
1452 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001453 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001454 if (!i)
1455 dac = spec->multiout.dig_out_nid;
1456 else
1457 dac = spec->slave_dig_outs[i - 1];
1458 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1459 continue;
1460 snd_hda_codec_write(codec, dac, 0,
1461 AC_VERB_SET_AMP_GAIN_MUTE,
1462 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001463 }
1464 pin = spec->autocfg.dig_in_pin;
1465 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001466 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001467}
1468
1469/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1470static void alc_auto_parse_digital(struct hda_codec *codec)
1471{
1472 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001473 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001474 hda_nid_t dig_nid;
1475
1476 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001477 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001478 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001479 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001480 err = snd_hda_get_connections(codec,
1481 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001482 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001483 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001484 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001485 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001486 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001487 spec->multiout.dig_out_nid = dig_nid;
1488 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1489 } else {
1490 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001491 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001492 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001493 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001494 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001495 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001496 }
1497
1498 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001499 dig_nid = codec->start_nid;
1500 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1501 unsigned int wcaps = get_wcaps(codec, dig_nid);
1502 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1503 continue;
1504 if (!(wcaps & AC_WCAP_DIGITAL))
1505 continue;
1506 if (!(wcaps & AC_WCAP_CONN_LIST))
1507 continue;
1508 err = get_connection_index(codec, dig_nid,
1509 spec->autocfg.dig_in_pin);
1510 if (err >= 0) {
1511 spec->dig_in_nid = dig_nid;
1512 break;
1513 }
1514 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001515 }
1516}
1517
Takashi Iwaif95474e2007-07-10 00:47:43 +02001518/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001519 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001520 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001521static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1522 struct snd_ctl_elem_info *uinfo)
1523{
1524 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1525 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001526 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001527 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001528
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001529 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001530 if (spec->vol_in_capsrc)
1531 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1532 else
1533 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1534 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001535 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001536 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001537 return err;
1538}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001540static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1541 unsigned int size, unsigned int __user *tlv)
1542{
1543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1544 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001545 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001546 int err;
1547
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001548 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001549 if (spec->vol_in_capsrc)
1550 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1551 else
1552 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1553 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001554 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001555 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001556 return err;
1557}
1558
1559typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1560 struct snd_ctl_elem_value *ucontrol);
1561
1562static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1563 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001564 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001565{
1566 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1567 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001568 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001569
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001570 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001571 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001572 for (i = 0; i < spec->num_adc_nids; i++) {
1573 kcontrol->private_value =
1574 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1575 3, 0, HDA_INPUT);
1576 err = func(kcontrol, ucontrol);
1577 if (err < 0)
1578 goto error;
1579 }
1580 } else {
1581 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001582 if (spec->vol_in_capsrc)
1583 kcontrol->private_value =
1584 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1585 3, 0, HDA_OUTPUT);
1586 else
1587 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001588 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1589 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001590 err = func(kcontrol, ucontrol);
1591 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001592 if (err >= 0 && is_put)
1593 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001594 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001595 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001596 return err;
1597}
1598
1599static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1600 struct snd_ctl_elem_value *ucontrol)
1601{
1602 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001603 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001604}
1605
1606static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1607 struct snd_ctl_elem_value *ucontrol)
1608{
1609 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001610 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001611}
1612
1613/* capture mixer elements */
1614#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1615
1616static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1618{
1619 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001620 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001621}
1622
1623static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_value *ucontrol)
1625{
1626 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001627 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001628}
1629
Takashi Iwaia23b6882009-03-23 15:21:36 +01001630#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001631 { \
1632 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1633 .name = "Capture Switch", \
1634 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1635 .count = num, \
1636 .info = alc_cap_sw_info, \
1637 .get = alc_cap_sw_get, \
1638 .put = alc_cap_sw_put, \
1639 }, \
1640 { \
1641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1642 .name = "Capture Volume", \
1643 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1644 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1645 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1646 .count = num, \
1647 .info = alc_cap_vol_info, \
1648 .get = alc_cap_vol_get, \
1649 .put = alc_cap_vol_put, \
1650 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001651 }
1652
1653#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001654 { \
1655 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1656 /* .name = "Capture Source", */ \
1657 .name = "Input Source", \
1658 .count = num, \
1659 .info = alc_mux_enum_info, \
1660 .get = alc_mux_enum_get, \
1661 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001662 }
1663
1664#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001665static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001666 _DEFINE_CAPMIX(num), \
1667 _DEFINE_CAPSRC(num), \
1668 { } /* end */ \
1669}
1670
1671#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001672static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001673 _DEFINE_CAPMIX(num), \
1674 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001675}
1676
1677/* up to three ADCs */
1678DEFINE_CAPMIX(1);
1679DEFINE_CAPMIX(2);
1680DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001681DEFINE_CAPMIX_NOSRC(1);
1682DEFINE_CAPMIX_NOSRC(2);
1683DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001684
1685/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001686 * Inverted digital-mic handling
1687 *
1688 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1689 * gives the additional mute only to the right channel of the digital mic
1690 * capture stream. This is a workaround for avoiding the almost silence
1691 * by summing the stereo stream from some (known to be ForteMedia)
1692 * digital mic unit.
1693 *
1694 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1695 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1696 * without caching so that the cache can still keep the original value.
1697 * The cached value is then restored when the flag is set off or any other
1698 * than d-mic is used as the current input source.
1699 */
1700static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1701{
1702 struct alc_spec *spec = codec->spec;
1703 int i;
1704
1705 if (!spec->inv_dmic_fixup)
1706 return;
1707 if (!spec->inv_dmic_muted && !force)
1708 return;
1709 for (i = 0; i < spec->num_adc_nids; i++) {
1710 int src = spec->dyn_adc_switch ? 0 : i;
1711 bool dmic_fixup = false;
1712 hda_nid_t nid;
1713 int parm, dir, v;
1714
1715 if (spec->inv_dmic_muted &&
1716 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1717 dmic_fixup = true;
1718 if (!dmic_fixup && !force)
1719 continue;
1720 if (spec->vol_in_capsrc) {
1721 nid = spec->capsrc_nids[i];
1722 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1723 dir = HDA_OUTPUT;
1724 } else {
1725 nid = spec->adc_nids[i];
1726 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1727 dir = HDA_INPUT;
1728 }
1729 /* we care only right channel */
1730 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1731 if (v & 0x80) /* if already muted, we don't need to touch */
1732 continue;
1733 if (dmic_fixup) /* add mute for d-mic */
1734 v |= 0x80;
1735 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1736 parm | v);
1737 }
1738}
1739
1740static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1741 struct snd_ctl_elem_value *ucontrol)
1742{
1743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1744 struct alc_spec *spec = codec->spec;
1745
1746 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1747 return 0;
1748}
1749
1750static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1751 struct snd_ctl_elem_value *ucontrol)
1752{
1753 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1754 struct alc_spec *spec = codec->spec;
1755 unsigned int val = !ucontrol->value.integer.value[0];
1756
1757 if (val == spec->inv_dmic_muted)
1758 return 0;
1759 spec->inv_dmic_muted = val;
1760 alc_inv_dmic_sync(codec, true);
1761 return 0;
1762}
1763
1764static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1765 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1766 .info = snd_ctl_boolean_mono_info,
1767 .get = alc_inv_dmic_sw_get,
1768 .put = alc_inv_dmic_sw_put,
1769};
1770
1771static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1772{
1773 struct alc_spec *spec = codec->spec;
1774 struct snd_kcontrol_new *knew = alc_kcontrol_new(spec);
1775 if (!knew)
1776 return -ENOMEM;
1777 *knew = alc_inv_dmic_sw;
1778 knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL);
1779 if (!knew->name)
1780 return -ENOMEM;
1781 spec->inv_dmic_fixup = 1;
1782 spec->inv_dmic_muted = 0;
1783 spec->inv_dmic_pin = nid;
1784 return 0;
1785}
1786
1787/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001788 * virtual master controls
1789 */
1790
1791/*
1792 * slave controls for virtual master
1793 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001794static const char * const alc_slave_pfxs[] = {
1795 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001796 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001797 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001798 NULL,
1799};
1800
1801/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001802 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001804
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001805#define NID_MAPPING (-1)
1806
1807#define SUBDEV_SPEAKER_ (0 << 6)
1808#define SUBDEV_HP_ (1 << 6)
1809#define SUBDEV_LINE_ (2 << 6)
1810#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1811#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1812#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1813
Takashi Iwai603c4012008-07-30 15:01:44 +02001814static void alc_free_kctls(struct hda_codec *codec);
1815
Takashi Iwai67d634c2009-11-16 15:35:59 +01001816#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001817/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001818static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001819 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001820 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001821 { } /* end */
1822};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001823#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001824
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001825static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826{
1827 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001828 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001829 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001830 int i, j, err;
1831 unsigned int u;
1832 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834 for (i = 0; i < spec->num_mixers; i++) {
1835 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1836 if (err < 0)
1837 return err;
1838 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001839 if (spec->cap_mixer) {
1840 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1841 if (err < 0)
1842 return err;
1843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001845 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001846 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001847 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 if (err < 0)
1849 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001850 if (!spec->no_analog) {
1851 err = snd_hda_create_spdif_share_sw(codec,
1852 &spec->multiout);
1853 if (err < 0)
1854 return err;
1855 spec->multiout.share_spdif = 1;
1856 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 }
1858 if (spec->dig_in_nid) {
1859 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1860 if (err < 0)
1861 return err;
1862 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001863
Takashi Iwai67d634c2009-11-16 15:35:59 +01001864#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001865 /* create beep controls if needed */
1866 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001867 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001868 for (knew = alc_beep_mixer; knew->name; knew++) {
1869 struct snd_kcontrol *kctl;
1870 kctl = snd_ctl_new1(knew, codec);
1871 if (!kctl)
1872 return -ENOMEM;
1873 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001874 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001875 if (err < 0)
1876 return err;
1877 }
1878 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001879#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001880
Takashi Iwai2134ea42008-01-10 16:53:55 +01001881 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001882 if (!spec->no_analog &&
1883 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001884 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001885 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001886 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001887 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001888 vmaster_tlv, alc_slave_pfxs,
1889 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001890 if (err < 0)
1891 return err;
1892 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001893 if (!spec->no_analog &&
1894 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001895 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1896 NULL, alc_slave_pfxs,
1897 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001898 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001899 if (err < 0)
1900 return err;
1901 }
1902
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001903 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001904 if (spec->capsrc_nids || spec->adc_nids) {
1905 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1906 if (!kctl)
1907 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1908 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001909 err = snd_hda_add_nid(codec, kctl, i,
1910 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001911 if (err < 0)
1912 return err;
1913 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001914 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001915 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001916 const char *kname = kctl ? kctl->id.name : NULL;
1917 for (knew = spec->cap_mixer; knew->name; knew++) {
1918 if (kname && strcmp(knew->name, kname) == 0)
1919 continue;
1920 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1921 for (i = 0; kctl && i < kctl->count; i++) {
1922 err = snd_hda_add_nid(codec, kctl, i,
1923 spec->adc_nids[i]);
1924 if (err < 0)
1925 return err;
1926 }
1927 }
1928 }
1929
1930 /* other nid->control mapping */
1931 for (i = 0; i < spec->num_mixers; i++) {
1932 for (knew = spec->mixers[i]; knew->name; knew++) {
1933 if (knew->iface != NID_MAPPING)
1934 continue;
1935 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1936 if (kctl == NULL)
1937 continue;
1938 u = knew->subdevice;
1939 for (j = 0; j < 4; j++, u >>= 8) {
1940 nid = u & 0x3f;
1941 if (nid == 0)
1942 continue;
1943 switch (u & 0xc0) {
1944 case SUBDEV_SPEAKER_:
1945 nid = spec->autocfg.speaker_pins[nid];
1946 break;
1947 case SUBDEV_LINE_:
1948 nid = spec->autocfg.line_out_pins[nid];
1949 break;
1950 case SUBDEV_HP_:
1951 nid = spec->autocfg.hp_pins[nid];
1952 break;
1953 default:
1954 continue;
1955 }
1956 err = snd_hda_add_nid(codec, kctl, 0, nid);
1957 if (err < 0)
1958 return err;
1959 }
1960 u = knew->private_value;
1961 for (j = 0; j < 4; j++, u >>= 8) {
1962 nid = u & 0xff;
1963 if (nid == 0)
1964 continue;
1965 err = snd_hda_add_nid(codec, kctl, 0, nid);
1966 if (err < 0)
1967 return err;
1968 }
1969 }
1970 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001971
1972 alc_free_kctls(codec); /* no longer needed */
1973
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001974 return 0;
1975}
1976
1977static int alc_build_controls(struct hda_codec *codec)
1978{
1979 struct alc_spec *spec = codec->spec;
1980 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001981 if (err < 0)
1982 return err;
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001983 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1984 if (err < 0)
1985 return err;
1986 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1987 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988}
1989
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001990
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001992 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001993 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001994
Takashi Iwai584c0c42011-03-10 12:51:11 +01001995static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001996static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998static int alc_init(struct hda_codec *codec)
1999{
2000 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002001
Takashi Iwai546bb672012-03-07 08:37:19 +01002002 if (spec->init_hook)
2003 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002004
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002005 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002006 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002007
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002008 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002009 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002010 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002011
Takashi Iwai58701122011-01-13 15:41:45 +01002012 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2013
Takashi Iwai01a61e12011-10-28 00:03:22 +02002014 snd_hda_jack_report_sync(codec);
2015
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002016 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 return 0;
2018}
2019
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002020static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2021{
2022 struct alc_spec *spec = codec->spec;
2023
2024 if (spec->unsol_event)
2025 spec->unsol_event(codec, res);
2026}
2027
Takashi Iwaicb53c622007-08-10 17:21:45 +02002028#ifdef CONFIG_SND_HDA_POWER_SAVE
2029static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2030{
2031 struct alc_spec *spec = codec->spec;
2032 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2033}
2034#endif
2035
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036/*
2037 * Analog playback callbacks
2038 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002039static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002041 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042{
2043 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002044 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2045 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002048static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 struct hda_codec *codec,
2050 unsigned int stream_tag,
2051 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002052 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053{
2054 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002055 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2056 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002059static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002061 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062{
2063 struct alc_spec *spec = codec->spec;
2064 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2065}
2066
2067/*
2068 * Digital out
2069 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002070static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002072 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
2074 struct alc_spec *spec = codec->spec;
2075 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2076}
2077
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002078static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002079 struct hda_codec *codec,
2080 unsigned int stream_tag,
2081 unsigned int format,
2082 struct snd_pcm_substream *substream)
2083{
2084 struct alc_spec *spec = codec->spec;
2085 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2086 stream_tag, format, substream);
2087}
2088
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002089static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002090 struct hda_codec *codec,
2091 struct snd_pcm_substream *substream)
2092{
2093 struct alc_spec *spec = codec->spec;
2094 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2095}
2096
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002097static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002099 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100{
2101 struct alc_spec *spec = codec->spec;
2102 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2103}
2104
2105/*
2106 * Analog capture
2107 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002108static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct hda_codec *codec,
2110 unsigned int stream_tag,
2111 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002112 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
2114 struct alc_spec *spec = codec->spec;
2115
Takashi Iwai63300792008-01-24 15:31:36 +01002116 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 stream_tag, 0, format);
2118 return 0;
2119}
2120
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002121static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002123 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
2125 struct alc_spec *spec = codec->spec;
2126
Takashi Iwai888afa12008-03-18 09:57:50 +01002127 snd_hda_codec_cleanup_stream(codec,
2128 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 return 0;
2130}
2131
Takashi Iwai840b64c2010-07-13 22:49:01 +02002132/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002133static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002134 struct hda_codec *codec,
2135 unsigned int stream_tag,
2136 unsigned int format,
2137 struct snd_pcm_substream *substream)
2138{
2139 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002140 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002141 spec->cur_adc_stream_tag = stream_tag;
2142 spec->cur_adc_format = format;
2143 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2144 return 0;
2145}
2146
Takashi Iwai21268962011-07-07 15:01:13 +02002147static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002148 struct hda_codec *codec,
2149 struct snd_pcm_substream *substream)
2150{
2151 struct alc_spec *spec = codec->spec;
2152 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2153 spec->cur_adc = 0;
2154 return 0;
2155}
2156
Takashi Iwai21268962011-07-07 15:01:13 +02002157static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002158 .substreams = 1,
2159 .channels_min = 2,
2160 .channels_max = 2,
2161 .nid = 0, /* fill later */
2162 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002163 .prepare = dyn_adc_capture_pcm_prepare,
2164 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002165 },
2166};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
2168/*
2169 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002170static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 .substreams = 1,
2172 .channels_min = 2,
2173 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002174 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002176 .open = alc_playback_pcm_open,
2177 .prepare = alc_playback_pcm_prepare,
2178 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 },
2180};
2181
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002182static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002183 .substreams = 1,
2184 .channels_min = 2,
2185 .channels_max = 2,
2186 /* NID is set in alc_build_pcms */
2187};
2188
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002189static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002190 .substreams = 1,
2191 .channels_min = 2,
2192 .channels_max = 2,
2193 /* NID is set in alc_build_pcms */
2194};
2195
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002196static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002197 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 .channels_min = 2,
2199 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002200 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002202 .prepare = alc_alt_capture_pcm_prepare,
2203 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 },
2205};
2206
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002207static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 .substreams = 1,
2209 .channels_min = 2,
2210 .channels_max = 2,
2211 /* NID is set in alc_build_pcms */
2212 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002213 .open = alc_dig_playback_pcm_open,
2214 .close = alc_dig_playback_pcm_close,
2215 .prepare = alc_dig_playback_pcm_prepare,
2216 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 },
2218};
2219
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002220static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 .substreams = 1,
2222 .channels_min = 2,
2223 .channels_max = 2,
2224 /* NID is set in alc_build_pcms */
2225};
2226
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002227/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002228static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002229 .substreams = 0,
2230 .channels_min = 0,
2231 .channels_max = 0,
2232};
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234static int alc_build_pcms(struct hda_codec *codec)
2235{
2236 struct alc_spec *spec = codec->spec;
2237 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002238 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002239 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 int i;
2241
2242 codec->num_pcms = 1;
2243 codec->pcm_info = info;
2244
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002245 if (spec->no_analog)
2246 goto skip_analog;
2247
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002248 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2249 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002251
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002252 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002253 p = spec->stream_analog_playback;
2254 if (!p)
2255 p = &alc_pcm_analog_playback;
2256 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002257 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2258 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002259 if (spec->adc_nids) {
2260 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002261 if (!p) {
2262 if (spec->dyn_adc_switch)
2263 p = &dyn_adc_pcm_analog_capture;
2264 else
2265 p = &alc_pcm_analog_capture;
2266 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002267 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002268 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
Takashi Iwai4a471b72005-12-07 13:56:29 +01002271 if (spec->channel_mode) {
2272 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2273 for (i = 0; i < spec->num_channel_mode; i++) {
2274 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2275 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 }
2278 }
2279
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002280 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002281 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002283 snprintf(spec->stream_name_digital,
2284 sizeof(spec->stream_name_digital),
2285 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002286 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002287 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002288 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002290 if (spec->dig_out_type)
2291 info->pcm_type = spec->dig_out_type;
2292 else
2293 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002294 if (spec->multiout.dig_out_nid) {
2295 p = spec->stream_digital_playback;
2296 if (!p)
2297 p = &alc_pcm_digital_playback;
2298 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2300 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002301 if (spec->dig_in_nid) {
2302 p = spec->stream_digital_capture;
2303 if (!p)
2304 p = &alc_pcm_digital_capture;
2305 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2307 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002308 /* FIXME: do we need this for all Realtek codec models? */
2309 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 }
2311
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002312 if (spec->no_analog)
2313 return 0;
2314
Takashi Iwaie08a0072006-09-07 17:52:14 +02002315 /* If the use of more than one ADC is requested for the current
2316 * model, configure a second analog capture-only PCM.
2317 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002318 have_multi_adcs = (spec->num_adc_nids > 1) &&
2319 !spec->dyn_adc_switch && !spec->auto_mic &&
2320 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002321 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002322 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002323 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002324 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002325 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002326 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002327 p = spec->stream_analog_alt_playback;
2328 if (!p)
2329 p = &alc_pcm_analog_alt_playback;
2330 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002331 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2332 spec->alt_dac_nid;
2333 } else {
2334 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2335 alc_pcm_null_stream;
2336 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2337 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002338 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002339 p = spec->stream_analog_alt_capture;
2340 if (!p)
2341 p = &alc_pcm_analog_alt_capture;
2342 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002343 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2344 spec->adc_nids[1];
2345 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2346 spec->num_adc_nids - 1;
2347 } else {
2348 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2349 alc_pcm_null_stream;
2350 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002351 }
2352 }
2353
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 return 0;
2355}
2356
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002357static inline void alc_shutup(struct hda_codec *codec)
2358{
Takashi Iwai1c716152011-04-07 10:37:16 +02002359 struct alc_spec *spec = codec->spec;
2360
2361 if (spec && spec->shutup)
2362 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002363 snd_hda_shutup_pins(codec);
2364}
2365
Takashi Iwai603c4012008-07-30 15:01:44 +02002366static void alc_free_kctls(struct hda_codec *codec)
2367{
2368 struct alc_spec *spec = codec->spec;
2369
2370 if (spec->kctls.list) {
2371 struct snd_kcontrol_new *kctl = spec->kctls.list;
2372 int i;
2373 for (i = 0; i < spec->kctls.used; i++)
2374 kfree(kctl[i].name);
2375 }
2376 snd_array_free(&spec->kctls);
2377}
2378
Takashi Iwai23c09b02011-08-19 09:05:35 +02002379static void alc_free_bind_ctls(struct hda_codec *codec)
2380{
2381 struct alc_spec *spec = codec->spec;
2382 if (spec->bind_ctls.list) {
2383 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2384 int i;
2385 for (i = 0; i < spec->bind_ctls.used; i++)
2386 kfree(ctl[i]);
2387 }
2388 snd_array_free(&spec->bind_ctls);
2389}
2390
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391static void alc_free(struct hda_codec *codec)
2392{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002393 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002394
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002395 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002396 return;
2397
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002398 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002399 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002400 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002401 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002402 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403}
2404
Hector Martinf5de24b2009-12-20 22:51:31 +01002405#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002406static void alc_power_eapd(struct hda_codec *codec)
2407{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002408 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002409}
2410
Hector Martinf5de24b2009-12-20 22:51:31 +01002411static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2412{
2413 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002414 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002415 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002416 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002417 return 0;
2418}
2419#endif
2420
Takashi Iwai2a439522011-07-26 09:52:50 +02002421#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002422static int alc_resume(struct hda_codec *codec)
2423{
Takashi Iwai1c716152011-04-07 10:37:16 +02002424 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002425 codec->patch_ops.init(codec);
2426 snd_hda_codec_resume_amp(codec);
2427 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002428 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002429 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002430 return 0;
2431}
Takashi Iwaie044c392008-10-27 16:56:24 +01002432#endif
2433
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434/*
2435 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002436static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 .build_controls = alc_build_controls,
2438 .build_pcms = alc_build_pcms,
2439 .init = alc_init,
2440 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002441 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002442#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002443 .resume = alc_resume,
2444#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002445#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002446 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002447 .check_power_status = alc_check_power_status,
2448#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002449 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450};
2451
Kailang Yangc027ddc2010-03-19 11:33:06 +01002452/* replace the codec chip_name with the given string */
2453static int alc_codec_rename(struct hda_codec *codec, const char *name)
2454{
2455 kfree(codec->chip_name);
2456 codec->chip_name = kstrdup(name, GFP_KERNEL);
2457 if (!codec->chip_name) {
2458 alc_free(codec);
2459 return -ENOMEM;
2460 }
2461 return 0;
2462}
2463
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002464/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002465 * Rename codecs appropriately from COEF value
2466 */
2467struct alc_codec_rename_table {
2468 unsigned int vendor_id;
2469 unsigned short coef_mask;
2470 unsigned short coef_bits;
2471 const char *name;
2472};
2473
2474static struct alc_codec_rename_table rename_tbl[] = {
2475 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2476 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2477 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2478 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2479 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2480 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2481 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002482 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002483 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2484 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2485 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2486 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2487 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2488 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2489 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2490 { } /* terminator */
2491};
2492
2493static int alc_codec_rename_from_preset(struct hda_codec *codec)
2494{
2495 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002496
2497 for (p = rename_tbl; p->vendor_id; p++) {
2498 if (p->vendor_id != codec->vendor_id)
2499 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002500 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002501 return alc_codec_rename(codec, p->name);
2502 }
2503 return 0;
2504}
2505
2506/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002507 * Automatic parse of I/O pins from the BIOS configuration
2508 */
2509
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002510enum {
2511 ALC_CTL_WIDGET_VOL,
2512 ALC_CTL_WIDGET_MUTE,
2513 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002514 ALC_CTL_BIND_VOL,
2515 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002516};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002517static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002518 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2519 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002520 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002521 HDA_BIND_VOL(NULL, 0),
2522 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002523};
2524
2525/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002526static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002527 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002528{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002529 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002530
Takashi Iwaice764ab2011-04-27 16:35:23 +02002531 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002532 if (!knew)
2533 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002534 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002535 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002536 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002537 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002538 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002539 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002540 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002541 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002542 return 0;
2543}
2544
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002545static int add_control_with_pfx(struct alc_spec *spec, int type,
2546 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002547 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002548{
2549 char name[32];
2550 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002551 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002552}
2553
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002554#define add_pb_vol_ctrl(spec, type, pfx, val) \
2555 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2556#define add_pb_sw_ctrl(spec, type, pfx, val) \
2557 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2558#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2559 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2560#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2561 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002562
Takashi Iwai23c09b02011-08-19 09:05:35 +02002563static const char * const channel_name[4] = {
2564 "Front", "Surround", "CLFE", "Side"
2565};
2566
Takashi Iwai6843ca12011-06-24 11:03:58 +02002567static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2568 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002569{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002570 struct auto_pin_cfg *cfg = &spec->autocfg;
2571
Takashi Iwai6843ca12011-06-24 11:03:58 +02002572 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002573 if (cfg->line_outs == 1 && !spec->multi_ios &&
2574 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002575 return "Master";
2576
2577 switch (cfg->line_out_type) {
2578 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002579 if (cfg->line_outs == 1)
2580 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002581 if (cfg->line_outs == 2)
2582 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002583 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002584 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002585 /* for multi-io case, only the primary out */
2586 if (ch && spec->multi_ios)
2587 break;
2588 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002589 return "Headphone";
2590 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002591 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002592 return "PCM";
2593 break;
2594 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002595 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2596 return "PCM";
2597
2598 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002599}
2600
Takashi Iwai164f73e2012-02-21 11:27:09 +01002601#ifdef CONFIG_SND_HDA_POWER_SAVE
2602/* add the powersave loopback-list entry */
2603static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2604{
2605 struct hda_amp_list *list;
2606
2607 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2608 return;
2609 list = spec->loopback_list + spec->num_loopbacks;
2610 list->nid = mix;
2611 list->dir = HDA_INPUT;
2612 list->idx = idx;
2613 spec->num_loopbacks++;
2614 spec->loopback.amplist = spec->loopback_list;
2615}
2616#else
2617#define add_loopback_list(spec, mix, idx) /* NOP */
2618#endif
2619
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002620/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002621static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002622 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002623 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002624{
Kailang Yangdf694da2005-12-05 19:42:22 +01002625 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002626
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002627 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002628 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2629 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002630 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002631 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002632 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2633 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002634 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002635 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002636 return 0;
2637}
2638
Takashi Iwai05f5f472009-08-25 13:10:18 +02002639static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002640{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002641 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2642 return (pincap & AC_PINCAP_IN) != 0;
2643}
2644
Takashi Iwai1d045db2011-07-07 18:23:21 +02002645/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002646static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002647{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002648 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002649 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002650 hda_nid_t *adc_nids = spec->private_adc_nids;
2651 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2652 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002653 int i, nums = 0;
2654
2655 nid = codec->start_nid;
2656 for (i = 0; i < codec->num_nodes; i++, nid++) {
2657 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002658 unsigned int caps = get_wcaps(codec, nid);
2659 int type = get_wcaps_type(caps);
2660
2661 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2662 continue;
2663 adc_nids[nums] = nid;
2664 cap_nids[nums] = nid;
2665 src = nid;
2666 for (;;) {
2667 int n;
2668 type = get_wcaps_type(get_wcaps(codec, src));
2669 if (type == AC_WID_PIN)
2670 break;
2671 if (type == AC_WID_AUD_SEL) {
2672 cap_nids[nums] = src;
2673 break;
2674 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002675 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002676 if (n > 1) {
2677 cap_nids[nums] = src;
2678 break;
2679 } else if (n != 1)
2680 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002681 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2682 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002683 }
2684 if (++nums >= max_nums)
2685 break;
2686 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002687 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002688 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002689 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002690 return nums;
2691}
2692
Takashi Iwai05f5f472009-08-25 13:10:18 +02002693/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002694static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002695{
2696 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002697 const struct auto_pin_cfg *cfg = &spec->autocfg;
2698 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002699 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002700 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002701 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002702 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002703
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002704 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002705 if (num_adcs < 0)
2706 return 0;
2707
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002708 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002709 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002710 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002711
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002712 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002713 if (!alc_is_input_pin(codec, pin))
2714 continue;
2715
David Henningsson5322bf22011-01-05 11:03:56 +01002716 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002717 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2718 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002719 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002720 type_idx++;
2721 else
2722 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002723 prev_label = label;
2724
Takashi Iwai05f5f472009-08-25 13:10:18 +02002725 if (mixer) {
2726 idx = get_connection_index(codec, mixer, pin);
2727 if (idx >= 0) {
2728 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002729 label, type_idx,
2730 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002731 if (err < 0)
2732 return err;
2733 }
2734 }
2735
Takashi Iwaib7821702011-07-06 15:12:46 +02002736 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002737 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002738 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002739 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002740 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002741 snd_hda_add_imux_item(imux, label, idx, NULL);
2742 break;
2743 }
2744 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002745 }
Takashi Iwai21268962011-07-07 15:01:13 +02002746
2747 spec->num_mux_defs = 1;
2748 spec->input_mux = imux;
2749
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002750 return 0;
2751}
2752
Takashi Iwai24de1832011-11-07 17:13:39 +01002753/* create a shared input with the headphone out */
2754static int alc_auto_create_shared_input(struct hda_codec *codec)
2755{
2756 struct alc_spec *spec = codec->spec;
2757 struct auto_pin_cfg *cfg = &spec->autocfg;
2758 unsigned int defcfg;
2759 hda_nid_t nid;
2760
2761 /* only one internal input pin? */
2762 if (cfg->num_inputs != 1)
2763 return 0;
2764 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2765 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2766 return 0;
2767
2768 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2769 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2770 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2771 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2772 else
2773 return 0; /* both not available */
2774
2775 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2776 return 0; /* no input */
2777
2778 cfg->inputs[1].pin = nid;
2779 cfg->inputs[1].type = AUTO_PIN_MIC;
2780 cfg->num_inputs = 2;
2781 spec->shared_mic_hp = 1;
2782 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2783 return 0;
2784}
2785
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002786static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2787 unsigned int pin_type)
2788{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002789 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002790 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002791 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2792 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002793 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002794}
2795
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002796static int get_pin_type(int line_out_type)
2797{
2798 if (line_out_type == AUTO_PIN_HP_OUT)
2799 return PIN_HP;
2800 else
2801 return PIN_OUT;
2802}
2803
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002804static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002805{
2806 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002807 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002808 int i;
2809
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002810 for (i = 0; i < cfg->num_inputs; i++) {
2811 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002812 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002813 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002814 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002815 snd_hda_codec_write(codec, nid, 0,
2816 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002817 AMP_OUT_MUTE);
2818 }
2819 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002820
2821 /* mute all loopback inputs */
2822 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002823 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002824 for (i = 0; i < nums; i++)
2825 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2826 AC_VERB_SET_AMP_GAIN_MUTE,
2827 AMP_IN_MUTE(i));
2828 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002829}
2830
Takashi Iwai7085ec12009-10-02 09:03:58 +02002831/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002832static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002833{
Takashi Iwai604401a2011-04-27 15:14:23 +02002834 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002835 int i, num;
2836
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002837 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2838 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002839 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2840 for (i = 0; i < num; i++) {
2841 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2842 return list[i];
2843 }
2844 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002845}
2846
Takashi Iwai604401a2011-04-27 15:14:23 +02002847/* go down to the selector widget before the mixer */
2848static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2849{
2850 hda_nid_t srcs[5];
2851 int num = snd_hda_get_connections(codec, pin, srcs,
2852 ARRAY_SIZE(srcs));
2853 if (num != 1 ||
2854 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2855 return pin;
2856 return srcs[0];
2857}
2858
Takashi Iwai7085ec12009-10-02 09:03:58 +02002859/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002860static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002861 hda_nid_t dac)
2862{
David Henningssoncc1c4522010-11-24 14:17:47 +01002863 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002864 int i, num;
2865
Takashi Iwai604401a2011-04-27 15:14:23 +02002866 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002867 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2868 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002869 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002870 return mix[i];
2871 }
2872 return 0;
2873}
2874
Takashi Iwaice764ab2011-04-27 16:35:23 +02002875/* select the connection from pin to DAC if needed */
2876static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2877 hda_nid_t dac)
2878{
2879 hda_nid_t mix[5];
2880 int i, num;
2881
2882 pin = alc_go_down_to_selector(codec, pin);
2883 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2884 if (num < 2)
2885 return 0;
2886 for (i = 0; i < num; i++) {
2887 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2888 snd_hda_codec_update_cache(codec, pin, 0,
2889 AC_VERB_SET_CONNECT_SEL, i);
2890 return 0;
2891 }
2892 }
2893 return 0;
2894}
2895
Takashi Iwai185d99f2012-02-16 18:39:45 +01002896static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2897{
2898 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002899 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002900 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2901 ARRAY_SIZE(spec->private_dac_nids)) ||
2902 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2903 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2904 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2905 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2906 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002907 for (i = 0; i < spec->multi_ios; i++) {
2908 if (spec->multi_io[i].dac == nid)
2909 return true;
2910 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002911 return false;
2912}
2913
Takashi Iwai7085ec12009-10-02 09:03:58 +02002914/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002915static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002916{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002917 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002918 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002919
Takashi Iwai604401a2011-04-27 15:14:23 +02002920 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002921 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002922 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002923 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002924 if (!nid)
2925 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002926 if (!alc_is_dac_already_used(codec, nid))
2927 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002928 }
2929 return 0;
2930}
2931
Takashi Iwai07b18f62011-11-10 15:42:54 +01002932/* check whether the DAC is reachable from the pin */
2933static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2934 hda_nid_t pin, hda_nid_t dac)
2935{
2936 hda_nid_t srcs[5];
2937 int i, num;
2938
Takashi Iwaidc31b582012-02-17 17:27:53 +01002939 if (!pin || !dac)
2940 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002941 pin = alc_go_down_to_selector(codec, pin);
2942 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2943 for (i = 0; i < num; i++) {
2944 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2945 if (nid == dac)
2946 return true;
2947 }
2948 return false;
2949}
2950
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002951static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2952{
Takashi Iwai140547e2012-02-16 17:23:46 +01002953 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002954 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002955 hda_nid_t nid, nid_found, srcs[5];
2956 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01002957 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01002958 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002959 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002960 nid_found = 0;
2961 for (i = 0; i < num; i++) {
2962 if (srcs[i] == spec->mixer_nid)
2963 continue;
2964 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2965 if (nid && !alc_is_dac_already_used(codec, nid)) {
2966 if (nid_found)
2967 return 0;
2968 nid_found = nid;
2969 }
2970 }
2971 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002972}
2973
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002974/* mark up volume and mute control NIDs: used during badness parsing and
2975 * at creating actual controls
2976 */
2977static inline unsigned int get_ctl_pos(unsigned int data)
2978{
2979 hda_nid_t nid = get_amp_nid_(data);
2980 unsigned int dir;
2981 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
2982 return 0;
2983 dir = get_amp_direction_(data);
2984 return (nid << 1) | dir;
2985}
2986
2987#define is_ctl_used(bits, data) \
2988 test_bit(get_ctl_pos(data), bits)
2989#define mark_ctl_usage(bits, data) \
2990 set_bit(get_ctl_pos(data), bits)
2991
2992static void clear_vol_marks(struct hda_codec *codec)
2993{
2994 struct alc_spec *spec = codec->spec;
2995 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
2996 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
2997}
2998
2999/* badness definition */
3000enum {
3001 /* No primary DAC is found for the main output */
3002 BAD_NO_PRIMARY_DAC = 0x10000,
3003 /* No DAC is found for the extra output */
3004 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003005 /* No possible multi-ios */
3006 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003007 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003008 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003009 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003010 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003011 /* Primary DAC shared with main surrounds */
3012 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003013 /* Primary DAC shared with main CLFE */
3014 BAD_SHARED_CLFE = 0x10,
3015 /* Primary DAC shared with extra surrounds */
3016 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003017 /* Volume widget is shared */
3018 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003019};
3020
3021static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3022 hda_nid_t pin, hda_nid_t dac);
3023static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3024 hda_nid_t pin, hda_nid_t dac);
3025
3026static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3027 hda_nid_t dac)
3028{
3029 struct alc_spec *spec = codec->spec;
3030 hda_nid_t nid;
3031 unsigned int val;
3032 int badness = 0;
3033
3034 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3035 if (nid) {
3036 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3037 if (is_ctl_used(spec->vol_ctls, nid))
3038 badness += BAD_SHARED_VOL;
3039 else
3040 mark_ctl_usage(spec->vol_ctls, val);
3041 } else
3042 badness += BAD_SHARED_VOL;
3043 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3044 if (nid) {
3045 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3046 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3047 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3048 else
3049 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3050 if (is_ctl_used(spec->sw_ctls, val))
3051 badness += BAD_SHARED_VOL;
3052 else
3053 mark_ctl_usage(spec->sw_ctls, val);
3054 } else
3055 badness += BAD_SHARED_VOL;
3056 return badness;
3057}
3058
Takashi Iwaidc31b582012-02-17 17:27:53 +01003059struct badness_table {
3060 int no_primary_dac; /* no primary DAC */
3061 int no_dac; /* no secondary DACs */
3062 int shared_primary; /* primary DAC is shared with main output */
3063 int shared_surr; /* secondary DAC shared with main or primary */
3064 int shared_clfe; /* third DAC shared with main or primary */
3065 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3066};
3067
3068static struct badness_table main_out_badness = {
3069 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3070 .no_dac = BAD_NO_DAC,
3071 .shared_primary = BAD_NO_PRIMARY_DAC,
3072 .shared_surr = BAD_SHARED_SURROUND,
3073 .shared_clfe = BAD_SHARED_CLFE,
3074 .shared_surr_main = BAD_SHARED_SURROUND,
3075};
3076
3077static struct badness_table extra_out_badness = {
3078 .no_primary_dac = BAD_NO_DAC,
3079 .no_dac = BAD_NO_DAC,
3080 .shared_primary = BAD_NO_EXTRA_DAC,
3081 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3082 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3083 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3084};
3085
3086/* try to assign DACs to pins and return the resultant badness */
3087static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3088 const hda_nid_t *pins, hda_nid_t *dacs,
3089 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003090{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003091 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003092 struct auto_pin_cfg *cfg = &spec->autocfg;
3093 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003094 int badness = 0;
3095 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003096
Takashi Iwai185d99f2012-02-16 18:39:45 +01003097 if (!num_outs)
3098 return 0;
3099
Takashi Iwaidc31b582012-02-17 17:27:53 +01003100 for (i = 0; i < num_outs; i++) {
3101 hda_nid_t pin = pins[i];
3102 if (!dacs[i])
3103 dacs[i] = alc_auto_look_for_dac(codec, pin);
3104 if (!dacs[i] && !i) {
3105 for (j = 1; j < num_outs; j++) {
3106 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3107 dacs[0] = dacs[j];
3108 dacs[j] = 0;
3109 break;
3110 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003111 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003112 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003113 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003114 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003115 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003116 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003117 else if (cfg->line_outs > i &&
3118 alc_auto_is_dac_reachable(codec, pin,
3119 spec->private_dac_nids[i]))
3120 dac = spec->private_dac_nids[i];
3121 if (dac) {
3122 if (!i)
3123 badness += bad->shared_primary;
3124 else if (i == 1)
3125 badness += bad->shared_surr;
3126 else
3127 badness += bad->shared_clfe;
3128 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003129 spec->private_dac_nids[0])) {
3130 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003131 badness += bad->shared_surr_main;
3132 } else if (!i)
3133 badness += bad->no_primary_dac;
3134 else
3135 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003136 }
3137 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003138 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003139 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003140
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003141 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003142}
3143
3144static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003145 hda_nid_t reference_pin,
3146 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003147
Takashi Iwai185d99f2012-02-16 18:39:45 +01003148static bool alc_map_singles(struct hda_codec *codec, int outs,
3149 const hda_nid_t *pins, hda_nid_t *dacs)
3150{
3151 int i;
3152 bool found = false;
3153 for (i = 0; i < outs; i++) {
3154 if (dacs[i])
3155 continue;
3156 dacs[i] = get_dac_if_single(codec, pins[i]);
3157 if (dacs[i])
3158 found = true;
3159 }
3160 return found;
3161}
3162
Takashi Iwai7085ec12009-10-02 09:03:58 +02003163/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003164static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003165 bool fill_hardwired,
3166 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003167{
3168 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003169 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003170 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003171
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003172 /* set num_dacs once to full for alc_auto_look_for_dac() */
3173 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003174 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003175 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3176 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3177 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003178 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003179 clear_vol_marks(codec);
3180 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003181
3182 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003183 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003184 bool mapped;
3185 do {
3186 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003187 cfg->line_out_pins,
3188 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003189 mapped |= alc_map_singles(codec, cfg->hp_outs,
3190 cfg->hp_pins,
3191 spec->multiout.hp_out_nid);
3192 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3193 cfg->speaker_pins,
3194 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003195 if (fill_mio_first && cfg->line_outs == 1 &&
3196 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3197 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3198 if (!err)
3199 mapped = true;
3200 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003201 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003202 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003203
Takashi Iwaidc31b582012-02-17 17:27:53 +01003204 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3205 spec->private_dac_nids,
3206 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003207
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003208 /* re-count num_dacs and squash invalid entries */
3209 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003210 for (i = 0; i < cfg->line_outs; i++) {
3211 if (spec->private_dac_nids[i])
3212 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003213 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003214 memmove(spec->private_dac_nids + i,
3215 spec->private_dac_nids + i + 1,
3216 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003217 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3218 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003219 }
3220
Takashi Iwai276dd702012-02-17 16:17:03 +01003221 if (fill_mio_first &&
3222 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003223 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003224 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003225 if (err < 0)
3226 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003227 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003228 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003229
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003230 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003231 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3232 spec->multiout.hp_out_nid,
3233 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003234 if (err < 0)
3235 return err;
3236 badness += err;
3237 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003238 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003239 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3240 cfg->speaker_pins,
3241 spec->multiout.extra_out_nid,
3242 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003243 if (err < 0)
3244 return err;
3245 badness += err;
3246 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003247 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3248 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003249 if (err < 0)
3250 return err;
3251 badness += err;
3252 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003253 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3254 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003255 int offset = 0;
3256 if (cfg->line_outs >= 3)
3257 offset = 1;
3258 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3259 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003260 if (err < 0)
3261 return err;
3262 badness += err;
3263 }
3264
3265 if (spec->multi_ios == 2) {
3266 for (i = 0; i < 2; i++)
3267 spec->private_dac_nids[spec->multiout.num_dacs++] =
3268 spec->multi_io[i].dac;
3269 spec->ext_channel_count = 2;
3270 } else if (spec->multi_ios) {
3271 spec->multi_ios = 0;
3272 badness += BAD_MULTI_IO;
3273 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003274
3275 return badness;
3276}
3277
3278#define DEBUG_BADNESS
3279
3280#ifdef DEBUG_BADNESS
3281#define debug_badness snd_printdd
3282#else
3283#define debug_badness(...)
3284#endif
3285
3286static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3287{
3288 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3289 cfg->line_out_pins[0], cfg->line_out_pins[1],
3290 cfg->line_out_pins[2], cfg->line_out_pins[2],
3291 spec->multiout.dac_nids[0],
3292 spec->multiout.dac_nids[1],
3293 spec->multiout.dac_nids[2],
3294 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003295 if (spec->multi_ios > 0)
3296 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3297 spec->multi_ios,
3298 spec->multi_io[0].pin, spec->multi_io[1].pin,
3299 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003300 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3301 cfg->hp_pins[0], cfg->hp_pins[1],
3302 cfg->hp_pins[2], cfg->hp_pins[2],
3303 spec->multiout.hp_out_nid[0],
3304 spec->multiout.hp_out_nid[1],
3305 spec->multiout.hp_out_nid[2],
3306 spec->multiout.hp_out_nid[3]);
3307 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3308 cfg->speaker_pins[0], cfg->speaker_pins[1],
3309 cfg->speaker_pins[2], cfg->speaker_pins[3],
3310 spec->multiout.extra_out_nid[0],
3311 spec->multiout.extra_out_nid[1],
3312 spec->multiout.extra_out_nid[2],
3313 spec->multiout.extra_out_nid[3]);
3314}
3315
3316static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3317{
3318 struct alc_spec *spec = codec->spec;
3319 struct auto_pin_cfg *cfg = &spec->autocfg;
3320 struct auto_pin_cfg *best_cfg;
3321 int best_badness = INT_MAX;
3322 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003323 bool fill_hardwired = true, fill_mio_first = true;
3324 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003325 bool hp_spk_swapped = false;
3326
3327 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3328 if (!best_cfg)
3329 return -ENOMEM;
3330 *best_cfg = *cfg;
3331
3332 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003333 badness = fill_and_eval_dacs(codec, fill_hardwired,
3334 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003335 if (badness < 0) {
3336 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003337 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003338 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003339 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3340 cfg->line_out_type, fill_hardwired, fill_mio_first,
3341 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003342 debug_show_configs(spec, cfg);
3343 if (badness < best_badness) {
3344 best_badness = badness;
3345 *best_cfg = *cfg;
3346 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003347 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003348 }
3349 if (!badness)
3350 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003351 fill_mio_first = !fill_mio_first;
3352 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003353 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003354 fill_hardwired = !fill_hardwired;
3355 if (!fill_hardwired)
3356 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003357 if (hp_spk_swapped)
3358 break;
3359 hp_spk_swapped = true;
3360 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003361 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3362 cfg->hp_outs = cfg->line_outs;
3363 memcpy(cfg->hp_pins, cfg->line_out_pins,
3364 sizeof(cfg->hp_pins));
3365 cfg->line_outs = cfg->speaker_outs;
3366 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3367 sizeof(cfg->speaker_pins));
3368 cfg->speaker_outs = 0;
3369 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3370 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003371 fill_hardwired = true;
3372 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003373 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003374 if (cfg->hp_outs > 0 &&
3375 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3376 cfg->speaker_outs = cfg->line_outs;
3377 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3378 sizeof(cfg->speaker_pins));
3379 cfg->line_outs = cfg->hp_outs;
3380 memcpy(cfg->line_out_pins, cfg->hp_pins,
3381 sizeof(cfg->hp_pins));
3382 cfg->hp_outs = 0;
3383 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3384 cfg->line_out_type = AUTO_PIN_HP_OUT;
3385 fill_hardwired = true;
3386 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003387 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003388 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003389 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003390
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003391 if (badness) {
3392 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003393 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003394 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003395 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3396 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003397 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003398
David Henningssonfde48a12011-12-09 18:27:42 +08003399 if (cfg->line_out_pins[0])
3400 spec->vmaster_nid =
3401 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3402 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003403
3404 /* clear the bitmap flags for creating controls */
3405 clear_vol_marks(codec);
3406 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003407 return 0;
3408}
3409
Takashi Iwai343a04b2011-07-06 14:28:39 +02003410static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003411 const char *pfx, int cidx,
3412 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003413{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003414 struct alc_spec *spec = codec->spec;
3415 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003416 if (!nid)
3417 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003418 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3419 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3420 return 0;
3421 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003422 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003423 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003424}
3425
Takashi Iwaie29d3772011-11-14 17:13:23 +01003426static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3427 const char *pfx, int cidx,
3428 hda_nid_t nid)
3429{
3430 int chs = 1;
3431 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3432 chs = 3;
3433 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3434}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003435
3436/* create a mute-switch for the given mixer widget;
3437 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3438 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003439static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003440 const char *pfx, int cidx,
3441 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003442{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003443 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003444 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003445 int type;
3446 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003447 if (!nid)
3448 return 0;
3449 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3450 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3451 type = ALC_CTL_WIDGET_MUTE;
3452 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003453 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003454 type = ALC_CTL_WIDGET_MUTE;
3455 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3456 } else {
3457 type = ALC_CTL_BIND_MUTE;
3458 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3459 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003460 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3461 return 0;
3462 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003463 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003464}
3465
Takashi Iwaie29d3772011-11-14 17:13:23 +01003466static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3467 int cidx, hda_nid_t nid)
3468{
3469 int chs = 1;
3470 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3471 chs = 3;
3472 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3473}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003474
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003475static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3476 hda_nid_t pin, hda_nid_t dac)
3477{
3478 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3479 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3480 return pin;
3481 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3482 return mix;
3483 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3484 return dac;
3485 return 0;
3486}
3487
3488static hda_nid_t alc_look_for_out_vol_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_volume(codec, dac, HDA_OUTPUT))
3493 return dac;
3494 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3495 return mix;
3496 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3497 return pin;
3498 return 0;
3499}
3500
Takashi Iwai7085ec12009-10-02 09:03:58 +02003501/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003502static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003503 const struct auto_pin_cfg *cfg)
3504{
3505 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003506 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003507
Takashi Iwaice764ab2011-04-27 16:35:23 +02003508 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003509 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003510 noutputs += spec->multi_ios;
3511
3512 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003513 const char *name;
3514 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003515 hda_nid_t dac, pin;
3516 hda_nid_t sw, vol;
3517
3518 dac = spec->multiout.dac_nids[i];
3519 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003520 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003521 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003522 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003523 index = 0;
3524 name = channel_name[i];
3525 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003526 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003527 name = alc_get_line_out_pfx(spec, i, true, &index);
3528 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003529
3530 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3531 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003532 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003533 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003534 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003535 if (err < 0)
3536 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003537 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003538 if (err < 0)
3539 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003540 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003541 if (err < 0)
3542 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003543 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003544 if (err < 0)
3545 return err;
3546 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003547 err = alc_auto_add_stereo_vol(codec, name, index, vol);
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_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003551 if (err < 0)
3552 return err;
3553 }
3554 }
3555 return 0;
3556}
3557
Takashi Iwai343a04b2011-07-06 14:28:39 +02003558static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003559 hda_nid_t dac, const char *pfx,
3560 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003561{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003562 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003563 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003564 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003565
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003566 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003567 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003568 /* the corresponding DAC is already occupied */
3569 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3570 return 0; /* no way */
3571 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003572 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3573 if (is_ctl_used(spec->sw_ctls, val))
3574 return 0; /* already created */
3575 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003576 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003577 }
3578
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003579 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3580 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003581 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003582 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003583 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003584 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003585 if (err < 0)
3586 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003587 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003588}
3589
Takashi Iwai23c09b02011-08-19 09:05:35 +02003590static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3591 unsigned int nums,
3592 struct hda_ctl_ops *ops)
3593{
3594 struct alc_spec *spec = codec->spec;
3595 struct hda_bind_ctls **ctlp, *ctl;
3596 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3597 ctlp = snd_array_new(&spec->bind_ctls);
3598 if (!ctlp)
3599 return NULL;
3600 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3601 *ctlp = ctl;
3602 if (ctl)
3603 ctl->ops = ops;
3604 return ctl;
3605}
3606
3607/* add playback controls for speaker and HP outputs */
3608static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3609 const hda_nid_t *pins,
3610 const hda_nid_t *dacs,
3611 const char *pfx)
3612{
3613 struct alc_spec *spec = codec->spec;
3614 struct hda_bind_ctls *ctl;
3615 char name[32];
3616 int i, n, err;
3617
3618 if (!num_pins || !pins[0])
3619 return 0;
3620
Takashi Iwai527e4d72011-10-27 16:33:27 +02003621 if (num_pins == 1) {
3622 hda_nid_t dac = *dacs;
3623 if (!dac)
3624 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003625 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003626 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003627
Takashi Iwai23c09b02011-08-19 09:05:35 +02003628 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003629 hda_nid_t dac;
3630 if (dacs[num_pins - 1])
3631 dac = dacs[i]; /* with individual volumes */
3632 else
3633 dac = 0;
3634 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3635 err = alc_auto_create_extra_out(codec, pins[i], dac,
3636 "Bass Speaker", 0);
3637 } else if (num_pins >= 3) {
3638 snprintf(name, sizeof(name), "%s %s",
3639 pfx, channel_name[i]);
3640 err = alc_auto_create_extra_out(codec, pins[i], dac,
3641 name, 0);
3642 } else {
3643 err = alc_auto_create_extra_out(codec, pins[i], dac,
3644 pfx, i);
3645 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003646 if (err < 0)
3647 return err;
3648 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003649 if (dacs[num_pins - 1])
3650 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003651
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003652 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003653 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3654 if (!ctl)
3655 return -ENOMEM;
3656 n = 0;
3657 for (i = 0; i < num_pins; i++) {
3658 hda_nid_t vol;
3659 if (!pins[i] || !dacs[i])
3660 continue;
3661 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3662 if (vol)
3663 ctl->values[n++] =
3664 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3665 }
3666 if (n) {
3667 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3668 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3669 if (err < 0)
3670 return err;
3671 }
3672 return 0;
3673}
3674
Takashi Iwai343a04b2011-07-06 14:28:39 +02003675static int alc_auto_create_hp_out(struct hda_codec *codec)
3676{
3677 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003678 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3679 spec->autocfg.hp_pins,
3680 spec->multiout.hp_out_nid,
3681 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003682}
3683
3684static int alc_auto_create_speaker_out(struct hda_codec *codec)
3685{
3686 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003687 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3688 spec->autocfg.speaker_pins,
3689 spec->multiout.extra_out_nid,
3690 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003691}
3692
Takashi Iwai343a04b2011-07-06 14:28:39 +02003693static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003694 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003695 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003696{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003697 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003698 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003699 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003700
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003701 alc_set_pin_output(codec, pin, pin_type);
3702 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003703 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003704 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003705 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003706 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003707 mix = srcs[i];
3708 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003709 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003710 if (!mix)
3711 return;
3712
3713 /* need the manual connection? */
3714 if (num > 1)
3715 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3716 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003717 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3718 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003719 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003720 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003721 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003722 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003723 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003724 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3725 if (nid)
3726 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3727 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003728
3729 /* unmute DAC if it's not assigned to a mixer */
3730 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3731 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3732 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3733 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003734}
3735
Takashi Iwai343a04b2011-07-06 14:28:39 +02003736static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003737{
3738 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003739 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003740 int i;
3741
3742 for (i = 0; i <= HDA_SIDE; i++) {
3743 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3744 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003745 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003746 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003747 }
3748}
3749
Takashi Iwai343a04b2011-07-06 14:28:39 +02003750static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003751{
3752 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003753 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003754 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003755
David Henningsson636030e2011-10-12 19:26:03 +02003756 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003757 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3758 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003759 pin = spec->autocfg.hp_pins[i];
3760 if (!pin)
3761 break;
3762 dac = spec->multiout.hp_out_nid[i];
3763 if (!dac) {
3764 if (i > 0 && spec->multiout.hp_out_nid[0])
3765 dac = spec->multiout.hp_out_nid[0];
3766 else
3767 dac = spec->multiout.dac_nids[0];
3768 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003769 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3770 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003771 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003772 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3773 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003774 pin = spec->autocfg.speaker_pins[i];
3775 if (!pin)
3776 break;
3777 dac = spec->multiout.extra_out_nid[i];
3778 if (!dac) {
3779 if (i > 0 && spec->multiout.extra_out_nid[0])
3780 dac = spec->multiout.extra_out_nid[0];
3781 else
3782 dac = spec->multiout.dac_nids[0];
3783 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003784 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3785 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003786}
3787
Takashi Iwai276dd702012-02-17 16:17:03 +01003788/* check whether the given pin can be a multi-io pin */
3789static bool can_be_multiio_pin(struct hda_codec *codec,
3790 unsigned int location, hda_nid_t nid)
3791{
3792 unsigned int defcfg, caps;
3793
3794 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3795 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3796 return false;
3797 if (location && get_defcfg_location(defcfg) != location)
3798 return false;
3799 caps = snd_hda_query_pin_caps(codec, nid);
3800 if (!(caps & AC_PINCAP_OUT))
3801 return false;
3802 return true;
3803}
3804
Takashi Iwaice764ab2011-04-27 16:35:23 +02003805/*
3806 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003807 *
3808 * When hardwired is set, try to fill ony hardwired pins, and returns
3809 * zero if any pins are filled, non-zero if nothing found.
3810 * When hardwired is off, try to fill possible input pins, and returns
3811 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003812 */
3813static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003814 hda_nid_t reference_pin,
3815 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003816{
3817 struct alc_spec *spec = codec->spec;
3818 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003819 int type, i, j, dacs, num_pins, old_pins;
3820 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3821 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003822 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003823
Takashi Iwai276dd702012-02-17 16:17:03 +01003824 old_pins = spec->multi_ios;
3825 if (old_pins >= 2)
3826 goto end_fill;
3827
3828 num_pins = 0;
3829 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3830 for (i = 0; i < cfg->num_inputs; i++) {
3831 if (cfg->inputs[i].type != type)
3832 continue;
3833 if (can_be_multiio_pin(codec, location,
3834 cfg->inputs[i].pin))
3835 num_pins++;
3836 }
3837 }
3838 if (num_pins < 2)
3839 goto end_fill;
3840
Takashi Iwai07b18f62011-11-10 15:42:54 +01003841 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003842 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3843 for (i = 0; i < cfg->num_inputs; i++) {
3844 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003845 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003846
Takashi Iwaice764ab2011-04-27 16:35:23 +02003847 if (cfg->inputs[i].type != type)
3848 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003849 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003850 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003851 for (j = 0; j < spec->multi_ios; j++) {
3852 if (nid == spec->multi_io[j].pin)
3853 break;
3854 }
3855 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003856 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003857
3858 if (offset && offset + spec->multi_ios < dacs) {
3859 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003860 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3861 dac = 0;
3862 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003863 if (hardwired)
3864 dac = get_dac_if_single(codec, nid);
3865 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003866 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003867 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003868 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003869 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003870 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003871 spec->multi_io[spec->multi_ios].pin = nid;
3872 spec->multi_io[spec->multi_ios].dac = dac;
3873 spec->multi_ios++;
3874 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003875 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003876 }
3877 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003878 end_fill:
3879 if (badness)
3880 badness = BAD_MULTI_IO;
3881 if (old_pins == spec->multi_ios) {
3882 if (hardwired)
3883 return 1; /* nothing found */
3884 else
3885 return badness; /* no badness if nothing found */
3886 }
3887 if (!hardwired && spec->multi_ios < 2) {
3888 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003889 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003890 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003891
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003892 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003893}
3894
3895static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3896 struct snd_ctl_elem_info *uinfo)
3897{
3898 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3899 struct alc_spec *spec = codec->spec;
3900
3901 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3902 uinfo->count = 1;
3903 uinfo->value.enumerated.items = spec->multi_ios + 1;
3904 if (uinfo->value.enumerated.item > spec->multi_ios)
3905 uinfo->value.enumerated.item = spec->multi_ios;
3906 sprintf(uinfo->value.enumerated.name, "%dch",
3907 (uinfo->value.enumerated.item + 1) * 2);
3908 return 0;
3909}
3910
3911static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3912 struct snd_ctl_elem_value *ucontrol)
3913{
3914 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3915 struct alc_spec *spec = codec->spec;
3916 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3917 return 0;
3918}
3919
3920static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3921{
3922 struct alc_spec *spec = codec->spec;
3923 hda_nid_t nid = spec->multi_io[idx].pin;
3924
3925 if (!spec->multi_io[idx].ctl_in)
3926 spec->multi_io[idx].ctl_in =
3927 snd_hda_codec_read(codec, nid, 0,
3928 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3929 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003930 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003931 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3932 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3933 HDA_AMP_MUTE, 0);
3934 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3935 } else {
3936 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3937 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3938 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003939 snd_hda_set_pin_ctl_cache(codec, nid,
3940 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003941 }
3942 return 0;
3943}
3944
3945static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3946 struct snd_ctl_elem_value *ucontrol)
3947{
3948 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3949 struct alc_spec *spec = codec->spec;
3950 int i, ch;
3951
3952 ch = ucontrol->value.enumerated.item[0];
3953 if (ch < 0 || ch > spec->multi_ios)
3954 return -EINVAL;
3955 if (ch == (spec->ext_channel_count - 1) / 2)
3956 return 0;
3957 spec->ext_channel_count = (ch + 1) * 2;
3958 for (i = 0; i < spec->multi_ios; i++)
3959 alc_set_multi_io(codec, i, i < ch);
3960 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003961 if (spec->need_dac_fix && !spec->const_channel_count)
3962 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003963 return 1;
3964}
3965
Takashi Iwaia9111322011-05-02 11:30:18 +02003966static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003967 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3968 .name = "Channel Mode",
3969 .info = alc_auto_ch_mode_info,
3970 .get = alc_auto_ch_mode_get,
3971 .put = alc_auto_ch_mode_put,
3972};
3973
Takashi Iwai23c09b02011-08-19 09:05:35 +02003974static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003975{
3976 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003977
Takashi Iwaic2674682011-08-24 17:57:44 +02003978 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003979 struct snd_kcontrol_new *knew;
3980
3981 knew = alc_kcontrol_new(spec);
3982 if (!knew)
3983 return -ENOMEM;
3984 *knew = alc_auto_channel_mode_enum;
3985 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3986 if (!knew->name)
3987 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003988 }
3989 return 0;
3990}
3991
Takashi Iwai1d045db2011-07-07 18:23:21 +02003992/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3993 * active input pins
3994 */
3995static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3996{
3997 struct alc_spec *spec = codec->spec;
3998 const struct hda_input_mux *imux;
3999 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4000 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4001 int i, n, nums;
4002
4003 imux = spec->input_mux;
4004 if (!imux)
4005 return;
4006 if (spec->dyn_adc_switch)
4007 return;
4008
Takashi Iwai26acaf02012-03-22 14:36:50 +01004009 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004010 nums = 0;
4011 for (n = 0; n < spec->num_adc_nids; n++) {
4012 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004013 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004014 for (i = 0; i < imux->num_items; i++) {
4015 hda_nid_t pin = spec->imux_pins[i];
4016 if (pin) {
4017 if (get_connection_index(codec, cap, pin) < 0)
4018 break;
4019 } else if (num_conns <= imux->items[i].index)
4020 break;
4021 }
4022 if (i >= imux->num_items) {
4023 adc_nids[nums] = spec->private_adc_nids[n];
4024 capsrc_nids[nums++] = cap;
4025 }
4026 }
4027 if (!nums) {
4028 /* check whether ADC-switch is possible */
4029 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004030 if (spec->shared_mic_hp) {
4031 spec->shared_mic_hp = 0;
4032 spec->private_imux[0].num_items = 1;
4033 goto again;
4034 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004035 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4036 " using fallback 0x%x\n",
4037 codec->chip_name, spec->private_adc_nids[0]);
4038 spec->num_adc_nids = 1;
4039 spec->auto_mic = 0;
4040 return;
4041 }
4042 } else if (nums != spec->num_adc_nids) {
4043 memcpy(spec->private_adc_nids, adc_nids,
4044 nums * sizeof(hda_nid_t));
4045 memcpy(spec->private_capsrc_nids, capsrc_nids,
4046 nums * sizeof(hda_nid_t));
4047 spec->num_adc_nids = nums;
4048 }
4049
4050 if (spec->auto_mic)
4051 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004052 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004053 spec->num_adc_nids = 1; /* reduce to a single ADC */
4054}
4055
4056/*
4057 * initialize ADC paths
4058 */
4059static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4060{
4061 struct alc_spec *spec = codec->spec;
4062 hda_nid_t nid;
4063
4064 nid = spec->adc_nids[adc_idx];
4065 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004066 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004067 snd_hda_codec_write(codec, nid, 0,
4068 AC_VERB_SET_AMP_GAIN_MUTE,
4069 AMP_IN_MUTE(0));
4070 return;
4071 }
4072 if (!spec->capsrc_nids)
4073 return;
4074 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004075 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004076 snd_hda_codec_write(codec, nid, 0,
4077 AC_VERB_SET_AMP_GAIN_MUTE,
4078 AMP_OUT_MUTE);
4079}
4080
4081static void alc_auto_init_input_src(struct hda_codec *codec)
4082{
4083 struct alc_spec *spec = codec->spec;
4084 int c, nums;
4085
4086 for (c = 0; c < spec->num_adc_nids; c++)
4087 alc_auto_init_adc(codec, c);
4088 if (spec->dyn_adc_switch)
4089 nums = 1;
4090 else
4091 nums = spec->num_adc_nids;
4092 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004093 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004094}
4095
4096/* add mic boosts if needed */
4097static int alc_auto_add_mic_boost(struct hda_codec *codec)
4098{
4099 struct alc_spec *spec = codec->spec;
4100 struct auto_pin_cfg *cfg = &spec->autocfg;
4101 int i, err;
4102 int type_idx = 0;
4103 hda_nid_t nid;
4104 const char *prev_label = NULL;
4105
4106 for (i = 0; i < cfg->num_inputs; i++) {
4107 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4108 break;
4109 nid = cfg->inputs[i].pin;
4110 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4111 const char *label;
4112 char boost_label[32];
4113
4114 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004115 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4116 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004117 if (prev_label && !strcmp(label, prev_label))
4118 type_idx++;
4119 else
4120 type_idx = 0;
4121 prev_label = label;
4122
4123 snprintf(boost_label, sizeof(boost_label),
4124 "%s Boost Volume", label);
4125 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4126 boost_label, type_idx,
4127 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4128 if (err < 0)
4129 return err;
4130 }
4131 }
4132 return 0;
4133}
4134
4135/* select or unmute the given capsrc route */
4136static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4137 int idx)
4138{
4139 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4140 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4141 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004142 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004143 snd_hda_codec_write_cache(codec, cap, 0,
4144 AC_VERB_SET_CONNECT_SEL, idx);
4145 }
4146}
4147
4148/* set the default connection to that pin */
4149static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4150{
4151 struct alc_spec *spec = codec->spec;
4152 int i;
4153
4154 if (!pin)
4155 return 0;
4156 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004157 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004158 int idx;
4159
4160 idx = get_connection_index(codec, cap, pin);
4161 if (idx < 0)
4162 continue;
4163 select_or_unmute_capsrc(codec, cap, idx);
4164 return i; /* return the found index */
4165 }
4166 return -1; /* not found */
4167}
4168
4169/* initialize some special cases for input sources */
4170static void alc_init_special_input_src(struct hda_codec *codec)
4171{
4172 struct alc_spec *spec = codec->spec;
4173 int i;
4174
4175 for (i = 0; i < spec->autocfg.num_inputs; i++)
4176 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4177}
4178
4179/* assign appropriate capture mixers */
4180static void set_capture_mixer(struct hda_codec *codec)
4181{
4182 struct alc_spec *spec = codec->spec;
4183 static const struct snd_kcontrol_new *caps[2][3] = {
4184 { alc_capture_mixer_nosrc1,
4185 alc_capture_mixer_nosrc2,
4186 alc_capture_mixer_nosrc3 },
4187 { alc_capture_mixer1,
4188 alc_capture_mixer2,
4189 alc_capture_mixer3 },
4190 };
4191
4192 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004193 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004194 if (!spec->capsrc_nids)
4195 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004196 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004197 return; /* no volume in capsrc, too */
4198 spec->vol_in_capsrc = 1;
4199 }
4200
4201 if (spec->num_adc_nids > 0) {
4202 int mux = 0;
4203 int num_adcs = 0;
4204
4205 if (spec->input_mux && spec->input_mux->num_items > 1)
4206 mux = 1;
4207 if (spec->auto_mic) {
4208 num_adcs = 1;
4209 mux = 0;
4210 } else if (spec->dyn_adc_switch)
4211 num_adcs = 1;
4212 if (!num_adcs) {
4213 if (spec->num_adc_nids > 3)
4214 spec->num_adc_nids = 3;
4215 else if (!spec->num_adc_nids)
4216 return;
4217 num_adcs = spec->num_adc_nids;
4218 }
4219 spec->cap_mixer = caps[mux][num_adcs - 1];
4220 }
4221}
4222
4223/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004224 * standard auto-parser initializations
4225 */
4226static void alc_auto_init_std(struct hda_codec *codec)
4227{
4228 struct alc_spec *spec = codec->spec;
4229 alc_auto_init_multi_out(codec);
4230 alc_auto_init_extra_out(codec);
4231 alc_auto_init_analog_input(codec);
4232 alc_auto_init_input_src(codec);
4233 alc_auto_init_digital(codec);
4234 if (spec->unsol_event)
4235 alc_inithook(codec);
4236}
4237
4238/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004239 * Digital-beep handlers
4240 */
4241#ifdef CONFIG_SND_HDA_INPUT_BEEP
4242#define set_beep_amp(spec, nid, idx, dir) \
4243 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4244
4245static const struct snd_pci_quirk beep_white_list[] = {
4246 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4247 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4248 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4249 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004250 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004251 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4252 {}
4253};
4254
4255static inline int has_cdefine_beep(struct hda_codec *codec)
4256{
4257 struct alc_spec *spec = codec->spec;
4258 const struct snd_pci_quirk *q;
4259 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4260 if (q)
4261 return q->value;
4262 return spec->cdefine.enable_pcbeep;
4263}
4264#else
4265#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4266#define has_cdefine_beep(codec) 0
4267#endif
4268
4269/* parse the BIOS configuration and set up the alc_spec */
4270/* return 1 if successful, 0 if the proper config is not found,
4271 * or a negative error code
4272 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004273static int alc_parse_auto_config(struct hda_codec *codec,
4274 const hda_nid_t *ignore_nids,
4275 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004276{
4277 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004278 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004279 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004280
Takashi Iwai53c334a2011-08-23 18:27:14 +02004281 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4282 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004283 if (err < 0)
4284 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004285 if (!cfg->line_outs) {
4286 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004287 spec->multiout.max_channels = 2;
4288 spec->no_analog = 1;
4289 goto dig_only;
4290 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004291 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004292 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004293
Takashi Iwai06503672011-10-06 08:27:19 +02004294 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4295 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004296 /* use HP as primary out */
4297 cfg->speaker_outs = cfg->line_outs;
4298 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4299 sizeof(cfg->speaker_pins));
4300 cfg->line_outs = cfg->hp_outs;
4301 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4302 cfg->hp_outs = 0;
4303 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4304 cfg->line_out_type = AUTO_PIN_HP_OUT;
4305 }
4306
Takashi Iwai1d045db2011-07-07 18:23:21 +02004307 err = alc_auto_fill_dac_nids(codec);
4308 if (err < 0)
4309 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004310 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004311 if (err < 0)
4312 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004313 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004314 if (err < 0)
4315 return err;
4316 err = alc_auto_create_hp_out(codec);
4317 if (err < 0)
4318 return err;
4319 err = alc_auto_create_speaker_out(codec);
4320 if (err < 0)
4321 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004322 err = alc_auto_create_shared_input(codec);
4323 if (err < 0)
4324 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004325 err = alc_auto_create_input_ctls(codec);
4326 if (err < 0)
4327 return err;
4328
4329 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4330
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004331 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004332 alc_auto_parse_digital(codec);
4333
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004334 if (!spec->no_analog)
4335 alc_remove_invalid_adc_nids(codec);
4336
4337 if (ssid_nids)
4338 alc_ssid_check(codec, ssid_nids);
4339
4340 if (!spec->no_analog) {
4341 alc_auto_check_switches(codec);
4342 err = alc_auto_add_mic_boost(codec);
4343 if (err < 0)
4344 return err;
4345 }
4346
Takashi Iwai1d045db2011-07-07 18:23:21 +02004347 if (spec->kctls.list)
4348 add_mixer(spec, spec->kctls.list);
4349
Takashi Iwai070cff42012-02-21 12:54:17 +01004350 if (!spec->no_analog && !spec->cap_mixer)
4351 set_capture_mixer(codec);
4352
Takashi Iwai1d045db2011-07-07 18:23:21 +02004353 return 1;
4354}
4355
Takashi Iwai3de95172012-05-07 18:03:15 +02004356/* common preparation job for alc_spec */
4357static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4358{
4359 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4360 int err;
4361
4362 if (!spec)
4363 return -ENOMEM;
4364 codec->spec = spec;
4365 spec->mixer_nid = mixer_nid;
4366
4367 err = alc_codec_rename_from_preset(codec);
4368 if (err < 0) {
4369 kfree(spec);
4370 return err;
4371 }
4372 return 0;
4373}
4374
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004375static int alc880_parse_auto_config(struct hda_codec *codec)
4376{
4377 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004378 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004379 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4380}
4381
Takashi Iwai1d045db2011-07-07 18:23:21 +02004382/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004383 * ALC880 fix-ups
4384 */
4385enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004386 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004387 ALC880_FIXUP_GPIO2,
4388 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004389 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004390 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004391 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004392 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004393 ALC880_FIXUP_VOL_KNOB,
4394 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004395 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004396 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004397 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004398 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004399 ALC880_FIXUP_3ST_BASE,
4400 ALC880_FIXUP_3ST,
4401 ALC880_FIXUP_3ST_DIG,
4402 ALC880_FIXUP_5ST_BASE,
4403 ALC880_FIXUP_5ST,
4404 ALC880_FIXUP_5ST_DIG,
4405 ALC880_FIXUP_6ST_BASE,
4406 ALC880_FIXUP_6ST,
4407 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004408};
4409
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004410/* enable the volume-knob widget support on NID 0x21 */
4411static void alc880_fixup_vol_knob(struct hda_codec *codec,
4412 const struct alc_fixup *fix, int action)
4413{
4414 if (action == ALC_FIXUP_ACT_PROBE)
4415 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4416}
4417
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004418static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004419 [ALC880_FIXUP_GPIO1] = {
4420 .type = ALC_FIXUP_VERBS,
4421 .v.verbs = alc_gpio1_init_verbs,
4422 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004423 [ALC880_FIXUP_GPIO2] = {
4424 .type = ALC_FIXUP_VERBS,
4425 .v.verbs = alc_gpio2_init_verbs,
4426 },
4427 [ALC880_FIXUP_MEDION_RIM] = {
4428 .type = ALC_FIXUP_VERBS,
4429 .v.verbs = (const struct hda_verb[]) {
4430 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4431 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4432 { }
4433 },
4434 .chained = true,
4435 .chain_id = ALC880_FIXUP_GPIO2,
4436 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004437 [ALC880_FIXUP_LG] = {
4438 .type = ALC_FIXUP_PINS,
4439 .v.pins = (const struct alc_pincfg[]) {
4440 /* disable bogus unused pins */
4441 { 0x16, 0x411111f0 },
4442 { 0x18, 0x411111f0 },
4443 { 0x1a, 0x411111f0 },
4444 { }
4445 }
4446 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004447 [ALC880_FIXUP_W810] = {
4448 .type = ALC_FIXUP_PINS,
4449 .v.pins = (const struct alc_pincfg[]) {
4450 /* disable bogus unused pins */
4451 { 0x17, 0x411111f0 },
4452 { }
4453 },
4454 .chained = true,
4455 .chain_id = ALC880_FIXUP_GPIO2,
4456 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004457 [ALC880_FIXUP_EAPD_COEF] = {
4458 .type = ALC_FIXUP_VERBS,
4459 .v.verbs = (const struct hda_verb[]) {
4460 /* change to EAPD mode */
4461 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4462 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4463 {}
4464 },
4465 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004466 [ALC880_FIXUP_TCL_S700] = {
4467 .type = ALC_FIXUP_VERBS,
4468 .v.verbs = (const struct hda_verb[]) {
4469 /* change to EAPD mode */
4470 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4471 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4472 {}
4473 },
4474 .chained = true,
4475 .chain_id = ALC880_FIXUP_GPIO2,
4476 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004477 [ALC880_FIXUP_VOL_KNOB] = {
4478 .type = ALC_FIXUP_FUNC,
4479 .v.func = alc880_fixup_vol_knob,
4480 },
4481 [ALC880_FIXUP_FUJITSU] = {
4482 /* override all pins as BIOS on old Amilo is broken */
4483 .type = ALC_FIXUP_PINS,
4484 .v.pins = (const struct alc_pincfg[]) {
4485 { 0x14, 0x0121411f }, /* HP */
4486 { 0x15, 0x99030120 }, /* speaker */
4487 { 0x16, 0x99030130 }, /* bass speaker */
4488 { 0x17, 0x411111f0 }, /* N/A */
4489 { 0x18, 0x411111f0 }, /* N/A */
4490 { 0x19, 0x01a19950 }, /* mic-in */
4491 { 0x1a, 0x411111f0 }, /* N/A */
4492 { 0x1b, 0x411111f0 }, /* N/A */
4493 { 0x1c, 0x411111f0 }, /* N/A */
4494 { 0x1d, 0x411111f0 }, /* N/A */
4495 { 0x1e, 0x01454140 }, /* SPDIF out */
4496 { }
4497 },
4498 .chained = true,
4499 .chain_id = ALC880_FIXUP_VOL_KNOB,
4500 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004501 [ALC880_FIXUP_F1734] = {
4502 /* almost compatible with FUJITSU, but no bass and SPDIF */
4503 .type = ALC_FIXUP_PINS,
4504 .v.pins = (const struct alc_pincfg[]) {
4505 { 0x14, 0x0121411f }, /* HP */
4506 { 0x15, 0x99030120 }, /* speaker */
4507 { 0x16, 0x411111f0 }, /* N/A */
4508 { 0x17, 0x411111f0 }, /* N/A */
4509 { 0x18, 0x411111f0 }, /* N/A */
4510 { 0x19, 0x01a19950 }, /* mic-in */
4511 { 0x1a, 0x411111f0 }, /* N/A */
4512 { 0x1b, 0x411111f0 }, /* N/A */
4513 { 0x1c, 0x411111f0 }, /* N/A */
4514 { 0x1d, 0x411111f0 }, /* N/A */
4515 { 0x1e, 0x411111f0 }, /* N/A */
4516 { }
4517 },
4518 .chained = true,
4519 .chain_id = ALC880_FIXUP_VOL_KNOB,
4520 },
Takashi Iwai817de922012-02-20 17:20:48 +01004521 [ALC880_FIXUP_UNIWILL] = {
4522 /* need to fix HP and speaker pins to be parsed correctly */
4523 .type = ALC_FIXUP_PINS,
4524 .v.pins = (const struct alc_pincfg[]) {
4525 { 0x14, 0x0121411f }, /* HP */
4526 { 0x15, 0x99030120 }, /* speaker */
4527 { 0x16, 0x99030130 }, /* bass speaker */
4528 { }
4529 },
4530 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004531 [ALC880_FIXUP_UNIWILL_DIG] = {
4532 .type = ALC_FIXUP_PINS,
4533 .v.pins = (const struct alc_pincfg[]) {
4534 /* disable bogus unused pins */
4535 { 0x17, 0x411111f0 },
4536 { 0x19, 0x411111f0 },
4537 { 0x1b, 0x411111f0 },
4538 { 0x1f, 0x411111f0 },
4539 { }
4540 }
4541 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004542 [ALC880_FIXUP_Z71V] = {
4543 .type = ALC_FIXUP_PINS,
4544 .v.pins = (const struct alc_pincfg[]) {
4545 /* set up the whole pins as BIOS is utterly broken */
4546 { 0x14, 0x99030120 }, /* speaker */
4547 { 0x15, 0x0121411f }, /* HP */
4548 { 0x16, 0x411111f0 }, /* N/A */
4549 { 0x17, 0x411111f0 }, /* N/A */
4550 { 0x18, 0x01a19950 }, /* mic-in */
4551 { 0x19, 0x411111f0 }, /* N/A */
4552 { 0x1a, 0x01813031 }, /* line-in */
4553 { 0x1b, 0x411111f0 }, /* N/A */
4554 { 0x1c, 0x411111f0 }, /* N/A */
4555 { 0x1d, 0x411111f0 }, /* N/A */
4556 { 0x1e, 0x0144111e }, /* SPDIF */
4557 { }
4558 }
4559 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004560 [ALC880_FIXUP_3ST_BASE] = {
4561 .type = ALC_FIXUP_PINS,
4562 .v.pins = (const struct alc_pincfg[]) {
4563 { 0x14, 0x01014010 }, /* line-out */
4564 { 0x15, 0x411111f0 }, /* N/A */
4565 { 0x16, 0x411111f0 }, /* N/A */
4566 { 0x17, 0x411111f0 }, /* N/A */
4567 { 0x18, 0x01a19c30 }, /* mic-in */
4568 { 0x19, 0x0121411f }, /* HP */
4569 { 0x1a, 0x01813031 }, /* line-in */
4570 { 0x1b, 0x02a19c40 }, /* front-mic */
4571 { 0x1c, 0x411111f0 }, /* N/A */
4572 { 0x1d, 0x411111f0 }, /* N/A */
4573 /* 0x1e is filled in below */
4574 { 0x1f, 0x411111f0 }, /* N/A */
4575 { }
4576 }
4577 },
4578 [ALC880_FIXUP_3ST] = {
4579 .type = ALC_FIXUP_PINS,
4580 .v.pins = (const struct alc_pincfg[]) {
4581 { 0x1e, 0x411111f0 }, /* N/A */
4582 { }
4583 },
4584 .chained = true,
4585 .chain_id = ALC880_FIXUP_3ST_BASE,
4586 },
4587 [ALC880_FIXUP_3ST_DIG] = {
4588 .type = ALC_FIXUP_PINS,
4589 .v.pins = (const struct alc_pincfg[]) {
4590 { 0x1e, 0x0144111e }, /* SPDIF */
4591 { }
4592 },
4593 .chained = true,
4594 .chain_id = ALC880_FIXUP_3ST_BASE,
4595 },
4596 [ALC880_FIXUP_5ST_BASE] = {
4597 .type = ALC_FIXUP_PINS,
4598 .v.pins = (const struct alc_pincfg[]) {
4599 { 0x14, 0x01014010 }, /* front */
4600 { 0x15, 0x411111f0 }, /* N/A */
4601 { 0x16, 0x01011411 }, /* CLFE */
4602 { 0x17, 0x01016412 }, /* surr */
4603 { 0x18, 0x01a19c30 }, /* mic-in */
4604 { 0x19, 0x0121411f }, /* HP */
4605 { 0x1a, 0x01813031 }, /* line-in */
4606 { 0x1b, 0x02a19c40 }, /* front-mic */
4607 { 0x1c, 0x411111f0 }, /* N/A */
4608 { 0x1d, 0x411111f0 }, /* N/A */
4609 /* 0x1e is filled in below */
4610 { 0x1f, 0x411111f0 }, /* N/A */
4611 { }
4612 }
4613 },
4614 [ALC880_FIXUP_5ST] = {
4615 .type = ALC_FIXUP_PINS,
4616 .v.pins = (const struct alc_pincfg[]) {
4617 { 0x1e, 0x411111f0 }, /* N/A */
4618 { }
4619 },
4620 .chained = true,
4621 .chain_id = ALC880_FIXUP_5ST_BASE,
4622 },
4623 [ALC880_FIXUP_5ST_DIG] = {
4624 .type = ALC_FIXUP_PINS,
4625 .v.pins = (const struct alc_pincfg[]) {
4626 { 0x1e, 0x0144111e }, /* SPDIF */
4627 { }
4628 },
4629 .chained = true,
4630 .chain_id = ALC880_FIXUP_5ST_BASE,
4631 },
4632 [ALC880_FIXUP_6ST_BASE] = {
4633 .type = ALC_FIXUP_PINS,
4634 .v.pins = (const struct alc_pincfg[]) {
4635 { 0x14, 0x01014010 }, /* front */
4636 { 0x15, 0x01016412 }, /* surr */
4637 { 0x16, 0x01011411 }, /* CLFE */
4638 { 0x17, 0x01012414 }, /* side */
4639 { 0x18, 0x01a19c30 }, /* mic-in */
4640 { 0x19, 0x02a19c40 }, /* front-mic */
4641 { 0x1a, 0x01813031 }, /* line-in */
4642 { 0x1b, 0x0121411f }, /* HP */
4643 { 0x1c, 0x411111f0 }, /* N/A */
4644 { 0x1d, 0x411111f0 }, /* N/A */
4645 /* 0x1e is filled in below */
4646 { 0x1f, 0x411111f0 }, /* N/A */
4647 { }
4648 }
4649 },
4650 [ALC880_FIXUP_6ST] = {
4651 .type = ALC_FIXUP_PINS,
4652 .v.pins = (const struct alc_pincfg[]) {
4653 { 0x1e, 0x411111f0 }, /* N/A */
4654 { }
4655 },
4656 .chained = true,
4657 .chain_id = ALC880_FIXUP_6ST_BASE,
4658 },
4659 [ALC880_FIXUP_6ST_DIG] = {
4660 .type = ALC_FIXUP_PINS,
4661 .v.pins = (const struct alc_pincfg[]) {
4662 { 0x1e, 0x0144111e }, /* SPDIF */
4663 { }
4664 },
4665 .chained = true,
4666 .chain_id = ALC880_FIXUP_6ST_BASE,
4667 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004668};
4669
4670static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004671 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004672 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004673 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4674 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004675 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004676 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004677 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004678 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004679 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004680 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004681 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004682 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004683 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004684 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004685 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004686 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4687 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4688 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004689 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004690
4691 /* Below is the copied entries from alc880_quirks.c.
4692 * It's not quite sure whether BIOS sets the correct pin-config table
4693 * on these machines, thus they are kept to be compatible with
4694 * the old static quirks. Once when it's confirmed to work without
4695 * these overrides, it'd be better to remove.
4696 */
4697 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4698 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4699 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4700 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4701 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4702 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4703 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4704 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4705 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4706 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4707 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4708 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4709 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4710 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4711 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4712 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4713 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4714 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4715 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4716 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4717 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4718 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4719 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4720 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4721 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4722 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4723 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4724 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4725 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4726 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4727 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4728 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4729 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4730 /* default Intel */
4731 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4732 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4733 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4734 {}
4735};
4736
4737static const struct alc_model_fixup alc880_fixup_models[] = {
4738 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4739 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4740 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4741 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4742 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4743 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004744 {}
4745};
4746
4747
4748/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004749 * OK, here we have finally the patch for ALC880
4750 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004751static int patch_alc880(struct hda_codec *codec)
4752{
4753 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004754 int err;
4755
Takashi Iwai3de95172012-05-07 18:03:15 +02004756 err = alc_alloc_spec(codec, 0x0b);
4757 if (err < 0)
4758 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004759
Takashi Iwai3de95172012-05-07 18:03:15 +02004760 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004761 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004762
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004763 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4764 alc880_fixups);
4765 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004766
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004767 /* automatic parse from the BIOS config */
4768 err = alc880_parse_auto_config(codec);
4769 if (err < 0)
4770 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004771
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004772 if (!spec->no_analog) {
4773 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004774 if (err < 0)
4775 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004776 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4777 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004778
Takashi Iwai1d045db2011-07-07 18:23:21 +02004779 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004780
Takashi Iwai589876e2012-02-20 15:47:55 +01004781 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4782
Takashi Iwai1d045db2011-07-07 18:23:21 +02004783 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004784
4785 error:
4786 alc_free(codec);
4787 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004788}
4789
4790
4791/*
4792 * ALC260 support
4793 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004794static int alc260_parse_auto_config(struct hda_codec *codec)
4795{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004796 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004797 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4798 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004799}
4800
Takashi Iwai1d045db2011-07-07 18:23:21 +02004801/*
4802 * Pin config fixes
4803 */
4804enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004805 ALC260_FIXUP_HP_DC5750,
4806 ALC260_FIXUP_HP_PIN_0F,
4807 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004808 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004809 ALC260_FIXUP_GPIO1_TOGGLE,
4810 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004811 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004812 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004813};
4814
Takashi Iwai20f7d922012-02-16 12:35:16 +01004815static void alc260_gpio1_automute(struct hda_codec *codec)
4816{
4817 struct alc_spec *spec = codec->spec;
4818 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4819 spec->hp_jack_present);
4820}
4821
4822static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4823 const struct alc_fixup *fix, int action)
4824{
4825 struct alc_spec *spec = codec->spec;
4826 if (action == ALC_FIXUP_ACT_PROBE) {
4827 /* although the machine has only one output pin, we need to
4828 * toggle GPIO1 according to the jack state
4829 */
4830 spec->automute_hook = alc260_gpio1_automute;
4831 spec->detect_hp = 1;
4832 spec->automute_speaker = 1;
4833 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4834 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4835 spec->unsol_event = alc_sku_unsol_event;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004836 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004837 }
4838}
4839
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004840static void alc260_fixup_kn1(struct hda_codec *codec,
4841 const struct alc_fixup *fix, int action)
4842{
4843 struct alc_spec *spec = codec->spec;
4844 static const struct alc_pincfg pincfgs[] = {
4845 { 0x0f, 0x02214000 }, /* HP/speaker */
4846 { 0x12, 0x90a60160 }, /* int mic */
4847 { 0x13, 0x02a19000 }, /* ext mic */
4848 { 0x18, 0x01446000 }, /* SPDIF out */
4849 /* disable bogus I/O pins */
4850 { 0x10, 0x411111f0 },
4851 { 0x11, 0x411111f0 },
4852 { 0x14, 0x411111f0 },
4853 { 0x15, 0x411111f0 },
4854 { 0x16, 0x411111f0 },
4855 { 0x17, 0x411111f0 },
4856 { 0x19, 0x411111f0 },
4857 { }
4858 };
4859
4860 switch (action) {
4861 case ALC_FIXUP_ACT_PRE_PROBE:
4862 alc_apply_pincfgs(codec, pincfgs);
4863 break;
4864 case ALC_FIXUP_ACT_PROBE:
4865 spec->init_amp = ALC_INIT_NONE;
4866 break;
4867 }
4868}
4869
Takashi Iwai1d045db2011-07-07 18:23:21 +02004870static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004871 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004872 .type = ALC_FIXUP_PINS,
4873 .v.pins = (const struct alc_pincfg[]) {
4874 { 0x11, 0x90130110 }, /* speaker */
4875 { }
4876 }
4877 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004878 [ALC260_FIXUP_HP_PIN_0F] = {
4879 .type = ALC_FIXUP_PINS,
4880 .v.pins = (const struct alc_pincfg[]) {
4881 { 0x0f, 0x01214000 }, /* HP */
4882 { }
4883 }
4884 },
4885 [ALC260_FIXUP_COEF] = {
4886 .type = ALC_FIXUP_VERBS,
4887 .v.verbs = (const struct hda_verb[]) {
4888 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4889 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4890 { }
4891 },
4892 .chained = true,
4893 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4894 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004895 [ALC260_FIXUP_GPIO1] = {
4896 .type = ALC_FIXUP_VERBS,
4897 .v.verbs = alc_gpio1_init_verbs,
4898 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004899 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4900 .type = ALC_FIXUP_FUNC,
4901 .v.func = alc260_fixup_gpio1_toggle,
4902 .chained = true,
4903 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4904 },
4905 [ALC260_FIXUP_REPLACER] = {
4906 .type = ALC_FIXUP_VERBS,
4907 .v.verbs = (const struct hda_verb[]) {
4908 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4909 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4910 { }
4911 },
4912 .chained = true,
4913 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4914 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004915 [ALC260_FIXUP_HP_B1900] = {
4916 .type = ALC_FIXUP_FUNC,
4917 .v.func = alc260_fixup_gpio1_toggle,
4918 .chained = true,
4919 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004920 },
4921 [ALC260_FIXUP_KN1] = {
4922 .type = ALC_FIXUP_FUNC,
4923 .v.func = alc260_fixup_kn1,
4924 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004925};
4926
4927static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004928 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004929 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004930 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004931 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004932 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004933 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004934 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004935 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004936 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004937 {}
4938};
4939
4940/*
4941 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004942static int patch_alc260(struct hda_codec *codec)
4943{
4944 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004945 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004946
Takashi Iwai3de95172012-05-07 18:03:15 +02004947 err = alc_alloc_spec(codec, 0x07);
4948 if (err < 0)
4949 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004950
Takashi Iwai3de95172012-05-07 18:03:15 +02004951 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004952
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004953 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4954 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004955
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004956 /* automatic parse from the BIOS config */
4957 err = alc260_parse_auto_config(codec);
4958 if (err < 0)
4959 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004960
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004961 if (!spec->no_analog) {
4962 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004963 if (err < 0)
4964 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004965 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4966 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004967
Takashi Iwai1d045db2011-07-07 18:23:21 +02004968 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004969 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004970
Takashi Iwai589876e2012-02-20 15:47:55 +01004971 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4972
Takashi Iwai1d045db2011-07-07 18:23:21 +02004973 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004974
4975 error:
4976 alc_free(codec);
4977 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004978}
4979
4980
4981/*
4982 * ALC882/883/885/888/889 support
4983 *
4984 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4985 * configuration. Each pin widget can choose any input DACs and a mixer.
4986 * Each ADC is connected from a mixer of all inputs. This makes possible
4987 * 6-channel independent captures.
4988 *
4989 * In addition, an independent DAC for the multi-playback (not used in this
4990 * driver yet).
4991 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004992
4993/*
4994 * Pin config fixes
4995 */
4996enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004997 ALC882_FIXUP_ABIT_AW9D_MAX,
4998 ALC882_FIXUP_LENOVO_Y530,
4999 ALC882_FIXUP_PB_M5210,
5000 ALC882_FIXUP_ACER_ASPIRE_7736,
5001 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005002 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005003 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005004 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005005 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005006 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005007 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005008 ALC882_FIXUP_GPIO1,
5009 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005010 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005011 ALC889_FIXUP_COEF,
5012 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005013 ALC882_FIXUP_ACER_ASPIRE_4930G,
5014 ALC882_FIXUP_ACER_ASPIRE_8930G,
5015 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005016 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005017 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005018 ALC889_FIXUP_MBP_VREF,
5019 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005020};
5021
Takashi Iwai68ef0562011-11-09 18:24:44 +01005022static void alc889_fixup_coef(struct hda_codec *codec,
5023 const struct alc_fixup *fix, int action)
5024{
5025 if (action != ALC_FIXUP_ACT_INIT)
5026 return;
5027 alc889_coef_init(codec);
5028}
5029
Takashi Iwai56710872011-11-14 17:42:11 +01005030/* toggle speaker-output according to the hp-jack state */
5031static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5032{
5033 unsigned int gpiostate, gpiomask, gpiodir;
5034
5035 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5036 AC_VERB_GET_GPIO_DATA, 0);
5037
5038 if (!muted)
5039 gpiostate |= (1 << pin);
5040 else
5041 gpiostate &= ~(1 << pin);
5042
5043 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5044 AC_VERB_GET_GPIO_MASK, 0);
5045 gpiomask |= (1 << pin);
5046
5047 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5048 AC_VERB_GET_GPIO_DIRECTION, 0);
5049 gpiodir |= (1 << pin);
5050
5051
5052 snd_hda_codec_write(codec, codec->afg, 0,
5053 AC_VERB_SET_GPIO_MASK, gpiomask);
5054 snd_hda_codec_write(codec, codec->afg, 0,
5055 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5056
5057 msleep(1);
5058
5059 snd_hda_codec_write(codec, codec->afg, 0,
5060 AC_VERB_SET_GPIO_DATA, gpiostate);
5061}
5062
5063/* set up GPIO at initialization */
5064static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5065 const struct alc_fixup *fix, int action)
5066{
5067 if (action != ALC_FIXUP_ACT_INIT)
5068 return;
5069 alc882_gpio_mute(codec, 0, 0);
5070 alc882_gpio_mute(codec, 1, 0);
5071}
5072
Takashi Iwai02a237b2012-02-13 15:25:07 +01005073/* Fix the connection of some pins for ALC889:
5074 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5075 * work correctly (bko#42740)
5076 */
5077static void alc889_fixup_dac_route(struct hda_codec *codec,
5078 const struct alc_fixup *fix, int action)
5079{
5080 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005081 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005082 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5083 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5084 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5085 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5086 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5087 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005088 } else if (action == ALC_FIXUP_ACT_PROBE) {
5089 /* restore the connections */
5090 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5091 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5092 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5093 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5094 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005095 }
5096}
5097
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005098/* Set VREF on HP pin */
5099static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5100 const struct alc_fixup *fix, int action)
5101{
5102 struct alc_spec *spec = codec->spec;
5103 static hda_nid_t nids[2] = { 0x14, 0x15 };
5104 int i;
5105
5106 if (action != ALC_FIXUP_ACT_INIT)
5107 return;
5108 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5109 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5110 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5111 continue;
5112 val = snd_hda_codec_read(codec, nids[i], 0,
5113 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5114 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005115 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005116 spec->keep_vref_in_automute = 1;
5117 break;
5118 }
5119}
5120
5121/* Set VREF on speaker pins on imac91 */
5122static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5123 const struct alc_fixup *fix, int action)
5124{
5125 struct alc_spec *spec = codec->spec;
5126 static hda_nid_t nids[2] = { 0x18, 0x1a };
5127 int i;
5128
5129 if (action != ALC_FIXUP_ACT_INIT)
5130 return;
5131 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5132 unsigned int val;
5133 val = snd_hda_codec_read(codec, nids[i], 0,
5134 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5135 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005136 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005137 }
5138 spec->keep_vref_in_automute = 1;
5139}
5140
Takashi Iwai1d045db2011-07-07 18:23:21 +02005141static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005142 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005143 .type = ALC_FIXUP_PINS,
5144 .v.pins = (const struct alc_pincfg[]) {
5145 { 0x15, 0x01080104 }, /* side */
5146 { 0x16, 0x01011012 }, /* rear */
5147 { 0x17, 0x01016011 }, /* clfe */
5148 { }
5149 }
5150 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005151 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005152 .type = ALC_FIXUP_PINS,
5153 .v.pins = (const struct alc_pincfg[]) {
5154 { 0x15, 0x99130112 }, /* rear int speakers */
5155 { 0x16, 0x99130111 }, /* subwoofer */
5156 { }
5157 }
5158 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005159 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005160 .type = ALC_FIXUP_VERBS,
5161 .v.verbs = (const struct hda_verb[]) {
5162 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5163 {}
5164 }
5165 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005166 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005167 .type = ALC_FIXUP_FUNC,
5168 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005169 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005170 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005171 .type = ALC_FIXUP_PINS,
5172 .v.pins = (const struct alc_pincfg[]) {
5173 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5174 { }
5175 }
5176 },
Marton Balint8f239212012-03-05 21:33:23 +01005177 [ALC889_FIXUP_CD] = {
5178 .type = ALC_FIXUP_PINS,
5179 .v.pins = (const struct alc_pincfg[]) {
5180 { 0x1c, 0x993301f0 }, /* CD */
5181 { }
5182 }
5183 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005184 [ALC889_FIXUP_VAIO_TT] = {
5185 .type = ALC_FIXUP_PINS,
5186 .v.pins = (const struct alc_pincfg[]) {
5187 { 0x17, 0x90170111 }, /* hidden surround speaker */
5188 { }
5189 }
5190 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005191 [ALC888_FIXUP_EEE1601] = {
5192 .type = ALC_FIXUP_VERBS,
5193 .v.verbs = (const struct hda_verb[]) {
5194 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5195 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5196 { }
5197 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005198 },
5199 [ALC882_FIXUP_EAPD] = {
5200 .type = ALC_FIXUP_VERBS,
5201 .v.verbs = (const struct hda_verb[]) {
5202 /* change to EAPD mode */
5203 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5204 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5205 { }
5206 }
5207 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005208 [ALC883_FIXUP_EAPD] = {
5209 .type = ALC_FIXUP_VERBS,
5210 .v.verbs = (const struct hda_verb[]) {
5211 /* change to EAPD mode */
5212 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5213 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5214 { }
5215 }
5216 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005217 [ALC883_FIXUP_ACER_EAPD] = {
5218 .type = ALC_FIXUP_VERBS,
5219 .v.verbs = (const struct hda_verb[]) {
5220 /* eanable EAPD on Acer laptops */
5221 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5222 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5223 { }
5224 }
5225 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005226 [ALC882_FIXUP_GPIO1] = {
5227 .type = ALC_FIXUP_VERBS,
5228 .v.verbs = alc_gpio1_init_verbs,
5229 },
5230 [ALC882_FIXUP_GPIO2] = {
5231 .type = ALC_FIXUP_VERBS,
5232 .v.verbs = alc_gpio2_init_verbs,
5233 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005234 [ALC882_FIXUP_GPIO3] = {
5235 .type = ALC_FIXUP_VERBS,
5236 .v.verbs = alc_gpio3_init_verbs,
5237 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005238 [ALC882_FIXUP_ASUS_W2JC] = {
5239 .type = ALC_FIXUP_VERBS,
5240 .v.verbs = alc_gpio1_init_verbs,
5241 .chained = true,
5242 .chain_id = ALC882_FIXUP_EAPD,
5243 },
5244 [ALC889_FIXUP_COEF] = {
5245 .type = ALC_FIXUP_FUNC,
5246 .v.func = alc889_fixup_coef,
5247 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005248 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5249 .type = ALC_FIXUP_PINS,
5250 .v.pins = (const struct alc_pincfg[]) {
5251 { 0x16, 0x99130111 }, /* CLFE speaker */
5252 { 0x17, 0x99130112 }, /* surround speaker */
5253 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005254 },
5255 .chained = true,
5256 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005257 },
5258 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5259 .type = ALC_FIXUP_PINS,
5260 .v.pins = (const struct alc_pincfg[]) {
5261 { 0x16, 0x99130111 }, /* CLFE speaker */
5262 { 0x1b, 0x99130112 }, /* surround speaker */
5263 { }
5264 },
5265 .chained = true,
5266 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5267 },
5268 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5269 /* additional init verbs for Acer Aspire 8930G */
5270 .type = ALC_FIXUP_VERBS,
5271 .v.verbs = (const struct hda_verb[]) {
5272 /* Enable all DACs */
5273 /* DAC DISABLE/MUTE 1? */
5274 /* setting bits 1-5 disables DAC nids 0x02-0x06
5275 * apparently. Init=0x38 */
5276 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5277 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5278 /* DAC DISABLE/MUTE 2? */
5279 /* some bit here disables the other DACs.
5280 * Init=0x4900 */
5281 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5282 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5283 /* DMIC fix
5284 * This laptop has a stereo digital microphone.
5285 * The mics are only 1cm apart which makes the stereo
5286 * useless. However, either the mic or the ALC889
5287 * makes the signal become a difference/sum signal
5288 * instead of standard stereo, which is annoying.
5289 * So instead we flip this bit which makes the
5290 * codec replicate the sum signal to both channels,
5291 * turning it into a normal mono mic.
5292 */
5293 /* DMIC_CONTROL? Init value = 0x0001 */
5294 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5295 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5296 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5297 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5298 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005299 },
5300 .chained = true,
5301 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005302 },
Takashi Iwai56710872011-11-14 17:42:11 +01005303 [ALC885_FIXUP_MACPRO_GPIO] = {
5304 .type = ALC_FIXUP_FUNC,
5305 .v.func = alc885_fixup_macpro_gpio,
5306 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005307 [ALC889_FIXUP_DAC_ROUTE] = {
5308 .type = ALC_FIXUP_FUNC,
5309 .v.func = alc889_fixup_dac_route,
5310 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005311 [ALC889_FIXUP_MBP_VREF] = {
5312 .type = ALC_FIXUP_FUNC,
5313 .v.func = alc889_fixup_mbp_vref,
5314 .chained = true,
5315 .chain_id = ALC882_FIXUP_GPIO1,
5316 },
5317 [ALC889_FIXUP_IMAC91_VREF] = {
5318 .type = ALC_FIXUP_FUNC,
5319 .v.func = alc889_fixup_imac91_vref,
5320 .chained = true,
5321 .chain_id = ALC882_FIXUP_GPIO1,
5322 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005323};
5324
5325static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005326 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5327 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5328 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5329 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5330 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5331 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005332 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5333 ALC882_FIXUP_ACER_ASPIRE_4930G),
5334 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5335 ALC882_FIXUP_ACER_ASPIRE_4930G),
5336 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5337 ALC882_FIXUP_ACER_ASPIRE_8930G),
5338 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5339 ALC882_FIXUP_ACER_ASPIRE_8930G),
5340 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5341 ALC882_FIXUP_ACER_ASPIRE_4930G),
5342 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5343 ALC882_FIXUP_ACER_ASPIRE_4930G),
5344 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5345 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005346 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005347 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5348 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005349 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005350 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005351 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005352 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005353 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005354 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005355 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005356 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005357
5358 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005359 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5360 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5361 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005362 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5363 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5364 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005365 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5366 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005367 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005368 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5369 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5370 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5371 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005372 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005373 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5374 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5375 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005376 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005377 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5378 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5379 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005380
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005381 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005382 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005383 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005384 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005385 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005386 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5387 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005388 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005389 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005390 {}
5391};
5392
Takashi Iwai912093b2012-04-11 14:03:41 +02005393static const struct alc_model_fixup alc882_fixup_models[] = {
5394 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5395 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5396 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
5397 {}
5398};
5399
Takashi Iwai1d045db2011-07-07 18:23:21 +02005400/*
5401 * BIOS auto configuration
5402 */
5403/* almost identical with ALC880 parser... */
5404static int alc882_parse_auto_config(struct hda_codec *codec)
5405{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005406 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005407 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5408 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005409}
5410
Takashi Iwai1d045db2011-07-07 18:23:21 +02005411/*
5412 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005413static int patch_alc882(struct hda_codec *codec)
5414{
5415 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005416 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005417
Takashi Iwai3de95172012-05-07 18:03:15 +02005418 err = alc_alloc_spec(codec, 0x0b);
5419 if (err < 0)
5420 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005421
Takashi Iwai3de95172012-05-07 18:03:15 +02005422 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005423
5424 switch (codec->vendor_id) {
5425 case 0x10ec0882:
5426 case 0x10ec0885:
5427 break;
5428 default:
5429 /* ALC883 and variants */
5430 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5431 break;
5432 }
5433
Takashi Iwai912093b2012-04-11 14:03:41 +02005434 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5435 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005436 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005437
5438 alc_auto_parse_customize_define(codec);
5439
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005440 /* automatic parse from the BIOS config */
5441 err = alc882_parse_auto_config(codec);
5442 if (err < 0)
5443 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005444
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005445 if (!spec->no_analog && has_cdefine_beep(codec)) {
5446 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005447 if (err < 0)
5448 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005449 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005450 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451
Takashi Iwai1d045db2011-07-07 18:23:21 +02005452 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005453
Takashi Iwai589876e2012-02-20 15:47:55 +01005454 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5455
Takashi Iwai1d045db2011-07-07 18:23:21 +02005456 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005457
5458 error:
5459 alc_free(codec);
5460 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005461}
5462
5463
5464/*
5465 * ALC262 support
5466 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005467static int alc262_parse_auto_config(struct hda_codec *codec)
5468{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005469 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005470 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5471 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005472}
5473
5474/*
5475 * Pin config fixes
5476 */
5477enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005478 ALC262_FIXUP_FSC_H270,
5479 ALC262_FIXUP_HP_Z200,
5480 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005481 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005482 ALC262_FIXUP_BENQ,
5483 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005484};
5485
5486static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005487 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005488 .type = ALC_FIXUP_PINS,
5489 .v.pins = (const struct alc_pincfg[]) {
5490 { 0x14, 0x99130110 }, /* speaker */
5491 { 0x15, 0x0221142f }, /* front HP */
5492 { 0x1b, 0x0121141f }, /* rear HP */
5493 { }
5494 }
5495 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005496 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005497 .type = ALC_FIXUP_PINS,
5498 .v.pins = (const struct alc_pincfg[]) {
5499 { 0x16, 0x99130120 }, /* internal speaker */
5500 { }
5501 }
5502 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005503 [ALC262_FIXUP_TYAN] = {
5504 .type = ALC_FIXUP_PINS,
5505 .v.pins = (const struct alc_pincfg[]) {
5506 { 0x14, 0x1993e1f0 }, /* int AUX */
5507 { }
5508 }
5509 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005510 [ALC262_FIXUP_LENOVO_3000] = {
5511 .type = ALC_FIXUP_VERBS,
5512 .v.verbs = (const struct hda_verb[]) {
5513 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005514 {}
5515 },
5516 .chained = true,
5517 .chain_id = ALC262_FIXUP_BENQ,
5518 },
5519 [ALC262_FIXUP_BENQ] = {
5520 .type = ALC_FIXUP_VERBS,
5521 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005522 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5523 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5524 {}
5525 }
5526 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005527 [ALC262_FIXUP_BENQ_T31] = {
5528 .type = ALC_FIXUP_VERBS,
5529 .v.verbs = (const struct hda_verb[]) {
5530 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5531 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5532 {}
5533 }
5534 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005535};
5536
5537static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005538 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005539 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5540 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005541 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5542 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005543 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005544 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5545 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005546 {}
5547};
5548
5549
Takashi Iwai1d045db2011-07-07 18:23:21 +02005550/*
5551 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005552static int patch_alc262(struct hda_codec *codec)
5553{
5554 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005555 int err;
5556
Takashi Iwai3de95172012-05-07 18:03:15 +02005557 err = alc_alloc_spec(codec, 0x0b);
5558 if (err < 0)
5559 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005560
Takashi Iwai3de95172012-05-07 18:03:15 +02005561 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005562
5563#if 0
5564 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5565 * under-run
5566 */
5567 {
5568 int tmp;
5569 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5570 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5571 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5572 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5573 }
5574#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005575 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5576
Takashi Iwai42399f72011-11-07 17:18:44 +01005577 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5578 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005579
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005580 alc_auto_parse_customize_define(codec);
5581
Takashi Iwai42399f72011-11-07 17:18:44 +01005582 /* automatic parse from the BIOS config */
5583 err = alc262_parse_auto_config(codec);
5584 if (err < 0)
5585 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005586
Takashi Iwai1d045db2011-07-07 18:23:21 +02005587 if (!spec->no_analog && has_cdefine_beep(codec)) {
5588 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005589 if (err < 0)
5590 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005591 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005592 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005593
Takashi Iwai1d045db2011-07-07 18:23:21 +02005594 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005595 spec->shutup = alc_eapd_shutup;
5596
Takashi Iwai589876e2012-02-20 15:47:55 +01005597 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5598
Takashi Iwai1d045db2011-07-07 18:23:21 +02005599 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005600
5601 error:
5602 alc_free(codec);
5603 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604}
5605
5606/*
5607 * ALC268
5608 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005609/* bind Beep switches of both NID 0x0f and 0x10 */
5610static const struct hda_bind_ctls alc268_bind_beep_sw = {
5611 .ops = &snd_hda_bind_sw,
5612 .values = {
5613 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5614 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5615 0
5616 },
5617};
5618
5619static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5620 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5621 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5622 { }
5623};
5624
5625/* set PCBEEP vol = 0, mute connections */
5626static const struct hda_verb alc268_beep_init_verbs[] = {
5627 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5628 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5629 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5630 { }
5631};
5632
5633/*
5634 * BIOS auto configuration
5635 */
5636static int alc268_parse_auto_config(struct hda_codec *codec)
5637{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005638 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005639 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005640 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5641 if (err > 0) {
5642 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5643 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005644 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005646 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005647 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005648}
5649
Takashi Iwai1d045db2011-07-07 18:23:21 +02005650/*
5651 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652static int patch_alc268(struct hda_codec *codec)
5653{
5654 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005655 int i, has_beep, err;
5656
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005658 err = alc_alloc_spec(codec, 0);
5659 if (err < 0)
5660 return err;
5661
5662 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005663
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005664 /* automatic parse from the BIOS config */
5665 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005666 if (err < 0)
5667 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005668
Takashi Iwai1d045db2011-07-07 18:23:21 +02005669 has_beep = 0;
5670 for (i = 0; i < spec->num_mixers; i++) {
5671 if (spec->mixers[i] == alc268_beep_mixer) {
5672 has_beep = 1;
5673 break;
5674 }
5675 }
5676
5677 if (has_beep) {
5678 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005679 if (err < 0)
5680 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005681 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5682 /* override the amp caps for beep generator */
5683 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5684 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5685 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5686 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5687 (0 << AC_AMPCAP_MUTE_SHIFT));
5688 }
5689
Takashi Iwai1d045db2011-07-07 18:23:21 +02005690 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691 spec->shutup = alc_eapd_shutup;
5692
Takashi Iwai1d045db2011-07-07 18:23:21 +02005693 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005694
5695 error:
5696 alc_free(codec);
5697 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005698}
5699
5700/*
5701 * ALC269
5702 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005703static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5704 .substreams = 1,
5705 .channels_min = 2,
5706 .channels_max = 8,
5707 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5708 /* NID is set in alc_build_pcms */
5709 .ops = {
5710 .open = alc_playback_pcm_open,
5711 .prepare = alc_playback_pcm_prepare,
5712 .cleanup = alc_playback_pcm_cleanup
5713 },
5714};
5715
5716static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5717 .substreams = 1,
5718 .channels_min = 2,
5719 .channels_max = 2,
5720 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5721 /* NID is set in alc_build_pcms */
5722};
5723
Takashi Iwai1d045db2011-07-07 18:23:21 +02005724/* different alc269-variants */
5725enum {
5726 ALC269_TYPE_ALC269VA,
5727 ALC269_TYPE_ALC269VB,
5728 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005729 ALC269_TYPE_ALC269VD,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005730};
5731
5732/*
5733 * BIOS auto configuration
5734 */
5735static int alc269_parse_auto_config(struct hda_codec *codec)
5736{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005737 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005738 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5739 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5740 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005741 const hda_nid_t *ssids;
5742
5743 switch (spec->codec_variant) {
5744 case ALC269_TYPE_ALC269VA:
5745 case ALC269_TYPE_ALC269VC:
5746 ssids = alc269va_ssids;
5747 break;
5748 case ALC269_TYPE_ALC269VB:
5749 case ALC269_TYPE_ALC269VD:
5750 ssids = alc269_ssids;
5751 break;
5752 default:
5753 ssids = alc269_ssids;
5754 break;
5755 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005756
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005757 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005758}
5759
Takashi Iwai1d045db2011-07-07 18:23:21 +02005760static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5761{
5762 int val = alc_read_coef_idx(codec, 0x04);
5763 if (power_up)
5764 val |= 1 << 11;
5765 else
5766 val &= ~(1 << 11);
5767 alc_write_coef_idx(codec, 0x04, val);
5768}
5769
5770static void alc269_shutup(struct hda_codec *codec)
5771{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005772 struct alc_spec *spec = codec->spec;
5773
5774 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5775 return;
5776
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005777 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005778 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005779 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005780 alc269_toggle_power_output(codec, 0);
5781 msleep(150);
5782 }
5783}
5784
Takashi Iwai2a439522011-07-26 09:52:50 +02005785#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786static int alc269_resume(struct hda_codec *codec)
5787{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005788 struct alc_spec *spec = codec->spec;
5789
5790 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5791 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005792 alc269_toggle_power_output(codec, 0);
5793 msleep(150);
5794 }
5795
5796 codec->patch_ops.init(codec);
5797
Kailang Yangadcc70b2012-05-25 08:08:38 +02005798 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5799 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005800 alc269_toggle_power_output(codec, 1);
5801 msleep(200);
5802 }
5803
Kailang Yangadcc70b2012-05-25 08:08:38 +02005804 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5805 (alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005806 alc269_toggle_power_output(codec, 1);
5807
5808 snd_hda_codec_resume_amp(codec);
5809 snd_hda_codec_resume_cache(codec);
5810 hda_call_check_power_status(codec, 0x01);
5811 return 0;
5812}
Takashi Iwai2a439522011-07-26 09:52:50 +02005813#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005814
5815static void alc269_fixup_hweq(struct hda_codec *codec,
5816 const struct alc_fixup *fix, int action)
5817{
5818 int coef;
5819
5820 if (action != ALC_FIXUP_ACT_INIT)
5821 return;
5822 coef = alc_read_coef_idx(codec, 0x1e);
5823 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5824}
5825
5826static void alc271_fixup_dmic(struct hda_codec *codec,
5827 const struct alc_fixup *fix, int action)
5828{
5829 static const struct hda_verb verbs[] = {
5830 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5831 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5832 {}
5833 };
5834 unsigned int cfg;
5835
5836 if (strcmp(codec->chip_name, "ALC271X"))
5837 return;
5838 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5839 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5840 snd_hda_sequence_write(codec, verbs);
5841}
5842
Takashi Iwai017f2a12011-07-09 14:42:25 +02005843static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5844 const struct alc_fixup *fix, int action)
5845{
5846 struct alc_spec *spec = codec->spec;
5847
5848 if (action != ALC_FIXUP_ACT_PROBE)
5849 return;
5850
5851 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5852 * fix the sample rate of analog I/O to 44.1kHz
5853 */
5854 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5855 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5856}
5857
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005858static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5859 const struct alc_fixup *fix, int action)
5860{
5861 int coef;
5862
5863 if (action != ALC_FIXUP_ACT_INIT)
5864 return;
5865 /* The digital-mic unit sends PDM (differential signal) instead of
5866 * the standard PCM, thus you can't record a valid mono stream as is.
5867 * Below is a workaround specific to ALC269 to control the dmic
5868 * signal source as mono.
5869 */
5870 coef = alc_read_coef_idx(codec, 0x07);
5871 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5872}
5873
Takashi Iwai24519912011-08-16 15:08:49 +02005874static void alc269_quanta_automute(struct hda_codec *codec)
5875{
David Henningsson42cf0d02011-09-20 12:04:56 +02005876 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005877
5878 snd_hda_codec_write(codec, 0x20, 0,
5879 AC_VERB_SET_COEF_INDEX, 0x0c);
5880 snd_hda_codec_write(codec, 0x20, 0,
5881 AC_VERB_SET_PROC_COEF, 0x680);
5882
5883 snd_hda_codec_write(codec, 0x20, 0,
5884 AC_VERB_SET_COEF_INDEX, 0x0c);
5885 snd_hda_codec_write(codec, 0x20, 0,
5886 AC_VERB_SET_PROC_COEF, 0x480);
5887}
5888
5889static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5890 const struct alc_fixup *fix, int action)
5891{
5892 struct alc_spec *spec = codec->spec;
5893 if (action != ALC_FIXUP_ACT_PROBE)
5894 return;
5895 spec->automute_hook = alc269_quanta_automute;
5896}
5897
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005898/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5899static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5900{
5901 struct hda_codec *codec = private_data;
5902 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005903 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005904}
5905
5906static void alc269_fixup_mic2_mute(struct hda_codec *codec,
5907 const struct alc_fixup *fix, int action)
5908{
5909 struct alc_spec *spec = codec->spec;
5910 switch (action) {
5911 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005912 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01005913 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005914 /* fallthru */
5915 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005916 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005917 break;
5918 }
5919}
5920
David Henningsson693b6132012-06-22 19:12:10 +02005921static void alc269_fixup_inv_dmic(struct hda_codec *codec,
5922 const struct alc_fixup *fix, int action)
5923{
5924 if (action == ALC_FIXUP_ACT_PROBE)
5925 alc_add_inv_dmic_mixer(codec, 0x12);
5926}
5927
5928
Takashi Iwai1d045db2011-07-07 18:23:21 +02005929enum {
5930 ALC269_FIXUP_SONY_VAIO,
5931 ALC275_FIXUP_SONY_VAIO_GPIO2,
5932 ALC269_FIXUP_DELL_M101Z,
5933 ALC269_FIXUP_SKU_IGNORE,
5934 ALC269_FIXUP_ASUS_G73JW,
5935 ALC269_FIXUP_LENOVO_EAPD,
5936 ALC275_FIXUP_SONY_HWEQ,
5937 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005938 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005939 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005940 ALC269_FIXUP_QUANTA_MUTE,
5941 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005942 ALC269_FIXUP_AMIC,
5943 ALC269_FIXUP_DMIC,
5944 ALC269VB_FIXUP_AMIC,
5945 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005946 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02005947 ALC269_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005948};
5949
5950static const struct alc_fixup alc269_fixups[] = {
5951 [ALC269_FIXUP_SONY_VAIO] = {
5952 .type = ALC_FIXUP_VERBS,
5953 .v.verbs = (const struct hda_verb[]) {
5954 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5955 {}
5956 }
5957 },
5958 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5959 .type = ALC_FIXUP_VERBS,
5960 .v.verbs = (const struct hda_verb[]) {
5961 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5962 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5963 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5964 { }
5965 },
5966 .chained = true,
5967 .chain_id = ALC269_FIXUP_SONY_VAIO
5968 },
5969 [ALC269_FIXUP_DELL_M101Z] = {
5970 .type = ALC_FIXUP_VERBS,
5971 .v.verbs = (const struct hda_verb[]) {
5972 /* Enables internal speaker */
5973 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5974 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5975 {}
5976 }
5977 },
5978 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005979 .type = ALC_FIXUP_FUNC,
5980 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005981 },
5982 [ALC269_FIXUP_ASUS_G73JW] = {
5983 .type = ALC_FIXUP_PINS,
5984 .v.pins = (const struct alc_pincfg[]) {
5985 { 0x17, 0x99130111 }, /* subwoofer */
5986 { }
5987 }
5988 },
5989 [ALC269_FIXUP_LENOVO_EAPD] = {
5990 .type = ALC_FIXUP_VERBS,
5991 .v.verbs = (const struct hda_verb[]) {
5992 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5993 {}
5994 }
5995 },
5996 [ALC275_FIXUP_SONY_HWEQ] = {
5997 .type = ALC_FIXUP_FUNC,
5998 .v.func = alc269_fixup_hweq,
5999 .chained = true,
6000 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6001 },
6002 [ALC271_FIXUP_DMIC] = {
6003 .type = ALC_FIXUP_FUNC,
6004 .v.func = alc271_fixup_dmic,
6005 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006006 [ALC269_FIXUP_PCM_44K] = {
6007 .type = ALC_FIXUP_FUNC,
6008 .v.func = alc269_fixup_pcm_44k,
6009 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006010 [ALC269_FIXUP_STEREO_DMIC] = {
6011 .type = ALC_FIXUP_FUNC,
6012 .v.func = alc269_fixup_stereo_dmic,
6013 },
Takashi Iwai24519912011-08-16 15:08:49 +02006014 [ALC269_FIXUP_QUANTA_MUTE] = {
6015 .type = ALC_FIXUP_FUNC,
6016 .v.func = alc269_fixup_quanta_mute,
6017 },
6018 [ALC269_FIXUP_LIFEBOOK] = {
6019 .type = ALC_FIXUP_PINS,
6020 .v.pins = (const struct alc_pincfg[]) {
6021 { 0x1a, 0x2101103f }, /* dock line-out */
6022 { 0x1b, 0x23a11040 }, /* dock mic-in */
6023 { }
6024 },
6025 .chained = true,
6026 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6027 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006028 [ALC269_FIXUP_AMIC] = {
6029 .type = ALC_FIXUP_PINS,
6030 .v.pins = (const struct alc_pincfg[]) {
6031 { 0x14, 0x99130110 }, /* speaker */
6032 { 0x15, 0x0121401f }, /* HP out */
6033 { 0x18, 0x01a19c20 }, /* mic */
6034 { 0x19, 0x99a3092f }, /* int-mic */
6035 { }
6036 },
6037 },
6038 [ALC269_FIXUP_DMIC] = {
6039 .type = ALC_FIXUP_PINS,
6040 .v.pins = (const struct alc_pincfg[]) {
6041 { 0x12, 0x99a3092f }, /* int-mic */
6042 { 0x14, 0x99130110 }, /* speaker */
6043 { 0x15, 0x0121401f }, /* HP out */
6044 { 0x18, 0x01a19c20 }, /* mic */
6045 { }
6046 },
6047 },
6048 [ALC269VB_FIXUP_AMIC] = {
6049 .type = ALC_FIXUP_PINS,
6050 .v.pins = (const struct alc_pincfg[]) {
6051 { 0x14, 0x99130110 }, /* speaker */
6052 { 0x18, 0x01a19c20 }, /* mic */
6053 { 0x19, 0x99a3092f }, /* int-mic */
6054 { 0x21, 0x0121401f }, /* HP out */
6055 { }
6056 },
6057 },
David Henningsson2267ea92012-01-03 08:45:56 +01006058 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006059 .type = ALC_FIXUP_PINS,
6060 .v.pins = (const struct alc_pincfg[]) {
6061 { 0x12, 0x99a3092f }, /* int-mic */
6062 { 0x14, 0x99130110 }, /* speaker */
6063 { 0x18, 0x01a19c20 }, /* mic */
6064 { 0x21, 0x0121401f }, /* HP out */
6065 { }
6066 },
6067 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006068 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6069 .type = ALC_FIXUP_FUNC,
6070 .v.func = alc269_fixup_mic2_mute,
6071 },
David Henningsson693b6132012-06-22 19:12:10 +02006072 [ALC269_FIXUP_INV_DMIC] = {
6073 .type = ALC_FIXUP_FUNC,
6074 .v.func = alc269_fixup_inv_dmic,
6075 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006076};
6077
6078static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006079 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6080 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006081 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006082 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006083 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006084 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006085 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6086 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6087 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6088 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6089 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006090 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6091 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6092 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6093 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6094 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6095 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006096 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006097 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6098 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6099 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6100 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6101 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006102 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006103 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006104 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006105
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006106#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006107 /* Below is a quirk table taken from the old code.
6108 * Basically the device should work as is without the fixup table.
6109 * If BIOS doesn't give a proper info, enable the corresponding
6110 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006111 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006112 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6113 ALC269_FIXUP_AMIC),
6114 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006115 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6116 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6117 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6118 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6119 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6120 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6121 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6122 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6123 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6124 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6125 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6126 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6127 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6128 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6129 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6130 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6131 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6132 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6133 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6134 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6135 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6136 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6137 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6138 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6139 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6140 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6141 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6142 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6143 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6144 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6145 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6146 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6147 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6148 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6149 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6150 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6151 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6152 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6153#endif
6154 {}
6155};
6156
6157static const struct alc_model_fixup alc269_fixup_models[] = {
6158 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6159 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006160 {}
6161};
6162
6163
Takashi Iwai546bb672012-03-07 08:37:19 +01006164static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006165{
Kailang Yang526af6e2012-03-07 08:25:20 +01006166 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006167 int val;
6168
Kailang Yang526af6e2012-03-07 08:25:20 +01006169 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006170 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006171
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006172 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006173 alc_write_coef_idx(codec, 0xf, 0x960b);
6174 alc_write_coef_idx(codec, 0xe, 0x8817);
6175 }
6176
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006177 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006178 alc_write_coef_idx(codec, 0xf, 0x960b);
6179 alc_write_coef_idx(codec, 0xe, 0x8814);
6180 }
6181
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006182 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006183 val = alc_read_coef_idx(codec, 0x04);
6184 /* Power up output pin */
6185 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6186 }
6187
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006188 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006189 val = alc_read_coef_idx(codec, 0xd);
6190 if ((val & 0x0c00) >> 10 != 0x1) {
6191 /* Capless ramp up clock control */
6192 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6193 }
6194 val = alc_read_coef_idx(codec, 0x17);
6195 if ((val & 0x01c0) >> 6 != 0x4) {
6196 /* Class D power on reset */
6197 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6198 }
6199 }
6200
6201 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6202 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6203
6204 val = alc_read_coef_idx(codec, 0x4); /* HP */
6205 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006206}
6207
6208/*
6209 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006210static int patch_alc269(struct hda_codec *codec)
6211{
6212 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006213 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006214
Takashi Iwai3de95172012-05-07 18:03:15 +02006215 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006216 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006217 return err;
6218
6219 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006220
Takashi Iwai1d045db2011-07-07 18:23:21 +02006221 if (codec->vendor_id == 0x10ec0269) {
6222 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006223 switch (alc_get_coef0(codec) & 0x00f0) {
6224 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006225 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006226 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006227 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006228 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006229 break;
6230 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006231 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6232 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006233 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006234 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006235 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006236 case 0x0030:
6237 spec->codec_variant = ALC269_TYPE_ALC269VD;
6238 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006239 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006240 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006241 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006242 if (err < 0)
6243 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006244 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006245 alc269_fill_coef(codec);
6246 }
6247
Takashi Iwaia4297b52011-08-23 18:40:12 +02006248 alc_pick_fixup(codec, alc269_fixup_models,
6249 alc269_fixup_tbl, alc269_fixups);
6250 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006251
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006252 alc_auto_parse_customize_define(codec);
6253
Takashi Iwaia4297b52011-08-23 18:40:12 +02006254 /* automatic parse from the BIOS config */
6255 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006256 if (err < 0)
6257 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006258
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006259 if (!spec->no_analog && has_cdefine_beep(codec)) {
6260 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006261 if (err < 0)
6262 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006263 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006264 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006265
Takashi Iwai1d045db2011-07-07 18:23:21 +02006266 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006267#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006268 codec->patch_ops.resume = alc269_resume;
6269#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006270 spec->shutup = alc269_shutup;
6271
Takashi Iwai589876e2012-02-20 15:47:55 +01006272 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6273
Takashi Iwai1d045db2011-07-07 18:23:21 +02006274 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006275
6276 error:
6277 alc_free(codec);
6278 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006279}
6280
6281/*
6282 * ALC861
6283 */
6284
Takashi Iwai1d045db2011-07-07 18:23:21 +02006285static int alc861_parse_auto_config(struct hda_codec *codec)
6286{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006287 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006288 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6289 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006290}
6291
Takashi Iwai1d045db2011-07-07 18:23:21 +02006292/* Pin config fixes */
6293enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006294 ALC861_FIXUP_FSC_AMILO_PI1505,
6295 ALC861_FIXUP_AMP_VREF_0F,
6296 ALC861_FIXUP_NO_JACK_DETECT,
6297 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006298};
6299
Takashi Iwai31150f22012-01-30 10:54:08 +01006300/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6301static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6302 const struct alc_fixup *fix, int action)
6303{
6304 struct alc_spec *spec = codec->spec;
6305 unsigned int val;
6306
6307 if (action != ALC_FIXUP_ACT_INIT)
6308 return;
6309 val = snd_hda_codec_read(codec, 0x0f, 0,
6310 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6311 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6312 val |= AC_PINCTL_IN_EN;
6313 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006314 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006315 spec->keep_vref_in_automute = 1;
6316}
6317
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006318/* suppress the jack-detection */
6319static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6320 const struct alc_fixup *fix, int action)
6321{
6322 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6323 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006324}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006325
Takashi Iwai1d045db2011-07-07 18:23:21 +02006326static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006327 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006328 .type = ALC_FIXUP_PINS,
6329 .v.pins = (const struct alc_pincfg[]) {
6330 { 0x0b, 0x0221101f }, /* HP */
6331 { 0x0f, 0x90170310 }, /* speaker */
6332 { }
6333 }
6334 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006335 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006336 .type = ALC_FIXUP_FUNC,
6337 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006338 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006339 [ALC861_FIXUP_NO_JACK_DETECT] = {
6340 .type = ALC_FIXUP_FUNC,
6341 .v.func = alc_fixup_no_jack_detect,
6342 },
6343 [ALC861_FIXUP_ASUS_A6RP] = {
6344 .type = ALC_FIXUP_FUNC,
6345 .v.func = alc861_fixup_asus_amp_vref_0f,
6346 .chained = true,
6347 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6348 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006349};
6350
6351static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006352 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6353 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6354 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6355 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6356 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6357 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006358 {}
6359};
6360
6361/*
6362 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006363static int patch_alc861(struct hda_codec *codec)
6364{
6365 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006366 int err;
6367
Takashi Iwai3de95172012-05-07 18:03:15 +02006368 err = alc_alloc_spec(codec, 0x15);
6369 if (err < 0)
6370 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006371
Takashi Iwai3de95172012-05-07 18:03:15 +02006372 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006373
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006374 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6375 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006376
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006377 /* automatic parse from the BIOS config */
6378 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006379 if (err < 0)
6380 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006381
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006382 if (!spec->no_analog) {
6383 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006384 if (err < 0)
6385 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006386 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6387 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006388
Takashi Iwai1d045db2011-07-07 18:23:21 +02006389 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006390#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006391 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006392#endif
6393
Takashi Iwai589876e2012-02-20 15:47:55 +01006394 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6395
Takashi Iwai1d045db2011-07-07 18:23:21 +02006396 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006397
6398 error:
6399 alc_free(codec);
6400 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006401}
6402
6403/*
6404 * ALC861-VD support
6405 *
6406 * Based on ALC882
6407 *
6408 * In addition, an independent DAC
6409 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006410static int alc861vd_parse_auto_config(struct hda_codec *codec)
6411{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006412 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006413 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6414 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006415}
6416
Takashi Iwai1d045db2011-07-07 18:23:21 +02006417enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006418 ALC660VD_FIX_ASUS_GPIO1,
6419 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006420};
6421
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006422/* exclude VREF80 */
6423static void alc861vd_fixup_dallas(struct hda_codec *codec,
6424 const struct alc_fixup *fix, int action)
6425{
6426 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6427 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6428 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6429 }
6430}
6431
Takashi Iwai1d045db2011-07-07 18:23:21 +02006432static const struct alc_fixup alc861vd_fixups[] = {
6433 [ALC660VD_FIX_ASUS_GPIO1] = {
6434 .type = ALC_FIXUP_VERBS,
6435 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006436 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006437 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6438 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6439 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6440 { }
6441 }
6442 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006443 [ALC861VD_FIX_DALLAS] = {
6444 .type = ALC_FIXUP_FUNC,
6445 .v.func = alc861vd_fixup_dallas,
6446 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006447};
6448
6449static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006450 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006451 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006452 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006453 {}
6454};
6455
6456static const struct hda_verb alc660vd_eapd_verbs[] = {
6457 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6458 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6459 { }
6460};
6461
6462/*
6463 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006464static int patch_alc861vd(struct hda_codec *codec)
6465{
6466 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006467 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006468
Takashi Iwai3de95172012-05-07 18:03:15 +02006469 err = alc_alloc_spec(codec, 0x0b);
6470 if (err < 0)
6471 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006472
Takashi Iwai3de95172012-05-07 18:03:15 +02006473 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006474
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006475 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6476 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006477
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006478 /* automatic parse from the BIOS config */
6479 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006480 if (err < 0)
6481 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006482
Takashi Iwai1d045db2011-07-07 18:23:21 +02006483 if (codec->vendor_id == 0x10ec0660) {
6484 /* always turn on EAPD */
Takashi Iwai23d30f22012-05-07 17:17:32 +02006485 snd_hda_gen_add_verbs(&spec->gen, alc660vd_eapd_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006486 }
6487
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006488 if (!spec->no_analog) {
6489 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006490 if (err < 0)
6491 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006492 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6493 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006494
Takashi Iwai1d045db2011-07-07 18:23:21 +02006495 codec->patch_ops = alc_patch_ops;
6496
Takashi Iwai1d045db2011-07-07 18:23:21 +02006497 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006498
Takashi Iwai589876e2012-02-20 15:47:55 +01006499 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6500
Takashi Iwai1d045db2011-07-07 18:23:21 +02006501 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006502
6503 error:
6504 alc_free(codec);
6505 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006506}
6507
6508/*
6509 * ALC662 support
6510 *
6511 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6512 * configuration. Each pin widget can choose any input DACs and a mixer.
6513 * Each ADC is connected from a mixer of all inputs. This makes possible
6514 * 6-channel independent captures.
6515 *
6516 * In addition, an independent DAC for the multi-playback (not used in this
6517 * driver yet).
6518 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006519
6520/*
6521 * BIOS auto configuration
6522 */
6523
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006524static int alc662_parse_auto_config(struct hda_codec *codec)
6525{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006526 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006527 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6528 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6529 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006530
Kailang Yang6227cdc2010-02-25 08:36:52 +01006531 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6532 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006533 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006534 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006535 ssids = alc662_ssids;
6536 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006537}
6538
Todd Broch6be79482010-12-07 16:51:05 -08006539static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006540 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006541{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006542 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006543 return;
Todd Broch6be79482010-12-07 16:51:05 -08006544 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6545 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6546 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6547 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6548 (0 << AC_AMPCAP_MUTE_SHIFT)))
6549 printk(KERN_WARNING
6550 "hda_codec: failed to override amp caps for NID 0x2\n");
6551}
6552
David Henningsson693b6132012-06-22 19:12:10 +02006553#define alc662_fixup_inv_dmic alc269_fixup_inv_dmic
Takashi Iwai125821a2012-06-22 14:30:29 +02006554
David Henningsson6cb3b702010-09-09 08:51:44 +02006555enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006556 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006557 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006558 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006559 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006560 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006561 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006562 ALC662_FIXUP_ASUS_MODE1,
6563 ALC662_FIXUP_ASUS_MODE2,
6564 ALC662_FIXUP_ASUS_MODE3,
6565 ALC662_FIXUP_ASUS_MODE4,
6566 ALC662_FIXUP_ASUS_MODE5,
6567 ALC662_FIXUP_ASUS_MODE6,
6568 ALC662_FIXUP_ASUS_MODE7,
6569 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006570 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006571 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006572 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006573};
6574
6575static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006576 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006577 .type = ALC_FIXUP_PINS,
6578 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006579 { 0x15, 0x99130112 }, /* subwoofer */
6580 { }
6581 }
6582 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006583 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006584 .type = ALC_FIXUP_PINS,
6585 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006586 { 0x17, 0x99130112 }, /* subwoofer */
6587 { }
6588 }
6589 },
Todd Broch6be79482010-12-07 16:51:05 -08006590 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006591 .type = ALC_FIXUP_FUNC,
6592 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006593 },
6594 [ALC662_FIXUP_CZC_P10T] = {
6595 .type = ALC_FIXUP_VERBS,
6596 .v.verbs = (const struct hda_verb[]) {
6597 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6598 {}
6599 }
6600 },
David Henningsson94024cd2011-04-29 14:10:55 +02006601 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006602 .type = ALC_FIXUP_FUNC,
6603 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006604 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006605 [ALC662_FIXUP_HP_RP5800] = {
6606 .type = ALC_FIXUP_PINS,
6607 .v.pins = (const struct alc_pincfg[]) {
6608 { 0x14, 0x0221201f }, /* HP out */
6609 { }
6610 },
6611 .chained = true,
6612 .chain_id = ALC662_FIXUP_SKU_IGNORE
6613 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006614 [ALC662_FIXUP_ASUS_MODE1] = {
6615 .type = ALC_FIXUP_PINS,
6616 .v.pins = (const struct alc_pincfg[]) {
6617 { 0x14, 0x99130110 }, /* speaker */
6618 { 0x18, 0x01a19c20 }, /* mic */
6619 { 0x19, 0x99a3092f }, /* int-mic */
6620 { 0x21, 0x0121401f }, /* HP out */
6621 { }
6622 },
6623 .chained = true,
6624 .chain_id = ALC662_FIXUP_SKU_IGNORE
6625 },
6626 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006627 .type = ALC_FIXUP_PINS,
6628 .v.pins = (const struct alc_pincfg[]) {
6629 { 0x14, 0x99130110 }, /* speaker */
6630 { 0x18, 0x01a19820 }, /* mic */
6631 { 0x19, 0x99a3092f }, /* int-mic */
6632 { 0x1b, 0x0121401f }, /* HP out */
6633 { }
6634 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006635 .chained = true,
6636 .chain_id = ALC662_FIXUP_SKU_IGNORE
6637 },
6638 [ALC662_FIXUP_ASUS_MODE3] = {
6639 .type = ALC_FIXUP_PINS,
6640 .v.pins = (const struct alc_pincfg[]) {
6641 { 0x14, 0x99130110 }, /* speaker */
6642 { 0x15, 0x0121441f }, /* HP */
6643 { 0x18, 0x01a19840 }, /* mic */
6644 { 0x19, 0x99a3094f }, /* int-mic */
6645 { 0x21, 0x01211420 }, /* HP2 */
6646 { }
6647 },
6648 .chained = true,
6649 .chain_id = ALC662_FIXUP_SKU_IGNORE
6650 },
6651 [ALC662_FIXUP_ASUS_MODE4] = {
6652 .type = ALC_FIXUP_PINS,
6653 .v.pins = (const struct alc_pincfg[]) {
6654 { 0x14, 0x99130110 }, /* speaker */
6655 { 0x16, 0x99130111 }, /* speaker */
6656 { 0x18, 0x01a19840 }, /* mic */
6657 { 0x19, 0x99a3094f }, /* int-mic */
6658 { 0x21, 0x0121441f }, /* HP */
6659 { }
6660 },
6661 .chained = true,
6662 .chain_id = ALC662_FIXUP_SKU_IGNORE
6663 },
6664 [ALC662_FIXUP_ASUS_MODE5] = {
6665 .type = ALC_FIXUP_PINS,
6666 .v.pins = (const struct alc_pincfg[]) {
6667 { 0x14, 0x99130110 }, /* speaker */
6668 { 0x15, 0x0121441f }, /* HP */
6669 { 0x16, 0x99130111 }, /* speaker */
6670 { 0x18, 0x01a19840 }, /* mic */
6671 { 0x19, 0x99a3094f }, /* int-mic */
6672 { }
6673 },
6674 .chained = true,
6675 .chain_id = ALC662_FIXUP_SKU_IGNORE
6676 },
6677 [ALC662_FIXUP_ASUS_MODE6] = {
6678 .type = ALC_FIXUP_PINS,
6679 .v.pins = (const struct alc_pincfg[]) {
6680 { 0x14, 0x99130110 }, /* speaker */
6681 { 0x15, 0x01211420 }, /* HP2 */
6682 { 0x18, 0x01a19840 }, /* mic */
6683 { 0x19, 0x99a3094f }, /* int-mic */
6684 { 0x1b, 0x0121441f }, /* HP */
6685 { }
6686 },
6687 .chained = true,
6688 .chain_id = ALC662_FIXUP_SKU_IGNORE
6689 },
6690 [ALC662_FIXUP_ASUS_MODE7] = {
6691 .type = ALC_FIXUP_PINS,
6692 .v.pins = (const struct alc_pincfg[]) {
6693 { 0x14, 0x99130110 }, /* speaker */
6694 { 0x17, 0x99130111 }, /* speaker */
6695 { 0x18, 0x01a19840 }, /* mic */
6696 { 0x19, 0x99a3094f }, /* int-mic */
6697 { 0x1b, 0x01214020 }, /* HP */
6698 { 0x21, 0x0121401f }, /* HP */
6699 { }
6700 },
6701 .chained = true,
6702 .chain_id = ALC662_FIXUP_SKU_IGNORE
6703 },
6704 [ALC662_FIXUP_ASUS_MODE8] = {
6705 .type = ALC_FIXUP_PINS,
6706 .v.pins = (const struct alc_pincfg[]) {
6707 { 0x14, 0x99130110 }, /* speaker */
6708 { 0x12, 0x99a30970 }, /* int-mic */
6709 { 0x15, 0x01214020 }, /* HP */
6710 { 0x17, 0x99130111 }, /* speaker */
6711 { 0x18, 0x01a19840 }, /* mic */
6712 { 0x21, 0x0121401f }, /* HP */
6713 { }
6714 },
6715 .chained = true,
6716 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006717 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006718 [ALC662_FIXUP_NO_JACK_DETECT] = {
6719 .type = ALC_FIXUP_FUNC,
6720 .v.func = alc_fixup_no_jack_detect,
6721 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006722 [ALC662_FIXUP_ZOTAC_Z68] = {
6723 .type = ALC_FIXUP_PINS,
6724 .v.pins = (const struct alc_pincfg[]) {
6725 { 0x1b, 0x02214020 }, /* Front HP */
6726 { }
6727 }
6728 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006729 [ALC662_FIXUP_INV_DMIC] = {
6730 .type = ALC_FIXUP_FUNC,
6731 .v.func = alc662_fixup_inv_dmic,
6732 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006733};
6734
Takashi Iwaia9111322011-05-02 11:30:18 +02006735static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006736 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006737 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006738 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006739 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006740 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006741 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006742 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006743 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006744 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006745 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006746 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006747 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006748 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006749
6750#if 0
6751 /* Below is a quirk table taken from the old code.
6752 * Basically the device should work as is without the fixup table.
6753 * If BIOS doesn't give a proper info, enable the corresponding
6754 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006755 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006756 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6757 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6758 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6759 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6760 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6761 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6762 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6763 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6764 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6765 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6766 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6767 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6768 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6769 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6770 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6771 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6772 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6773 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6774 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6775 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6776 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6777 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6778 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6779 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6780 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6781 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6782 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6783 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6784 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6785 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6786 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6787 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6788 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6789 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6790 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6791 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6792 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6793 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6794 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6795 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6796 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6797 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6798 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6799 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6800 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6801 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6802 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6803 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6804 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6805 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6806#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006807 {}
6808};
6809
Todd Broch6be79482010-12-07 16:51:05 -08006810static const struct alc_model_fixup alc662_fixup_models[] = {
6811 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006812 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6813 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6814 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6815 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6816 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6817 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6818 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6819 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006820 {}
6821};
David Henningsson6cb3b702010-09-09 08:51:44 +02006822
6823
Takashi Iwai1d045db2011-07-07 18:23:21 +02006824/*
6825 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006826static int patch_alc662(struct hda_codec *codec)
6827{
6828 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006829 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006830
Takashi Iwai3de95172012-05-07 18:03:15 +02006831 err = alc_alloc_spec(codec, 0x0b);
6832 if (err < 0)
6833 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006834
Takashi Iwai3de95172012-05-07 18:03:15 +02006835 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006836
Takashi Iwai53c334a2011-08-23 18:27:14 +02006837 /* handle multiple HPs as is */
6838 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6839
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006840 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6841
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006842 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006843 codec->bus->pci->subsystem_vendor == 0x1025 &&
6844 spec->cdefine.platform_type == 1) {
6845 if (alc_codec_rename(codec, "ALC272X") < 0)
6846 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006847 }
Kailang Yang274693f2009-12-03 10:07:50 +01006848
Takashi Iwaib9c51062011-08-24 18:08:07 +02006849 alc_pick_fixup(codec, alc662_fixup_models,
6850 alc662_fixup_tbl, alc662_fixups);
6851 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006852
6853 alc_auto_parse_customize_define(codec);
6854
Takashi Iwaib9c51062011-08-24 18:08:07 +02006855 /* automatic parse from the BIOS config */
6856 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006857 if (err < 0)
6858 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006859
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006860 if (!spec->no_analog && has_cdefine_beep(codec)) {
6861 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006862 if (err < 0)
6863 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006864 switch (codec->vendor_id) {
6865 case 0x10ec0662:
6866 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6867 break;
6868 case 0x10ec0272:
6869 case 0x10ec0663:
6870 case 0x10ec0665:
6871 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6872 break;
6873 case 0x10ec0273:
6874 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6875 break;
6876 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006877 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006878
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006879 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02006880 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006881
Takashi Iwai589876e2012-02-20 15:47:55 +01006882 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6883
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006884 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006885
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006886 error:
6887 alc_free(codec);
6888 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006889}
6890
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006891/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006892 * ALC680 support
6893 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006894
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006895static int alc680_parse_auto_config(struct hda_codec *codec)
6896{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006897 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006898}
6899
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006900/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006901 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006902static int patch_alc680(struct hda_codec *codec)
6903{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006904 int err;
6905
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006906 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006907 err = alc_alloc_spec(codec, 0);
6908 if (err < 0)
6909 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006910
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006911 /* automatic parse from the BIOS config */
6912 err = alc680_parse_auto_config(codec);
6913 if (err < 0) {
6914 alc_free(codec);
6915 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006916 }
6917
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006918 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006919
6920 return 0;
6921}
6922
6923/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924 * patch entries
6925 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006926static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006927 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006928 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006929 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006930 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006931 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006932 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006933 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006934 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006935 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006936 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006937 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006938 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006939 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6940 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6941 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006942 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006943 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006944 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6945 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006946 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6947 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006948 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006949 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006950 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006951 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006952 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006953 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006954 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006955 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006956 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006957 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006958 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006959 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006960 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006961 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006962 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006963 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006964 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006965 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006966 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006967 {} /* terminator */
6968};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006969
6970MODULE_ALIAS("snd-hda-codec-id:10ec*");
6971
6972MODULE_LICENSE("GPL");
6973MODULE_DESCRIPTION("Realtek HD-audio codec");
6974
6975static struct hda_codec_preset_list realtek_list = {
6976 .preset = snd_hda_preset_realtek,
6977 .owner = THIS_MODULE,
6978};
6979
6980static int __init patch_realtek_init(void)
6981{
6982 return snd_hda_add_codec_preset(&realtek_list);
6983}
6984
6985static void __exit patch_realtek_exit(void)
6986{
6987 snd_hda_delete_codec_preset(&realtek_list);
6988}
6989
6990module_init(patch_realtek_init)
6991module_exit(patch_realtek_exit)