blob: 06c0c12d4fec8b50cff8e76a91c7898ac2a0ed3d [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 Woithe7cf51e482006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
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"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Takashi Iwai1d045db2011-07-07 18:23:21 +020037/* unsol event tags */
38#define ALC_FRONT_EVENT 0x01
39#define ALC_DCVOL_EVENT 0x02
40#define ALC_HP_EVENT 0x04
41#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020042
Kailang Yangdf694da2005-12-05 19:42:22 +010043/* for GPIO Poll */
44#define GPIO_MASK 0x03
45
Takashi Iwai4a79ba32009-04-22 16:31:35 +020046/* extra amp-initialization sequence types */
47enum {
48 ALC_INIT_NONE,
49 ALC_INIT_DEFAULT,
50 ALC_INIT_GPIO1,
51 ALC_INIT_GPIO2,
52 ALC_INIT_GPIO3,
53};
54
Kailang Yangda00c242010-03-19 11:23:45 +010055struct alc_customize_define {
56 unsigned int sku_cfg;
57 unsigned char port_connectivity;
58 unsigned char check_sum;
59 unsigned char customization;
60 unsigned char external_amp;
61 unsigned int enable_pcbeep:1;
62 unsigned int platform_type:1;
63 unsigned int swap:1;
64 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020065 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010066};
67
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010068struct alc_fixup;
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwaid922b512011-04-28 12:18:53 +020076enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020077 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020080};
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082struct alc_spec {
83 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020084 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020086 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010087 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Takashi Iwai2d9c6482009-10-13 08:06:55 +020089 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020090 * don't forget NULL
91 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020092 */
93 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Takashi Iwaiaa563af2009-07-31 10:05:11 +020095 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020096 const struct hda_pcm_stream *stream_analog_playback;
97 const struct hda_pcm_stream *stream_analog_capture;
98 const struct hda_pcm_stream *stream_analog_alt_playback;
99 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200101 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200102 const struct hda_pcm_stream *stream_digital_playback;
103 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200106 struct hda_multi_out multiout; /* playback set-up
107 * max_channels, dacs must be set
108 * dig_out_nid and hp_nid are optional
109 */
Takashi Iwai63300792008-01-24 15:31:36 +0100110 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100111 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100112 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 /* capture */
115 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200116 const hda_nid_t *adc_nids;
117 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200118 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200119 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwai527e4d72011-10-27 16:33:27 +0200120 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
121 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Takashi Iwai840b64c2010-07-13 22:49:01 +0200123 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200124 hda_nid_t cur_adc;
125 unsigned int cur_adc_stream_tag;
126 unsigned int cur_adc_format;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200129 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 const struct hda_input_mux *input_mux;
131 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200132 hda_nid_t ext_mic_pin;
133 hda_nid_t dock_mic_pin;
134 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100137 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200139 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200140 int const_channel_count;
141 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100144 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200145
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200146 /* dynamic controls, init_verbs and input_mux */
147 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100148 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200149 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200150 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200151 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200152 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
153 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200154 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
155 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
156 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100157
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100158 /* hooks */
159 void (*init_hook)(struct hda_codec *codec);
160 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100161#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500162 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100163#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200164 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200165 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100166
Takashi Iwai834be882006-03-01 14:16:17 +0100167 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200168 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200169 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200170 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200171 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200172 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200173 unsigned int automute_speaker:1; /* automute speaker outputs */
174 unsigned int automute_lo:1; /* automute LO outputs */
175 unsigned int detect_hp:1; /* Headphone detection enabled */
176 unsigned int detect_lo:1; /* Line-out detection enabled */
177 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
178 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200179
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100180 /* other flags */
181 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200182 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100183 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200184 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200185 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwaid922b512011-04-28 12:18:53 +0200186
187 /* auto-mute control */
188 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200189 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200190
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200191 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200192 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100193
Takashi Iwai2134ea42008-01-10 16:53:55 +0100194 /* for virtual master */
195 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200196#ifdef CONFIG_SND_HDA_POWER_SAVE
197 struct hda_loopback_check loopback;
198#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200199
200 /* for PLL fix */
201 hda_nid_t pll_nid;
202 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200203 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100204
205 /* fix-up list */
206 int fixup_id;
207 const struct alc_fixup *fixup_list;
208 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200209
210 /* multi-io */
211 int multi_ios;
212 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200213
214 /* bind volumes */
215 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100216};
217
Takashi Iwai1d045db2011-07-07 18:23:21 +0200218#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Takashi Iwai44c02402011-07-08 15:14:19 +0200220static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
221 int dir, unsigned int bits)
222{
223 if (!nid)
224 return false;
225 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
226 if (query_amp_caps(codec, nid, dir) & bits)
227 return true;
228 return false;
229}
230
231#define nid_has_mute(codec, nid, dir) \
232 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
233#define nid_has_volume(codec, nid, dir) \
234 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236/*
237 * input MUX handling
238 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200239static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
240 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
242 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
243 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200244 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
245 if (mux_idx >= spec->num_mux_defs)
246 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100247 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
248 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200249 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200252static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
253 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
256 struct alc_spec *spec = codec->spec;
257 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
258
259 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
260 return 0;
261}
262
Takashi Iwai21268962011-07-07 15:01:13 +0200263static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Takashi Iwai21268962011-07-07 15:01:13 +0200265 struct alc_spec *spec = codec->spec;
266 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
267
268 if (spec->cur_adc && spec->cur_adc != new_adc) {
269 /* stream is running, let's swap the current ADC */
270 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
271 spec->cur_adc = new_adc;
272 snd_hda_codec_setup_stream(codec, new_adc,
273 spec->cur_adc_stream_tag, 0,
274 spec->cur_adc_format);
275 return true;
276 }
277 return false;
278}
279
280/* select the given imux item; either unmute exclusively or select the route */
281static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
282 unsigned int idx, bool force)
283{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100285 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100286 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100287 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200288 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Takashi Iwaicd896c32008-11-18 12:36:33 +0100290 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
291 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100292 if (!imux->num_items && mux_idx > 0)
293 imux = &spec->input_mux[0];
Takashi Iwaicd896c32008-11-18 12:36:33 +0100294
Takashi Iwai21268962011-07-07 15:01:13 +0200295 if (idx >= imux->num_items)
296 idx = imux->num_items - 1;
297 if (spec->cur_mux[adc_idx] == idx && !force)
298 return 0;
299 spec->cur_mux[adc_idx] = idx;
300
301 if (spec->dyn_adc_switch) {
302 alc_dyn_adc_pcm_resetup(codec, idx);
303 adc_idx = spec->dyn_adc_idx[idx];
304 }
305
306 nid = spec->capsrc_nids ?
307 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
308
309 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100310 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
311 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200312 return 1;
313
Takashi Iwaia22d5432009-07-27 12:54:26 +0200314 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200315 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100316 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100317 int active = imux->items[idx].index;
318 for (i = 0; i < num_conns; i++) {
319 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
320 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100321 HDA_AMP_MUTE, v);
322 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100323 } else {
324 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200325 snd_hda_codec_write_cache(codec, nid, 0,
326 AC_VERB_SET_CONNECT_SEL,
327 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100328 }
Takashi Iwai21268962011-07-07 15:01:13 +0200329 return 1;
330}
331
332static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
333 struct snd_ctl_elem_value *ucontrol)
334{
335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
337 return alc_mux_select(codec, adc_idx,
338 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100339}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100342 * set up the input pin config (depending on the given auto-pin type)
343 */
344static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
345 int auto_pin_type)
346{
347 unsigned int val = PIN_IN;
348
Takashi Iwai86e29592010-09-09 14:50:17 +0200349 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100350 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200351 unsigned int oldval;
352 oldval = snd_hda_codec_read(codec, nid, 0,
353 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100354 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100355 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200356 /* if the default pin setup is vref50, we give it priority */
357 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100358 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200359 else if (pincap & AC_PINCAP_VREF_50)
360 val = PIN_VREF50;
361 else if (pincap & AC_PINCAP_VREF_100)
362 val = PIN_VREF100;
363 else if (pincap & AC_PINCAP_VREF_GRD)
364 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100365 }
366 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
367}
368
369/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200370 * Append the given mixer and verb elements for the later use
371 * The mixer array is referred in build_controls(), and init_verbs are
372 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100373 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200374static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100375{
376 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
377 return;
378 spec->mixers[spec->num_mixers++] = mix;
379}
380
381static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
382{
383 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
384 return;
385 spec->init_verbs[spec->num_init_verbs++] = verb;
386}
387
388/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200389 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100390 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200391/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200392static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200393 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
394 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
395 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
396 { }
397};
398
Takashi Iwaia9111322011-05-02 11:30:18 +0200399static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200400 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
401 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
402 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
403 { }
404};
405
Takashi Iwaia9111322011-05-02 11:30:18 +0200406static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200407 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
408 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
409 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
410 { }
411};
412
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200413/*
414 * Fix hardware PLL issue
415 * On some codecs, the analog PLL gating control must be off while
416 * the default value is 1.
417 */
418static void alc_fix_pll(struct hda_codec *codec)
419{
420 struct alc_spec *spec = codec->spec;
421 unsigned int val;
422
423 if (!spec->pll_nid)
424 return;
425 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
426 spec->pll_coef_idx);
427 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
428 AC_VERB_GET_PROC_COEF, 0);
429 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
430 spec->pll_coef_idx);
431 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
432 val & ~(1 << spec->pll_coef_bit));
433}
434
435static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
436 unsigned int coef_idx, unsigned int coef_bit)
437{
438 struct alc_spec *spec = codec->spec;
439 spec->pll_nid = nid;
440 spec->pll_coef_idx = coef_idx;
441 spec->pll_coef_bit = coef_bit;
442 alc_fix_pll(codec);
443}
444
Takashi Iwai1d045db2011-07-07 18:23:21 +0200445/*
446 * Jack-reporting via input-jack layer
447 */
448
449/* initialization of jacks; currently checks only a few known pins */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200450static int alc_init_jacks(struct hda_codec *codec)
451{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100452#ifdef CONFIG_SND_HDA_INPUT_JACK
Kailang Yang9ad0e492010-09-14 23:22:00 +0200453 struct alc_spec *spec = codec->spec;
454 int err;
455 unsigned int hp_nid = spec->autocfg.hp_pins[0];
Takashi Iwai21268962011-07-07 15:01:13 +0200456 unsigned int mic_nid = spec->ext_mic_pin;
457 unsigned int dock_nid = spec->dock_mic_pin;
Kailang Yang9ad0e492010-09-14 23:22:00 +0200458
Takashi Iwai265a0242010-09-21 11:26:21 +0200459 if (hp_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100460 err = snd_hda_input_jack_add(codec, hp_nid,
461 SND_JACK_HEADPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200462 if (err < 0)
463 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100464 snd_hda_input_jack_report(codec, hp_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200465 }
Kailang Yang9ad0e492010-09-14 23:22:00 +0200466
Takashi Iwai265a0242010-09-21 11:26:21 +0200467 if (mic_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100468 err = snd_hda_input_jack_add(codec, mic_nid,
469 SND_JACK_MICROPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200470 if (err < 0)
471 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100472 snd_hda_input_jack_report(codec, mic_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200473 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200474 if (dock_nid) {
475 err = snd_hda_input_jack_add(codec, dock_nid,
476 SND_JACK_MICROPHONE, NULL);
477 if (err < 0)
478 return err;
479 snd_hda_input_jack_report(codec, dock_nid);
480 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100481#endif /* CONFIG_SND_HDA_INPUT_JACK */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200482 return 0;
483}
Kailang Yang9ad0e492010-09-14 23:22:00 +0200484
Takashi Iwai1d045db2011-07-07 18:23:21 +0200485/*
486 * Jack detections for HP auto-mute and mic-switch
487 */
488
489/* check each pin in the given array; returns true if any of them is plugged */
490static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200491{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200492 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200493
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200494 for (i = 0; i < num_pins; i++) {
495 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200496 if (!nid)
497 break;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100498 snd_hda_input_jack_report(codec, nid);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200499 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200500 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 return present;
502}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200503
Takashi Iwai1d045db2011-07-07 18:23:21 +0200504/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200505static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200506 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507{
508 struct alc_spec *spec = codec->spec;
509 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200510 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200511 int i;
512
513 for (i = 0; i < num_pins; i++) {
514 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200515 if (!nid)
516 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200517 switch (spec->automute_mode) {
518 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200519 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200520 AC_VERB_SET_PIN_WIDGET_CONTROL,
521 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200522 break;
523 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200524 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200525 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200526 break;
527 case ALC_AUTOMUTE_MIXER:
528 nid = spec->automute_mixer_nid[i];
529 if (!nid)
530 break;
531 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200533 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200534 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200535 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200536 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200537 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200538}
539
David Henningsson42cf0d02011-09-20 12:04:56 +0200540/* Toggle outputs muting */
541static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200542{
543 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200544 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200545
Takashi Iwaic0a20262011-06-10 15:28:15 +0200546 /* Control HP pins/amps depending on master_mute state;
547 * in general, HP pins/amps control should be enabled in all cases,
548 * but currently set only for master_mute, just to be safe
549 */
550 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
551 spec->autocfg.hp_pins, spec->master_mute, true);
552
David Henningsson42cf0d02011-09-20 12:04:56 +0200553 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200554 on = 0;
555 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200556 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200557 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200559 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200560
561 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200562 /* if LO is a copy of either HP or Speaker, don't need to handle it */
563 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
564 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200565 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200566 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200567 on = 0;
568 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200569 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200571 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200572 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200573}
574
David Henningsson42cf0d02011-09-20 12:04:56 +0200575static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200576{
577 struct alc_spec *spec = codec->spec;
578 if (spec->automute_hook)
579 spec->automute_hook(codec);
580 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200581 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200582}
583
Takashi Iwai1d045db2011-07-07 18:23:21 +0200584/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200585static void alc_hp_automute(struct hda_codec *codec)
586{
587 struct alc_spec *spec = codec->spec;
588
David Henningsson42cf0d02011-09-20 12:04:56 +0200589 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
591 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200593 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200594 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200595}
596
Takashi Iwai1d045db2011-07-07 18:23:21 +0200597/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200598static void alc_line_automute(struct hda_codec *codec)
599{
600 struct alc_spec *spec = codec->spec;
601
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200602 /* check LO jack only when it's different from HP */
603 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
604 return;
605
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200606 spec->line_jack_present =
607 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
608 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200609 if (!spec->automute_speaker || !spec->detect_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 Iwai8d087c72011-06-28 12:45:47 +0200614#define get_connection_index(codec, mux, nid) \
615 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200616
Takashi Iwai1d045db2011-07-07 18:23:21 +0200617/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200618static void alc_mic_automute(struct hda_codec *codec)
619{
620 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200621 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200622
Takashi Iwai21268962011-07-07 15:01:13 +0200623 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200624 return;
625 if (snd_BUG_ON(!spec->adc_nids))
626 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200627 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200628 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200629
Takashi Iwai21268962011-07-07 15:01:13 +0200630 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
631 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
632 else if (spec->dock_mic_idx >= 0 &&
633 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
634 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
635 else
636 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Takashi Iwai6c819492009-08-10 18:47:44 +0200637
Takashi Iwai21268962011-07-07 15:01:13 +0200638 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
639 if (spec->dock_mic_idx >= 0)
640 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200641}
642
Kailang Yangc9b58002007-10-16 14:30:01 +0200643/* unsolicited event for HP jack sensing */
644static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
645{
646 if (codec->vendor_id == 0x10ec0880)
647 res >>= 28;
648 else
649 res >>= 26;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200650 switch (res) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200651 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200652 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200653 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200654 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200655 alc_line_automute(codec);
656 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200657 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200658 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200659 break;
660 }
Kailang Yang7fb0d782008-10-15 11:12:35 +0200661}
662
Takashi Iwai1d045db2011-07-07 18:23:21 +0200663/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200664static void alc_inithook(struct hda_codec *codec)
665{
Takashi Iwaid922b512011-04-28 12:18:53 +0200666 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200667 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200668 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200669}
670
Kailang Yangf9423e72008-05-27 12:32:25 +0200671/* additional initialization for ALC888 variants */
672static void alc888_coef_init(struct hda_codec *codec)
673{
674 unsigned int tmp;
675
676 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
677 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
678 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100679 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200680 /* alc888S-VC */
681 snd_hda_codec_read(codec, 0x20, 0,
682 AC_VERB_SET_PROC_COEF, 0x830);
683 else
684 /* alc888-VB */
685 snd_hda_codec_read(codec, 0x20, 0,
686 AC_VERB_SET_PROC_COEF, 0x3030);
687}
688
Takashi Iwai1d045db2011-07-07 18:23:21 +0200689/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200690static void alc889_coef_init(struct hda_codec *codec)
691{
692 unsigned int tmp;
693
694 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
695 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
696 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
698}
699
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100700/* turn on/off EAPD control (only if available) */
701static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
702{
703 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
704 return;
705 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
706 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
707 on ? 2 : 0);
708}
709
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200710/* turn on/off EAPD controls of the codec */
711static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
712{
713 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200714 static hda_nid_t pins[] = {
715 0x0f, 0x10, 0x14, 0x15, 0
716 };
717 hda_nid_t *p;
718 for (p = pins; *p; p++)
719 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200720}
721
Takashi Iwai1c7161532011-04-07 10:37:16 +0200722/* generic shutup callback;
723 * just turning off EPAD and a little pause for avoiding pop-noise
724 */
725static void alc_eapd_shutup(struct hda_codec *codec)
726{
727 alc_auto_setup_eapd(codec, false);
728 msleep(200);
729}
730
Takashi Iwai1d045db2011-07-07 18:23:21 +0200731/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200732static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200733{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200734 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200735
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200736 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200737 switch (type) {
738 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200739 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
740 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200741 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200742 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
743 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200744 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200745 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
746 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200747 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200748 switch (codec->vendor_id) {
749 case 0x10ec0260:
750 snd_hda_codec_write(codec, 0x1a, 0,
751 AC_VERB_SET_COEF_INDEX, 7);
752 tmp = snd_hda_codec_read(codec, 0x1a, 0,
753 AC_VERB_GET_PROC_COEF, 0);
754 snd_hda_codec_write(codec, 0x1a, 0,
755 AC_VERB_SET_COEF_INDEX, 7);
756 snd_hda_codec_write(codec, 0x1a, 0,
757 AC_VERB_SET_PROC_COEF,
758 tmp | 0x2010);
759 break;
760 case 0x10ec0262:
761 case 0x10ec0880:
762 case 0x10ec0882:
763 case 0x10ec0883:
764 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100765 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100766 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200767 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200768 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200769 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200771 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100772#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200773 case 0x10ec0267:
774 case 0x10ec0268:
775 snd_hda_codec_write(codec, 0x20, 0,
776 AC_VERB_SET_COEF_INDEX, 7);
777 tmp = snd_hda_codec_read(codec, 0x20, 0,
778 AC_VERB_GET_PROC_COEF, 0);
779 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200780 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200781 snd_hda_codec_write(codec, 0x20, 0,
782 AC_VERB_SET_PROC_COEF,
783 tmp | 0x3000);
784 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100785#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200786 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200787 break;
788 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200789}
Kailang Yangea1fb292008-08-26 12:58:38 +0200790
Takashi Iwai1d045db2011-07-07 18:23:21 +0200791/*
792 * Auto-Mute mode mixer enum support
793 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200794static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_info *uinfo)
796{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct alc_spec *spec = codec->spec;
799 static const char * const texts2[] = {
800 "Disabled", "Enabled"
801 };
802 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200803 "Disabled", "Speaker Only", "Line-Out+Speaker"
804 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200805 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200806
807 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
808 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200809 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200810 uinfo->value.enumerated.items = 3;
811 texts = texts3;
812 } else {
813 uinfo->value.enumerated.items = 2;
814 texts = texts2;
815 }
816 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
817 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200818 strcpy(uinfo->value.enumerated.name,
819 texts[uinfo->value.enumerated.item]);
820 return 0;
821}
822
823static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
824 struct snd_ctl_elem_value *ucontrol)
825{
826 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
827 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200828 unsigned int val = 0;
829 if (spec->automute_speaker)
830 val++;
831 if (spec->automute_lo)
832 val++;
833
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200834 ucontrol->value.enumerated.item[0] = val;
835 return 0;
836}
837
838static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
840{
841 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
842 struct alc_spec *spec = codec->spec;
843
844 switch (ucontrol->value.enumerated.item[0]) {
845 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200846 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200847 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200848 spec->automute_speaker = 0;
849 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200850 break;
851 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200852 if (spec->automute_speaker_possible) {
853 if (!spec->automute_lo && spec->automute_speaker)
854 return 0;
855 spec->automute_speaker = 1;
856 spec->automute_lo = 0;
857 } else if (spec->automute_lo_possible) {
858 if (spec->automute_lo)
859 return 0;
860 spec->automute_lo = 1;
861 } else
862 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200863 break;
864 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200865 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200866 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200867 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200868 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200869 spec->automute_speaker = 1;
870 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200871 break;
872 default:
873 return -EINVAL;
874 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200875 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200876 return 1;
877}
878
Takashi Iwaia9111322011-05-02 11:30:18 +0200879static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
881 .name = "Auto-Mute Mode",
882 .info = alc_automute_mode_info,
883 .get = alc_automute_mode_get,
884 .put = alc_automute_mode_put,
885};
886
Takashi Iwai1d045db2011-07-07 18:23:21 +0200887static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
888{
889 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
890 return snd_array_new(&spec->kctls);
891}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200892
893static int alc_add_automute_mode_enum(struct hda_codec *codec)
894{
895 struct alc_spec *spec = codec->spec;
896 struct snd_kcontrol_new *knew;
897
898 knew = alc_kcontrol_new(spec);
899 if (!knew)
900 return -ENOMEM;
901 *knew = alc_automute_mode_enum;
902 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
903 if (!knew->name)
904 return -ENOMEM;
905 return 0;
906}
907
Takashi Iwai1d045db2011-07-07 18:23:21 +0200908/*
909 * Check the availability of HP/line-out auto-mute;
910 * Set up appropriately if really supported
911 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200912static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200913{
914 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200915 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200916 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200917 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200918
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200919 if (cfg->hp_pins[0])
920 present++;
921 if (cfg->line_out_pins[0])
922 present++;
923 if (cfg->speaker_pins[0])
924 present++;
925 if (present < 2) /* need two different output types */
926 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200927
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200928 if (!cfg->speaker_pins[0] &&
929 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200930 memcpy(cfg->speaker_pins, cfg->line_out_pins,
931 sizeof(cfg->speaker_pins));
932 cfg->speaker_outs = cfg->line_outs;
933 }
934
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200935 if (!cfg->hp_pins[0] &&
936 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200937 memcpy(cfg->hp_pins, cfg->line_out_pins,
938 sizeof(cfg->hp_pins));
939 cfg->hp_outs = cfg->line_outs;
940 }
941
David Henningsson42cf0d02011-09-20 12:04:56 +0200942 spec->automute_mode = ALC_AUTOMUTE_PIN;
943
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200944 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200945 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200946 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200947 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200948 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200949 nid);
950 snd_hda_codec_write_cache(codec, nid, 0,
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200951 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +0200952 AC_USRSP_EN | ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200953 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200954 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200955
David Henningsson42cf0d02011-09-20 12:04:56 +0200956 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
957 if (cfg->speaker_outs)
958 for (i = 0; i < cfg->line_outs; i++) {
959 hda_nid_t nid = cfg->line_out_pins[i];
960 if (!is_jack_detectable(codec, nid))
961 continue;
962 snd_printdd("realtek: Enable Line-Out "
963 "auto-muting on NID 0x%x\n", nid);
964 snd_hda_codec_write_cache(codec, nid, 0,
965 AC_VERB_SET_UNSOLICITED_ENABLE,
966 AC_USRSP_EN | ALC_FRONT_EVENT);
967 spec->detect_lo = 1;
968 }
969 spec->automute_lo_possible = spec->detect_hp;
970 }
971
972 spec->automute_speaker_possible = cfg->speaker_outs &&
973 (spec->detect_hp || spec->detect_lo);
974
975 spec->automute_lo = spec->automute_lo_possible;
976 spec->automute_speaker = spec->automute_speaker_possible;
977
978 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200979 /* create a control for automute mode */
980 alc_add_automute_mode_enum(codec);
981 spec->unsol_event = alc_sku_unsol_event;
982 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200983}
984
Takashi Iwai1d045db2011-07-07 18:23:21 +0200985/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200986static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
987{
988 int i;
989 for (i = 0; i < nums; i++)
990 if (list[i] == nid)
991 return i;
992 return -1;
993}
994
Takashi Iwai1d045db2011-07-07 18:23:21 +0200995/* check whether dynamic ADC-switching is available */
996static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
997{
998 struct alc_spec *spec = codec->spec;
999 struct hda_input_mux *imux = &spec->private_imux[0];
1000 int i, n, idx;
1001 hda_nid_t cap, pin;
1002
1003 if (imux != spec->input_mux) /* no dynamic imux? */
1004 return false;
1005
1006 for (n = 0; n < spec->num_adc_nids; n++) {
1007 cap = spec->private_capsrc_nids[n];
1008 for (i = 0; i < imux->num_items; i++) {
1009 pin = spec->imux_pins[i];
1010 if (!pin)
1011 return false;
1012 if (get_connection_index(codec, cap, pin) < 0)
1013 break;
1014 }
1015 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001016 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001017 }
1018
1019 for (i = 0; i < imux->num_items; i++) {
1020 pin = spec->imux_pins[i];
1021 for (n = 0; n < spec->num_adc_nids; n++) {
1022 cap = spec->private_capsrc_nids[n];
1023 idx = get_connection_index(codec, cap, pin);
1024 if (idx >= 0) {
1025 imux->items[i].index = idx;
1026 spec->dyn_adc_idx[i] = n;
1027 break;
1028 }
1029 }
1030 }
1031
1032 snd_printdd("realtek: enabling ADC switching\n");
1033 spec->dyn_adc_switch = 1;
1034 return true;
1035}
Takashi Iwai21268962011-07-07 15:01:13 +02001036
1037/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1038static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1039{
1040 struct alc_spec *spec = codec->spec;
1041 struct hda_input_mux *imux;
1042 static char * const texts[3] = {
1043 "Mic", "Internal Mic", "Dock Mic"
1044 };
1045 int i;
1046
1047 if (!spec->auto_mic)
1048 return false;
1049 imux = &spec->private_imux[0];
1050 if (spec->input_mux == imux)
1051 return true;
1052 spec->imux_pins[0] = spec->ext_mic_pin;
1053 spec->imux_pins[1] = spec->int_mic_pin;
1054 spec->imux_pins[2] = spec->dock_mic_pin;
1055 for (i = 0; i < 3; i++) {
1056 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001057 if (spec->imux_pins[i]) {
1058 hda_nid_t pin = spec->imux_pins[i];
1059 int c;
1060 for (c = 0; c < spec->num_adc_nids; c++) {
1061 hda_nid_t cap = spec->capsrc_nids ?
1062 spec->capsrc_nids[c] : spec->adc_nids[c];
1063 int idx = get_connection_index(codec, cap, pin);
1064 if (idx >= 0) {
1065 imux->items[i].index = idx;
1066 break;
1067 }
1068 }
Takashi Iwai21268962011-07-07 15:01:13 +02001069 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001070 }
Takashi Iwai21268962011-07-07 15:01:13 +02001071 }
1072 spec->num_mux_defs = 1;
1073 spec->input_mux = imux;
1074 return true;
1075}
1076
1077/* check whether all auto-mic pins are valid; setup indices if OK */
1078static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1079{
1080 struct alc_spec *spec = codec->spec;
1081 const struct hda_input_mux *imux;
1082
1083 if (!spec->auto_mic)
1084 return false;
1085 if (spec->auto_mic_valid_imux)
1086 return true; /* already checked */
1087
1088 /* fill up imux indices */
1089 if (!alc_check_dyn_adc_switch(codec)) {
1090 spec->auto_mic = 0;
1091 return false;
1092 }
1093
1094 imux = spec->input_mux;
1095 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1098 spec->imux_pins, imux->num_items);
1099 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1100 spec->imux_pins, imux->num_items);
1101 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1102 spec->auto_mic = 0;
1103 return false; /* no corresponding imux */
1104 }
1105
1106 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1107 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001108 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001109 if (spec->dock_mic_pin)
1110 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1111 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001112 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001113
1114 spec->auto_mic_valid_imux = 1;
1115 spec->auto_mic = 1;
1116 return true;
1117}
1118
Takashi Iwai1d045db2011-07-07 18:23:21 +02001119/*
1120 * Check the availability of auto-mic switch;
1121 * Set up if really supported
1122 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001123static void alc_init_auto_mic(struct hda_codec *codec)
1124{
1125 struct alc_spec *spec = codec->spec;
1126 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001127 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001128 int i;
1129
Takashi Iwai21268962011-07-07 15:01:13 +02001130 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1131
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001132 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001133 for (i = 0; i < cfg->num_inputs; i++) {
1134 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001135 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001136 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001137 switch (snd_hda_get_input_pin_attr(defcfg)) {
1138 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001139 if (fixed)
1140 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001141 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1142 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001143 fixed = nid;
1144 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001145 case INPUT_PIN_ATTR_UNUSED:
1146 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001147 case INPUT_PIN_ATTR_DOCK:
1148 if (dock)
1149 return; /* already occupied */
1150 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1151 return; /* invalid type */
1152 dock = nid;
1153 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001154 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001155 if (ext)
1156 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001157 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1158 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001159 ext = nid;
1160 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001161 }
1162 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001163 if (!ext && dock) {
1164 ext = dock;
1165 dock = 0;
1166 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001167 if (!ext || !fixed)
1168 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001169 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001170 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001171 if (dock && !is_jack_detectable(codec, dock))
1172 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001173
1174 /* check imux indices */
1175 spec->ext_mic_pin = ext;
1176 spec->int_mic_pin = fixed;
1177 spec->dock_mic_pin = dock;
1178
1179 spec->auto_mic = 1;
1180 if (!alc_auto_mic_check_imux(codec))
1181 return;
1182
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001183 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1184 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001185 spec->unsol_event = alc_sku_unsol_event;
1186}
1187
Takashi Iwai1d045db2011-07-07 18:23:21 +02001188/* check the availabilities of auto-mute and auto-mic switches */
1189static void alc_auto_check_switches(struct hda_codec *codec)
1190{
David Henningsson42cf0d02011-09-20 12:04:56 +02001191 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001192 alc_init_auto_mic(codec);
1193}
1194
1195/*
1196 * Realtek SSID verification
1197 */
1198
David Henningsson90622912010-10-14 14:50:18 +02001199/* Could be any non-zero and even value. When used as fixup, tells
1200 * the driver to ignore any present sku defines.
1201 */
1202#define ALC_FIXUP_SKU_IGNORE (2)
1203
Kailang Yangda00c242010-03-19 11:23:45 +01001204static int alc_auto_parse_customize_define(struct hda_codec *codec)
1205{
1206 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001207 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001208 struct alc_spec *spec = codec->spec;
1209
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001210 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1211
David Henningsson90622912010-10-14 14:50:18 +02001212 if (spec->cdefine.fixup) {
1213 ass = spec->cdefine.sku_cfg;
1214 if (ass == ALC_FIXUP_SKU_IGNORE)
1215 return -1;
1216 goto do_sku;
1217 }
1218
Kailang Yangda00c242010-03-19 11:23:45 +01001219 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001220 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001221 goto do_sku;
1222
1223 nid = 0x1d;
1224 if (codec->vendor_id == 0x10ec0260)
1225 nid = 0x17;
1226 ass = snd_hda_codec_get_pincfg(codec, nid);
1227
1228 if (!(ass & 1)) {
1229 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1230 codec->chip_name, ass);
1231 return -1;
1232 }
1233
1234 /* check sum */
1235 tmp = 0;
1236 for (i = 1; i < 16; i++) {
1237 if ((ass >> i) & 1)
1238 tmp++;
1239 }
1240 if (((ass >> 16) & 0xf) != tmp)
1241 return -1;
1242
1243 spec->cdefine.port_connectivity = ass >> 30;
1244 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1245 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1246 spec->cdefine.customization = ass >> 8;
1247do_sku:
1248 spec->cdefine.sku_cfg = ass;
1249 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1250 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1251 spec->cdefine.swap = (ass & 0x2) >> 1;
1252 spec->cdefine.override = ass & 0x1;
1253
1254 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1255 nid, spec->cdefine.sku_cfg);
1256 snd_printd("SKU: port_connectivity=0x%x\n",
1257 spec->cdefine.port_connectivity);
1258 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1259 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1260 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1261 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1262 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1263 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1264 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1265
1266 return 0;
1267}
1268
Takashi Iwai1d045db2011-07-07 18:23:21 +02001269/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001270static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1271{
Takashi Iwai21268962011-07-07 15:01:13 +02001272 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001273}
1274
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001275/* check subsystem ID and set up device-specific initialization;
1276 * return 1 if initialized, 0 if invalid SSID
1277 */
1278/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1279 * 31 ~ 16 : Manufacture ID
1280 * 15 ~ 8 : SKU ID
1281 * 7 ~ 0 : Assembly ID
1282 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1283 */
1284static int alc_subsystem_id(struct hda_codec *codec,
1285 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001286 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001287{
1288 unsigned int ass, tmp, i;
1289 unsigned nid;
1290 struct alc_spec *spec = codec->spec;
1291
David Henningsson90622912010-10-14 14:50:18 +02001292 if (spec->cdefine.fixup) {
1293 ass = spec->cdefine.sku_cfg;
1294 if (ass == ALC_FIXUP_SKU_IGNORE)
1295 return 0;
1296 goto do_sku;
1297 }
1298
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001299 ass = codec->subsystem_id & 0xffff;
1300 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1301 goto do_sku;
1302
1303 /* invalid SSID, check the special NID pin defcfg instead */
1304 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001305 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001306 * 29~21 : reserve
1307 * 20 : PCBEEP input
1308 * 19~16 : Check sum (15:1)
1309 * 15~1 : Custom
1310 * 0 : override
1311 */
1312 nid = 0x1d;
1313 if (codec->vendor_id == 0x10ec0260)
1314 nid = 0x17;
1315 ass = snd_hda_codec_get_pincfg(codec, nid);
1316 snd_printd("realtek: No valid SSID, "
1317 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001318 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001319 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001320 return 0;
1321 if ((ass >> 30) != 1) /* no physical connection */
1322 return 0;
1323
1324 /* check sum */
1325 tmp = 0;
1326 for (i = 1; i < 16; i++) {
1327 if ((ass >> i) & 1)
1328 tmp++;
1329 }
1330 if (((ass >> 16) & 0xf) != tmp)
1331 return 0;
1332do_sku:
1333 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1334 ass & 0xffff, codec->vendor_id);
1335 /*
1336 * 0 : override
1337 * 1 : Swap Jack
1338 * 2 : 0 --> Desktop, 1 --> Laptop
1339 * 3~5 : External Amplifier control
1340 * 7~6 : Reserved
1341 */
1342 tmp = (ass & 0x38) >> 3; /* external Amp control */
1343 switch (tmp) {
1344 case 1:
1345 spec->init_amp = ALC_INIT_GPIO1;
1346 break;
1347 case 3:
1348 spec->init_amp = ALC_INIT_GPIO2;
1349 break;
1350 case 7:
1351 spec->init_amp = ALC_INIT_GPIO3;
1352 break;
1353 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001354 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001355 spec->init_amp = ALC_INIT_DEFAULT;
1356 break;
1357 }
1358
1359 /* is laptop or Desktop and enable the function "Mute internal speaker
1360 * when the external headphone out jack is plugged"
1361 */
1362 if (!(ass & 0x8000))
1363 return 1;
1364 /*
1365 * 10~8 : Jack location
1366 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1367 * 14~13: Resvered
1368 * 15 : 1 --> enable the function "Mute internal speaker
1369 * when the external headphone out jack is plugged"
1370 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001371 if (!spec->autocfg.hp_pins[0] &&
1372 !(spec->autocfg.line_out_pins[0] &&
1373 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001374 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001375 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1376 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001377 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001378 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001379 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001380 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001381 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001382 else if (tmp == 3)
1383 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001384 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001385 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001386 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1387 spec->autocfg.line_outs))
1388 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001389 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001390 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001391 return 1;
1392}
Kailang Yangea1fb292008-08-26 12:58:38 +02001393
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001394/* Check the validity of ALC subsystem-id
1395 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1396static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001397{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001398 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001399 struct alc_spec *spec = codec->spec;
1400 snd_printd("realtek: "
1401 "Enable default setup for auto mode as fallback\n");
1402 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001403 }
Takashi Iwai21268962011-07-07 15:01:13 +02001404}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001405
Takashi Iwai41e41f12005-06-08 14:48:49 +02001406/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001407 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001408 */
1409
1410struct alc_pincfg {
1411 hda_nid_t nid;
1412 u32 val;
1413};
1414
Todd Broche1eb5f12010-12-06 11:19:51 -08001415struct alc_model_fixup {
1416 const int id;
1417 const char *name;
1418};
1419
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001420struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001421 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001422 bool chained;
1423 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001424 union {
1425 unsigned int sku;
1426 const struct alc_pincfg *pins;
1427 const struct hda_verb *verbs;
1428 void (*func)(struct hda_codec *codec,
1429 const struct alc_fixup *fix,
1430 int action);
1431 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001432};
1433
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001434enum {
1435 ALC_FIXUP_INVALID,
1436 ALC_FIXUP_SKU,
1437 ALC_FIXUP_PINS,
1438 ALC_FIXUP_VERBS,
1439 ALC_FIXUP_FUNC,
1440};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001441
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001442enum {
1443 ALC_FIXUP_ACT_PRE_PROBE,
1444 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001445 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001446};
1447
1448static void alc_apply_fixup(struct hda_codec *codec, int action)
1449{
1450 struct alc_spec *spec = codec->spec;
1451 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001452#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001453 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001454#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001455 int depth = 0;
1456
1457 if (!spec->fixup_list)
1458 return;
1459
1460 while (id >= 0) {
1461 const struct alc_fixup *fix = spec->fixup_list + id;
1462 const struct alc_pincfg *cfg;
1463
1464 switch (fix->type) {
1465 case ALC_FIXUP_SKU:
1466 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001467 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001468 snd_printdd(KERN_INFO "hda_codec: %s: "
1469 "Apply sku override for %s\n",
1470 codec->chip_name, modelname);
1471 spec->cdefine.sku_cfg = fix->v.sku;
1472 spec->cdefine.fixup = 1;
1473 break;
1474 case ALC_FIXUP_PINS:
1475 cfg = fix->v.pins;
1476 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1477 break;
1478 snd_printdd(KERN_INFO "hda_codec: %s: "
1479 "Apply pincfg for %s\n",
1480 codec->chip_name, modelname);
1481 for (; cfg->nid; cfg++)
1482 snd_hda_codec_set_pincfg(codec, cfg->nid,
1483 cfg->val);
1484 break;
1485 case ALC_FIXUP_VERBS:
1486 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1487 break;
1488 snd_printdd(KERN_INFO "hda_codec: %s: "
1489 "Apply fix-verbs for %s\n",
1490 codec->chip_name, modelname);
1491 add_verb(codec->spec, fix->v.verbs);
1492 break;
1493 case ALC_FIXUP_FUNC:
1494 if (!fix->v.func)
1495 break;
1496 snd_printdd(KERN_INFO "hda_codec: %s: "
1497 "Apply fix-func for %s\n",
1498 codec->chip_name, modelname);
1499 fix->v.func(codec, fix, action);
1500 break;
1501 default:
1502 snd_printk(KERN_ERR "hda_codec: %s: "
1503 "Invalid fixup type %d\n",
1504 codec->chip_name, fix->type);
1505 break;
1506 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001507 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001508 break;
1509 if (++depth > 10)
1510 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001511 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001512 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001513}
1514
Todd Broche1eb5f12010-12-06 11:19:51 -08001515static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001516 const struct alc_model_fixup *models,
1517 const struct snd_pci_quirk *quirk,
1518 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001519{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001520 struct alc_spec *spec = codec->spec;
1521 int id = -1;
1522 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001523
Todd Broche1eb5f12010-12-06 11:19:51 -08001524 if (codec->modelname && models) {
1525 while (models->name) {
1526 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001527 id = models->id;
1528 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001529 break;
1530 }
1531 models++;
1532 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001533 }
1534 if (id < 0) {
1535 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1536 if (quirk) {
1537 id = quirk->value;
1538#ifdef CONFIG_SND_DEBUG_VERBOSE
1539 name = quirk->name;
1540#endif
1541 }
1542 }
1543
1544 spec->fixup_id = id;
1545 if (id >= 0) {
1546 spec->fixup_list = fixlist;
1547 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001548 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001549}
1550
Takashi Iwai1d045db2011-07-07 18:23:21 +02001551/*
1552 * COEF access helper functions
1553 */
Kailang Yang274693f2009-12-03 10:07:50 +01001554static int alc_read_coef_idx(struct hda_codec *codec,
1555 unsigned int coef_idx)
1556{
1557 unsigned int val;
1558 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1559 coef_idx);
1560 val = snd_hda_codec_read(codec, 0x20, 0,
1561 AC_VERB_GET_PROC_COEF, 0);
1562 return val;
1563}
1564
Kailang Yang977ddd62010-09-15 10:02:29 +02001565static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1566 unsigned int coef_val)
1567{
1568 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1569 coef_idx);
1570 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1571 coef_val);
1572}
1573
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001574/* a special bypass for COEF 0; read the cached value at the second time */
1575static unsigned int alc_get_coef0(struct hda_codec *codec)
1576{
1577 struct alc_spec *spec = codec->spec;
1578 if (!spec->coef0)
1579 spec->coef0 = alc_read_coef_idx(codec, 0);
1580 return spec->coef0;
1581}
1582
Takashi Iwai1d045db2011-07-07 18:23:21 +02001583/*
1584 * Digital I/O handling
1585 */
1586
Takashi Iwai757899a2010-07-30 10:48:14 +02001587/* set right pin controls for digital I/O */
1588static void alc_auto_init_digital(struct hda_codec *codec)
1589{
1590 struct alc_spec *spec = codec->spec;
1591 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001592 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001593
1594 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1595 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001596 if (!pin)
1597 continue;
1598 snd_hda_codec_write(codec, pin, 0,
1599 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1600 if (!i)
1601 dac = spec->multiout.dig_out_nid;
1602 else
1603 dac = spec->slave_dig_outs[i - 1];
1604 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1605 continue;
1606 snd_hda_codec_write(codec, dac, 0,
1607 AC_VERB_SET_AMP_GAIN_MUTE,
1608 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001609 }
1610 pin = spec->autocfg.dig_in_pin;
1611 if (pin)
1612 snd_hda_codec_write(codec, pin, 0,
1613 AC_VERB_SET_PIN_WIDGET_CONTROL,
1614 PIN_IN);
1615}
1616
1617/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1618static void alc_auto_parse_digital(struct hda_codec *codec)
1619{
1620 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001621 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001622 hda_nid_t dig_nid;
1623
1624 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001625 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001626 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001627 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001628 err = snd_hda_get_connections(codec,
1629 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001630 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001631 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001632 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001633 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001634 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001635 spec->multiout.dig_out_nid = dig_nid;
1636 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1637 } else {
1638 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001639 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001640 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001641 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001642 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001643 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001644 }
1645
1646 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001647 dig_nid = codec->start_nid;
1648 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1649 unsigned int wcaps = get_wcaps(codec, dig_nid);
1650 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1651 continue;
1652 if (!(wcaps & AC_WCAP_DIGITAL))
1653 continue;
1654 if (!(wcaps & AC_WCAP_CONN_LIST))
1655 continue;
1656 err = get_connection_index(codec, dig_nid,
1657 spec->autocfg.dig_in_pin);
1658 if (err >= 0) {
1659 spec->dig_in_nid = dig_nid;
1660 break;
1661 }
1662 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001663 }
1664}
1665
Takashi Iwaif95474e2007-07-10 00:47:43 +02001666/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001667 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001668 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001669static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1670 struct snd_ctl_elem_info *uinfo)
1671{
1672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1673 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001674 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001675 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001676
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001677 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001678 if (spec->vol_in_capsrc)
1679 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1680 else
1681 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1682 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001683 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001684 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001685 return err;
1686}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001688static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1689 unsigned int size, unsigned int __user *tlv)
1690{
1691 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1692 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001693 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001694 int err;
1695
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001696 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001697 if (spec->vol_in_capsrc)
1698 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1699 else
1700 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1701 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001702 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001703 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001704 return err;
1705}
1706
1707typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1708 struct snd_ctl_elem_value *ucontrol);
1709
1710static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1711 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001712 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001713{
1714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1715 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001716 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001717
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001718 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001719 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001720 for (i = 0; i < spec->num_adc_nids; i++) {
1721 kcontrol->private_value =
1722 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1723 3, 0, HDA_INPUT);
1724 err = func(kcontrol, ucontrol);
1725 if (err < 0)
1726 goto error;
1727 }
1728 } else {
1729 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001730 if (spec->vol_in_capsrc)
1731 kcontrol->private_value =
1732 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1733 3, 0, HDA_OUTPUT);
1734 else
1735 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001736 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1737 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001738 err = func(kcontrol, ucontrol);
1739 }
1740 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001741 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001742 return err;
1743}
1744
1745static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol)
1747{
1748 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001749 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001750}
1751
1752static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1753 struct snd_ctl_elem_value *ucontrol)
1754{
1755 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001756 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001757}
1758
1759/* capture mixer elements */
1760#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1761
1762static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol)
1764{
1765 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001766 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001767}
1768
1769static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1770 struct snd_ctl_elem_value *ucontrol)
1771{
1772 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001773 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001774}
1775
Takashi Iwaia23b6882009-03-23 15:21:36 +01001776#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001777 { \
1778 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1779 .name = "Capture Switch", \
1780 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1781 .count = num, \
1782 .info = alc_cap_sw_info, \
1783 .get = alc_cap_sw_get, \
1784 .put = alc_cap_sw_put, \
1785 }, \
1786 { \
1787 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1788 .name = "Capture Volume", \
1789 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1790 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1791 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1792 .count = num, \
1793 .info = alc_cap_vol_info, \
1794 .get = alc_cap_vol_get, \
1795 .put = alc_cap_vol_put, \
1796 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001797 }
1798
1799#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001800 { \
1801 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1802 /* .name = "Capture Source", */ \
1803 .name = "Input Source", \
1804 .count = num, \
1805 .info = alc_mux_enum_info, \
1806 .get = alc_mux_enum_get, \
1807 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001808 }
1809
1810#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001811static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001812 _DEFINE_CAPMIX(num), \
1813 _DEFINE_CAPSRC(num), \
1814 { } /* end */ \
1815}
1816
1817#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001818static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001819 _DEFINE_CAPMIX(num), \
1820 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001821}
1822
1823/* up to three ADCs */
1824DEFINE_CAPMIX(1);
1825DEFINE_CAPMIX(2);
1826DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001827DEFINE_CAPMIX_NOSRC(1);
1828DEFINE_CAPMIX_NOSRC(2);
1829DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001830
1831/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001832 * virtual master controls
1833 */
1834
1835/*
1836 * slave controls for virtual master
1837 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001838static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001839 "Front Playback Volume",
1840 "Surround Playback Volume",
1841 "Center Playback Volume",
1842 "LFE Playback Volume",
1843 "Side Playback Volume",
1844 "Headphone Playback Volume",
1845 "Speaker Playback Volume",
1846 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001847 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001848 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001849 NULL,
1850};
1851
Takashi Iwaiea734962011-01-17 11:29:34 +01001852static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001853 "Front Playback Switch",
1854 "Surround Playback Switch",
1855 "Center Playback Switch",
1856 "LFE Playback Switch",
1857 "Side Playback Switch",
1858 "Headphone Playback Switch",
1859 "Speaker Playback Switch",
1860 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001861 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001862 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001863 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001864 NULL,
1865};
1866
1867/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001868 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001870
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001871#define NID_MAPPING (-1)
1872
1873#define SUBDEV_SPEAKER_ (0 << 6)
1874#define SUBDEV_HP_ (1 << 6)
1875#define SUBDEV_LINE_ (2 << 6)
1876#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1877#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1878#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1879
Takashi Iwai603c4012008-07-30 15:01:44 +02001880static void alc_free_kctls(struct hda_codec *codec);
1881
Takashi Iwai67d634c2009-11-16 15:35:59 +01001882#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001883/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001884static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001885 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001886 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001887 { } /* end */
1888};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001889#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001890
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891static int alc_build_controls(struct hda_codec *codec)
1892{
1893 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001894 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001895 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001896 int i, j, err;
1897 unsigned int u;
1898 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
1900 for (i = 0; i < spec->num_mixers; i++) {
1901 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1902 if (err < 0)
1903 return err;
1904 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001905 if (spec->cap_mixer) {
1906 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1907 if (err < 0)
1908 return err;
1909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001911 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001912 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001913 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 if (err < 0)
1915 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001916 if (!spec->no_analog) {
1917 err = snd_hda_create_spdif_share_sw(codec,
1918 &spec->multiout);
1919 if (err < 0)
1920 return err;
1921 spec->multiout.share_spdif = 1;
1922 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 }
1924 if (spec->dig_in_nid) {
1925 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1926 if (err < 0)
1927 return err;
1928 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001929
Takashi Iwai67d634c2009-11-16 15:35:59 +01001930#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001931 /* create beep controls if needed */
1932 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001933 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001934 for (knew = alc_beep_mixer; knew->name; knew++) {
1935 struct snd_kcontrol *kctl;
1936 kctl = snd_ctl_new1(knew, codec);
1937 if (!kctl)
1938 return -ENOMEM;
1939 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001940 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001941 if (err < 0)
1942 return err;
1943 }
1944 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001945#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001946
Takashi Iwai2134ea42008-01-10 16:53:55 +01001947 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001948 if (!spec->no_analog &&
1949 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001950 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001951 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001952 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001953 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001954 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001955 if (err < 0)
1956 return err;
1957 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001958 if (!spec->no_analog &&
1959 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001960 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1961 NULL, alc_slave_sws);
1962 if (err < 0)
1963 return err;
1964 }
1965
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001966 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001967 if (spec->capsrc_nids || spec->adc_nids) {
1968 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1969 if (!kctl)
1970 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1971 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02001972 const hda_nid_t *nids = spec->capsrc_nids;
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001973 if (!nids)
1974 nids = spec->adc_nids;
1975 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1976 if (err < 0)
1977 return err;
1978 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001979 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001980 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001981 const char *kname = kctl ? kctl->id.name : NULL;
1982 for (knew = spec->cap_mixer; knew->name; knew++) {
1983 if (kname && strcmp(knew->name, kname) == 0)
1984 continue;
1985 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1986 for (i = 0; kctl && i < kctl->count; i++) {
1987 err = snd_hda_add_nid(codec, kctl, i,
1988 spec->adc_nids[i]);
1989 if (err < 0)
1990 return err;
1991 }
1992 }
1993 }
1994
1995 /* other nid->control mapping */
1996 for (i = 0; i < spec->num_mixers; i++) {
1997 for (knew = spec->mixers[i]; knew->name; knew++) {
1998 if (knew->iface != NID_MAPPING)
1999 continue;
2000 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2001 if (kctl == NULL)
2002 continue;
2003 u = knew->subdevice;
2004 for (j = 0; j < 4; j++, u >>= 8) {
2005 nid = u & 0x3f;
2006 if (nid == 0)
2007 continue;
2008 switch (u & 0xc0) {
2009 case SUBDEV_SPEAKER_:
2010 nid = spec->autocfg.speaker_pins[nid];
2011 break;
2012 case SUBDEV_LINE_:
2013 nid = spec->autocfg.line_out_pins[nid];
2014 break;
2015 case SUBDEV_HP_:
2016 nid = spec->autocfg.hp_pins[nid];
2017 break;
2018 default:
2019 continue;
2020 }
2021 err = snd_hda_add_nid(codec, kctl, 0, nid);
2022 if (err < 0)
2023 return err;
2024 }
2025 u = knew->private_value;
2026 for (j = 0; j < 4; j++, u >>= 8) {
2027 nid = u & 0xff;
2028 if (nid == 0)
2029 continue;
2030 err = snd_hda_add_nid(codec, kctl, 0, nid);
2031 if (err < 0)
2032 return err;
2033 }
2034 }
2035 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002036
2037 alc_free_kctls(codec); /* no longer needed */
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 return 0;
2040}
2041
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002044 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002045 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002046
Takashi Iwai584c0c42011-03-10 12:51:11 +01002047static void alc_init_special_input_src(struct hda_codec *codec);
2048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049static int alc_init(struct hda_codec *codec)
2050{
2051 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002052 unsigned int i;
2053
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002054 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002055 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002056
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002057 for (i = 0; i < spec->num_init_verbs; i++)
2058 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002059 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002060
2061 if (spec->init_hook)
2062 spec->init_hook(codec);
2063
Takashi Iwai58701122011-01-13 15:41:45 +01002064 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2065
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002066 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 return 0;
2068}
2069
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002070static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2071{
2072 struct alc_spec *spec = codec->spec;
2073
2074 if (spec->unsol_event)
2075 spec->unsol_event(codec, res);
2076}
2077
Takashi Iwaicb53c622007-08-10 17:21:45 +02002078#ifdef CONFIG_SND_HDA_POWER_SAVE
2079static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2080{
2081 struct alc_spec *spec = codec->spec;
2082 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2083}
2084#endif
2085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086/*
2087 * Analog playback callbacks
2088 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002089static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002091 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092{
2093 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002094 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2095 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002098static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 struct hda_codec *codec,
2100 unsigned int stream_tag,
2101 unsigned int format,
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;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002105 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2106 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002109static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002111 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112{
2113 struct alc_spec *spec = codec->spec;
2114 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2115}
2116
2117/*
2118 * Digital out
2119 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002120static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002122 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123{
2124 struct alc_spec *spec = codec->spec;
2125 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2126}
2127
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002128static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002129 struct hda_codec *codec,
2130 unsigned int stream_tag,
2131 unsigned int format,
2132 struct snd_pcm_substream *substream)
2133{
2134 struct alc_spec *spec = codec->spec;
2135 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2136 stream_tag, format, substream);
2137}
2138
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002139static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002140 struct hda_codec *codec,
2141 struct snd_pcm_substream *substream)
2142{
2143 struct alc_spec *spec = codec->spec;
2144 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2145}
2146
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002147static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002149 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
2151 struct alc_spec *spec = codec->spec;
2152 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2153}
2154
2155/*
2156 * Analog capture
2157 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002158static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct hda_codec *codec,
2160 unsigned int stream_tag,
2161 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002162 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163{
2164 struct alc_spec *spec = codec->spec;
2165
Takashi Iwai63300792008-01-24 15:31:36 +01002166 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 stream_tag, 0, format);
2168 return 0;
2169}
2170
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002171static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002173 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
2175 struct alc_spec *spec = codec->spec;
2176
Takashi Iwai888afa12008-03-18 09:57:50 +01002177 snd_hda_codec_cleanup_stream(codec,
2178 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 return 0;
2180}
2181
Takashi Iwai840b64c2010-07-13 22:49:01 +02002182/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002183static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002184 struct hda_codec *codec,
2185 unsigned int stream_tag,
2186 unsigned int format,
2187 struct snd_pcm_substream *substream)
2188{
2189 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002190 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002191 spec->cur_adc_stream_tag = stream_tag;
2192 spec->cur_adc_format = format;
2193 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2194 return 0;
2195}
2196
Takashi Iwai21268962011-07-07 15:01:13 +02002197static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002198 struct hda_codec *codec,
2199 struct snd_pcm_substream *substream)
2200{
2201 struct alc_spec *spec = codec->spec;
2202 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2203 spec->cur_adc = 0;
2204 return 0;
2205}
2206
Takashi Iwai21268962011-07-07 15:01:13 +02002207static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002208 .substreams = 1,
2209 .channels_min = 2,
2210 .channels_max = 2,
2211 .nid = 0, /* fill later */
2212 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002213 .prepare = dyn_adc_capture_pcm_prepare,
2214 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002215 },
2216};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
2218/*
2219 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002220static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 .substreams = 1,
2222 .channels_min = 2,
2223 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002224 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002226 .open = alc_playback_pcm_open,
2227 .prepare = alc_playback_pcm_prepare,
2228 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 },
2230};
2231
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002232static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002233 .substreams = 1,
2234 .channels_min = 2,
2235 .channels_max = 2,
2236 /* NID is set in alc_build_pcms */
2237};
2238
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002239static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002240 .substreams = 1,
2241 .channels_min = 2,
2242 .channels_max = 2,
2243 /* NID is set in alc_build_pcms */
2244};
2245
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002246static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002247 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 .channels_min = 2,
2249 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002250 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002252 .prepare = alc_alt_capture_pcm_prepare,
2253 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 },
2255};
2256
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002257static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 .substreams = 1,
2259 .channels_min = 2,
2260 .channels_max = 2,
2261 /* NID is set in alc_build_pcms */
2262 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002263 .open = alc_dig_playback_pcm_open,
2264 .close = alc_dig_playback_pcm_close,
2265 .prepare = alc_dig_playback_pcm_prepare,
2266 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 },
2268};
2269
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002270static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 .substreams = 1,
2272 .channels_min = 2,
2273 .channels_max = 2,
2274 /* NID is set in alc_build_pcms */
2275};
2276
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002277/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002278static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002279 .substreams = 0,
2280 .channels_min = 0,
2281 .channels_max = 0,
2282};
2283
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284static int alc_build_pcms(struct hda_codec *codec)
2285{
2286 struct alc_spec *spec = codec->spec;
2287 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002288 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002289 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 int i;
2291
2292 codec->num_pcms = 1;
2293 codec->pcm_info = info;
2294
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002295 if (spec->no_analog)
2296 goto skip_analog;
2297
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002298 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2299 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002301
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002302 if (spec->multiout.dac_nids > 0) {
2303 p = spec->stream_analog_playback;
2304 if (!p)
2305 p = &alc_pcm_analog_playback;
2306 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002307 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2308 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002309 if (spec->adc_nids) {
2310 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002311 if (!p) {
2312 if (spec->dyn_adc_switch)
2313 p = &dyn_adc_pcm_analog_capture;
2314 else
2315 p = &alc_pcm_analog_capture;
2316 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002317 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002318 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Takashi Iwai4a471b72005-12-07 13:56:29 +01002321 if (spec->channel_mode) {
2322 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2323 for (i = 0; i < spec->num_channel_mode; i++) {
2324 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2325 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 }
2328 }
2329
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002330 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002331 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002333 snprintf(spec->stream_name_digital,
2334 sizeof(spec->stream_name_digital),
2335 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002336 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002337 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002338 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002340 if (spec->dig_out_type)
2341 info->pcm_type = spec->dig_out_type;
2342 else
2343 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002344 if (spec->multiout.dig_out_nid) {
2345 p = spec->stream_digital_playback;
2346 if (!p)
2347 p = &alc_pcm_digital_playback;
2348 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2350 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002351 if (spec->dig_in_nid) {
2352 p = spec->stream_digital_capture;
2353 if (!p)
2354 p = &alc_pcm_digital_capture;
2355 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2357 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002358 /* FIXME: do we need this for all Realtek codec models? */
2359 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 }
2361
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002362 if (spec->no_analog)
2363 return 0;
2364
Takashi Iwaie08a0072006-09-07 17:52:14 +02002365 /* If the use of more than one ADC is requested for the current
2366 * model, configure a second analog capture-only PCM.
2367 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002368 have_multi_adcs = (spec->num_adc_nids > 1) &&
2369 !spec->dyn_adc_switch && !spec->auto_mic &&
2370 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002371 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002372 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002373 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002374 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002375 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002376 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002377 p = spec->stream_analog_alt_playback;
2378 if (!p)
2379 p = &alc_pcm_analog_alt_playback;
2380 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002381 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2382 spec->alt_dac_nid;
2383 } else {
2384 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2385 alc_pcm_null_stream;
2386 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2387 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002388 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002389 p = spec->stream_analog_alt_capture;
2390 if (!p)
2391 p = &alc_pcm_analog_alt_capture;
2392 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002393 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2394 spec->adc_nids[1];
2395 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2396 spec->num_adc_nids - 1;
2397 } else {
2398 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2399 alc_pcm_null_stream;
2400 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002401 }
2402 }
2403
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 return 0;
2405}
2406
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002407static inline void alc_shutup(struct hda_codec *codec)
2408{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002409 struct alc_spec *spec = codec->spec;
2410
2411 if (spec && spec->shutup)
2412 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002413 snd_hda_shutup_pins(codec);
2414}
2415
Takashi Iwai603c4012008-07-30 15:01:44 +02002416static void alc_free_kctls(struct hda_codec *codec)
2417{
2418 struct alc_spec *spec = codec->spec;
2419
2420 if (spec->kctls.list) {
2421 struct snd_kcontrol_new *kctl = spec->kctls.list;
2422 int i;
2423 for (i = 0; i < spec->kctls.used; i++)
2424 kfree(kctl[i].name);
2425 }
2426 snd_array_free(&spec->kctls);
2427}
2428
Takashi Iwai23c09b02011-08-19 09:05:35 +02002429static void alc_free_bind_ctls(struct hda_codec *codec)
2430{
2431 struct alc_spec *spec = codec->spec;
2432 if (spec->bind_ctls.list) {
2433 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2434 int i;
2435 for (i = 0; i < spec->bind_ctls.used; i++)
2436 kfree(ctl[i]);
2437 }
2438 snd_array_free(&spec->bind_ctls);
2439}
2440
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441static void alc_free(struct hda_codec *codec)
2442{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002443 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002444
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002445 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002446 return;
2447
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002448 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002449 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002450 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002451 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002452 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002453 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454}
2455
Hector Martinf5de24b2009-12-20 22:51:31 +01002456#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002457static void alc_power_eapd(struct hda_codec *codec)
2458{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002459 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002460}
2461
Hector Martinf5de24b2009-12-20 22:51:31 +01002462static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2463{
2464 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002465 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002466 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002467 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002468 return 0;
2469}
2470#endif
2471
Takashi Iwai2a439522011-07-26 09:52:50 +02002472#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002473static int alc_resume(struct hda_codec *codec)
2474{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002475 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002476 codec->patch_ops.init(codec);
2477 snd_hda_codec_resume_amp(codec);
2478 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002479 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002480 return 0;
2481}
Takashi Iwaie044c392008-10-27 16:56:24 +01002482#endif
2483
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484/*
2485 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002486static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 .build_controls = alc_build_controls,
2488 .build_pcms = alc_build_pcms,
2489 .init = alc_init,
2490 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002491 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002492#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002493 .resume = alc_resume,
2494#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002495#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002496 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002497 .check_power_status = alc_check_power_status,
2498#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002499 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500};
2501
Kailang Yangc027ddc2010-03-19 11:33:06 +01002502/* replace the codec chip_name with the given string */
2503static int alc_codec_rename(struct hda_codec *codec, const char *name)
2504{
2505 kfree(codec->chip_name);
2506 codec->chip_name = kstrdup(name, GFP_KERNEL);
2507 if (!codec->chip_name) {
2508 alc_free(codec);
2509 return -ENOMEM;
2510 }
2511 return 0;
2512}
2513
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002514/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002515 * Rename codecs appropriately from COEF value
2516 */
2517struct alc_codec_rename_table {
2518 unsigned int vendor_id;
2519 unsigned short coef_mask;
2520 unsigned short coef_bits;
2521 const char *name;
2522};
2523
2524static struct alc_codec_rename_table rename_tbl[] = {
2525 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2526 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2527 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2528 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2529 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2530 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2531 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2532 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2533 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2534 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2535 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2536 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2537 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2538 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2539 { } /* terminator */
2540};
2541
2542static int alc_codec_rename_from_preset(struct hda_codec *codec)
2543{
2544 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002545
2546 for (p = rename_tbl; p->vendor_id; p++) {
2547 if (p->vendor_id != codec->vendor_id)
2548 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002549 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002550 return alc_codec_rename(codec, p->name);
2551 }
2552 return 0;
2553}
2554
2555/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002556 * Automatic parse of I/O pins from the BIOS configuration
2557 */
2558
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002559enum {
2560 ALC_CTL_WIDGET_VOL,
2561 ALC_CTL_WIDGET_MUTE,
2562 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002563 ALC_CTL_BIND_VOL,
2564 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002565};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002566static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002567 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2568 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002569 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002570 HDA_BIND_VOL(NULL, 0),
2571 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002572};
2573
2574/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002575static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002576 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002577{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002578 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002579
Takashi Iwaice764ab2011-04-27 16:35:23 +02002580 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002581 if (!knew)
2582 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002583 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002584 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002585 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002586 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002587 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002588 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002589 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002590 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002591 return 0;
2592}
2593
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002594static int add_control_with_pfx(struct alc_spec *spec, int type,
2595 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002596 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002597{
2598 char name[32];
2599 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002600 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002601}
2602
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002603#define add_pb_vol_ctrl(spec, type, pfx, val) \
2604 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2605#define add_pb_sw_ctrl(spec, type, pfx, val) \
2606 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2607#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2608 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2609#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2610 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002611
Takashi Iwai23c09b02011-08-19 09:05:35 +02002612static const char * const channel_name[4] = {
2613 "Front", "Surround", "CLFE", "Side"
2614};
2615
Takashi Iwai6843ca12011-06-24 11:03:58 +02002616static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2617 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002618{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002619 struct auto_pin_cfg *cfg = &spec->autocfg;
2620
Takashi Iwai6843ca12011-06-24 11:03:58 +02002621 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002622 if (cfg->line_outs == 1 && !spec->multi_ios &&
2623 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002624 return "Master";
2625
2626 switch (cfg->line_out_type) {
2627 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002628 if (cfg->line_outs == 1)
2629 return "Speaker";
2630 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002631 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002632 /* for multi-io case, only the primary out */
2633 if (ch && spec->multi_ios)
2634 break;
2635 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002636 return "Headphone";
2637 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002638 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002639 return "PCM";
2640 break;
2641 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002642 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2643 return "PCM";
2644
2645 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002646}
2647
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002648/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002649static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002650 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002651 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002652{
Kailang Yangdf694da2005-12-05 19:42:22 +01002653 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002654
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002655 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));
2657 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002658 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002659 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002660 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2661 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002662 return err;
2663 return 0;
2664}
2665
Takashi Iwai05f5f472009-08-25 13:10:18 +02002666static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002667{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002668 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2669 return (pincap & AC_PINCAP_IN) != 0;
2670}
2671
Takashi Iwai1d045db2011-07-07 18:23:21 +02002672/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002673static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002674{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002675 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002676 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002677 hda_nid_t *adc_nids = spec->private_adc_nids;
2678 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2679 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002680 int i, nums = 0;
2681
2682 nid = codec->start_nid;
2683 for (i = 0; i < codec->num_nodes; i++, nid++) {
2684 hda_nid_t src;
2685 const hda_nid_t *list;
2686 unsigned int caps = get_wcaps(codec, nid);
2687 int type = get_wcaps_type(caps);
2688
2689 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2690 continue;
2691 adc_nids[nums] = nid;
2692 cap_nids[nums] = nid;
2693 src = nid;
2694 for (;;) {
2695 int n;
2696 type = get_wcaps_type(get_wcaps(codec, src));
2697 if (type == AC_WID_PIN)
2698 break;
2699 if (type == AC_WID_AUD_SEL) {
2700 cap_nids[nums] = src;
2701 break;
2702 }
2703 n = snd_hda_get_conn_list(codec, src, &list);
2704 if (n > 1) {
2705 cap_nids[nums] = src;
2706 break;
2707 } else if (n != 1)
2708 break;
2709 src = *list;
2710 }
2711 if (++nums >= max_nums)
2712 break;
2713 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002714 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002715 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002716 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002717 return nums;
2718}
2719
Takashi Iwai05f5f472009-08-25 13:10:18 +02002720/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002721static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002722{
2723 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002724 const struct auto_pin_cfg *cfg = &spec->autocfg;
2725 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002726 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002727 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002728 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002729 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002730
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002731 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002732 if (num_adcs < 0)
2733 return 0;
2734
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002735 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002736 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002737 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002738
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002739 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002740 if (!alc_is_input_pin(codec, pin))
2741 continue;
2742
David Henningsson5322bf22011-01-05 11:03:56 +01002743 label = hda_get_autocfg_input_label(codec, cfg, i);
2744 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002745 type_idx++;
2746 else
2747 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002748 prev_label = label;
2749
Takashi Iwai05f5f472009-08-25 13:10:18 +02002750 if (mixer) {
2751 idx = get_connection_index(codec, mixer, pin);
2752 if (idx >= 0) {
2753 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002754 label, type_idx,
2755 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002756 if (err < 0)
2757 return err;
2758 }
2759 }
2760
Takashi Iwaib7821702011-07-06 15:12:46 +02002761 for (c = 0; c < num_adcs; c++) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002762 hda_nid_t cap = spec->capsrc_nids ?
2763 spec->capsrc_nids[c] : spec->adc_nids[c];
2764 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002765 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002766 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002767 snd_hda_add_imux_item(imux, label, idx, NULL);
2768 break;
2769 }
2770 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002771 }
Takashi Iwai21268962011-07-07 15:01:13 +02002772
2773 spec->num_mux_defs = 1;
2774 spec->input_mux = imux;
2775
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002776 return 0;
2777}
2778
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002779static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2780 unsigned int pin_type)
2781{
2782 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2783 pin_type);
2784 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002785 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2786 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002787 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002788}
2789
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002790static int get_pin_type(int line_out_type)
2791{
2792 if (line_out_type == AUTO_PIN_HP_OUT)
2793 return PIN_HP;
2794 else
2795 return PIN_OUT;
2796}
2797
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002798static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002799{
2800 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002801 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002802 int i;
2803
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002804 for (i = 0; i < cfg->num_inputs; i++) {
2805 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002806 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002807 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002808 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002809 snd_hda_codec_write(codec, nid, 0,
2810 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002811 AMP_OUT_MUTE);
2812 }
2813 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002814
2815 /* mute all loopback inputs */
2816 if (spec->mixer_nid) {
2817 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2818 for (i = 0; i < nums; i++)
2819 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2820 AC_VERB_SET_AMP_GAIN_MUTE,
2821 AMP_IN_MUTE(i));
2822 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002823}
2824
Takashi Iwai7085ec12009-10-02 09:03:58 +02002825/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002826static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002827{
Takashi Iwai604401a2011-04-27 15:14:23 +02002828 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002829 int i, num;
2830
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002831 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2832 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002833 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2834 for (i = 0; i < num; i++) {
2835 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2836 return list[i];
2837 }
2838 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002839}
2840
Takashi Iwai604401a2011-04-27 15:14:23 +02002841/* go down to the selector widget before the mixer */
2842static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2843{
2844 hda_nid_t srcs[5];
2845 int num = snd_hda_get_connections(codec, pin, srcs,
2846 ARRAY_SIZE(srcs));
2847 if (num != 1 ||
2848 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2849 return pin;
2850 return srcs[0];
2851}
2852
Takashi Iwai7085ec12009-10-02 09:03:58 +02002853/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002854static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002855 hda_nid_t dac)
2856{
David Henningssoncc1c4522010-11-24 14:17:47 +01002857 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002858 int i, num;
2859
Takashi Iwai604401a2011-04-27 15:14:23 +02002860 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002861 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2862 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002863 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002864 return mix[i];
2865 }
2866 return 0;
2867}
2868
Takashi Iwaice764ab2011-04-27 16:35:23 +02002869/* select the connection from pin to DAC if needed */
2870static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2871 hda_nid_t dac)
2872{
2873 hda_nid_t mix[5];
2874 int i, num;
2875
2876 pin = alc_go_down_to_selector(codec, pin);
2877 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2878 if (num < 2)
2879 return 0;
2880 for (i = 0; i < num; i++) {
2881 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2882 snd_hda_codec_update_cache(codec, pin, 0,
2883 AC_VERB_SET_CONNECT_SEL, i);
2884 return 0;
2885 }
2886 }
2887 return 0;
2888}
2889
Takashi Iwai7085ec12009-10-02 09:03:58 +02002890/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002891static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002892{
2893 struct alc_spec *spec = codec->spec;
2894 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002895 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002896
Takashi Iwai604401a2011-04-27 15:14:23 +02002897 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002898 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002899 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002900 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002901 if (!nid)
2902 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002903 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2904 spec->multiout.num_dacs))
2905 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002906 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2907 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2908 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002909 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2910 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2911 continue;
2912 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002913 }
2914 return 0;
2915}
2916
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002917static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2918{
2919 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2920 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2921 return alc_auto_look_for_dac(codec, pin);
2922 return 0;
2923}
2924
Takashi Iwaic2674682011-08-24 17:57:44 +02002925static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2926 const hda_nid_t *pins, hda_nid_t *dacs)
2927{
2928 int i;
2929
2930 if (num_outs && !dacs[0]) {
2931 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2932 if (!dacs[0])
2933 return 0;
2934 }
2935
2936 for (i = 1; i < num_outs; i++)
2937 dacs[i] = get_dac_if_single(codec, pins[i]);
2938 for (i = 1; i < num_outs; i++) {
2939 if (!dacs[i])
2940 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2941 }
2942 return 0;
2943}
2944
2945static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2946 unsigned int location);
2947
Takashi Iwai7085ec12009-10-02 09:03:58 +02002948/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02002949static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002950{
2951 struct alc_spec *spec = codec->spec;
Takashi Iwaicb053a82011-06-27 11:32:07 +02002952 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai350434e2011-06-30 21:29:12 +02002953 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002954 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002955
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002956 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002957 /* set num_dacs once to full for alc_auto_look_for_dac() */
2958 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02002959 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002960 spec->multiout.extra_out_nid[0] = 0;
2961 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2962 spec->multiout.dac_nids = spec->private_dac_nids;
2963
2964 /* fill hard-wired DACs first */
2965 if (!redone) {
2966 for (i = 0; i < cfg->line_outs; i++)
2967 spec->private_dac_nids[i] =
2968 get_dac_if_single(codec, cfg->line_out_pins[i]);
2969 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02002970 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002971 get_dac_if_single(codec, cfg->hp_pins[0]);
2972 if (cfg->speaker_outs)
2973 spec->multiout.extra_out_nid[0] =
2974 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002975 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002976
2977 for (i = 0; i < cfg->line_outs; i++) {
2978 hda_nid_t pin = cfg->line_out_pins[i];
2979 if (spec->private_dac_nids[i])
2980 continue;
2981 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2982 if (!spec->private_dac_nids[i] && !redone) {
2983 /* if we can't find primary DACs, re-probe without
2984 * checking the hard-wired DACs
2985 */
2986 redone = true;
2987 goto again;
2988 }
2989 }
2990
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002991 /* re-count num_dacs and squash invalid entries */
2992 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002993 for (i = 0; i < cfg->line_outs; i++) {
2994 if (spec->private_dac_nids[i])
2995 spec->multiout.num_dacs++;
2996 else
2997 memmove(spec->private_dac_nids + i,
2998 spec->private_dac_nids + i + 1,
2999 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3000 }
3001
Takashi Iwaic2674682011-08-24 17:57:44 +02003002 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3003 /* try to fill multi-io first */
3004 unsigned int location, defcfg;
3005 int num_pins;
Takashi Iwaibb8bf4d2011-07-06 13:07:54 +02003006
Takashi Iwaic2674682011-08-24 17:57:44 +02003007 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3008 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003009
Takashi Iwaic2674682011-08-24 17:57:44 +02003010 num_pins = alc_auto_fill_multi_ios(codec, location);
3011 if (num_pins > 0) {
3012 spec->multi_ios = num_pins;
3013 spec->ext_channel_count = 2;
3014 spec->multiout.num_dacs = num_pins + 1;
3015 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003016 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003017
Takashi Iwai716eef02011-10-21 15:07:42 +02003018 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3019 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003020 spec->multiout.hp_out_nid);
Takashi Iwai716eef02011-10-21 15:07:42 +02003021 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3022 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003023 spec->multiout.extra_out_nid);
3024
Takashi Iwai23c09b02011-08-19 09:05:35 +02003025 return 0;
3026}
3027
Takashi Iwai527e4d72011-10-27 16:33:27 +02003028static inline unsigned int get_ctl_pos(unsigned int data)
3029{
3030 hda_nid_t nid = get_amp_nid_(data);
3031 unsigned int dir = get_amp_direction_(data);
3032 return (nid << 1) | dir;
3033}
3034
3035#define is_ctl_used(bits, data) \
3036 test_bit(get_ctl_pos(data), bits)
3037#define mark_ctl_usage(bits, data) \
3038 set_bit(get_ctl_pos(data), bits)
3039
Takashi Iwai343a04b2011-07-06 14:28:39 +02003040static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003041 const char *pfx, int cidx,
3042 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003043{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003044 struct alc_spec *spec = codec->spec;
3045 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003046 if (!nid)
3047 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003048 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3049 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3050 return 0;
3051 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003052 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003053 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003054}
3055
Takashi Iwai343a04b2011-07-06 14:28:39 +02003056#define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
3057 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai97aaab72011-07-06 14:02:55 +02003058
3059/* create a mute-switch for the given mixer widget;
3060 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3061 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003062static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003063 const char *pfx, int cidx,
3064 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003065{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003066 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003067 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003068 int type;
3069 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003070 if (!nid)
3071 return 0;
3072 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3073 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3074 type = ALC_CTL_WIDGET_MUTE;
3075 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3076 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003077 type = ALC_CTL_WIDGET_MUTE;
3078 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3079 } else {
3080 type = ALC_CTL_BIND_MUTE;
3081 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3082 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003083 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3084 return 0;
3085 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003086 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003087}
3088
Takashi Iwai343a04b2011-07-06 14:28:39 +02003089#define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
3090 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003091
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003092static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3093 hda_nid_t pin, hda_nid_t dac)
3094{
3095 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3096 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3097 return pin;
3098 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3099 return mix;
3100 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3101 return dac;
3102 return 0;
3103}
3104
3105static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3106 hda_nid_t pin, hda_nid_t dac)
3107{
3108 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3109 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3110 return dac;
3111 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3112 return mix;
3113 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3114 return pin;
3115 return 0;
3116}
3117
Takashi Iwai7085ec12009-10-02 09:03:58 +02003118/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003119static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003120 const struct auto_pin_cfg *cfg)
3121{
3122 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003123 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003124
Takashi Iwaice764ab2011-04-27 16:35:23 +02003125 noutputs = cfg->line_outs;
3126 if (spec->multi_ios > 0)
3127 noutputs += spec->multi_ios;
3128
3129 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003130 const char *name;
3131 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003132 hda_nid_t dac, pin;
3133 hda_nid_t sw, vol;
3134
3135 dac = spec->multiout.dac_nids[i];
3136 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003137 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003138 if (i >= cfg->line_outs)
3139 pin = spec->multi_io[i - 1].pin;
3140 else
3141 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003142
3143 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3144 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003145 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003146 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003147 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003148 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003149 if (err < 0)
3150 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003151 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003152 if (err < 0)
3153 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003154 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003155 if (err < 0)
3156 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003157 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003158 if (err < 0)
3159 return err;
3160 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003161 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003162 if (err < 0)
3163 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003164 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003165 if (err < 0)
3166 return err;
3167 }
3168 }
3169 return 0;
3170}
3171
Takashi Iwai343a04b2011-07-06 14:28:39 +02003172static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai23c09b02011-08-19 09:05:35 +02003173 hda_nid_t dac, const char *pfx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003174{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003175 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003176 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003177 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003178
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003179 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003180 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003181 /* the corresponding DAC is already occupied */
3182 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3183 return 0; /* no way */
3184 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003185 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3186 if (is_ctl_used(spec->sw_ctls, val))
3187 return 0; /* already created */
3188 mark_ctl_usage(spec->sw_ctls, val);
3189 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003190 }
3191
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003192 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3193 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3194 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003195 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003196 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003197 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003198 if (err < 0)
3199 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003200 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003201}
3202
Takashi Iwai23c09b02011-08-19 09:05:35 +02003203static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3204 unsigned int nums,
3205 struct hda_ctl_ops *ops)
3206{
3207 struct alc_spec *spec = codec->spec;
3208 struct hda_bind_ctls **ctlp, *ctl;
3209 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3210 ctlp = snd_array_new(&spec->bind_ctls);
3211 if (!ctlp)
3212 return NULL;
3213 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3214 *ctlp = ctl;
3215 if (ctl)
3216 ctl->ops = ops;
3217 return ctl;
3218}
3219
3220/* add playback controls for speaker and HP outputs */
3221static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3222 const hda_nid_t *pins,
3223 const hda_nid_t *dacs,
3224 const char *pfx)
3225{
3226 struct alc_spec *spec = codec->spec;
3227 struct hda_bind_ctls *ctl;
3228 char name[32];
3229 int i, n, err;
3230
3231 if (!num_pins || !pins[0])
3232 return 0;
3233
Takashi Iwai527e4d72011-10-27 16:33:27 +02003234 if (num_pins == 1) {
3235 hda_nid_t dac = *dacs;
3236 if (!dac)
3237 dac = spec->multiout.dac_nids[0];
3238 return alc_auto_create_extra_out(codec, *pins, dac, pfx);
3239 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003240
3241 if (dacs[num_pins - 1]) {
3242 /* OK, we have a multi-output system with individual volumes */
3243 for (i = 0; i < num_pins; i++) {
3244 snprintf(name, sizeof(name), "%s %s",
3245 pfx, channel_name[i]);
3246 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3247 name);
3248 if (err < 0)
3249 return err;
3250 }
3251 return 0;
3252 }
3253
3254 /* Let's create a bind-controls */
3255 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3256 if (!ctl)
3257 return -ENOMEM;
3258 n = 0;
3259 for (i = 0; i < num_pins; i++) {
3260 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3261 ctl->values[n++] =
3262 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3263 }
3264 if (n) {
3265 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3266 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3267 if (err < 0)
3268 return err;
3269 }
3270
3271 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3272 if (!ctl)
3273 return -ENOMEM;
3274 n = 0;
3275 for (i = 0; i < num_pins; i++) {
3276 hda_nid_t vol;
3277 if (!pins[i] || !dacs[i])
3278 continue;
3279 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3280 if (vol)
3281 ctl->values[n++] =
3282 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3283 }
3284 if (n) {
3285 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3286 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3287 if (err < 0)
3288 return err;
3289 }
3290 return 0;
3291}
3292
Takashi Iwai343a04b2011-07-06 14:28:39 +02003293static int alc_auto_create_hp_out(struct hda_codec *codec)
3294{
3295 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003296 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3297 spec->autocfg.hp_pins,
3298 spec->multiout.hp_out_nid,
3299 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003300}
3301
3302static int alc_auto_create_speaker_out(struct hda_codec *codec)
3303{
3304 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003305 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3306 spec->autocfg.speaker_pins,
3307 spec->multiout.extra_out_nid,
3308 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003309}
3310
Takashi Iwai343a04b2011-07-06 14:28:39 +02003311static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003312 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003313 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003314{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003315 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003316 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003317 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003318
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003319 alc_set_pin_output(codec, pin, pin_type);
3320 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003321 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003322 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003323 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003324 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003325 mix = srcs[i];
3326 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003327 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003328 if (!mix)
3329 return;
3330
3331 /* need the manual connection? */
3332 if (num > 1)
3333 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3334 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003335 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3336 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003337 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003338 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003339 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003340 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003341 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003342 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3343 if (nid)
3344 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3345 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003346
3347 /* unmute DAC if it's not assigned to a mixer */
3348 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3349 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3350 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3351 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003352}
3353
Takashi Iwai343a04b2011-07-06 14:28:39 +02003354static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003355{
3356 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003357 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003358 int i;
3359
3360 for (i = 0; i <= HDA_SIDE; i++) {
3361 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3362 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003363 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003364 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003365 }
3366}
3367
Takashi Iwai343a04b2011-07-06 14:28:39 +02003368static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003369{
3370 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003371 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003372 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003373
David Henningsson636030e2011-10-12 19:26:03 +02003374 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003375 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3376 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003377 pin = spec->autocfg.hp_pins[i];
3378 if (!pin)
3379 break;
3380 dac = spec->multiout.hp_out_nid[i];
3381 if (!dac) {
3382 if (i > 0 && spec->multiout.hp_out_nid[0])
3383 dac = spec->multiout.hp_out_nid[0];
3384 else
3385 dac = spec->multiout.dac_nids[0];
3386 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003387 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3388 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003389 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003390 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3391 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003392 pin = spec->autocfg.speaker_pins[i];
3393 if (!pin)
3394 break;
3395 dac = spec->multiout.extra_out_nid[i];
3396 if (!dac) {
3397 if (i > 0 && spec->multiout.extra_out_nid[0])
3398 dac = spec->multiout.extra_out_nid[0];
3399 else
3400 dac = spec->multiout.dac_nids[0];
3401 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003402 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3403 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003404}
3405
Takashi Iwaice764ab2011-04-27 16:35:23 +02003406/*
3407 * multi-io helper
3408 */
3409static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3410 unsigned int location)
3411{
3412 struct alc_spec *spec = codec->spec;
3413 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003414 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwaice764ab2011-04-27 16:35:23 +02003415 int type, i, num_pins = 0;
3416
3417 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3418 for (i = 0; i < cfg->num_inputs; i++) {
3419 hda_nid_t nid = cfg->inputs[i].pin;
3420 hda_nid_t dac;
3421 unsigned int defcfg, caps;
3422 if (cfg->inputs[i].type != type)
3423 continue;
3424 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3425 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3426 continue;
3427 if (location && get_defcfg_location(defcfg) != location)
3428 continue;
3429 caps = snd_hda_query_pin_caps(codec, nid);
3430 if (!(caps & AC_PINCAP_OUT))
3431 continue;
3432 dac = alc_auto_look_for_dac(codec, nid);
3433 if (!dac)
3434 continue;
3435 spec->multi_io[num_pins].pin = nid;
3436 spec->multi_io[num_pins].dac = dac;
3437 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003438 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003439 }
3440 }
3441 spec->multiout.num_dacs = 1;
Takashi Iwaic2674682011-08-24 17:57:44 +02003442 if (num_pins < 2) {
3443 /* clear up again */
3444 memset(spec->private_dac_nids, 0,
3445 sizeof(spec->private_dac_nids));
3446 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003447 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003448 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003449 return num_pins;
3450}
3451
3452static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3453 struct snd_ctl_elem_info *uinfo)
3454{
3455 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3456 struct alc_spec *spec = codec->spec;
3457
3458 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3459 uinfo->count = 1;
3460 uinfo->value.enumerated.items = spec->multi_ios + 1;
3461 if (uinfo->value.enumerated.item > spec->multi_ios)
3462 uinfo->value.enumerated.item = spec->multi_ios;
3463 sprintf(uinfo->value.enumerated.name, "%dch",
3464 (uinfo->value.enumerated.item + 1) * 2);
3465 return 0;
3466}
3467
3468static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3469 struct snd_ctl_elem_value *ucontrol)
3470{
3471 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3472 struct alc_spec *spec = codec->spec;
3473 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3474 return 0;
3475}
3476
3477static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3478{
3479 struct alc_spec *spec = codec->spec;
3480 hda_nid_t nid = spec->multi_io[idx].pin;
3481
3482 if (!spec->multi_io[idx].ctl_in)
3483 spec->multi_io[idx].ctl_in =
3484 snd_hda_codec_read(codec, nid, 0,
3485 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3486 if (output) {
3487 snd_hda_codec_update_cache(codec, nid, 0,
3488 AC_VERB_SET_PIN_WIDGET_CONTROL,
3489 PIN_OUT);
3490 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3491 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3492 HDA_AMP_MUTE, 0);
3493 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3494 } else {
3495 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3496 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3497 HDA_AMP_MUTE, HDA_AMP_MUTE);
3498 snd_hda_codec_update_cache(codec, nid, 0,
3499 AC_VERB_SET_PIN_WIDGET_CONTROL,
3500 spec->multi_io[idx].ctl_in);
3501 }
3502 return 0;
3503}
3504
3505static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3506 struct snd_ctl_elem_value *ucontrol)
3507{
3508 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3509 struct alc_spec *spec = codec->spec;
3510 int i, ch;
3511
3512 ch = ucontrol->value.enumerated.item[0];
3513 if (ch < 0 || ch > spec->multi_ios)
3514 return -EINVAL;
3515 if (ch == (spec->ext_channel_count - 1) / 2)
3516 return 0;
3517 spec->ext_channel_count = (ch + 1) * 2;
3518 for (i = 0; i < spec->multi_ios; i++)
3519 alc_set_multi_io(codec, i, i < ch);
3520 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003521 if (spec->need_dac_fix && !spec->const_channel_count)
3522 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003523 return 1;
3524}
3525
Takashi Iwaia9111322011-05-02 11:30:18 +02003526static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003527 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3528 .name = "Channel Mode",
3529 .info = alc_auto_ch_mode_info,
3530 .get = alc_auto_ch_mode_get,
3531 .put = alc_auto_ch_mode_put,
3532};
3533
Takashi Iwai23c09b02011-08-19 09:05:35 +02003534static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003535{
3536 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003537
Takashi Iwaic2674682011-08-24 17:57:44 +02003538 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003539 struct snd_kcontrol_new *knew;
3540
3541 knew = alc_kcontrol_new(spec);
3542 if (!knew)
3543 return -ENOMEM;
3544 *knew = alc_auto_channel_mode_enum;
3545 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3546 if (!knew->name)
3547 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003548 }
3549 return 0;
3550}
3551
Takashi Iwai1d045db2011-07-07 18:23:21 +02003552/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3553 * active input pins
3554 */
3555static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3556{
3557 struct alc_spec *spec = codec->spec;
3558 const struct hda_input_mux *imux;
3559 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3560 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3561 int i, n, nums;
3562
3563 imux = spec->input_mux;
3564 if (!imux)
3565 return;
3566 if (spec->dyn_adc_switch)
3567 return;
3568
3569 nums = 0;
3570 for (n = 0; n < spec->num_adc_nids; n++) {
3571 hda_nid_t cap = spec->private_capsrc_nids[n];
3572 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3573 for (i = 0; i < imux->num_items; i++) {
3574 hda_nid_t pin = spec->imux_pins[i];
3575 if (pin) {
3576 if (get_connection_index(codec, cap, pin) < 0)
3577 break;
3578 } else if (num_conns <= imux->items[i].index)
3579 break;
3580 }
3581 if (i >= imux->num_items) {
3582 adc_nids[nums] = spec->private_adc_nids[n];
3583 capsrc_nids[nums++] = cap;
3584 }
3585 }
3586 if (!nums) {
3587 /* check whether ADC-switch is possible */
3588 if (!alc_check_dyn_adc_switch(codec)) {
3589 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3590 " using fallback 0x%x\n",
3591 codec->chip_name, spec->private_adc_nids[0]);
3592 spec->num_adc_nids = 1;
3593 spec->auto_mic = 0;
3594 return;
3595 }
3596 } else if (nums != spec->num_adc_nids) {
3597 memcpy(spec->private_adc_nids, adc_nids,
3598 nums * sizeof(hda_nid_t));
3599 memcpy(spec->private_capsrc_nids, capsrc_nids,
3600 nums * sizeof(hda_nid_t));
3601 spec->num_adc_nids = nums;
3602 }
3603
3604 if (spec->auto_mic)
3605 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3606 else if (spec->input_mux->num_items == 1)
3607 spec->num_adc_nids = 1; /* reduce to a single ADC */
3608}
3609
3610/*
3611 * initialize ADC paths
3612 */
3613static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3614{
3615 struct alc_spec *spec = codec->spec;
3616 hda_nid_t nid;
3617
3618 nid = spec->adc_nids[adc_idx];
3619 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003620 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003621 snd_hda_codec_write(codec, nid, 0,
3622 AC_VERB_SET_AMP_GAIN_MUTE,
3623 AMP_IN_MUTE(0));
3624 return;
3625 }
3626 if (!spec->capsrc_nids)
3627 return;
3628 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003629 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003630 snd_hda_codec_write(codec, nid, 0,
3631 AC_VERB_SET_AMP_GAIN_MUTE,
3632 AMP_OUT_MUTE);
3633}
3634
3635static void alc_auto_init_input_src(struct hda_codec *codec)
3636{
3637 struct alc_spec *spec = codec->spec;
3638 int c, nums;
3639
3640 for (c = 0; c < spec->num_adc_nids; c++)
3641 alc_auto_init_adc(codec, c);
3642 if (spec->dyn_adc_switch)
3643 nums = 1;
3644 else
3645 nums = spec->num_adc_nids;
3646 for (c = 0; c < nums; c++)
3647 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3648}
3649
3650/* add mic boosts if needed */
3651static int alc_auto_add_mic_boost(struct hda_codec *codec)
3652{
3653 struct alc_spec *spec = codec->spec;
3654 struct auto_pin_cfg *cfg = &spec->autocfg;
3655 int i, err;
3656 int type_idx = 0;
3657 hda_nid_t nid;
3658 const char *prev_label = NULL;
3659
3660 for (i = 0; i < cfg->num_inputs; i++) {
3661 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3662 break;
3663 nid = cfg->inputs[i].pin;
3664 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3665 const char *label;
3666 char boost_label[32];
3667
3668 label = hda_get_autocfg_input_label(codec, cfg, i);
3669 if (prev_label && !strcmp(label, prev_label))
3670 type_idx++;
3671 else
3672 type_idx = 0;
3673 prev_label = label;
3674
3675 snprintf(boost_label, sizeof(boost_label),
3676 "%s Boost Volume", label);
3677 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3678 boost_label, type_idx,
3679 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3680 if (err < 0)
3681 return err;
3682 }
3683 }
3684 return 0;
3685}
3686
3687/* select or unmute the given capsrc route */
3688static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3689 int idx)
3690{
3691 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3692 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3693 HDA_AMP_MUTE, 0);
3694 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3695 snd_hda_codec_write_cache(codec, cap, 0,
3696 AC_VERB_SET_CONNECT_SEL, idx);
3697 }
3698}
3699
3700/* set the default connection to that pin */
3701static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3702{
3703 struct alc_spec *spec = codec->spec;
3704 int i;
3705
3706 if (!pin)
3707 return 0;
3708 for (i = 0; i < spec->num_adc_nids; i++) {
3709 hda_nid_t cap = spec->capsrc_nids ?
3710 spec->capsrc_nids[i] : spec->adc_nids[i];
3711 int idx;
3712
3713 idx = get_connection_index(codec, cap, pin);
3714 if (idx < 0)
3715 continue;
3716 select_or_unmute_capsrc(codec, cap, idx);
3717 return i; /* return the found index */
3718 }
3719 return -1; /* not found */
3720}
3721
3722/* initialize some special cases for input sources */
3723static void alc_init_special_input_src(struct hda_codec *codec)
3724{
3725 struct alc_spec *spec = codec->spec;
3726 int i;
3727
3728 for (i = 0; i < spec->autocfg.num_inputs; i++)
3729 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3730}
3731
3732/* assign appropriate capture mixers */
3733static void set_capture_mixer(struct hda_codec *codec)
3734{
3735 struct alc_spec *spec = codec->spec;
3736 static const struct snd_kcontrol_new *caps[2][3] = {
3737 { alc_capture_mixer_nosrc1,
3738 alc_capture_mixer_nosrc2,
3739 alc_capture_mixer_nosrc3 },
3740 { alc_capture_mixer1,
3741 alc_capture_mixer2,
3742 alc_capture_mixer3 },
3743 };
3744
3745 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003746 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003747 if (!spec->capsrc_nids)
3748 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003749 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003750 return; /* no volume in capsrc, too */
3751 spec->vol_in_capsrc = 1;
3752 }
3753
3754 if (spec->num_adc_nids > 0) {
3755 int mux = 0;
3756 int num_adcs = 0;
3757
3758 if (spec->input_mux && spec->input_mux->num_items > 1)
3759 mux = 1;
3760 if (spec->auto_mic) {
3761 num_adcs = 1;
3762 mux = 0;
3763 } else if (spec->dyn_adc_switch)
3764 num_adcs = 1;
3765 if (!num_adcs) {
3766 if (spec->num_adc_nids > 3)
3767 spec->num_adc_nids = 3;
3768 else if (!spec->num_adc_nids)
3769 return;
3770 num_adcs = spec->num_adc_nids;
3771 }
3772 spec->cap_mixer = caps[mux][num_adcs - 1];
3773 }
3774}
3775
3776/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003777 * standard auto-parser initializations
3778 */
3779static void alc_auto_init_std(struct hda_codec *codec)
3780{
3781 struct alc_spec *spec = codec->spec;
3782 alc_auto_init_multi_out(codec);
3783 alc_auto_init_extra_out(codec);
3784 alc_auto_init_analog_input(codec);
3785 alc_auto_init_input_src(codec);
3786 alc_auto_init_digital(codec);
3787 if (spec->unsol_event)
3788 alc_inithook(codec);
3789}
3790
3791/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003792 * Digital-beep handlers
3793 */
3794#ifdef CONFIG_SND_HDA_INPUT_BEEP
3795#define set_beep_amp(spec, nid, idx, dir) \
3796 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3797
3798static const struct snd_pci_quirk beep_white_list[] = {
3799 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3800 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3801 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3802 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3803 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3804 {}
3805};
3806
3807static inline int has_cdefine_beep(struct hda_codec *codec)
3808{
3809 struct alc_spec *spec = codec->spec;
3810 const struct snd_pci_quirk *q;
3811 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3812 if (q)
3813 return q->value;
3814 return spec->cdefine.enable_pcbeep;
3815}
3816#else
3817#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3818#define has_cdefine_beep(codec) 0
3819#endif
3820
3821/* parse the BIOS configuration and set up the alc_spec */
3822/* return 1 if successful, 0 if the proper config is not found,
3823 * or a negative error code
3824 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003825static int alc_parse_auto_config(struct hda_codec *codec,
3826 const hda_nid_t *ignore_nids,
3827 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003828{
3829 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003830 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003831 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003832
Takashi Iwai53c334a2011-08-23 18:27:14 +02003833 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3834 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003835 if (err < 0)
3836 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003837 if (!cfg->line_outs) {
3838 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003839 spec->multiout.max_channels = 2;
3840 spec->no_analog = 1;
3841 goto dig_only;
3842 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003843 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003844 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003845
Takashi Iwai06503672011-10-06 08:27:19 +02003846 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3847 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003848 /* use HP as primary out */
3849 cfg->speaker_outs = cfg->line_outs;
3850 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3851 sizeof(cfg->speaker_pins));
3852 cfg->line_outs = cfg->hp_outs;
3853 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3854 cfg->hp_outs = 0;
3855 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3856 cfg->line_out_type = AUTO_PIN_HP_OUT;
3857 }
3858
Takashi Iwai1d045db2011-07-07 18:23:21 +02003859 err = alc_auto_fill_dac_nids(codec);
3860 if (err < 0)
3861 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003862 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003863 if (err < 0)
3864 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003865 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003866 if (err < 0)
3867 return err;
3868 err = alc_auto_create_hp_out(codec);
3869 if (err < 0)
3870 return err;
3871 err = alc_auto_create_speaker_out(codec);
3872 if (err < 0)
3873 return err;
3874 err = alc_auto_create_input_ctls(codec);
3875 if (err < 0)
3876 return err;
3877
3878 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3879
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003880 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02003881 alc_auto_parse_digital(codec);
3882
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003883 if (!spec->no_analog)
3884 alc_remove_invalid_adc_nids(codec);
3885
3886 if (ssid_nids)
3887 alc_ssid_check(codec, ssid_nids);
3888
3889 if (!spec->no_analog) {
3890 alc_auto_check_switches(codec);
3891 err = alc_auto_add_mic_boost(codec);
3892 if (err < 0)
3893 return err;
3894 }
3895
Takashi Iwai1d045db2011-07-07 18:23:21 +02003896 if (spec->kctls.list)
3897 add_mixer(spec, spec->kctls.list);
3898
Takashi Iwai1d045db2011-07-07 18:23:21 +02003899 return 1;
3900}
3901
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003902static int alc880_parse_auto_config(struct hda_codec *codec)
3903{
3904 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3905 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3906 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3907}
3908
Takashi Iwai1d045db2011-07-07 18:23:21 +02003909#ifdef CONFIG_SND_HDA_POWER_SAVE
3910static const struct hda_amp_list alc880_loopbacks[] = {
3911 { 0x0b, HDA_INPUT, 0 },
3912 { 0x0b, HDA_INPUT, 1 },
3913 { 0x0b, HDA_INPUT, 2 },
3914 { 0x0b, HDA_INPUT, 3 },
3915 { 0x0b, HDA_INPUT, 4 },
3916 { } /* end */
3917};
3918#endif
3919
3920/*
3921 * board setups
3922 */
3923#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3924#define alc_board_config \
3925 snd_hda_check_board_config
3926#define alc_board_codec_sid_config \
3927 snd_hda_check_board_codec_sid_config
3928#include "alc_quirks.c"
3929#else
3930#define alc_board_config(codec, nums, models, tbl) -1
3931#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3932#define setup_preset(codec, x) /* NOP */
3933#endif
3934
3935/*
3936 * OK, here we have finally the patch for ALC880
3937 */
3938#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3939#include "alc880_quirks.c"
3940#endif
3941
3942static int patch_alc880(struct hda_codec *codec)
3943{
3944 struct alc_spec *spec;
3945 int board_config;
3946 int err;
3947
3948 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3949 if (spec == NULL)
3950 return -ENOMEM;
3951
3952 codec->spec = spec;
3953
3954 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003955 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003956
3957 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3958 alc880_models, alc880_cfg_tbl);
3959 if (board_config < 0) {
3960 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3961 codec->chip_name);
3962 board_config = ALC_MODEL_AUTO;
3963 }
3964
3965 if (board_config == ALC_MODEL_AUTO) {
3966 /* automatic parse from the BIOS config */
3967 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02003968 if (err < 0)
3969 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003970#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3971 else if (!err) {
3972 printk(KERN_INFO
3973 "hda_codec: Cannot set up configuration "
3974 "from BIOS. Using 3-stack mode...\n");
3975 board_config = ALC880_3ST;
3976 }
3977#endif
3978 }
3979
Takashi Iwai1d045db2011-07-07 18:23:21 +02003980 if (board_config != ALC_MODEL_AUTO)
3981 setup_preset(codec, &alc880_presets[board_config]);
3982
Takashi Iwai60a6a842011-07-27 14:01:24 +02003983 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003984 alc_auto_fill_adc_caps(codec);
3985 alc_rebuild_imux_for_auto_mic(codec);
3986 alc_remove_invalid_adc_nids(codec);
3987 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003988
3989 if (!spec->no_analog && !spec->cap_mixer)
3990 set_capture_mixer(codec);
3991
3992 if (!spec->no_analog) {
3993 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02003994 if (err < 0)
3995 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003996 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3997 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003998
3999 spec->vmaster_nid = 0x0c;
4000
4001 codec->patch_ops = alc_patch_ops;
4002 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004003 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004004#ifdef CONFIG_SND_HDA_POWER_SAVE
4005 if (!spec->loopback.amplist)
4006 spec->loopback.amplist = alc880_loopbacks;
4007#endif
4008
4009 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004010
4011 error:
4012 alc_free(codec);
4013 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004014}
4015
4016
4017/*
4018 * ALC260 support
4019 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004020static int alc260_parse_auto_config(struct hda_codec *codec)
4021{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004022 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004023 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4024 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004025}
4026
Takashi Iwai1d045db2011-07-07 18:23:21 +02004027#ifdef CONFIG_SND_HDA_POWER_SAVE
4028static const struct hda_amp_list alc260_loopbacks[] = {
4029 { 0x07, HDA_INPUT, 0 },
4030 { 0x07, HDA_INPUT, 1 },
4031 { 0x07, HDA_INPUT, 2 },
4032 { 0x07, HDA_INPUT, 3 },
4033 { 0x07, HDA_INPUT, 4 },
4034 { } /* end */
4035};
4036#endif
4037
4038/*
4039 * Pin config fixes
4040 */
4041enum {
4042 PINFIX_HP_DC5750,
4043};
4044
4045static const struct alc_fixup alc260_fixups[] = {
4046 [PINFIX_HP_DC5750] = {
4047 .type = ALC_FIXUP_PINS,
4048 .v.pins = (const struct alc_pincfg[]) {
4049 { 0x11, 0x90130110 }, /* speaker */
4050 { }
4051 }
4052 },
4053};
4054
4055static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4056 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4057 {}
4058};
4059
4060/*
4061 */
4062#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4063#include "alc260_quirks.c"
4064#endif
4065
4066static int patch_alc260(struct hda_codec *codec)
4067{
4068 struct alc_spec *spec;
4069 int err, board_config;
4070
4071 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4072 if (spec == NULL)
4073 return -ENOMEM;
4074
4075 codec->spec = spec;
4076
4077 spec->mixer_nid = 0x07;
4078
4079 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4080 alc260_models, alc260_cfg_tbl);
4081 if (board_config < 0) {
4082 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4083 codec->chip_name);
4084 board_config = ALC_MODEL_AUTO;
4085 }
4086
4087 if (board_config == ALC_MODEL_AUTO) {
4088 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4089 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4090 }
4091
4092 if (board_config == ALC_MODEL_AUTO) {
4093 /* automatic parse from the BIOS config */
4094 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004095 if (err < 0)
4096 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004097#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4098 else if (!err) {
4099 printk(KERN_INFO
4100 "hda_codec: Cannot set up configuration "
4101 "from BIOS. Using base mode...\n");
4102 board_config = ALC260_BASIC;
4103 }
4104#endif
4105 }
4106
Takashi Iwai1d045db2011-07-07 18:23:21 +02004107 if (board_config != ALC_MODEL_AUTO)
4108 setup_preset(codec, &alc260_presets[board_config]);
4109
Takashi Iwai60a6a842011-07-27 14:01:24 +02004110 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004111 alc_auto_fill_adc_caps(codec);
4112 alc_rebuild_imux_for_auto_mic(codec);
4113 alc_remove_invalid_adc_nids(codec);
4114 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004115
4116 if (!spec->no_analog && !spec->cap_mixer)
4117 set_capture_mixer(codec);
4118
4119 if (!spec->no_analog) {
4120 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004121 if (err < 0)
4122 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004123 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4124 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004125
4126 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4127
4128 spec->vmaster_nid = 0x08;
4129
4130 codec->patch_ops = alc_patch_ops;
4131 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004132 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004133 spec->shutup = alc_eapd_shutup;
4134#ifdef CONFIG_SND_HDA_POWER_SAVE
4135 if (!spec->loopback.amplist)
4136 spec->loopback.amplist = alc260_loopbacks;
4137#endif
4138
4139 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004140
4141 error:
4142 alc_free(codec);
4143 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004144}
4145
4146
4147/*
4148 * ALC882/883/885/888/889 support
4149 *
4150 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4151 * configuration. Each pin widget can choose any input DACs and a mixer.
4152 * Each ADC is connected from a mixer of all inputs. This makes possible
4153 * 6-channel independent captures.
4154 *
4155 * In addition, an independent DAC for the multi-playback (not used in this
4156 * driver yet).
4157 */
4158#ifdef CONFIG_SND_HDA_POWER_SAVE
4159#define alc882_loopbacks alc880_loopbacks
4160#endif
4161
4162/*
4163 * Pin config fixes
4164 */
4165enum {
4166 PINFIX_ABIT_AW9D_MAX,
4167 PINFIX_LENOVO_Y530,
4168 PINFIX_PB_M5210,
4169 PINFIX_ACER_ASPIRE_7736,
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004170 PINFIX_ASUS_W90V,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004171};
4172
4173static const struct alc_fixup alc882_fixups[] = {
4174 [PINFIX_ABIT_AW9D_MAX] = {
4175 .type = ALC_FIXUP_PINS,
4176 .v.pins = (const struct alc_pincfg[]) {
4177 { 0x15, 0x01080104 }, /* side */
4178 { 0x16, 0x01011012 }, /* rear */
4179 { 0x17, 0x01016011 }, /* clfe */
4180 { }
4181 }
4182 },
4183 [PINFIX_LENOVO_Y530] = {
4184 .type = ALC_FIXUP_PINS,
4185 .v.pins = (const struct alc_pincfg[]) {
4186 { 0x15, 0x99130112 }, /* rear int speakers */
4187 { 0x16, 0x99130111 }, /* subwoofer */
4188 { }
4189 }
4190 },
4191 [PINFIX_PB_M5210] = {
4192 .type = ALC_FIXUP_VERBS,
4193 .v.verbs = (const struct hda_verb[]) {
4194 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4195 {}
4196 }
4197 },
4198 [PINFIX_ACER_ASPIRE_7736] = {
4199 .type = ALC_FIXUP_SKU,
4200 .v.sku = ALC_FIXUP_SKU_IGNORE,
4201 },
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004202 [PINFIX_ASUS_W90V] = {
4203 .type = ALC_FIXUP_PINS,
4204 .v.pins = (const struct alc_pincfg[]) {
4205 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4206 { }
4207 }
4208 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004209};
4210
4211static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4212 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004213 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004214 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4215 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4216 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4217 {}
4218};
4219
4220/*
4221 * BIOS auto configuration
4222 */
4223/* almost identical with ALC880 parser... */
4224static int alc882_parse_auto_config(struct hda_codec *codec)
4225{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004226 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004227 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4228 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004229}
4230
Takashi Iwai1d045db2011-07-07 18:23:21 +02004231/*
4232 */
4233#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4234#include "alc882_quirks.c"
4235#endif
4236
4237static int patch_alc882(struct hda_codec *codec)
4238{
4239 struct alc_spec *spec;
4240 int err, board_config;
4241
4242 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4243 if (spec == NULL)
4244 return -ENOMEM;
4245
4246 codec->spec = spec;
4247
4248 spec->mixer_nid = 0x0b;
4249
4250 switch (codec->vendor_id) {
4251 case 0x10ec0882:
4252 case 0x10ec0885:
4253 break;
4254 default:
4255 /* ALC883 and variants */
4256 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4257 break;
4258 }
4259
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004260 err = alc_codec_rename_from_preset(codec);
4261 if (err < 0)
4262 goto error;
4263
Takashi Iwai1d045db2011-07-07 18:23:21 +02004264 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4265 alc882_models, alc882_cfg_tbl);
4266
4267 if (board_config < 0)
4268 board_config = alc_board_codec_sid_config(codec,
4269 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4270
4271 if (board_config < 0) {
4272 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4273 codec->chip_name);
4274 board_config = ALC_MODEL_AUTO;
4275 }
4276
4277 if (board_config == ALC_MODEL_AUTO) {
4278 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4279 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4280 }
4281
4282 alc_auto_parse_customize_define(codec);
4283
4284 if (board_config == ALC_MODEL_AUTO) {
4285 /* automatic parse from the BIOS config */
4286 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004287 if (err < 0)
4288 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004289#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4290 else if (!err) {
4291 printk(KERN_INFO
4292 "hda_codec: Cannot set up configuration "
4293 "from BIOS. Using base mode...\n");
4294 board_config = ALC882_3ST_DIG;
4295 }
4296#endif
4297 }
4298
Takashi Iwai1d045db2011-07-07 18:23:21 +02004299 if (board_config != ALC_MODEL_AUTO)
4300 setup_preset(codec, &alc882_presets[board_config]);
4301
Takashi Iwai60a6a842011-07-27 14:01:24 +02004302 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004303 alc_auto_fill_adc_caps(codec);
4304 alc_rebuild_imux_for_auto_mic(codec);
4305 alc_remove_invalid_adc_nids(codec);
4306 }
4307
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004308 if (!spec->no_analog && !spec->cap_mixer)
4309 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004310
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004311 if (!spec->no_analog && has_cdefine_beep(codec)) {
4312 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004313 if (err < 0)
4314 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004315 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004316 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004317
4318 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4319
4320 spec->vmaster_nid = 0x0c;
4321
4322 codec->patch_ops = alc_patch_ops;
4323 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004324 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004325
4326 alc_init_jacks(codec);
4327#ifdef CONFIG_SND_HDA_POWER_SAVE
4328 if (!spec->loopback.amplist)
4329 spec->loopback.amplist = alc882_loopbacks;
4330#endif
4331
4332 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004333
4334 error:
4335 alc_free(codec);
4336 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004337}
4338
4339
4340/*
4341 * ALC262 support
4342 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004343static int alc262_parse_auto_config(struct hda_codec *codec)
4344{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004345 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004346 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4347 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004348}
4349
4350/*
4351 * Pin config fixes
4352 */
4353enum {
4354 PINFIX_FSC_H270,
4355 PINFIX_HP_Z200,
4356};
4357
4358static const struct alc_fixup alc262_fixups[] = {
4359 [PINFIX_FSC_H270] = {
4360 .type = ALC_FIXUP_PINS,
4361 .v.pins = (const struct alc_pincfg[]) {
4362 { 0x14, 0x99130110 }, /* speaker */
4363 { 0x15, 0x0221142f }, /* front HP */
4364 { 0x1b, 0x0121141f }, /* rear HP */
4365 { }
4366 }
4367 },
4368 [PINFIX_HP_Z200] = {
4369 .type = ALC_FIXUP_PINS,
4370 .v.pins = (const struct alc_pincfg[]) {
4371 { 0x16, 0x99130120 }, /* internal speaker */
4372 { }
4373 }
4374 },
4375};
4376
4377static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4378 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4379 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4380 {}
4381};
4382
4383
4384#ifdef CONFIG_SND_HDA_POWER_SAVE
4385#define alc262_loopbacks alc880_loopbacks
4386#endif
4387
Takashi Iwai1d045db2011-07-07 18:23:21 +02004388/*
4389 */
4390#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4391#include "alc262_quirks.c"
4392#endif
4393
4394static int patch_alc262(struct hda_codec *codec)
4395{
4396 struct alc_spec *spec;
4397 int board_config;
4398 int err;
4399
4400 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4401 if (spec == NULL)
4402 return -ENOMEM;
4403
4404 codec->spec = spec;
4405
4406 spec->mixer_nid = 0x0b;
4407
4408#if 0
4409 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4410 * under-run
4411 */
4412 {
4413 int tmp;
4414 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4415 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4416 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4417 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4418 }
4419#endif
4420 alc_auto_parse_customize_define(codec);
4421
4422 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4423
4424 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4425 alc262_models, alc262_cfg_tbl);
4426
4427 if (board_config < 0) {
4428 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4429 codec->chip_name);
4430 board_config = ALC_MODEL_AUTO;
4431 }
4432
4433 if (board_config == ALC_MODEL_AUTO) {
4434 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4435 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4436 }
4437
4438 if (board_config == ALC_MODEL_AUTO) {
4439 /* automatic parse from the BIOS config */
4440 err = alc262_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004441 if (err < 0)
4442 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004443#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4444 else if (!err) {
4445 printk(KERN_INFO
4446 "hda_codec: Cannot set up configuration "
4447 "from BIOS. Using base mode...\n");
4448 board_config = ALC262_BASIC;
4449 }
4450#endif
4451 }
4452
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004453 if (board_config != ALC_MODEL_AUTO)
4454 setup_preset(codec, &alc262_presets[board_config]);
4455
Takashi Iwai60a6a842011-07-27 14:01:24 +02004456 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004457 alc_auto_fill_adc_caps(codec);
4458 alc_rebuild_imux_for_auto_mic(codec);
4459 alc_remove_invalid_adc_nids(codec);
4460 }
4461
4462 if (!spec->no_analog && !spec->cap_mixer)
4463 set_capture_mixer(codec);
4464
Takashi Iwai1d045db2011-07-07 18:23:21 +02004465 if (!spec->no_analog && has_cdefine_beep(codec)) {
4466 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004467 if (err < 0)
4468 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004469 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004470 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004471
4472 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4473
4474 spec->vmaster_nid = 0x0c;
4475
4476 codec->patch_ops = alc_patch_ops;
4477 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004478 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004479 spec->shutup = alc_eapd_shutup;
4480
4481 alc_init_jacks(codec);
4482#ifdef CONFIG_SND_HDA_POWER_SAVE
4483 if (!spec->loopback.amplist)
4484 spec->loopback.amplist = alc262_loopbacks;
4485#endif
4486
4487 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004488
4489 error:
4490 alc_free(codec);
4491 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004492}
4493
4494/*
4495 * ALC268
4496 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004497/* bind Beep switches of both NID 0x0f and 0x10 */
4498static const struct hda_bind_ctls alc268_bind_beep_sw = {
4499 .ops = &snd_hda_bind_sw,
4500 .values = {
4501 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4502 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4503 0
4504 },
4505};
4506
4507static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4508 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4509 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4510 { }
4511};
4512
4513/* set PCBEEP vol = 0, mute connections */
4514static const struct hda_verb alc268_beep_init_verbs[] = {
4515 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4516 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4517 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4518 { }
4519};
4520
4521/*
4522 * BIOS auto configuration
4523 */
4524static int alc268_parse_auto_config(struct hda_codec *codec)
4525{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004526 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004527 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004528 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4529 if (err > 0) {
4530 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4531 add_mixer(spec, alc268_beep_mixer);
4532 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004533 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004534 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004535 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004536}
4537
Takashi Iwai1d045db2011-07-07 18:23:21 +02004538/*
4539 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004540static int patch_alc268(struct hda_codec *codec)
4541{
4542 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004543 int i, has_beep, err;
4544
4545 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4546 if (spec == NULL)
4547 return -ENOMEM;
4548
4549 codec->spec = spec;
4550
4551 /* ALC268 has no aa-loopback mixer */
4552
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004553 /* automatic parse from the BIOS config */
4554 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004555 if (err < 0)
4556 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004557
Takashi Iwai1d045db2011-07-07 18:23:21 +02004558 has_beep = 0;
4559 for (i = 0; i < spec->num_mixers; i++) {
4560 if (spec->mixers[i] == alc268_beep_mixer) {
4561 has_beep = 1;
4562 break;
4563 }
4564 }
4565
4566 if (has_beep) {
4567 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004568 if (err < 0)
4569 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004570 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4571 /* override the amp caps for beep generator */
4572 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4573 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4574 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4575 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4576 (0 << AC_AMPCAP_MUTE_SHIFT));
4577 }
4578
Takashi Iwai60a6a842011-07-27 14:01:24 +02004579 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004580 alc_auto_fill_adc_caps(codec);
4581 alc_rebuild_imux_for_auto_mic(codec);
4582 alc_remove_invalid_adc_nids(codec);
4583 }
4584
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004585 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004586 set_capture_mixer(codec);
4587
4588 spec->vmaster_nid = 0x02;
4589
4590 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004591 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004592 spec->shutup = alc_eapd_shutup;
4593
4594 alc_init_jacks(codec);
4595
4596 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004597
4598 error:
4599 alc_free(codec);
4600 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004601}
4602
4603/*
4604 * ALC269
4605 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004606#ifdef CONFIG_SND_HDA_POWER_SAVE
4607#define alc269_loopbacks alc880_loopbacks
4608#endif
4609
4610static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4611 .substreams = 1,
4612 .channels_min = 2,
4613 .channels_max = 8,
4614 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4615 /* NID is set in alc_build_pcms */
4616 .ops = {
4617 .open = alc_playback_pcm_open,
4618 .prepare = alc_playback_pcm_prepare,
4619 .cleanup = alc_playback_pcm_cleanup
4620 },
4621};
4622
4623static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4624 .substreams = 1,
4625 .channels_min = 2,
4626 .channels_max = 2,
4627 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4628 /* NID is set in alc_build_pcms */
4629};
4630
4631#ifdef CONFIG_SND_HDA_POWER_SAVE
4632static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4633{
4634 switch (codec->subsystem_id) {
4635 case 0x103c1586:
4636 return 1;
4637 }
4638 return 0;
4639}
4640
4641static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4642{
4643 /* update mute-LED according to the speaker mute state */
4644 if (nid == 0x01 || nid == 0x14) {
4645 int pinval;
4646 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4647 HDA_AMP_MUTE)
4648 pinval = 0x24;
4649 else
4650 pinval = 0x20;
4651 /* mic2 vref pin is used for mute LED control */
4652 snd_hda_codec_update_cache(codec, 0x19, 0,
4653 AC_VERB_SET_PIN_WIDGET_CONTROL,
4654 pinval);
4655 }
4656 return alc_check_power_status(codec, nid);
4657}
4658#endif /* CONFIG_SND_HDA_POWER_SAVE */
4659
4660/* different alc269-variants */
4661enum {
4662 ALC269_TYPE_ALC269VA,
4663 ALC269_TYPE_ALC269VB,
4664 ALC269_TYPE_ALC269VC,
4665};
4666
4667/*
4668 * BIOS auto configuration
4669 */
4670static int alc269_parse_auto_config(struct hda_codec *codec)
4671{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004672 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004673 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4674 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4675 struct alc_spec *spec = codec->spec;
4676 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4677 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004678
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004679 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004680}
4681
Takashi Iwai1d045db2011-07-07 18:23:21 +02004682static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4683{
4684 int val = alc_read_coef_idx(codec, 0x04);
4685 if (power_up)
4686 val |= 1 << 11;
4687 else
4688 val &= ~(1 << 11);
4689 alc_write_coef_idx(codec, 0x04, val);
4690}
4691
4692static void alc269_shutup(struct hda_codec *codec)
4693{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004694 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004695 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004696 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004697 alc269_toggle_power_output(codec, 0);
4698 msleep(150);
4699 }
4700}
4701
Takashi Iwai2a439522011-07-26 09:52:50 +02004702#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02004703static int alc269_resume(struct hda_codec *codec)
4704{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004705 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004706 alc269_toggle_power_output(codec, 0);
4707 msleep(150);
4708 }
4709
4710 codec->patch_ops.init(codec);
4711
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004712 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004713 alc269_toggle_power_output(codec, 1);
4714 msleep(200);
4715 }
4716
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004717 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004718 alc269_toggle_power_output(codec, 1);
4719
4720 snd_hda_codec_resume_amp(codec);
4721 snd_hda_codec_resume_cache(codec);
4722 hda_call_check_power_status(codec, 0x01);
4723 return 0;
4724}
Takashi Iwai2a439522011-07-26 09:52:50 +02004725#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004726
4727static void alc269_fixup_hweq(struct hda_codec *codec,
4728 const struct alc_fixup *fix, int action)
4729{
4730 int coef;
4731
4732 if (action != ALC_FIXUP_ACT_INIT)
4733 return;
4734 coef = alc_read_coef_idx(codec, 0x1e);
4735 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4736}
4737
4738static void alc271_fixup_dmic(struct hda_codec *codec,
4739 const struct alc_fixup *fix, int action)
4740{
4741 static const struct hda_verb verbs[] = {
4742 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4743 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4744 {}
4745 };
4746 unsigned int cfg;
4747
4748 if (strcmp(codec->chip_name, "ALC271X"))
4749 return;
4750 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4751 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4752 snd_hda_sequence_write(codec, verbs);
4753}
4754
Takashi Iwai017f2a12011-07-09 14:42:25 +02004755static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4756 const struct alc_fixup *fix, int action)
4757{
4758 struct alc_spec *spec = codec->spec;
4759
4760 if (action != ALC_FIXUP_ACT_PROBE)
4761 return;
4762
4763 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4764 * fix the sample rate of analog I/O to 44.1kHz
4765 */
4766 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4767 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4768}
4769
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004770static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4771 const struct alc_fixup *fix, int action)
4772{
4773 int coef;
4774
4775 if (action != ALC_FIXUP_ACT_INIT)
4776 return;
4777 /* The digital-mic unit sends PDM (differential signal) instead of
4778 * the standard PCM, thus you can't record a valid mono stream as is.
4779 * Below is a workaround specific to ALC269 to control the dmic
4780 * signal source as mono.
4781 */
4782 coef = alc_read_coef_idx(codec, 0x07);
4783 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4784}
4785
Takashi Iwai24519912011-08-16 15:08:49 +02004786static void alc269_quanta_automute(struct hda_codec *codec)
4787{
David Henningsson42cf0d02011-09-20 12:04:56 +02004788 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02004789
4790 snd_hda_codec_write(codec, 0x20, 0,
4791 AC_VERB_SET_COEF_INDEX, 0x0c);
4792 snd_hda_codec_write(codec, 0x20, 0,
4793 AC_VERB_SET_PROC_COEF, 0x680);
4794
4795 snd_hda_codec_write(codec, 0x20, 0,
4796 AC_VERB_SET_COEF_INDEX, 0x0c);
4797 snd_hda_codec_write(codec, 0x20, 0,
4798 AC_VERB_SET_PROC_COEF, 0x480);
4799}
4800
4801static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4802 const struct alc_fixup *fix, int action)
4803{
4804 struct alc_spec *spec = codec->spec;
4805 if (action != ALC_FIXUP_ACT_PROBE)
4806 return;
4807 spec->automute_hook = alc269_quanta_automute;
4808}
4809
Takashi Iwai1d045db2011-07-07 18:23:21 +02004810enum {
4811 ALC269_FIXUP_SONY_VAIO,
4812 ALC275_FIXUP_SONY_VAIO_GPIO2,
4813 ALC269_FIXUP_DELL_M101Z,
4814 ALC269_FIXUP_SKU_IGNORE,
4815 ALC269_FIXUP_ASUS_G73JW,
4816 ALC269_FIXUP_LENOVO_EAPD,
4817 ALC275_FIXUP_SONY_HWEQ,
4818 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02004819 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004820 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02004821 ALC269_FIXUP_QUANTA_MUTE,
4822 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02004823 ALC269_FIXUP_AMIC,
4824 ALC269_FIXUP_DMIC,
4825 ALC269VB_FIXUP_AMIC,
4826 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004827};
4828
4829static const struct alc_fixup alc269_fixups[] = {
4830 [ALC269_FIXUP_SONY_VAIO] = {
4831 .type = ALC_FIXUP_VERBS,
4832 .v.verbs = (const struct hda_verb[]) {
4833 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4834 {}
4835 }
4836 },
4837 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4838 .type = ALC_FIXUP_VERBS,
4839 .v.verbs = (const struct hda_verb[]) {
4840 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4841 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4842 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4843 { }
4844 },
4845 .chained = true,
4846 .chain_id = ALC269_FIXUP_SONY_VAIO
4847 },
4848 [ALC269_FIXUP_DELL_M101Z] = {
4849 .type = ALC_FIXUP_VERBS,
4850 .v.verbs = (const struct hda_verb[]) {
4851 /* Enables internal speaker */
4852 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4853 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4854 {}
4855 }
4856 },
4857 [ALC269_FIXUP_SKU_IGNORE] = {
4858 .type = ALC_FIXUP_SKU,
4859 .v.sku = ALC_FIXUP_SKU_IGNORE,
4860 },
4861 [ALC269_FIXUP_ASUS_G73JW] = {
4862 .type = ALC_FIXUP_PINS,
4863 .v.pins = (const struct alc_pincfg[]) {
4864 { 0x17, 0x99130111 }, /* subwoofer */
4865 { }
4866 }
4867 },
4868 [ALC269_FIXUP_LENOVO_EAPD] = {
4869 .type = ALC_FIXUP_VERBS,
4870 .v.verbs = (const struct hda_verb[]) {
4871 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4872 {}
4873 }
4874 },
4875 [ALC275_FIXUP_SONY_HWEQ] = {
4876 .type = ALC_FIXUP_FUNC,
4877 .v.func = alc269_fixup_hweq,
4878 .chained = true,
4879 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4880 },
4881 [ALC271_FIXUP_DMIC] = {
4882 .type = ALC_FIXUP_FUNC,
4883 .v.func = alc271_fixup_dmic,
4884 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02004885 [ALC269_FIXUP_PCM_44K] = {
4886 .type = ALC_FIXUP_FUNC,
4887 .v.func = alc269_fixup_pcm_44k,
4888 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004889 [ALC269_FIXUP_STEREO_DMIC] = {
4890 .type = ALC_FIXUP_FUNC,
4891 .v.func = alc269_fixup_stereo_dmic,
4892 },
Takashi Iwai24519912011-08-16 15:08:49 +02004893 [ALC269_FIXUP_QUANTA_MUTE] = {
4894 .type = ALC_FIXUP_FUNC,
4895 .v.func = alc269_fixup_quanta_mute,
4896 },
4897 [ALC269_FIXUP_LIFEBOOK] = {
4898 .type = ALC_FIXUP_PINS,
4899 .v.pins = (const struct alc_pincfg[]) {
4900 { 0x1a, 0x2101103f }, /* dock line-out */
4901 { 0x1b, 0x23a11040 }, /* dock mic-in */
4902 { }
4903 },
4904 .chained = true,
4905 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4906 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02004907 [ALC269_FIXUP_AMIC] = {
4908 .type = ALC_FIXUP_PINS,
4909 .v.pins = (const struct alc_pincfg[]) {
4910 { 0x14, 0x99130110 }, /* speaker */
4911 { 0x15, 0x0121401f }, /* HP out */
4912 { 0x18, 0x01a19c20 }, /* mic */
4913 { 0x19, 0x99a3092f }, /* int-mic */
4914 { }
4915 },
4916 },
4917 [ALC269_FIXUP_DMIC] = {
4918 .type = ALC_FIXUP_PINS,
4919 .v.pins = (const struct alc_pincfg[]) {
4920 { 0x12, 0x99a3092f }, /* int-mic */
4921 { 0x14, 0x99130110 }, /* speaker */
4922 { 0x15, 0x0121401f }, /* HP out */
4923 { 0x18, 0x01a19c20 }, /* mic */
4924 { }
4925 },
4926 },
4927 [ALC269VB_FIXUP_AMIC] = {
4928 .type = ALC_FIXUP_PINS,
4929 .v.pins = (const struct alc_pincfg[]) {
4930 { 0x14, 0x99130110 }, /* speaker */
4931 { 0x18, 0x01a19c20 }, /* mic */
4932 { 0x19, 0x99a3092f }, /* int-mic */
4933 { 0x21, 0x0121401f }, /* HP out */
4934 { }
4935 },
4936 },
4937 [ALC269_FIXUP_DMIC] = {
4938 .type = ALC_FIXUP_PINS,
4939 .v.pins = (const struct alc_pincfg[]) {
4940 { 0x12, 0x99a3092f }, /* int-mic */
4941 { 0x14, 0x99130110 }, /* speaker */
4942 { 0x18, 0x01a19c20 }, /* mic */
4943 { 0x21, 0x0121401f }, /* HP out */
4944 { }
4945 },
4946 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004947};
4948
4949static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02004950 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004951 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4952 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4953 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4954 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4955 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004956 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4957 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4958 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4959 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4960 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4961 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02004962 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004963 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4964 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4965 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4966 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4967 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02004968 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02004969 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004970 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02004971
4972#if 1
4973 /* Below is a quirk table taken from the old code.
4974 * Basically the device should work as is without the fixup table.
4975 * If BIOS doesn't give a proper info, enable the corresponding
4976 * fixup entry.
4977 */
4978 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4979 ALC269_FIXUP_AMIC),
4980 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
4981 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
4982 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
4983 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
4984 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
4985 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
4986 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
4987 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
4988 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
4989 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
4990 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
4991 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
4992 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
4993 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
4994 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
4995 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
4996 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
4997 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
4998 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
4999 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5000 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5001 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5002 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5003 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5004 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5005 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5006 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5007 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5008 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5009 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5010 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5011 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5012 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5013 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5014 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5015 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5016 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5017 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5018 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5019 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5020#endif
5021 {}
5022};
5023
5024static const struct alc_model_fixup alc269_fixup_models[] = {
5025 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5026 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005027 {}
5028};
5029
5030
5031static int alc269_fill_coef(struct hda_codec *codec)
5032{
5033 int val;
5034
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005035 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005036 alc_write_coef_idx(codec, 0xf, 0x960b);
5037 alc_write_coef_idx(codec, 0xe, 0x8817);
5038 }
5039
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005040 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005041 alc_write_coef_idx(codec, 0xf, 0x960b);
5042 alc_write_coef_idx(codec, 0xe, 0x8814);
5043 }
5044
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005045 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005046 val = alc_read_coef_idx(codec, 0x04);
5047 /* Power up output pin */
5048 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5049 }
5050
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005051 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005052 val = alc_read_coef_idx(codec, 0xd);
5053 if ((val & 0x0c00) >> 10 != 0x1) {
5054 /* Capless ramp up clock control */
5055 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5056 }
5057 val = alc_read_coef_idx(codec, 0x17);
5058 if ((val & 0x01c0) >> 6 != 0x4) {
5059 /* Class D power on reset */
5060 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5061 }
5062 }
5063
5064 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5065 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5066
5067 val = alc_read_coef_idx(codec, 0x4); /* HP */
5068 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5069
5070 return 0;
5071}
5072
5073/*
5074 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005075static int patch_alc269(struct hda_codec *codec)
5076{
5077 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005078 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005079
5080 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5081 if (spec == NULL)
5082 return -ENOMEM;
5083
5084 codec->spec = spec;
5085
5086 spec->mixer_nid = 0x0b;
5087
5088 alc_auto_parse_customize_define(codec);
5089
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005090 err = alc_codec_rename_from_preset(codec);
5091 if (err < 0)
5092 goto error;
5093
Takashi Iwai1d045db2011-07-07 18:23:21 +02005094 if (codec->vendor_id == 0x10ec0269) {
5095 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005096 switch (alc_get_coef0(codec) & 0x00f0) {
5097 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005098 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005099 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005100 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005101 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005102 break;
5103 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005104 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5105 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005106 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005107 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005108 break;
5109 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005110 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005111 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005112 if (err < 0)
5113 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005114 alc269_fill_coef(codec);
5115 }
5116
Takashi Iwaia4297b52011-08-23 18:40:12 +02005117 alc_pick_fixup(codec, alc269_fixup_models,
5118 alc269_fixup_tbl, alc269_fixups);
5119 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005120
Takashi Iwaia4297b52011-08-23 18:40:12 +02005121 /* automatic parse from the BIOS config */
5122 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005123 if (err < 0)
5124 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005125
Takashi Iwai60a6a842011-07-27 14:01:24 +02005126 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005127 alc_auto_fill_adc_caps(codec);
5128 alc_rebuild_imux_for_auto_mic(codec);
5129 alc_remove_invalid_adc_nids(codec);
5130 }
5131
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005132 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005133 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005134
5135 if (!spec->no_analog && has_cdefine_beep(codec)) {
5136 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005137 if (err < 0)
5138 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005139 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005140 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005141
5142 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5143
5144 spec->vmaster_nid = 0x02;
5145
5146 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005147#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005148 codec->patch_ops.resume = alc269_resume;
5149#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005150 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005151 spec->shutup = alc269_shutup;
5152
5153 alc_init_jacks(codec);
5154#ifdef CONFIG_SND_HDA_POWER_SAVE
5155 if (!spec->loopback.amplist)
5156 spec->loopback.amplist = alc269_loopbacks;
5157 if (alc269_mic2_for_mute_led(codec))
5158 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5159#endif
5160
5161 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005162
5163 error:
5164 alc_free(codec);
5165 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005166}
5167
5168/*
5169 * ALC861
5170 */
5171
Takashi Iwai1d045db2011-07-07 18:23:21 +02005172static int alc861_parse_auto_config(struct hda_codec *codec)
5173{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005174 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005175 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5176 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005177}
5178
Takashi Iwai1d045db2011-07-07 18:23:21 +02005179#ifdef CONFIG_SND_HDA_POWER_SAVE
5180static const struct hda_amp_list alc861_loopbacks[] = {
5181 { 0x15, HDA_INPUT, 0 },
5182 { 0x15, HDA_INPUT, 1 },
5183 { 0x15, HDA_INPUT, 2 },
5184 { 0x15, HDA_INPUT, 3 },
5185 { } /* end */
5186};
5187#endif
5188
5189
5190/* Pin config fixes */
5191enum {
5192 PINFIX_FSC_AMILO_PI1505,
5193};
5194
5195static const struct alc_fixup alc861_fixups[] = {
5196 [PINFIX_FSC_AMILO_PI1505] = {
5197 .type = ALC_FIXUP_PINS,
5198 .v.pins = (const struct alc_pincfg[]) {
5199 { 0x0b, 0x0221101f }, /* HP */
5200 { 0x0f, 0x90170310 }, /* speaker */
5201 { }
5202 }
5203 },
5204};
5205
5206static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5207 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5208 {}
5209};
5210
5211/*
5212 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005213static int patch_alc861(struct hda_codec *codec)
5214{
5215 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005216 int err;
5217
5218 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5219 if (spec == NULL)
5220 return -ENOMEM;
5221
5222 codec->spec = spec;
5223
5224 spec->mixer_nid = 0x15;
5225
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005226 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5227 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005228
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005229 /* automatic parse from the BIOS config */
5230 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005231 if (err < 0)
5232 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005233
Takashi Iwai60a6a842011-07-27 14:01:24 +02005234 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005235 alc_auto_fill_adc_caps(codec);
5236 alc_rebuild_imux_for_auto_mic(codec);
5237 alc_remove_invalid_adc_nids(codec);
5238 }
5239
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005240 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005241 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005242
5243 if (!spec->no_analog) {
5244 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005245 if (err < 0)
5246 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005247 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5248 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005249
5250 spec->vmaster_nid = 0x03;
5251
5252 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5253
5254 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005255 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005256#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005257 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005258 if (!spec->loopback.amplist)
5259 spec->loopback.amplist = alc861_loopbacks;
5260#endif
5261
5262 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005263
5264 error:
5265 alc_free(codec);
5266 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005267}
5268
5269/*
5270 * ALC861-VD support
5271 *
5272 * Based on ALC882
5273 *
5274 * In addition, an independent DAC
5275 */
5276#ifdef CONFIG_SND_HDA_POWER_SAVE
5277#define alc861vd_loopbacks alc880_loopbacks
5278#endif
5279
Takashi Iwai1d045db2011-07-07 18:23:21 +02005280static int alc861vd_parse_auto_config(struct hda_codec *codec)
5281{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005282 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005283 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5284 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005285}
5286
Takashi Iwai1d045db2011-07-07 18:23:21 +02005287enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005288 ALC660VD_FIX_ASUS_GPIO1,
5289 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005290};
5291
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005292/* exclude VREF80 */
5293static void alc861vd_fixup_dallas(struct hda_codec *codec,
5294 const struct alc_fixup *fix, int action)
5295{
5296 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5297 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5298 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5299 }
5300}
5301
Takashi Iwai1d045db2011-07-07 18:23:21 +02005302static const struct alc_fixup alc861vd_fixups[] = {
5303 [ALC660VD_FIX_ASUS_GPIO1] = {
5304 .type = ALC_FIXUP_VERBS,
5305 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005306 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005307 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5308 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5309 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5310 { }
5311 }
5312 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005313 [ALC861VD_FIX_DALLAS] = {
5314 .type = ALC_FIXUP_FUNC,
5315 .v.func = alc861vd_fixup_dallas,
5316 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005317};
5318
5319static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005320 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005321 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005322 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005323 {}
5324};
5325
5326static const struct hda_verb alc660vd_eapd_verbs[] = {
5327 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5328 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5329 { }
5330};
5331
5332/*
5333 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005334static int patch_alc861vd(struct hda_codec *codec)
5335{
5336 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005337 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005338
5339 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5340 if (spec == NULL)
5341 return -ENOMEM;
5342
5343 codec->spec = spec;
5344
5345 spec->mixer_nid = 0x0b;
5346
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005347 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5348 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005349
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005350 /* automatic parse from the BIOS config */
5351 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005352 if (err < 0)
5353 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005354
Takashi Iwai1d045db2011-07-07 18:23:21 +02005355 if (codec->vendor_id == 0x10ec0660) {
5356 /* always turn on EAPD */
5357 add_verb(spec, alc660vd_eapd_verbs);
5358 }
5359
Takashi Iwai60a6a842011-07-27 14:01:24 +02005360 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005361 alc_auto_fill_adc_caps(codec);
5362 alc_rebuild_imux_for_auto_mic(codec);
5363 alc_remove_invalid_adc_nids(codec);
5364 }
5365
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005366 if (!spec->no_analog && !spec->cap_mixer)
5367 set_capture_mixer(codec);
5368
5369 if (!spec->no_analog) {
5370 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005371 if (err < 0)
5372 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005373 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5374 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005375
5376 spec->vmaster_nid = 0x02;
5377
5378 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5379
5380 codec->patch_ops = alc_patch_ops;
5381
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005382 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005383 spec->shutup = alc_eapd_shutup;
5384#ifdef CONFIG_SND_HDA_POWER_SAVE
5385 if (!spec->loopback.amplist)
5386 spec->loopback.amplist = alc861vd_loopbacks;
5387#endif
5388
5389 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005390
5391 error:
5392 alc_free(codec);
5393 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005394}
5395
5396/*
5397 * ALC662 support
5398 *
5399 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5400 * configuration. Each pin widget can choose any input DACs and a mixer.
5401 * Each ADC is connected from a mixer of all inputs. This makes possible
5402 * 6-channel independent captures.
5403 *
5404 * In addition, an independent DAC for the multi-playback (not used in this
5405 * driver yet).
5406 */
5407#ifdef CONFIG_SND_HDA_POWER_SAVE
5408#define alc662_loopbacks alc880_loopbacks
5409#endif
5410
5411/*
5412 * BIOS auto configuration
5413 */
5414
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005415static int alc662_parse_auto_config(struct hda_codec *codec)
5416{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005417 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005418 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5419 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5420 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005421
Kailang Yang6227cdc2010-02-25 08:36:52 +01005422 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5423 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005424 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005425 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005426 ssids = alc662_ssids;
5427 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005428}
5429
Todd Broch6be79482010-12-07 16:51:05 -08005430static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005431 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005432{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005433 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005434 return;
Todd Broch6be79482010-12-07 16:51:05 -08005435 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5436 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5437 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5438 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5439 (0 << AC_AMPCAP_MUTE_SHIFT)))
5440 printk(KERN_WARNING
5441 "hda_codec: failed to override amp caps for NID 0x2\n");
5442}
5443
David Henningsson6cb3b702010-09-09 08:51:44 +02005444enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005445 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005446 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005447 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005448 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005449 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005450 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005451 ALC662_FIXUP_ASUS_MODE1,
5452 ALC662_FIXUP_ASUS_MODE2,
5453 ALC662_FIXUP_ASUS_MODE3,
5454 ALC662_FIXUP_ASUS_MODE4,
5455 ALC662_FIXUP_ASUS_MODE5,
5456 ALC662_FIXUP_ASUS_MODE6,
5457 ALC662_FIXUP_ASUS_MODE7,
5458 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005459};
5460
5461static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005462 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005463 .type = ALC_FIXUP_PINS,
5464 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005465 { 0x15, 0x99130112 }, /* subwoofer */
5466 { }
5467 }
5468 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005469 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005470 .type = ALC_FIXUP_PINS,
5471 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005472 { 0x17, 0x99130112 }, /* subwoofer */
5473 { }
5474 }
5475 },
Todd Broch6be79482010-12-07 16:51:05 -08005476 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005477 .type = ALC_FIXUP_FUNC,
5478 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005479 },
5480 [ALC662_FIXUP_CZC_P10T] = {
5481 .type = ALC_FIXUP_VERBS,
5482 .v.verbs = (const struct hda_verb[]) {
5483 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5484 {}
5485 }
5486 },
David Henningsson94024cd2011-04-29 14:10:55 +02005487 [ALC662_FIXUP_SKU_IGNORE] = {
5488 .type = ALC_FIXUP_SKU,
5489 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005490 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005491 [ALC662_FIXUP_HP_RP5800] = {
5492 .type = ALC_FIXUP_PINS,
5493 .v.pins = (const struct alc_pincfg[]) {
5494 { 0x14, 0x0221201f }, /* HP out */
5495 { }
5496 },
5497 .chained = true,
5498 .chain_id = ALC662_FIXUP_SKU_IGNORE
5499 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005500 [ALC662_FIXUP_ASUS_MODE1] = {
5501 .type = ALC_FIXUP_PINS,
5502 .v.pins = (const struct alc_pincfg[]) {
5503 { 0x14, 0x99130110 }, /* speaker */
5504 { 0x18, 0x01a19c20 }, /* mic */
5505 { 0x19, 0x99a3092f }, /* int-mic */
5506 { 0x21, 0x0121401f }, /* HP out */
5507 { }
5508 },
5509 .chained = true,
5510 .chain_id = ALC662_FIXUP_SKU_IGNORE
5511 },
5512 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005513 .type = ALC_FIXUP_PINS,
5514 .v.pins = (const struct alc_pincfg[]) {
5515 { 0x14, 0x99130110 }, /* speaker */
5516 { 0x18, 0x01a19820 }, /* mic */
5517 { 0x19, 0x99a3092f }, /* int-mic */
5518 { 0x1b, 0x0121401f }, /* HP out */
5519 { }
5520 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005521 .chained = true,
5522 .chain_id = ALC662_FIXUP_SKU_IGNORE
5523 },
5524 [ALC662_FIXUP_ASUS_MODE3] = {
5525 .type = ALC_FIXUP_PINS,
5526 .v.pins = (const struct alc_pincfg[]) {
5527 { 0x14, 0x99130110 }, /* speaker */
5528 { 0x15, 0x0121441f }, /* HP */
5529 { 0x18, 0x01a19840 }, /* mic */
5530 { 0x19, 0x99a3094f }, /* int-mic */
5531 { 0x21, 0x01211420 }, /* HP2 */
5532 { }
5533 },
5534 .chained = true,
5535 .chain_id = ALC662_FIXUP_SKU_IGNORE
5536 },
5537 [ALC662_FIXUP_ASUS_MODE4] = {
5538 .type = ALC_FIXUP_PINS,
5539 .v.pins = (const struct alc_pincfg[]) {
5540 { 0x14, 0x99130110 }, /* speaker */
5541 { 0x16, 0x99130111 }, /* speaker */
5542 { 0x18, 0x01a19840 }, /* mic */
5543 { 0x19, 0x99a3094f }, /* int-mic */
5544 { 0x21, 0x0121441f }, /* HP */
5545 { }
5546 },
5547 .chained = true,
5548 .chain_id = ALC662_FIXUP_SKU_IGNORE
5549 },
5550 [ALC662_FIXUP_ASUS_MODE5] = {
5551 .type = ALC_FIXUP_PINS,
5552 .v.pins = (const struct alc_pincfg[]) {
5553 { 0x14, 0x99130110 }, /* speaker */
5554 { 0x15, 0x0121441f }, /* HP */
5555 { 0x16, 0x99130111 }, /* speaker */
5556 { 0x18, 0x01a19840 }, /* mic */
5557 { 0x19, 0x99a3094f }, /* int-mic */
5558 { }
5559 },
5560 .chained = true,
5561 .chain_id = ALC662_FIXUP_SKU_IGNORE
5562 },
5563 [ALC662_FIXUP_ASUS_MODE6] = {
5564 .type = ALC_FIXUP_PINS,
5565 .v.pins = (const struct alc_pincfg[]) {
5566 { 0x14, 0x99130110 }, /* speaker */
5567 { 0x15, 0x01211420 }, /* HP2 */
5568 { 0x18, 0x01a19840 }, /* mic */
5569 { 0x19, 0x99a3094f }, /* int-mic */
5570 { 0x1b, 0x0121441f }, /* HP */
5571 { }
5572 },
5573 .chained = true,
5574 .chain_id = ALC662_FIXUP_SKU_IGNORE
5575 },
5576 [ALC662_FIXUP_ASUS_MODE7] = {
5577 .type = ALC_FIXUP_PINS,
5578 .v.pins = (const struct alc_pincfg[]) {
5579 { 0x14, 0x99130110 }, /* speaker */
5580 { 0x17, 0x99130111 }, /* speaker */
5581 { 0x18, 0x01a19840 }, /* mic */
5582 { 0x19, 0x99a3094f }, /* int-mic */
5583 { 0x1b, 0x01214020 }, /* HP */
5584 { 0x21, 0x0121401f }, /* HP */
5585 { }
5586 },
5587 .chained = true,
5588 .chain_id = ALC662_FIXUP_SKU_IGNORE
5589 },
5590 [ALC662_FIXUP_ASUS_MODE8] = {
5591 .type = ALC_FIXUP_PINS,
5592 .v.pins = (const struct alc_pincfg[]) {
5593 { 0x14, 0x99130110 }, /* speaker */
5594 { 0x12, 0x99a30970 }, /* int-mic */
5595 { 0x15, 0x01214020 }, /* HP */
5596 { 0x17, 0x99130111 }, /* speaker */
5597 { 0x18, 0x01a19840 }, /* mic */
5598 { 0x21, 0x0121401f }, /* HP */
5599 { }
5600 },
5601 .chained = true,
5602 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005603 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005604};
5605
Takashi Iwaia9111322011-05-02 11:30:18 +02005606static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02005607 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01005608 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02005609 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04005610 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005611 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005612 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05005613 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06005614 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02005615 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01005616 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005617
5618#if 0
5619 /* Below is a quirk table taken from the old code.
5620 * Basically the device should work as is without the fixup table.
5621 * If BIOS doesn't give a proper info, enable the corresponding
5622 * fixup entry.
5623 */
5624 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5625 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5626 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5627 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5628 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5629 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5630 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5631 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5632 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5633 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5634 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5635 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5636 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5637 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5638 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5639 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5640 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5641 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5642 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5643 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5644 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5645 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5646 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5647 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5648 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5649 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5650 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5651 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5652 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5653 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5654 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5655 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5656 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5657 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5658 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5659 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5660 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5661 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5662 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5663 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5664 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5665 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5666 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5667 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5668 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5669 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5670 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5671 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5672 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5673 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5674#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02005675 {}
5676};
5677
Todd Broch6be79482010-12-07 16:51:05 -08005678static const struct alc_model_fixup alc662_fixup_models[] = {
5679 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02005680 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5681 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5682 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5683 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5684 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5685 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5686 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5687 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08005688 {}
5689};
David Henningsson6cb3b702010-09-09 08:51:44 +02005690
5691
Takashi Iwai1d045db2011-07-07 18:23:21 +02005692/*
5693 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005694static int patch_alc662(struct hda_codec *codec)
5695{
5696 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005697 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005698
5699 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5700 if (!spec)
5701 return -ENOMEM;
5702
5703 codec->spec = spec;
5704
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005705 spec->mixer_nid = 0x0b;
5706
Takashi Iwai53c334a2011-08-23 18:27:14 +02005707 /* handle multiple HPs as is */
5708 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5709
Kailang Yangda00c242010-03-19 11:23:45 +01005710 alc_auto_parse_customize_define(codec);
5711
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02005712 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5713
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005714 err = alc_codec_rename_from_preset(codec);
5715 if (err < 0)
5716 goto error;
5717
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005718 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005719 codec->bus->pci->subsystem_vendor == 0x1025 &&
5720 spec->cdefine.platform_type == 1) {
5721 if (alc_codec_rename(codec, "ALC272X") < 0)
5722 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005723 }
Kailang Yang274693f2009-12-03 10:07:50 +01005724
Takashi Iwaib9c51062011-08-24 18:08:07 +02005725 alc_pick_fixup(codec, alc662_fixup_models,
5726 alc662_fixup_tbl, alc662_fixups);
5727 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5728 /* automatic parse from the BIOS config */
5729 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005730 if (err < 0)
5731 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005732
Takashi Iwai60a6a842011-07-27 14:01:24 +02005733 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005734 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02005735 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005736 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02005737 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005738
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005739 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02005740 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01005741
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005742 if (!spec->no_analog && has_cdefine_beep(codec)) {
5743 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005744 if (err < 0)
5745 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01005746 switch (codec->vendor_id) {
5747 case 0x10ec0662:
5748 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5749 break;
5750 case 0x10ec0272:
5751 case 0x10ec0663:
5752 case 0x10ec0665:
5753 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5754 break;
5755 case 0x10ec0273:
5756 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5757 break;
5758 }
Kailang Yangcec27c82010-02-04 14:18:18 +01005759 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01005760 spec->vmaster_nid = 0x02;
5761
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005762 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5763
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005764 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02005765 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c7161532011-04-07 10:37:16 +02005766 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02005767
Kailang Yangbf1b0222010-10-21 08:49:56 +02005768 alc_init_jacks(codec);
5769
Takashi Iwaicb53c622007-08-10 17:21:45 +02005770#ifdef CONFIG_SND_HDA_POWER_SAVE
5771 if (!spec->loopback.amplist)
5772 spec->loopback.amplist = alc662_loopbacks;
5773#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005774
5775 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005776
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005777 error:
5778 alc_free(codec);
5779 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02005780}
5781
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005782/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005783 * ALC680 support
5784 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005785
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005786static int alc680_parse_auto_config(struct hda_codec *codec)
5787{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005788 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005789}
5790
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005791/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005792 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005793static int patch_alc680(struct hda_codec *codec)
5794{
5795 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005796 int err;
5797
5798 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5799 if (spec == NULL)
5800 return -ENOMEM;
5801
5802 codec->spec = spec;
5803
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005804 /* ALC680 has no aa-loopback mixer */
5805
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005806 /* automatic parse from the BIOS config */
5807 err = alc680_parse_auto_config(codec);
5808 if (err < 0) {
5809 alc_free(codec);
5810 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005811 }
5812
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005813 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005814 set_capture_mixer(codec);
5815
5816 spec->vmaster_nid = 0x02;
5817
5818 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005819 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005820
5821 return 0;
5822}
5823
5824/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825 * patch entries
5826 */
Takashi Iwaia9111322011-05-02 11:30:18 +02005827static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02005828 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005830 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005831 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02005832 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005833 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005834 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02005835 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005836 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02005837 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005838 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005839 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005840 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5841 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5842 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005843 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005844 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005845 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5846 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02005847 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
5848 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02005849 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01005850 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01005851 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005852 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005853 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02005855 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02005856 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005857 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02005858 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005859 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005860 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005861 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02005862 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005863 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005864 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02005865 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01005866 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005867 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868 {} /* terminator */
5869};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005870
5871MODULE_ALIAS("snd-hda-codec-id:10ec*");
5872
5873MODULE_LICENSE("GPL");
5874MODULE_DESCRIPTION("Realtek HD-audio codec");
5875
5876static struct hda_codec_preset_list realtek_list = {
5877 .preset = snd_hda_preset_realtek,
5878 .owner = THIS_MODULE,
5879};
5880
5881static int __init patch_realtek_init(void)
5882{
5883 return snd_hda_add_codec_preset(&realtek_list);
5884}
5885
5886static void __exit patch_realtek_exit(void)
5887{
5888 snd_hda_delete_codec_preset(&realtek_list);
5889}
5890
5891module_init(patch_realtek_init)
5892module_exit(patch_realtek_exit)