blob: 214d4f91d6af5fd6a829b2eb1e808966de9e7fcf [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
Takashi Iwai61071592011-11-23 07:52:15 +0100280static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
281{
282 return spec->capsrc_nids ?
283 spec->capsrc_nids[idx] : spec->adc_nids[idx];
284}
285
Takashi Iwai21268962011-07-07 15:01:13 +0200286/* select the given imux item; either unmute exclusively or select the route */
287static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
288 unsigned int idx, bool force)
289{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100291 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100292 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100293 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200294 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Takashi Iwaicd896c32008-11-18 12:36:33 +0100296 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
297 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100298 if (!imux->num_items && mux_idx > 0)
299 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100300 if (!imux->num_items)
301 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100302
Takashi Iwai21268962011-07-07 15:01:13 +0200303 if (idx >= imux->num_items)
304 idx = imux->num_items - 1;
305 if (spec->cur_mux[adc_idx] == idx && !force)
306 return 0;
307 spec->cur_mux[adc_idx] = idx;
308
309 if (spec->dyn_adc_switch) {
310 alc_dyn_adc_pcm_resetup(codec, idx);
311 adc_idx = spec->dyn_adc_idx[idx];
312 }
313
Takashi Iwai61071592011-11-23 07:52:15 +0100314 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200315
316 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100317 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
318 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200319 return 1;
320
Takashi Iwaia22d5432009-07-27 12:54:26 +0200321 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200322 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100323 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100324 int active = imux->items[idx].index;
325 for (i = 0; i < num_conns; i++) {
326 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
327 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100328 HDA_AMP_MUTE, v);
329 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100330 } else {
331 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200332 snd_hda_codec_write_cache(codec, nid, 0,
333 AC_VERB_SET_CONNECT_SEL,
334 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100335 }
Takashi Iwai21268962011-07-07 15:01:13 +0200336 return 1;
337}
338
339static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
340 struct snd_ctl_elem_value *ucontrol)
341{
342 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
343 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
344 return alc_mux_select(codec, adc_idx,
345 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100346}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100349 * set up the input pin config (depending on the given auto-pin type)
350 */
351static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
352 int auto_pin_type)
353{
354 unsigned int val = PIN_IN;
355
Takashi Iwai86e29592010-09-09 14:50:17 +0200356 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100357 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200358 unsigned int oldval;
359 oldval = snd_hda_codec_read(codec, nid, 0,
360 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100361 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100362 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200363 /* if the default pin setup is vref50, we give it priority */
364 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100365 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200366 else if (pincap & AC_PINCAP_VREF_50)
367 val = PIN_VREF50;
368 else if (pincap & AC_PINCAP_VREF_100)
369 val = PIN_VREF100;
370 else if (pincap & AC_PINCAP_VREF_GRD)
371 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100372 }
373 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
374}
375
376/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200377 * Append the given mixer and verb elements for the later use
378 * The mixer array is referred in build_controls(), and init_verbs are
379 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100380 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200381static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100382{
383 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
384 return;
385 spec->mixers[spec->num_mixers++] = mix;
386}
387
388static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
389{
390 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
391 return;
392 spec->init_verbs[spec->num_init_verbs++] = verb;
393}
394
395/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200396 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100397 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200398/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200399static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200400 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
401 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
402 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
403 { }
404};
405
Takashi Iwaia9111322011-05-02 11:30:18 +0200406static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200407 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
408 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
409 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
410 { }
411};
412
Takashi Iwaia9111322011-05-02 11:30:18 +0200413static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200414 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
415 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
416 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
417 { }
418};
419
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200420/*
421 * Fix hardware PLL issue
422 * On some codecs, the analog PLL gating control must be off while
423 * the default value is 1.
424 */
425static void alc_fix_pll(struct hda_codec *codec)
426{
427 struct alc_spec *spec = codec->spec;
428 unsigned int val;
429
430 if (!spec->pll_nid)
431 return;
432 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
433 spec->pll_coef_idx);
434 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
435 AC_VERB_GET_PROC_COEF, 0);
436 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
437 spec->pll_coef_idx);
438 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
439 val & ~(1 << spec->pll_coef_bit));
440}
441
442static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
443 unsigned int coef_idx, unsigned int coef_bit)
444{
445 struct alc_spec *spec = codec->spec;
446 spec->pll_nid = nid;
447 spec->pll_coef_idx = coef_idx;
448 spec->pll_coef_bit = coef_bit;
449 alc_fix_pll(codec);
450}
451
Takashi Iwai1d045db2011-07-07 18:23:21 +0200452/*
453 * Jack-reporting via input-jack layer
454 */
455
456/* initialization of jacks; currently checks only a few known pins */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200457static int alc_init_jacks(struct hda_codec *codec)
458{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100459#ifdef CONFIG_SND_HDA_INPUT_JACK
Kailang Yang9ad0e492010-09-14 23:22:00 +0200460 struct alc_spec *spec = codec->spec;
461 int err;
462 unsigned int hp_nid = spec->autocfg.hp_pins[0];
Takashi Iwai21268962011-07-07 15:01:13 +0200463 unsigned int mic_nid = spec->ext_mic_pin;
464 unsigned int dock_nid = spec->dock_mic_pin;
Kailang Yang9ad0e492010-09-14 23:22:00 +0200465
Takashi Iwai265a0242010-09-21 11:26:21 +0200466 if (hp_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100467 err = snd_hda_input_jack_add(codec, hp_nid,
468 SND_JACK_HEADPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200469 if (err < 0)
470 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100471 snd_hda_input_jack_report(codec, hp_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200472 }
Kailang Yang9ad0e492010-09-14 23:22:00 +0200473
Takashi Iwai265a0242010-09-21 11:26:21 +0200474 if (mic_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100475 err = snd_hda_input_jack_add(codec, mic_nid,
476 SND_JACK_MICROPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200477 if (err < 0)
478 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100479 snd_hda_input_jack_report(codec, mic_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200480 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200481 if (dock_nid) {
482 err = snd_hda_input_jack_add(codec, dock_nid,
483 SND_JACK_MICROPHONE, NULL);
484 if (err < 0)
485 return err;
486 snd_hda_input_jack_report(codec, dock_nid);
487 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100488#endif /* CONFIG_SND_HDA_INPUT_JACK */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200489 return 0;
490}
Kailang Yang9ad0e492010-09-14 23:22:00 +0200491
Takashi Iwai1d045db2011-07-07 18:23:21 +0200492/*
493 * Jack detections for HP auto-mute and mic-switch
494 */
495
496/* check each pin in the given array; returns true if any of them is plugged */
497static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200498{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200499 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200500
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 for (i = 0; i < num_pins; i++) {
502 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200503 if (!nid)
504 break;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100505 snd_hda_input_jack_report(codec, nid);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200506 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200507 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200508 return present;
509}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200510
Takashi Iwai1d045db2011-07-07 18:23:21 +0200511/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200512static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200513 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200514{
515 struct alc_spec *spec = codec->spec;
516 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200517 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200518 int i;
519
520 for (i = 0; i < num_pins; i++) {
521 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200522 if (!nid)
523 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200524 switch (spec->automute_mode) {
525 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200526 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200527 AC_VERB_SET_PIN_WIDGET_CONTROL,
528 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200529 break;
530 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200531 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200533 break;
534 case ALC_AUTOMUTE_MIXER:
535 nid = spec->automute_mixer_nid[i];
536 if (!nid)
537 break;
538 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200539 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200540 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200541 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200542 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200543 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200544 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200545}
546
David Henningsson42cf0d02011-09-20 12:04:56 +0200547/* Toggle outputs muting */
548static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200549{
550 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200551 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200552
Takashi Iwaic0a20262011-06-10 15:28:15 +0200553 /* Control HP pins/amps depending on master_mute state;
554 * in general, HP pins/amps control should be enabled in all cases,
555 * but currently set only for master_mute, just to be safe
556 */
557 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
558 spec->autocfg.hp_pins, spec->master_mute, true);
559
David Henningsson42cf0d02011-09-20 12:04:56 +0200560 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200561 on = 0;
562 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200563 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200564 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200565 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200567
568 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200569 /* if LO is a copy of either HP or Speaker, don't need to handle it */
570 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
571 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200572 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200573 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200574 on = 0;
575 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200576 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200577 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200578 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200579 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200580}
581
David Henningsson42cf0d02011-09-20 12:04:56 +0200582static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200583{
584 struct alc_spec *spec = codec->spec;
585 if (spec->automute_hook)
586 spec->automute_hook(codec);
587 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200588 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200589}
590
Takashi Iwai1d045db2011-07-07 18:23:21 +0200591/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200592static void alc_hp_automute(struct hda_codec *codec)
593{
594 struct alc_spec *spec = codec->spec;
595
David Henningsson42cf0d02011-09-20 12:04:56 +0200596 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200597 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
598 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200599 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200600 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200601 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602}
603
Takashi Iwai1d045db2011-07-07 18:23:21 +0200604/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200605static void alc_line_automute(struct hda_codec *codec)
606{
607 struct alc_spec *spec = codec->spec;
608
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200609 /* check LO jack only when it's different from HP */
610 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
611 return;
612
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200613 spec->line_jack_present =
614 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
615 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200616 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200617 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200618 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200619}
620
Takashi Iwai8d087c72011-06-28 12:45:47 +0200621#define get_connection_index(codec, mux, nid) \
622 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200623
Takashi Iwai1d045db2011-07-07 18:23:21 +0200624/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200625static void alc_mic_automute(struct hda_codec *codec)
626{
627 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200628 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200629
Takashi Iwai21268962011-07-07 15:01:13 +0200630 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200631 return;
632 if (snd_BUG_ON(!spec->adc_nids))
633 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200634 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200635 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200636
Takashi Iwai21268962011-07-07 15:01:13 +0200637 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
638 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
639 else if (spec->dock_mic_idx >= 0 &&
640 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
641 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
642 else
643 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Takashi Iwai6c819492009-08-10 18:47:44 +0200644
Takashi Iwai21268962011-07-07 15:01:13 +0200645 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
646 if (spec->dock_mic_idx >= 0)
647 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200648}
649
Kailang Yangc9b58002007-10-16 14:30:01 +0200650/* unsolicited event for HP jack sensing */
651static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
652{
653 if (codec->vendor_id == 0x10ec0880)
654 res >>= 28;
655 else
656 res >>= 26;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200657 switch (res) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200658 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200659 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200660 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200661 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200662 alc_line_automute(codec);
663 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200664 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200665 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200666 break;
667 }
Kailang Yang7fb0d782008-10-15 11:12:35 +0200668}
669
Takashi Iwai1d045db2011-07-07 18:23:21 +0200670/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200671static void alc_inithook(struct hda_codec *codec)
672{
Takashi Iwaid922b512011-04-28 12:18:53 +0200673 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200674 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200675 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200676}
677
Kailang Yangf9423e72008-05-27 12:32:25 +0200678/* additional initialization for ALC888 variants */
679static void alc888_coef_init(struct hda_codec *codec)
680{
681 unsigned int tmp;
682
683 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
684 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
685 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100686 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200687 /* alc888S-VC */
688 snd_hda_codec_read(codec, 0x20, 0,
689 AC_VERB_SET_PROC_COEF, 0x830);
690 else
691 /* alc888-VB */
692 snd_hda_codec_read(codec, 0x20, 0,
693 AC_VERB_SET_PROC_COEF, 0x3030);
694}
695
Takashi Iwai1d045db2011-07-07 18:23:21 +0200696/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200697static void alc889_coef_init(struct hda_codec *codec)
698{
699 unsigned int tmp;
700
701 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
702 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
703 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
704 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
705}
706
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100707/* turn on/off EAPD control (only if available) */
708static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
709{
710 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
711 return;
712 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
713 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
714 on ? 2 : 0);
715}
716
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200717/* turn on/off EAPD controls of the codec */
718static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
719{
720 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200721 static hda_nid_t pins[] = {
722 0x0f, 0x10, 0x14, 0x15, 0
723 };
724 hda_nid_t *p;
725 for (p = pins; *p; p++)
726 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200727}
728
Takashi Iwai1c7161532011-04-07 10:37:16 +0200729/* generic shutup callback;
730 * just turning off EPAD and a little pause for avoiding pop-noise
731 */
732static void alc_eapd_shutup(struct hda_codec *codec)
733{
734 alc_auto_setup_eapd(codec, false);
735 msleep(200);
736}
737
Takashi Iwai1d045db2011-07-07 18:23:21 +0200738/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200739static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200740{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200741 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200742
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200743 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200744 switch (type) {
745 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200746 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
747 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200748 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200749 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
750 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200751 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200752 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
753 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200754 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200755 switch (codec->vendor_id) {
756 case 0x10ec0260:
757 snd_hda_codec_write(codec, 0x1a, 0,
758 AC_VERB_SET_COEF_INDEX, 7);
759 tmp = snd_hda_codec_read(codec, 0x1a, 0,
760 AC_VERB_GET_PROC_COEF, 0);
761 snd_hda_codec_write(codec, 0x1a, 0,
762 AC_VERB_SET_COEF_INDEX, 7);
763 snd_hda_codec_write(codec, 0x1a, 0,
764 AC_VERB_SET_PROC_COEF,
765 tmp | 0x2010);
766 break;
767 case 0x10ec0262:
768 case 0x10ec0880:
769 case 0x10ec0882:
770 case 0x10ec0883:
771 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100772 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100773 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200774 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200775 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200776 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200778 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100779#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200780 case 0x10ec0267:
781 case 0x10ec0268:
782 snd_hda_codec_write(codec, 0x20, 0,
783 AC_VERB_SET_COEF_INDEX, 7);
784 tmp = snd_hda_codec_read(codec, 0x20, 0,
785 AC_VERB_GET_PROC_COEF, 0);
786 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200787 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200788 snd_hda_codec_write(codec, 0x20, 0,
789 AC_VERB_SET_PROC_COEF,
790 tmp | 0x3000);
791 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100792#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200793 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200794 break;
795 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200796}
Kailang Yangea1fb292008-08-26 12:58:38 +0200797
Takashi Iwai1d045db2011-07-07 18:23:21 +0200798/*
799 * Auto-Mute mode mixer enum support
800 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200801static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_info *uinfo)
803{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200804 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
805 struct alc_spec *spec = codec->spec;
806 static const char * const texts2[] = {
807 "Disabled", "Enabled"
808 };
809 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200810 "Disabled", "Speaker Only", "Line-Out+Speaker"
811 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200812 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200813
814 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
815 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200816 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200817 uinfo->value.enumerated.items = 3;
818 texts = texts3;
819 } else {
820 uinfo->value.enumerated.items = 2;
821 texts = texts2;
822 }
823 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
824 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200825 strcpy(uinfo->value.enumerated.name,
826 texts[uinfo->value.enumerated.item]);
827 return 0;
828}
829
830static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
831 struct snd_ctl_elem_value *ucontrol)
832{
833 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
834 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200835 unsigned int val = 0;
836 if (spec->automute_speaker)
837 val++;
838 if (spec->automute_lo)
839 val++;
840
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200841 ucontrol->value.enumerated.item[0] = val;
842 return 0;
843}
844
845static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
846 struct snd_ctl_elem_value *ucontrol)
847{
848 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
849 struct alc_spec *spec = codec->spec;
850
851 switch (ucontrol->value.enumerated.item[0]) {
852 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200853 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200854 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200855 spec->automute_speaker = 0;
856 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200857 break;
858 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200859 if (spec->automute_speaker_possible) {
860 if (!spec->automute_lo && spec->automute_speaker)
861 return 0;
862 spec->automute_speaker = 1;
863 spec->automute_lo = 0;
864 } else if (spec->automute_lo_possible) {
865 if (spec->automute_lo)
866 return 0;
867 spec->automute_lo = 1;
868 } else
869 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200870 break;
871 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200872 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200873 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200874 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200875 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200876 spec->automute_speaker = 1;
877 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200878 break;
879 default:
880 return -EINVAL;
881 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200882 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200883 return 1;
884}
885
Takashi Iwaia9111322011-05-02 11:30:18 +0200886static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200887 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
888 .name = "Auto-Mute Mode",
889 .info = alc_automute_mode_info,
890 .get = alc_automute_mode_get,
891 .put = alc_automute_mode_put,
892};
893
Takashi Iwai1d045db2011-07-07 18:23:21 +0200894static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
895{
896 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
897 return snd_array_new(&spec->kctls);
898}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899
900static int alc_add_automute_mode_enum(struct hda_codec *codec)
901{
902 struct alc_spec *spec = codec->spec;
903 struct snd_kcontrol_new *knew;
904
905 knew = alc_kcontrol_new(spec);
906 if (!knew)
907 return -ENOMEM;
908 *knew = alc_automute_mode_enum;
909 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
910 if (!knew->name)
911 return -ENOMEM;
912 return 0;
913}
914
Takashi Iwai1d045db2011-07-07 18:23:21 +0200915/*
916 * Check the availability of HP/line-out auto-mute;
917 * Set up appropriately if really supported
918 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200919static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200920{
921 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200922 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200923 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200924 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200925
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200926 if (cfg->hp_pins[0])
927 present++;
928 if (cfg->line_out_pins[0])
929 present++;
930 if (cfg->speaker_pins[0])
931 present++;
932 if (present < 2) /* need two different output types */
933 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200934
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200935 if (!cfg->speaker_pins[0] &&
936 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200937 memcpy(cfg->speaker_pins, cfg->line_out_pins,
938 sizeof(cfg->speaker_pins));
939 cfg->speaker_outs = cfg->line_outs;
940 }
941
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200942 if (!cfg->hp_pins[0] &&
943 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200944 memcpy(cfg->hp_pins, cfg->line_out_pins,
945 sizeof(cfg->hp_pins));
946 cfg->hp_outs = cfg->line_outs;
947 }
948
David Henningsson42cf0d02011-09-20 12:04:56 +0200949 spec->automute_mode = ALC_AUTOMUTE_PIN;
950
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200951 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200952 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200953 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200954 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200955 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200956 nid);
957 snd_hda_codec_write_cache(codec, nid, 0,
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200958 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +0200959 AC_USRSP_EN | ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200960 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200961 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200962
David Henningsson42cf0d02011-09-20 12:04:56 +0200963 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
964 if (cfg->speaker_outs)
965 for (i = 0; i < cfg->line_outs; i++) {
966 hda_nid_t nid = cfg->line_out_pins[i];
967 if (!is_jack_detectable(codec, nid))
968 continue;
969 snd_printdd("realtek: Enable Line-Out "
970 "auto-muting on NID 0x%x\n", nid);
971 snd_hda_codec_write_cache(codec, nid, 0,
972 AC_VERB_SET_UNSOLICITED_ENABLE,
973 AC_USRSP_EN | ALC_FRONT_EVENT);
974 spec->detect_lo = 1;
975 }
976 spec->automute_lo_possible = spec->detect_hp;
977 }
978
979 spec->automute_speaker_possible = cfg->speaker_outs &&
980 (spec->detect_hp || spec->detect_lo);
981
982 spec->automute_lo = spec->automute_lo_possible;
983 spec->automute_speaker = spec->automute_speaker_possible;
984
985 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200986 /* create a control for automute mode */
987 alc_add_automute_mode_enum(codec);
988 spec->unsol_event = alc_sku_unsol_event;
989 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200990}
991
Takashi Iwai1d045db2011-07-07 18:23:21 +0200992/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200993static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
994{
995 int i;
996 for (i = 0; i < nums; i++)
997 if (list[i] == nid)
998 return i;
999 return -1;
1000}
1001
Takashi Iwai1d045db2011-07-07 18:23:21 +02001002/* check whether dynamic ADC-switching is available */
1003static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1004{
1005 struct alc_spec *spec = codec->spec;
1006 struct hda_input_mux *imux = &spec->private_imux[0];
1007 int i, n, idx;
1008 hda_nid_t cap, pin;
1009
1010 if (imux != spec->input_mux) /* no dynamic imux? */
1011 return false;
1012
1013 for (n = 0; n < spec->num_adc_nids; n++) {
1014 cap = spec->private_capsrc_nids[n];
1015 for (i = 0; i < imux->num_items; i++) {
1016 pin = spec->imux_pins[i];
1017 if (!pin)
1018 return false;
1019 if (get_connection_index(codec, cap, pin) < 0)
1020 break;
1021 }
1022 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001023 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001024 }
1025
1026 for (i = 0; i < imux->num_items; i++) {
1027 pin = spec->imux_pins[i];
1028 for (n = 0; n < spec->num_adc_nids; n++) {
1029 cap = spec->private_capsrc_nids[n];
1030 idx = get_connection_index(codec, cap, pin);
1031 if (idx >= 0) {
1032 imux->items[i].index = idx;
1033 spec->dyn_adc_idx[i] = n;
1034 break;
1035 }
1036 }
1037 }
1038
1039 snd_printdd("realtek: enabling ADC switching\n");
1040 spec->dyn_adc_switch = 1;
1041 return true;
1042}
Takashi Iwai21268962011-07-07 15:01:13 +02001043
1044/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1045static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1046{
1047 struct alc_spec *spec = codec->spec;
1048 struct hda_input_mux *imux;
1049 static char * const texts[3] = {
1050 "Mic", "Internal Mic", "Dock Mic"
1051 };
1052 int i;
1053
1054 if (!spec->auto_mic)
1055 return false;
1056 imux = &spec->private_imux[0];
1057 if (spec->input_mux == imux)
1058 return true;
1059 spec->imux_pins[0] = spec->ext_mic_pin;
1060 spec->imux_pins[1] = spec->int_mic_pin;
1061 spec->imux_pins[2] = spec->dock_mic_pin;
1062 for (i = 0; i < 3; i++) {
1063 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001064 if (spec->imux_pins[i]) {
1065 hda_nid_t pin = spec->imux_pins[i];
1066 int c;
1067 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001068 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001069 int idx = get_connection_index(codec, cap, pin);
1070 if (idx >= 0) {
1071 imux->items[i].index = idx;
1072 break;
1073 }
1074 }
Takashi Iwai21268962011-07-07 15:01:13 +02001075 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001076 }
Takashi Iwai21268962011-07-07 15:01:13 +02001077 }
1078 spec->num_mux_defs = 1;
1079 spec->input_mux = imux;
1080 return true;
1081}
1082
1083/* check whether all auto-mic pins are valid; setup indices if OK */
1084static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1085{
1086 struct alc_spec *spec = codec->spec;
1087 const struct hda_input_mux *imux;
1088
1089 if (!spec->auto_mic)
1090 return false;
1091 if (spec->auto_mic_valid_imux)
1092 return true; /* already checked */
1093
1094 /* fill up imux indices */
1095 if (!alc_check_dyn_adc_switch(codec)) {
1096 spec->auto_mic = 0;
1097 return false;
1098 }
1099
1100 imux = spec->input_mux;
1101 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1102 spec->imux_pins, imux->num_items);
1103 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1104 spec->imux_pins, imux->num_items);
1105 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1106 spec->imux_pins, imux->num_items);
1107 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1108 spec->auto_mic = 0;
1109 return false; /* no corresponding imux */
1110 }
1111
1112 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1113 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001114 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001115 if (spec->dock_mic_pin)
1116 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1117 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001118 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001119
1120 spec->auto_mic_valid_imux = 1;
1121 spec->auto_mic = 1;
1122 return true;
1123}
1124
Takashi Iwai1d045db2011-07-07 18:23:21 +02001125/*
1126 * Check the availability of auto-mic switch;
1127 * Set up if really supported
1128 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001129static void alc_init_auto_mic(struct hda_codec *codec)
1130{
1131 struct alc_spec *spec = codec->spec;
1132 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001133 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001134 int i;
1135
Takashi Iwai21268962011-07-07 15:01:13 +02001136 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1137
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001138 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001139 for (i = 0; i < cfg->num_inputs; i++) {
1140 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001141 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001142 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001143 switch (snd_hda_get_input_pin_attr(defcfg)) {
1144 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 if (fixed)
1146 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001147 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1148 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001149 fixed = nid;
1150 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001151 case INPUT_PIN_ATTR_UNUSED:
1152 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001153 case INPUT_PIN_ATTR_DOCK:
1154 if (dock)
1155 return; /* already occupied */
1156 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1157 return; /* invalid type */
1158 dock = nid;
1159 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001160 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001161 if (ext)
1162 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001163 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1164 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001165 ext = nid;
1166 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001167 }
1168 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001169 if (!ext && dock) {
1170 ext = dock;
1171 dock = 0;
1172 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001173 if (!ext || !fixed)
1174 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001175 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001176 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001177 if (dock && !is_jack_detectable(codec, dock))
1178 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001179
1180 /* check imux indices */
1181 spec->ext_mic_pin = ext;
1182 spec->int_mic_pin = fixed;
1183 spec->dock_mic_pin = dock;
1184
1185 spec->auto_mic = 1;
1186 if (!alc_auto_mic_check_imux(codec))
1187 return;
1188
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001189 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1190 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001191 spec->unsol_event = alc_sku_unsol_event;
1192}
1193
Takashi Iwai1d045db2011-07-07 18:23:21 +02001194/* check the availabilities of auto-mute and auto-mic switches */
1195static void alc_auto_check_switches(struct hda_codec *codec)
1196{
David Henningsson42cf0d02011-09-20 12:04:56 +02001197 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001198 alc_init_auto_mic(codec);
1199}
1200
1201/*
1202 * Realtek SSID verification
1203 */
1204
David Henningsson90622912010-10-14 14:50:18 +02001205/* Could be any non-zero and even value. When used as fixup, tells
1206 * the driver to ignore any present sku defines.
1207 */
1208#define ALC_FIXUP_SKU_IGNORE (2)
1209
Kailang Yangda00c242010-03-19 11:23:45 +01001210static int alc_auto_parse_customize_define(struct hda_codec *codec)
1211{
1212 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001213 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001214 struct alc_spec *spec = codec->spec;
1215
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001216 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1217
David Henningsson90622912010-10-14 14:50:18 +02001218 if (spec->cdefine.fixup) {
1219 ass = spec->cdefine.sku_cfg;
1220 if (ass == ALC_FIXUP_SKU_IGNORE)
1221 return -1;
1222 goto do_sku;
1223 }
1224
Kailang Yangda00c242010-03-19 11:23:45 +01001225 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001226 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001227 goto do_sku;
1228
1229 nid = 0x1d;
1230 if (codec->vendor_id == 0x10ec0260)
1231 nid = 0x17;
1232 ass = snd_hda_codec_get_pincfg(codec, nid);
1233
1234 if (!(ass & 1)) {
1235 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1236 codec->chip_name, ass);
1237 return -1;
1238 }
1239
1240 /* check sum */
1241 tmp = 0;
1242 for (i = 1; i < 16; i++) {
1243 if ((ass >> i) & 1)
1244 tmp++;
1245 }
1246 if (((ass >> 16) & 0xf) != tmp)
1247 return -1;
1248
1249 spec->cdefine.port_connectivity = ass >> 30;
1250 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1251 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1252 spec->cdefine.customization = ass >> 8;
1253do_sku:
1254 spec->cdefine.sku_cfg = ass;
1255 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1256 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1257 spec->cdefine.swap = (ass & 0x2) >> 1;
1258 spec->cdefine.override = ass & 0x1;
1259
1260 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1261 nid, spec->cdefine.sku_cfg);
1262 snd_printd("SKU: port_connectivity=0x%x\n",
1263 spec->cdefine.port_connectivity);
1264 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1265 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1266 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1267 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1268 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1269 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1270 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1271
1272 return 0;
1273}
1274
Takashi Iwai1d045db2011-07-07 18:23:21 +02001275/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001276static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1277{
Takashi Iwai21268962011-07-07 15:01:13 +02001278 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001279}
1280
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001281/* check subsystem ID and set up device-specific initialization;
1282 * return 1 if initialized, 0 if invalid SSID
1283 */
1284/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1285 * 31 ~ 16 : Manufacture ID
1286 * 15 ~ 8 : SKU ID
1287 * 7 ~ 0 : Assembly ID
1288 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1289 */
1290static int alc_subsystem_id(struct hda_codec *codec,
1291 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001292 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001293{
1294 unsigned int ass, tmp, i;
1295 unsigned nid;
1296 struct alc_spec *spec = codec->spec;
1297
David Henningsson90622912010-10-14 14:50:18 +02001298 if (spec->cdefine.fixup) {
1299 ass = spec->cdefine.sku_cfg;
1300 if (ass == ALC_FIXUP_SKU_IGNORE)
1301 return 0;
1302 goto do_sku;
1303 }
1304
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001305 ass = codec->subsystem_id & 0xffff;
1306 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1307 goto do_sku;
1308
1309 /* invalid SSID, check the special NID pin defcfg instead */
1310 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001311 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001312 * 29~21 : reserve
1313 * 20 : PCBEEP input
1314 * 19~16 : Check sum (15:1)
1315 * 15~1 : Custom
1316 * 0 : override
1317 */
1318 nid = 0x1d;
1319 if (codec->vendor_id == 0x10ec0260)
1320 nid = 0x17;
1321 ass = snd_hda_codec_get_pincfg(codec, nid);
1322 snd_printd("realtek: No valid SSID, "
1323 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001324 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001325 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001326 return 0;
1327 if ((ass >> 30) != 1) /* no physical connection */
1328 return 0;
1329
1330 /* check sum */
1331 tmp = 0;
1332 for (i = 1; i < 16; i++) {
1333 if ((ass >> i) & 1)
1334 tmp++;
1335 }
1336 if (((ass >> 16) & 0xf) != tmp)
1337 return 0;
1338do_sku:
1339 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1340 ass & 0xffff, codec->vendor_id);
1341 /*
1342 * 0 : override
1343 * 1 : Swap Jack
1344 * 2 : 0 --> Desktop, 1 --> Laptop
1345 * 3~5 : External Amplifier control
1346 * 7~6 : Reserved
1347 */
1348 tmp = (ass & 0x38) >> 3; /* external Amp control */
1349 switch (tmp) {
1350 case 1:
1351 spec->init_amp = ALC_INIT_GPIO1;
1352 break;
1353 case 3:
1354 spec->init_amp = ALC_INIT_GPIO2;
1355 break;
1356 case 7:
1357 spec->init_amp = ALC_INIT_GPIO3;
1358 break;
1359 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001360 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001361 spec->init_amp = ALC_INIT_DEFAULT;
1362 break;
1363 }
1364
1365 /* is laptop or Desktop and enable the function "Mute internal speaker
1366 * when the external headphone out jack is plugged"
1367 */
1368 if (!(ass & 0x8000))
1369 return 1;
1370 /*
1371 * 10~8 : Jack location
1372 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1373 * 14~13: Resvered
1374 * 15 : 1 --> enable the function "Mute internal speaker
1375 * when the external headphone out jack is plugged"
1376 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001377 if (!spec->autocfg.hp_pins[0] &&
1378 !(spec->autocfg.line_out_pins[0] &&
1379 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001380 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001381 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1382 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001383 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001384 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001385 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001386 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001387 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001388 else if (tmp == 3)
1389 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001390 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001391 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001392 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1393 spec->autocfg.line_outs))
1394 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001395 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001396 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001397 return 1;
1398}
Kailang Yangea1fb292008-08-26 12:58:38 +02001399
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001400/* Check the validity of ALC subsystem-id
1401 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1402static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001403{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001404 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001405 struct alc_spec *spec = codec->spec;
1406 snd_printd("realtek: "
1407 "Enable default setup for auto mode as fallback\n");
1408 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001409 }
Takashi Iwai21268962011-07-07 15:01:13 +02001410}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001411
Takashi Iwai41e41f12005-06-08 14:48:49 +02001412/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001413 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001414 */
1415
1416struct alc_pincfg {
1417 hda_nid_t nid;
1418 u32 val;
1419};
1420
Todd Broche1eb5f12010-12-06 11:19:51 -08001421struct alc_model_fixup {
1422 const int id;
1423 const char *name;
1424};
1425
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001426struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001427 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001428 bool chained;
1429 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001430 union {
1431 unsigned int sku;
1432 const struct alc_pincfg *pins;
1433 const struct hda_verb *verbs;
1434 void (*func)(struct hda_codec *codec,
1435 const struct alc_fixup *fix,
1436 int action);
1437 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001438};
1439
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001440enum {
1441 ALC_FIXUP_INVALID,
1442 ALC_FIXUP_SKU,
1443 ALC_FIXUP_PINS,
1444 ALC_FIXUP_VERBS,
1445 ALC_FIXUP_FUNC,
1446};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001447
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001448enum {
1449 ALC_FIXUP_ACT_PRE_PROBE,
1450 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001451 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001452};
1453
1454static void alc_apply_fixup(struct hda_codec *codec, int action)
1455{
1456 struct alc_spec *spec = codec->spec;
1457 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001458#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001459 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001460#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001461 int depth = 0;
1462
1463 if (!spec->fixup_list)
1464 return;
1465
1466 while (id >= 0) {
1467 const struct alc_fixup *fix = spec->fixup_list + id;
1468 const struct alc_pincfg *cfg;
1469
1470 switch (fix->type) {
1471 case ALC_FIXUP_SKU:
1472 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001473 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001474 snd_printdd(KERN_INFO "hda_codec: %s: "
1475 "Apply sku override for %s\n",
1476 codec->chip_name, modelname);
1477 spec->cdefine.sku_cfg = fix->v.sku;
1478 spec->cdefine.fixup = 1;
1479 break;
1480 case ALC_FIXUP_PINS:
1481 cfg = fix->v.pins;
1482 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1483 break;
1484 snd_printdd(KERN_INFO "hda_codec: %s: "
1485 "Apply pincfg for %s\n",
1486 codec->chip_name, modelname);
1487 for (; cfg->nid; cfg++)
1488 snd_hda_codec_set_pincfg(codec, cfg->nid,
1489 cfg->val);
1490 break;
1491 case ALC_FIXUP_VERBS:
1492 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1493 break;
1494 snd_printdd(KERN_INFO "hda_codec: %s: "
1495 "Apply fix-verbs for %s\n",
1496 codec->chip_name, modelname);
1497 add_verb(codec->spec, fix->v.verbs);
1498 break;
1499 case ALC_FIXUP_FUNC:
1500 if (!fix->v.func)
1501 break;
1502 snd_printdd(KERN_INFO "hda_codec: %s: "
1503 "Apply fix-func for %s\n",
1504 codec->chip_name, modelname);
1505 fix->v.func(codec, fix, action);
1506 break;
1507 default:
1508 snd_printk(KERN_ERR "hda_codec: %s: "
1509 "Invalid fixup type %d\n",
1510 codec->chip_name, fix->type);
1511 break;
1512 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001513 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001514 break;
1515 if (++depth > 10)
1516 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001517 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001518 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001519}
1520
Todd Broche1eb5f12010-12-06 11:19:51 -08001521static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001522 const struct alc_model_fixup *models,
1523 const struct snd_pci_quirk *quirk,
1524 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001525{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001526 struct alc_spec *spec = codec->spec;
1527 int id = -1;
1528 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001529
Todd Broche1eb5f12010-12-06 11:19:51 -08001530 if (codec->modelname && models) {
1531 while (models->name) {
1532 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001533 id = models->id;
1534 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001535 break;
1536 }
1537 models++;
1538 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001539 }
1540 if (id < 0) {
1541 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1542 if (quirk) {
1543 id = quirk->value;
1544#ifdef CONFIG_SND_DEBUG_VERBOSE
1545 name = quirk->name;
1546#endif
1547 }
1548 }
1549
1550 spec->fixup_id = id;
1551 if (id >= 0) {
1552 spec->fixup_list = fixlist;
1553 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001554 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001555}
1556
Takashi Iwai1d045db2011-07-07 18:23:21 +02001557/*
1558 * COEF access helper functions
1559 */
Kailang Yang274693f2009-12-03 10:07:50 +01001560static int alc_read_coef_idx(struct hda_codec *codec,
1561 unsigned int coef_idx)
1562{
1563 unsigned int val;
1564 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1565 coef_idx);
1566 val = snd_hda_codec_read(codec, 0x20, 0,
1567 AC_VERB_GET_PROC_COEF, 0);
1568 return val;
1569}
1570
Kailang Yang977ddd62010-09-15 10:02:29 +02001571static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1572 unsigned int coef_val)
1573{
1574 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1575 coef_idx);
1576 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1577 coef_val);
1578}
1579
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001580/* a special bypass for COEF 0; read the cached value at the second time */
1581static unsigned int alc_get_coef0(struct hda_codec *codec)
1582{
1583 struct alc_spec *spec = codec->spec;
1584 if (!spec->coef0)
1585 spec->coef0 = alc_read_coef_idx(codec, 0);
1586 return spec->coef0;
1587}
1588
Takashi Iwai1d045db2011-07-07 18:23:21 +02001589/*
1590 * Digital I/O handling
1591 */
1592
Takashi Iwai757899a2010-07-30 10:48:14 +02001593/* set right pin controls for digital I/O */
1594static void alc_auto_init_digital(struct hda_codec *codec)
1595{
1596 struct alc_spec *spec = codec->spec;
1597 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001598 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001599
1600 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1601 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001602 if (!pin)
1603 continue;
1604 snd_hda_codec_write(codec, pin, 0,
1605 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1606 if (!i)
1607 dac = spec->multiout.dig_out_nid;
1608 else
1609 dac = spec->slave_dig_outs[i - 1];
1610 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1611 continue;
1612 snd_hda_codec_write(codec, dac, 0,
1613 AC_VERB_SET_AMP_GAIN_MUTE,
1614 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001615 }
1616 pin = spec->autocfg.dig_in_pin;
1617 if (pin)
1618 snd_hda_codec_write(codec, pin, 0,
1619 AC_VERB_SET_PIN_WIDGET_CONTROL,
1620 PIN_IN);
1621}
1622
1623/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1624static void alc_auto_parse_digital(struct hda_codec *codec)
1625{
1626 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001627 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001628 hda_nid_t dig_nid;
1629
1630 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001631 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001632 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001633 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001634 err = snd_hda_get_connections(codec,
1635 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001636 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001637 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001638 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001639 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001640 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001641 spec->multiout.dig_out_nid = dig_nid;
1642 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1643 } else {
1644 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001645 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001646 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001647 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001648 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001649 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001650 }
1651
1652 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001653 dig_nid = codec->start_nid;
1654 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1655 unsigned int wcaps = get_wcaps(codec, dig_nid);
1656 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1657 continue;
1658 if (!(wcaps & AC_WCAP_DIGITAL))
1659 continue;
1660 if (!(wcaps & AC_WCAP_CONN_LIST))
1661 continue;
1662 err = get_connection_index(codec, dig_nid,
1663 spec->autocfg.dig_in_pin);
1664 if (err >= 0) {
1665 spec->dig_in_nid = dig_nid;
1666 break;
1667 }
1668 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001669 }
1670}
1671
Takashi Iwaif95474e2007-07-10 00:47:43 +02001672/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001673 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001674 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001675static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1676 struct snd_ctl_elem_info *uinfo)
1677{
1678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1679 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001680 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001681 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001682
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001683 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001684 if (spec->vol_in_capsrc)
1685 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1686 else
1687 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1688 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001689 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001690 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001691 return err;
1692}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001694static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1695 unsigned int size, unsigned int __user *tlv)
1696{
1697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1698 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001699 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001700 int err;
1701
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001702 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001703 if (spec->vol_in_capsrc)
1704 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1705 else
1706 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1707 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001708 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001709 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001710 return err;
1711}
1712
1713typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1714 struct snd_ctl_elem_value *ucontrol);
1715
1716static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1717 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001718 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001719{
1720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1721 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001722 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001723
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001724 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001725 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001726 for (i = 0; i < spec->num_adc_nids; i++) {
1727 kcontrol->private_value =
1728 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1729 3, 0, HDA_INPUT);
1730 err = func(kcontrol, ucontrol);
1731 if (err < 0)
1732 goto error;
1733 }
1734 } else {
1735 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001736 if (spec->vol_in_capsrc)
1737 kcontrol->private_value =
1738 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1739 3, 0, HDA_OUTPUT);
1740 else
1741 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001742 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1743 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001744 err = func(kcontrol, ucontrol);
1745 }
1746 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001747 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001748 return err;
1749}
1750
1751static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1752 struct snd_ctl_elem_value *ucontrol)
1753{
1754 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001755 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001756}
1757
1758static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1759 struct snd_ctl_elem_value *ucontrol)
1760{
1761 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001762 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001763}
1764
1765/* capture mixer elements */
1766#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1767
1768static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1769 struct snd_ctl_elem_value *ucontrol)
1770{
1771 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001772 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001773}
1774
1775static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1776 struct snd_ctl_elem_value *ucontrol)
1777{
1778 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001779 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001780}
1781
Takashi Iwaia23b6882009-03-23 15:21:36 +01001782#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001783 { \
1784 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1785 .name = "Capture Switch", \
1786 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1787 .count = num, \
1788 .info = alc_cap_sw_info, \
1789 .get = alc_cap_sw_get, \
1790 .put = alc_cap_sw_put, \
1791 }, \
1792 { \
1793 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1794 .name = "Capture Volume", \
1795 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1796 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1797 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1798 .count = num, \
1799 .info = alc_cap_vol_info, \
1800 .get = alc_cap_vol_get, \
1801 .put = alc_cap_vol_put, \
1802 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001803 }
1804
1805#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001806 { \
1807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1808 /* .name = "Capture Source", */ \
1809 .name = "Input Source", \
1810 .count = num, \
1811 .info = alc_mux_enum_info, \
1812 .get = alc_mux_enum_get, \
1813 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001814 }
1815
1816#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001817static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001818 _DEFINE_CAPMIX(num), \
1819 _DEFINE_CAPSRC(num), \
1820 { } /* end */ \
1821}
1822
1823#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001824static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001825 _DEFINE_CAPMIX(num), \
1826 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001827}
1828
1829/* up to three ADCs */
1830DEFINE_CAPMIX(1);
1831DEFINE_CAPMIX(2);
1832DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001833DEFINE_CAPMIX_NOSRC(1);
1834DEFINE_CAPMIX_NOSRC(2);
1835DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001836
1837/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001838 * virtual master controls
1839 */
1840
1841/*
1842 * slave controls for virtual master
1843 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001844static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001845 "Front Playback Volume",
1846 "Surround Playback Volume",
1847 "Center Playback Volume",
1848 "LFE Playback Volume",
1849 "Side Playback Volume",
1850 "Headphone Playback Volume",
1851 "Speaker Playback Volume",
1852 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001853 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001854 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001855 NULL,
1856};
1857
Takashi Iwaiea734962011-01-17 11:29:34 +01001858static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001859 "Front Playback Switch",
1860 "Surround Playback Switch",
1861 "Center Playback Switch",
1862 "LFE Playback Switch",
1863 "Side Playback Switch",
1864 "Headphone Playback Switch",
1865 "Speaker Playback Switch",
1866 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001867 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001868 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001869 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001870 NULL,
1871};
1872
1873/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001874 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001876
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001877#define NID_MAPPING (-1)
1878
1879#define SUBDEV_SPEAKER_ (0 << 6)
1880#define SUBDEV_HP_ (1 << 6)
1881#define SUBDEV_LINE_ (2 << 6)
1882#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1883#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1884#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1885
Takashi Iwai603c4012008-07-30 15:01:44 +02001886static void alc_free_kctls(struct hda_codec *codec);
1887
Takashi Iwai67d634c2009-11-16 15:35:59 +01001888#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001889/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001890static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001891 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001892 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001893 { } /* end */
1894};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001895#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001896
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897static int alc_build_controls(struct hda_codec *codec)
1898{
1899 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001900 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001901 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001902 int i, j, err;
1903 unsigned int u;
1904 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
1906 for (i = 0; i < spec->num_mixers; i++) {
1907 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1908 if (err < 0)
1909 return err;
1910 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001911 if (spec->cap_mixer) {
1912 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1913 if (err < 0)
1914 return err;
1915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001917 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001918 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001919 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 if (err < 0)
1921 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001922 if (!spec->no_analog) {
1923 err = snd_hda_create_spdif_share_sw(codec,
1924 &spec->multiout);
1925 if (err < 0)
1926 return err;
1927 spec->multiout.share_spdif = 1;
1928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 }
1930 if (spec->dig_in_nid) {
1931 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1932 if (err < 0)
1933 return err;
1934 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001935
Takashi Iwai67d634c2009-11-16 15:35:59 +01001936#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001937 /* create beep controls if needed */
1938 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001939 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001940 for (knew = alc_beep_mixer; knew->name; knew++) {
1941 struct snd_kcontrol *kctl;
1942 kctl = snd_ctl_new1(knew, codec);
1943 if (!kctl)
1944 return -ENOMEM;
1945 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001946 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001947 if (err < 0)
1948 return err;
1949 }
1950 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001951#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001952
Takashi Iwai2134ea42008-01-10 16:53:55 +01001953 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001954 if (!spec->no_analog &&
1955 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001956 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001957 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001958 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001959 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001960 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001961 if (err < 0)
1962 return err;
1963 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001964 if (!spec->no_analog &&
1965 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001966 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1967 NULL, alc_slave_sws);
1968 if (err < 0)
1969 return err;
1970 }
1971
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001972 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001973 if (spec->capsrc_nids || spec->adc_nids) {
1974 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1975 if (!kctl)
1976 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1977 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001978 err = snd_hda_add_nid(codec, kctl, i,
1979 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001980 if (err < 0)
1981 return err;
1982 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001983 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001984 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001985 const char *kname = kctl ? kctl->id.name : NULL;
1986 for (knew = spec->cap_mixer; knew->name; knew++) {
1987 if (kname && strcmp(knew->name, kname) == 0)
1988 continue;
1989 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1990 for (i = 0; kctl && i < kctl->count; i++) {
1991 err = snd_hda_add_nid(codec, kctl, i,
1992 spec->adc_nids[i]);
1993 if (err < 0)
1994 return err;
1995 }
1996 }
1997 }
1998
1999 /* other nid->control mapping */
2000 for (i = 0; i < spec->num_mixers; i++) {
2001 for (knew = spec->mixers[i]; knew->name; knew++) {
2002 if (knew->iface != NID_MAPPING)
2003 continue;
2004 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2005 if (kctl == NULL)
2006 continue;
2007 u = knew->subdevice;
2008 for (j = 0; j < 4; j++, u >>= 8) {
2009 nid = u & 0x3f;
2010 if (nid == 0)
2011 continue;
2012 switch (u & 0xc0) {
2013 case SUBDEV_SPEAKER_:
2014 nid = spec->autocfg.speaker_pins[nid];
2015 break;
2016 case SUBDEV_LINE_:
2017 nid = spec->autocfg.line_out_pins[nid];
2018 break;
2019 case SUBDEV_HP_:
2020 nid = spec->autocfg.hp_pins[nid];
2021 break;
2022 default:
2023 continue;
2024 }
2025 err = snd_hda_add_nid(codec, kctl, 0, nid);
2026 if (err < 0)
2027 return err;
2028 }
2029 u = knew->private_value;
2030 for (j = 0; j < 4; j++, u >>= 8) {
2031 nid = u & 0xff;
2032 if (nid == 0)
2033 continue;
2034 err = snd_hda_add_nid(codec, kctl, 0, nid);
2035 if (err < 0)
2036 return err;
2037 }
2038 }
2039 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002040
2041 alc_free_kctls(codec); /* no longer needed */
2042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 return 0;
2044}
2045
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002048 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002049 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002050
Takashi Iwai584c0c42011-03-10 12:51:11 +01002051static void alc_init_special_input_src(struct hda_codec *codec);
2052
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053static int alc_init(struct hda_codec *codec)
2054{
2055 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002056 unsigned int i;
2057
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002058 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002059 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002060
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002061 for (i = 0; i < spec->num_init_verbs; i++)
2062 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002063 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002064
2065 if (spec->init_hook)
2066 spec->init_hook(codec);
2067
Takashi Iwai58701122011-01-13 15:41:45 +01002068 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2069
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002070 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 return 0;
2072}
2073
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002074static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2075{
2076 struct alc_spec *spec = codec->spec;
2077
2078 if (spec->unsol_event)
2079 spec->unsol_event(codec, res);
2080}
2081
Takashi Iwaicb53c622007-08-10 17:21:45 +02002082#ifdef CONFIG_SND_HDA_POWER_SAVE
2083static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2084{
2085 struct alc_spec *spec = codec->spec;
2086 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2087}
2088#endif
2089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090/*
2091 * Analog playback callbacks
2092 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002093static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002095 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
2097 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002098 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2099 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100}
2101
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002102static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct hda_codec *codec,
2104 unsigned int stream_tag,
2105 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002106 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002109 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2110 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111}
2112
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002113static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002115 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
2117 struct alc_spec *spec = codec->spec;
2118 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2119}
2120
2121/*
2122 * Digital out
2123 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002124static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002126 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127{
2128 struct alc_spec *spec = codec->spec;
2129 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2130}
2131
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002132static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002133 struct hda_codec *codec,
2134 unsigned int stream_tag,
2135 unsigned int format,
2136 struct snd_pcm_substream *substream)
2137{
2138 struct alc_spec *spec = codec->spec;
2139 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2140 stream_tag, format, substream);
2141}
2142
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002143static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002144 struct hda_codec *codec,
2145 struct snd_pcm_substream *substream)
2146{
2147 struct alc_spec *spec = codec->spec;
2148 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2149}
2150
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002151static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002153 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154{
2155 struct alc_spec *spec = codec->spec;
2156 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2157}
2158
2159/*
2160 * Analog capture
2161 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002162static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 struct hda_codec *codec,
2164 unsigned int stream_tag,
2165 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002166 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167{
2168 struct alc_spec *spec = codec->spec;
2169
Takashi Iwai63300792008-01-24 15:31:36 +01002170 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 stream_tag, 0, format);
2172 return 0;
2173}
2174
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002175static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002177 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
2179 struct alc_spec *spec = codec->spec;
2180
Takashi Iwai888afa12008-03-18 09:57:50 +01002181 snd_hda_codec_cleanup_stream(codec,
2182 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 return 0;
2184}
2185
Takashi Iwai840b64c2010-07-13 22:49:01 +02002186/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002187static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002188 struct hda_codec *codec,
2189 unsigned int stream_tag,
2190 unsigned int format,
2191 struct snd_pcm_substream *substream)
2192{
2193 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002194 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002195 spec->cur_adc_stream_tag = stream_tag;
2196 spec->cur_adc_format = format;
2197 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2198 return 0;
2199}
2200
Takashi Iwai21268962011-07-07 15:01:13 +02002201static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002202 struct hda_codec *codec,
2203 struct snd_pcm_substream *substream)
2204{
2205 struct alc_spec *spec = codec->spec;
2206 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2207 spec->cur_adc = 0;
2208 return 0;
2209}
2210
Takashi Iwai21268962011-07-07 15:01:13 +02002211static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002212 .substreams = 1,
2213 .channels_min = 2,
2214 .channels_max = 2,
2215 .nid = 0, /* fill later */
2216 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002217 .prepare = dyn_adc_capture_pcm_prepare,
2218 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002219 },
2220};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
2222/*
2223 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002224static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 .substreams = 1,
2226 .channels_min = 2,
2227 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002228 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002230 .open = alc_playback_pcm_open,
2231 .prepare = alc_playback_pcm_prepare,
2232 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 },
2234};
2235
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002236static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002237 .substreams = 1,
2238 .channels_min = 2,
2239 .channels_max = 2,
2240 /* NID is set in alc_build_pcms */
2241};
2242
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002243static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002244 .substreams = 1,
2245 .channels_min = 2,
2246 .channels_max = 2,
2247 /* NID is set in alc_build_pcms */
2248};
2249
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002250static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002251 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 .channels_min = 2,
2253 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002254 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002256 .prepare = alc_alt_capture_pcm_prepare,
2257 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 },
2259};
2260
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002261static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 .substreams = 1,
2263 .channels_min = 2,
2264 .channels_max = 2,
2265 /* NID is set in alc_build_pcms */
2266 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002267 .open = alc_dig_playback_pcm_open,
2268 .close = alc_dig_playback_pcm_close,
2269 .prepare = alc_dig_playback_pcm_prepare,
2270 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 },
2272};
2273
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002274static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 .substreams = 1,
2276 .channels_min = 2,
2277 .channels_max = 2,
2278 /* NID is set in alc_build_pcms */
2279};
2280
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002281/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002282static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002283 .substreams = 0,
2284 .channels_min = 0,
2285 .channels_max = 0,
2286};
2287
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288static int alc_build_pcms(struct hda_codec *codec)
2289{
2290 struct alc_spec *spec = codec->spec;
2291 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002292 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002293 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 int i;
2295
2296 codec->num_pcms = 1;
2297 codec->pcm_info = info;
2298
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002299 if (spec->no_analog)
2300 goto skip_analog;
2301
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002302 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2303 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002305
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002306 if (spec->multiout.dac_nids > 0) {
2307 p = spec->stream_analog_playback;
2308 if (!p)
2309 p = &alc_pcm_analog_playback;
2310 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002311 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2312 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002313 if (spec->adc_nids) {
2314 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002315 if (!p) {
2316 if (spec->dyn_adc_switch)
2317 p = &dyn_adc_pcm_analog_capture;
2318 else
2319 p = &alc_pcm_analog_capture;
2320 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002321 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002322 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Takashi Iwai4a471b72005-12-07 13:56:29 +01002325 if (spec->channel_mode) {
2326 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2327 for (i = 0; i < spec->num_channel_mode; i++) {
2328 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 }
2332 }
2333
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002334 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002335 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002337 snprintf(spec->stream_name_digital,
2338 sizeof(spec->stream_name_digital),
2339 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002340 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002341 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002342 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002344 if (spec->dig_out_type)
2345 info->pcm_type = spec->dig_out_type;
2346 else
2347 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002348 if (spec->multiout.dig_out_nid) {
2349 p = spec->stream_digital_playback;
2350 if (!p)
2351 p = &alc_pcm_digital_playback;
2352 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2354 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002355 if (spec->dig_in_nid) {
2356 p = spec->stream_digital_capture;
2357 if (!p)
2358 p = &alc_pcm_digital_capture;
2359 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2361 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002362 /* FIXME: do we need this for all Realtek codec models? */
2363 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 }
2365
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002366 if (spec->no_analog)
2367 return 0;
2368
Takashi Iwaie08a0072006-09-07 17:52:14 +02002369 /* If the use of more than one ADC is requested for the current
2370 * model, configure a second analog capture-only PCM.
2371 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002372 have_multi_adcs = (spec->num_adc_nids > 1) &&
2373 !spec->dyn_adc_switch && !spec->auto_mic &&
2374 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002375 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002376 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002377 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002378 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002379 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002380 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002381 p = spec->stream_analog_alt_playback;
2382 if (!p)
2383 p = &alc_pcm_analog_alt_playback;
2384 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002385 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2386 spec->alt_dac_nid;
2387 } else {
2388 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2389 alc_pcm_null_stream;
2390 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2391 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002392 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002393 p = spec->stream_analog_alt_capture;
2394 if (!p)
2395 p = &alc_pcm_analog_alt_capture;
2396 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002397 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2398 spec->adc_nids[1];
2399 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2400 spec->num_adc_nids - 1;
2401 } else {
2402 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2403 alc_pcm_null_stream;
2404 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002405 }
2406 }
2407
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 return 0;
2409}
2410
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002411static inline void alc_shutup(struct hda_codec *codec)
2412{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002413 struct alc_spec *spec = codec->spec;
2414
2415 if (spec && spec->shutup)
2416 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002417 snd_hda_shutup_pins(codec);
2418}
2419
Takashi Iwai603c4012008-07-30 15:01:44 +02002420static void alc_free_kctls(struct hda_codec *codec)
2421{
2422 struct alc_spec *spec = codec->spec;
2423
2424 if (spec->kctls.list) {
2425 struct snd_kcontrol_new *kctl = spec->kctls.list;
2426 int i;
2427 for (i = 0; i < spec->kctls.used; i++)
2428 kfree(kctl[i].name);
2429 }
2430 snd_array_free(&spec->kctls);
2431}
2432
Takashi Iwai23c09b02011-08-19 09:05:35 +02002433static void alc_free_bind_ctls(struct hda_codec *codec)
2434{
2435 struct alc_spec *spec = codec->spec;
2436 if (spec->bind_ctls.list) {
2437 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2438 int i;
2439 for (i = 0; i < spec->bind_ctls.used; i++)
2440 kfree(ctl[i]);
2441 }
2442 snd_array_free(&spec->bind_ctls);
2443}
2444
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445static void alc_free(struct hda_codec *codec)
2446{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002447 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002448
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002449 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002450 return;
2451
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002452 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002453 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002454 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002455 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002456 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002457 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458}
2459
Hector Martinf5de24b2009-12-20 22:51:31 +01002460#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002461static void alc_power_eapd(struct hda_codec *codec)
2462{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002463 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002464}
2465
Hector Martinf5de24b2009-12-20 22:51:31 +01002466static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2467{
2468 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002469 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002470 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002471 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002472 return 0;
2473}
2474#endif
2475
Takashi Iwai2a439522011-07-26 09:52:50 +02002476#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002477static int alc_resume(struct hda_codec *codec)
2478{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002479 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002480 codec->patch_ops.init(codec);
2481 snd_hda_codec_resume_amp(codec);
2482 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002483 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002484 return 0;
2485}
Takashi Iwaie044c392008-10-27 16:56:24 +01002486#endif
2487
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488/*
2489 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002490static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 .build_controls = alc_build_controls,
2492 .build_pcms = alc_build_pcms,
2493 .init = alc_init,
2494 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002495 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002496#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002497 .resume = alc_resume,
2498#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002499#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002500 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002501 .check_power_status = alc_check_power_status,
2502#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002503 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504};
2505
Kailang Yangc027ddc2010-03-19 11:33:06 +01002506/* replace the codec chip_name with the given string */
2507static int alc_codec_rename(struct hda_codec *codec, const char *name)
2508{
2509 kfree(codec->chip_name);
2510 codec->chip_name = kstrdup(name, GFP_KERNEL);
2511 if (!codec->chip_name) {
2512 alc_free(codec);
2513 return -ENOMEM;
2514 }
2515 return 0;
2516}
2517
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002518/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002519 * Rename codecs appropriately from COEF value
2520 */
2521struct alc_codec_rename_table {
2522 unsigned int vendor_id;
2523 unsigned short coef_mask;
2524 unsigned short coef_bits;
2525 const char *name;
2526};
2527
2528static struct alc_codec_rename_table rename_tbl[] = {
2529 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2530 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2531 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2532 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2533 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2534 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2535 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2536 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2537 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2538 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2539 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2540 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2541 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2542 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2543 { } /* terminator */
2544};
2545
2546static int alc_codec_rename_from_preset(struct hda_codec *codec)
2547{
2548 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002549
2550 for (p = rename_tbl; p->vendor_id; p++) {
2551 if (p->vendor_id != codec->vendor_id)
2552 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002553 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002554 return alc_codec_rename(codec, p->name);
2555 }
2556 return 0;
2557}
2558
2559/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002560 * Automatic parse of I/O pins from the BIOS configuration
2561 */
2562
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002563enum {
2564 ALC_CTL_WIDGET_VOL,
2565 ALC_CTL_WIDGET_MUTE,
2566 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002567 ALC_CTL_BIND_VOL,
2568 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002569};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002570static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002571 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2572 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002573 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002574 HDA_BIND_VOL(NULL, 0),
2575 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002576};
2577
2578/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002579static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002580 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002581{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002582 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002583
Takashi Iwaice764ab2011-04-27 16:35:23 +02002584 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002585 if (!knew)
2586 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002587 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002588 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002589 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002590 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002591 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002592 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002593 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002594 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002595 return 0;
2596}
2597
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002598static int add_control_with_pfx(struct alc_spec *spec, int type,
2599 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002600 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002601{
2602 char name[32];
2603 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002604 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002605}
2606
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002607#define add_pb_vol_ctrl(spec, type, pfx, val) \
2608 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2609#define add_pb_sw_ctrl(spec, type, pfx, val) \
2610 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2611#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2612 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2613#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2614 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002615
Takashi Iwai23c09b02011-08-19 09:05:35 +02002616static const char * const channel_name[4] = {
2617 "Front", "Surround", "CLFE", "Side"
2618};
2619
Takashi Iwai6843ca12011-06-24 11:03:58 +02002620static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2621 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002622{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002623 struct auto_pin_cfg *cfg = &spec->autocfg;
2624
Takashi Iwai6843ca12011-06-24 11:03:58 +02002625 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002626 if (cfg->line_outs == 1 && !spec->multi_ios &&
2627 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002628 return "Master";
2629
2630 switch (cfg->line_out_type) {
2631 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002632 if (cfg->line_outs == 1)
2633 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002634 if (cfg->line_outs == 2)
2635 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002636 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002637 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002638 /* for multi-io case, only the primary out */
2639 if (ch && spec->multi_ios)
2640 break;
2641 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002642 return "Headphone";
2643 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002644 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002645 return "PCM";
2646 break;
2647 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002648 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2649 return "PCM";
2650
2651 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002652}
2653
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002654/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002655static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002656 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002657 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002658{
Kailang Yangdf694da2005-12-05 19:42:22 +01002659 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002660
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002661 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002662 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2663 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002664 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002665 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002666 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2667 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002668 return err;
2669 return 0;
2670}
2671
Takashi Iwai05f5f472009-08-25 13:10:18 +02002672static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002673{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002674 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2675 return (pincap & AC_PINCAP_IN) != 0;
2676}
2677
Takashi Iwai1d045db2011-07-07 18:23:21 +02002678/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002679static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002680{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002681 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002682 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002683 hda_nid_t *adc_nids = spec->private_adc_nids;
2684 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2685 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002686 int i, nums = 0;
2687
2688 nid = codec->start_nid;
2689 for (i = 0; i < codec->num_nodes; i++, nid++) {
2690 hda_nid_t src;
2691 const hda_nid_t *list;
2692 unsigned int caps = get_wcaps(codec, nid);
2693 int type = get_wcaps_type(caps);
2694
2695 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2696 continue;
2697 adc_nids[nums] = nid;
2698 cap_nids[nums] = nid;
2699 src = nid;
2700 for (;;) {
2701 int n;
2702 type = get_wcaps_type(get_wcaps(codec, src));
2703 if (type == AC_WID_PIN)
2704 break;
2705 if (type == AC_WID_AUD_SEL) {
2706 cap_nids[nums] = src;
2707 break;
2708 }
2709 n = snd_hda_get_conn_list(codec, src, &list);
2710 if (n > 1) {
2711 cap_nids[nums] = src;
2712 break;
2713 } else if (n != 1)
2714 break;
2715 src = *list;
2716 }
2717 if (++nums >= max_nums)
2718 break;
2719 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002720 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002721 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002722 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002723 return nums;
2724}
2725
Takashi Iwai05f5f472009-08-25 13:10:18 +02002726/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002727static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002728{
2729 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002730 const struct auto_pin_cfg *cfg = &spec->autocfg;
2731 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002732 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002733 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002734 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002735 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002736
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002737 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002738 if (num_adcs < 0)
2739 return 0;
2740
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002741 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002742 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002743 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002744
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002745 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002746 if (!alc_is_input_pin(codec, pin))
2747 continue;
2748
David Henningsson5322bf22011-01-05 11:03:56 +01002749 label = hda_get_autocfg_input_label(codec, cfg, i);
2750 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002751 type_idx++;
2752 else
2753 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002754 prev_label = label;
2755
Takashi Iwai05f5f472009-08-25 13:10:18 +02002756 if (mixer) {
2757 idx = get_connection_index(codec, mixer, pin);
2758 if (idx >= 0) {
2759 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002760 label, type_idx,
2761 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002762 if (err < 0)
2763 return err;
2764 }
2765 }
2766
Takashi Iwaib7821702011-07-06 15:12:46 +02002767 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002768 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002769 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002770 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002771 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002772 snd_hda_add_imux_item(imux, label, idx, NULL);
2773 break;
2774 }
2775 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002776 }
Takashi Iwai21268962011-07-07 15:01:13 +02002777
2778 spec->num_mux_defs = 1;
2779 spec->input_mux = imux;
2780
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002781 return 0;
2782}
2783
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002784static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2785 unsigned int pin_type)
2786{
2787 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2788 pin_type);
2789 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002790 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2791 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002792 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002793}
2794
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002795static int get_pin_type(int line_out_type)
2796{
2797 if (line_out_type == AUTO_PIN_HP_OUT)
2798 return PIN_HP;
2799 else
2800 return PIN_OUT;
2801}
2802
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002803static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002804{
2805 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002806 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002807 int i;
2808
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002809 for (i = 0; i < cfg->num_inputs; i++) {
2810 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002811 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002812 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002813 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002814 snd_hda_codec_write(codec, nid, 0,
2815 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002816 AMP_OUT_MUTE);
2817 }
2818 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002819
2820 /* mute all loopback inputs */
2821 if (spec->mixer_nid) {
2822 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2823 for (i = 0; i < nums; i++)
2824 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2825 AC_VERB_SET_AMP_GAIN_MUTE,
2826 AMP_IN_MUTE(i));
2827 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002828}
2829
Takashi Iwai7085ec12009-10-02 09:03:58 +02002830/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002831static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002832{
Takashi Iwai604401a2011-04-27 15:14:23 +02002833 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002834 int i, num;
2835
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002836 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2837 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002838 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2839 for (i = 0; i < num; i++) {
2840 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2841 return list[i];
2842 }
2843 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002844}
2845
Takashi Iwai604401a2011-04-27 15:14:23 +02002846/* go down to the selector widget before the mixer */
2847static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2848{
2849 hda_nid_t srcs[5];
2850 int num = snd_hda_get_connections(codec, pin, srcs,
2851 ARRAY_SIZE(srcs));
2852 if (num != 1 ||
2853 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2854 return pin;
2855 return srcs[0];
2856}
2857
Takashi Iwai7085ec12009-10-02 09:03:58 +02002858/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002859static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002860 hda_nid_t dac)
2861{
David Henningssoncc1c4522010-11-24 14:17:47 +01002862 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002863 int i, num;
2864
Takashi Iwai604401a2011-04-27 15:14:23 +02002865 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002866 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2867 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002868 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002869 return mix[i];
2870 }
2871 return 0;
2872}
2873
Takashi Iwaice764ab2011-04-27 16:35:23 +02002874/* select the connection from pin to DAC if needed */
2875static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2876 hda_nid_t dac)
2877{
2878 hda_nid_t mix[5];
2879 int i, num;
2880
2881 pin = alc_go_down_to_selector(codec, pin);
2882 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2883 if (num < 2)
2884 return 0;
2885 for (i = 0; i < num; i++) {
2886 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2887 snd_hda_codec_update_cache(codec, pin, 0,
2888 AC_VERB_SET_CONNECT_SEL, i);
2889 return 0;
2890 }
2891 }
2892 return 0;
2893}
2894
Takashi Iwai7085ec12009-10-02 09:03:58 +02002895/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002896static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002897{
2898 struct alc_spec *spec = codec->spec;
2899 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002900 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002901
Takashi Iwai604401a2011-04-27 15:14:23 +02002902 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002903 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002904 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002905 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002906 if (!nid)
2907 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002908 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2909 spec->multiout.num_dacs))
2910 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002911 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2912 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2913 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002914 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2915 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2916 continue;
2917 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002918 }
2919 return 0;
2920}
2921
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002922static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2923{
2924 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2925 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2926 return alc_auto_look_for_dac(codec, pin);
2927 return 0;
2928}
2929
Takashi Iwaic2674682011-08-24 17:57:44 +02002930static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2931 const hda_nid_t *pins, hda_nid_t *dacs)
2932{
2933 int i;
2934
2935 if (num_outs && !dacs[0]) {
2936 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2937 if (!dacs[0])
2938 return 0;
2939 }
2940
2941 for (i = 1; i < num_outs; i++)
2942 dacs[i] = get_dac_if_single(codec, pins[i]);
2943 for (i = 1; i < num_outs; i++) {
2944 if (!dacs[i])
2945 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2946 }
2947 return 0;
2948}
2949
2950static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2951 unsigned int location);
2952
Takashi Iwai7085ec12009-10-02 09:03:58 +02002953/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02002954static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002955{
2956 struct alc_spec *spec = codec->spec;
Takashi Iwaicb053a82011-06-27 11:32:07 +02002957 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai350434e2011-06-30 21:29:12 +02002958 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002959 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002960
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002961 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002962 /* set num_dacs once to full for alc_auto_look_for_dac() */
2963 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02002964 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002965 spec->multiout.extra_out_nid[0] = 0;
2966 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2967 spec->multiout.dac_nids = spec->private_dac_nids;
2968
2969 /* fill hard-wired DACs first */
2970 if (!redone) {
2971 for (i = 0; i < cfg->line_outs; i++)
2972 spec->private_dac_nids[i] =
2973 get_dac_if_single(codec, cfg->line_out_pins[i]);
2974 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02002975 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002976 get_dac_if_single(codec, cfg->hp_pins[0]);
2977 if (cfg->speaker_outs)
2978 spec->multiout.extra_out_nid[0] =
2979 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002980 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002981
2982 for (i = 0; i < cfg->line_outs; i++) {
2983 hda_nid_t pin = cfg->line_out_pins[i];
2984 if (spec->private_dac_nids[i])
2985 continue;
2986 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2987 if (!spec->private_dac_nids[i] && !redone) {
2988 /* if we can't find primary DACs, re-probe without
2989 * checking the hard-wired DACs
2990 */
2991 redone = true;
2992 goto again;
2993 }
2994 }
2995
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002996 /* re-count num_dacs and squash invalid entries */
2997 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002998 for (i = 0; i < cfg->line_outs; i++) {
2999 if (spec->private_dac_nids[i])
3000 spec->multiout.num_dacs++;
3001 else
3002 memmove(spec->private_dac_nids + i,
3003 spec->private_dac_nids + i + 1,
3004 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3005 }
3006
Takashi Iwaic2674682011-08-24 17:57:44 +02003007 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3008 /* try to fill multi-io first */
3009 unsigned int location, defcfg;
3010 int num_pins;
Takashi Iwaibb8bf4d2011-07-06 13:07:54 +02003011
Takashi Iwaic2674682011-08-24 17:57:44 +02003012 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3013 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003014
Takashi Iwaic2674682011-08-24 17:57:44 +02003015 num_pins = alc_auto_fill_multi_ios(codec, location);
3016 if (num_pins > 0) {
3017 spec->multi_ios = num_pins;
3018 spec->ext_channel_count = 2;
3019 spec->multiout.num_dacs = num_pins + 1;
3020 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003021 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003022
Takashi Iwai716eef02011-10-21 15:07:42 +02003023 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3024 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003025 spec->multiout.hp_out_nid);
Takashi Iwai716eef02011-10-21 15:07:42 +02003026 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3027 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003028 spec->multiout.extra_out_nid);
3029
Takashi Iwai23c09b02011-08-19 09:05:35 +02003030 return 0;
3031}
3032
Takashi Iwai527e4d72011-10-27 16:33:27 +02003033static inline unsigned int get_ctl_pos(unsigned int data)
3034{
3035 hda_nid_t nid = get_amp_nid_(data);
3036 unsigned int dir = get_amp_direction_(data);
3037 return (nid << 1) | dir;
3038}
3039
3040#define is_ctl_used(bits, data) \
3041 test_bit(get_ctl_pos(data), bits)
3042#define mark_ctl_usage(bits, data) \
3043 set_bit(get_ctl_pos(data), bits)
3044
Takashi Iwai343a04b2011-07-06 14:28:39 +02003045static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003046 const char *pfx, int cidx,
3047 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003048{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003049 struct alc_spec *spec = codec->spec;
3050 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003051 if (!nid)
3052 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003053 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3054 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3055 return 0;
3056 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003057 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003058 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003059}
3060
Takashi Iwai343a04b2011-07-06 14:28:39 +02003061#define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
3062 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai97aaab72011-07-06 14:02:55 +02003063
3064/* create a mute-switch for the given mixer widget;
3065 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3066 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003067static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003068 const char *pfx, int cidx,
3069 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003070{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003071 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003072 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003073 int type;
3074 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003075 if (!nid)
3076 return 0;
3077 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3078 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3079 type = ALC_CTL_WIDGET_MUTE;
3080 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3081 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003082 type = ALC_CTL_WIDGET_MUTE;
3083 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3084 } else {
3085 type = ALC_CTL_BIND_MUTE;
3086 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3087 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003088 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3089 return 0;
3090 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003091 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003092}
3093
Takashi Iwai343a04b2011-07-06 14:28:39 +02003094#define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
3095 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003096
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003097static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3098 hda_nid_t pin, hda_nid_t dac)
3099{
3100 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3101 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3102 return pin;
3103 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3104 return mix;
3105 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3106 return dac;
3107 return 0;
3108}
3109
3110static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3111 hda_nid_t pin, hda_nid_t dac)
3112{
3113 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3114 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3115 return dac;
3116 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3117 return mix;
3118 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3119 return pin;
3120 return 0;
3121}
3122
Takashi Iwai7085ec12009-10-02 09:03:58 +02003123/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003124static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003125 const struct auto_pin_cfg *cfg)
3126{
3127 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003128 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003129
Takashi Iwaice764ab2011-04-27 16:35:23 +02003130 noutputs = cfg->line_outs;
3131 if (spec->multi_ios > 0)
3132 noutputs += spec->multi_ios;
3133
3134 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003135 const char *name;
3136 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003137 hda_nid_t dac, pin;
3138 hda_nid_t sw, vol;
3139
3140 dac = spec->multiout.dac_nids[i];
3141 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003142 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003143 if (i >= cfg->line_outs)
3144 pin = spec->multi_io[i - 1].pin;
3145 else
3146 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003147
3148 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3149 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003150 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003151 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003152 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003153 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003154 if (err < 0)
3155 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003156 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003157 if (err < 0)
3158 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003159 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003160 if (err < 0)
3161 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003162 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003163 if (err < 0)
3164 return err;
3165 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003166 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003167 if (err < 0)
3168 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003169 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003170 if (err < 0)
3171 return err;
3172 }
3173 }
3174 return 0;
3175}
3176
Takashi Iwai343a04b2011-07-06 14:28:39 +02003177static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003178 hda_nid_t dac, const char *pfx,
3179 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003180{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003181 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003182 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003183 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003184
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003185 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003186 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003187 /* the corresponding DAC is already occupied */
3188 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3189 return 0; /* no way */
3190 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003191 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3192 if (is_ctl_used(spec->sw_ctls, val))
3193 return 0; /* already created */
3194 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003195 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003196 }
3197
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003198 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3199 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003200 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003201 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003202 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003203 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003204 if (err < 0)
3205 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003206 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003207}
3208
Takashi Iwai23c09b02011-08-19 09:05:35 +02003209static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3210 unsigned int nums,
3211 struct hda_ctl_ops *ops)
3212{
3213 struct alc_spec *spec = codec->spec;
3214 struct hda_bind_ctls **ctlp, *ctl;
3215 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3216 ctlp = snd_array_new(&spec->bind_ctls);
3217 if (!ctlp)
3218 return NULL;
3219 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3220 *ctlp = ctl;
3221 if (ctl)
3222 ctl->ops = ops;
3223 return ctl;
3224}
3225
3226/* add playback controls for speaker and HP outputs */
3227static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3228 const hda_nid_t *pins,
3229 const hda_nid_t *dacs,
3230 const char *pfx)
3231{
3232 struct alc_spec *spec = codec->spec;
3233 struct hda_bind_ctls *ctl;
3234 char name[32];
3235 int i, n, err;
3236
3237 if (!num_pins || !pins[0])
3238 return 0;
3239
Takashi Iwai527e4d72011-10-27 16:33:27 +02003240 if (num_pins == 1) {
3241 hda_nid_t dac = *dacs;
3242 if (!dac)
3243 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003244 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003245 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003246
3247 if (dacs[num_pins - 1]) {
3248 /* OK, we have a multi-output system with individual volumes */
3249 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003250 if (num_pins >= 3) {
3251 snprintf(name, sizeof(name), "%s %s",
3252 pfx, channel_name[i]);
3253 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3254 name, 0);
3255 } else {
3256 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3257 pfx, i);
3258 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003259 if (err < 0)
3260 return err;
3261 }
3262 return 0;
3263 }
3264
3265 /* Let's create a bind-controls */
3266 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3267 if (!ctl)
3268 return -ENOMEM;
3269 n = 0;
3270 for (i = 0; i < num_pins; i++) {
3271 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3272 ctl->values[n++] =
3273 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3274 }
3275 if (n) {
3276 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3277 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3278 if (err < 0)
3279 return err;
3280 }
3281
3282 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3283 if (!ctl)
3284 return -ENOMEM;
3285 n = 0;
3286 for (i = 0; i < num_pins; i++) {
3287 hda_nid_t vol;
3288 if (!pins[i] || !dacs[i])
3289 continue;
3290 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3291 if (vol)
3292 ctl->values[n++] =
3293 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3294 }
3295 if (n) {
3296 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3297 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3298 if (err < 0)
3299 return err;
3300 }
3301 return 0;
3302}
3303
Takashi Iwai343a04b2011-07-06 14:28:39 +02003304static int alc_auto_create_hp_out(struct hda_codec *codec)
3305{
3306 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003307 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3308 spec->autocfg.hp_pins,
3309 spec->multiout.hp_out_nid,
3310 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003311}
3312
3313static int alc_auto_create_speaker_out(struct hda_codec *codec)
3314{
3315 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003316 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3317 spec->autocfg.speaker_pins,
3318 spec->multiout.extra_out_nid,
3319 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003320}
3321
Takashi Iwai343a04b2011-07-06 14:28:39 +02003322static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003323 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003324 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003325{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003326 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003327 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003328 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003329
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003330 alc_set_pin_output(codec, pin, pin_type);
3331 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003332 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003333 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003334 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003335 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003336 mix = srcs[i];
3337 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003338 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003339 if (!mix)
3340 return;
3341
3342 /* need the manual connection? */
3343 if (num > 1)
3344 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3345 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003346 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3347 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003348 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003349 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003350 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003351 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003352 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003353 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3354 if (nid)
3355 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3356 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003357
3358 /* unmute DAC if it's not assigned to a mixer */
3359 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3360 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3361 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3362 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003363}
3364
Takashi Iwai343a04b2011-07-06 14:28:39 +02003365static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003366{
3367 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003368 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003369 int i;
3370
3371 for (i = 0; i <= HDA_SIDE; i++) {
3372 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3373 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003374 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003375 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003376 }
3377}
3378
Takashi Iwai343a04b2011-07-06 14:28:39 +02003379static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003380{
3381 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003382 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003383 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003384
David Henningsson636030e2011-10-12 19:26:03 +02003385 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003386 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3387 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003388 pin = spec->autocfg.hp_pins[i];
3389 if (!pin)
3390 break;
3391 dac = spec->multiout.hp_out_nid[i];
3392 if (!dac) {
3393 if (i > 0 && spec->multiout.hp_out_nid[0])
3394 dac = spec->multiout.hp_out_nid[0];
3395 else
3396 dac = spec->multiout.dac_nids[0];
3397 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003398 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3399 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003400 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003401 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3402 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003403 pin = spec->autocfg.speaker_pins[i];
3404 if (!pin)
3405 break;
3406 dac = spec->multiout.extra_out_nid[i];
3407 if (!dac) {
3408 if (i > 0 && spec->multiout.extra_out_nid[0])
3409 dac = spec->multiout.extra_out_nid[0];
3410 else
3411 dac = spec->multiout.dac_nids[0];
3412 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003413 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3414 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003415}
3416
Takashi Iwaice764ab2011-04-27 16:35:23 +02003417/*
3418 * multi-io helper
3419 */
3420static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3421 unsigned int location)
3422{
3423 struct alc_spec *spec = codec->spec;
3424 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003425 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwaice764ab2011-04-27 16:35:23 +02003426 int type, i, num_pins = 0;
3427
3428 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3429 for (i = 0; i < cfg->num_inputs; i++) {
3430 hda_nid_t nid = cfg->inputs[i].pin;
3431 hda_nid_t dac;
3432 unsigned int defcfg, caps;
3433 if (cfg->inputs[i].type != type)
3434 continue;
3435 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3436 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3437 continue;
3438 if (location && get_defcfg_location(defcfg) != location)
3439 continue;
3440 caps = snd_hda_query_pin_caps(codec, nid);
3441 if (!(caps & AC_PINCAP_OUT))
3442 continue;
3443 dac = alc_auto_look_for_dac(codec, nid);
3444 if (!dac)
3445 continue;
3446 spec->multi_io[num_pins].pin = nid;
3447 spec->multi_io[num_pins].dac = dac;
3448 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003449 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003450 }
3451 }
3452 spec->multiout.num_dacs = 1;
Takashi Iwaic2674682011-08-24 17:57:44 +02003453 if (num_pins < 2) {
3454 /* clear up again */
3455 memset(spec->private_dac_nids, 0,
3456 sizeof(spec->private_dac_nids));
3457 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003458 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003459 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003460 return num_pins;
3461}
3462
3463static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3464 struct snd_ctl_elem_info *uinfo)
3465{
3466 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3467 struct alc_spec *spec = codec->spec;
3468
3469 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3470 uinfo->count = 1;
3471 uinfo->value.enumerated.items = spec->multi_ios + 1;
3472 if (uinfo->value.enumerated.item > spec->multi_ios)
3473 uinfo->value.enumerated.item = spec->multi_ios;
3474 sprintf(uinfo->value.enumerated.name, "%dch",
3475 (uinfo->value.enumerated.item + 1) * 2);
3476 return 0;
3477}
3478
3479static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3480 struct snd_ctl_elem_value *ucontrol)
3481{
3482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3483 struct alc_spec *spec = codec->spec;
3484 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3485 return 0;
3486}
3487
3488static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3489{
3490 struct alc_spec *spec = codec->spec;
3491 hda_nid_t nid = spec->multi_io[idx].pin;
3492
3493 if (!spec->multi_io[idx].ctl_in)
3494 spec->multi_io[idx].ctl_in =
3495 snd_hda_codec_read(codec, nid, 0,
3496 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3497 if (output) {
3498 snd_hda_codec_update_cache(codec, nid, 0,
3499 AC_VERB_SET_PIN_WIDGET_CONTROL,
3500 PIN_OUT);
3501 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3502 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3503 HDA_AMP_MUTE, 0);
3504 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3505 } else {
3506 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3507 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3508 HDA_AMP_MUTE, HDA_AMP_MUTE);
3509 snd_hda_codec_update_cache(codec, nid, 0,
3510 AC_VERB_SET_PIN_WIDGET_CONTROL,
3511 spec->multi_io[idx].ctl_in);
3512 }
3513 return 0;
3514}
3515
3516static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3517 struct snd_ctl_elem_value *ucontrol)
3518{
3519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3520 struct alc_spec *spec = codec->spec;
3521 int i, ch;
3522
3523 ch = ucontrol->value.enumerated.item[0];
3524 if (ch < 0 || ch > spec->multi_ios)
3525 return -EINVAL;
3526 if (ch == (spec->ext_channel_count - 1) / 2)
3527 return 0;
3528 spec->ext_channel_count = (ch + 1) * 2;
3529 for (i = 0; i < spec->multi_ios; i++)
3530 alc_set_multi_io(codec, i, i < ch);
3531 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003532 if (spec->need_dac_fix && !spec->const_channel_count)
3533 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003534 return 1;
3535}
3536
Takashi Iwaia9111322011-05-02 11:30:18 +02003537static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003538 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3539 .name = "Channel Mode",
3540 .info = alc_auto_ch_mode_info,
3541 .get = alc_auto_ch_mode_get,
3542 .put = alc_auto_ch_mode_put,
3543};
3544
Takashi Iwai23c09b02011-08-19 09:05:35 +02003545static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003546{
3547 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003548
Takashi Iwaic2674682011-08-24 17:57:44 +02003549 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003550 struct snd_kcontrol_new *knew;
3551
3552 knew = alc_kcontrol_new(spec);
3553 if (!knew)
3554 return -ENOMEM;
3555 *knew = alc_auto_channel_mode_enum;
3556 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3557 if (!knew->name)
3558 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003559 }
3560 return 0;
3561}
3562
Takashi Iwai1d045db2011-07-07 18:23:21 +02003563/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3564 * active input pins
3565 */
3566static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3567{
3568 struct alc_spec *spec = codec->spec;
3569 const struct hda_input_mux *imux;
3570 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3571 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3572 int i, n, nums;
3573
3574 imux = spec->input_mux;
3575 if (!imux)
3576 return;
3577 if (spec->dyn_adc_switch)
3578 return;
3579
3580 nums = 0;
3581 for (n = 0; n < spec->num_adc_nids; n++) {
3582 hda_nid_t cap = spec->private_capsrc_nids[n];
3583 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3584 for (i = 0; i < imux->num_items; i++) {
3585 hda_nid_t pin = spec->imux_pins[i];
3586 if (pin) {
3587 if (get_connection_index(codec, cap, pin) < 0)
3588 break;
3589 } else if (num_conns <= imux->items[i].index)
3590 break;
3591 }
3592 if (i >= imux->num_items) {
3593 adc_nids[nums] = spec->private_adc_nids[n];
3594 capsrc_nids[nums++] = cap;
3595 }
3596 }
3597 if (!nums) {
3598 /* check whether ADC-switch is possible */
3599 if (!alc_check_dyn_adc_switch(codec)) {
3600 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3601 " using fallback 0x%x\n",
3602 codec->chip_name, spec->private_adc_nids[0]);
3603 spec->num_adc_nids = 1;
3604 spec->auto_mic = 0;
3605 return;
3606 }
3607 } else if (nums != spec->num_adc_nids) {
3608 memcpy(spec->private_adc_nids, adc_nids,
3609 nums * sizeof(hda_nid_t));
3610 memcpy(spec->private_capsrc_nids, capsrc_nids,
3611 nums * sizeof(hda_nid_t));
3612 spec->num_adc_nids = nums;
3613 }
3614
3615 if (spec->auto_mic)
3616 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3617 else if (spec->input_mux->num_items == 1)
3618 spec->num_adc_nids = 1; /* reduce to a single ADC */
3619}
3620
3621/*
3622 * initialize ADC paths
3623 */
3624static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3625{
3626 struct alc_spec *spec = codec->spec;
3627 hda_nid_t nid;
3628
3629 nid = spec->adc_nids[adc_idx];
3630 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003631 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003632 snd_hda_codec_write(codec, nid, 0,
3633 AC_VERB_SET_AMP_GAIN_MUTE,
3634 AMP_IN_MUTE(0));
3635 return;
3636 }
3637 if (!spec->capsrc_nids)
3638 return;
3639 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003640 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003641 snd_hda_codec_write(codec, nid, 0,
3642 AC_VERB_SET_AMP_GAIN_MUTE,
3643 AMP_OUT_MUTE);
3644}
3645
3646static void alc_auto_init_input_src(struct hda_codec *codec)
3647{
3648 struct alc_spec *spec = codec->spec;
3649 int c, nums;
3650
3651 for (c = 0; c < spec->num_adc_nids; c++)
3652 alc_auto_init_adc(codec, c);
3653 if (spec->dyn_adc_switch)
3654 nums = 1;
3655 else
3656 nums = spec->num_adc_nids;
3657 for (c = 0; c < nums; c++)
3658 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3659}
3660
3661/* add mic boosts if needed */
3662static int alc_auto_add_mic_boost(struct hda_codec *codec)
3663{
3664 struct alc_spec *spec = codec->spec;
3665 struct auto_pin_cfg *cfg = &spec->autocfg;
3666 int i, err;
3667 int type_idx = 0;
3668 hda_nid_t nid;
3669 const char *prev_label = NULL;
3670
3671 for (i = 0; i < cfg->num_inputs; i++) {
3672 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3673 break;
3674 nid = cfg->inputs[i].pin;
3675 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3676 const char *label;
3677 char boost_label[32];
3678
3679 label = hda_get_autocfg_input_label(codec, cfg, i);
3680 if (prev_label && !strcmp(label, prev_label))
3681 type_idx++;
3682 else
3683 type_idx = 0;
3684 prev_label = label;
3685
3686 snprintf(boost_label, sizeof(boost_label),
3687 "%s Boost Volume", label);
3688 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3689 boost_label, type_idx,
3690 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3691 if (err < 0)
3692 return err;
3693 }
3694 }
3695 return 0;
3696}
3697
3698/* select or unmute the given capsrc route */
3699static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3700 int idx)
3701{
3702 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3703 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3704 HDA_AMP_MUTE, 0);
3705 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3706 snd_hda_codec_write_cache(codec, cap, 0,
3707 AC_VERB_SET_CONNECT_SEL, idx);
3708 }
3709}
3710
3711/* set the default connection to that pin */
3712static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3713{
3714 struct alc_spec *spec = codec->spec;
3715 int i;
3716
3717 if (!pin)
3718 return 0;
3719 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01003720 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003721 int idx;
3722
3723 idx = get_connection_index(codec, cap, pin);
3724 if (idx < 0)
3725 continue;
3726 select_or_unmute_capsrc(codec, cap, idx);
3727 return i; /* return the found index */
3728 }
3729 return -1; /* not found */
3730}
3731
3732/* initialize some special cases for input sources */
3733static void alc_init_special_input_src(struct hda_codec *codec)
3734{
3735 struct alc_spec *spec = codec->spec;
3736 int i;
3737
3738 for (i = 0; i < spec->autocfg.num_inputs; i++)
3739 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3740}
3741
3742/* assign appropriate capture mixers */
3743static void set_capture_mixer(struct hda_codec *codec)
3744{
3745 struct alc_spec *spec = codec->spec;
3746 static const struct snd_kcontrol_new *caps[2][3] = {
3747 { alc_capture_mixer_nosrc1,
3748 alc_capture_mixer_nosrc2,
3749 alc_capture_mixer_nosrc3 },
3750 { alc_capture_mixer1,
3751 alc_capture_mixer2,
3752 alc_capture_mixer3 },
3753 };
3754
3755 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003756 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003757 if (!spec->capsrc_nids)
3758 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003759 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003760 return; /* no volume in capsrc, too */
3761 spec->vol_in_capsrc = 1;
3762 }
3763
3764 if (spec->num_adc_nids > 0) {
3765 int mux = 0;
3766 int num_adcs = 0;
3767
3768 if (spec->input_mux && spec->input_mux->num_items > 1)
3769 mux = 1;
3770 if (spec->auto_mic) {
3771 num_adcs = 1;
3772 mux = 0;
3773 } else if (spec->dyn_adc_switch)
3774 num_adcs = 1;
3775 if (!num_adcs) {
3776 if (spec->num_adc_nids > 3)
3777 spec->num_adc_nids = 3;
3778 else if (!spec->num_adc_nids)
3779 return;
3780 num_adcs = spec->num_adc_nids;
3781 }
3782 spec->cap_mixer = caps[mux][num_adcs - 1];
3783 }
3784}
3785
3786/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003787 * standard auto-parser initializations
3788 */
3789static void alc_auto_init_std(struct hda_codec *codec)
3790{
3791 struct alc_spec *spec = codec->spec;
3792 alc_auto_init_multi_out(codec);
3793 alc_auto_init_extra_out(codec);
3794 alc_auto_init_analog_input(codec);
3795 alc_auto_init_input_src(codec);
3796 alc_auto_init_digital(codec);
3797 if (spec->unsol_event)
3798 alc_inithook(codec);
3799}
3800
3801/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003802 * Digital-beep handlers
3803 */
3804#ifdef CONFIG_SND_HDA_INPUT_BEEP
3805#define set_beep_amp(spec, nid, idx, dir) \
3806 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3807
3808static const struct snd_pci_quirk beep_white_list[] = {
3809 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3810 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3811 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3812 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3813 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3814 {}
3815};
3816
3817static inline int has_cdefine_beep(struct hda_codec *codec)
3818{
3819 struct alc_spec *spec = codec->spec;
3820 const struct snd_pci_quirk *q;
3821 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3822 if (q)
3823 return q->value;
3824 return spec->cdefine.enable_pcbeep;
3825}
3826#else
3827#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3828#define has_cdefine_beep(codec) 0
3829#endif
3830
3831/* parse the BIOS configuration and set up the alc_spec */
3832/* return 1 if successful, 0 if the proper config is not found,
3833 * or a negative error code
3834 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003835static int alc_parse_auto_config(struct hda_codec *codec,
3836 const hda_nid_t *ignore_nids,
3837 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003838{
3839 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003840 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003841 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003842
Takashi Iwai53c334a2011-08-23 18:27:14 +02003843 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3844 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003845 if (err < 0)
3846 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003847 if (!cfg->line_outs) {
3848 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003849 spec->multiout.max_channels = 2;
3850 spec->no_analog = 1;
3851 goto dig_only;
3852 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003853 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003854 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003855
Takashi Iwai06503672011-10-06 08:27:19 +02003856 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3857 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003858 /* use HP as primary out */
3859 cfg->speaker_outs = cfg->line_outs;
3860 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3861 sizeof(cfg->speaker_pins));
3862 cfg->line_outs = cfg->hp_outs;
3863 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3864 cfg->hp_outs = 0;
3865 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3866 cfg->line_out_type = AUTO_PIN_HP_OUT;
3867 }
3868
Takashi Iwai1d045db2011-07-07 18:23:21 +02003869 err = alc_auto_fill_dac_nids(codec);
3870 if (err < 0)
3871 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003872 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003873 if (err < 0)
3874 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003875 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003876 if (err < 0)
3877 return err;
3878 err = alc_auto_create_hp_out(codec);
3879 if (err < 0)
3880 return err;
3881 err = alc_auto_create_speaker_out(codec);
3882 if (err < 0)
3883 return err;
3884 err = alc_auto_create_input_ctls(codec);
3885 if (err < 0)
3886 return err;
3887
3888 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3889
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003890 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02003891 alc_auto_parse_digital(codec);
3892
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003893 if (!spec->no_analog)
3894 alc_remove_invalid_adc_nids(codec);
3895
3896 if (ssid_nids)
3897 alc_ssid_check(codec, ssid_nids);
3898
3899 if (!spec->no_analog) {
3900 alc_auto_check_switches(codec);
3901 err = alc_auto_add_mic_boost(codec);
3902 if (err < 0)
3903 return err;
3904 }
3905
Takashi Iwai1d045db2011-07-07 18:23:21 +02003906 if (spec->kctls.list)
3907 add_mixer(spec, spec->kctls.list);
3908
Takashi Iwai1d045db2011-07-07 18:23:21 +02003909 return 1;
3910}
3911
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003912static int alc880_parse_auto_config(struct hda_codec *codec)
3913{
3914 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3915 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3916 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3917}
3918
Takashi Iwai1d045db2011-07-07 18:23:21 +02003919#ifdef CONFIG_SND_HDA_POWER_SAVE
3920static const struct hda_amp_list alc880_loopbacks[] = {
3921 { 0x0b, HDA_INPUT, 0 },
3922 { 0x0b, HDA_INPUT, 1 },
3923 { 0x0b, HDA_INPUT, 2 },
3924 { 0x0b, HDA_INPUT, 3 },
3925 { 0x0b, HDA_INPUT, 4 },
3926 { } /* end */
3927};
3928#endif
3929
3930/*
3931 * board setups
3932 */
3933#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3934#define alc_board_config \
3935 snd_hda_check_board_config
3936#define alc_board_codec_sid_config \
3937 snd_hda_check_board_codec_sid_config
3938#include "alc_quirks.c"
3939#else
3940#define alc_board_config(codec, nums, models, tbl) -1
3941#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3942#define setup_preset(codec, x) /* NOP */
3943#endif
3944
3945/*
3946 * OK, here we have finally the patch for ALC880
3947 */
3948#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3949#include "alc880_quirks.c"
3950#endif
3951
3952static int patch_alc880(struct hda_codec *codec)
3953{
3954 struct alc_spec *spec;
3955 int board_config;
3956 int err;
3957
3958 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3959 if (spec == NULL)
3960 return -ENOMEM;
3961
3962 codec->spec = spec;
3963
3964 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003965 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003966
3967 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3968 alc880_models, alc880_cfg_tbl);
3969 if (board_config < 0) {
3970 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3971 codec->chip_name);
3972 board_config = ALC_MODEL_AUTO;
3973 }
3974
3975 if (board_config == ALC_MODEL_AUTO) {
3976 /* automatic parse from the BIOS config */
3977 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02003978 if (err < 0)
3979 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003980#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3981 else if (!err) {
3982 printk(KERN_INFO
3983 "hda_codec: Cannot set up configuration "
3984 "from BIOS. Using 3-stack mode...\n");
3985 board_config = ALC880_3ST;
3986 }
3987#endif
3988 }
3989
Takashi Iwai1d045db2011-07-07 18:23:21 +02003990 if (board_config != ALC_MODEL_AUTO)
3991 setup_preset(codec, &alc880_presets[board_config]);
3992
Takashi Iwai60a6a842011-07-27 14:01:24 +02003993 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003994 alc_auto_fill_adc_caps(codec);
3995 alc_rebuild_imux_for_auto_mic(codec);
3996 alc_remove_invalid_adc_nids(codec);
3997 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003998
3999 if (!spec->no_analog && !spec->cap_mixer)
4000 set_capture_mixer(codec);
4001
4002 if (!spec->no_analog) {
4003 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004004 if (err < 0)
4005 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004006 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4007 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004008
4009 spec->vmaster_nid = 0x0c;
4010
4011 codec->patch_ops = alc_patch_ops;
4012 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004013 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004014#ifdef CONFIG_SND_HDA_POWER_SAVE
4015 if (!spec->loopback.amplist)
4016 spec->loopback.amplist = alc880_loopbacks;
4017#endif
4018
4019 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004020
4021 error:
4022 alc_free(codec);
4023 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004024}
4025
4026
4027/*
4028 * ALC260 support
4029 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004030static int alc260_parse_auto_config(struct hda_codec *codec)
4031{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004032 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004033 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4034 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004035}
4036
Takashi Iwai1d045db2011-07-07 18:23:21 +02004037#ifdef CONFIG_SND_HDA_POWER_SAVE
4038static const struct hda_amp_list alc260_loopbacks[] = {
4039 { 0x07, HDA_INPUT, 0 },
4040 { 0x07, HDA_INPUT, 1 },
4041 { 0x07, HDA_INPUT, 2 },
4042 { 0x07, HDA_INPUT, 3 },
4043 { 0x07, HDA_INPUT, 4 },
4044 { } /* end */
4045};
4046#endif
4047
4048/*
4049 * Pin config fixes
4050 */
4051enum {
4052 PINFIX_HP_DC5750,
4053};
4054
4055static const struct alc_fixup alc260_fixups[] = {
4056 [PINFIX_HP_DC5750] = {
4057 .type = ALC_FIXUP_PINS,
4058 .v.pins = (const struct alc_pincfg[]) {
4059 { 0x11, 0x90130110 }, /* speaker */
4060 { }
4061 }
4062 },
4063};
4064
4065static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4066 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4067 {}
4068};
4069
4070/*
4071 */
4072#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4073#include "alc260_quirks.c"
4074#endif
4075
4076static int patch_alc260(struct hda_codec *codec)
4077{
4078 struct alc_spec *spec;
4079 int err, board_config;
4080
4081 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4082 if (spec == NULL)
4083 return -ENOMEM;
4084
4085 codec->spec = spec;
4086
4087 spec->mixer_nid = 0x07;
4088
4089 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4090 alc260_models, alc260_cfg_tbl);
4091 if (board_config < 0) {
4092 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4093 codec->chip_name);
4094 board_config = ALC_MODEL_AUTO;
4095 }
4096
4097 if (board_config == ALC_MODEL_AUTO) {
4098 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4099 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4100 }
4101
4102 if (board_config == ALC_MODEL_AUTO) {
4103 /* automatic parse from the BIOS config */
4104 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004105 if (err < 0)
4106 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004107#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4108 else if (!err) {
4109 printk(KERN_INFO
4110 "hda_codec: Cannot set up configuration "
4111 "from BIOS. Using base mode...\n");
4112 board_config = ALC260_BASIC;
4113 }
4114#endif
4115 }
4116
Takashi Iwai1d045db2011-07-07 18:23:21 +02004117 if (board_config != ALC_MODEL_AUTO)
4118 setup_preset(codec, &alc260_presets[board_config]);
4119
Takashi Iwai60a6a842011-07-27 14:01:24 +02004120 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004121 alc_auto_fill_adc_caps(codec);
4122 alc_rebuild_imux_for_auto_mic(codec);
4123 alc_remove_invalid_adc_nids(codec);
4124 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004125
4126 if (!spec->no_analog && !spec->cap_mixer)
4127 set_capture_mixer(codec);
4128
4129 if (!spec->no_analog) {
4130 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004131 if (err < 0)
4132 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004133 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4134 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004135
4136 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4137
4138 spec->vmaster_nid = 0x08;
4139
4140 codec->patch_ops = alc_patch_ops;
4141 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004142 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004143 spec->shutup = alc_eapd_shutup;
4144#ifdef CONFIG_SND_HDA_POWER_SAVE
4145 if (!spec->loopback.amplist)
4146 spec->loopback.amplist = alc260_loopbacks;
4147#endif
4148
4149 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004150
4151 error:
4152 alc_free(codec);
4153 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004154}
4155
4156
4157/*
4158 * ALC882/883/885/888/889 support
4159 *
4160 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4161 * configuration. Each pin widget can choose any input DACs and a mixer.
4162 * Each ADC is connected from a mixer of all inputs. This makes possible
4163 * 6-channel independent captures.
4164 *
4165 * In addition, an independent DAC for the multi-playback (not used in this
4166 * driver yet).
4167 */
4168#ifdef CONFIG_SND_HDA_POWER_SAVE
4169#define alc882_loopbacks alc880_loopbacks
4170#endif
4171
4172/*
4173 * Pin config fixes
4174 */
4175enum {
4176 PINFIX_ABIT_AW9D_MAX,
4177 PINFIX_LENOVO_Y530,
4178 PINFIX_PB_M5210,
4179 PINFIX_ACER_ASPIRE_7736,
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004180 PINFIX_ASUS_W90V,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004181};
4182
4183static const struct alc_fixup alc882_fixups[] = {
4184 [PINFIX_ABIT_AW9D_MAX] = {
4185 .type = ALC_FIXUP_PINS,
4186 .v.pins = (const struct alc_pincfg[]) {
4187 { 0x15, 0x01080104 }, /* side */
4188 { 0x16, 0x01011012 }, /* rear */
4189 { 0x17, 0x01016011 }, /* clfe */
4190 { }
4191 }
4192 },
4193 [PINFIX_LENOVO_Y530] = {
4194 .type = ALC_FIXUP_PINS,
4195 .v.pins = (const struct alc_pincfg[]) {
4196 { 0x15, 0x99130112 }, /* rear int speakers */
4197 { 0x16, 0x99130111 }, /* subwoofer */
4198 { }
4199 }
4200 },
4201 [PINFIX_PB_M5210] = {
4202 .type = ALC_FIXUP_VERBS,
4203 .v.verbs = (const struct hda_verb[]) {
4204 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4205 {}
4206 }
4207 },
4208 [PINFIX_ACER_ASPIRE_7736] = {
4209 .type = ALC_FIXUP_SKU,
4210 .v.sku = ALC_FIXUP_SKU_IGNORE,
4211 },
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004212 [PINFIX_ASUS_W90V] = {
4213 .type = ALC_FIXUP_PINS,
4214 .v.pins = (const struct alc_pincfg[]) {
4215 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4216 { }
4217 }
4218 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004219};
4220
4221static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4222 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004223 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004224 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4225 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4226 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4227 {}
4228};
4229
4230/*
4231 * BIOS auto configuration
4232 */
4233/* almost identical with ALC880 parser... */
4234static int alc882_parse_auto_config(struct hda_codec *codec)
4235{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004236 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004237 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4238 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004239}
4240
Takashi Iwai1d045db2011-07-07 18:23:21 +02004241/*
4242 */
4243#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4244#include "alc882_quirks.c"
4245#endif
4246
4247static int patch_alc882(struct hda_codec *codec)
4248{
4249 struct alc_spec *spec;
4250 int err, board_config;
4251
4252 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4253 if (spec == NULL)
4254 return -ENOMEM;
4255
4256 codec->spec = spec;
4257
4258 spec->mixer_nid = 0x0b;
4259
4260 switch (codec->vendor_id) {
4261 case 0x10ec0882:
4262 case 0x10ec0885:
4263 break;
4264 default:
4265 /* ALC883 and variants */
4266 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4267 break;
4268 }
4269
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004270 err = alc_codec_rename_from_preset(codec);
4271 if (err < 0)
4272 goto error;
4273
Takashi Iwai1d045db2011-07-07 18:23:21 +02004274 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4275 alc882_models, alc882_cfg_tbl);
4276
4277 if (board_config < 0)
4278 board_config = alc_board_codec_sid_config(codec,
4279 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4280
4281 if (board_config < 0) {
4282 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4283 codec->chip_name);
4284 board_config = ALC_MODEL_AUTO;
4285 }
4286
4287 if (board_config == ALC_MODEL_AUTO) {
4288 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4289 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4290 }
4291
4292 alc_auto_parse_customize_define(codec);
4293
4294 if (board_config == ALC_MODEL_AUTO) {
4295 /* automatic parse from the BIOS config */
4296 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004297 if (err < 0)
4298 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004299#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4300 else if (!err) {
4301 printk(KERN_INFO
4302 "hda_codec: Cannot set up configuration "
4303 "from BIOS. Using base mode...\n");
4304 board_config = ALC882_3ST_DIG;
4305 }
4306#endif
4307 }
4308
Takashi Iwai1d045db2011-07-07 18:23:21 +02004309 if (board_config != ALC_MODEL_AUTO)
4310 setup_preset(codec, &alc882_presets[board_config]);
4311
Takashi Iwai60a6a842011-07-27 14:01:24 +02004312 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004313 alc_auto_fill_adc_caps(codec);
4314 alc_rebuild_imux_for_auto_mic(codec);
4315 alc_remove_invalid_adc_nids(codec);
4316 }
4317
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004318 if (!spec->no_analog && !spec->cap_mixer)
4319 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004320
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004321 if (!spec->no_analog && has_cdefine_beep(codec)) {
4322 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004323 if (err < 0)
4324 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004325 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004326 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004327
4328 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4329
4330 spec->vmaster_nid = 0x0c;
4331
4332 codec->patch_ops = alc_patch_ops;
4333 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004334 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004335
4336 alc_init_jacks(codec);
4337#ifdef CONFIG_SND_HDA_POWER_SAVE
4338 if (!spec->loopback.amplist)
4339 spec->loopback.amplist = alc882_loopbacks;
4340#endif
4341
4342 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004343
4344 error:
4345 alc_free(codec);
4346 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004347}
4348
4349
4350/*
4351 * ALC262 support
4352 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004353static int alc262_parse_auto_config(struct hda_codec *codec)
4354{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004355 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004356 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4357 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004358}
4359
4360/*
4361 * Pin config fixes
4362 */
4363enum {
4364 PINFIX_FSC_H270,
4365 PINFIX_HP_Z200,
4366};
4367
4368static const struct alc_fixup alc262_fixups[] = {
4369 [PINFIX_FSC_H270] = {
4370 .type = ALC_FIXUP_PINS,
4371 .v.pins = (const struct alc_pincfg[]) {
4372 { 0x14, 0x99130110 }, /* speaker */
4373 { 0x15, 0x0221142f }, /* front HP */
4374 { 0x1b, 0x0121141f }, /* rear HP */
4375 { }
4376 }
4377 },
4378 [PINFIX_HP_Z200] = {
4379 .type = ALC_FIXUP_PINS,
4380 .v.pins = (const struct alc_pincfg[]) {
4381 { 0x16, 0x99130120 }, /* internal speaker */
4382 { }
4383 }
4384 },
4385};
4386
4387static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4388 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4389 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4390 {}
4391};
4392
4393
4394#ifdef CONFIG_SND_HDA_POWER_SAVE
4395#define alc262_loopbacks alc880_loopbacks
4396#endif
4397
Takashi Iwai1d045db2011-07-07 18:23:21 +02004398/*
4399 */
4400#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4401#include "alc262_quirks.c"
4402#endif
4403
4404static int patch_alc262(struct hda_codec *codec)
4405{
4406 struct alc_spec *spec;
4407 int board_config;
4408 int err;
4409
4410 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4411 if (spec == NULL)
4412 return -ENOMEM;
4413
4414 codec->spec = spec;
4415
4416 spec->mixer_nid = 0x0b;
4417
4418#if 0
4419 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4420 * under-run
4421 */
4422 {
4423 int tmp;
4424 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4425 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4426 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4427 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4428 }
4429#endif
4430 alc_auto_parse_customize_define(codec);
4431
4432 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4433
4434 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4435 alc262_models, alc262_cfg_tbl);
4436
4437 if (board_config < 0) {
4438 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4439 codec->chip_name);
4440 board_config = ALC_MODEL_AUTO;
4441 }
4442
4443 if (board_config == ALC_MODEL_AUTO) {
4444 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4445 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4446 }
4447
4448 if (board_config == ALC_MODEL_AUTO) {
4449 /* automatic parse from the BIOS config */
4450 err = alc262_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004451 if (err < 0)
4452 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004453#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4454 else if (!err) {
4455 printk(KERN_INFO
4456 "hda_codec: Cannot set up configuration "
4457 "from BIOS. Using base mode...\n");
4458 board_config = ALC262_BASIC;
4459 }
4460#endif
4461 }
4462
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004463 if (board_config != ALC_MODEL_AUTO)
4464 setup_preset(codec, &alc262_presets[board_config]);
4465
Takashi Iwai60a6a842011-07-27 14:01:24 +02004466 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004467 alc_auto_fill_adc_caps(codec);
4468 alc_rebuild_imux_for_auto_mic(codec);
4469 alc_remove_invalid_adc_nids(codec);
4470 }
4471
4472 if (!spec->no_analog && !spec->cap_mixer)
4473 set_capture_mixer(codec);
4474
Takashi Iwai1d045db2011-07-07 18:23:21 +02004475 if (!spec->no_analog && has_cdefine_beep(codec)) {
4476 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004477 if (err < 0)
4478 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004479 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004480 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004481
4482 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4483
4484 spec->vmaster_nid = 0x0c;
4485
4486 codec->patch_ops = alc_patch_ops;
4487 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004488 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004489 spec->shutup = alc_eapd_shutup;
4490
4491 alc_init_jacks(codec);
4492#ifdef CONFIG_SND_HDA_POWER_SAVE
4493 if (!spec->loopback.amplist)
4494 spec->loopback.amplist = alc262_loopbacks;
4495#endif
4496
4497 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004498
4499 error:
4500 alc_free(codec);
4501 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004502}
4503
4504/*
4505 * ALC268
4506 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004507/* bind Beep switches of both NID 0x0f and 0x10 */
4508static const struct hda_bind_ctls alc268_bind_beep_sw = {
4509 .ops = &snd_hda_bind_sw,
4510 .values = {
4511 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4512 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4513 0
4514 },
4515};
4516
4517static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4518 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4519 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4520 { }
4521};
4522
4523/* set PCBEEP vol = 0, mute connections */
4524static const struct hda_verb alc268_beep_init_verbs[] = {
4525 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4526 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4527 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4528 { }
4529};
4530
4531/*
4532 * BIOS auto configuration
4533 */
4534static int alc268_parse_auto_config(struct hda_codec *codec)
4535{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004536 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004537 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004538 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4539 if (err > 0) {
4540 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4541 add_mixer(spec, alc268_beep_mixer);
4542 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004543 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004544 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004545 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004546}
4547
Takashi Iwai1d045db2011-07-07 18:23:21 +02004548/*
4549 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004550static int patch_alc268(struct hda_codec *codec)
4551{
4552 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004553 int i, has_beep, err;
4554
4555 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4556 if (spec == NULL)
4557 return -ENOMEM;
4558
4559 codec->spec = spec;
4560
4561 /* ALC268 has no aa-loopback mixer */
4562
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004563 /* automatic parse from the BIOS config */
4564 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004565 if (err < 0)
4566 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004567
Takashi Iwai1d045db2011-07-07 18:23:21 +02004568 has_beep = 0;
4569 for (i = 0; i < spec->num_mixers; i++) {
4570 if (spec->mixers[i] == alc268_beep_mixer) {
4571 has_beep = 1;
4572 break;
4573 }
4574 }
4575
4576 if (has_beep) {
4577 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004578 if (err < 0)
4579 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004580 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4581 /* override the amp caps for beep generator */
4582 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4583 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4584 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4585 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4586 (0 << AC_AMPCAP_MUTE_SHIFT));
4587 }
4588
Takashi Iwai60a6a842011-07-27 14:01:24 +02004589 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004590 alc_auto_fill_adc_caps(codec);
4591 alc_rebuild_imux_for_auto_mic(codec);
4592 alc_remove_invalid_adc_nids(codec);
4593 }
4594
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004595 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004596 set_capture_mixer(codec);
4597
4598 spec->vmaster_nid = 0x02;
4599
4600 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004601 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004602 spec->shutup = alc_eapd_shutup;
4603
4604 alc_init_jacks(codec);
4605
4606 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004607
4608 error:
4609 alc_free(codec);
4610 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004611}
4612
4613/*
4614 * ALC269
4615 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004616#ifdef CONFIG_SND_HDA_POWER_SAVE
4617#define alc269_loopbacks alc880_loopbacks
4618#endif
4619
4620static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4621 .substreams = 1,
4622 .channels_min = 2,
4623 .channels_max = 8,
4624 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4625 /* NID is set in alc_build_pcms */
4626 .ops = {
4627 .open = alc_playback_pcm_open,
4628 .prepare = alc_playback_pcm_prepare,
4629 .cleanup = alc_playback_pcm_cleanup
4630 },
4631};
4632
4633static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4634 .substreams = 1,
4635 .channels_min = 2,
4636 .channels_max = 2,
4637 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4638 /* NID is set in alc_build_pcms */
4639};
4640
4641#ifdef CONFIG_SND_HDA_POWER_SAVE
4642static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4643{
4644 switch (codec->subsystem_id) {
4645 case 0x103c1586:
4646 return 1;
4647 }
4648 return 0;
4649}
4650
4651static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4652{
4653 /* update mute-LED according to the speaker mute state */
4654 if (nid == 0x01 || nid == 0x14) {
4655 int pinval;
4656 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4657 HDA_AMP_MUTE)
4658 pinval = 0x24;
4659 else
4660 pinval = 0x20;
4661 /* mic2 vref pin is used for mute LED control */
4662 snd_hda_codec_update_cache(codec, 0x19, 0,
4663 AC_VERB_SET_PIN_WIDGET_CONTROL,
4664 pinval);
4665 }
4666 return alc_check_power_status(codec, nid);
4667}
4668#endif /* CONFIG_SND_HDA_POWER_SAVE */
4669
4670/* different alc269-variants */
4671enum {
4672 ALC269_TYPE_ALC269VA,
4673 ALC269_TYPE_ALC269VB,
4674 ALC269_TYPE_ALC269VC,
4675};
4676
4677/*
4678 * BIOS auto configuration
4679 */
4680static int alc269_parse_auto_config(struct hda_codec *codec)
4681{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004682 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004683 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4684 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4685 struct alc_spec *spec = codec->spec;
4686 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4687 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004688
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004689 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004690}
4691
Takashi Iwai1d045db2011-07-07 18:23:21 +02004692static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4693{
4694 int val = alc_read_coef_idx(codec, 0x04);
4695 if (power_up)
4696 val |= 1 << 11;
4697 else
4698 val &= ~(1 << 11);
4699 alc_write_coef_idx(codec, 0x04, val);
4700}
4701
4702static void alc269_shutup(struct hda_codec *codec)
4703{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004704 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004705 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004706 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004707 alc269_toggle_power_output(codec, 0);
4708 msleep(150);
4709 }
4710}
4711
Takashi Iwai2a439522011-07-26 09:52:50 +02004712#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02004713static int alc269_resume(struct hda_codec *codec)
4714{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004715 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004716 alc269_toggle_power_output(codec, 0);
4717 msleep(150);
4718 }
4719
4720 codec->patch_ops.init(codec);
4721
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004722 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004723 alc269_toggle_power_output(codec, 1);
4724 msleep(200);
4725 }
4726
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004727 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004728 alc269_toggle_power_output(codec, 1);
4729
4730 snd_hda_codec_resume_amp(codec);
4731 snd_hda_codec_resume_cache(codec);
4732 hda_call_check_power_status(codec, 0x01);
4733 return 0;
4734}
Takashi Iwai2a439522011-07-26 09:52:50 +02004735#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004736
4737static void alc269_fixup_hweq(struct hda_codec *codec,
4738 const struct alc_fixup *fix, int action)
4739{
4740 int coef;
4741
4742 if (action != ALC_FIXUP_ACT_INIT)
4743 return;
4744 coef = alc_read_coef_idx(codec, 0x1e);
4745 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4746}
4747
4748static void alc271_fixup_dmic(struct hda_codec *codec,
4749 const struct alc_fixup *fix, int action)
4750{
4751 static const struct hda_verb verbs[] = {
4752 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4753 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4754 {}
4755 };
4756 unsigned int cfg;
4757
4758 if (strcmp(codec->chip_name, "ALC271X"))
4759 return;
4760 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4761 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4762 snd_hda_sequence_write(codec, verbs);
4763}
4764
Takashi Iwai017f2a12011-07-09 14:42:25 +02004765static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4766 const struct alc_fixup *fix, int action)
4767{
4768 struct alc_spec *spec = codec->spec;
4769
4770 if (action != ALC_FIXUP_ACT_PROBE)
4771 return;
4772
4773 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4774 * fix the sample rate of analog I/O to 44.1kHz
4775 */
4776 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4777 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4778}
4779
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004780static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4781 const struct alc_fixup *fix, int action)
4782{
4783 int coef;
4784
4785 if (action != ALC_FIXUP_ACT_INIT)
4786 return;
4787 /* The digital-mic unit sends PDM (differential signal) instead of
4788 * the standard PCM, thus you can't record a valid mono stream as is.
4789 * Below is a workaround specific to ALC269 to control the dmic
4790 * signal source as mono.
4791 */
4792 coef = alc_read_coef_idx(codec, 0x07);
4793 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4794}
4795
Takashi Iwai24519912011-08-16 15:08:49 +02004796static void alc269_quanta_automute(struct hda_codec *codec)
4797{
David Henningsson42cf0d02011-09-20 12:04:56 +02004798 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02004799
4800 snd_hda_codec_write(codec, 0x20, 0,
4801 AC_VERB_SET_COEF_INDEX, 0x0c);
4802 snd_hda_codec_write(codec, 0x20, 0,
4803 AC_VERB_SET_PROC_COEF, 0x680);
4804
4805 snd_hda_codec_write(codec, 0x20, 0,
4806 AC_VERB_SET_COEF_INDEX, 0x0c);
4807 snd_hda_codec_write(codec, 0x20, 0,
4808 AC_VERB_SET_PROC_COEF, 0x480);
4809}
4810
4811static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4812 const struct alc_fixup *fix, int action)
4813{
4814 struct alc_spec *spec = codec->spec;
4815 if (action != ALC_FIXUP_ACT_PROBE)
4816 return;
4817 spec->automute_hook = alc269_quanta_automute;
4818}
4819
Takashi Iwai1d045db2011-07-07 18:23:21 +02004820enum {
4821 ALC269_FIXUP_SONY_VAIO,
4822 ALC275_FIXUP_SONY_VAIO_GPIO2,
4823 ALC269_FIXUP_DELL_M101Z,
4824 ALC269_FIXUP_SKU_IGNORE,
4825 ALC269_FIXUP_ASUS_G73JW,
4826 ALC269_FIXUP_LENOVO_EAPD,
4827 ALC275_FIXUP_SONY_HWEQ,
4828 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02004829 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004830 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02004831 ALC269_FIXUP_QUANTA_MUTE,
4832 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02004833 ALC269_FIXUP_AMIC,
4834 ALC269_FIXUP_DMIC,
4835 ALC269VB_FIXUP_AMIC,
4836 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004837};
4838
4839static const struct alc_fixup alc269_fixups[] = {
4840 [ALC269_FIXUP_SONY_VAIO] = {
4841 .type = ALC_FIXUP_VERBS,
4842 .v.verbs = (const struct hda_verb[]) {
4843 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4844 {}
4845 }
4846 },
4847 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4848 .type = ALC_FIXUP_VERBS,
4849 .v.verbs = (const struct hda_verb[]) {
4850 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4851 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4852 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4853 { }
4854 },
4855 .chained = true,
4856 .chain_id = ALC269_FIXUP_SONY_VAIO
4857 },
4858 [ALC269_FIXUP_DELL_M101Z] = {
4859 .type = ALC_FIXUP_VERBS,
4860 .v.verbs = (const struct hda_verb[]) {
4861 /* Enables internal speaker */
4862 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4863 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4864 {}
4865 }
4866 },
4867 [ALC269_FIXUP_SKU_IGNORE] = {
4868 .type = ALC_FIXUP_SKU,
4869 .v.sku = ALC_FIXUP_SKU_IGNORE,
4870 },
4871 [ALC269_FIXUP_ASUS_G73JW] = {
4872 .type = ALC_FIXUP_PINS,
4873 .v.pins = (const struct alc_pincfg[]) {
4874 { 0x17, 0x99130111 }, /* subwoofer */
4875 { }
4876 }
4877 },
4878 [ALC269_FIXUP_LENOVO_EAPD] = {
4879 .type = ALC_FIXUP_VERBS,
4880 .v.verbs = (const struct hda_verb[]) {
4881 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4882 {}
4883 }
4884 },
4885 [ALC275_FIXUP_SONY_HWEQ] = {
4886 .type = ALC_FIXUP_FUNC,
4887 .v.func = alc269_fixup_hweq,
4888 .chained = true,
4889 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4890 },
4891 [ALC271_FIXUP_DMIC] = {
4892 .type = ALC_FIXUP_FUNC,
4893 .v.func = alc271_fixup_dmic,
4894 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02004895 [ALC269_FIXUP_PCM_44K] = {
4896 .type = ALC_FIXUP_FUNC,
4897 .v.func = alc269_fixup_pcm_44k,
4898 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004899 [ALC269_FIXUP_STEREO_DMIC] = {
4900 .type = ALC_FIXUP_FUNC,
4901 .v.func = alc269_fixup_stereo_dmic,
4902 },
Takashi Iwai24519912011-08-16 15:08:49 +02004903 [ALC269_FIXUP_QUANTA_MUTE] = {
4904 .type = ALC_FIXUP_FUNC,
4905 .v.func = alc269_fixup_quanta_mute,
4906 },
4907 [ALC269_FIXUP_LIFEBOOK] = {
4908 .type = ALC_FIXUP_PINS,
4909 .v.pins = (const struct alc_pincfg[]) {
4910 { 0x1a, 0x2101103f }, /* dock line-out */
4911 { 0x1b, 0x23a11040 }, /* dock mic-in */
4912 { }
4913 },
4914 .chained = true,
4915 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4916 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02004917 [ALC269_FIXUP_AMIC] = {
4918 .type = ALC_FIXUP_PINS,
4919 .v.pins = (const struct alc_pincfg[]) {
4920 { 0x14, 0x99130110 }, /* speaker */
4921 { 0x15, 0x0121401f }, /* HP out */
4922 { 0x18, 0x01a19c20 }, /* mic */
4923 { 0x19, 0x99a3092f }, /* int-mic */
4924 { }
4925 },
4926 },
4927 [ALC269_FIXUP_DMIC] = {
4928 .type = ALC_FIXUP_PINS,
4929 .v.pins = (const struct alc_pincfg[]) {
4930 { 0x12, 0x99a3092f }, /* int-mic */
4931 { 0x14, 0x99130110 }, /* speaker */
4932 { 0x15, 0x0121401f }, /* HP out */
4933 { 0x18, 0x01a19c20 }, /* mic */
4934 { }
4935 },
4936 },
4937 [ALC269VB_FIXUP_AMIC] = {
4938 .type = ALC_FIXUP_PINS,
4939 .v.pins = (const struct alc_pincfg[]) {
4940 { 0x14, 0x99130110 }, /* speaker */
4941 { 0x18, 0x01a19c20 }, /* mic */
4942 { 0x19, 0x99a3092f }, /* int-mic */
4943 { 0x21, 0x0121401f }, /* HP out */
4944 { }
4945 },
4946 },
4947 [ALC269_FIXUP_DMIC] = {
4948 .type = ALC_FIXUP_PINS,
4949 .v.pins = (const struct alc_pincfg[]) {
4950 { 0x12, 0x99a3092f }, /* int-mic */
4951 { 0x14, 0x99130110 }, /* speaker */
4952 { 0x18, 0x01a19c20 }, /* mic */
4953 { 0x21, 0x0121401f }, /* HP out */
4954 { }
4955 },
4956 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004957};
4958
4959static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02004960 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004961 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4962 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4963 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4964 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4965 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004966 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4967 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4968 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4969 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4970 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4971 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02004972 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004973 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4974 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4975 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4976 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4977 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02004978 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02004979 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004980 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02004981
4982#if 1
4983 /* Below is a quirk table taken from the old code.
4984 * Basically the device should work as is without the fixup table.
4985 * If BIOS doesn't give a proper info, enable the corresponding
4986 * fixup entry.
4987 */
4988 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4989 ALC269_FIXUP_AMIC),
4990 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
4991 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
4992 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
4993 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
4994 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
4995 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
4996 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
4997 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
4998 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
4999 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5000 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5001 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5002 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5003 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5004 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5005 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5006 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5007 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5008 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5009 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5010 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5011 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5012 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5013 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5014 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5015 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5016 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5017 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5018 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5019 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5020 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5021 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5022 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5023 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5024 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5025 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5026 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5027 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5028 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5029 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5030#endif
5031 {}
5032};
5033
5034static const struct alc_model_fixup alc269_fixup_models[] = {
5035 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5036 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005037 {}
5038};
5039
5040
5041static int alc269_fill_coef(struct hda_codec *codec)
5042{
5043 int val;
5044
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005045 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005046 alc_write_coef_idx(codec, 0xf, 0x960b);
5047 alc_write_coef_idx(codec, 0xe, 0x8817);
5048 }
5049
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005050 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005051 alc_write_coef_idx(codec, 0xf, 0x960b);
5052 alc_write_coef_idx(codec, 0xe, 0x8814);
5053 }
5054
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005055 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005056 val = alc_read_coef_idx(codec, 0x04);
5057 /* Power up output pin */
5058 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5059 }
5060
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005061 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005062 val = alc_read_coef_idx(codec, 0xd);
5063 if ((val & 0x0c00) >> 10 != 0x1) {
5064 /* Capless ramp up clock control */
5065 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5066 }
5067 val = alc_read_coef_idx(codec, 0x17);
5068 if ((val & 0x01c0) >> 6 != 0x4) {
5069 /* Class D power on reset */
5070 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5071 }
5072 }
5073
5074 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5075 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5076
5077 val = alc_read_coef_idx(codec, 0x4); /* HP */
5078 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5079
5080 return 0;
5081}
5082
5083/*
5084 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005085static int patch_alc269(struct hda_codec *codec)
5086{
5087 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005088 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005089
5090 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5091 if (spec == NULL)
5092 return -ENOMEM;
5093
5094 codec->spec = spec;
5095
5096 spec->mixer_nid = 0x0b;
5097
5098 alc_auto_parse_customize_define(codec);
5099
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005100 err = alc_codec_rename_from_preset(codec);
5101 if (err < 0)
5102 goto error;
5103
Takashi Iwai1d045db2011-07-07 18:23:21 +02005104 if (codec->vendor_id == 0x10ec0269) {
5105 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005106 switch (alc_get_coef0(codec) & 0x00f0) {
5107 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005108 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005109 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005110 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005111 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005112 break;
5113 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005114 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5115 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005116 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005117 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005118 break;
5119 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005120 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005121 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005122 if (err < 0)
5123 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005124 alc269_fill_coef(codec);
5125 }
5126
Takashi Iwaia4297b52011-08-23 18:40:12 +02005127 alc_pick_fixup(codec, alc269_fixup_models,
5128 alc269_fixup_tbl, alc269_fixups);
5129 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005130
Takashi Iwaia4297b52011-08-23 18:40:12 +02005131 /* automatic parse from the BIOS config */
5132 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005133 if (err < 0)
5134 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005135
Takashi Iwai60a6a842011-07-27 14:01:24 +02005136 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005137 alc_auto_fill_adc_caps(codec);
5138 alc_rebuild_imux_for_auto_mic(codec);
5139 alc_remove_invalid_adc_nids(codec);
5140 }
5141
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005142 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005143 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005144
5145 if (!spec->no_analog && has_cdefine_beep(codec)) {
5146 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005147 if (err < 0)
5148 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005149 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005150 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005151
5152 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5153
5154 spec->vmaster_nid = 0x02;
5155
5156 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005157#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005158 codec->patch_ops.resume = alc269_resume;
5159#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005160 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005161 spec->shutup = alc269_shutup;
5162
5163 alc_init_jacks(codec);
5164#ifdef CONFIG_SND_HDA_POWER_SAVE
5165 if (!spec->loopback.amplist)
5166 spec->loopback.amplist = alc269_loopbacks;
5167 if (alc269_mic2_for_mute_led(codec))
5168 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5169#endif
5170
5171 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005172
5173 error:
5174 alc_free(codec);
5175 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005176}
5177
5178/*
5179 * ALC861
5180 */
5181
Takashi Iwai1d045db2011-07-07 18:23:21 +02005182static int alc861_parse_auto_config(struct hda_codec *codec)
5183{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005184 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005185 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5186 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005187}
5188
Takashi Iwai1d045db2011-07-07 18:23:21 +02005189#ifdef CONFIG_SND_HDA_POWER_SAVE
5190static const struct hda_amp_list alc861_loopbacks[] = {
5191 { 0x15, HDA_INPUT, 0 },
5192 { 0x15, HDA_INPUT, 1 },
5193 { 0x15, HDA_INPUT, 2 },
5194 { 0x15, HDA_INPUT, 3 },
5195 { } /* end */
5196};
5197#endif
5198
5199
5200/* Pin config fixes */
5201enum {
5202 PINFIX_FSC_AMILO_PI1505,
5203};
5204
5205static const struct alc_fixup alc861_fixups[] = {
5206 [PINFIX_FSC_AMILO_PI1505] = {
5207 .type = ALC_FIXUP_PINS,
5208 .v.pins = (const struct alc_pincfg[]) {
5209 { 0x0b, 0x0221101f }, /* HP */
5210 { 0x0f, 0x90170310 }, /* speaker */
5211 { }
5212 }
5213 },
5214};
5215
5216static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5217 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5218 {}
5219};
5220
5221/*
5222 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005223static int patch_alc861(struct hda_codec *codec)
5224{
5225 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005226 int err;
5227
5228 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5229 if (spec == NULL)
5230 return -ENOMEM;
5231
5232 codec->spec = spec;
5233
5234 spec->mixer_nid = 0x15;
5235
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005236 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5237 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005238
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005239 /* automatic parse from the BIOS config */
5240 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005241 if (err < 0)
5242 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005243
Takashi Iwai60a6a842011-07-27 14:01:24 +02005244 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005245 alc_auto_fill_adc_caps(codec);
5246 alc_rebuild_imux_for_auto_mic(codec);
5247 alc_remove_invalid_adc_nids(codec);
5248 }
5249
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005250 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005251 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005252
5253 if (!spec->no_analog) {
5254 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005255 if (err < 0)
5256 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005257 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5258 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005259
5260 spec->vmaster_nid = 0x03;
5261
5262 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5263
5264 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005265 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005266#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005267 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005268 if (!spec->loopback.amplist)
5269 spec->loopback.amplist = alc861_loopbacks;
5270#endif
5271
5272 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005273
5274 error:
5275 alc_free(codec);
5276 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005277}
5278
5279/*
5280 * ALC861-VD support
5281 *
5282 * Based on ALC882
5283 *
5284 * In addition, an independent DAC
5285 */
5286#ifdef CONFIG_SND_HDA_POWER_SAVE
5287#define alc861vd_loopbacks alc880_loopbacks
5288#endif
5289
Takashi Iwai1d045db2011-07-07 18:23:21 +02005290static int alc861vd_parse_auto_config(struct hda_codec *codec)
5291{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005292 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005293 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5294 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005295}
5296
Takashi Iwai1d045db2011-07-07 18:23:21 +02005297enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005298 ALC660VD_FIX_ASUS_GPIO1,
5299 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005300};
5301
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005302/* exclude VREF80 */
5303static void alc861vd_fixup_dallas(struct hda_codec *codec,
5304 const struct alc_fixup *fix, int action)
5305{
5306 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5307 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5308 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5309 }
5310}
5311
Takashi Iwai1d045db2011-07-07 18:23:21 +02005312static const struct alc_fixup alc861vd_fixups[] = {
5313 [ALC660VD_FIX_ASUS_GPIO1] = {
5314 .type = ALC_FIXUP_VERBS,
5315 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005316 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005317 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5318 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5319 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5320 { }
5321 }
5322 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005323 [ALC861VD_FIX_DALLAS] = {
5324 .type = ALC_FIXUP_FUNC,
5325 .v.func = alc861vd_fixup_dallas,
5326 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005327};
5328
5329static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005330 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005331 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005332 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005333 {}
5334};
5335
5336static const struct hda_verb alc660vd_eapd_verbs[] = {
5337 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5338 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5339 { }
5340};
5341
5342/*
5343 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005344static int patch_alc861vd(struct hda_codec *codec)
5345{
5346 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005347 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005348
5349 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5350 if (spec == NULL)
5351 return -ENOMEM;
5352
5353 codec->spec = spec;
5354
5355 spec->mixer_nid = 0x0b;
5356
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005357 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5358 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005359
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005360 /* automatic parse from the BIOS config */
5361 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005362 if (err < 0)
5363 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005364
Takashi Iwai1d045db2011-07-07 18:23:21 +02005365 if (codec->vendor_id == 0x10ec0660) {
5366 /* always turn on EAPD */
5367 add_verb(spec, alc660vd_eapd_verbs);
5368 }
5369
Takashi Iwai60a6a842011-07-27 14:01:24 +02005370 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005371 alc_auto_fill_adc_caps(codec);
5372 alc_rebuild_imux_for_auto_mic(codec);
5373 alc_remove_invalid_adc_nids(codec);
5374 }
5375
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005376 if (!spec->no_analog && !spec->cap_mixer)
5377 set_capture_mixer(codec);
5378
5379 if (!spec->no_analog) {
5380 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005381 if (err < 0)
5382 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005383 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5384 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005385
5386 spec->vmaster_nid = 0x02;
5387
5388 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5389
5390 codec->patch_ops = alc_patch_ops;
5391
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005392 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005393 spec->shutup = alc_eapd_shutup;
5394#ifdef CONFIG_SND_HDA_POWER_SAVE
5395 if (!spec->loopback.amplist)
5396 spec->loopback.amplist = alc861vd_loopbacks;
5397#endif
5398
5399 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005400
5401 error:
5402 alc_free(codec);
5403 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005404}
5405
5406/*
5407 * ALC662 support
5408 *
5409 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5410 * configuration. Each pin widget can choose any input DACs and a mixer.
5411 * Each ADC is connected from a mixer of all inputs. This makes possible
5412 * 6-channel independent captures.
5413 *
5414 * In addition, an independent DAC for the multi-playback (not used in this
5415 * driver yet).
5416 */
5417#ifdef CONFIG_SND_HDA_POWER_SAVE
5418#define alc662_loopbacks alc880_loopbacks
5419#endif
5420
5421/*
5422 * BIOS auto configuration
5423 */
5424
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005425static int alc662_parse_auto_config(struct hda_codec *codec)
5426{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005427 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005428 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5429 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5430 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005431
Kailang Yang6227cdc2010-02-25 08:36:52 +01005432 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5433 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005434 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005435 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005436 ssids = alc662_ssids;
5437 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005438}
5439
Todd Broch6be79482010-12-07 16:51:05 -08005440static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005441 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005442{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005443 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005444 return;
Todd Broch6be79482010-12-07 16:51:05 -08005445 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5446 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5447 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5448 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5449 (0 << AC_AMPCAP_MUTE_SHIFT)))
5450 printk(KERN_WARNING
5451 "hda_codec: failed to override amp caps for NID 0x2\n");
5452}
5453
David Henningsson6cb3b702010-09-09 08:51:44 +02005454enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005455 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005456 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005457 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005458 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005459 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005460 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005461 ALC662_FIXUP_ASUS_MODE1,
5462 ALC662_FIXUP_ASUS_MODE2,
5463 ALC662_FIXUP_ASUS_MODE3,
5464 ALC662_FIXUP_ASUS_MODE4,
5465 ALC662_FIXUP_ASUS_MODE5,
5466 ALC662_FIXUP_ASUS_MODE6,
5467 ALC662_FIXUP_ASUS_MODE7,
5468 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005469};
5470
5471static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005472 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005473 .type = ALC_FIXUP_PINS,
5474 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005475 { 0x15, 0x99130112 }, /* subwoofer */
5476 { }
5477 }
5478 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005479 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005480 .type = ALC_FIXUP_PINS,
5481 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005482 { 0x17, 0x99130112 }, /* subwoofer */
5483 { }
5484 }
5485 },
Todd Broch6be79482010-12-07 16:51:05 -08005486 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005487 .type = ALC_FIXUP_FUNC,
5488 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005489 },
5490 [ALC662_FIXUP_CZC_P10T] = {
5491 .type = ALC_FIXUP_VERBS,
5492 .v.verbs = (const struct hda_verb[]) {
5493 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5494 {}
5495 }
5496 },
David Henningsson94024cd2011-04-29 14:10:55 +02005497 [ALC662_FIXUP_SKU_IGNORE] = {
5498 .type = ALC_FIXUP_SKU,
5499 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005500 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005501 [ALC662_FIXUP_HP_RP5800] = {
5502 .type = ALC_FIXUP_PINS,
5503 .v.pins = (const struct alc_pincfg[]) {
5504 { 0x14, 0x0221201f }, /* HP out */
5505 { }
5506 },
5507 .chained = true,
5508 .chain_id = ALC662_FIXUP_SKU_IGNORE
5509 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005510 [ALC662_FIXUP_ASUS_MODE1] = {
5511 .type = ALC_FIXUP_PINS,
5512 .v.pins = (const struct alc_pincfg[]) {
5513 { 0x14, 0x99130110 }, /* speaker */
5514 { 0x18, 0x01a19c20 }, /* mic */
5515 { 0x19, 0x99a3092f }, /* int-mic */
5516 { 0x21, 0x0121401f }, /* HP out */
5517 { }
5518 },
5519 .chained = true,
5520 .chain_id = ALC662_FIXUP_SKU_IGNORE
5521 },
5522 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005523 .type = ALC_FIXUP_PINS,
5524 .v.pins = (const struct alc_pincfg[]) {
5525 { 0x14, 0x99130110 }, /* speaker */
5526 { 0x18, 0x01a19820 }, /* mic */
5527 { 0x19, 0x99a3092f }, /* int-mic */
5528 { 0x1b, 0x0121401f }, /* HP out */
5529 { }
5530 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005531 .chained = true,
5532 .chain_id = ALC662_FIXUP_SKU_IGNORE
5533 },
5534 [ALC662_FIXUP_ASUS_MODE3] = {
5535 .type = ALC_FIXUP_PINS,
5536 .v.pins = (const struct alc_pincfg[]) {
5537 { 0x14, 0x99130110 }, /* speaker */
5538 { 0x15, 0x0121441f }, /* HP */
5539 { 0x18, 0x01a19840 }, /* mic */
5540 { 0x19, 0x99a3094f }, /* int-mic */
5541 { 0x21, 0x01211420 }, /* HP2 */
5542 { }
5543 },
5544 .chained = true,
5545 .chain_id = ALC662_FIXUP_SKU_IGNORE
5546 },
5547 [ALC662_FIXUP_ASUS_MODE4] = {
5548 .type = ALC_FIXUP_PINS,
5549 .v.pins = (const struct alc_pincfg[]) {
5550 { 0x14, 0x99130110 }, /* speaker */
5551 { 0x16, 0x99130111 }, /* speaker */
5552 { 0x18, 0x01a19840 }, /* mic */
5553 { 0x19, 0x99a3094f }, /* int-mic */
5554 { 0x21, 0x0121441f }, /* HP */
5555 { }
5556 },
5557 .chained = true,
5558 .chain_id = ALC662_FIXUP_SKU_IGNORE
5559 },
5560 [ALC662_FIXUP_ASUS_MODE5] = {
5561 .type = ALC_FIXUP_PINS,
5562 .v.pins = (const struct alc_pincfg[]) {
5563 { 0x14, 0x99130110 }, /* speaker */
5564 { 0x15, 0x0121441f }, /* HP */
5565 { 0x16, 0x99130111 }, /* speaker */
5566 { 0x18, 0x01a19840 }, /* mic */
5567 { 0x19, 0x99a3094f }, /* int-mic */
5568 { }
5569 },
5570 .chained = true,
5571 .chain_id = ALC662_FIXUP_SKU_IGNORE
5572 },
5573 [ALC662_FIXUP_ASUS_MODE6] = {
5574 .type = ALC_FIXUP_PINS,
5575 .v.pins = (const struct alc_pincfg[]) {
5576 { 0x14, 0x99130110 }, /* speaker */
5577 { 0x15, 0x01211420 }, /* HP2 */
5578 { 0x18, 0x01a19840 }, /* mic */
5579 { 0x19, 0x99a3094f }, /* int-mic */
5580 { 0x1b, 0x0121441f }, /* HP */
5581 { }
5582 },
5583 .chained = true,
5584 .chain_id = ALC662_FIXUP_SKU_IGNORE
5585 },
5586 [ALC662_FIXUP_ASUS_MODE7] = {
5587 .type = ALC_FIXUP_PINS,
5588 .v.pins = (const struct alc_pincfg[]) {
5589 { 0x14, 0x99130110 }, /* speaker */
5590 { 0x17, 0x99130111 }, /* speaker */
5591 { 0x18, 0x01a19840 }, /* mic */
5592 { 0x19, 0x99a3094f }, /* int-mic */
5593 { 0x1b, 0x01214020 }, /* HP */
5594 { 0x21, 0x0121401f }, /* HP */
5595 { }
5596 },
5597 .chained = true,
5598 .chain_id = ALC662_FIXUP_SKU_IGNORE
5599 },
5600 [ALC662_FIXUP_ASUS_MODE8] = {
5601 .type = ALC_FIXUP_PINS,
5602 .v.pins = (const struct alc_pincfg[]) {
5603 { 0x14, 0x99130110 }, /* speaker */
5604 { 0x12, 0x99a30970 }, /* int-mic */
5605 { 0x15, 0x01214020 }, /* HP */
5606 { 0x17, 0x99130111 }, /* speaker */
5607 { 0x18, 0x01a19840 }, /* mic */
5608 { 0x21, 0x0121401f }, /* HP */
5609 { }
5610 },
5611 .chained = true,
5612 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005613 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005614};
5615
Takashi Iwaia9111322011-05-02 11:30:18 +02005616static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02005617 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01005618 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02005619 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04005620 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005621 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005622 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05005623 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06005624 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02005625 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01005626 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005627
5628#if 0
5629 /* Below is a quirk table taken from the old code.
5630 * Basically the device should work as is without the fixup table.
5631 * If BIOS doesn't give a proper info, enable the corresponding
5632 * fixup entry.
5633 */
5634 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5635 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5636 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5637 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5638 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5639 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5640 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5641 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5642 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5643 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5644 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5645 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5646 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5647 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5648 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5649 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5650 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5651 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5652 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5653 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5654 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5655 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5656 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5657 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5658 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5659 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5660 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5661 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5662 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5663 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5664 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5665 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5666 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5667 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5668 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5669 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5670 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5671 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5672 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5673 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5674 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5675 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5676 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5677 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5678 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5679 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5680 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5681 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5682 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5683 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5684#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02005685 {}
5686};
5687
Todd Broch6be79482010-12-07 16:51:05 -08005688static const struct alc_model_fixup alc662_fixup_models[] = {
5689 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02005690 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5691 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5692 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5693 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5694 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5695 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5696 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5697 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08005698 {}
5699};
David Henningsson6cb3b702010-09-09 08:51:44 +02005700
5701
Takashi Iwai1d045db2011-07-07 18:23:21 +02005702/*
5703 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005704static int patch_alc662(struct hda_codec *codec)
5705{
5706 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005707 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005708
5709 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5710 if (!spec)
5711 return -ENOMEM;
5712
5713 codec->spec = spec;
5714
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005715 spec->mixer_nid = 0x0b;
5716
Takashi Iwai53c334a2011-08-23 18:27:14 +02005717 /* handle multiple HPs as is */
5718 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5719
Kailang Yangda00c242010-03-19 11:23:45 +01005720 alc_auto_parse_customize_define(codec);
5721
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02005722 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5723
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005724 err = alc_codec_rename_from_preset(codec);
5725 if (err < 0)
5726 goto error;
5727
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005728 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005729 codec->bus->pci->subsystem_vendor == 0x1025 &&
5730 spec->cdefine.platform_type == 1) {
5731 if (alc_codec_rename(codec, "ALC272X") < 0)
5732 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005733 }
Kailang Yang274693f2009-12-03 10:07:50 +01005734
Takashi Iwaib9c51062011-08-24 18:08:07 +02005735 alc_pick_fixup(codec, alc662_fixup_models,
5736 alc662_fixup_tbl, alc662_fixups);
5737 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5738 /* automatic parse from the BIOS config */
5739 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005740 if (err < 0)
5741 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005742
Takashi Iwai60a6a842011-07-27 14:01:24 +02005743 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005744 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02005745 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005746 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02005747 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005748
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005749 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02005750 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01005751
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005752 if (!spec->no_analog && has_cdefine_beep(codec)) {
5753 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005754 if (err < 0)
5755 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01005756 switch (codec->vendor_id) {
5757 case 0x10ec0662:
5758 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5759 break;
5760 case 0x10ec0272:
5761 case 0x10ec0663:
5762 case 0x10ec0665:
5763 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5764 break;
5765 case 0x10ec0273:
5766 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5767 break;
5768 }
Kailang Yangcec27c82010-02-04 14:18:18 +01005769 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01005770 spec->vmaster_nid = 0x02;
5771
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005772 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5773
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005774 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02005775 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c7161532011-04-07 10:37:16 +02005776 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02005777
Kailang Yangbf1b0222010-10-21 08:49:56 +02005778 alc_init_jacks(codec);
5779
Takashi Iwaicb53c622007-08-10 17:21:45 +02005780#ifdef CONFIG_SND_HDA_POWER_SAVE
5781 if (!spec->loopback.amplist)
5782 spec->loopback.amplist = alc662_loopbacks;
5783#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005784
5785 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005786
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005787 error:
5788 alc_free(codec);
5789 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02005790}
5791
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005792/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005793 * ALC680 support
5794 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005795
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005796static int alc680_parse_auto_config(struct hda_codec *codec)
5797{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005798 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005799}
5800
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005801/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005802 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005803static int patch_alc680(struct hda_codec *codec)
5804{
5805 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005806 int err;
5807
5808 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5809 if (spec == NULL)
5810 return -ENOMEM;
5811
5812 codec->spec = spec;
5813
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005814 /* ALC680 has no aa-loopback mixer */
5815
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005816 /* automatic parse from the BIOS config */
5817 err = alc680_parse_auto_config(codec);
5818 if (err < 0) {
5819 alc_free(codec);
5820 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005821 }
5822
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005823 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005824 set_capture_mixer(codec);
5825
5826 spec->vmaster_nid = 0x02;
5827
5828 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005829 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005830
5831 return 0;
5832}
5833
5834/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835 * patch entries
5836 */
Takashi Iwaia9111322011-05-02 11:30:18 +02005837static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02005838 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005840 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005841 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02005842 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005843 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005844 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02005845 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005846 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02005847 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005848 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005849 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005850 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5851 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5852 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005853 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005854 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005855 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5856 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02005857 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
5858 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02005859 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01005860 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01005861 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005862 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005863 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02005865 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02005866 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005867 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02005868 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005869 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005870 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005871 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02005872 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005873 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005874 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02005875 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01005876 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005877 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878 {} /* terminator */
5879};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005880
5881MODULE_ALIAS("snd-hda-codec-id:10ec*");
5882
5883MODULE_LICENSE("GPL");
5884MODULE_DESCRIPTION("Realtek HD-audio codec");
5885
5886static struct hda_codec_preset_list realtek_list = {
5887 .preset = snd_hda_preset_realtek,
5888 .owner = THIS_MODULE,
5889};
5890
5891static int __init patch_realtek_init(void)
5892{
5893 return snd_hda_add_codec_preset(&realtek_list);
5894}
5895
5896static void __exit patch_realtek_exit(void)
5897{
5898 snd_hda_delete_codec_preset(&realtek_list);
5899}
5900
5901module_init(patch_realtek_init)
5902module_exit(patch_realtek_exit)