blob: 9a38107cf0f58a1d5baa31c66b1db16524b15f68 [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 Iwaic14c95f2012-02-16 16:38:07 +010076#define MAX_VOL_NIDS 0x40
77
Takashi Iwai23d30f22012-05-07 17:17:32 +020078/* make compatible with old code */
79#define alc_apply_pincfgs snd_hda_apply_pincfgs
80#define alc_apply_fixup snd_hda_apply_fixup
81#define alc_pick_fixup snd_hda_pick_fixup
82#define alc_fixup hda_fixup
83#define alc_pincfg hda_pintbl
84#define alc_model_fixup hda_model_fixup
85
86#define ALC_FIXUP_PINS HDA_FIXUP_PINS
87#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
88#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
89
90#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
91#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
92#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
93#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
94
95
Takashi Iwai30dcd3b2012-12-06 15:45:38 +010096#define MAX_NID_PATH_DEPTH 5
97
Takashi Iwai36f0fd52012-12-12 17:25:00 +010098/* Widget connection path
99 *
100 * For output, stored in the order of DAC -> ... -> pin,
101 * for input, pin -> ... -> ADC.
102 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100103 * idx[i] contains the source index number to select on of the widget path[i];
104 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100105 * multi[] indicates whether it's a selector widget with multi-connectors
106 * (i.e. the connection selection is mandatory)
107 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
108 */
109struct nid_path {
110 int depth;
111 hda_nid_t path[MAX_NID_PATH_DEPTH];
112 unsigned char idx[MAX_NID_PATH_DEPTH];
113 unsigned char multi[MAX_NID_PATH_DEPTH];
114 unsigned int ctls[2]; /* 0 = volume, 1 = mute */
Takashi Iwai130e5f02012-12-14 16:09:29 +0100115 bool active;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100116};
117
Takashi Iwaiba8111272012-12-06 18:06:23 +0100118enum { NID_PATH_VOL_CTL = 0, NID_PATH_MUTE_CTL = 1 };
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200121 struct hda_gen_spec gen;
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200124 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +0200126 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100127 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200129 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200130 const struct hda_pcm_stream *stream_analog_playback;
131 const struct hda_pcm_stream *stream_analog_capture;
132 const struct hda_pcm_stream *stream_analog_alt_playback;
133 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200135 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200136 const struct hda_pcm_stream *stream_digital_playback;
137 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200140 struct hda_multi_out multiout; /* playback set-up
141 * max_channels, dacs must be set
142 * dig_out_nid and hp_nid are optional
143 */
Takashi Iwai63300792008-01-24 15:31:36 +0100144 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100145 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100146 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* capture */
149 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200150 const hda_nid_t *adc_nids;
151 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200152 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200153 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Takashi Iwai840b64c2010-07-13 22:49:01 +0200155 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200156 hda_nid_t cur_adc;
157 unsigned int cur_adc_stream_tag;
158 unsigned int cur_adc_format;
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200161 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 const struct hda_input_mux *input_mux;
163 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200164 hda_nid_t ext_mic_pin;
165 hda_nid_t dock_mic_pin;
166 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100169 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200171 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100172 int const_channel_count; /* min. channel count (for speakers) */
173 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100176 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200177
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200178 /* dynamic controls, init_verbs and input_mux */
179 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100180 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200181 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200182 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200183 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200184 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
185 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200186 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
187 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
188 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200189 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100190
Takashi Iwai463419d2012-12-05 14:17:37 +0100191 /* DAC list */
192 int num_all_dacs;
193 hda_nid_t all_dacs[16];
194
Takashi Iwaic9967f12012-12-14 16:39:22 +0100195 /* path list */
196 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100197
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100198 /* hooks */
199 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200200#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500201 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100202#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200203 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200204 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100205
Takashi Iwai834be882006-03-01 14:16:17 +0100206 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200207 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200208 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200209 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200210 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200211 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200212 unsigned int automute_speaker:1; /* automute speaker outputs */
213 unsigned int automute_lo:1; /* automute LO outputs */
214 unsigned int detect_hp:1; /* Headphone detection enabled */
215 unsigned int detect_lo:1; /* Line-out detection enabled */
216 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
217 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100218 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200219
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100220 /* other flags */
221 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200222 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100223 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200224 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200225 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100226 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200227 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
228 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200229 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200230
231 /* auto-mute control */
232 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200233 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200234
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200235 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200236 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100237
Takashi Iwai2134ea42008-01-10 16:53:55 +0100238 /* for virtual master */
239 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100240 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200241#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200242 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100243 int num_loopbacks;
244 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200245#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200246
247 /* for PLL fix */
248 hda_nid_t pll_nid;
249 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200250 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100251
Takashi Iwaice764ab2011-04-27 16:35:23 +0200252 /* multi-io */
253 int multi_ios;
254 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200255
256 /* bind volumes */
257 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100258};
259
Takashi Iwai44c02402011-07-08 15:14:19 +0200260static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
261 int dir, unsigned int bits)
262{
263 if (!nid)
264 return false;
265 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
266 if (query_amp_caps(codec, nid, dir) & bits)
267 return true;
268 return false;
269}
270
271#define nid_has_mute(codec, nid, dir) \
272 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
273#define nid_has_volume(codec, nid, dir) \
274 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276/*
277 * input MUX handling
278 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200279static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
282 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
283 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200284 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
285 if (mux_idx >= spec->num_mux_defs)
286 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100287 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
288 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200289 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200292static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
296 struct alc_spec *spec = codec->spec;
297 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
298
299 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
300 return 0;
301}
302
Takashi Iwai21268962011-07-07 15:01:13 +0200303static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Takashi Iwai21268962011-07-07 15:01:13 +0200305 struct alc_spec *spec = codec->spec;
306 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
307
308 if (spec->cur_adc && spec->cur_adc != new_adc) {
309 /* stream is running, let's swap the current ADC */
310 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
311 spec->cur_adc = new_adc;
312 snd_hda_codec_setup_stream(codec, new_adc,
313 spec->cur_adc_stream_tag, 0,
314 spec->cur_adc_format);
315 return true;
316 }
317 return false;
318}
319
Takashi Iwai61071592011-11-23 07:52:15 +0100320static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
321{
322 return spec->capsrc_nids ?
323 spec->capsrc_nids[idx] : spec->adc_nids[idx];
324}
325
Takashi Iwai24de1832011-11-07 17:13:39 +0100326static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200327static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100328
David Henningsson00227f12012-06-27 18:45:44 +0200329/* for shared I/O, change the pin-control accordingly */
330static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
331{
332 struct alc_spec *spec = codec->spec;
333 unsigned int val;
334 hda_nid_t pin = spec->autocfg.inputs[1].pin;
335 /* NOTE: this assumes that there are only two inputs, the
336 * first is the real internal mic and the second is HP/mic jack.
337 */
338
339 val = snd_hda_get_default_vref(codec, pin);
340
341 /* This pin does not have vref caps - let's enable vref on pin 0x18
342 instead, as suggested by Realtek */
343 if (val == AC_PINCTL_VREF_HIZ) {
344 const hda_nid_t vref_pin = 0x18;
345 /* Sanity check pin 0x18 */
346 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
347 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
348 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
349 if (vref_val != AC_PINCTL_VREF_HIZ)
350 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
351 }
352 }
353
354 val = set_as_mic ? val | PIN_IN : PIN_HP;
355 snd_hda_set_pin_ctl(codec, pin, val);
356
357 spec->automute_speaker = !set_as_mic;
358 call_update_outputs(codec);
359}
Takashi Iwai21268962011-07-07 15:01:13 +0200360
361/* select the given imux item; either unmute exclusively or select the route */
362static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
363 unsigned int idx, bool force)
364{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100366 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100367 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100368 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200369 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Takashi Iwai5803a322012-02-21 11:59:45 +0100371 if (!spec->input_mux)
372 return 0;
373
Takashi Iwaicd896c32008-11-18 12:36:33 +0100374 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
375 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100376 if (!imux->num_items && mux_idx > 0)
377 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100378 if (!imux->num_items)
379 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100380
Takashi Iwai21268962011-07-07 15:01:13 +0200381 if (idx >= imux->num_items)
382 idx = imux->num_items - 1;
383 if (spec->cur_mux[adc_idx] == idx && !force)
384 return 0;
385 spec->cur_mux[adc_idx] = idx;
386
David Henningsson00227f12012-06-27 18:45:44 +0200387 if (spec->shared_mic_hp)
388 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100389
Takashi Iwai21268962011-07-07 15:01:13 +0200390 if (spec->dyn_adc_switch) {
391 alc_dyn_adc_pcm_resetup(codec, idx);
392 adc_idx = spec->dyn_adc_idx[idx];
393 }
394
Takashi Iwai61071592011-11-23 07:52:15 +0100395 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200396
397 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200398 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100399 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200400 return 1;
401
Takashi Iwaia22d5432009-07-27 12:54:26 +0200402 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200403 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100404 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100405 int active = imux->items[idx].index;
406 for (i = 0; i < num_conns; i++) {
407 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
408 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100409 HDA_AMP_MUTE, v);
410 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100411 } else {
412 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200413 snd_hda_codec_write_cache(codec, nid, 0,
414 AC_VERB_SET_CONNECT_SEL,
415 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100416 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200417 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200418 return 1;
419}
420
421static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
422 struct snd_ctl_elem_value *ucontrol)
423{
424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
425 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
426 return alc_mux_select(codec, adc_idx,
427 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100428}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100431 * set up the input pin config (depending on the given auto-pin type)
432 */
433static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
434 int auto_pin_type)
435{
436 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200437 if (auto_pin_type == AUTO_PIN_MIC)
438 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200439 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100440}
441
442/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200443 * Append the given mixer and verb elements for the later use
444 * The mixer array is referred in build_controls(), and init_verbs are
445 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100446 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200447static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100448{
449 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
450 return;
451 spec->mixers[spec->num_mixers++] = mix;
452}
453
Takashi Iwaid88897e2008-10-31 15:01:37 +0100454/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200455 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100456 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200457/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200458static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200459 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
460 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
461 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
462 { }
463};
464
Takashi Iwaia9111322011-05-02 11:30:18 +0200465static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200466 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
467 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
468 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
469 { }
470};
471
Takashi Iwaia9111322011-05-02 11:30:18 +0200472static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200473 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
474 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
475 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
476 { }
477};
478
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200479/*
480 * Fix hardware PLL issue
481 * On some codecs, the analog PLL gating control must be off while
482 * the default value is 1.
483 */
484static void alc_fix_pll(struct hda_codec *codec)
485{
486 struct alc_spec *spec = codec->spec;
487 unsigned int val;
488
489 if (!spec->pll_nid)
490 return;
491 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
492 spec->pll_coef_idx);
493 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
494 AC_VERB_GET_PROC_COEF, 0);
495 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
496 spec->pll_coef_idx);
497 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
498 val & ~(1 << spec->pll_coef_bit));
499}
500
501static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
502 unsigned int coef_idx, unsigned int coef_bit)
503{
504 struct alc_spec *spec = codec->spec;
505 spec->pll_nid = nid;
506 spec->pll_coef_idx = coef_idx;
507 spec->pll_coef_bit = coef_bit;
508 alc_fix_pll(codec);
509}
510
Takashi Iwai1d045db2011-07-07 18:23:21 +0200511/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200512 * Jack detections for HP auto-mute and mic-switch
513 */
514
515/* check each pin in the given array; returns true if any of them is plugged */
516static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200517{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200518 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200519
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200520 for (i = 0; i < num_pins; i++) {
521 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200522 if (!nid)
523 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200524 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200525 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526 return present;
527}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200528
Takashi Iwai1d045db2011-07-07 18:23:21 +0200529/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200530static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200531 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532{
533 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200534 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200535 int i;
536
537 for (i = 0; i < num_pins; i++) {
538 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100539 unsigned int val;
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200540 if (!nid)
541 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100542 /* don't reset VREF value in case it's controlling
543 * the amp (see alc861_fixup_asus_amp_vref_0f())
544 */
545 if (spec->keep_vref_in_automute) {
546 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100547 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100548 val &= ~PIN_HP;
549 } else
550 val = 0;
551 val |= pin_bits;
552 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200553 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200554}
555
David Henningsson42cf0d02011-09-20 12:04:56 +0200556/* Toggle outputs muting */
557static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558{
559 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561
Takashi Iwaic0a20262011-06-10 15:28:15 +0200562 /* Control HP pins/amps depending on master_mute state;
563 * in general, HP pins/amps control should be enabled in all cases,
564 * but currently set only for master_mute, just to be safe
565 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100566 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
567 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200568 spec->autocfg.hp_pins, spec->master_mute, true);
569
David Henningsson42cf0d02011-09-20 12:04:56 +0200570 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200571 on = 0;
572 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200573 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200574 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200575 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200576 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577
578 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200579 /* if LO is a copy of either HP or Speaker, don't need to handle it */
580 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
581 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200583 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200584 on = 0;
585 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200586 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200587 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200589 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590}
591
David Henningsson42cf0d02011-09-20 12:04:56 +0200592static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200593{
594 struct alc_spec *spec = codec->spec;
595 if (spec->automute_hook)
596 spec->automute_hook(codec);
597 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200598 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200599}
600
Takashi Iwai1d045db2011-07-07 18:23:21 +0200601/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200602static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200603{
604 struct alc_spec *spec = codec->spec;
605
David Henningsson42cf0d02011-09-20 12:04:56 +0200606 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
608 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200609 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200610 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200611 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200612}
613
Takashi Iwai1d045db2011-07-07 18:23:21 +0200614/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200615static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200616{
617 struct alc_spec *spec = codec->spec;
618
David Henningssonf7f4b2322012-10-10 16:32:09 +0200619 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
620 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200621 /* check LO jack only when it's different from HP */
622 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
623 return;
624
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200625 spec->line_jack_present =
626 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
627 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200628 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200629 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200630 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200631}
632
Takashi Iwai8d087c72011-06-28 12:45:47 +0200633#define get_connection_index(codec, mux, nid) \
634 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200635
Takashi Iwai1d045db2011-07-07 18:23:21 +0200636/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200637static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200638{
639 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200640 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200641
Takashi Iwai21268962011-07-07 15:01:13 +0200642 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200643 return;
644 if (snd_BUG_ON(!spec->adc_nids))
645 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200646 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200647 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200648
Takashi Iwai21268962011-07-07 15:01:13 +0200649 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
650 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
651 else if (spec->dock_mic_idx >= 0 &&
652 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
653 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
654 else
655 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200656}
657
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100658/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200659static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100660{
661 unsigned int val;
662 struct snd_kcontrol *kctl;
663 struct snd_ctl_elem_value *uctl;
664
665 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
666 if (!kctl)
667 return;
668 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
669 if (!uctl)
670 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200671 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100672 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
673 val &= HDA_AMP_VOLMASK;
674 uctl->value.integer.value[0] = val;
675 uctl->value.integer.value[1] = val;
676 kctl->put(kctl, uctl);
677 kfree(uctl);
678}
679
David Henningsson29adc4b2012-09-25 11:31:00 +0200680static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100681{
David Henningsson29adc4b2012-09-25 11:31:00 +0200682 /* For some reason, the res given from ALC880 is broken.
683 Here we adjust it properly. */
684 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100685}
686
Takashi Iwai1d045db2011-07-07 18:23:21 +0200687/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200688static void alc_inithook(struct hda_codec *codec)
689{
David Henningsson29adc4b2012-09-25 11:31:00 +0200690 alc_hp_automute(codec, NULL);
691 alc_line_automute(codec, NULL);
692 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200693}
694
Kailang Yangf9423e72008-05-27 12:32:25 +0200695/* additional initialization for ALC888 variants */
696static void alc888_coef_init(struct hda_codec *codec)
697{
698 unsigned int tmp;
699
700 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
701 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
702 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100703 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200704 /* alc888S-VC */
705 snd_hda_codec_read(codec, 0x20, 0,
706 AC_VERB_SET_PROC_COEF, 0x830);
707 else
708 /* alc888-VB */
709 snd_hda_codec_read(codec, 0x20, 0,
710 AC_VERB_SET_PROC_COEF, 0x3030);
711}
712
Takashi Iwai1d045db2011-07-07 18:23:21 +0200713/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200714static void alc889_coef_init(struct hda_codec *codec)
715{
716 unsigned int tmp;
717
718 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
719 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
720 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
722}
723
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100724/* turn on/off EAPD control (only if available) */
725static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
726{
727 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
728 return;
729 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
731 on ? 2 : 0);
732}
733
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200734/* turn on/off EAPD controls of the codec */
735static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
736{
737 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200738 static hda_nid_t pins[] = {
739 0x0f, 0x10, 0x14, 0x15, 0
740 };
741 hda_nid_t *p;
742 for (p = pins; *p; p++)
743 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200744}
745
Takashi Iwai1c7161532011-04-07 10:37:16 +0200746/* generic shutup callback;
747 * just turning off EPAD and a little pause for avoiding pop-noise
748 */
749static void alc_eapd_shutup(struct hda_codec *codec)
750{
751 alc_auto_setup_eapd(codec, false);
752 msleep(200);
753}
754
Takashi Iwai1d045db2011-07-07 18:23:21 +0200755/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200756static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200757{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200758 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200759
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200760 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200761 switch (type) {
762 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200763 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
764 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200765 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200766 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
767 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200768 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200769 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
770 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200771 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200772 switch (codec->vendor_id) {
773 case 0x10ec0260:
774 snd_hda_codec_write(codec, 0x1a, 0,
775 AC_VERB_SET_COEF_INDEX, 7);
776 tmp = snd_hda_codec_read(codec, 0x1a, 0,
777 AC_VERB_GET_PROC_COEF, 0);
778 snd_hda_codec_write(codec, 0x1a, 0,
779 AC_VERB_SET_COEF_INDEX, 7);
780 snd_hda_codec_write(codec, 0x1a, 0,
781 AC_VERB_SET_PROC_COEF,
782 tmp | 0x2010);
783 break;
784 case 0x10ec0262:
785 case 0x10ec0880:
786 case 0x10ec0882:
787 case 0x10ec0883:
788 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100789 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100790 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200791 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200792 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200793 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200794 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200795 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100796#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200797 case 0x10ec0267:
798 case 0x10ec0268:
799 snd_hda_codec_write(codec, 0x20, 0,
800 AC_VERB_SET_COEF_INDEX, 7);
801 tmp = snd_hda_codec_read(codec, 0x20, 0,
802 AC_VERB_GET_PROC_COEF, 0);
803 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200804 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200805 snd_hda_codec_write(codec, 0x20, 0,
806 AC_VERB_SET_PROC_COEF,
807 tmp | 0x3000);
808 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100809#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200810 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200811 break;
812 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200813}
Kailang Yangea1fb292008-08-26 12:58:38 +0200814
Takashi Iwai1d045db2011-07-07 18:23:21 +0200815/*
816 * Auto-Mute mode mixer enum support
817 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200818static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
819 struct snd_ctl_elem_info *uinfo)
820{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200821 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
822 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200823 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100824 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200825 };
826
Takashi Iwaidda415d2012-11-30 18:34:38 +0100827 if (spec->automute_speaker_possible && spec->automute_lo_possible)
828 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
829 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200830}
831
832static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
833 struct snd_ctl_elem_value *ucontrol)
834{
835 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
836 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200837 unsigned int val = 0;
838 if (spec->automute_speaker)
839 val++;
840 if (spec->automute_lo)
841 val++;
842
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200843 ucontrol->value.enumerated.item[0] = val;
844 return 0;
845}
846
847static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
848 struct snd_ctl_elem_value *ucontrol)
849{
850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
851 struct alc_spec *spec = codec->spec;
852
853 switch (ucontrol->value.enumerated.item[0]) {
854 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200855 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200856 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200857 spec->automute_speaker = 0;
858 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200859 break;
860 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200861 if (spec->automute_speaker_possible) {
862 if (!spec->automute_lo && spec->automute_speaker)
863 return 0;
864 spec->automute_speaker = 1;
865 spec->automute_lo = 0;
866 } else if (spec->automute_lo_possible) {
867 if (spec->automute_lo)
868 return 0;
869 spec->automute_lo = 1;
870 } else
871 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200872 break;
873 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200874 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200875 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200876 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200877 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200878 spec->automute_speaker = 1;
879 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 break;
881 default:
882 return -EINVAL;
883 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 return 1;
886}
887
Takashi Iwaia9111322011-05-02 11:30:18 +0200888static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200889 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
890 .name = "Auto-Mute Mode",
891 .info = alc_automute_mode_info,
892 .get = alc_automute_mode_get,
893 .put = alc_automute_mode_put,
894};
895
Takashi Iwai668d1e92012-11-29 14:10:17 +0100896static struct snd_kcontrol_new *
897alc_kcontrol_new(struct alc_spec *spec, const char *name,
898 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200899{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100900 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
901 if (!knew)
902 return NULL;
903 *knew = *temp;
904 knew->name = kstrdup(name, GFP_KERNEL);
905 if (!knew->name)
906 return NULL;
907 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200908}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909
910static int alc_add_automute_mode_enum(struct hda_codec *codec)
911{
912 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200913
Takashi Iwai668d1e92012-11-29 14:10:17 +0100914 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200915 return -ENOMEM;
916 return 0;
917}
918
Takashi Iwai1d045db2011-07-07 18:23:21 +0200919/*
920 * Check the availability of HP/line-out auto-mute;
921 * Set up appropriately if really supported
922 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100923static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200924{
925 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200926 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200927 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100928 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200929
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200930 if (cfg->hp_pins[0])
931 present++;
932 if (cfg->line_out_pins[0])
933 present++;
934 if (cfg->speaker_pins[0])
935 present++;
936 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100937 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200938
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200939 if (!cfg->speaker_pins[0] &&
940 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200941 memcpy(cfg->speaker_pins, cfg->line_out_pins,
942 sizeof(cfg->speaker_pins));
943 cfg->speaker_outs = cfg->line_outs;
944 }
945
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200946 if (!cfg->hp_pins[0] &&
947 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200948 memcpy(cfg->hp_pins, cfg->line_out_pins,
949 sizeof(cfg->hp_pins));
950 cfg->hp_outs = cfg->line_outs;
951 }
952
953 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200954 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200955 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200956 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200957 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200958 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200959 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
960 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200961 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200962 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200963
David Henningsson42cf0d02011-09-20 12:04:56 +0200964 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
965 if (cfg->speaker_outs)
966 for (i = 0; i < cfg->line_outs; i++) {
967 hda_nid_t nid = cfg->line_out_pins[i];
968 if (!is_jack_detectable(codec, nid))
969 continue;
970 snd_printdd("realtek: Enable Line-Out "
971 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200972 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
973 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200974 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200975 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200976 spec->automute_lo_possible = spec->detect_hp;
977 }
978
979 spec->automute_speaker_possible = cfg->speaker_outs &&
980 (spec->detect_hp || spec->detect_lo);
981
982 spec->automute_lo = spec->automute_lo_possible;
983 spec->automute_speaker = spec->automute_speaker_possible;
984
Takashi Iwai475c3d22012-11-30 08:31:30 +0100985 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200986 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100987 err = alc_add_automute_mode_enum(codec);
988 if (err < 0)
989 return err;
990 }
991 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200992}
993
Takashi Iwai1d045db2011-07-07 18:23:21 +0200994/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200995static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
996{
997 int i;
998 for (i = 0; i < nums; i++)
999 if (list[i] == nid)
1000 return i;
1001 return -1;
1002}
1003
Takashi Iwai1d045db2011-07-07 18:23:21 +02001004/* check whether dynamic ADC-switching is available */
1005static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1006{
1007 struct alc_spec *spec = codec->spec;
1008 struct hda_input_mux *imux = &spec->private_imux[0];
1009 int i, n, idx;
1010 hda_nid_t cap, pin;
1011
1012 if (imux != spec->input_mux) /* no dynamic imux? */
1013 return false;
1014
1015 for (n = 0; n < spec->num_adc_nids; n++) {
1016 cap = spec->private_capsrc_nids[n];
1017 for (i = 0; i < imux->num_items; i++) {
1018 pin = spec->imux_pins[i];
1019 if (!pin)
1020 return false;
1021 if (get_connection_index(codec, cap, pin) < 0)
1022 break;
1023 }
1024 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001025 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001026 }
1027
1028 for (i = 0; i < imux->num_items; i++) {
1029 pin = spec->imux_pins[i];
1030 for (n = 0; n < spec->num_adc_nids; n++) {
1031 cap = spec->private_capsrc_nids[n];
1032 idx = get_connection_index(codec, cap, pin);
1033 if (idx >= 0) {
1034 imux->items[i].index = idx;
1035 spec->dyn_adc_idx[i] = n;
1036 break;
1037 }
1038 }
1039 }
1040
1041 snd_printdd("realtek: enabling ADC switching\n");
1042 spec->dyn_adc_switch = 1;
1043 return true;
1044}
Takashi Iwai21268962011-07-07 15:01:13 +02001045
Takashi Iwai21268962011-07-07 15:01:13 +02001046/* check whether all auto-mic pins are valid; setup indices if OK */
1047static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1048{
1049 struct alc_spec *spec = codec->spec;
1050 const struct hda_input_mux *imux;
1051
1052 if (!spec->auto_mic)
1053 return false;
1054 if (spec->auto_mic_valid_imux)
1055 return true; /* already checked */
1056
1057 /* fill up imux indices */
1058 if (!alc_check_dyn_adc_switch(codec)) {
1059 spec->auto_mic = 0;
1060 return false;
1061 }
1062
1063 imux = spec->input_mux;
1064 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1065 spec->imux_pins, imux->num_items);
1066 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1067 spec->imux_pins, imux->num_items);
1068 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1069 spec->imux_pins, imux->num_items);
1070 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1071 spec->auto_mic = 0;
1072 return false; /* no corresponding imux */
1073 }
1074
David Henningsson29adc4b2012-09-25 11:31:00 +02001075 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1076 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001077 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001078 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1079 ALC_MIC_EVENT,
1080 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001081
1082 spec->auto_mic_valid_imux = 1;
1083 spec->auto_mic = 1;
1084 return true;
1085}
1086
Takashi Iwai1d045db2011-07-07 18:23:21 +02001087/*
1088 * Check the availability of auto-mic switch;
1089 * Set up if really supported
1090 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001091static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001092{
1093 struct alc_spec *spec = codec->spec;
1094 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001095 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001096 int i;
1097
Takashi Iwai24de1832011-11-07 17:13:39 +01001098 if (spec->shared_mic_hp)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001099 return 0; /* no auto-mic for the shared I/O */
Takashi Iwai24de1832011-11-07 17:13:39 +01001100
Takashi Iwai21268962011-07-07 15:01:13 +02001101 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1102
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001103 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001104 for (i = 0; i < cfg->num_inputs; i++) {
1105 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001106 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001107 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001108 switch (snd_hda_get_input_pin_attr(defcfg)) {
1109 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001110 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001111 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001112 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001113 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001114 fixed = nid;
1115 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001116 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001117 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001118 case INPUT_PIN_ATTR_DOCK:
1119 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001120 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001121 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001122 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001123 dock = nid;
1124 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001125 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001126 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001127 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001128 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001129 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001130 ext = nid;
1131 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001132 }
1133 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001134 if (!ext && dock) {
1135 ext = dock;
1136 dock = 0;
1137 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001138 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001139 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001140 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001141 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001142 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001143 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001144
1145 /* check imux indices */
1146 spec->ext_mic_pin = ext;
1147 spec->int_mic_pin = fixed;
1148 spec->dock_mic_pin = dock;
1149
1150 spec->auto_mic = 1;
1151 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001152 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001153
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001154 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1155 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001156
1157 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001158}
1159
Takashi Iwai1d045db2011-07-07 18:23:21 +02001160/* check the availabilities of auto-mute and auto-mic switches */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001161static int alc_auto_check_switches(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02001162{
Takashi Iwai475c3d22012-11-30 08:31:30 +01001163 int err;
1164
1165 err = alc_init_automute(codec);
1166 if (err < 0)
1167 return err;
1168 err = alc_init_auto_mic(codec);
1169 if (err < 0)
1170 return err;
1171 return 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02001172}
1173
1174/*
1175 * Realtek SSID verification
1176 */
1177
David Henningsson90622912010-10-14 14:50:18 +02001178/* Could be any non-zero and even value. When used as fixup, tells
1179 * the driver to ignore any present sku defines.
1180 */
1181#define ALC_FIXUP_SKU_IGNORE (2)
1182
Takashi Iwai23d30f22012-05-07 17:17:32 +02001183static void alc_fixup_sku_ignore(struct hda_codec *codec,
1184 const struct hda_fixup *fix, int action)
1185{
1186 struct alc_spec *spec = codec->spec;
1187 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1188 spec->cdefine.fixup = 1;
1189 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1190 }
1191}
1192
Kailang Yangda00c242010-03-19 11:23:45 +01001193static int alc_auto_parse_customize_define(struct hda_codec *codec)
1194{
1195 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001196 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001197 struct alc_spec *spec = codec->spec;
1198
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001199 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1200
David Henningsson90622912010-10-14 14:50:18 +02001201 if (spec->cdefine.fixup) {
1202 ass = spec->cdefine.sku_cfg;
1203 if (ass == ALC_FIXUP_SKU_IGNORE)
1204 return -1;
1205 goto do_sku;
1206 }
1207
Kailang Yangda00c242010-03-19 11:23:45 +01001208 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001209 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001210 goto do_sku;
1211
1212 nid = 0x1d;
1213 if (codec->vendor_id == 0x10ec0260)
1214 nid = 0x17;
1215 ass = snd_hda_codec_get_pincfg(codec, nid);
1216
1217 if (!(ass & 1)) {
1218 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1219 codec->chip_name, ass);
1220 return -1;
1221 }
1222
1223 /* check sum */
1224 tmp = 0;
1225 for (i = 1; i < 16; i++) {
1226 if ((ass >> i) & 1)
1227 tmp++;
1228 }
1229 if (((ass >> 16) & 0xf) != tmp)
1230 return -1;
1231
1232 spec->cdefine.port_connectivity = ass >> 30;
1233 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1234 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1235 spec->cdefine.customization = ass >> 8;
1236do_sku:
1237 spec->cdefine.sku_cfg = ass;
1238 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1239 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1240 spec->cdefine.swap = (ass & 0x2) >> 1;
1241 spec->cdefine.override = ass & 0x1;
1242
1243 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1244 nid, spec->cdefine.sku_cfg);
1245 snd_printd("SKU: port_connectivity=0x%x\n",
1246 spec->cdefine.port_connectivity);
1247 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1248 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1249 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1250 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1251 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1252 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1253 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1254
1255 return 0;
1256}
1257
Takashi Iwai1d045db2011-07-07 18:23:21 +02001258/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001259static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1260{
Takashi Iwai21268962011-07-07 15:01:13 +02001261 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001262}
1263
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001264/* check subsystem ID and set up device-specific initialization;
1265 * return 1 if initialized, 0 if invalid SSID
1266 */
1267/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1268 * 31 ~ 16 : Manufacture ID
1269 * 15 ~ 8 : SKU ID
1270 * 7 ~ 0 : Assembly ID
1271 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1272 */
1273static int alc_subsystem_id(struct hda_codec *codec,
1274 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001275 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001276{
1277 unsigned int ass, tmp, i;
1278 unsigned nid;
1279 struct alc_spec *spec = codec->spec;
1280
David Henningsson90622912010-10-14 14:50:18 +02001281 if (spec->cdefine.fixup) {
1282 ass = spec->cdefine.sku_cfg;
1283 if (ass == ALC_FIXUP_SKU_IGNORE)
1284 return 0;
1285 goto do_sku;
1286 }
1287
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001288 ass = codec->subsystem_id & 0xffff;
1289 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1290 goto do_sku;
1291
1292 /* invalid SSID, check the special NID pin defcfg instead */
1293 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001294 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001295 * 29~21 : reserve
1296 * 20 : PCBEEP input
1297 * 19~16 : Check sum (15:1)
1298 * 15~1 : Custom
1299 * 0 : override
1300 */
1301 nid = 0x1d;
1302 if (codec->vendor_id == 0x10ec0260)
1303 nid = 0x17;
1304 ass = snd_hda_codec_get_pincfg(codec, nid);
1305 snd_printd("realtek: No valid SSID, "
1306 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001307 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001308 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001309 return 0;
1310 if ((ass >> 30) != 1) /* no physical connection */
1311 return 0;
1312
1313 /* check sum */
1314 tmp = 0;
1315 for (i = 1; i < 16; i++) {
1316 if ((ass >> i) & 1)
1317 tmp++;
1318 }
1319 if (((ass >> 16) & 0xf) != tmp)
1320 return 0;
1321do_sku:
1322 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1323 ass & 0xffff, codec->vendor_id);
1324 /*
1325 * 0 : override
1326 * 1 : Swap Jack
1327 * 2 : 0 --> Desktop, 1 --> Laptop
1328 * 3~5 : External Amplifier control
1329 * 7~6 : Reserved
1330 */
1331 tmp = (ass & 0x38) >> 3; /* external Amp control */
1332 switch (tmp) {
1333 case 1:
1334 spec->init_amp = ALC_INIT_GPIO1;
1335 break;
1336 case 3:
1337 spec->init_amp = ALC_INIT_GPIO2;
1338 break;
1339 case 7:
1340 spec->init_amp = ALC_INIT_GPIO3;
1341 break;
1342 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001343 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001344 spec->init_amp = ALC_INIT_DEFAULT;
1345 break;
1346 }
1347
1348 /* is laptop or Desktop and enable the function "Mute internal speaker
1349 * when the external headphone out jack is plugged"
1350 */
1351 if (!(ass & 0x8000))
1352 return 1;
1353 /*
1354 * 10~8 : Jack location
1355 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1356 * 14~13: Resvered
1357 * 15 : 1 --> enable the function "Mute internal speaker
1358 * when the external headphone out jack is plugged"
1359 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001360 if (!spec->autocfg.hp_pins[0] &&
1361 !(spec->autocfg.line_out_pins[0] &&
1362 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001363 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001364 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1365 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001366 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001367 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001368 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001369 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001370 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001371 else if (tmp == 3)
1372 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001373 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001374 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001375 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1376 spec->autocfg.line_outs))
1377 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001378 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001379 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001380 return 1;
1381}
Kailang Yangea1fb292008-08-26 12:58:38 +02001382
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001383/* Check the validity of ALC subsystem-id
1384 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1385static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001386{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001387 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001388 struct alc_spec *spec = codec->spec;
1389 snd_printd("realtek: "
1390 "Enable default setup for auto mode as fallback\n");
1391 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001392 }
Takashi Iwai21268962011-07-07 15:01:13 +02001393}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001394
Takashi Iwai41e41f12005-06-08 14:48:49 +02001395/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001396 * COEF access helper functions
1397 */
Kailang Yang274693f2009-12-03 10:07:50 +01001398static int alc_read_coef_idx(struct hda_codec *codec,
1399 unsigned int coef_idx)
1400{
1401 unsigned int val;
1402 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1403 coef_idx);
1404 val = snd_hda_codec_read(codec, 0x20, 0,
1405 AC_VERB_GET_PROC_COEF, 0);
1406 return val;
1407}
1408
Kailang Yang977ddd62010-09-15 10:02:29 +02001409static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1410 unsigned int coef_val)
1411{
1412 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1413 coef_idx);
1414 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1415 coef_val);
1416}
1417
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001418/* a special bypass for COEF 0; read the cached value at the second time */
1419static unsigned int alc_get_coef0(struct hda_codec *codec)
1420{
1421 struct alc_spec *spec = codec->spec;
1422 if (!spec->coef0)
1423 spec->coef0 = alc_read_coef_idx(codec, 0);
1424 return spec->coef0;
1425}
1426
Takashi Iwai1d045db2011-07-07 18:23:21 +02001427/*
1428 * Digital I/O handling
1429 */
1430
Takashi Iwai757899a2010-07-30 10:48:14 +02001431/* set right pin controls for digital I/O */
1432static void alc_auto_init_digital(struct hda_codec *codec)
1433{
1434 struct alc_spec *spec = codec->spec;
1435 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001436 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001437
1438 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1439 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001440 if (!pin)
1441 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001442 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001443 if (!i)
1444 dac = spec->multiout.dig_out_nid;
1445 else
1446 dac = spec->slave_dig_outs[i - 1];
1447 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1448 continue;
1449 snd_hda_codec_write(codec, dac, 0,
1450 AC_VERB_SET_AMP_GAIN_MUTE,
1451 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001452 }
1453 pin = spec->autocfg.dig_in_pin;
1454 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001455 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001456}
1457
1458/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1459static void alc_auto_parse_digital(struct hda_codec *codec)
1460{
1461 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001462 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001463 hda_nid_t dig_nid;
1464
1465 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001466 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001467 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001468 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001469 err = snd_hda_get_connections(codec,
1470 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001471 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001472 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001473 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001474 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001475 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001476 spec->multiout.dig_out_nid = dig_nid;
1477 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1478 } else {
1479 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001480 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001481 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001482 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001483 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001484 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001485 }
1486
1487 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001488 dig_nid = codec->start_nid;
1489 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1490 unsigned int wcaps = get_wcaps(codec, dig_nid);
1491 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1492 continue;
1493 if (!(wcaps & AC_WCAP_DIGITAL))
1494 continue;
1495 if (!(wcaps & AC_WCAP_CONN_LIST))
1496 continue;
1497 err = get_connection_index(codec, dig_nid,
1498 spec->autocfg.dig_in_pin);
1499 if (err >= 0) {
1500 spec->dig_in_nid = dig_nid;
1501 break;
1502 }
1503 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001504 }
1505}
1506
Takashi Iwaif95474e2007-07-10 00:47:43 +02001507/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001508 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001509 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001510static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1511 struct snd_ctl_elem_info *uinfo)
1512{
1513 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1514 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001515 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001516 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001517
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001518 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001519 if (spec->vol_in_capsrc)
1520 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1521 else
1522 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1523 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001524 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001525 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001526 return err;
1527}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001529static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1530 unsigned int size, unsigned int __user *tlv)
1531{
1532 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1533 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001534 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001535 int err;
1536
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001537 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001538 if (spec->vol_in_capsrc)
1539 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1540 else
1541 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1542 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001543 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001544 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001545 return err;
1546}
1547
1548typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1549 struct snd_ctl_elem_value *ucontrol);
1550
1551static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1552 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001553 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001554{
1555 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1556 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001557 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001558
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001559 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001560 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001561 for (i = 0; i < spec->num_adc_nids; i++) {
1562 kcontrol->private_value =
1563 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1564 3, 0, HDA_INPUT);
1565 err = func(kcontrol, ucontrol);
1566 if (err < 0)
1567 goto error;
1568 }
1569 } else {
1570 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001571 if (spec->vol_in_capsrc)
1572 kcontrol->private_value =
1573 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1574 3, 0, HDA_OUTPUT);
1575 else
1576 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001577 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1578 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001579 err = func(kcontrol, ucontrol);
1580 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001581 if (err >= 0 && is_put)
1582 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001583 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001584 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001585 return err;
1586}
1587
1588static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1589 struct snd_ctl_elem_value *ucontrol)
1590{
1591 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001592 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001593}
1594
1595static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1596 struct snd_ctl_elem_value *ucontrol)
1597{
1598 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001599 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001600}
1601
1602/* capture mixer elements */
1603#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1604
1605static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1606 struct snd_ctl_elem_value *ucontrol)
1607{
1608 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001609 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001610}
1611
1612static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1613 struct snd_ctl_elem_value *ucontrol)
1614{
1615 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001616 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001617}
1618
Takashi Iwaia23b6882009-03-23 15:21:36 +01001619#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001620 { \
1621 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1622 .name = "Capture Switch", \
1623 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1624 .count = num, \
1625 .info = alc_cap_sw_info, \
1626 .get = alc_cap_sw_get, \
1627 .put = alc_cap_sw_put, \
1628 }, \
1629 { \
1630 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1631 .name = "Capture Volume", \
1632 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1633 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1634 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1635 .count = num, \
1636 .info = alc_cap_vol_info, \
1637 .get = alc_cap_vol_get, \
1638 .put = alc_cap_vol_put, \
1639 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001640 }
1641
1642#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001643 { \
1644 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1645 /* .name = "Capture Source", */ \
1646 .name = "Input Source", \
1647 .count = num, \
1648 .info = alc_mux_enum_info, \
1649 .get = alc_mux_enum_get, \
1650 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001651 }
1652
1653#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001654static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001655 _DEFINE_CAPMIX(num), \
1656 _DEFINE_CAPSRC(num), \
1657 { } /* end */ \
1658}
1659
1660#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001661static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001662 _DEFINE_CAPMIX(num), \
1663 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001664}
1665
1666/* up to three ADCs */
1667DEFINE_CAPMIX(1);
1668DEFINE_CAPMIX(2);
1669DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001670DEFINE_CAPMIX_NOSRC(1);
1671DEFINE_CAPMIX_NOSRC(2);
1672DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001673
1674/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001675 * Inverted digital-mic handling
1676 *
1677 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1678 * gives the additional mute only to the right channel of the digital mic
1679 * capture stream. This is a workaround for avoiding the almost silence
1680 * by summing the stereo stream from some (known to be ForteMedia)
1681 * digital mic unit.
1682 *
1683 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1684 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1685 * without caching so that the cache can still keep the original value.
1686 * The cached value is then restored when the flag is set off or any other
1687 * than d-mic is used as the current input source.
1688 */
1689static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1690{
1691 struct alc_spec *spec = codec->spec;
1692 int i;
1693
1694 if (!spec->inv_dmic_fixup)
1695 return;
1696 if (!spec->inv_dmic_muted && !force)
1697 return;
1698 for (i = 0; i < spec->num_adc_nids; i++) {
1699 int src = spec->dyn_adc_switch ? 0 : i;
1700 bool dmic_fixup = false;
1701 hda_nid_t nid;
1702 int parm, dir, v;
1703
1704 if (spec->inv_dmic_muted &&
1705 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1706 dmic_fixup = true;
1707 if (!dmic_fixup && !force)
1708 continue;
1709 if (spec->vol_in_capsrc) {
1710 nid = spec->capsrc_nids[i];
1711 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1712 dir = HDA_OUTPUT;
1713 } else {
1714 nid = spec->adc_nids[i];
1715 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1716 dir = HDA_INPUT;
1717 }
1718 /* we care only right channel */
1719 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1720 if (v & 0x80) /* if already muted, we don't need to touch */
1721 continue;
1722 if (dmic_fixup) /* add mute for d-mic */
1723 v |= 0x80;
1724 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1725 parm | v);
1726 }
1727}
1728
1729static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol)
1731{
1732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1733 struct alc_spec *spec = codec->spec;
1734
1735 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1736 return 0;
1737}
1738
1739static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1740 struct snd_ctl_elem_value *ucontrol)
1741{
1742 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1743 struct alc_spec *spec = codec->spec;
1744 unsigned int val = !ucontrol->value.integer.value[0];
1745
1746 if (val == spec->inv_dmic_muted)
1747 return 0;
1748 spec->inv_dmic_muted = val;
1749 alc_inv_dmic_sync(codec, true);
1750 return 0;
1751}
1752
1753static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1755 .info = snd_ctl_boolean_mono_info,
1756 .get = alc_inv_dmic_sw_get,
1757 .put = alc_inv_dmic_sw_put,
1758};
1759
1760static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1761{
1762 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001763
1764 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1765 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001766 return -ENOMEM;
1767 spec->inv_dmic_fixup = 1;
1768 spec->inv_dmic_muted = 0;
1769 spec->inv_dmic_pin = nid;
1770 return 0;
1771}
1772
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001773/* typically the digital mic is put at node 0x12 */
1774static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1775 const struct alc_fixup *fix, int action)
1776{
1777 if (action == ALC_FIXUP_ACT_PROBE)
1778 alc_add_inv_dmic_mixer(codec, 0x12);
1779}
1780
Takashi Iwai125821a2012-06-22 14:30:29 +02001781/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001782 * virtual master controls
1783 */
1784
1785/*
1786 * slave controls for virtual master
1787 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001788static const char * const alc_slave_pfxs[] = {
1789 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001790 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001791 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001792 NULL,
1793};
1794
1795/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001796 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001798
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001799#define NID_MAPPING (-1)
1800
1801#define SUBDEV_SPEAKER_ (0 << 6)
1802#define SUBDEV_HP_ (1 << 6)
1803#define SUBDEV_LINE_ (2 << 6)
1804#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1805#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1806#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1807
Takashi Iwai603c4012008-07-30 15:01:44 +02001808static void alc_free_kctls(struct hda_codec *codec);
1809
Takashi Iwai67d634c2009-11-16 15:35:59 +01001810#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001811/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001812static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001813 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001814 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001815 { } /* end */
1816};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001817#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001818
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001819static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820{
1821 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001822 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001823 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001824 int i, j, err;
1825 unsigned int u;
1826 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
1828 for (i = 0; i < spec->num_mixers; i++) {
1829 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1830 if (err < 0)
1831 return err;
1832 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001833 if (spec->cap_mixer) {
1834 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1835 if (err < 0)
1836 return err;
1837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001839 err = snd_hda_create_dig_out_ctls(codec,
1840 spec->multiout.dig_out_nid,
1841 spec->multiout.dig_out_nid,
1842 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 if (err < 0)
1844 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001845 if (!spec->no_analog) {
1846 err = snd_hda_create_spdif_share_sw(codec,
1847 &spec->multiout);
1848 if (err < 0)
1849 return err;
1850 spec->multiout.share_spdif = 1;
1851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 }
1853 if (spec->dig_in_nid) {
1854 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1855 if (err < 0)
1856 return err;
1857 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001858
Takashi Iwai67d634c2009-11-16 15:35:59 +01001859#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001860 /* create beep controls if needed */
1861 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001862 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001863 for (knew = alc_beep_mixer; knew->name; knew++) {
1864 struct snd_kcontrol *kctl;
1865 kctl = snd_ctl_new1(knew, codec);
1866 if (!kctl)
1867 return -ENOMEM;
1868 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001869 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001870 if (err < 0)
1871 return err;
1872 }
1873 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001874#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001875
Takashi Iwai2134ea42008-01-10 16:53:55 +01001876 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001877 if (!spec->no_analog &&
1878 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001879 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001880 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001881 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001882 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001883 vmaster_tlv, alc_slave_pfxs,
1884 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001885 if (err < 0)
1886 return err;
1887 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001888 if (!spec->no_analog &&
1889 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001890 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1891 NULL, alc_slave_pfxs,
1892 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001893 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001894 if (err < 0)
1895 return err;
1896 }
1897
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001898 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001899 if (spec->capsrc_nids || spec->adc_nids) {
1900 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1901 if (!kctl)
1902 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1903 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001904 err = snd_hda_add_nid(codec, kctl, i,
1905 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001906 if (err < 0)
1907 return err;
1908 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001909 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001910 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001911 const char *kname = kctl ? kctl->id.name : NULL;
1912 for (knew = spec->cap_mixer; knew->name; knew++) {
1913 if (kname && strcmp(knew->name, kname) == 0)
1914 continue;
1915 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1916 for (i = 0; kctl && i < kctl->count; i++) {
1917 err = snd_hda_add_nid(codec, kctl, i,
1918 spec->adc_nids[i]);
1919 if (err < 0)
1920 return err;
1921 }
1922 }
1923 }
1924
1925 /* other nid->control mapping */
1926 for (i = 0; i < spec->num_mixers; i++) {
1927 for (knew = spec->mixers[i]; knew->name; knew++) {
1928 if (knew->iface != NID_MAPPING)
1929 continue;
1930 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1931 if (kctl == NULL)
1932 continue;
1933 u = knew->subdevice;
1934 for (j = 0; j < 4; j++, u >>= 8) {
1935 nid = u & 0x3f;
1936 if (nid == 0)
1937 continue;
1938 switch (u & 0xc0) {
1939 case SUBDEV_SPEAKER_:
1940 nid = spec->autocfg.speaker_pins[nid];
1941 break;
1942 case SUBDEV_LINE_:
1943 nid = spec->autocfg.line_out_pins[nid];
1944 break;
1945 case SUBDEV_HP_:
1946 nid = spec->autocfg.hp_pins[nid];
1947 break;
1948 default:
1949 continue;
1950 }
1951 err = snd_hda_add_nid(codec, kctl, 0, nid);
1952 if (err < 0)
1953 return err;
1954 }
1955 u = knew->private_value;
1956 for (j = 0; j < 4; j++, u >>= 8) {
1957 nid = u & 0xff;
1958 if (nid == 0)
1959 continue;
1960 err = snd_hda_add_nid(codec, kctl, 0, nid);
1961 if (err < 0)
1962 return err;
1963 }
1964 }
1965 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001966
1967 alc_free_kctls(codec); /* no longer needed */
1968
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001969 return 0;
1970}
1971
David Henningsson5780b622012-06-27 18:45:45 +02001972static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001973{
1974 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001975
1976 if (spec->shared_mic_hp) {
1977 int err;
1978 int nid = spec->autocfg.inputs[1].pin;
1979 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1980 if (err < 0)
1981 return err;
1982 err = snd_hda_jack_detect_enable(codec, nid, 0);
1983 if (err < 0)
1984 return err;
1985 }
1986
1987 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1988}
1989
1990static int alc_build_controls(struct hda_codec *codec)
1991{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001992 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001993 if (err < 0)
1994 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001995
1996 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001997 if (err < 0)
1998 return err;
1999 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2000 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002003
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002005 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002006 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002007
Takashi Iwai584c0c42011-03-10 12:51:11 +01002008static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002009static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002010
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011static int alc_init(struct hda_codec *codec)
2012{
2013 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002014
Takashi Iwai546bb672012-03-07 08:37:19 +01002015 if (spec->init_hook)
2016 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002017
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002018 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002019 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002020
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002021 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002022 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002023 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002024
Takashi Iwai58701122011-01-13 15:41:45 +01002025 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2026
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002027 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 return 0;
2029}
2030
Takashi Iwai83012a72012-08-24 18:38:08 +02002031#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002032static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2033{
2034 struct alc_spec *spec = codec->spec;
2035 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2036}
2037#endif
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039/*
2040 * Analog playback callbacks
2041 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002042static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002044 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045{
2046 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002047 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2048 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002051static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 struct hda_codec *codec,
2053 unsigned int stream_tag,
2054 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002055 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056{
2057 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002058 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2059 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002062static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002064 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065{
2066 struct alc_spec *spec = codec->spec;
2067 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2068}
2069
2070/*
2071 * Digital out
2072 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002073static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002075 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
2077 struct alc_spec *spec = codec->spec;
2078 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2079}
2080
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002081static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002082 struct hda_codec *codec,
2083 unsigned int stream_tag,
2084 unsigned int format,
2085 struct snd_pcm_substream *substream)
2086{
2087 struct alc_spec *spec = codec->spec;
2088 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2089 stream_tag, format, substream);
2090}
2091
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002092static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002093 struct hda_codec *codec,
2094 struct snd_pcm_substream *substream)
2095{
2096 struct alc_spec *spec = codec->spec;
2097 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2098}
2099
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002100static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002102 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
2104 struct alc_spec *spec = codec->spec;
2105 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2106}
2107
2108/*
2109 * Analog capture
2110 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002111static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 struct hda_codec *codec,
2113 unsigned int stream_tag,
2114 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002115 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
2117 struct alc_spec *spec = codec->spec;
2118
Takashi Iwai63300792008-01-24 15:31:36 +01002119 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 stream_tag, 0, format);
2121 return 0;
2122}
2123
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002124static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002126 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127{
2128 struct alc_spec *spec = codec->spec;
2129
Takashi Iwai888afa12008-03-18 09:57:50 +01002130 snd_hda_codec_cleanup_stream(codec,
2131 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 return 0;
2133}
2134
Takashi Iwai840b64c2010-07-13 22:49:01 +02002135/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002136static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002137 struct hda_codec *codec,
2138 unsigned int stream_tag,
2139 unsigned int format,
2140 struct snd_pcm_substream *substream)
2141{
2142 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002143 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002144 spec->cur_adc_stream_tag = stream_tag;
2145 spec->cur_adc_format = format;
2146 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2147 return 0;
2148}
2149
Takashi Iwai21268962011-07-07 15:01:13 +02002150static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002151 struct hda_codec *codec,
2152 struct snd_pcm_substream *substream)
2153{
2154 struct alc_spec *spec = codec->spec;
2155 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2156 spec->cur_adc = 0;
2157 return 0;
2158}
2159
Takashi Iwai21268962011-07-07 15:01:13 +02002160static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002161 .substreams = 1,
2162 .channels_min = 2,
2163 .channels_max = 2,
2164 .nid = 0, /* fill later */
2165 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002166 .prepare = dyn_adc_capture_pcm_prepare,
2167 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002168 },
2169};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
2171/*
2172 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002173static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 .substreams = 1,
2175 .channels_min = 2,
2176 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002177 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002179 .open = alc_playback_pcm_open,
2180 .prepare = alc_playback_pcm_prepare,
2181 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 },
2183};
2184
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002185static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002186 .substreams = 1,
2187 .channels_min = 2,
2188 .channels_max = 2,
2189 /* NID is set in alc_build_pcms */
2190};
2191
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002192static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002193 .substreams = 1,
2194 .channels_min = 2,
2195 .channels_max = 2,
2196 /* NID is set in alc_build_pcms */
2197};
2198
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002199static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002200 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 .channels_min = 2,
2202 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002203 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002205 .prepare = alc_alt_capture_pcm_prepare,
2206 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 },
2208};
2209
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002210static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 .substreams = 1,
2212 .channels_min = 2,
2213 .channels_max = 2,
2214 /* NID is set in alc_build_pcms */
2215 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002216 .open = alc_dig_playback_pcm_open,
2217 .close = alc_dig_playback_pcm_close,
2218 .prepare = alc_dig_playback_pcm_prepare,
2219 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 },
2221};
2222
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002223static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 .substreams = 1,
2225 .channels_min = 2,
2226 .channels_max = 2,
2227 /* NID is set in alc_build_pcms */
2228};
2229
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002230/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002231static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002232 .substreams = 0,
2233 .channels_min = 0,
2234 .channels_max = 0,
2235};
2236
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237static int alc_build_pcms(struct hda_codec *codec)
2238{
2239 struct alc_spec *spec = codec->spec;
2240 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002241 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002242 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 int i;
2244
2245 codec->num_pcms = 1;
2246 codec->pcm_info = info;
2247
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002248 if (spec->no_analog)
2249 goto skip_analog;
2250
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002251 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2252 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002254
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002255 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002256 p = spec->stream_analog_playback;
2257 if (!p)
2258 p = &alc_pcm_analog_playback;
2259 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002260 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002261 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2262 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002263 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2264 spec->autocfg.line_outs == 2)
2265 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2266 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002267 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002268 if (spec->adc_nids) {
2269 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002270 if (!p) {
2271 if (spec->dyn_adc_switch)
2272 p = &dyn_adc_pcm_analog_capture;
2273 else
2274 p = &alc_pcm_analog_capture;
2275 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002276 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002277 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Takashi Iwai4a471b72005-12-07 13:56:29 +01002280 if (spec->channel_mode) {
2281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2282 for (i = 0; i < spec->num_channel_mode; i++) {
2283 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2284 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 }
2287 }
2288
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002289 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002290 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002292 snprintf(spec->stream_name_digital,
2293 sizeof(spec->stream_name_digital),
2294 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002295 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002296 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002297 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002299 if (spec->dig_out_type)
2300 info->pcm_type = spec->dig_out_type;
2301 else
2302 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002303 if (spec->multiout.dig_out_nid) {
2304 p = spec->stream_digital_playback;
2305 if (!p)
2306 p = &alc_pcm_digital_playback;
2307 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2309 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002310 if (spec->dig_in_nid) {
2311 p = spec->stream_digital_capture;
2312 if (!p)
2313 p = &alc_pcm_digital_capture;
2314 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2316 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002317 /* FIXME: do we need this for all Realtek codec models? */
2318 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002321 if (spec->no_analog)
2322 return 0;
2323
Takashi Iwaie08a0072006-09-07 17:52:14 +02002324 /* If the use of more than one ADC is requested for the current
2325 * model, configure a second analog capture-only PCM.
2326 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002327 have_multi_adcs = (spec->num_adc_nids > 1) &&
2328 !spec->dyn_adc_switch && !spec->auto_mic &&
2329 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002330 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002331 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002332 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002333 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002334 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002335 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002336 p = spec->stream_analog_alt_playback;
2337 if (!p)
2338 p = &alc_pcm_analog_alt_playback;
2339 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002340 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2341 spec->alt_dac_nid;
2342 } else {
2343 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2344 alc_pcm_null_stream;
2345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2346 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002347 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002348 p = spec->stream_analog_alt_capture;
2349 if (!p)
2350 p = &alc_pcm_analog_alt_capture;
2351 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002352 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2353 spec->adc_nids[1];
2354 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2355 spec->num_adc_nids - 1;
2356 } else {
2357 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2358 alc_pcm_null_stream;
2359 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002360 }
2361 }
2362
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 return 0;
2364}
2365
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002366static inline void alc_shutup(struct hda_codec *codec)
2367{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002368 struct alc_spec *spec = codec->spec;
2369
2370 if (spec && spec->shutup)
2371 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002372 snd_hda_shutup_pins(codec);
2373}
2374
Takashi Iwai603c4012008-07-30 15:01:44 +02002375static void alc_free_kctls(struct hda_codec *codec)
2376{
2377 struct alc_spec *spec = codec->spec;
2378
2379 if (spec->kctls.list) {
2380 struct snd_kcontrol_new *kctl = spec->kctls.list;
2381 int i;
2382 for (i = 0; i < spec->kctls.used; i++)
2383 kfree(kctl[i].name);
2384 }
2385 snd_array_free(&spec->kctls);
2386}
2387
Takashi Iwai23c09b02011-08-19 09:05:35 +02002388static void alc_free_bind_ctls(struct hda_codec *codec)
2389{
2390 struct alc_spec *spec = codec->spec;
2391 if (spec->bind_ctls.list) {
2392 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2393 int i;
2394 for (i = 0; i < spec->bind_ctls.used; i++)
2395 kfree(ctl[i]);
2396 }
2397 snd_array_free(&spec->bind_ctls);
2398}
2399
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400static void alc_free(struct hda_codec *codec)
2401{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002402 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002403
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002404 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002405 return;
2406
Takashi Iwai603c4012008-07-30 15:01:44 +02002407 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002408 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002409 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002410 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002411 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002412 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413}
2414
Takashi Iwai83012a72012-08-24 18:38:08 +02002415#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002416static void alc_power_eapd(struct hda_codec *codec)
2417{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002418 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002419}
2420
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002421static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002422{
2423 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002424 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002425 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002426 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002427 return 0;
2428}
2429#endif
2430
Takashi Iwai2a439522011-07-26 09:52:50 +02002431#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002432static int alc_resume(struct hda_codec *codec)
2433{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002434 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002435 codec->patch_ops.init(codec);
2436 snd_hda_codec_resume_amp(codec);
2437 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002438 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002439 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002440 return 0;
2441}
Takashi Iwaie044c392008-10-27 16:56:24 +01002442#endif
2443
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444/*
2445 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002446static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 .build_controls = alc_build_controls,
2448 .build_pcms = alc_build_pcms,
2449 .init = alc_init,
2450 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002451 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002452#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002453 .resume = alc_resume,
2454#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002455#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002456 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002457 .check_power_status = alc_check_power_status,
2458#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002459 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460};
2461
David Henningsson29adc4b2012-09-25 11:31:00 +02002462
Kailang Yangc027ddc2010-03-19 11:33:06 +01002463/* replace the codec chip_name with the given string */
2464static int alc_codec_rename(struct hda_codec *codec, const char *name)
2465{
2466 kfree(codec->chip_name);
2467 codec->chip_name = kstrdup(name, GFP_KERNEL);
2468 if (!codec->chip_name) {
2469 alc_free(codec);
2470 return -ENOMEM;
2471 }
2472 return 0;
2473}
2474
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002475/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002476 * Rename codecs appropriately from COEF value
2477 */
2478struct alc_codec_rename_table {
2479 unsigned int vendor_id;
2480 unsigned short coef_mask;
2481 unsigned short coef_bits;
2482 const char *name;
2483};
2484
2485static struct alc_codec_rename_table rename_tbl[] = {
2486 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2487 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2488 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2489 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2490 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2491 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2492 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002493 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002494 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2495 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2496 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2497 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2498 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2499 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2500 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2501 { } /* terminator */
2502};
2503
2504static int alc_codec_rename_from_preset(struct hda_codec *codec)
2505{
2506 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002507
2508 for (p = rename_tbl; p->vendor_id; p++) {
2509 if (p->vendor_id != codec->vendor_id)
2510 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002511 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002512 return alc_codec_rename(codec, p->name);
2513 }
2514 return 0;
2515}
2516
2517/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002518 * Automatic parse of I/O pins from the BIOS configuration
2519 */
2520
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002521enum {
2522 ALC_CTL_WIDGET_VOL,
2523 ALC_CTL_WIDGET_MUTE,
2524 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002525 ALC_CTL_BIND_VOL,
2526 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002527};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002528static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002529 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2530 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002531 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002532 HDA_BIND_VOL(NULL, 0),
2533 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002534};
2535
2536/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002537static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002538 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002539{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002540 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002541
Takashi Iwai668d1e92012-11-29 14:10:17 +01002542 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002543 if (!knew)
2544 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002545 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002546 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002547 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002548 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002549 return 0;
2550}
2551
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002552static int add_control_with_pfx(struct alc_spec *spec, int type,
2553 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002554 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002555{
2556 char name[32];
2557 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002558 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002559}
2560
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002561#define add_pb_vol_ctrl(spec, type, pfx, val) \
2562 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2563#define add_pb_sw_ctrl(spec, type, pfx, val) \
2564 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2565#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2566 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2567#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2568 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002569
Takashi Iwai23c09b02011-08-19 09:05:35 +02002570static const char * const channel_name[4] = {
2571 "Front", "Surround", "CLFE", "Side"
2572};
2573
Takashi Iwai6843ca12011-06-24 11:03:58 +02002574static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2575 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002576{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002577 struct auto_pin_cfg *cfg = &spec->autocfg;
2578
Takashi Iwai6843ca12011-06-24 11:03:58 +02002579 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002580 if (cfg->line_outs == 1 && !spec->multi_ios &&
2581 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002582 return "Master";
2583
2584 switch (cfg->line_out_type) {
2585 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002586 if (cfg->line_outs == 1)
2587 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002588 if (cfg->line_outs == 2)
2589 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002590 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002591 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002592 /* for multi-io case, only the primary out */
2593 if (ch && spec->multi_ios)
2594 break;
2595 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002596 return "Headphone";
2597 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002598 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002599 return "PCM";
2600 break;
2601 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002602 if (ch >= ARRAY_SIZE(channel_name)) {
2603 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002604 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002605 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002606
2607 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002608}
2609
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002610static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2611 hda_nid_t to_nid, int with_aa_mix,
2612 struct nid_path *path);
2613
Takashi Iwai83012a72012-08-24 18:38:08 +02002614#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002615/* add the powersave loopback-list entry */
2616static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2617{
2618 struct hda_amp_list *list;
2619
2620 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2621 return;
2622 list = spec->loopback_list + spec->num_loopbacks;
2623 list->nid = mix;
2624 list->dir = HDA_INPUT;
2625 list->idx = idx;
2626 spec->num_loopbacks++;
2627 spec->loopback.amplist = spec->loopback_list;
2628}
2629#else
2630#define add_loopback_list(spec, mix, idx) /* NOP */
2631#endif
2632
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002633/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002634static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002635 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002636 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002637{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002638 struct alc_spec *spec = codec->spec;
2639 struct nid_path *path;
2640 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002641
Takashi Iwaibd32f782012-12-12 18:08:52 +01002642 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2643 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2644 return 0; /* no need for analog loopback */
2645
Takashi Iwaic9967f12012-12-14 16:39:22 +01002646 path = snd_array_new(&spec->paths);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002647 if (!path)
2648 return -ENOMEM;
2649 memset(path, 0, sizeof(*path));
2650 if (!parse_nid_path(codec, pin, mix_nid, 2, path))
2651 return -EINVAL;
2652
2653 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002654 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
2655 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002656 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002657 if (err < 0)
2658 return err;
2659 }
2660
2661 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
2662 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002663 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002664 if (err < 0)
2665 return err;
2666 }
2667
Takashi Iwai164f73e2012-02-21 11:27:09 +01002668 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002669 return 0;
2670}
2671
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002672static int new_capture_source(struct hda_codec *codec, int adc_idx,
2673 hda_nid_t pin, int idx, const char *label)
2674{
2675 struct alc_spec *spec = codec->spec;
2676 struct hda_input_mux *imux = &spec->private_imux[0];
2677 struct nid_path *path;
2678
Takashi Iwaic9967f12012-12-14 16:39:22 +01002679 path = snd_array_new(&spec->paths);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002680 if (!path)
2681 return -ENOMEM;
2682 memset(path, 0, sizeof(*path));
2683 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2684 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2685 pin, spec->adc_nids[adc_idx]);
2686 return -EINVAL;
2687 }
2688
2689 spec->imux_pins[imux->num_items] = pin;
2690 snd_hda_add_imux_item(imux, label, idx, NULL);
2691 return 0;
2692}
2693
Takashi Iwai05f5f472009-08-25 13:10:18 +02002694static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002695{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002696 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2697 return (pincap & AC_PINCAP_IN) != 0;
2698}
2699
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002700/* check whether the given two widgets can be connected */
2701static bool is_reachable_path(struct hda_codec *codec,
2702 hda_nid_t from_nid, hda_nid_t to_nid)
2703{
2704 if (!from_nid || !to_nid)
2705 return false;
2706 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2707}
2708
Takashi Iwai1d045db2011-07-07 18:23:21 +02002709/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002710static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002711{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002712 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002713 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002714 hda_nid_t *adc_nids = spec->private_adc_nids;
2715 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2716 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002717 int i, nums = 0;
2718
2719 nid = codec->start_nid;
2720 for (i = 0; i < codec->num_nodes; i++, nid++) {
2721 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002722 unsigned int caps = get_wcaps(codec, nid);
2723 int type = get_wcaps_type(caps);
2724
2725 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2726 continue;
2727 adc_nids[nums] = nid;
2728 cap_nids[nums] = nid;
2729 src = nid;
2730 for (;;) {
2731 int n;
2732 type = get_wcaps_type(get_wcaps(codec, src));
2733 if (type == AC_WID_PIN)
2734 break;
2735 if (type == AC_WID_AUD_SEL) {
2736 cap_nids[nums] = src;
2737 break;
2738 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002739 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002740 if (n > 1) {
2741 cap_nids[nums] = src;
2742 break;
2743 } else if (n != 1)
2744 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002745 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2746 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002747 }
2748 if (++nums >= max_nums)
2749 break;
2750 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002751 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002752 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002753 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002754 return nums;
2755}
2756
Takashi Iwai05f5f472009-08-25 13:10:18 +02002757/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002758static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002759{
2760 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002761 const struct auto_pin_cfg *cfg = &spec->autocfg;
2762 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002763 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002764 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002765 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002766 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002767
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002768 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002769 if (num_adcs < 0)
2770 return 0;
2771
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002772 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002773 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002774 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002775
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002776 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002777 if (!alc_is_input_pin(codec, pin))
2778 continue;
2779
David Henningsson5322bf22011-01-05 11:03:56 +01002780 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002781 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2782 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002783 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002784 type_idx++;
2785 else
2786 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002787 prev_label = label;
2788
Takashi Iwai05f5f472009-08-25 13:10:18 +02002789 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002790 if (is_reachable_path(codec, pin, mixer)) {
2791 err = new_analog_input(codec, pin,
2792 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002793 if (err < 0)
2794 return err;
2795 }
2796 }
2797
Takashi Iwaib7821702011-07-06 15:12:46 +02002798 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002799 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002800 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002801 if (idx >= 0) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002802 err = new_capture_source(codec, c, pin, idx, label);
2803 if (err < 0)
2804 return err;
Takashi Iwaib7821702011-07-06 15:12:46 +02002805 break;
2806 }
2807 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002808 }
Takashi Iwai21268962011-07-07 15:01:13 +02002809
2810 spec->num_mux_defs = 1;
2811 spec->input_mux = imux;
2812
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002813 return 0;
2814}
2815
Takashi Iwai24de1832011-11-07 17:13:39 +01002816/* create a shared input with the headphone out */
2817static int alc_auto_create_shared_input(struct hda_codec *codec)
2818{
2819 struct alc_spec *spec = codec->spec;
2820 struct auto_pin_cfg *cfg = &spec->autocfg;
2821 unsigned int defcfg;
2822 hda_nid_t nid;
2823
2824 /* only one internal input pin? */
2825 if (cfg->num_inputs != 1)
2826 return 0;
2827 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2828 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2829 return 0;
2830
2831 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2832 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2833 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2834 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2835 else
2836 return 0; /* both not available */
2837
2838 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2839 return 0; /* no input */
2840
2841 cfg->inputs[1].pin = nid;
2842 cfg->inputs[1].type = AUTO_PIN_MIC;
2843 cfg->num_inputs = 2;
2844 spec->shared_mic_hp = 1;
2845 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2846 return 0;
2847}
2848
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002849static int get_pin_type(int line_out_type)
2850{
2851 if (line_out_type == AUTO_PIN_HP_OUT)
2852 return PIN_HP;
2853 else
2854 return PIN_OUT;
2855}
2856
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002857static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002858{
2859 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002860 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002861 int i;
2862
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002863 for (i = 0; i < cfg->num_inputs; i++) {
2864 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002865 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002866 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002867 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002868 snd_hda_codec_write(codec, nid, 0,
2869 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002870 AMP_OUT_MUTE);
2871 }
2872 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002873
2874 /* mute all loopback inputs */
2875 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002876 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002877 for (i = 0; i < nums; i++)
2878 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2879 AC_VERB_SET_AMP_GAIN_MUTE,
2880 AMP_IN_MUTE(i));
2881 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002882}
2883
Takashi Iwai185d99f2012-02-16 18:39:45 +01002884static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2885{
2886 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002887 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002888
Takashi Iwaic9967f12012-12-14 16:39:22 +01002889 for (i = 0; i < spec->paths.used; i++) {
2890 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002891 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002892 return true;
2893 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002894 return false;
2895}
2896
Takashi Iwai463419d2012-12-05 14:17:37 +01002897/* look for an empty DAC slot */
2898static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2899{
2900 struct alc_spec *spec = codec->spec;
2901 int i;
2902
2903 for (i = 0; i < spec->num_all_dacs; i++) {
2904 hda_nid_t nid = spec->all_dacs[i];
2905 if (!nid || alc_is_dac_already_used(codec, nid))
2906 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002907 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002908 return nid;
2909 }
2910 return 0;
2911}
2912
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002913/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002914static bool __parse_nid_path(struct hda_codec *codec,
2915 hda_nid_t from_nid, hda_nid_t to_nid,
2916 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002917{
2918 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002919 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002920 int i, nums;
2921
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002922 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002923 if (!with_aa_mix)
2924 return false;
2925 with_aa_mix = 2; /* mark aa-mix is included */
2926 }
2927
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002928 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002929 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002930 if (conn[i] != from_nid) {
2931 /* special case: when from_nid is 0,
2932 * try to find an empty DAC
2933 */
2934 if (from_nid ||
2935 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2936 alc_is_dac_already_used(codec, conn[i]))
2937 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002938 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002939 /* aa-mix is requested but not included? */
2940 if (!(spec->mixer_nid && with_aa_mix == 1))
2941 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002942 }
2943 if (depth >= MAX_NID_PATH_DEPTH)
2944 return false;
2945 for (i = 0; i < nums; i++) {
2946 unsigned int type;
2947 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002948 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2949 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002950 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002951 if (__parse_nid_path(codec, from_nid, conn[i],
2952 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002953 goto found;
2954 }
2955 return false;
2956
2957 found:
2958 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002959 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002960 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002961 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002962 path->depth++;
2963 return true;
2964}
2965
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002966/* parse the widget path from the given nid to the target nid;
2967 * when @from_nid is 0, try to find an empty DAC;
2968 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2969 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2970 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002971 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002972static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2973 hda_nid_t to_nid, int with_aa_mix,
2974 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002975{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002976 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2977 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002978 path->depth++;
2979#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002980 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002981 path->depth, path->path[0], path->path[1],
2982 path->path[2], path->path[3], path->path[4]);
2983#endif
2984 return true;
2985 }
2986 return false;
2987}
2988
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002989static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2990{
Takashi Iwai140547e2012-02-16 17:23:46 +01002991 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002992 int i;
2993 hda_nid_t nid_found = 0;
2994
2995 for (i = 0; i < spec->num_all_dacs; i++) {
2996 hda_nid_t nid = spec->all_dacs[i];
2997 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01002998 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002999 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003000 if (nid_found)
3001 return 0;
3002 nid_found = nid;
3003 }
3004 }
3005 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003006}
3007
Takashi Iwaiba8111272012-12-06 18:06:23 +01003008static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003009{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003010 struct alc_spec *spec = codec->spec;
3011 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003012
Takashi Iwaic9967f12012-12-14 16:39:22 +01003013 for (i = 0; i < spec->paths.used; i++) {
3014 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003015 if (path->ctls[type] == val)
3016 return true;
3017 }
3018 return false;
3019}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003020
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003021/* badness definition */
3022enum {
3023 /* No primary DAC is found for the main output */
3024 BAD_NO_PRIMARY_DAC = 0x10000,
3025 /* No DAC is found for the extra output */
3026 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003027 /* No possible multi-ios */
3028 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003029 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003030 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003031 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003032 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003033 /* Primary DAC shared with main surrounds */
3034 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003035 /* Primary DAC shared with main CLFE */
3036 BAD_SHARED_CLFE = 0x10,
3037 /* Primary DAC shared with extra surrounds */
3038 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003039 /* Volume widget is shared */
3040 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003041};
3042
3043static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003044 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003045static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003046 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003047
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003048static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3049 hda_nid_t dac)
3050{
3051 struct alc_spec *spec = codec->spec;
3052 struct nid_path *path;
3053
Takashi Iwaic9967f12012-12-14 16:39:22 +01003054 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003055 if (!path)
3056 return false;
3057 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003058 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003059 return true;
3060 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01003061 spec->paths.used--;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003062 return false;
3063}
3064
Takashi Iwaiba8111272012-12-06 18:06:23 +01003065/* get the path pointing from the given dac to pin;
3066 * passing 0 to either @pin or @dac behaves as a wildcard
3067 */
3068static struct nid_path *get_out_path(struct hda_codec *codec, hda_nid_t pin,
3069 hda_nid_t dac)
3070{
3071 struct alc_spec *spec = codec->spec;
3072 int i;
3073
Takashi Iwaic9967f12012-12-14 16:39:22 +01003074 for (i = 0; i < spec->paths.used; i++) {
3075 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003076 if (path->depth <= 0)
3077 continue;
3078 if ((!dac || path->path[0] == dac) &&
3079 (!pin || path->path[path->depth - 1] == pin))
3080 return path;
3081 }
3082 return NULL;
3083}
3084
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003085/* look for widgets in the path between the given NIDs appropriate for
3086 * volume and mute controls, and assign the values to ctls[].
3087 *
3088 * When no appropriate widget is found in the path, the badness value
3089 * is incremented depending on the situation. The function returns the
3090 * total badness for both volume and mute controls.
3091 */
3092static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3093 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003094{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003095 struct nid_path *path = get_out_path(codec, pin, dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003096 hda_nid_t nid;
3097 unsigned int val;
3098 int badness = 0;
3099
Takashi Iwaiba8111272012-12-06 18:06:23 +01003100 if (!path)
3101 return BAD_SHARED_VOL * 2;
3102 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003103 if (nid) {
3104 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003105 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003106 badness += BAD_SHARED_VOL;
3107 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003108 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003109 } else
3110 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003111 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003112 if (nid) {
3113 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003114 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3115 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003116 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3117 else
3118 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003119 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003120 badness += BAD_SHARED_VOL;
3121 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003122 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003123 } else
3124 badness += BAD_SHARED_VOL;
3125 return badness;
3126}
3127
Takashi Iwaidc31b582012-02-17 17:27:53 +01003128struct badness_table {
3129 int no_primary_dac; /* no primary DAC */
3130 int no_dac; /* no secondary DACs */
3131 int shared_primary; /* primary DAC is shared with main output */
3132 int shared_surr; /* secondary DAC shared with main or primary */
3133 int shared_clfe; /* third DAC shared with main or primary */
3134 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3135};
3136
3137static struct badness_table main_out_badness = {
3138 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3139 .no_dac = BAD_NO_DAC,
3140 .shared_primary = BAD_NO_PRIMARY_DAC,
3141 .shared_surr = BAD_SHARED_SURROUND,
3142 .shared_clfe = BAD_SHARED_CLFE,
3143 .shared_surr_main = BAD_SHARED_SURROUND,
3144};
3145
3146static struct badness_table extra_out_badness = {
3147 .no_primary_dac = BAD_NO_DAC,
3148 .no_dac = BAD_NO_DAC,
3149 .shared_primary = BAD_NO_EXTRA_DAC,
3150 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3151 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3152 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3153};
3154
3155/* try to assign DACs to pins and return the resultant badness */
3156static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3157 const hda_nid_t *pins, hda_nid_t *dacs,
3158 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003159{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003160 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003161 struct auto_pin_cfg *cfg = &spec->autocfg;
3162 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003163 int badness = 0;
3164 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003165
Takashi Iwai185d99f2012-02-16 18:39:45 +01003166 if (!num_outs)
3167 return 0;
3168
Takashi Iwaidc31b582012-02-17 17:27:53 +01003169 for (i = 0; i < num_outs; i++) {
3170 hda_nid_t pin = pins[i];
3171 if (!dacs[i])
3172 dacs[i] = alc_auto_look_for_dac(codec, pin);
3173 if (!dacs[i] && !i) {
3174 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003175 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003176 dacs[0] = dacs[j];
3177 dacs[j] = 0;
3178 break;
3179 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003180 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003181 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003182 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003183 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003184 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003185 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003186 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003187 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003188 dac = spec->private_dac_nids[i];
3189 if (dac) {
3190 if (!i)
3191 badness += bad->shared_primary;
3192 else if (i == 1)
3193 badness += bad->shared_surr;
3194 else
3195 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003196 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003197 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003198 badness += bad->shared_surr_main;
3199 } else if (!i)
3200 badness += bad->no_primary_dac;
3201 else
3202 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003203 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003204 if (!add_new_out_path(codec, pin, dac))
3205 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003206 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003207 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003208 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003209
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003210 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003211}
3212
3213static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003214 hda_nid_t reference_pin,
3215 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003216
Takashi Iwai185d99f2012-02-16 18:39:45 +01003217static bool alc_map_singles(struct hda_codec *codec, int outs,
3218 const hda_nid_t *pins, hda_nid_t *dacs)
3219{
3220 int i;
3221 bool found = false;
3222 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003223 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003224 if (dacs[i])
3225 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003226 dac = get_dac_if_single(codec, pins[i]);
3227 if (!dac)
3228 continue;
3229 if (add_new_out_path(codec, pins[i], dac)) {
3230 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003231 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003232 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003233 }
3234 return found;
3235}
3236
Takashi Iwai7085ec12009-10-02 09:03:58 +02003237/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003238static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003239 bool fill_hardwired,
3240 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003241{
3242 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003243 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003244 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003245
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003246 /* set num_dacs once to full for alc_auto_look_for_dac() */
3247 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003248 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003249 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3250 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3251 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003252 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003253 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003254 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003255
3256 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003257 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003258 bool mapped;
3259 do {
3260 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003261 cfg->line_out_pins,
3262 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003263 mapped |= alc_map_singles(codec, cfg->hp_outs,
3264 cfg->hp_pins,
3265 spec->multiout.hp_out_nid);
3266 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3267 cfg->speaker_pins,
3268 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003269 if (fill_mio_first && cfg->line_outs == 1 &&
3270 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3271 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3272 if (!err)
3273 mapped = true;
3274 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003275 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003276 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003277
Takashi Iwaidc31b582012-02-17 17:27:53 +01003278 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3279 spec->private_dac_nids,
3280 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003281
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003282 /* re-count num_dacs and squash invalid entries */
3283 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003284 for (i = 0; i < cfg->line_outs; i++) {
3285 if (spec->private_dac_nids[i])
3286 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003287 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003288 memmove(spec->private_dac_nids + i,
3289 spec->private_dac_nids + i + 1,
3290 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003291 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3292 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003293 }
3294
Takashi Iwai276dd702012-02-17 16:17:03 +01003295 if (fill_mio_first &&
3296 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003297 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003298 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003299 if (err < 0)
3300 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003301 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003302 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003303
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003304 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003305 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3306 spec->multiout.hp_out_nid,
3307 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003308 if (err < 0)
3309 return err;
3310 badness += err;
3311 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003312 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003313 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3314 cfg->speaker_pins,
3315 spec->multiout.extra_out_nid,
3316 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003317 if (err < 0)
3318 return err;
3319 badness += err;
3320 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003321 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3322 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003323 if (err < 0)
3324 return err;
3325 badness += err;
3326 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003327 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3328 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003329 int offset = 0;
3330 if (cfg->line_outs >= 3)
3331 offset = 1;
3332 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3333 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003334 if (err < 0)
3335 return err;
3336 badness += err;
3337 }
3338
3339 if (spec->multi_ios == 2) {
3340 for (i = 0; i < 2; i++)
3341 spec->private_dac_nids[spec->multiout.num_dacs++] =
3342 spec->multi_io[i].dac;
3343 spec->ext_channel_count = 2;
3344 } else if (spec->multi_ios) {
3345 spec->multi_ios = 0;
3346 badness += BAD_MULTI_IO;
3347 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003348
3349 return badness;
3350}
3351
3352#define DEBUG_BADNESS
3353
3354#ifdef DEBUG_BADNESS
3355#define debug_badness snd_printdd
3356#else
3357#define debug_badness(...)
3358#endif
3359
3360static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3361{
3362 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3363 cfg->line_out_pins[0], cfg->line_out_pins[1],
3364 cfg->line_out_pins[2], cfg->line_out_pins[2],
3365 spec->multiout.dac_nids[0],
3366 spec->multiout.dac_nids[1],
3367 spec->multiout.dac_nids[2],
3368 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003369 if (spec->multi_ios > 0)
3370 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3371 spec->multi_ios,
3372 spec->multi_io[0].pin, spec->multi_io[1].pin,
3373 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003374 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3375 cfg->hp_pins[0], cfg->hp_pins[1],
3376 cfg->hp_pins[2], cfg->hp_pins[2],
3377 spec->multiout.hp_out_nid[0],
3378 spec->multiout.hp_out_nid[1],
3379 spec->multiout.hp_out_nid[2],
3380 spec->multiout.hp_out_nid[3]);
3381 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3382 cfg->speaker_pins[0], cfg->speaker_pins[1],
3383 cfg->speaker_pins[2], cfg->speaker_pins[3],
3384 spec->multiout.extra_out_nid[0],
3385 spec->multiout.extra_out_nid[1],
3386 spec->multiout.extra_out_nid[2],
3387 spec->multiout.extra_out_nid[3]);
3388}
3389
Takashi Iwai463419d2012-12-05 14:17:37 +01003390/* find all available DACs of the codec */
3391static void alc_fill_all_nids(struct hda_codec *codec)
3392{
3393 struct alc_spec *spec = codec->spec;
3394 int i;
3395 hda_nid_t nid = codec->start_nid;
3396
3397 spec->num_all_dacs = 0;
3398 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3399 for (i = 0; i < codec->num_nodes; i++, nid++) {
3400 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3401 continue;
3402 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3403 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3404 break;
3405 }
3406 spec->all_dacs[spec->num_all_dacs++] = nid;
3407 }
3408}
3409
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003410static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3411{
3412 struct alc_spec *spec = codec->spec;
3413 struct auto_pin_cfg *cfg = &spec->autocfg;
3414 struct auto_pin_cfg *best_cfg;
3415 int best_badness = INT_MAX;
3416 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003417 bool fill_hardwired = true, fill_mio_first = true;
3418 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003419 bool hp_spk_swapped = false;
3420
Takashi Iwai463419d2012-12-05 14:17:37 +01003421 alc_fill_all_nids(codec);
3422
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003423 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3424 if (!best_cfg)
3425 return -ENOMEM;
3426 *best_cfg = *cfg;
3427
3428 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003429 badness = fill_and_eval_dacs(codec, fill_hardwired,
3430 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003431 if (badness < 0) {
3432 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003433 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003434 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003435 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3436 cfg->line_out_type, fill_hardwired, fill_mio_first,
3437 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003438 debug_show_configs(spec, cfg);
3439 if (badness < best_badness) {
3440 best_badness = badness;
3441 *best_cfg = *cfg;
3442 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003443 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003444 }
3445 if (!badness)
3446 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003447 fill_mio_first = !fill_mio_first;
3448 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003449 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003450 fill_hardwired = !fill_hardwired;
3451 if (!fill_hardwired)
3452 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003453 if (hp_spk_swapped)
3454 break;
3455 hp_spk_swapped = true;
3456 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003457 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3458 cfg->hp_outs = cfg->line_outs;
3459 memcpy(cfg->hp_pins, cfg->line_out_pins,
3460 sizeof(cfg->hp_pins));
3461 cfg->line_outs = cfg->speaker_outs;
3462 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3463 sizeof(cfg->speaker_pins));
3464 cfg->speaker_outs = 0;
3465 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3466 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003467 fill_hardwired = true;
3468 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003469 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003470 if (cfg->hp_outs > 0 &&
3471 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3472 cfg->speaker_outs = cfg->line_outs;
3473 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3474 sizeof(cfg->speaker_pins));
3475 cfg->line_outs = cfg->hp_outs;
3476 memcpy(cfg->line_out_pins, cfg->hp_pins,
3477 sizeof(cfg->hp_pins));
3478 cfg->hp_outs = 0;
3479 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3480 cfg->line_out_type = AUTO_PIN_HP_OUT;
3481 fill_hardwired = true;
3482 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003483 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003484 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003485 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003486
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003487 if (badness) {
3488 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003489 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003490 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003491 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3492 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003493 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003494
Takashi Iwaiba8111272012-12-06 18:06:23 +01003495 if (cfg->line_out_pins[0]) {
3496 struct nid_path *path = get_out_path(codec,
3497 cfg->line_out_pins[0],
3498 spec->multiout.dac_nids[0]);
3499 if (path)
3500 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3501 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003502
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003503 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003504 return 0;
3505}
3506
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003507/* replace the channels in the composed amp value with the given number */
3508static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3509{
3510 val &= ~(0x3U << 16);
3511 val |= chs << 16;
3512 return val;
3513}
3514
Takashi Iwai343a04b2011-07-06 14:28:39 +02003515static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003516 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003517 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003518 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003519{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003520 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003521 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003522 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003523 val = path->ctls[NID_PATH_VOL_CTL];
3524 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003525 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003526 val = amp_val_replace_channels(val, chs);
3527 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3528}
3529
3530/* return the channel bits suitable for the given path->ctls[] */
3531static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3532 int type)
3533{
3534 int chs = 1; /* mono (left only) */
3535 if (path) {
3536 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3537 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3538 chs = 3; /* stereo */
3539 }
3540 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003541}
3542
Takashi Iwaie29d3772011-11-14 17:13:23 +01003543static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3544 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003545 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003546{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003547 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3548 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003549}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003550
3551/* create a mute-switch for the given mixer widget;
3552 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3553 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003554static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003555 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003556 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003557 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003558{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003559 unsigned int val;
3560 int type = ALC_CTL_WIDGET_MUTE;
3561
3562 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003563 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003564 val = path->ctls[NID_PATH_MUTE_CTL];
3565 if (!val)
3566 return 0;
3567 val = amp_val_replace_channels(val, chs);
3568 if (get_amp_direction_(val) == HDA_INPUT) {
3569 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003570 int nums = snd_hda_get_num_conns(codec, nid);
3571 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003572 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003573 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003574 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003575 }
3576 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003577}
3578
Takashi Iwaie29d3772011-11-14 17:13:23 +01003579static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003580 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003581{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003582 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3583 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003584}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003585
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003586static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003587 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003588{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003589 int i;
3590
3591 for (i = path->depth - 1; i >= 0; i--) {
3592 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3593 return path->path[i];
3594 if (i != path->depth - 1 && i != 0 &&
3595 nid_has_mute(codec, path->path[i], HDA_INPUT))
3596 return path->path[i];
3597 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003598 return 0;
3599}
3600
3601static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003602 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003603{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003604 int i;
3605
3606 for (i = path->depth - 1; i >= 0; i--) {
3607 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3608 return path->path[i];
3609 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003610 return 0;
3611}
3612
Takashi Iwai7085ec12009-10-02 09:03:58 +02003613/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003614static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003615 const struct auto_pin_cfg *cfg)
3616{
3617 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003618 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003619
Takashi Iwaice764ab2011-04-27 16:35:23 +02003620 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003621 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003622 noutputs += spec->multi_ios;
3623
3624 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003625 const char *name;
3626 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003627 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003628 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003629
3630 dac = spec->multiout.dac_nids[i];
3631 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003632 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003633 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003634 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003635 index = 0;
3636 name = channel_name[i];
3637 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003638 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003639 name = alc_get_line_out_pfx(spec, i, true, &index);
3640 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003641
Takashi Iwaiba8111272012-12-06 18:06:23 +01003642 path = get_out_path(codec, pin, dac);
3643 if (!path)
3644 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003645 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003646 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003647 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003648 if (err < 0)
3649 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003650 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003651 if (err < 0)
3652 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003653 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003654 if (err < 0)
3655 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003656 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003657 if (err < 0)
3658 return err;
3659 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003660 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003661 if (err < 0)
3662 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003663 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003664 if (err < 0)
3665 return err;
3666 }
3667 }
3668 return 0;
3669}
3670
Takashi Iwai343a04b2011-07-06 14:28:39 +02003671static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003672 hda_nid_t dac, const char *pfx,
3673 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003674{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003675 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003676 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003677
Takashi Iwaiba8111272012-12-06 18:06:23 +01003678 path = get_out_path(codec, pin, dac);
3679 if (!path)
3680 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003681 /* bind volume control will be created in the case of dac = 0 */
3682 if (dac) {
3683 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3684 if (err < 0)
3685 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003686 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003687 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003688 if (err < 0)
3689 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003690 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003691}
3692
Takashi Iwai23c09b02011-08-19 09:05:35 +02003693static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3694 unsigned int nums,
3695 struct hda_ctl_ops *ops)
3696{
3697 struct alc_spec *spec = codec->spec;
3698 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003699 ctlp = snd_array_new(&spec->bind_ctls);
3700 if (!ctlp)
3701 return NULL;
3702 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3703 *ctlp = ctl;
3704 if (ctl)
3705 ctl->ops = ops;
3706 return ctl;
3707}
3708
3709/* add playback controls for speaker and HP outputs */
3710static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3711 const hda_nid_t *pins,
3712 const hda_nid_t *dacs,
3713 const char *pfx)
3714{
3715 struct alc_spec *spec = codec->spec;
3716 struct hda_bind_ctls *ctl;
3717 char name[32];
3718 int i, n, err;
3719
3720 if (!num_pins || !pins[0])
3721 return 0;
3722
Takashi Iwai527e4d72011-10-27 16:33:27 +02003723 if (num_pins == 1) {
3724 hda_nid_t dac = *dacs;
3725 if (!dac)
3726 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003727 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003728 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003729
Takashi Iwai23c09b02011-08-19 09:05:35 +02003730 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003731 hda_nid_t dac;
3732 if (dacs[num_pins - 1])
3733 dac = dacs[i]; /* with individual volumes */
3734 else
3735 dac = 0;
3736 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3737 err = alc_auto_create_extra_out(codec, pins[i], dac,
3738 "Bass Speaker", 0);
3739 } else if (num_pins >= 3) {
3740 snprintf(name, sizeof(name), "%s %s",
3741 pfx, channel_name[i]);
3742 err = alc_auto_create_extra_out(codec, pins[i], dac,
3743 name, 0);
3744 } else {
3745 err = alc_auto_create_extra_out(codec, pins[i], dac,
3746 pfx, i);
3747 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003748 if (err < 0)
3749 return err;
3750 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003751 if (dacs[num_pins - 1])
3752 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003753
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003754 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003755 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3756 if (!ctl)
3757 return -ENOMEM;
3758 n = 0;
3759 for (i = 0; i < num_pins; i++) {
3760 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003761 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003762 if (!pins[i] || !dacs[i])
3763 continue;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003764 path = get_out_path(codec, pins[i], dacs[i]);
3765 if (!path)
3766 continue;
3767 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003768 if (vol)
3769 ctl->values[n++] =
3770 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3771 }
3772 if (n) {
3773 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3774 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3775 if (err < 0)
3776 return err;
3777 }
3778 return 0;
3779}
3780
Takashi Iwai343a04b2011-07-06 14:28:39 +02003781static int alc_auto_create_hp_out(struct hda_codec *codec)
3782{
3783 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003784 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3785 spec->autocfg.hp_pins,
3786 spec->multiout.hp_out_nid,
3787 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003788}
3789
3790static int alc_auto_create_speaker_out(struct hda_codec *codec)
3791{
3792 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003793 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3794 spec->autocfg.speaker_pins,
3795 spec->multiout.extra_out_nid,
3796 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003797}
3798
Takashi Iwai130e5f02012-12-14 16:09:29 +01003799/* check whether a control with the given (nid, dir, idx) was assigned */
3800static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3801 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003802{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003803 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003804 int i, type;
3805
3806 for (i = 0; i < spec->paths.used; i++) {
3807 struct nid_path *p = snd_array_elem(&spec->paths, i);
3808 if (p->depth <= 0)
3809 continue;
3810 for (type = 0; type < 2; type++) {
3811 unsigned int val = p->ctls[type];
3812 if (get_amp_nid_(val) == nid &&
3813 get_amp_direction_(val) == dir &&
3814 get_amp_index_(val) == idx)
3815 return true;
3816 }
3817 }
3818 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003819}
3820
3821/* can have the amp-in capability? */
3822static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3823{
3824 hda_nid_t nid = path->path[idx];
3825 unsigned int caps = get_wcaps(codec, nid);
3826 unsigned int type = get_wcaps_type(caps);
3827
3828 if (!(caps & AC_WCAP_IN_AMP))
3829 return false;
3830 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3831 return false;
3832 return true;
3833}
3834
3835/* can have the amp-out capability? */
3836static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3837{
3838 hda_nid_t nid = path->path[idx];
3839 unsigned int caps = get_wcaps(codec, nid);
3840 unsigned int type = get_wcaps_type(caps);
3841
3842 if (!(caps & AC_WCAP_OUT_AMP))
3843 return false;
3844 if (type == AC_WID_PIN && !idx) /* only for output pins */
3845 return false;
3846 return true;
3847}
3848
Takashi Iwaic9967f12012-12-14 16:39:22 +01003849/* check whether the given (nid,dir,idx) is active */
3850static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3851 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003852{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003853 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003854 int i, n;
3855
Takashi Iwaic9967f12012-12-14 16:39:22 +01003856 for (n = 0; n < spec->paths.used; n++) {
3857 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003858 if (!path->active)
3859 continue;
3860 for (i = 0; i < path->depth; i++) {
3861 if (path->path[i] == nid) {
3862 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3863 return true;
3864 break;
3865 }
3866 }
3867 }
3868 return false;
3869}
3870
Takashi Iwai130e5f02012-12-14 16:09:29 +01003871/* get the default amp value for the target state */
3872static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3873 int dir, bool enable)
3874{
3875 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003876 unsigned int val = 0;
3877
3878 caps = query_amp_caps(codec, nid, dir);
3879 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003880 /* set to 0dB */
3881 if (enable)
3882 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003883 }
3884 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003885 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003886 val |= HDA_AMP_MUTE;
3887 }
3888 return val;
3889}
3890
Takashi Iwai130e5f02012-12-14 16:09:29 +01003891/* initialize the amp value (only at the first time) */
3892static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3893{
3894 int val = get_amp_val_to_activate(codec, nid, dir, false);
3895 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3896}
3897
3898static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3899 int idx, bool enable)
3900{
3901 int val;
3902 if (is_ctl_associated(codec, nid, dir, idx) ||
3903 is_active_nid(codec, nid, dir, idx))
3904 return;
3905 val = get_amp_val_to_activate(codec, nid, dir, enable);
3906 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3907}
3908
3909static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3910 int i, bool enable)
3911{
3912 hda_nid_t nid = path->path[i];
3913 init_amp(codec, nid, HDA_OUTPUT, 0);
3914 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3915}
3916
3917static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
3918 int i, bool enable)
3919{
3920 struct alc_spec *spec = codec->spec;
3921 hda_nid_t conn[16];
3922 int n, nums;
3923 hda_nid_t nid = path->path[i];
3924
3925 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
3926 for (n = 0; n < nums; n++)
3927 init_amp(codec, nid, HDA_INPUT, n);
3928
3929 if (is_ctl_associated(codec, nid, HDA_INPUT, path->idx[i]))
3930 return;
3931
3932 /* here is a little bit tricky in comparison with activate_amp_out();
3933 * when aa-mixer is available, we need to enable the path as well
3934 */
3935 for (n = 0; n < nums; n++) {
3936 if (n != path->idx[i] && conn[n] != spec->mixer_nid)
3937 continue;
3938 activate_amp(codec, nid, HDA_INPUT, n, enable);
3939 }
3940}
3941
3942static void activate_path(struct hda_codec *codec, struct nid_path *path,
3943 bool enable)
3944{
3945 int i;
3946
3947 if (path->active == enable)
3948 return;
3949
3950 if (!enable)
3951 path->active = false;
3952
3953 for (i = path->depth - 1; i >= 0; i--) {
3954 if (path->multi[i])
3955 snd_hda_codec_write_cache(codec, path->path[i], 0,
3956 AC_VERB_SET_CONNECT_SEL,
3957 path->idx[i]);
3958 if (has_amp_in(codec, path, i))
3959 activate_amp_in(codec, path, i, enable);
3960 if (has_amp_out(codec, path, i))
3961 activate_amp_out(codec, path, i, enable);
3962 }
3963
3964 if (enable)
3965 path->active = true;
3966}
3967
Takashi Iwai78e635c2012-12-10 17:07:16 +01003968/* configure the path from the given dac to the pin as the proper output */
3969static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3970 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003971 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003972{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003973 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003974
Takashi Iwai130e5f02012-12-14 16:09:29 +01003975 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003976 path = get_out_path(codec, pin, dac);
3977 if (!path)
3978 return;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003979 activate_path(codec, path, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003980}
3981
Takashi Iwai343a04b2011-07-06 14:28:39 +02003982static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003983{
3984 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003985 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003986 int i;
3987
3988 for (i = 0; i <= HDA_SIDE; i++) {
3989 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3990 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003991 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003992 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003993
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003994 }
3995}
3996
Takashi Iwai343a04b2011-07-06 14:28:39 +02003997static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003998{
3999 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004000 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004001 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004002
David Henningsson636030e2011-10-12 19:26:03 +02004003 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004004 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4005 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02004006 pin = spec->autocfg.hp_pins[i];
4007 if (!pin)
4008 break;
4009 dac = spec->multiout.hp_out_nid[i];
4010 if (!dac) {
4011 if (i > 0 && spec->multiout.hp_out_nid[0])
4012 dac = spec->multiout.hp_out_nid[0];
4013 else
4014 dac = spec->multiout.dac_nids[0];
4015 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004016 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004017 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02004018 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004019 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4020 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004021 pin = spec->autocfg.speaker_pins[i];
4022 if (!pin)
4023 break;
4024 dac = spec->multiout.extra_out_nid[i];
4025 if (!dac) {
4026 if (i > 0 && spec->multiout.extra_out_nid[0])
4027 dac = spec->multiout.extra_out_nid[0];
4028 else
4029 dac = spec->multiout.dac_nids[0];
4030 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004031 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004032 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004033}
4034
Takashi Iwai276dd702012-02-17 16:17:03 +01004035/* check whether the given pin can be a multi-io pin */
4036static bool can_be_multiio_pin(struct hda_codec *codec,
4037 unsigned int location, hda_nid_t nid)
4038{
4039 unsigned int defcfg, caps;
4040
4041 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4042 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4043 return false;
4044 if (location && get_defcfg_location(defcfg) != location)
4045 return false;
4046 caps = snd_hda_query_pin_caps(codec, nid);
4047 if (!(caps & AC_PINCAP_OUT))
4048 return false;
4049 return true;
4050}
4051
Takashi Iwaice764ab2011-04-27 16:35:23 +02004052/*
4053 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004054 *
4055 * When hardwired is set, try to fill ony hardwired pins, and returns
4056 * zero if any pins are filled, non-zero if nothing found.
4057 * When hardwired is off, try to fill possible input pins, and returns
4058 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004059 */
4060static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004061 hda_nid_t reference_pin,
4062 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004063{
4064 struct alc_spec *spec = codec->spec;
4065 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004066 int type, i, j, dacs, num_pins, old_pins;
4067 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4068 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004069 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004070
Takashi Iwai276dd702012-02-17 16:17:03 +01004071 old_pins = spec->multi_ios;
4072 if (old_pins >= 2)
4073 goto end_fill;
4074
4075 num_pins = 0;
4076 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4077 for (i = 0; i < cfg->num_inputs; i++) {
4078 if (cfg->inputs[i].type != type)
4079 continue;
4080 if (can_be_multiio_pin(codec, location,
4081 cfg->inputs[i].pin))
4082 num_pins++;
4083 }
4084 }
4085 if (num_pins < 2)
4086 goto end_fill;
4087
Takashi Iwai07b18f62011-11-10 15:42:54 +01004088 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004089 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4090 for (i = 0; i < cfg->num_inputs; i++) {
4091 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004092 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004093
Takashi Iwaice764ab2011-04-27 16:35:23 +02004094 if (cfg->inputs[i].type != type)
4095 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004096 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004097 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004098 for (j = 0; j < spec->multi_ios; j++) {
4099 if (nid == spec->multi_io[j].pin)
4100 break;
4101 }
4102 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004103 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004104
4105 if (offset && offset + spec->multi_ios < dacs) {
4106 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004107 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004108 dac = 0;
4109 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004110 if (hardwired)
4111 dac = get_dac_if_single(codec, nid);
4112 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01004113 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004114 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004115 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004116 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004117 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004118 if (!add_new_out_path(codec, nid, dac)) {
4119 badness++;
4120 continue;
4121 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004122 spec->multi_io[spec->multi_ios].pin = nid;
4123 spec->multi_io[spec->multi_ios].dac = dac;
4124 spec->multi_ios++;
4125 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004126 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004127 }
4128 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004129 end_fill:
4130 if (badness)
4131 badness = BAD_MULTI_IO;
4132 if (old_pins == spec->multi_ios) {
4133 if (hardwired)
4134 return 1; /* nothing found */
4135 else
4136 return badness; /* no badness if nothing found */
4137 }
4138 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004139 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004140 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004141 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004142 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004143 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004144
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004145 /* assign volume and mute controls */
4146 for (i = old_pins; i < spec->multi_ios; i++)
4147 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4148 spec->multi_io[i].dac);
4149
4150 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004151}
4152
4153static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4154 struct snd_ctl_elem_info *uinfo)
4155{
4156 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4157 struct alc_spec *spec = codec->spec;
4158
4159 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4160 uinfo->count = 1;
4161 uinfo->value.enumerated.items = spec->multi_ios + 1;
4162 if (uinfo->value.enumerated.item > spec->multi_ios)
4163 uinfo->value.enumerated.item = spec->multi_ios;
4164 sprintf(uinfo->value.enumerated.name, "%dch",
4165 (uinfo->value.enumerated.item + 1) * 2);
4166 return 0;
4167}
4168
4169static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4170 struct snd_ctl_elem_value *ucontrol)
4171{
4172 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4173 struct alc_spec *spec = codec->spec;
4174 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4175 return 0;
4176}
4177
4178static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4179{
4180 struct alc_spec *spec = codec->spec;
4181 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004182 struct nid_path *path;
4183
4184 path = get_out_path(codec, nid, spec->multi_io[idx].dac);
4185 if (!path)
4186 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004187
4188 if (!spec->multi_io[idx].ctl_in)
4189 spec->multi_io[idx].ctl_in =
Takashi Iwai130e5f02012-12-14 16:09:29 +01004190 snd_hda_codec_update_cache(codec, nid, 0,
Takashi Iwaice764ab2011-04-27 16:35:23 +02004191 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004192
Takashi Iwaice764ab2011-04-27 16:35:23 +02004193 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004194 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004195 activate_path(codec, path, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004196 } else {
Takashi Iwai130e5f02012-12-14 16:09:29 +01004197 activate_path(codec, path, false);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004198 snd_hda_set_pin_ctl_cache(codec, nid,
4199 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004200 }
4201 return 0;
4202}
4203
4204static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4205 struct snd_ctl_elem_value *ucontrol)
4206{
4207 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4208 struct alc_spec *spec = codec->spec;
4209 int i, ch;
4210
4211 ch = ucontrol->value.enumerated.item[0];
4212 if (ch < 0 || ch > spec->multi_ios)
4213 return -EINVAL;
4214 if (ch == (spec->ext_channel_count - 1) / 2)
4215 return 0;
4216 spec->ext_channel_count = (ch + 1) * 2;
4217 for (i = 0; i < spec->multi_ios; i++)
4218 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004219 spec->multiout.max_channels = max(spec->ext_channel_count,
4220 spec->const_channel_count);
4221 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004222 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004223 return 1;
4224}
4225
Takashi Iwaia9111322011-05-02 11:30:18 +02004226static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004227 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4228 .name = "Channel Mode",
4229 .info = alc_auto_ch_mode_info,
4230 .get = alc_auto_ch_mode_get,
4231 .put = alc_auto_ch_mode_put,
4232};
4233
Takashi Iwai23c09b02011-08-19 09:05:35 +02004234static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004235{
4236 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004237
Takashi Iwaic2674682011-08-24 17:57:44 +02004238 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004239 if (!alc_kcontrol_new(spec, "Channel Mode",
4240 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004241 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004242 }
4243 return 0;
4244}
4245
Takashi Iwai1d045db2011-07-07 18:23:21 +02004246/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4247 * active input pins
4248 */
4249static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4250{
4251 struct alc_spec *spec = codec->spec;
4252 const struct hda_input_mux *imux;
4253 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4254 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4255 int i, n, nums;
4256
4257 imux = spec->input_mux;
4258 if (!imux)
4259 return;
4260 if (spec->dyn_adc_switch)
4261 return;
4262
Takashi Iwai26acaf02012-03-22 14:36:50 +01004263 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004264 nums = 0;
4265 for (n = 0; n < spec->num_adc_nids; n++) {
4266 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004267 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004268 for (i = 0; i < imux->num_items; i++) {
4269 hda_nid_t pin = spec->imux_pins[i];
4270 if (pin) {
4271 if (get_connection_index(codec, cap, pin) < 0)
4272 break;
4273 } else if (num_conns <= imux->items[i].index)
4274 break;
4275 }
4276 if (i >= imux->num_items) {
4277 adc_nids[nums] = spec->private_adc_nids[n];
4278 capsrc_nids[nums++] = cap;
4279 }
4280 }
4281 if (!nums) {
4282 /* check whether ADC-switch is possible */
4283 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004284 if (spec->shared_mic_hp) {
4285 spec->shared_mic_hp = 0;
4286 spec->private_imux[0].num_items = 1;
4287 goto again;
4288 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004289 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4290 " using fallback 0x%x\n",
4291 codec->chip_name, spec->private_adc_nids[0]);
4292 spec->num_adc_nids = 1;
4293 spec->auto_mic = 0;
4294 return;
4295 }
4296 } else if (nums != spec->num_adc_nids) {
4297 memcpy(spec->private_adc_nids, adc_nids,
4298 nums * sizeof(hda_nid_t));
4299 memcpy(spec->private_capsrc_nids, capsrc_nids,
4300 nums * sizeof(hda_nid_t));
4301 spec->num_adc_nids = nums;
4302 }
4303
4304 if (spec->auto_mic)
4305 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004306 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004307 spec->num_adc_nids = 1; /* reduce to a single ADC */
4308}
4309
4310/*
4311 * initialize ADC paths
4312 */
4313static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4314{
4315 struct alc_spec *spec = codec->spec;
4316 hda_nid_t nid;
4317
4318 nid = spec->adc_nids[adc_idx];
4319 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004320 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004321 snd_hda_codec_write(codec, nid, 0,
4322 AC_VERB_SET_AMP_GAIN_MUTE,
4323 AMP_IN_MUTE(0));
4324 return;
4325 }
4326 if (!spec->capsrc_nids)
4327 return;
4328 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004329 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004330 snd_hda_codec_write(codec, nid, 0,
4331 AC_VERB_SET_AMP_GAIN_MUTE,
4332 AMP_OUT_MUTE);
4333}
4334
4335static void alc_auto_init_input_src(struct hda_codec *codec)
4336{
4337 struct alc_spec *spec = codec->spec;
4338 int c, nums;
4339
4340 for (c = 0; c < spec->num_adc_nids; c++)
4341 alc_auto_init_adc(codec, c);
4342 if (spec->dyn_adc_switch)
4343 nums = 1;
4344 else
4345 nums = spec->num_adc_nids;
4346 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004347 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004348}
4349
4350/* add mic boosts if needed */
4351static int alc_auto_add_mic_boost(struct hda_codec *codec)
4352{
4353 struct alc_spec *spec = codec->spec;
4354 struct auto_pin_cfg *cfg = &spec->autocfg;
4355 int i, err;
4356 int type_idx = 0;
4357 hda_nid_t nid;
4358 const char *prev_label = NULL;
4359
4360 for (i = 0; i < cfg->num_inputs; i++) {
4361 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4362 break;
4363 nid = cfg->inputs[i].pin;
4364 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4365 const char *label;
4366 char boost_label[32];
4367
4368 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004369 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4370 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004371 if (prev_label && !strcmp(label, prev_label))
4372 type_idx++;
4373 else
4374 type_idx = 0;
4375 prev_label = label;
4376
4377 snprintf(boost_label, sizeof(boost_label),
4378 "%s Boost Volume", label);
4379 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4380 boost_label, type_idx,
4381 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4382 if (err < 0)
4383 return err;
4384 }
4385 }
4386 return 0;
4387}
4388
4389/* select or unmute the given capsrc route */
4390static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4391 int idx)
4392{
4393 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4394 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4395 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004396 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004397 snd_hda_codec_write_cache(codec, cap, 0,
4398 AC_VERB_SET_CONNECT_SEL, idx);
4399 }
4400}
4401
4402/* set the default connection to that pin */
4403static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4404{
4405 struct alc_spec *spec = codec->spec;
4406 int i;
4407
4408 if (!pin)
4409 return 0;
4410 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004411 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004412 int idx;
4413
4414 idx = get_connection_index(codec, cap, pin);
4415 if (idx < 0)
4416 continue;
4417 select_or_unmute_capsrc(codec, cap, idx);
4418 return i; /* return the found index */
4419 }
4420 return -1; /* not found */
4421}
4422
4423/* initialize some special cases for input sources */
4424static void alc_init_special_input_src(struct hda_codec *codec)
4425{
4426 struct alc_spec *spec = codec->spec;
4427 int i;
4428
4429 for (i = 0; i < spec->autocfg.num_inputs; i++)
4430 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4431}
4432
4433/* assign appropriate capture mixers */
4434static void set_capture_mixer(struct hda_codec *codec)
4435{
4436 struct alc_spec *spec = codec->spec;
4437 static const struct snd_kcontrol_new *caps[2][3] = {
4438 { alc_capture_mixer_nosrc1,
4439 alc_capture_mixer_nosrc2,
4440 alc_capture_mixer_nosrc3 },
4441 { alc_capture_mixer1,
4442 alc_capture_mixer2,
4443 alc_capture_mixer3 },
4444 };
4445
4446 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004447 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004448 if (!spec->capsrc_nids)
4449 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004450 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004451 return; /* no volume in capsrc, too */
4452 spec->vol_in_capsrc = 1;
4453 }
4454
4455 if (spec->num_adc_nids > 0) {
4456 int mux = 0;
4457 int num_adcs = 0;
4458
4459 if (spec->input_mux && spec->input_mux->num_items > 1)
4460 mux = 1;
4461 if (spec->auto_mic) {
4462 num_adcs = 1;
4463 mux = 0;
4464 } else if (spec->dyn_adc_switch)
4465 num_adcs = 1;
4466 if (!num_adcs) {
4467 if (spec->num_adc_nids > 3)
4468 spec->num_adc_nids = 3;
4469 else if (!spec->num_adc_nids)
4470 return;
4471 num_adcs = spec->num_adc_nids;
4472 }
4473 spec->cap_mixer = caps[mux][num_adcs - 1];
4474 }
4475}
4476
4477/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004478 * standard auto-parser initializations
4479 */
4480static void alc_auto_init_std(struct hda_codec *codec)
4481{
Takashi Iwaie4770622011-07-08 11:11:35 +02004482 alc_auto_init_multi_out(codec);
4483 alc_auto_init_extra_out(codec);
4484 alc_auto_init_analog_input(codec);
4485 alc_auto_init_input_src(codec);
4486 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004487 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004488}
4489
4490/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004491 * Digital-beep handlers
4492 */
4493#ifdef CONFIG_SND_HDA_INPUT_BEEP
4494#define set_beep_amp(spec, nid, idx, dir) \
4495 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4496
4497static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004498 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004499 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4500 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4501 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4502 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004503 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004504 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4505 {}
4506};
4507
4508static inline int has_cdefine_beep(struct hda_codec *codec)
4509{
4510 struct alc_spec *spec = codec->spec;
4511 const struct snd_pci_quirk *q;
4512 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4513 if (q)
4514 return q->value;
4515 return spec->cdefine.enable_pcbeep;
4516}
4517#else
4518#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4519#define has_cdefine_beep(codec) 0
4520#endif
4521
4522/* parse the BIOS configuration and set up the alc_spec */
4523/* return 1 if successful, 0 if the proper config is not found,
4524 * or a negative error code
4525 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004526static int alc_parse_auto_config(struct hda_codec *codec,
4527 const hda_nid_t *ignore_nids,
4528 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004529{
4530 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004531 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004532 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004533
Takashi Iwai53c334a2011-08-23 18:27:14 +02004534 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4535 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004536 if (err < 0)
4537 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004538 if (!cfg->line_outs) {
4539 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004540 spec->multiout.max_channels = 2;
4541 spec->no_analog = 1;
4542 goto dig_only;
4543 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004544 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004545 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004546
Takashi Iwaie427c232012-07-29 10:04:08 +02004547 if (!spec->no_primary_hp &&
4548 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004549 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004550 /* use HP as primary out */
4551 cfg->speaker_outs = cfg->line_outs;
4552 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4553 sizeof(cfg->speaker_pins));
4554 cfg->line_outs = cfg->hp_outs;
4555 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4556 cfg->hp_outs = 0;
4557 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4558 cfg->line_out_type = AUTO_PIN_HP_OUT;
4559 }
4560
Takashi Iwai1d045db2011-07-07 18:23:21 +02004561 err = alc_auto_fill_dac_nids(codec);
4562 if (err < 0)
4563 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004564 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004565 if (err < 0)
4566 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004567 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004568 if (err < 0)
4569 return err;
4570 err = alc_auto_create_hp_out(codec);
4571 if (err < 0)
4572 return err;
4573 err = alc_auto_create_speaker_out(codec);
4574 if (err < 0)
4575 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004576 err = alc_auto_create_shared_input(codec);
4577 if (err < 0)
4578 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004579 err = alc_auto_create_input_ctls(codec);
4580 if (err < 0)
4581 return err;
4582
Takashi Iwaib6adb572012-12-03 10:30:58 +01004583 /* check the multiple speaker pins */
4584 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4585 spec->const_channel_count = cfg->line_outs * 2;
4586 else
4587 spec->const_channel_count = cfg->speaker_outs * 2;
4588
4589 if (spec->multi_ios > 0)
4590 spec->multiout.max_channels = max(spec->ext_channel_count,
4591 spec->const_channel_count);
4592 else
4593 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004594
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004595 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004596 alc_auto_parse_digital(codec);
4597
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004598 if (!spec->no_analog)
4599 alc_remove_invalid_adc_nids(codec);
4600
4601 if (ssid_nids)
4602 alc_ssid_check(codec, ssid_nids);
4603
4604 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004605 err = alc_auto_check_switches(codec);
4606 if (err < 0)
4607 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004608 err = alc_auto_add_mic_boost(codec);
4609 if (err < 0)
4610 return err;
4611 }
4612
Takashi Iwai1d045db2011-07-07 18:23:21 +02004613 if (spec->kctls.list)
4614 add_mixer(spec, spec->kctls.list);
4615
Takashi Iwai070cff42012-02-21 12:54:17 +01004616 if (!spec->no_analog && !spec->cap_mixer)
4617 set_capture_mixer(codec);
4618
Takashi Iwai1d045db2011-07-07 18:23:21 +02004619 return 1;
4620}
4621
Takashi Iwai3de95172012-05-07 18:03:15 +02004622/* common preparation job for alc_spec */
4623static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4624{
4625 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4626 int err;
4627
4628 if (!spec)
4629 return -ENOMEM;
4630 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004631 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004632 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004633 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004634 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4635 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004636 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004637
4638 err = alc_codec_rename_from_preset(codec);
4639 if (err < 0) {
4640 kfree(spec);
4641 return err;
4642 }
4643 return 0;
4644}
4645
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004646static int alc880_parse_auto_config(struct hda_codec *codec)
4647{
4648 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004649 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004650 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4651}
4652
Takashi Iwai1d045db2011-07-07 18:23:21 +02004653/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004654 * ALC880 fix-ups
4655 */
4656enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004657 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004658 ALC880_FIXUP_GPIO2,
4659 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004660 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004661 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004662 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004663 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004664 ALC880_FIXUP_VOL_KNOB,
4665 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004666 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004667 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004668 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004669 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004670 ALC880_FIXUP_3ST_BASE,
4671 ALC880_FIXUP_3ST,
4672 ALC880_FIXUP_3ST_DIG,
4673 ALC880_FIXUP_5ST_BASE,
4674 ALC880_FIXUP_5ST,
4675 ALC880_FIXUP_5ST_DIG,
4676 ALC880_FIXUP_6ST_BASE,
4677 ALC880_FIXUP_6ST,
4678 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004679};
4680
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004681/* enable the volume-knob widget support on NID 0x21 */
4682static void alc880_fixup_vol_knob(struct hda_codec *codec,
4683 const struct alc_fixup *fix, int action)
4684{
4685 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004686 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004687}
4688
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004689static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004690 [ALC880_FIXUP_GPIO1] = {
4691 .type = ALC_FIXUP_VERBS,
4692 .v.verbs = alc_gpio1_init_verbs,
4693 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004694 [ALC880_FIXUP_GPIO2] = {
4695 .type = ALC_FIXUP_VERBS,
4696 .v.verbs = alc_gpio2_init_verbs,
4697 },
4698 [ALC880_FIXUP_MEDION_RIM] = {
4699 .type = ALC_FIXUP_VERBS,
4700 .v.verbs = (const struct hda_verb[]) {
4701 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4702 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4703 { }
4704 },
4705 .chained = true,
4706 .chain_id = ALC880_FIXUP_GPIO2,
4707 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004708 [ALC880_FIXUP_LG] = {
4709 .type = ALC_FIXUP_PINS,
4710 .v.pins = (const struct alc_pincfg[]) {
4711 /* disable bogus unused pins */
4712 { 0x16, 0x411111f0 },
4713 { 0x18, 0x411111f0 },
4714 { 0x1a, 0x411111f0 },
4715 { }
4716 }
4717 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004718 [ALC880_FIXUP_W810] = {
4719 .type = ALC_FIXUP_PINS,
4720 .v.pins = (const struct alc_pincfg[]) {
4721 /* disable bogus unused pins */
4722 { 0x17, 0x411111f0 },
4723 { }
4724 },
4725 .chained = true,
4726 .chain_id = ALC880_FIXUP_GPIO2,
4727 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004728 [ALC880_FIXUP_EAPD_COEF] = {
4729 .type = ALC_FIXUP_VERBS,
4730 .v.verbs = (const struct hda_verb[]) {
4731 /* change to EAPD mode */
4732 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4733 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4734 {}
4735 },
4736 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004737 [ALC880_FIXUP_TCL_S700] = {
4738 .type = ALC_FIXUP_VERBS,
4739 .v.verbs = (const struct hda_verb[]) {
4740 /* change to EAPD mode */
4741 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4742 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4743 {}
4744 },
4745 .chained = true,
4746 .chain_id = ALC880_FIXUP_GPIO2,
4747 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004748 [ALC880_FIXUP_VOL_KNOB] = {
4749 .type = ALC_FIXUP_FUNC,
4750 .v.func = alc880_fixup_vol_knob,
4751 },
4752 [ALC880_FIXUP_FUJITSU] = {
4753 /* override all pins as BIOS on old Amilo is broken */
4754 .type = ALC_FIXUP_PINS,
4755 .v.pins = (const struct alc_pincfg[]) {
4756 { 0x14, 0x0121411f }, /* HP */
4757 { 0x15, 0x99030120 }, /* speaker */
4758 { 0x16, 0x99030130 }, /* bass speaker */
4759 { 0x17, 0x411111f0 }, /* N/A */
4760 { 0x18, 0x411111f0 }, /* N/A */
4761 { 0x19, 0x01a19950 }, /* mic-in */
4762 { 0x1a, 0x411111f0 }, /* N/A */
4763 { 0x1b, 0x411111f0 }, /* N/A */
4764 { 0x1c, 0x411111f0 }, /* N/A */
4765 { 0x1d, 0x411111f0 }, /* N/A */
4766 { 0x1e, 0x01454140 }, /* SPDIF out */
4767 { }
4768 },
4769 .chained = true,
4770 .chain_id = ALC880_FIXUP_VOL_KNOB,
4771 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004772 [ALC880_FIXUP_F1734] = {
4773 /* almost compatible with FUJITSU, but no bass and SPDIF */
4774 .type = ALC_FIXUP_PINS,
4775 .v.pins = (const struct alc_pincfg[]) {
4776 { 0x14, 0x0121411f }, /* HP */
4777 { 0x15, 0x99030120 }, /* speaker */
4778 { 0x16, 0x411111f0 }, /* N/A */
4779 { 0x17, 0x411111f0 }, /* N/A */
4780 { 0x18, 0x411111f0 }, /* N/A */
4781 { 0x19, 0x01a19950 }, /* mic-in */
4782 { 0x1a, 0x411111f0 }, /* N/A */
4783 { 0x1b, 0x411111f0 }, /* N/A */
4784 { 0x1c, 0x411111f0 }, /* N/A */
4785 { 0x1d, 0x411111f0 }, /* N/A */
4786 { 0x1e, 0x411111f0 }, /* N/A */
4787 { }
4788 },
4789 .chained = true,
4790 .chain_id = ALC880_FIXUP_VOL_KNOB,
4791 },
Takashi Iwai817de922012-02-20 17:20:48 +01004792 [ALC880_FIXUP_UNIWILL] = {
4793 /* need to fix HP and speaker pins to be parsed correctly */
4794 .type = ALC_FIXUP_PINS,
4795 .v.pins = (const struct alc_pincfg[]) {
4796 { 0x14, 0x0121411f }, /* HP */
4797 { 0x15, 0x99030120 }, /* speaker */
4798 { 0x16, 0x99030130 }, /* bass speaker */
4799 { }
4800 },
4801 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004802 [ALC880_FIXUP_UNIWILL_DIG] = {
4803 .type = ALC_FIXUP_PINS,
4804 .v.pins = (const struct alc_pincfg[]) {
4805 /* disable bogus unused pins */
4806 { 0x17, 0x411111f0 },
4807 { 0x19, 0x411111f0 },
4808 { 0x1b, 0x411111f0 },
4809 { 0x1f, 0x411111f0 },
4810 { }
4811 }
4812 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004813 [ALC880_FIXUP_Z71V] = {
4814 .type = ALC_FIXUP_PINS,
4815 .v.pins = (const struct alc_pincfg[]) {
4816 /* set up the whole pins as BIOS is utterly broken */
4817 { 0x14, 0x99030120 }, /* speaker */
4818 { 0x15, 0x0121411f }, /* HP */
4819 { 0x16, 0x411111f0 }, /* N/A */
4820 { 0x17, 0x411111f0 }, /* N/A */
4821 { 0x18, 0x01a19950 }, /* mic-in */
4822 { 0x19, 0x411111f0 }, /* N/A */
4823 { 0x1a, 0x01813031 }, /* line-in */
4824 { 0x1b, 0x411111f0 }, /* N/A */
4825 { 0x1c, 0x411111f0 }, /* N/A */
4826 { 0x1d, 0x411111f0 }, /* N/A */
4827 { 0x1e, 0x0144111e }, /* SPDIF */
4828 { }
4829 }
4830 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004831 [ALC880_FIXUP_3ST_BASE] = {
4832 .type = ALC_FIXUP_PINS,
4833 .v.pins = (const struct alc_pincfg[]) {
4834 { 0x14, 0x01014010 }, /* line-out */
4835 { 0x15, 0x411111f0 }, /* N/A */
4836 { 0x16, 0x411111f0 }, /* N/A */
4837 { 0x17, 0x411111f0 }, /* N/A */
4838 { 0x18, 0x01a19c30 }, /* mic-in */
4839 { 0x19, 0x0121411f }, /* HP */
4840 { 0x1a, 0x01813031 }, /* line-in */
4841 { 0x1b, 0x02a19c40 }, /* front-mic */
4842 { 0x1c, 0x411111f0 }, /* N/A */
4843 { 0x1d, 0x411111f0 }, /* N/A */
4844 /* 0x1e is filled in below */
4845 { 0x1f, 0x411111f0 }, /* N/A */
4846 { }
4847 }
4848 },
4849 [ALC880_FIXUP_3ST] = {
4850 .type = ALC_FIXUP_PINS,
4851 .v.pins = (const struct alc_pincfg[]) {
4852 { 0x1e, 0x411111f0 }, /* N/A */
4853 { }
4854 },
4855 .chained = true,
4856 .chain_id = ALC880_FIXUP_3ST_BASE,
4857 },
4858 [ALC880_FIXUP_3ST_DIG] = {
4859 .type = ALC_FIXUP_PINS,
4860 .v.pins = (const struct alc_pincfg[]) {
4861 { 0x1e, 0x0144111e }, /* SPDIF */
4862 { }
4863 },
4864 .chained = true,
4865 .chain_id = ALC880_FIXUP_3ST_BASE,
4866 },
4867 [ALC880_FIXUP_5ST_BASE] = {
4868 .type = ALC_FIXUP_PINS,
4869 .v.pins = (const struct alc_pincfg[]) {
4870 { 0x14, 0x01014010 }, /* front */
4871 { 0x15, 0x411111f0 }, /* N/A */
4872 { 0x16, 0x01011411 }, /* CLFE */
4873 { 0x17, 0x01016412 }, /* surr */
4874 { 0x18, 0x01a19c30 }, /* mic-in */
4875 { 0x19, 0x0121411f }, /* HP */
4876 { 0x1a, 0x01813031 }, /* line-in */
4877 { 0x1b, 0x02a19c40 }, /* front-mic */
4878 { 0x1c, 0x411111f0 }, /* N/A */
4879 { 0x1d, 0x411111f0 }, /* N/A */
4880 /* 0x1e is filled in below */
4881 { 0x1f, 0x411111f0 }, /* N/A */
4882 { }
4883 }
4884 },
4885 [ALC880_FIXUP_5ST] = {
4886 .type = ALC_FIXUP_PINS,
4887 .v.pins = (const struct alc_pincfg[]) {
4888 { 0x1e, 0x411111f0 }, /* N/A */
4889 { }
4890 },
4891 .chained = true,
4892 .chain_id = ALC880_FIXUP_5ST_BASE,
4893 },
4894 [ALC880_FIXUP_5ST_DIG] = {
4895 .type = ALC_FIXUP_PINS,
4896 .v.pins = (const struct alc_pincfg[]) {
4897 { 0x1e, 0x0144111e }, /* SPDIF */
4898 { }
4899 },
4900 .chained = true,
4901 .chain_id = ALC880_FIXUP_5ST_BASE,
4902 },
4903 [ALC880_FIXUP_6ST_BASE] = {
4904 .type = ALC_FIXUP_PINS,
4905 .v.pins = (const struct alc_pincfg[]) {
4906 { 0x14, 0x01014010 }, /* front */
4907 { 0x15, 0x01016412 }, /* surr */
4908 { 0x16, 0x01011411 }, /* CLFE */
4909 { 0x17, 0x01012414 }, /* side */
4910 { 0x18, 0x01a19c30 }, /* mic-in */
4911 { 0x19, 0x02a19c40 }, /* front-mic */
4912 { 0x1a, 0x01813031 }, /* line-in */
4913 { 0x1b, 0x0121411f }, /* HP */
4914 { 0x1c, 0x411111f0 }, /* N/A */
4915 { 0x1d, 0x411111f0 }, /* N/A */
4916 /* 0x1e is filled in below */
4917 { 0x1f, 0x411111f0 }, /* N/A */
4918 { }
4919 }
4920 },
4921 [ALC880_FIXUP_6ST] = {
4922 .type = ALC_FIXUP_PINS,
4923 .v.pins = (const struct alc_pincfg[]) {
4924 { 0x1e, 0x411111f0 }, /* N/A */
4925 { }
4926 },
4927 .chained = true,
4928 .chain_id = ALC880_FIXUP_6ST_BASE,
4929 },
4930 [ALC880_FIXUP_6ST_DIG] = {
4931 .type = ALC_FIXUP_PINS,
4932 .v.pins = (const struct alc_pincfg[]) {
4933 { 0x1e, 0x0144111e }, /* SPDIF */
4934 { }
4935 },
4936 .chained = true,
4937 .chain_id = ALC880_FIXUP_6ST_BASE,
4938 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004939};
4940
4941static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004942 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004943 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004944 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4945 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004946 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004947 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004948 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004949 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004950 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004951 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004952 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004953 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004954 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004955 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004956 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004957 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4958 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4959 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004960 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004961
4962 /* Below is the copied entries from alc880_quirks.c.
4963 * It's not quite sure whether BIOS sets the correct pin-config table
4964 * on these machines, thus they are kept to be compatible with
4965 * the old static quirks. Once when it's confirmed to work without
4966 * these overrides, it'd be better to remove.
4967 */
4968 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4969 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4970 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4971 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4972 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4973 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4974 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4975 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4976 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4977 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4978 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4979 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4980 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4981 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4982 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4983 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4984 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4985 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4986 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4987 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4988 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4989 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4990 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4991 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4992 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4993 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4994 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4995 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4996 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4997 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4998 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4999 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5000 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5001 /* default Intel */
5002 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
5003 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
5004 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
5005 {}
5006};
5007
5008static const struct alc_model_fixup alc880_fixup_models[] = {
5009 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
5010 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
5011 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
5012 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
5013 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
5014 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01005015 {}
5016};
5017
5018
5019/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02005020 * OK, here we have finally the patch for ALC880
5021 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005022static int patch_alc880(struct hda_codec *codec)
5023{
5024 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005025 int err;
5026
Takashi Iwai3de95172012-05-07 18:03:15 +02005027 err = alc_alloc_spec(codec, 0x0b);
5028 if (err < 0)
5029 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005030
Takashi Iwai3de95172012-05-07 18:03:15 +02005031 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02005032 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005033
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005034 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
5035 alc880_fixups);
5036 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005037
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005038 /* automatic parse from the BIOS config */
5039 err = alc880_parse_auto_config(codec);
5040 if (err < 0)
5041 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005042
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005043 if (!spec->no_analog) {
5044 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005045 if (err < 0)
5046 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005047 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5048 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005049
Takashi Iwai1d045db2011-07-07 18:23:21 +02005050 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02005051 codec->patch_ops.unsol_event = alc880_unsol_event;
5052
Takashi Iwai1d045db2011-07-07 18:23:21 +02005053
Takashi Iwai589876e2012-02-20 15:47:55 +01005054 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5055
Takashi Iwai1d045db2011-07-07 18:23:21 +02005056 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005057
5058 error:
5059 alc_free(codec);
5060 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005061}
5062
5063
5064/*
5065 * ALC260 support
5066 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005067static int alc260_parse_auto_config(struct hda_codec *codec)
5068{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005069 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005070 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5071 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005072}
5073
Takashi Iwai1d045db2011-07-07 18:23:21 +02005074/*
5075 * Pin config fixes
5076 */
5077enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005078 ALC260_FIXUP_HP_DC5750,
5079 ALC260_FIXUP_HP_PIN_0F,
5080 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005081 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005082 ALC260_FIXUP_GPIO1_TOGGLE,
5083 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005084 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005085 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005086};
5087
Takashi Iwai20f7d922012-02-16 12:35:16 +01005088static void alc260_gpio1_automute(struct hda_codec *codec)
5089{
5090 struct alc_spec *spec = codec->spec;
5091 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5092 spec->hp_jack_present);
5093}
5094
5095static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5096 const struct alc_fixup *fix, int action)
5097{
5098 struct alc_spec *spec = codec->spec;
5099 if (action == ALC_FIXUP_ACT_PROBE) {
5100 /* although the machine has only one output pin, we need to
5101 * toggle GPIO1 according to the jack state
5102 */
5103 spec->automute_hook = alc260_gpio1_automute;
5104 spec->detect_hp = 1;
5105 spec->automute_speaker = 1;
5106 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005107 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5108 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005109 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005110 }
5111}
5112
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005113static void alc260_fixup_kn1(struct hda_codec *codec,
5114 const struct alc_fixup *fix, int action)
5115{
5116 struct alc_spec *spec = codec->spec;
5117 static const struct alc_pincfg pincfgs[] = {
5118 { 0x0f, 0x02214000 }, /* HP/speaker */
5119 { 0x12, 0x90a60160 }, /* int mic */
5120 { 0x13, 0x02a19000 }, /* ext mic */
5121 { 0x18, 0x01446000 }, /* SPDIF out */
5122 /* disable bogus I/O pins */
5123 { 0x10, 0x411111f0 },
5124 { 0x11, 0x411111f0 },
5125 { 0x14, 0x411111f0 },
5126 { 0x15, 0x411111f0 },
5127 { 0x16, 0x411111f0 },
5128 { 0x17, 0x411111f0 },
5129 { 0x19, 0x411111f0 },
5130 { }
5131 };
5132
5133 switch (action) {
5134 case ALC_FIXUP_ACT_PRE_PROBE:
5135 alc_apply_pincfgs(codec, pincfgs);
5136 break;
5137 case ALC_FIXUP_ACT_PROBE:
5138 spec->init_amp = ALC_INIT_NONE;
5139 break;
5140 }
5141}
5142
Takashi Iwai1d045db2011-07-07 18:23:21 +02005143static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005144 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005145 .type = ALC_FIXUP_PINS,
5146 .v.pins = (const struct alc_pincfg[]) {
5147 { 0x11, 0x90130110 }, /* speaker */
5148 { }
5149 }
5150 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005151 [ALC260_FIXUP_HP_PIN_0F] = {
5152 .type = ALC_FIXUP_PINS,
5153 .v.pins = (const struct alc_pincfg[]) {
5154 { 0x0f, 0x01214000 }, /* HP */
5155 { }
5156 }
5157 },
5158 [ALC260_FIXUP_COEF] = {
5159 .type = ALC_FIXUP_VERBS,
5160 .v.verbs = (const struct hda_verb[]) {
5161 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5162 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5163 { }
5164 },
5165 .chained = true,
5166 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5167 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005168 [ALC260_FIXUP_GPIO1] = {
5169 .type = ALC_FIXUP_VERBS,
5170 .v.verbs = alc_gpio1_init_verbs,
5171 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005172 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5173 .type = ALC_FIXUP_FUNC,
5174 .v.func = alc260_fixup_gpio1_toggle,
5175 .chained = true,
5176 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5177 },
5178 [ALC260_FIXUP_REPLACER] = {
5179 .type = ALC_FIXUP_VERBS,
5180 .v.verbs = (const struct hda_verb[]) {
5181 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5182 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5183 { }
5184 },
5185 .chained = true,
5186 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5187 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005188 [ALC260_FIXUP_HP_B1900] = {
5189 .type = ALC_FIXUP_FUNC,
5190 .v.func = alc260_fixup_gpio1_toggle,
5191 .chained = true,
5192 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005193 },
5194 [ALC260_FIXUP_KN1] = {
5195 .type = ALC_FIXUP_FUNC,
5196 .v.func = alc260_fixup_kn1,
5197 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005198};
5199
5200static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005201 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005202 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005203 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005204 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005205 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005206 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005207 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005208 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005209 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005210 {}
5211};
5212
5213/*
5214 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005215static int patch_alc260(struct hda_codec *codec)
5216{
5217 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005218 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005219
Takashi Iwai3de95172012-05-07 18:03:15 +02005220 err = alc_alloc_spec(codec, 0x07);
5221 if (err < 0)
5222 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005223
Takashi Iwai3de95172012-05-07 18:03:15 +02005224 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005225
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005226 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5227 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005228
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005229 /* automatic parse from the BIOS config */
5230 err = alc260_parse_auto_config(codec);
5231 if (err < 0)
5232 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005233
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005234 if (!spec->no_analog) {
5235 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005236 if (err < 0)
5237 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005238 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5239 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005240
Takashi Iwai1d045db2011-07-07 18:23:21 +02005241 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005242 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005243
Takashi Iwai589876e2012-02-20 15:47:55 +01005244 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5245
Takashi Iwai1d045db2011-07-07 18:23:21 +02005246 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005247
5248 error:
5249 alc_free(codec);
5250 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005251}
5252
5253
5254/*
5255 * ALC882/883/885/888/889 support
5256 *
5257 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5258 * configuration. Each pin widget can choose any input DACs and a mixer.
5259 * Each ADC is connected from a mixer of all inputs. This makes possible
5260 * 6-channel independent captures.
5261 *
5262 * In addition, an independent DAC for the multi-playback (not used in this
5263 * driver yet).
5264 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005265
5266/*
5267 * Pin config fixes
5268 */
5269enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005270 ALC882_FIXUP_ABIT_AW9D_MAX,
5271 ALC882_FIXUP_LENOVO_Y530,
5272 ALC882_FIXUP_PB_M5210,
5273 ALC882_FIXUP_ACER_ASPIRE_7736,
5274 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005275 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005276 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005277 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005278 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005279 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005280 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005281 ALC882_FIXUP_GPIO1,
5282 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005283 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005284 ALC889_FIXUP_COEF,
5285 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005286 ALC882_FIXUP_ACER_ASPIRE_4930G,
5287 ALC882_FIXUP_ACER_ASPIRE_8930G,
5288 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005289 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005290 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005291 ALC889_FIXUP_MBP_VREF,
5292 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005293 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005294 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005295};
5296
Takashi Iwai68ef0562011-11-09 18:24:44 +01005297static void alc889_fixup_coef(struct hda_codec *codec,
5298 const struct alc_fixup *fix, int action)
5299{
5300 if (action != ALC_FIXUP_ACT_INIT)
5301 return;
5302 alc889_coef_init(codec);
5303}
5304
Takashi Iwai56710872011-11-14 17:42:11 +01005305/* toggle speaker-output according to the hp-jack state */
5306static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5307{
5308 unsigned int gpiostate, gpiomask, gpiodir;
5309
5310 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5311 AC_VERB_GET_GPIO_DATA, 0);
5312
5313 if (!muted)
5314 gpiostate |= (1 << pin);
5315 else
5316 gpiostate &= ~(1 << pin);
5317
5318 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5319 AC_VERB_GET_GPIO_MASK, 0);
5320 gpiomask |= (1 << pin);
5321
5322 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5323 AC_VERB_GET_GPIO_DIRECTION, 0);
5324 gpiodir |= (1 << pin);
5325
5326
5327 snd_hda_codec_write(codec, codec->afg, 0,
5328 AC_VERB_SET_GPIO_MASK, gpiomask);
5329 snd_hda_codec_write(codec, codec->afg, 0,
5330 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5331
5332 msleep(1);
5333
5334 snd_hda_codec_write(codec, codec->afg, 0,
5335 AC_VERB_SET_GPIO_DATA, gpiostate);
5336}
5337
5338/* set up GPIO at initialization */
5339static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5340 const struct alc_fixup *fix, int action)
5341{
5342 if (action != ALC_FIXUP_ACT_INIT)
5343 return;
5344 alc882_gpio_mute(codec, 0, 0);
5345 alc882_gpio_mute(codec, 1, 0);
5346}
5347
Takashi Iwai02a237b2012-02-13 15:25:07 +01005348/* Fix the connection of some pins for ALC889:
5349 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5350 * work correctly (bko#42740)
5351 */
5352static void alc889_fixup_dac_route(struct hda_codec *codec,
5353 const struct alc_fixup *fix, int action)
5354{
5355 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005356 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005357 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5358 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5359 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5360 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5361 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5362 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005363 } else if (action == ALC_FIXUP_ACT_PROBE) {
5364 /* restore the connections */
5365 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5366 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5367 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5368 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5369 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005370 }
5371}
5372
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005373/* Set VREF on HP pin */
5374static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5375 const struct alc_fixup *fix, int action)
5376{
5377 struct alc_spec *spec = codec->spec;
5378 static hda_nid_t nids[2] = { 0x14, 0x15 };
5379 int i;
5380
5381 if (action != ALC_FIXUP_ACT_INIT)
5382 return;
5383 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5384 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5385 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5386 continue;
5387 val = snd_hda_codec_read(codec, nids[i], 0,
5388 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5389 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005390 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005391 spec->keep_vref_in_automute = 1;
5392 break;
5393 }
5394}
5395
5396/* Set VREF on speaker pins on imac91 */
5397static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5398 const struct alc_fixup *fix, int action)
5399{
5400 struct alc_spec *spec = codec->spec;
5401 static hda_nid_t nids[2] = { 0x18, 0x1a };
5402 int i;
5403
5404 if (action != ALC_FIXUP_ACT_INIT)
5405 return;
5406 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5407 unsigned int val;
5408 val = snd_hda_codec_read(codec, nids[i], 0,
5409 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5410 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005411 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005412 }
5413 spec->keep_vref_in_automute = 1;
5414}
5415
Takashi Iwaie427c232012-07-29 10:04:08 +02005416/* Don't take HP output as primary
5417 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5418 */
5419static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5420 const struct alc_fixup *fix, int action)
5421{
5422 struct alc_spec *spec = codec->spec;
5423 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5424 spec->no_primary_hp = 1;
5425}
5426
Takashi Iwai1d045db2011-07-07 18:23:21 +02005427static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005428 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005429 .type = ALC_FIXUP_PINS,
5430 .v.pins = (const struct alc_pincfg[]) {
5431 { 0x15, 0x01080104 }, /* side */
5432 { 0x16, 0x01011012 }, /* rear */
5433 { 0x17, 0x01016011 }, /* clfe */
5434 { }
5435 }
5436 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005437 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005438 .type = ALC_FIXUP_PINS,
5439 .v.pins = (const struct alc_pincfg[]) {
5440 { 0x15, 0x99130112 }, /* rear int speakers */
5441 { 0x16, 0x99130111 }, /* subwoofer */
5442 { }
5443 }
5444 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005445 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005446 .type = ALC_FIXUP_VERBS,
5447 .v.verbs = (const struct hda_verb[]) {
5448 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5449 {}
5450 }
5451 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005452 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005453 .type = ALC_FIXUP_FUNC,
5454 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005455 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005456 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005457 .type = ALC_FIXUP_PINS,
5458 .v.pins = (const struct alc_pincfg[]) {
5459 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5460 { }
5461 }
5462 },
Marton Balint8f239212012-03-05 21:33:23 +01005463 [ALC889_FIXUP_CD] = {
5464 .type = ALC_FIXUP_PINS,
5465 .v.pins = (const struct alc_pincfg[]) {
5466 { 0x1c, 0x993301f0 }, /* CD */
5467 { }
5468 }
5469 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005470 [ALC889_FIXUP_VAIO_TT] = {
5471 .type = ALC_FIXUP_PINS,
5472 .v.pins = (const struct alc_pincfg[]) {
5473 { 0x17, 0x90170111 }, /* hidden surround speaker */
5474 { }
5475 }
5476 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005477 [ALC888_FIXUP_EEE1601] = {
5478 .type = ALC_FIXUP_VERBS,
5479 .v.verbs = (const struct hda_verb[]) {
5480 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5481 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5482 { }
5483 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005484 },
5485 [ALC882_FIXUP_EAPD] = {
5486 .type = ALC_FIXUP_VERBS,
5487 .v.verbs = (const struct hda_verb[]) {
5488 /* change to EAPD mode */
5489 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5490 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5491 { }
5492 }
5493 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005494 [ALC883_FIXUP_EAPD] = {
5495 .type = ALC_FIXUP_VERBS,
5496 .v.verbs = (const struct hda_verb[]) {
5497 /* change to EAPD mode */
5498 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5499 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5500 { }
5501 }
5502 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005503 [ALC883_FIXUP_ACER_EAPD] = {
5504 .type = ALC_FIXUP_VERBS,
5505 .v.verbs = (const struct hda_verb[]) {
5506 /* eanable EAPD on Acer laptops */
5507 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5508 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5509 { }
5510 }
5511 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005512 [ALC882_FIXUP_GPIO1] = {
5513 .type = ALC_FIXUP_VERBS,
5514 .v.verbs = alc_gpio1_init_verbs,
5515 },
5516 [ALC882_FIXUP_GPIO2] = {
5517 .type = ALC_FIXUP_VERBS,
5518 .v.verbs = alc_gpio2_init_verbs,
5519 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005520 [ALC882_FIXUP_GPIO3] = {
5521 .type = ALC_FIXUP_VERBS,
5522 .v.verbs = alc_gpio3_init_verbs,
5523 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005524 [ALC882_FIXUP_ASUS_W2JC] = {
5525 .type = ALC_FIXUP_VERBS,
5526 .v.verbs = alc_gpio1_init_verbs,
5527 .chained = true,
5528 .chain_id = ALC882_FIXUP_EAPD,
5529 },
5530 [ALC889_FIXUP_COEF] = {
5531 .type = ALC_FIXUP_FUNC,
5532 .v.func = alc889_fixup_coef,
5533 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005534 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5535 .type = ALC_FIXUP_PINS,
5536 .v.pins = (const struct alc_pincfg[]) {
5537 { 0x16, 0x99130111 }, /* CLFE speaker */
5538 { 0x17, 0x99130112 }, /* surround speaker */
5539 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005540 },
5541 .chained = true,
5542 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005543 },
5544 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5545 .type = ALC_FIXUP_PINS,
5546 .v.pins = (const struct alc_pincfg[]) {
5547 { 0x16, 0x99130111 }, /* CLFE speaker */
5548 { 0x1b, 0x99130112 }, /* surround speaker */
5549 { }
5550 },
5551 .chained = true,
5552 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5553 },
5554 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5555 /* additional init verbs for Acer Aspire 8930G */
5556 .type = ALC_FIXUP_VERBS,
5557 .v.verbs = (const struct hda_verb[]) {
5558 /* Enable all DACs */
5559 /* DAC DISABLE/MUTE 1? */
5560 /* setting bits 1-5 disables DAC nids 0x02-0x06
5561 * apparently. Init=0x38 */
5562 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5563 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5564 /* DAC DISABLE/MUTE 2? */
5565 /* some bit here disables the other DACs.
5566 * Init=0x4900 */
5567 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5568 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5569 /* DMIC fix
5570 * This laptop has a stereo digital microphone.
5571 * The mics are only 1cm apart which makes the stereo
5572 * useless. However, either the mic or the ALC889
5573 * makes the signal become a difference/sum signal
5574 * instead of standard stereo, which is annoying.
5575 * So instead we flip this bit which makes the
5576 * codec replicate the sum signal to both channels,
5577 * turning it into a normal mono mic.
5578 */
5579 /* DMIC_CONTROL? Init value = 0x0001 */
5580 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5581 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5582 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5583 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5584 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005585 },
5586 .chained = true,
5587 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005588 },
Takashi Iwai56710872011-11-14 17:42:11 +01005589 [ALC885_FIXUP_MACPRO_GPIO] = {
5590 .type = ALC_FIXUP_FUNC,
5591 .v.func = alc885_fixup_macpro_gpio,
5592 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005593 [ALC889_FIXUP_DAC_ROUTE] = {
5594 .type = ALC_FIXUP_FUNC,
5595 .v.func = alc889_fixup_dac_route,
5596 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005597 [ALC889_FIXUP_MBP_VREF] = {
5598 .type = ALC_FIXUP_FUNC,
5599 .v.func = alc889_fixup_mbp_vref,
5600 .chained = true,
5601 .chain_id = ALC882_FIXUP_GPIO1,
5602 },
5603 [ALC889_FIXUP_IMAC91_VREF] = {
5604 .type = ALC_FIXUP_FUNC,
5605 .v.func = alc889_fixup_imac91_vref,
5606 .chained = true,
5607 .chain_id = ALC882_FIXUP_GPIO1,
5608 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005609 [ALC882_FIXUP_INV_DMIC] = {
5610 .type = ALC_FIXUP_FUNC,
5611 .v.func = alc_fixup_inv_dmic_0x12,
5612 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005613 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5614 .type = ALC_FIXUP_FUNC,
5615 .v.func = alc882_fixup_no_primary_hp,
5616 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005617};
5618
5619static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005620 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5621 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5622 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5623 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5624 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5625 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005626 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5627 ALC882_FIXUP_ACER_ASPIRE_4930G),
5628 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5629 ALC882_FIXUP_ACER_ASPIRE_4930G),
5630 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5631 ALC882_FIXUP_ACER_ASPIRE_8930G),
5632 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5633 ALC882_FIXUP_ACER_ASPIRE_8930G),
5634 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5635 ALC882_FIXUP_ACER_ASPIRE_4930G),
5636 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5637 ALC882_FIXUP_ACER_ASPIRE_4930G),
5638 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5639 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005640 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005641 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5642 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005643 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005644 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005645 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005646 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005647 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005648 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005649 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005650 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005651 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005652
5653 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005654 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5655 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5656 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005657 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5658 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5659 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005660 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5661 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005662 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005663 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5664 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5665 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5666 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005667 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005668 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5669 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5670 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005671 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005672 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005673 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5674 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5675 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005676
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005677 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005678 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005679 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005680 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005681 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005682 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5683 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005684 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005685 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005686 {}
5687};
5688
Takashi Iwai912093b2012-04-11 14:03:41 +02005689static const struct alc_model_fixup alc882_fixup_models[] = {
5690 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5691 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5692 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005693 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005694 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005695 {}
5696};
5697
Takashi Iwai1d045db2011-07-07 18:23:21 +02005698/*
5699 * BIOS auto configuration
5700 */
5701/* almost identical with ALC880 parser... */
5702static int alc882_parse_auto_config(struct hda_codec *codec)
5703{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005704 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005705 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5706 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005707}
5708
Takashi Iwai1d045db2011-07-07 18:23:21 +02005709/*
5710 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005711static int patch_alc882(struct hda_codec *codec)
5712{
5713 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005714 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005715
Takashi Iwai3de95172012-05-07 18:03:15 +02005716 err = alc_alloc_spec(codec, 0x0b);
5717 if (err < 0)
5718 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005719
Takashi Iwai3de95172012-05-07 18:03:15 +02005720 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721
5722 switch (codec->vendor_id) {
5723 case 0x10ec0882:
5724 case 0x10ec0885:
5725 break;
5726 default:
5727 /* ALC883 and variants */
5728 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5729 break;
5730 }
5731
Takashi Iwai912093b2012-04-11 14:03:41 +02005732 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5733 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005734 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005735
5736 alc_auto_parse_customize_define(codec);
5737
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005738 /* automatic parse from the BIOS config */
5739 err = alc882_parse_auto_config(codec);
5740 if (err < 0)
5741 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005742
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005743 if (!spec->no_analog && has_cdefine_beep(codec)) {
5744 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005745 if (err < 0)
5746 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005747 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005748 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005749
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005751
Takashi Iwai589876e2012-02-20 15:47:55 +01005752 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5753
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005755
5756 error:
5757 alc_free(codec);
5758 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005759}
5760
5761
5762/*
5763 * ALC262 support
5764 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765static int alc262_parse_auto_config(struct hda_codec *codec)
5766{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005768 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5769 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005770}
5771
5772/*
5773 * Pin config fixes
5774 */
5775enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005776 ALC262_FIXUP_FSC_H270,
5777 ALC262_FIXUP_HP_Z200,
5778 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005779 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005780 ALC262_FIXUP_BENQ,
5781 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005782 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005783};
5784
5785static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005786 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005787 .type = ALC_FIXUP_PINS,
5788 .v.pins = (const struct alc_pincfg[]) {
5789 { 0x14, 0x99130110 }, /* speaker */
5790 { 0x15, 0x0221142f }, /* front HP */
5791 { 0x1b, 0x0121141f }, /* rear HP */
5792 { }
5793 }
5794 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005795 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005796 .type = ALC_FIXUP_PINS,
5797 .v.pins = (const struct alc_pincfg[]) {
5798 { 0x16, 0x99130120 }, /* internal speaker */
5799 { }
5800 }
5801 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005802 [ALC262_FIXUP_TYAN] = {
5803 .type = ALC_FIXUP_PINS,
5804 .v.pins = (const struct alc_pincfg[]) {
5805 { 0x14, 0x1993e1f0 }, /* int AUX */
5806 { }
5807 }
5808 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005809 [ALC262_FIXUP_LENOVO_3000] = {
5810 .type = ALC_FIXUP_VERBS,
5811 .v.verbs = (const struct hda_verb[]) {
5812 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005813 {}
5814 },
5815 .chained = true,
5816 .chain_id = ALC262_FIXUP_BENQ,
5817 },
5818 [ALC262_FIXUP_BENQ] = {
5819 .type = ALC_FIXUP_VERBS,
5820 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005821 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5822 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5823 {}
5824 }
5825 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005826 [ALC262_FIXUP_BENQ_T31] = {
5827 .type = ALC_FIXUP_VERBS,
5828 .v.verbs = (const struct hda_verb[]) {
5829 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5830 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5831 {}
5832 }
5833 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005834 [ALC262_FIXUP_INV_DMIC] = {
5835 .type = ALC_FIXUP_FUNC,
5836 .v.func = alc_fixup_inv_dmic_0x12,
5837 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005838};
5839
5840static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005841 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005842 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5843 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005844 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5845 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005846 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005847 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5848 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005849 {}
5850};
5851
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005852static const struct alc_model_fixup alc262_fixup_models[] = {
5853 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5854 {}
5855};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005856
Takashi Iwai1d045db2011-07-07 18:23:21 +02005857/*
5858 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005859static int patch_alc262(struct hda_codec *codec)
5860{
5861 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005862 int err;
5863
Takashi Iwai3de95172012-05-07 18:03:15 +02005864 err = alc_alloc_spec(codec, 0x0b);
5865 if (err < 0)
5866 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005867
Takashi Iwai3de95172012-05-07 18:03:15 +02005868 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005869
5870#if 0
5871 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5872 * under-run
5873 */
5874 {
5875 int tmp;
5876 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5877 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5878 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5879 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5880 }
5881#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005882 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5883
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005884 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5885 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005886 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005888 alc_auto_parse_customize_define(codec);
5889
Takashi Iwai42399f72011-11-07 17:18:44 +01005890 /* automatic parse from the BIOS config */
5891 err = alc262_parse_auto_config(codec);
5892 if (err < 0)
5893 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005894
Takashi Iwai1d045db2011-07-07 18:23:21 +02005895 if (!spec->no_analog && has_cdefine_beep(codec)) {
5896 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005897 if (err < 0)
5898 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005899 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005900 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005901
Takashi Iwai1d045db2011-07-07 18:23:21 +02005902 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005903 spec->shutup = alc_eapd_shutup;
5904
Takashi Iwai589876e2012-02-20 15:47:55 +01005905 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5906
Takashi Iwai1d045db2011-07-07 18:23:21 +02005907 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005908
5909 error:
5910 alc_free(codec);
5911 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005912}
5913
5914/*
5915 * ALC268
5916 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005917/* bind Beep switches of both NID 0x0f and 0x10 */
5918static const struct hda_bind_ctls alc268_bind_beep_sw = {
5919 .ops = &snd_hda_bind_sw,
5920 .values = {
5921 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5922 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5923 0
5924 },
5925};
5926
5927static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5928 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5929 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5930 { }
5931};
5932
5933/* set PCBEEP vol = 0, mute connections */
5934static const struct hda_verb alc268_beep_init_verbs[] = {
5935 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5936 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5937 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5938 { }
5939};
5940
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005941enum {
5942 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005943 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005944};
5945
5946static const struct alc_fixup alc268_fixups[] = {
5947 [ALC268_FIXUP_INV_DMIC] = {
5948 .type = ALC_FIXUP_FUNC,
5949 .v.func = alc_fixup_inv_dmic_0x12,
5950 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005951 [ALC268_FIXUP_HP_EAPD] = {
5952 .type = ALC_FIXUP_VERBS,
5953 .v.verbs = (const struct hda_verb[]) {
5954 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5955 {}
5956 }
5957 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005958};
5959
5960static const struct alc_model_fixup alc268_fixup_models[] = {
5961 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005962 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5963 {}
5964};
5965
5966static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5967 /* below is codec SSID since multiple Toshiba laptops have the
5968 * same PCI SSID 1179:ff00
5969 */
5970 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005971 {}
5972};
5973
Takashi Iwai1d045db2011-07-07 18:23:21 +02005974/*
5975 * BIOS auto configuration
5976 */
5977static int alc268_parse_auto_config(struct hda_codec *codec)
5978{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005979 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005980 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005981 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5982 if (err > 0) {
5983 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5984 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005985 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005986 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005987 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005988 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005989}
5990
Takashi Iwai1d045db2011-07-07 18:23:21 +02005991/*
5992 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005993static int patch_alc268(struct hda_codec *codec)
5994{
5995 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005996 int i, has_beep, err;
5997
Takashi Iwai1d045db2011-07-07 18:23:21 +02005998 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005999 err = alc_alloc_spec(codec, 0);
6000 if (err < 0)
6001 return err;
6002
6003 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006004
Takashi Iwaicb766402012-10-20 10:55:21 +02006005 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006006 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6007
Takashi Iwai6ebb8052011-08-16 15:15:40 +02006008 /* automatic parse from the BIOS config */
6009 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006010 if (err < 0)
6011 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006012
Takashi Iwai1d045db2011-07-07 18:23:21 +02006013 has_beep = 0;
6014 for (i = 0; i < spec->num_mixers; i++) {
6015 if (spec->mixers[i] == alc268_beep_mixer) {
6016 has_beep = 1;
6017 break;
6018 }
6019 }
6020
6021 if (has_beep) {
6022 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006023 if (err < 0)
6024 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006025 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
6026 /* override the amp caps for beep generator */
6027 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
6028 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
6029 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
6030 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6031 (0 << AC_AMPCAP_MUTE_SHIFT));
6032 }
6033
Takashi Iwai1d045db2011-07-07 18:23:21 +02006034 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006035 spec->shutup = alc_eapd_shutup;
6036
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006037 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6038
Takashi Iwai1d045db2011-07-07 18:23:21 +02006039 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006040
6041 error:
6042 alc_free(codec);
6043 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006044}
6045
6046/*
6047 * ALC269
6048 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006049static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6050 .substreams = 1,
6051 .channels_min = 2,
6052 .channels_max = 8,
6053 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6054 /* NID is set in alc_build_pcms */
6055 .ops = {
6056 .open = alc_playback_pcm_open,
6057 .prepare = alc_playback_pcm_prepare,
6058 .cleanup = alc_playback_pcm_cleanup
6059 },
6060};
6061
6062static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6063 .substreams = 1,
6064 .channels_min = 2,
6065 .channels_max = 2,
6066 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6067 /* NID is set in alc_build_pcms */
6068};
6069
Takashi Iwai1d045db2011-07-07 18:23:21 +02006070/* different alc269-variants */
6071enum {
6072 ALC269_TYPE_ALC269VA,
6073 ALC269_TYPE_ALC269VB,
6074 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006075 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006076 ALC269_TYPE_ALC280,
6077 ALC269_TYPE_ALC282,
6078 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006079};
6080
6081/*
6082 * BIOS auto configuration
6083 */
6084static int alc269_parse_auto_config(struct hda_codec *codec)
6085{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006086 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006087 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6088 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6089 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006090 const hda_nid_t *ssids;
6091
6092 switch (spec->codec_variant) {
6093 case ALC269_TYPE_ALC269VA:
6094 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006095 case ALC269_TYPE_ALC280:
6096 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006097 ssids = alc269va_ssids;
6098 break;
6099 case ALC269_TYPE_ALC269VB:
6100 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006101 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006102 ssids = alc269_ssids;
6103 break;
6104 default:
6105 ssids = alc269_ssids;
6106 break;
6107 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006108
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006109 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006110}
6111
Kailang Yang1387e2d2012-11-08 10:23:18 +01006112static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006113{
6114 int val = alc_read_coef_idx(codec, 0x04);
6115 if (power_up)
6116 val |= 1 << 11;
6117 else
6118 val &= ~(1 << 11);
6119 alc_write_coef_idx(codec, 0x04, val);
6120}
6121
6122static void alc269_shutup(struct hda_codec *codec)
6123{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006124 struct alc_spec *spec = codec->spec;
6125
6126 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6127 return;
6128
Kailang Yang1387e2d2012-11-08 10:23:18 +01006129 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6130 alc269vb_toggle_power_output(codec, 0);
6131 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6132 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006133 msleep(150);
6134 }
6135}
6136
Takashi Iwai2a439522011-07-26 09:52:50 +02006137#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006138static int alc269_resume(struct hda_codec *codec)
6139{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006140 struct alc_spec *spec = codec->spec;
6141
Kailang Yang1387e2d2012-11-08 10:23:18 +01006142 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6143 alc269vb_toggle_power_output(codec, 0);
6144 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006145 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006146 msleep(150);
6147 }
6148
6149 codec->patch_ops.init(codec);
6150
Kailang Yang1387e2d2012-11-08 10:23:18 +01006151 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6152 alc269vb_toggle_power_output(codec, 1);
6153 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006154 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006155 msleep(200);
6156 }
6157
Takashi Iwai1d045db2011-07-07 18:23:21 +02006158 snd_hda_codec_resume_amp(codec);
6159 snd_hda_codec_resume_cache(codec);
6160 hda_call_check_power_status(codec, 0x01);
6161 return 0;
6162}
Takashi Iwai2a439522011-07-26 09:52:50 +02006163#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006164
David Henningsson108cc102012-07-20 10:37:25 +02006165static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6166 const struct alc_fixup *fix, int action)
6167{
6168 struct alc_spec *spec = codec->spec;
6169
6170 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6171 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6172}
6173
Takashi Iwai1d045db2011-07-07 18:23:21 +02006174static void alc269_fixup_hweq(struct hda_codec *codec,
6175 const struct alc_fixup *fix, int action)
6176{
6177 int coef;
6178
6179 if (action != ALC_FIXUP_ACT_INIT)
6180 return;
6181 coef = alc_read_coef_idx(codec, 0x1e);
6182 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6183}
6184
6185static void alc271_fixup_dmic(struct hda_codec *codec,
6186 const struct alc_fixup *fix, int action)
6187{
6188 static const struct hda_verb verbs[] = {
6189 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6190 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6191 {}
6192 };
6193 unsigned int cfg;
6194
6195 if (strcmp(codec->chip_name, "ALC271X"))
6196 return;
6197 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6198 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6199 snd_hda_sequence_write(codec, verbs);
6200}
6201
Takashi Iwai017f2a12011-07-09 14:42:25 +02006202static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6203 const struct alc_fixup *fix, int action)
6204{
6205 struct alc_spec *spec = codec->spec;
6206
6207 if (action != ALC_FIXUP_ACT_PROBE)
6208 return;
6209
6210 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6211 * fix the sample rate of analog I/O to 44.1kHz
6212 */
6213 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6214 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6215}
6216
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006217static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6218 const struct alc_fixup *fix, int action)
6219{
6220 int coef;
6221
6222 if (action != ALC_FIXUP_ACT_INIT)
6223 return;
6224 /* The digital-mic unit sends PDM (differential signal) instead of
6225 * the standard PCM, thus you can't record a valid mono stream as is.
6226 * Below is a workaround specific to ALC269 to control the dmic
6227 * signal source as mono.
6228 */
6229 coef = alc_read_coef_idx(codec, 0x07);
6230 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6231}
6232
Takashi Iwai24519912011-08-16 15:08:49 +02006233static void alc269_quanta_automute(struct hda_codec *codec)
6234{
David Henningsson42cf0d02011-09-20 12:04:56 +02006235 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006236
6237 snd_hda_codec_write(codec, 0x20, 0,
6238 AC_VERB_SET_COEF_INDEX, 0x0c);
6239 snd_hda_codec_write(codec, 0x20, 0,
6240 AC_VERB_SET_PROC_COEF, 0x680);
6241
6242 snd_hda_codec_write(codec, 0x20, 0,
6243 AC_VERB_SET_COEF_INDEX, 0x0c);
6244 snd_hda_codec_write(codec, 0x20, 0,
6245 AC_VERB_SET_PROC_COEF, 0x480);
6246}
6247
6248static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6249 const struct alc_fixup *fix, int action)
6250{
6251 struct alc_spec *spec = codec->spec;
6252 if (action != ALC_FIXUP_ACT_PROBE)
6253 return;
6254 spec->automute_hook = alc269_quanta_automute;
6255}
6256
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006257/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6258static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6259{
6260 struct hda_codec *codec = private_data;
6261 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6262 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6263 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6264}
6265
6266static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6267 const struct alc_fixup *fix, int action)
6268{
6269 struct alc_spec *spec = codec->spec;
6270 switch (action) {
6271 case ALC_FIXUP_ACT_BUILD:
6272 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6273 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6274 /* fallthru */
6275 case ALC_FIXUP_ACT_INIT:
6276 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6277 break;
6278 }
6279}
6280
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006281/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6282static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6283{
6284 struct hda_codec *codec = private_data;
6285 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006286 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006287}
6288
6289static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6290 const struct alc_fixup *fix, int action)
6291{
6292 struct alc_spec *spec = codec->spec;
6293 switch (action) {
6294 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006295 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006296 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006297 /* fallthru */
6298 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006299 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006300 break;
6301 }
6302}
6303
Dylan Reid08a978d2012-11-18 22:56:40 -08006304static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6305 const struct alc_fixup *fix,
6306 int action)
6307{
6308 struct alc_spec *spec = codec->spec;
6309
6310 if (action == ALC_FIXUP_ACT_PROBE)
6311 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6312 spec->autocfg.hp_pins[0]);
6313}
David Henningsson693b6132012-06-22 19:12:10 +02006314
Takashi Iwai1d045db2011-07-07 18:23:21 +02006315enum {
6316 ALC269_FIXUP_SONY_VAIO,
6317 ALC275_FIXUP_SONY_VAIO_GPIO2,
6318 ALC269_FIXUP_DELL_M101Z,
6319 ALC269_FIXUP_SKU_IGNORE,
6320 ALC269_FIXUP_ASUS_G73JW,
6321 ALC269_FIXUP_LENOVO_EAPD,
6322 ALC275_FIXUP_SONY_HWEQ,
6323 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006324 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006325 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006326 ALC269_FIXUP_QUANTA_MUTE,
6327 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006328 ALC269_FIXUP_AMIC,
6329 ALC269_FIXUP_DMIC,
6330 ALC269VB_FIXUP_AMIC,
6331 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006332 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006333 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006334 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006335 ALC269_FIXUP_LENOVO_DOCK,
6336 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006337 ALC271_FIXUP_AMIC_MIC2,
6338 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006339};
6340
6341static const struct alc_fixup alc269_fixups[] = {
6342 [ALC269_FIXUP_SONY_VAIO] = {
6343 .type = ALC_FIXUP_VERBS,
6344 .v.verbs = (const struct hda_verb[]) {
6345 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6346 {}
6347 }
6348 },
6349 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6350 .type = ALC_FIXUP_VERBS,
6351 .v.verbs = (const struct hda_verb[]) {
6352 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6353 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6354 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6355 { }
6356 },
6357 .chained = true,
6358 .chain_id = ALC269_FIXUP_SONY_VAIO
6359 },
6360 [ALC269_FIXUP_DELL_M101Z] = {
6361 .type = ALC_FIXUP_VERBS,
6362 .v.verbs = (const struct hda_verb[]) {
6363 /* Enables internal speaker */
6364 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6365 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6366 {}
6367 }
6368 },
6369 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006370 .type = ALC_FIXUP_FUNC,
6371 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006372 },
6373 [ALC269_FIXUP_ASUS_G73JW] = {
6374 .type = ALC_FIXUP_PINS,
6375 .v.pins = (const struct alc_pincfg[]) {
6376 { 0x17, 0x99130111 }, /* subwoofer */
6377 { }
6378 }
6379 },
6380 [ALC269_FIXUP_LENOVO_EAPD] = {
6381 .type = ALC_FIXUP_VERBS,
6382 .v.verbs = (const struct hda_verb[]) {
6383 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6384 {}
6385 }
6386 },
6387 [ALC275_FIXUP_SONY_HWEQ] = {
6388 .type = ALC_FIXUP_FUNC,
6389 .v.func = alc269_fixup_hweq,
6390 .chained = true,
6391 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6392 },
6393 [ALC271_FIXUP_DMIC] = {
6394 .type = ALC_FIXUP_FUNC,
6395 .v.func = alc271_fixup_dmic,
6396 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006397 [ALC269_FIXUP_PCM_44K] = {
6398 .type = ALC_FIXUP_FUNC,
6399 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006400 .chained = true,
6401 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006402 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006403 [ALC269_FIXUP_STEREO_DMIC] = {
6404 .type = ALC_FIXUP_FUNC,
6405 .v.func = alc269_fixup_stereo_dmic,
6406 },
Takashi Iwai24519912011-08-16 15:08:49 +02006407 [ALC269_FIXUP_QUANTA_MUTE] = {
6408 .type = ALC_FIXUP_FUNC,
6409 .v.func = alc269_fixup_quanta_mute,
6410 },
6411 [ALC269_FIXUP_LIFEBOOK] = {
6412 .type = ALC_FIXUP_PINS,
6413 .v.pins = (const struct alc_pincfg[]) {
6414 { 0x1a, 0x2101103f }, /* dock line-out */
6415 { 0x1b, 0x23a11040 }, /* dock mic-in */
6416 { }
6417 },
6418 .chained = true,
6419 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6420 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006421 [ALC269_FIXUP_AMIC] = {
6422 .type = ALC_FIXUP_PINS,
6423 .v.pins = (const struct alc_pincfg[]) {
6424 { 0x14, 0x99130110 }, /* speaker */
6425 { 0x15, 0x0121401f }, /* HP out */
6426 { 0x18, 0x01a19c20 }, /* mic */
6427 { 0x19, 0x99a3092f }, /* int-mic */
6428 { }
6429 },
6430 },
6431 [ALC269_FIXUP_DMIC] = {
6432 .type = ALC_FIXUP_PINS,
6433 .v.pins = (const struct alc_pincfg[]) {
6434 { 0x12, 0x99a3092f }, /* int-mic */
6435 { 0x14, 0x99130110 }, /* speaker */
6436 { 0x15, 0x0121401f }, /* HP out */
6437 { 0x18, 0x01a19c20 }, /* mic */
6438 { }
6439 },
6440 },
6441 [ALC269VB_FIXUP_AMIC] = {
6442 .type = ALC_FIXUP_PINS,
6443 .v.pins = (const struct alc_pincfg[]) {
6444 { 0x14, 0x99130110 }, /* speaker */
6445 { 0x18, 0x01a19c20 }, /* mic */
6446 { 0x19, 0x99a3092f }, /* int-mic */
6447 { 0x21, 0x0121401f }, /* HP out */
6448 { }
6449 },
6450 },
David Henningsson2267ea92012-01-03 08:45:56 +01006451 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006452 .type = ALC_FIXUP_PINS,
6453 .v.pins = (const struct alc_pincfg[]) {
6454 { 0x12, 0x99a3092f }, /* int-mic */
6455 { 0x14, 0x99130110 }, /* speaker */
6456 { 0x18, 0x01a19c20 }, /* mic */
6457 { 0x21, 0x0121401f }, /* HP out */
6458 { }
6459 },
6460 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006461 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6462 .type = ALC_FIXUP_FUNC,
6463 .v.func = alc269_fixup_mic1_mute,
6464 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006465 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6466 .type = ALC_FIXUP_FUNC,
6467 .v.func = alc269_fixup_mic2_mute,
6468 },
David Henningsson693b6132012-06-22 19:12:10 +02006469 [ALC269_FIXUP_INV_DMIC] = {
6470 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006471 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006472 },
David Henningsson108cc102012-07-20 10:37:25 +02006473 [ALC269_FIXUP_LENOVO_DOCK] = {
6474 .type = ALC_FIXUP_PINS,
6475 .v.pins = (const struct alc_pincfg[]) {
6476 { 0x19, 0x23a11040 }, /* dock mic */
6477 { 0x1b, 0x2121103f }, /* dock headphone */
6478 { }
6479 },
6480 .chained = true,
6481 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6482 },
6483 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6484 .type = ALC_FIXUP_FUNC,
6485 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6486 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006487 [ALC271_FIXUP_AMIC_MIC2] = {
6488 .type = ALC_FIXUP_PINS,
6489 .v.pins = (const struct alc_pincfg[]) {
6490 { 0x14, 0x99130110 }, /* speaker */
6491 { 0x19, 0x01a19c20 }, /* mic */
6492 { 0x1b, 0x99a7012f }, /* int-mic */
6493 { 0x21, 0x0121401f }, /* HP out */
6494 { }
6495 },
6496 },
6497 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6498 .type = ALC_FIXUP_FUNC,
6499 .v.func = alc271_hp_gate_mic_jack,
6500 .chained = true,
6501 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6502 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006503};
6504
6505static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006506 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6507 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006508 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006509 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006510 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006511 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006512 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006513 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006514 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6515 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6516 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6517 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6518 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006519 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6520 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6521 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6522 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6523 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006524 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006525 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006526 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006527 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6528 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6529 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6530 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6531 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006532 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006533 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006534 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006535 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006536 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006537 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006538 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006539
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006540#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006541 /* Below is a quirk table taken from the old code.
6542 * Basically the device should work as is without the fixup table.
6543 * If BIOS doesn't give a proper info, enable the corresponding
6544 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006545 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006546 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6547 ALC269_FIXUP_AMIC),
6548 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006549 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6550 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6551 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6552 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6553 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6554 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6555 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6556 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6557 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6558 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6559 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6560 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6561 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6562 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6563 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6564 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6565 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6566 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6567 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6568 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6569 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6570 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6571 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6572 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6573 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6574 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6575 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6576 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6577 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6578 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6579 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6580 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6581 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6582 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6583 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6584 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6585 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6586 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6587#endif
6588 {}
6589};
6590
6591static const struct alc_model_fixup alc269_fixup_models[] = {
6592 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6593 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006594 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6595 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6596 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006597 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006598 {}
6599};
6600
6601
Takashi Iwai546bb672012-03-07 08:37:19 +01006602static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006603{
Kailang Yang526af6e2012-03-07 08:25:20 +01006604 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006605 int val;
6606
Kailang Yang526af6e2012-03-07 08:25:20 +01006607 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006608 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006609
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006610 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006611 alc_write_coef_idx(codec, 0xf, 0x960b);
6612 alc_write_coef_idx(codec, 0xe, 0x8817);
6613 }
6614
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006615 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006616 alc_write_coef_idx(codec, 0xf, 0x960b);
6617 alc_write_coef_idx(codec, 0xe, 0x8814);
6618 }
6619
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006620 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006621 val = alc_read_coef_idx(codec, 0x04);
6622 /* Power up output pin */
6623 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6624 }
6625
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006626 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006627 val = alc_read_coef_idx(codec, 0xd);
6628 if ((val & 0x0c00) >> 10 != 0x1) {
6629 /* Capless ramp up clock control */
6630 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6631 }
6632 val = alc_read_coef_idx(codec, 0x17);
6633 if ((val & 0x01c0) >> 6 != 0x4) {
6634 /* Class D power on reset */
6635 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6636 }
6637 }
6638
6639 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6640 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6641
6642 val = alc_read_coef_idx(codec, 0x4); /* HP */
6643 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006644}
6645
6646/*
6647 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006648static int patch_alc269(struct hda_codec *codec)
6649{
6650 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006651 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006652
Takashi Iwai3de95172012-05-07 18:03:15 +02006653 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006654 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006655 return err;
6656
6657 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006658
Herton Ronaldo Krzesinski9f720bb92012-09-27 10:38:14 -03006659 alc_pick_fixup(codec, alc269_fixup_models,
6660 alc269_fixup_tbl, alc269_fixups);
6661 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6662
6663 alc_auto_parse_customize_define(codec);
6664
Kailang Yang065380f2013-01-10 10:25:48 +01006665 switch (codec->vendor_id) {
6666 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006667 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006668 switch (alc_get_coef0(codec) & 0x00f0) {
6669 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006670 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006671 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006672 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006673 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006674 break;
6675 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006676 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6677 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006678 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006679 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006680 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006681 case 0x0030:
6682 spec->codec_variant = ALC269_TYPE_ALC269VD;
6683 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006684 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006685 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006686 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006687 if (err < 0)
6688 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006689 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006690 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006691 break;
6692
6693 case 0x10ec0280:
6694 case 0x10ec0290:
6695 spec->codec_variant = ALC269_TYPE_ALC280;
6696 break;
6697 case 0x10ec0282:
6698 case 0x10ec0283:
6699 spec->codec_variant = ALC269_TYPE_ALC282;
6700 break;
6701 case 0x10ec0284:
6702 case 0x10ec0292:
6703 spec->codec_variant = ALC269_TYPE_ALC284;
6704 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006705 }
6706
Takashi Iwaia4297b52011-08-23 18:40:12 +02006707 /* automatic parse from the BIOS config */
6708 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006709 if (err < 0)
6710 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006711
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006712 if (!spec->no_analog && has_cdefine_beep(codec)) {
6713 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006714 if (err < 0)
6715 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006716 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006717 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006718
Takashi Iwai1d045db2011-07-07 18:23:21 +02006719 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006720#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006721 codec->patch_ops.resume = alc269_resume;
6722#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006723 spec->shutup = alc269_shutup;
6724
Takashi Iwai589876e2012-02-20 15:47:55 +01006725 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6726
Takashi Iwai1d045db2011-07-07 18:23:21 +02006727 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006728
6729 error:
6730 alc_free(codec);
6731 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006732}
6733
6734/*
6735 * ALC861
6736 */
6737
Takashi Iwai1d045db2011-07-07 18:23:21 +02006738static int alc861_parse_auto_config(struct hda_codec *codec)
6739{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006740 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006741 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6742 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006743}
6744
Takashi Iwai1d045db2011-07-07 18:23:21 +02006745/* Pin config fixes */
6746enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006747 ALC861_FIXUP_FSC_AMILO_PI1505,
6748 ALC861_FIXUP_AMP_VREF_0F,
6749 ALC861_FIXUP_NO_JACK_DETECT,
6750 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006751};
6752
Takashi Iwai31150f22012-01-30 10:54:08 +01006753/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6754static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6755 const struct alc_fixup *fix, int action)
6756{
6757 struct alc_spec *spec = codec->spec;
6758 unsigned int val;
6759
6760 if (action != ALC_FIXUP_ACT_INIT)
6761 return;
6762 val = snd_hda_codec_read(codec, 0x0f, 0,
6763 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6764 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6765 val |= AC_PINCTL_IN_EN;
6766 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006767 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006768 spec->keep_vref_in_automute = 1;
6769}
6770
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006771/* suppress the jack-detection */
6772static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6773 const struct alc_fixup *fix, int action)
6774{
6775 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6776 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006777}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006778
Takashi Iwai1d045db2011-07-07 18:23:21 +02006779static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006780 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006781 .type = ALC_FIXUP_PINS,
6782 .v.pins = (const struct alc_pincfg[]) {
6783 { 0x0b, 0x0221101f }, /* HP */
6784 { 0x0f, 0x90170310 }, /* speaker */
6785 { }
6786 }
6787 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006788 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006789 .type = ALC_FIXUP_FUNC,
6790 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006791 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006792 [ALC861_FIXUP_NO_JACK_DETECT] = {
6793 .type = ALC_FIXUP_FUNC,
6794 .v.func = alc_fixup_no_jack_detect,
6795 },
6796 [ALC861_FIXUP_ASUS_A6RP] = {
6797 .type = ALC_FIXUP_FUNC,
6798 .v.func = alc861_fixup_asus_amp_vref_0f,
6799 .chained = true,
6800 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6801 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006802};
6803
6804static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006805 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6806 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6807 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6808 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6809 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6810 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006811 {}
6812};
6813
6814/*
6815 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006816static int patch_alc861(struct hda_codec *codec)
6817{
6818 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006819 int err;
6820
Takashi Iwai3de95172012-05-07 18:03:15 +02006821 err = alc_alloc_spec(codec, 0x15);
6822 if (err < 0)
6823 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006824
Takashi Iwai3de95172012-05-07 18:03:15 +02006825 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006826
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006827 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6828 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006829
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006830 /* automatic parse from the BIOS config */
6831 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006832 if (err < 0)
6833 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006834
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006835 if (!spec->no_analog) {
6836 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006837 if (err < 0)
6838 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006839 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6840 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006841
Takashi Iwai1d045db2011-07-07 18:23:21 +02006842 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006843#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006844 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006845#endif
6846
Takashi Iwai589876e2012-02-20 15:47:55 +01006847 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6848
Takashi Iwai1d045db2011-07-07 18:23:21 +02006849 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006850
6851 error:
6852 alc_free(codec);
6853 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006854}
6855
6856/*
6857 * ALC861-VD support
6858 *
6859 * Based on ALC882
6860 *
6861 * In addition, an independent DAC
6862 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006863static int alc861vd_parse_auto_config(struct hda_codec *codec)
6864{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006865 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006866 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6867 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006868}
6869
Takashi Iwai1d045db2011-07-07 18:23:21 +02006870enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006871 ALC660VD_FIX_ASUS_GPIO1,
6872 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006873};
6874
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006875/* exclude VREF80 */
6876static void alc861vd_fixup_dallas(struct hda_codec *codec,
6877 const struct alc_fixup *fix, int action)
6878{
6879 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006880 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6881 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006882 }
6883}
6884
Takashi Iwai1d045db2011-07-07 18:23:21 +02006885static const struct alc_fixup alc861vd_fixups[] = {
6886 [ALC660VD_FIX_ASUS_GPIO1] = {
6887 .type = ALC_FIXUP_VERBS,
6888 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006889 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006890 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6891 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6892 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6893 { }
6894 }
6895 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006896 [ALC861VD_FIX_DALLAS] = {
6897 .type = ALC_FIXUP_FUNC,
6898 .v.func = alc861vd_fixup_dallas,
6899 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006900};
6901
6902static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006903 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006904 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006905 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006906 {}
6907};
6908
Takashi Iwai1d045db2011-07-07 18:23:21 +02006909/*
6910 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006911static int patch_alc861vd(struct hda_codec *codec)
6912{
6913 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006914 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006915
Takashi Iwai3de95172012-05-07 18:03:15 +02006916 err = alc_alloc_spec(codec, 0x0b);
6917 if (err < 0)
6918 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006919
Takashi Iwai3de95172012-05-07 18:03:15 +02006920 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006921
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006922 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6923 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006924
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006925 /* automatic parse from the BIOS config */
6926 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006927 if (err < 0)
6928 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006929
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006930 if (!spec->no_analog) {
6931 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006932 if (err < 0)
6933 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006934 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6935 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006936
Takashi Iwai1d045db2011-07-07 18:23:21 +02006937 codec->patch_ops = alc_patch_ops;
6938
Takashi Iwai1d045db2011-07-07 18:23:21 +02006939 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006940
Takashi Iwai589876e2012-02-20 15:47:55 +01006941 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6942
Takashi Iwai1d045db2011-07-07 18:23:21 +02006943 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006944
6945 error:
6946 alc_free(codec);
6947 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006948}
6949
6950/*
6951 * ALC662 support
6952 *
6953 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6954 * configuration. Each pin widget can choose any input DACs and a mixer.
6955 * Each ADC is connected from a mixer of all inputs. This makes possible
6956 * 6-channel independent captures.
6957 *
6958 * In addition, an independent DAC for the multi-playback (not used in this
6959 * driver yet).
6960 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006961
6962/*
6963 * BIOS auto configuration
6964 */
6965
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006966static int alc662_parse_auto_config(struct hda_codec *codec)
6967{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006968 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006969 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6970 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6971 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006972
Kailang Yang6227cdc2010-02-25 08:36:52 +01006973 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6974 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006975 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006976 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006977 ssids = alc662_ssids;
6978 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006979}
6980
Todd Broch6be79482010-12-07 16:51:05 -08006981static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006982 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006983{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006984 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006985 return;
Todd Broch6be79482010-12-07 16:51:05 -08006986 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6987 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6988 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6989 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6990 (0 << AC_AMPCAP_MUTE_SHIFT)))
6991 printk(KERN_WARNING
6992 "hda_codec: failed to override amp caps for NID 0x2\n");
6993}
6994
David Henningsson6cb3b702010-09-09 08:51:44 +02006995enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006996 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006997 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006998 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006999 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02007000 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007001 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02007002 ALC662_FIXUP_ASUS_MODE1,
7003 ALC662_FIXUP_ASUS_MODE2,
7004 ALC662_FIXUP_ASUS_MODE3,
7005 ALC662_FIXUP_ASUS_MODE4,
7006 ALC662_FIXUP_ASUS_MODE5,
7007 ALC662_FIXUP_ASUS_MODE6,
7008 ALC662_FIXUP_ASUS_MODE7,
7009 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01007010 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02007011 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02007012 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02007013};
7014
7015static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04007016 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007017 .type = ALC_FIXUP_PINS,
7018 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04007019 { 0x15, 0x99130112 }, /* subwoofer */
7020 { }
7021 }
7022 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007023 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007024 .type = ALC_FIXUP_PINS,
7025 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02007026 { 0x17, 0x99130112 }, /* subwoofer */
7027 { }
7028 }
7029 },
Todd Broch6be79482010-12-07 16:51:05 -08007030 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007031 .type = ALC_FIXUP_FUNC,
7032 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007033 },
7034 [ALC662_FIXUP_CZC_P10T] = {
7035 .type = ALC_FIXUP_VERBS,
7036 .v.verbs = (const struct hda_verb[]) {
7037 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7038 {}
7039 }
7040 },
David Henningsson94024cd2011-04-29 14:10:55 +02007041 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02007042 .type = ALC_FIXUP_FUNC,
7043 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02007044 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007045 [ALC662_FIXUP_HP_RP5800] = {
7046 .type = ALC_FIXUP_PINS,
7047 .v.pins = (const struct alc_pincfg[]) {
7048 { 0x14, 0x0221201f }, /* HP out */
7049 { }
7050 },
7051 .chained = true,
7052 .chain_id = ALC662_FIXUP_SKU_IGNORE
7053 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007054 [ALC662_FIXUP_ASUS_MODE1] = {
7055 .type = ALC_FIXUP_PINS,
7056 .v.pins = (const struct alc_pincfg[]) {
7057 { 0x14, 0x99130110 }, /* speaker */
7058 { 0x18, 0x01a19c20 }, /* mic */
7059 { 0x19, 0x99a3092f }, /* int-mic */
7060 { 0x21, 0x0121401f }, /* HP out */
7061 { }
7062 },
7063 .chained = true,
7064 .chain_id = ALC662_FIXUP_SKU_IGNORE
7065 },
7066 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007067 .type = ALC_FIXUP_PINS,
7068 .v.pins = (const struct alc_pincfg[]) {
7069 { 0x14, 0x99130110 }, /* speaker */
7070 { 0x18, 0x01a19820 }, /* mic */
7071 { 0x19, 0x99a3092f }, /* int-mic */
7072 { 0x1b, 0x0121401f }, /* HP out */
7073 { }
7074 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007075 .chained = true,
7076 .chain_id = ALC662_FIXUP_SKU_IGNORE
7077 },
7078 [ALC662_FIXUP_ASUS_MODE3] = {
7079 .type = ALC_FIXUP_PINS,
7080 .v.pins = (const struct alc_pincfg[]) {
7081 { 0x14, 0x99130110 }, /* speaker */
7082 { 0x15, 0x0121441f }, /* HP */
7083 { 0x18, 0x01a19840 }, /* mic */
7084 { 0x19, 0x99a3094f }, /* int-mic */
7085 { 0x21, 0x01211420 }, /* HP2 */
7086 { }
7087 },
7088 .chained = true,
7089 .chain_id = ALC662_FIXUP_SKU_IGNORE
7090 },
7091 [ALC662_FIXUP_ASUS_MODE4] = {
7092 .type = ALC_FIXUP_PINS,
7093 .v.pins = (const struct alc_pincfg[]) {
7094 { 0x14, 0x99130110 }, /* speaker */
7095 { 0x16, 0x99130111 }, /* speaker */
7096 { 0x18, 0x01a19840 }, /* mic */
7097 { 0x19, 0x99a3094f }, /* int-mic */
7098 { 0x21, 0x0121441f }, /* HP */
7099 { }
7100 },
7101 .chained = true,
7102 .chain_id = ALC662_FIXUP_SKU_IGNORE
7103 },
7104 [ALC662_FIXUP_ASUS_MODE5] = {
7105 .type = ALC_FIXUP_PINS,
7106 .v.pins = (const struct alc_pincfg[]) {
7107 { 0x14, 0x99130110 }, /* speaker */
7108 { 0x15, 0x0121441f }, /* HP */
7109 { 0x16, 0x99130111 }, /* speaker */
7110 { 0x18, 0x01a19840 }, /* mic */
7111 { 0x19, 0x99a3094f }, /* int-mic */
7112 { }
7113 },
7114 .chained = true,
7115 .chain_id = ALC662_FIXUP_SKU_IGNORE
7116 },
7117 [ALC662_FIXUP_ASUS_MODE6] = {
7118 .type = ALC_FIXUP_PINS,
7119 .v.pins = (const struct alc_pincfg[]) {
7120 { 0x14, 0x99130110 }, /* speaker */
7121 { 0x15, 0x01211420 }, /* HP2 */
7122 { 0x18, 0x01a19840 }, /* mic */
7123 { 0x19, 0x99a3094f }, /* int-mic */
7124 { 0x1b, 0x0121441f }, /* HP */
7125 { }
7126 },
7127 .chained = true,
7128 .chain_id = ALC662_FIXUP_SKU_IGNORE
7129 },
7130 [ALC662_FIXUP_ASUS_MODE7] = {
7131 .type = ALC_FIXUP_PINS,
7132 .v.pins = (const struct alc_pincfg[]) {
7133 { 0x14, 0x99130110 }, /* speaker */
7134 { 0x17, 0x99130111 }, /* speaker */
7135 { 0x18, 0x01a19840 }, /* mic */
7136 { 0x19, 0x99a3094f }, /* int-mic */
7137 { 0x1b, 0x01214020 }, /* HP */
7138 { 0x21, 0x0121401f }, /* HP */
7139 { }
7140 },
7141 .chained = true,
7142 .chain_id = ALC662_FIXUP_SKU_IGNORE
7143 },
7144 [ALC662_FIXUP_ASUS_MODE8] = {
7145 .type = ALC_FIXUP_PINS,
7146 .v.pins = (const struct alc_pincfg[]) {
7147 { 0x14, 0x99130110 }, /* speaker */
7148 { 0x12, 0x99a30970 }, /* int-mic */
7149 { 0x15, 0x01214020 }, /* HP */
7150 { 0x17, 0x99130111 }, /* speaker */
7151 { 0x18, 0x01a19840 }, /* mic */
7152 { 0x21, 0x0121401f }, /* HP */
7153 { }
7154 },
7155 .chained = true,
7156 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007157 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007158 [ALC662_FIXUP_NO_JACK_DETECT] = {
7159 .type = ALC_FIXUP_FUNC,
7160 .v.func = alc_fixup_no_jack_detect,
7161 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007162 [ALC662_FIXUP_ZOTAC_Z68] = {
7163 .type = ALC_FIXUP_PINS,
7164 .v.pins = (const struct alc_pincfg[]) {
7165 { 0x1b, 0x02214020 }, /* Front HP */
7166 { }
7167 }
7168 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007169 [ALC662_FIXUP_INV_DMIC] = {
7170 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007171 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007172 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007173};
7174
Takashi Iwaia9111322011-05-02 11:30:18 +02007175static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007176 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007177 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007178 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007179 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007180 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007181 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007182 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007183 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007184 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007185 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007186 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007187 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007188 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007189
7190#if 0
7191 /* Below is a quirk table taken from the old code.
7192 * Basically the device should work as is without the fixup table.
7193 * If BIOS doesn't give a proper info, enable the corresponding
7194 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007195 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007196 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7197 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7198 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7199 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7200 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7201 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7202 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7203 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7204 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7205 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7206 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7207 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7208 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7209 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7210 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7211 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7212 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7213 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7214 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7215 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7216 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7217 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7218 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7219 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7220 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7221 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7222 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7223 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7224 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7225 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7226 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7227 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7228 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7229 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7230 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7231 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7232 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7233 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7234 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7235 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7236 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7237 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7238 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7239 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7240 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7241 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7242 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7243 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7244 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7245 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7246#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007247 {}
7248};
7249
Todd Broch6be79482010-12-07 16:51:05 -08007250static const struct alc_model_fixup alc662_fixup_models[] = {
7251 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007252 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7253 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7254 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7255 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7256 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7257 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7258 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7259 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007260 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007261 {}
7262};
David Henningsson6cb3b702010-09-09 08:51:44 +02007263
Kailang Yang8663ff72012-06-29 09:35:52 +02007264static void alc662_fill_coef(struct hda_codec *codec)
7265{
7266 int val, coef;
7267
7268 coef = alc_get_coef0(codec);
7269
7270 switch (codec->vendor_id) {
7271 case 0x10ec0662:
7272 if ((coef & 0x00f0) == 0x0030) {
7273 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7274 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7275 }
7276 break;
7277 case 0x10ec0272:
7278 case 0x10ec0273:
7279 case 0x10ec0663:
7280 case 0x10ec0665:
7281 case 0x10ec0670:
7282 case 0x10ec0671:
7283 case 0x10ec0672:
7284 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7285 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7286 break;
7287 }
7288}
David Henningsson6cb3b702010-09-09 08:51:44 +02007289
Takashi Iwai1d045db2011-07-07 18:23:21 +02007290/*
7291 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007292static int patch_alc662(struct hda_codec *codec)
7293{
7294 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007295 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007296
Takashi Iwai3de95172012-05-07 18:03:15 +02007297 err = alc_alloc_spec(codec, 0x0b);
7298 if (err < 0)
7299 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007300
Takashi Iwai3de95172012-05-07 18:03:15 +02007301 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007302
Takashi Iwai53c334a2011-08-23 18:27:14 +02007303 /* handle multiple HPs as is */
7304 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7305
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007306 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7307
Kailang Yang8663ff72012-06-29 09:35:52 +02007308 spec->init_hook = alc662_fill_coef;
7309 alc662_fill_coef(codec);
7310
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007311 alc_pick_fixup(codec, alc662_fixup_models,
7312 alc662_fixup_tbl, alc662_fixups);
7313 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7314
7315 alc_auto_parse_customize_define(codec);
7316
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007317 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007318 codec->bus->pci->subsystem_vendor == 0x1025 &&
7319 spec->cdefine.platform_type == 1) {
7320 if (alc_codec_rename(codec, "ALC272X") < 0)
7321 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007322 }
Kailang Yang274693f2009-12-03 10:07:50 +01007323
Takashi Iwaib9c51062011-08-24 18:08:07 +02007324 /* automatic parse from the BIOS config */
7325 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007326 if (err < 0)
7327 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007328
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007329 if (!spec->no_analog && has_cdefine_beep(codec)) {
7330 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007331 if (err < 0)
7332 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007333 switch (codec->vendor_id) {
7334 case 0x10ec0662:
7335 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7336 break;
7337 case 0x10ec0272:
7338 case 0x10ec0663:
7339 case 0x10ec0665:
7340 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7341 break;
7342 case 0x10ec0273:
7343 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7344 break;
7345 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007346 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007347
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007348 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02007349 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007350
Takashi Iwai589876e2012-02-20 15:47:55 +01007351 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7352
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007353 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007354
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007355 error:
7356 alc_free(codec);
7357 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007358}
7359
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007360/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007361 * ALC680 support
7362 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007363
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007364static int alc680_parse_auto_config(struct hda_codec *codec)
7365{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007366 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007367}
7368
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007369/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007370 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007371static int patch_alc680(struct hda_codec *codec)
7372{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007373 int err;
7374
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007375 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007376 err = alc_alloc_spec(codec, 0);
7377 if (err < 0)
7378 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007379
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007380 /* automatic parse from the BIOS config */
7381 err = alc680_parse_auto_config(codec);
7382 if (err < 0) {
7383 alc_free(codec);
7384 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007385 }
7386
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007387 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007388
7389 return 0;
7390}
7391
7392/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007393 * patch entries
7394 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007395static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007396 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007397 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007398 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007399 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007400 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007401 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007402 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007403 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007404 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007405 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007406 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007407 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007408 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007409 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007410 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007411 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007412 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007413 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007414 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7415 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7416 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007417 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007418 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007419 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7420 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007421 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7422 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007423 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007424 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007425 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007426 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007427 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007428 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007429 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007430 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007431 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007432 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007433 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007434 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007435 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007436 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007437 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007438 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007439 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007440 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007441 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007442 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007443 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007444 {} /* terminator */
7445};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007446
7447MODULE_ALIAS("snd-hda-codec-id:10ec*");
7448
7449MODULE_LICENSE("GPL");
7450MODULE_DESCRIPTION("Realtek HD-audio codec");
7451
7452static struct hda_codec_preset_list realtek_list = {
7453 .preset = snd_hda_preset_realtek,
7454 .owner = THIS_MODULE,
7455};
7456
7457static int __init patch_realtek_init(void)
7458{
7459 return snd_hda_add_codec_preset(&realtek_list);
7460}
7461
7462static void __exit patch_realtek_exit(void)
7463{
7464 snd_hda_delete_codec_preset(&realtek_list);
7465}
7466
7467module_init(patch_realtek_init)
7468module_exit(patch_realtek_exit)