blob: 22c73b78ac6f193b635ef362c026bf51b8fe1da8 [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 Woithe7cf51e42006-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"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Takashi Iwaic14c95f2012-02-16 16:38:07 +010083#define MAX_VOL_NIDS 0x40
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085struct alc_spec {
86 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020089 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010090 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Takashi Iwai2d9c6482009-10-13 08:06:55 +020092 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020093 * don't forget NULL
94 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020095 */
96 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Takashi Iwaiaa563af2009-07-31 10:05:11 +020098 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020099 const struct hda_pcm_stream *stream_analog_playback;
100 const struct hda_pcm_stream *stream_analog_capture;
101 const struct hda_pcm_stream *stream_analog_alt_playback;
102 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200104 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200105 const struct hda_pcm_stream *stream_digital_playback;
106 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200109 struct hda_multi_out multiout; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
112 */
Takashi Iwai63300792008-01-24 15:31:36 +0100113 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100114 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100115 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 /* capture */
118 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200119 const hda_nid_t *adc_nids;
120 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200121 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200122 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwaic14c95f2012-02-16 16:38:07 +0100123 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
124 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Takashi Iwai840b64c2010-07-13 22:49:01 +0200126 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200127 hda_nid_t cur_adc;
128 unsigned int cur_adc_stream_tag;
129 unsigned int cur_adc_format;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200132 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 const struct hda_input_mux *input_mux;
134 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200135 hda_nid_t ext_mic_pin;
136 hda_nid_t dock_mic_pin;
137 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100140 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200142 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200143 int const_channel_count;
144 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100147 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200148
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100151 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200152 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200153 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200154 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai49535502009-06-30 15:28:30 +0200155 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
156 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200157 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
158 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
159 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100160
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100161 /* hooks */
162 void (*init_hook)(struct hda_codec *codec);
163 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500165 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100166#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200167 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200168 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100169
Takashi Iwai834be882006-03-01 14:16:17 +0100170 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200171 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200172 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200173 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200174 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200175 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200176 unsigned int automute_speaker:1; /* automute speaker outputs */
177 unsigned int automute_lo:1; /* automute LO outputs */
178 unsigned int detect_hp:1; /* Headphone detection enabled */
179 unsigned int detect_lo:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100182 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200183
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100184 /* other flags */
185 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200186 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100187 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200188 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200189 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100190 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200191
192 /* auto-mute control */
193 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200194 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200195
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200196 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200197 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100198
Takashi Iwai2134ea42008-01-10 16:53:55 +0100199 /* for virtual master */
200 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200201#ifdef CONFIG_SND_HDA_POWER_SAVE
202 struct hda_loopback_check loopback;
203#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200204
205 /* for PLL fix */
206 hda_nid_t pll_nid;
207 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200208 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100209
210 /* fix-up list */
211 int fixup_id;
212 const struct alc_fixup *fixup_list;
213 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200214
215 /* multi-io */
216 int multi_ios;
217 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200218
219 /* bind volumes */
220 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100221};
222
Takashi Iwai1d045db2011-07-07 18:23:21 +0200223#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Takashi Iwai44c02402011-07-08 15:14:19 +0200225static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
226 int dir, unsigned int bits)
227{
228 if (!nid)
229 return false;
230 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
231 if (query_amp_caps(codec, nid, dir) & bits)
232 return true;
233 return false;
234}
235
236#define nid_has_mute(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
238#define nid_has_volume(codec, nid, dir) \
239 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241/*
242 * input MUX handling
243 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200244static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
245 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
248 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200249 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
250 if (mux_idx >= spec->num_mux_defs)
251 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100252 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
253 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200254 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200257static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
258 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
261 struct alc_spec *spec = codec->spec;
262 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
263
264 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
265 return 0;
266}
267
Takashi Iwai21268962011-07-07 15:01:13 +0200268static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Takashi Iwai21268962011-07-07 15:01:13 +0200270 struct alc_spec *spec = codec->spec;
271 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
272
273 if (spec->cur_adc && spec->cur_adc != new_adc) {
274 /* stream is running, let's swap the current ADC */
275 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
276 spec->cur_adc = new_adc;
277 snd_hda_codec_setup_stream(codec, new_adc,
278 spec->cur_adc_stream_tag, 0,
279 spec->cur_adc_format);
280 return true;
281 }
282 return false;
283}
284
Takashi Iwai61071592011-11-23 07:52:15 +0100285static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
286{
287 return spec->capsrc_nids ?
288 spec->capsrc_nids[idx] : spec->adc_nids[idx];
289}
290
Takashi Iwai24de1832011-11-07 17:13:39 +0100291static void call_update_outputs(struct hda_codec *codec);
292
Takashi Iwai21268962011-07-07 15:01:13 +0200293/* select the given imux item; either unmute exclusively or select the route */
294static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
295 unsigned int idx, bool force)
296{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100298 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100299 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100300 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200301 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Takashi Iwaicd896c32008-11-18 12:36:33 +0100303 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
304 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100305 if (!imux->num_items && mux_idx > 0)
306 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100307 if (!imux->num_items)
308 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100309
Takashi Iwai21268962011-07-07 15:01:13 +0200310 if (idx >= imux->num_items)
311 idx = imux->num_items - 1;
312 if (spec->cur_mux[adc_idx] == idx && !force)
313 return 0;
314 spec->cur_mux[adc_idx] = idx;
315
Takashi Iwai24de1832011-11-07 17:13:39 +0100316 /* for shared I/O, change the pin-control accordingly */
317 if (spec->shared_mic_hp) {
318 /* NOTE: this assumes that there are only two inputs, the
319 * first is the real internal mic and the second is HP jack.
320 */
321 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
322 AC_VERB_SET_PIN_WIDGET_CONTROL,
323 spec->cur_mux[adc_idx] ?
324 PIN_VREF80 : PIN_HP);
325 spec->automute_speaker = !spec->cur_mux[adc_idx];
326 call_update_outputs(codec);
327 }
328
Takashi Iwai21268962011-07-07 15:01:13 +0200329 if (spec->dyn_adc_switch) {
330 alc_dyn_adc_pcm_resetup(codec, idx);
331 adc_idx = spec->dyn_adc_idx[idx];
332 }
333
Takashi Iwai61071592011-11-23 07:52:15 +0100334 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200335
336 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100337 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
338 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200339 return 1;
340
Takashi Iwaia22d5432009-07-27 12:54:26 +0200341 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200342 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100343 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100344 int active = imux->items[idx].index;
345 for (i = 0; i < num_conns; i++) {
346 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
347 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100348 HDA_AMP_MUTE, v);
349 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100350 } else {
351 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200352 snd_hda_codec_write_cache(codec, nid, 0,
353 AC_VERB_SET_CONNECT_SEL,
354 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100355 }
Takashi Iwai21268962011-07-07 15:01:13 +0200356 return 1;
357}
358
359static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_value *ucontrol)
361{
362 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
363 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
364 return alc_mux_select(codec, adc_idx,
365 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100366}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100369 * set up the input pin config (depending on the given auto-pin type)
370 */
371static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
372 int auto_pin_type)
373{
374 unsigned int val = PIN_IN;
375
Takashi Iwai86e29592010-09-09 14:50:17 +0200376 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100377 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200378 unsigned int oldval;
379 oldval = snd_hda_codec_read(codec, nid, 0,
380 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100381 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100382 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200383 /* if the default pin setup is vref50, we give it priority */
384 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100385 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200386 else if (pincap & AC_PINCAP_VREF_50)
387 val = PIN_VREF50;
388 else if (pincap & AC_PINCAP_VREF_100)
389 val = PIN_VREF100;
390 else if (pincap & AC_PINCAP_VREF_GRD)
391 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100392 }
393 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
394}
395
396/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200397 * Append the given mixer and verb elements for the later use
398 * The mixer array is referred in build_controls(), and init_verbs are
399 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100400 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200401static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100402{
403 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
404 return;
405 spec->mixers[spec->num_mixers++] = mix;
406}
407
408static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
409{
410 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
411 return;
412 spec->init_verbs[spec->num_init_verbs++] = verb;
413}
414
415/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200416 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100417 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200418/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200419static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200420 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
421 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
422 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
423 { }
424};
425
Takashi Iwaia9111322011-05-02 11:30:18 +0200426static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200427 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
428 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
429 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
430 { }
431};
432
Takashi Iwaia9111322011-05-02 11:30:18 +0200433static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200434 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
435 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
436 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
437 { }
438};
439
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200440/*
441 * Fix hardware PLL issue
442 * On some codecs, the analog PLL gating control must be off while
443 * the default value is 1.
444 */
445static void alc_fix_pll(struct hda_codec *codec)
446{
447 struct alc_spec *spec = codec->spec;
448 unsigned int val;
449
450 if (!spec->pll_nid)
451 return;
452 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
453 spec->pll_coef_idx);
454 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
455 AC_VERB_GET_PROC_COEF, 0);
456 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
457 spec->pll_coef_idx);
458 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
459 val & ~(1 << spec->pll_coef_bit));
460}
461
462static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
463 unsigned int coef_idx, unsigned int coef_bit)
464{
465 struct alc_spec *spec = codec->spec;
466 spec->pll_nid = nid;
467 spec->pll_coef_idx = coef_idx;
468 spec->pll_coef_bit = coef_bit;
469 alc_fix_pll(codec);
470}
471
Takashi Iwai1d045db2011-07-07 18:23:21 +0200472/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200473 * Jack detections for HP auto-mute and mic-switch
474 */
475
476/* check each pin in the given array; returns true if any of them is plugged */
477static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200478{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200479 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200480
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200481 for (i = 0; i < num_pins; i++) {
482 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200483 if (!nid)
484 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200485 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200486 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200487 return present;
488}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200489
Takashi Iwai1d045db2011-07-07 18:23:21 +0200490/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200491static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200492 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200493{
494 struct alc_spec *spec = codec->spec;
495 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200496 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200497 int i;
498
499 for (i = 0; i < num_pins; i++) {
500 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100501 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200502 if (!nid)
503 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200504 switch (spec->automute_mode) {
505 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100506 /* don't reset VREF value in case it's controlling
507 * the amp (see alc861_fixup_asus_amp_vref_0f())
508 */
509 if (spec->keep_vref_in_automute) {
510 val = snd_hda_codec_read(codec, nid, 0,
511 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
512 val &= ~PIN_HP;
513 } else
514 val = 0;
515 val |= pin_bits;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200516 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai31150f22012-01-30 10:54:08 +0100518 val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200519 break;
520 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200521 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200522 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200523 break;
524 case ALC_AUTOMUTE_MIXER:
525 nid = spec->automute_mixer_nid[i];
526 if (!nid)
527 break;
528 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200530 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200531 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200532 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200533 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200534 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200535}
536
David Henningsson42cf0d02011-09-20 12:04:56 +0200537/* Toggle outputs muting */
538static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200539{
540 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200541 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200542
Takashi Iwaic0a20262011-06-10 15:28:15 +0200543 /* Control HP pins/amps depending on master_mute state;
544 * in general, HP pins/amps control should be enabled in all cases,
545 * but currently set only for master_mute, just to be safe
546 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100547 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
548 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200549 spec->autocfg.hp_pins, spec->master_mute, true);
550
David Henningsson42cf0d02011-09-20 12:04:56 +0200551 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200552 on = 0;
553 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200554 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200557 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558
559 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 /* if LO is a copy of either HP or Speaker, don't need to handle it */
561 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
562 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200563 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200564 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 on = 0;
566 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200567 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200568 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200569 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200571}
572
David Henningsson42cf0d02011-09-20 12:04:56 +0200573static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200574{
575 struct alc_spec *spec = codec->spec;
576 if (spec->automute_hook)
577 spec->automute_hook(codec);
578 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200579 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200580}
581
Takashi Iwai1d045db2011-07-07 18:23:21 +0200582/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583static void alc_hp_automute(struct hda_codec *codec)
584{
585 struct alc_spec *spec = codec->spec;
586
David Henningsson42cf0d02011-09-20 12:04:56 +0200587 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
589 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200590 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200591 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200593}
594
Takashi Iwai1d045db2011-07-07 18:23:21 +0200595/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200596static void alc_line_automute(struct hda_codec *codec)
597{
598 struct alc_spec *spec = codec->spec;
599
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200600 /* check LO jack only when it's different from HP */
601 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
602 return;
603
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200604 spec->line_jack_present =
605 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
606 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200607 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200608 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200609 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200610}
611
Takashi Iwai8d087c72011-06-28 12:45:47 +0200612#define get_connection_index(codec, mux, nid) \
613 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200614
Takashi Iwai1d045db2011-07-07 18:23:21 +0200615/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200616static void alc_mic_automute(struct hda_codec *codec)
617{
618 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200619 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200620
Takashi Iwai21268962011-07-07 15:01:13 +0200621 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200622 return;
623 if (snd_BUG_ON(!spec->adc_nids))
624 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200625 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200626 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200627
Takashi Iwai21268962011-07-07 15:01:13 +0200628 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
629 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
630 else if (spec->dock_mic_idx >= 0 &&
631 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
632 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
633 else
634 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200635}
636
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100637/* handle the specified unsol action (ALC_XXX_EVENT) */
638static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200639{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100640 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200641 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200642 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200643 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200644 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200645 alc_line_automute(codec);
646 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200647 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200648 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200649 break;
650 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200651 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200652}
653
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100654/* unsolicited event for HP jack sensing */
655static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
656{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100657 if (codec->vendor_id == 0x10ec0880)
658 res >>= 28;
659 else
660 res >>= 26;
Takashi Iwaia7309792012-01-19 15:03:48 +0100661 res = snd_hda_jack_get_action(codec, res);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100662 alc_exec_unsol_event(codec, res);
663}
664
Takashi Iwai1d045db2011-07-07 18:23:21 +0200665/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200666static void alc_inithook(struct hda_codec *codec)
667{
Takashi Iwaid922b512011-04-28 12:18:53 +0200668 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200669 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200670 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200671}
672
Kailang Yangf9423e72008-05-27 12:32:25 +0200673/* additional initialization for ALC888 variants */
674static void alc888_coef_init(struct hda_codec *codec)
675{
676 unsigned int tmp;
677
678 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
679 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
680 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100681 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200682 /* alc888S-VC */
683 snd_hda_codec_read(codec, 0x20, 0,
684 AC_VERB_SET_PROC_COEF, 0x830);
685 else
686 /* alc888-VB */
687 snd_hda_codec_read(codec, 0x20, 0,
688 AC_VERB_SET_PROC_COEF, 0x3030);
689}
690
Takashi Iwai1d045db2011-07-07 18:23:21 +0200691/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200692static void alc889_coef_init(struct hda_codec *codec)
693{
694 unsigned int tmp;
695
696 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
697 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
698 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
699 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
700}
701
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100702/* turn on/off EAPD control (only if available) */
703static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
704{
705 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
706 return;
707 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
708 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
709 on ? 2 : 0);
710}
711
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200712/* turn on/off EAPD controls of the codec */
713static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
714{
715 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200716 static hda_nid_t pins[] = {
717 0x0f, 0x10, 0x14, 0x15, 0
718 };
719 hda_nid_t *p;
720 for (p = pins; *p; p++)
721 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200722}
723
Takashi Iwai1c716152011-04-07 10:37:16 +0200724/* generic shutup callback;
725 * just turning off EPAD and a little pause for avoiding pop-noise
726 */
727static void alc_eapd_shutup(struct hda_codec *codec)
728{
729 alc_auto_setup_eapd(codec, false);
730 msleep(200);
731}
732
Takashi Iwai1d045db2011-07-07 18:23:21 +0200733/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200734static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200735{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200736 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200737
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200738 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200739 switch (type) {
740 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200741 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
742 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200743 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200744 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
745 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200746 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200747 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
748 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200749 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200750 switch (codec->vendor_id) {
751 case 0x10ec0260:
752 snd_hda_codec_write(codec, 0x1a, 0,
753 AC_VERB_SET_COEF_INDEX, 7);
754 tmp = snd_hda_codec_read(codec, 0x1a, 0,
755 AC_VERB_GET_PROC_COEF, 0);
756 snd_hda_codec_write(codec, 0x1a, 0,
757 AC_VERB_SET_COEF_INDEX, 7);
758 snd_hda_codec_write(codec, 0x1a, 0,
759 AC_VERB_SET_PROC_COEF,
760 tmp | 0x2010);
761 break;
762 case 0x10ec0262:
763 case 0x10ec0880:
764 case 0x10ec0882:
765 case 0x10ec0883:
766 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100767 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100768 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200769 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200770 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200771 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200772 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200773 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100774#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200775 case 0x10ec0267:
776 case 0x10ec0268:
777 snd_hda_codec_write(codec, 0x20, 0,
778 AC_VERB_SET_COEF_INDEX, 7);
779 tmp = snd_hda_codec_read(codec, 0x20, 0,
780 AC_VERB_GET_PROC_COEF, 0);
781 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200782 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200783 snd_hda_codec_write(codec, 0x20, 0,
784 AC_VERB_SET_PROC_COEF,
785 tmp | 0x3000);
786 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100787#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200788 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200789 break;
790 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200791}
Kailang Yangea1fb292008-08-26 12:58:38 +0200792
Takashi Iwai1d045db2011-07-07 18:23:21 +0200793/*
794 * Auto-Mute mode mixer enum support
795 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200796static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
797 struct snd_ctl_elem_info *uinfo)
798{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200799 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
800 struct alc_spec *spec = codec->spec;
801 static const char * const texts2[] = {
802 "Disabled", "Enabled"
803 };
804 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100805 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200806 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200807 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200808
809 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
810 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200811 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200812 uinfo->value.enumerated.items = 3;
813 texts = texts3;
814 } else {
815 uinfo->value.enumerated.items = 2;
816 texts = texts2;
817 }
818 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
819 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200820 strcpy(uinfo->value.enumerated.name,
821 texts[uinfo->value.enumerated.item]);
822 return 0;
823}
824
825static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
826 struct snd_ctl_elem_value *ucontrol)
827{
828 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
829 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200830 unsigned int val = 0;
831 if (spec->automute_speaker)
832 val++;
833 if (spec->automute_lo)
834 val++;
835
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200836 ucontrol->value.enumerated.item[0] = val;
837 return 0;
838}
839
840static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
841 struct snd_ctl_elem_value *ucontrol)
842{
843 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
844 struct alc_spec *spec = codec->spec;
845
846 switch (ucontrol->value.enumerated.item[0]) {
847 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200848 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200849 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200850 spec->automute_speaker = 0;
851 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200852 break;
853 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200854 if (spec->automute_speaker_possible) {
855 if (!spec->automute_lo && spec->automute_speaker)
856 return 0;
857 spec->automute_speaker = 1;
858 spec->automute_lo = 0;
859 } else if (spec->automute_lo_possible) {
860 if (spec->automute_lo)
861 return 0;
862 spec->automute_lo = 1;
863 } else
864 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200865 break;
866 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200867 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200868 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200869 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200870 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200871 spec->automute_speaker = 1;
872 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200873 break;
874 default:
875 return -EINVAL;
876 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200877 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200878 return 1;
879}
880
Takashi Iwaia9111322011-05-02 11:30:18 +0200881static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200882 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
883 .name = "Auto-Mute Mode",
884 .info = alc_automute_mode_info,
885 .get = alc_automute_mode_get,
886 .put = alc_automute_mode_put,
887};
888
Takashi Iwai1d045db2011-07-07 18:23:21 +0200889static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
890{
891 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
892 return snd_array_new(&spec->kctls);
893}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200894
895static int alc_add_automute_mode_enum(struct hda_codec *codec)
896{
897 struct alc_spec *spec = codec->spec;
898 struct snd_kcontrol_new *knew;
899
900 knew = alc_kcontrol_new(spec);
901 if (!knew)
902 return -ENOMEM;
903 *knew = alc_automute_mode_enum;
904 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
905 if (!knew->name)
906 return -ENOMEM;
907 return 0;
908}
909
Takashi Iwai1d045db2011-07-07 18:23:21 +0200910/*
911 * Check the availability of HP/line-out auto-mute;
912 * Set up appropriately if really supported
913 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200914static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200915{
916 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200917 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200918 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200919 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200920
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200921 if (cfg->hp_pins[0])
922 present++;
923 if (cfg->line_out_pins[0])
924 present++;
925 if (cfg->speaker_pins[0])
926 present++;
927 if (present < 2) /* need two different output types */
928 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200929
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200930 if (!cfg->speaker_pins[0] &&
931 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200932 memcpy(cfg->speaker_pins, cfg->line_out_pins,
933 sizeof(cfg->speaker_pins));
934 cfg->speaker_outs = cfg->line_outs;
935 }
936
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200937 if (!cfg->hp_pins[0] &&
938 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200939 memcpy(cfg->hp_pins, cfg->line_out_pins,
940 sizeof(cfg->hp_pins));
941 cfg->hp_outs = cfg->line_outs;
942 }
943
David Henningsson42cf0d02011-09-20 12:04:56 +0200944 spec->automute_mode = ALC_AUTOMUTE_PIN;
945
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200946 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200947 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200948 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200949 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200950 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200951 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200952 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200953 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200954 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200955
David Henningsson42cf0d02011-09-20 12:04:56 +0200956 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
957 if (cfg->speaker_outs)
958 for (i = 0; i < cfg->line_outs; i++) {
959 hda_nid_t nid = cfg->line_out_pins[i];
960 if (!is_jack_detectable(codec, nid))
961 continue;
962 snd_printdd("realtek: Enable Line-Out "
963 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200964 snd_hda_jack_detect_enable(codec, nid,
965 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200966 spec->detect_lo = 1;
967 }
968 spec->automute_lo_possible = spec->detect_hp;
969 }
970
971 spec->automute_speaker_possible = cfg->speaker_outs &&
972 (spec->detect_hp || spec->detect_lo);
973
974 spec->automute_lo = spec->automute_lo_possible;
975 spec->automute_speaker = spec->automute_speaker_possible;
976
977 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200978 /* create a control for automute mode */
979 alc_add_automute_mode_enum(codec);
980 spec->unsol_event = alc_sku_unsol_event;
981 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200982}
983
Takashi Iwai1d045db2011-07-07 18:23:21 +0200984/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200985static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
986{
987 int i;
988 for (i = 0; i < nums; i++)
989 if (list[i] == nid)
990 return i;
991 return -1;
992}
993
Takashi Iwai1d045db2011-07-07 18:23:21 +0200994/* check whether dynamic ADC-switching is available */
995static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
996{
997 struct alc_spec *spec = codec->spec;
998 struct hda_input_mux *imux = &spec->private_imux[0];
999 int i, n, idx;
1000 hda_nid_t cap, pin;
1001
1002 if (imux != spec->input_mux) /* no dynamic imux? */
1003 return false;
1004
1005 for (n = 0; n < spec->num_adc_nids; n++) {
1006 cap = spec->private_capsrc_nids[n];
1007 for (i = 0; i < imux->num_items; i++) {
1008 pin = spec->imux_pins[i];
1009 if (!pin)
1010 return false;
1011 if (get_connection_index(codec, cap, pin) < 0)
1012 break;
1013 }
1014 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001015 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001016 }
1017
1018 for (i = 0; i < imux->num_items; i++) {
1019 pin = spec->imux_pins[i];
1020 for (n = 0; n < spec->num_adc_nids; n++) {
1021 cap = spec->private_capsrc_nids[n];
1022 idx = get_connection_index(codec, cap, pin);
1023 if (idx >= 0) {
1024 imux->items[i].index = idx;
1025 spec->dyn_adc_idx[i] = n;
1026 break;
1027 }
1028 }
1029 }
1030
1031 snd_printdd("realtek: enabling ADC switching\n");
1032 spec->dyn_adc_switch = 1;
1033 return true;
1034}
Takashi Iwai21268962011-07-07 15:01:13 +02001035
1036/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1037static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1038{
1039 struct alc_spec *spec = codec->spec;
1040 struct hda_input_mux *imux;
1041 static char * const texts[3] = {
1042 "Mic", "Internal Mic", "Dock Mic"
1043 };
1044 int i;
1045
1046 if (!spec->auto_mic)
1047 return false;
1048 imux = &spec->private_imux[0];
1049 if (spec->input_mux == imux)
1050 return true;
1051 spec->imux_pins[0] = spec->ext_mic_pin;
1052 spec->imux_pins[1] = spec->int_mic_pin;
1053 spec->imux_pins[2] = spec->dock_mic_pin;
1054 for (i = 0; i < 3; i++) {
1055 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001056 if (spec->imux_pins[i]) {
1057 hda_nid_t pin = spec->imux_pins[i];
1058 int c;
1059 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001060 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001061 int idx = get_connection_index(codec, cap, pin);
1062 if (idx >= 0) {
1063 imux->items[i].index = idx;
1064 break;
1065 }
1066 }
Takashi Iwai21268962011-07-07 15:01:13 +02001067 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001068 }
Takashi Iwai21268962011-07-07 15:01:13 +02001069 }
1070 spec->num_mux_defs = 1;
1071 spec->input_mux = imux;
1072 return true;
1073}
1074
1075/* check whether all auto-mic pins are valid; setup indices if OK */
1076static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1077{
1078 struct alc_spec *spec = codec->spec;
1079 const struct hda_input_mux *imux;
1080
1081 if (!spec->auto_mic)
1082 return false;
1083 if (spec->auto_mic_valid_imux)
1084 return true; /* already checked */
1085
1086 /* fill up imux indices */
1087 if (!alc_check_dyn_adc_switch(codec)) {
1088 spec->auto_mic = 0;
1089 return false;
1090 }
1091
1092 imux = spec->input_mux;
1093 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1094 spec->imux_pins, imux->num_items);
1095 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1098 spec->imux_pins, imux->num_items);
1099 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1100 spec->auto_mic = 0;
1101 return false; /* no corresponding imux */
1102 }
1103
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001104 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001105 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001106 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1107 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001108
1109 spec->auto_mic_valid_imux = 1;
1110 spec->auto_mic = 1;
1111 return true;
1112}
1113
Takashi Iwai1d045db2011-07-07 18:23:21 +02001114/*
1115 * Check the availability of auto-mic switch;
1116 * Set up if really supported
1117 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001118static void alc_init_auto_mic(struct hda_codec *codec)
1119{
1120 struct alc_spec *spec = codec->spec;
1121 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001122 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001123 int i;
1124
Takashi Iwai24de1832011-11-07 17:13:39 +01001125 if (spec->shared_mic_hp)
1126 return; /* no auto-mic for the shared I/O */
1127
Takashi Iwai21268962011-07-07 15:01:13 +02001128 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1129
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001130 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001131 for (i = 0; i < cfg->num_inputs; i++) {
1132 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001133 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001134 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001135 switch (snd_hda_get_input_pin_attr(defcfg)) {
1136 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001137 if (fixed)
1138 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001139 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1140 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001141 fixed = nid;
1142 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001143 case INPUT_PIN_ATTR_UNUSED:
1144 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001145 case INPUT_PIN_ATTR_DOCK:
1146 if (dock)
1147 return; /* already occupied */
1148 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1149 return; /* invalid type */
1150 dock = nid;
1151 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001152 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001153 if (ext)
1154 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001155 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1156 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001157 ext = nid;
1158 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001159 }
1160 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001161 if (!ext && dock) {
1162 ext = dock;
1163 dock = 0;
1164 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001165 if (!ext || !fixed)
1166 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001167 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001168 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001169 if (dock && !is_jack_detectable(codec, dock))
1170 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001171
1172 /* check imux indices */
1173 spec->ext_mic_pin = ext;
1174 spec->int_mic_pin = fixed;
1175 spec->dock_mic_pin = dock;
1176
1177 spec->auto_mic = 1;
1178 if (!alc_auto_mic_check_imux(codec))
1179 return;
1180
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001181 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1182 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001183 spec->unsol_event = alc_sku_unsol_event;
1184}
1185
Takashi Iwai1d045db2011-07-07 18:23:21 +02001186/* check the availabilities of auto-mute and auto-mic switches */
1187static void alc_auto_check_switches(struct hda_codec *codec)
1188{
David Henningsson42cf0d02011-09-20 12:04:56 +02001189 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001190 alc_init_auto_mic(codec);
1191}
1192
1193/*
1194 * Realtek SSID verification
1195 */
1196
David Henningsson90622912010-10-14 14:50:18 +02001197/* Could be any non-zero and even value. When used as fixup, tells
1198 * the driver to ignore any present sku defines.
1199 */
1200#define ALC_FIXUP_SKU_IGNORE (2)
1201
Kailang Yangda00c242010-03-19 11:23:45 +01001202static int alc_auto_parse_customize_define(struct hda_codec *codec)
1203{
1204 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001205 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001206 struct alc_spec *spec = codec->spec;
1207
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001208 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1209
David Henningsson90622912010-10-14 14:50:18 +02001210 if (spec->cdefine.fixup) {
1211 ass = spec->cdefine.sku_cfg;
1212 if (ass == ALC_FIXUP_SKU_IGNORE)
1213 return -1;
1214 goto do_sku;
1215 }
1216
Kailang Yangda00c242010-03-19 11:23:45 +01001217 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001218 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001219 goto do_sku;
1220
1221 nid = 0x1d;
1222 if (codec->vendor_id == 0x10ec0260)
1223 nid = 0x17;
1224 ass = snd_hda_codec_get_pincfg(codec, nid);
1225
1226 if (!(ass & 1)) {
1227 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1228 codec->chip_name, ass);
1229 return -1;
1230 }
1231
1232 /* check sum */
1233 tmp = 0;
1234 for (i = 1; i < 16; i++) {
1235 if ((ass >> i) & 1)
1236 tmp++;
1237 }
1238 if (((ass >> 16) & 0xf) != tmp)
1239 return -1;
1240
1241 spec->cdefine.port_connectivity = ass >> 30;
1242 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1243 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1244 spec->cdefine.customization = ass >> 8;
1245do_sku:
1246 spec->cdefine.sku_cfg = ass;
1247 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1248 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1249 spec->cdefine.swap = (ass & 0x2) >> 1;
1250 spec->cdefine.override = ass & 0x1;
1251
1252 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1253 nid, spec->cdefine.sku_cfg);
1254 snd_printd("SKU: port_connectivity=0x%x\n",
1255 spec->cdefine.port_connectivity);
1256 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1257 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1258 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1259 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1260 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1261 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1262 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1263
1264 return 0;
1265}
1266
Takashi Iwai1d045db2011-07-07 18:23:21 +02001267/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001268static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1269{
Takashi Iwai21268962011-07-07 15:01:13 +02001270 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001271}
1272
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001273/* check subsystem ID and set up device-specific initialization;
1274 * return 1 if initialized, 0 if invalid SSID
1275 */
1276/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1277 * 31 ~ 16 : Manufacture ID
1278 * 15 ~ 8 : SKU ID
1279 * 7 ~ 0 : Assembly ID
1280 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1281 */
1282static int alc_subsystem_id(struct hda_codec *codec,
1283 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001284 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001285{
1286 unsigned int ass, tmp, i;
1287 unsigned nid;
1288 struct alc_spec *spec = codec->spec;
1289
David Henningsson90622912010-10-14 14:50:18 +02001290 if (spec->cdefine.fixup) {
1291 ass = spec->cdefine.sku_cfg;
1292 if (ass == ALC_FIXUP_SKU_IGNORE)
1293 return 0;
1294 goto do_sku;
1295 }
1296
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001297 ass = codec->subsystem_id & 0xffff;
1298 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1299 goto do_sku;
1300
1301 /* invalid SSID, check the special NID pin defcfg instead */
1302 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001303 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001304 * 29~21 : reserve
1305 * 20 : PCBEEP input
1306 * 19~16 : Check sum (15:1)
1307 * 15~1 : Custom
1308 * 0 : override
1309 */
1310 nid = 0x1d;
1311 if (codec->vendor_id == 0x10ec0260)
1312 nid = 0x17;
1313 ass = snd_hda_codec_get_pincfg(codec, nid);
1314 snd_printd("realtek: No valid SSID, "
1315 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001316 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001317 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001318 return 0;
1319 if ((ass >> 30) != 1) /* no physical connection */
1320 return 0;
1321
1322 /* check sum */
1323 tmp = 0;
1324 for (i = 1; i < 16; i++) {
1325 if ((ass >> i) & 1)
1326 tmp++;
1327 }
1328 if (((ass >> 16) & 0xf) != tmp)
1329 return 0;
1330do_sku:
1331 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1332 ass & 0xffff, codec->vendor_id);
1333 /*
1334 * 0 : override
1335 * 1 : Swap Jack
1336 * 2 : 0 --> Desktop, 1 --> Laptop
1337 * 3~5 : External Amplifier control
1338 * 7~6 : Reserved
1339 */
1340 tmp = (ass & 0x38) >> 3; /* external Amp control */
1341 switch (tmp) {
1342 case 1:
1343 spec->init_amp = ALC_INIT_GPIO1;
1344 break;
1345 case 3:
1346 spec->init_amp = ALC_INIT_GPIO2;
1347 break;
1348 case 7:
1349 spec->init_amp = ALC_INIT_GPIO3;
1350 break;
1351 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001352 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001353 spec->init_amp = ALC_INIT_DEFAULT;
1354 break;
1355 }
1356
1357 /* is laptop or Desktop and enable the function "Mute internal speaker
1358 * when the external headphone out jack is plugged"
1359 */
1360 if (!(ass & 0x8000))
1361 return 1;
1362 /*
1363 * 10~8 : Jack location
1364 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1365 * 14~13: Resvered
1366 * 15 : 1 --> enable the function "Mute internal speaker
1367 * when the external headphone out jack is plugged"
1368 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001369 if (!spec->autocfg.hp_pins[0] &&
1370 !(spec->autocfg.line_out_pins[0] &&
1371 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001372 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001373 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1374 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001375 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001376 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001377 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001378 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001379 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001380 else if (tmp == 3)
1381 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001382 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001383 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001384 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1385 spec->autocfg.line_outs))
1386 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001387 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001388 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001389 return 1;
1390}
Kailang Yangea1fb292008-08-26 12:58:38 +02001391
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001392/* Check the validity of ALC subsystem-id
1393 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1394static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001395{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001396 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001397 struct alc_spec *spec = codec->spec;
1398 snd_printd("realtek: "
1399 "Enable default setup for auto mode as fallback\n");
1400 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001401 }
Takashi Iwai21268962011-07-07 15:01:13 +02001402}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001403
Takashi Iwai41e41f12005-06-08 14:48:49 +02001404/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001405 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001406 */
1407
1408struct alc_pincfg {
1409 hda_nid_t nid;
1410 u32 val;
1411};
1412
Todd Broche1eb5f12010-12-06 11:19:51 -08001413struct alc_model_fixup {
1414 const int id;
1415 const char *name;
1416};
1417
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001418struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001419 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001420 bool chained;
1421 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001422 union {
1423 unsigned int sku;
1424 const struct alc_pincfg *pins;
1425 const struct hda_verb *verbs;
1426 void (*func)(struct hda_codec *codec,
1427 const struct alc_fixup *fix,
1428 int action);
1429 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001430};
1431
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001432enum {
1433 ALC_FIXUP_INVALID,
1434 ALC_FIXUP_SKU,
1435 ALC_FIXUP_PINS,
1436 ALC_FIXUP_VERBS,
1437 ALC_FIXUP_FUNC,
1438};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001439
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001440enum {
1441 ALC_FIXUP_ACT_PRE_PROBE,
1442 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001443 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001444};
1445
1446static void alc_apply_fixup(struct hda_codec *codec, int action)
1447{
1448 struct alc_spec *spec = codec->spec;
1449 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001450#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001451 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001452#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001453 int depth = 0;
1454
1455 if (!spec->fixup_list)
1456 return;
1457
1458 while (id >= 0) {
1459 const struct alc_fixup *fix = spec->fixup_list + id;
1460 const struct alc_pincfg *cfg;
1461
1462 switch (fix->type) {
1463 case ALC_FIXUP_SKU:
1464 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001465 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001466 snd_printdd(KERN_INFO "hda_codec: %s: "
1467 "Apply sku override for %s\n",
1468 codec->chip_name, modelname);
1469 spec->cdefine.sku_cfg = fix->v.sku;
1470 spec->cdefine.fixup = 1;
1471 break;
1472 case ALC_FIXUP_PINS:
1473 cfg = fix->v.pins;
1474 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1475 break;
1476 snd_printdd(KERN_INFO "hda_codec: %s: "
1477 "Apply pincfg for %s\n",
1478 codec->chip_name, modelname);
1479 for (; cfg->nid; cfg++)
1480 snd_hda_codec_set_pincfg(codec, cfg->nid,
1481 cfg->val);
1482 break;
1483 case ALC_FIXUP_VERBS:
1484 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1485 break;
1486 snd_printdd(KERN_INFO "hda_codec: %s: "
1487 "Apply fix-verbs for %s\n",
1488 codec->chip_name, modelname);
1489 add_verb(codec->spec, fix->v.verbs);
1490 break;
1491 case ALC_FIXUP_FUNC:
1492 if (!fix->v.func)
1493 break;
1494 snd_printdd(KERN_INFO "hda_codec: %s: "
1495 "Apply fix-func for %s\n",
1496 codec->chip_name, modelname);
1497 fix->v.func(codec, fix, action);
1498 break;
1499 default:
1500 snd_printk(KERN_ERR "hda_codec: %s: "
1501 "Invalid fixup type %d\n",
1502 codec->chip_name, fix->type);
1503 break;
1504 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001505 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001506 break;
1507 if (++depth > 10)
1508 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001509 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001510 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001511}
1512
Todd Broche1eb5f12010-12-06 11:19:51 -08001513static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001514 const struct alc_model_fixup *models,
1515 const struct snd_pci_quirk *quirk,
1516 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001517{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001518 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001519 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001520 int id = -1;
1521 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001522
Todd Broche1eb5f12010-12-06 11:19:51 -08001523 if (codec->modelname && models) {
1524 while (models->name) {
1525 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001526 id = models->id;
1527 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001528 break;
1529 }
1530 models++;
1531 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001532 }
1533 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001534 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1535 if (q) {
1536 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001537#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001538 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001539#endif
1540 }
1541 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001542 if (id < 0) {
1543 for (q = quirk; q->subvendor; q++) {
1544 unsigned int vendorid =
1545 q->subdevice | (q->subvendor << 16);
1546 if (vendorid == codec->subsystem_id) {
1547 id = q->value;
1548#ifdef CONFIG_SND_DEBUG_VERBOSE
1549 name = q->name;
1550#endif
1551 break;
1552 }
1553 }
1554 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001555
1556 spec->fixup_id = id;
1557 if (id >= 0) {
1558 spec->fixup_list = fixlist;
1559 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001560 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001561}
1562
Takashi Iwai1d045db2011-07-07 18:23:21 +02001563/*
1564 * COEF access helper functions
1565 */
Kailang Yang274693f2009-12-03 10:07:50 +01001566static int alc_read_coef_idx(struct hda_codec *codec,
1567 unsigned int coef_idx)
1568{
1569 unsigned int val;
1570 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1571 coef_idx);
1572 val = snd_hda_codec_read(codec, 0x20, 0,
1573 AC_VERB_GET_PROC_COEF, 0);
1574 return val;
1575}
1576
Kailang Yang977ddd62010-09-15 10:02:29 +02001577static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1578 unsigned int coef_val)
1579{
1580 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1581 coef_idx);
1582 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1583 coef_val);
1584}
1585
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001586/* a special bypass for COEF 0; read the cached value at the second time */
1587static unsigned int alc_get_coef0(struct hda_codec *codec)
1588{
1589 struct alc_spec *spec = codec->spec;
1590 if (!spec->coef0)
1591 spec->coef0 = alc_read_coef_idx(codec, 0);
1592 return spec->coef0;
1593}
1594
Takashi Iwai1d045db2011-07-07 18:23:21 +02001595/*
1596 * Digital I/O handling
1597 */
1598
Takashi Iwai757899a2010-07-30 10:48:14 +02001599/* set right pin controls for digital I/O */
1600static void alc_auto_init_digital(struct hda_codec *codec)
1601{
1602 struct alc_spec *spec = codec->spec;
1603 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001604 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001605
1606 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1607 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001608 if (!pin)
1609 continue;
1610 snd_hda_codec_write(codec, pin, 0,
1611 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1612 if (!i)
1613 dac = spec->multiout.dig_out_nid;
1614 else
1615 dac = spec->slave_dig_outs[i - 1];
1616 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1617 continue;
1618 snd_hda_codec_write(codec, dac, 0,
1619 AC_VERB_SET_AMP_GAIN_MUTE,
1620 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001621 }
1622 pin = spec->autocfg.dig_in_pin;
1623 if (pin)
1624 snd_hda_codec_write(codec, pin, 0,
1625 AC_VERB_SET_PIN_WIDGET_CONTROL,
1626 PIN_IN);
1627}
1628
1629/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1630static void alc_auto_parse_digital(struct hda_codec *codec)
1631{
1632 struct alc_spec *spec = codec->spec;
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001633 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001634 hda_nid_t dig_nid;
1635
1636 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001637 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001638 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001639 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001640 err = snd_hda_get_connections(codec,
1641 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001642 conn, ARRAY_SIZE(conn));
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001643 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001644 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001645 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001646 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001647 spec->multiout.dig_out_nid = dig_nid;
1648 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1649 } else {
1650 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001651 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001652 break;
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001653 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001654 }
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001655 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001656 }
1657
1658 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001659 dig_nid = codec->start_nid;
1660 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1661 unsigned int wcaps = get_wcaps(codec, dig_nid);
1662 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1663 continue;
1664 if (!(wcaps & AC_WCAP_DIGITAL))
1665 continue;
1666 if (!(wcaps & AC_WCAP_CONN_LIST))
1667 continue;
1668 err = get_connection_index(codec, dig_nid,
1669 spec->autocfg.dig_in_pin);
1670 if (err >= 0) {
1671 spec->dig_in_nid = dig_nid;
1672 break;
1673 }
1674 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001675 }
1676}
1677
Takashi Iwaif95474e2007-07-10 00:47:43 +02001678/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001679 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001680 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001681static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1682 struct snd_ctl_elem_info *uinfo)
1683{
1684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1685 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001686 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001687 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001688
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001689 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001690 if (spec->vol_in_capsrc)
1691 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1692 else
1693 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1694 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001695 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001696 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001697 return err;
1698}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001700static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1701 unsigned int size, unsigned int __user *tlv)
1702{
1703 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1704 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001705 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001706 int err;
1707
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001708 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001709 if (spec->vol_in_capsrc)
1710 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1711 else
1712 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1713 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001714 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001715 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001716 return err;
1717}
1718
1719typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1720 struct snd_ctl_elem_value *ucontrol);
1721
1722static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1723 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001724 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001725{
1726 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1727 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001728 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001729
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001730 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001731 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001732 for (i = 0; i < spec->num_adc_nids; i++) {
1733 kcontrol->private_value =
1734 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1735 3, 0, HDA_INPUT);
1736 err = func(kcontrol, ucontrol);
1737 if (err < 0)
1738 goto error;
1739 }
1740 } else {
1741 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001742 if (spec->vol_in_capsrc)
1743 kcontrol->private_value =
1744 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1745 3, 0, HDA_OUTPUT);
1746 else
1747 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001748 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1749 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001750 err = func(kcontrol, ucontrol);
1751 }
1752 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001753 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001754 return err;
1755}
1756
1757static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1758 struct snd_ctl_elem_value *ucontrol)
1759{
1760 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001761 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001762}
1763
1764static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1765 struct snd_ctl_elem_value *ucontrol)
1766{
1767 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001768 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001769}
1770
1771/* capture mixer elements */
1772#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1773
1774static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1775 struct snd_ctl_elem_value *ucontrol)
1776{
1777 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001778 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001779}
1780
1781static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1782 struct snd_ctl_elem_value *ucontrol)
1783{
1784 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001785 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001786}
1787
Takashi Iwaia23b6882009-03-23 15:21:36 +01001788#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001789 { \
1790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1791 .name = "Capture Switch", \
1792 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1793 .count = num, \
1794 .info = alc_cap_sw_info, \
1795 .get = alc_cap_sw_get, \
1796 .put = alc_cap_sw_put, \
1797 }, \
1798 { \
1799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1800 .name = "Capture Volume", \
1801 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1802 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1803 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1804 .count = num, \
1805 .info = alc_cap_vol_info, \
1806 .get = alc_cap_vol_get, \
1807 .put = alc_cap_vol_put, \
1808 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001809 }
1810
1811#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001812 { \
1813 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1814 /* .name = "Capture Source", */ \
1815 .name = "Input Source", \
1816 .count = num, \
1817 .info = alc_mux_enum_info, \
1818 .get = alc_mux_enum_get, \
1819 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001820 }
1821
1822#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001823static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001824 _DEFINE_CAPMIX(num), \
1825 _DEFINE_CAPSRC(num), \
1826 { } /* end */ \
1827}
1828
1829#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001830static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001831 _DEFINE_CAPMIX(num), \
1832 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001833}
1834
1835/* up to three ADCs */
1836DEFINE_CAPMIX(1);
1837DEFINE_CAPMIX(2);
1838DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001839DEFINE_CAPMIX_NOSRC(1);
1840DEFINE_CAPMIX_NOSRC(2);
1841DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001842
1843/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001844 * virtual master controls
1845 */
1846
1847/*
1848 * slave controls for virtual master
1849 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001850static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001851 "Front Playback Volume",
1852 "Surround Playback Volume",
1853 "Center Playback Volume",
1854 "LFE Playback Volume",
1855 "Side Playback Volume",
1856 "Headphone Playback Volume",
1857 "Speaker Playback Volume",
1858 "Mono Playback Volume",
Takashi Iwaie49a3432012-03-01 18:14:41 +01001859 "Line Out Playback Volume",
Takashi Iwaib544d1e2012-02-03 11:56:35 +01001860 "CLFE Playback Volume",
1861 "Bass Speaker Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001862 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001863 NULL,
1864};
1865
Takashi Iwaiea734962011-01-17 11:29:34 +01001866static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001867 "Front Playback Switch",
1868 "Surround Playback Switch",
1869 "Center Playback Switch",
1870 "LFE Playback Switch",
1871 "Side Playback Switch",
1872 "Headphone Playback Switch",
1873 "Speaker Playback Switch",
1874 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001875 "IEC958 Playback Switch",
Takashi Iwaie49a3432012-03-01 18:14:41 +01001876 "Line Out Playback Switch",
Takashi Iwaib544d1e2012-02-03 11:56:35 +01001877 "CLFE Playback Switch",
1878 "Bass Speaker Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001879 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001880 NULL,
1881};
1882
1883/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001884 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001886
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001887#define NID_MAPPING (-1)
1888
1889#define SUBDEV_SPEAKER_ (0 << 6)
1890#define SUBDEV_HP_ (1 << 6)
1891#define SUBDEV_LINE_ (2 << 6)
1892#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1893#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1894#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1895
Takashi Iwai603c4012008-07-30 15:01:44 +02001896static void alc_free_kctls(struct hda_codec *codec);
1897
Takashi Iwai67d634c2009-11-16 15:35:59 +01001898#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001899/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001900static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001901 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001902 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001903 { } /* end */
1904};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001905#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001906
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001907static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908{
1909 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001910 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001911 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001912 int i, j, err;
1913 unsigned int u;
1914 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
1916 for (i = 0; i < spec->num_mixers; i++) {
1917 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1918 if (err < 0)
1919 return err;
1920 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001921 if (spec->cap_mixer) {
1922 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1923 if (err < 0)
1924 return err;
1925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001927 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001928 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001929 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 if (err < 0)
1931 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001932 if (!spec->no_analog) {
1933 err = snd_hda_create_spdif_share_sw(codec,
1934 &spec->multiout);
1935 if (err < 0)
1936 return err;
1937 spec->multiout.share_spdif = 1;
1938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 }
1940 if (spec->dig_in_nid) {
1941 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1942 if (err < 0)
1943 return err;
1944 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001945
Takashi Iwai67d634c2009-11-16 15:35:59 +01001946#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001947 /* create beep controls if needed */
1948 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001949 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001950 for (knew = alc_beep_mixer; knew->name; knew++) {
1951 struct snd_kcontrol *kctl;
1952 kctl = snd_ctl_new1(knew, codec);
1953 if (!kctl)
1954 return -ENOMEM;
1955 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001956 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001957 if (err < 0)
1958 return err;
1959 }
1960 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001961#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001962
Takashi Iwai2134ea42008-01-10 16:53:55 +01001963 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001964 if (!spec->no_analog &&
1965 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001966 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001967 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001968 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001969 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001970 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001971 if (err < 0)
1972 return err;
1973 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001974 if (!spec->no_analog &&
1975 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001976 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1977 NULL, alc_slave_sws);
1978 if (err < 0)
1979 return err;
1980 }
1981
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001982 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001983 if (spec->capsrc_nids || spec->adc_nids) {
1984 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1985 if (!kctl)
1986 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1987 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001988 err = snd_hda_add_nid(codec, kctl, i,
1989 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001990 if (err < 0)
1991 return err;
1992 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001993 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001994 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001995 const char *kname = kctl ? kctl->id.name : NULL;
1996 for (knew = spec->cap_mixer; knew->name; knew++) {
1997 if (kname && strcmp(knew->name, kname) == 0)
1998 continue;
1999 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2000 for (i = 0; kctl && i < kctl->count; i++) {
2001 err = snd_hda_add_nid(codec, kctl, i,
2002 spec->adc_nids[i]);
2003 if (err < 0)
2004 return err;
2005 }
2006 }
2007 }
2008
2009 /* other nid->control mapping */
2010 for (i = 0; i < spec->num_mixers; i++) {
2011 for (knew = spec->mixers[i]; knew->name; knew++) {
2012 if (knew->iface != NID_MAPPING)
2013 continue;
2014 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2015 if (kctl == NULL)
2016 continue;
2017 u = knew->subdevice;
2018 for (j = 0; j < 4; j++, u >>= 8) {
2019 nid = u & 0x3f;
2020 if (nid == 0)
2021 continue;
2022 switch (u & 0xc0) {
2023 case SUBDEV_SPEAKER_:
2024 nid = spec->autocfg.speaker_pins[nid];
2025 break;
2026 case SUBDEV_LINE_:
2027 nid = spec->autocfg.line_out_pins[nid];
2028 break;
2029 case SUBDEV_HP_:
2030 nid = spec->autocfg.hp_pins[nid];
2031 break;
2032 default:
2033 continue;
2034 }
2035 err = snd_hda_add_nid(codec, kctl, 0, nid);
2036 if (err < 0)
2037 return err;
2038 }
2039 u = knew->private_value;
2040 for (j = 0; j < 4; j++, u >>= 8) {
2041 nid = u & 0xff;
2042 if (nid == 0)
2043 continue;
2044 err = snd_hda_add_nid(codec, kctl, 0, nid);
2045 if (err < 0)
2046 return err;
2047 }
2048 }
2049 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002050
2051 alc_free_kctls(codec); /* no longer needed */
2052
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002053 return 0;
2054}
2055
2056static int alc_build_controls(struct hda_codec *codec)
2057{
2058 struct alc_spec *spec = codec->spec;
2059 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002060 if (err < 0)
2061 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002062 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063}
2064
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002067 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002068 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002069
Takashi Iwai584c0c42011-03-10 12:51:11 +01002070static void alc_init_special_input_src(struct hda_codec *codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002071static int alc269_fill_coef(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002072
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073static int alc_init(struct hda_codec *codec)
2074{
2075 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002076 unsigned int i;
2077
Kailang Yang526af6e2012-03-07 08:25:20 +01002078 if (codec->vendor_id == 0x10ec0269)
2079 alc269_fill_coef(codec);
2080
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002081 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002082 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002083
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002084 for (i = 0; i < spec->num_init_verbs; i++)
2085 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002086 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002087
2088 if (spec->init_hook)
2089 spec->init_hook(codec);
2090
Takashi Iwai58701122011-01-13 15:41:45 +01002091 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2092
Takashi Iwai01a61e12011-10-28 00:03:22 +02002093 snd_hda_jack_report_sync(codec);
2094
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002095 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 return 0;
2097}
2098
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002099static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2100{
2101 struct alc_spec *spec = codec->spec;
2102
2103 if (spec->unsol_event)
2104 spec->unsol_event(codec, res);
2105}
2106
Takashi Iwaicb53c622007-08-10 17:21:45 +02002107#ifdef CONFIG_SND_HDA_POWER_SAVE
2108static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2109{
2110 struct alc_spec *spec = codec->spec;
2111 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2112}
2113#endif
2114
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115/*
2116 * Analog playback callbacks
2117 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002118static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002120 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121{
2122 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002123 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2124 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002127static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 struct hda_codec *codec,
2129 unsigned int stream_tag,
2130 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002131 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
2133 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002134 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2135 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136}
2137
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002138static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002140 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
2142 struct alc_spec *spec = codec->spec;
2143 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2144}
2145
2146/*
2147 * Digital out
2148 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002149static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002151 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152{
2153 struct alc_spec *spec = codec->spec;
2154 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2155}
2156
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002157static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002158 struct hda_codec *codec,
2159 unsigned int stream_tag,
2160 unsigned int format,
2161 struct snd_pcm_substream *substream)
2162{
2163 struct alc_spec *spec = codec->spec;
2164 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2165 stream_tag, format, substream);
2166}
2167
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002168static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002169 struct hda_codec *codec,
2170 struct snd_pcm_substream *substream)
2171{
2172 struct alc_spec *spec = codec->spec;
2173 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2174}
2175
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002176static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002178 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
2180 struct alc_spec *spec = codec->spec;
2181 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2182}
2183
2184/*
2185 * Analog capture
2186 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002187static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 struct hda_codec *codec,
2189 unsigned int stream_tag,
2190 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002191 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
2193 struct alc_spec *spec = codec->spec;
2194
Takashi Iwai63300792008-01-24 15:31:36 +01002195 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 stream_tag, 0, format);
2197 return 0;
2198}
2199
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002200static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002202 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203{
2204 struct alc_spec *spec = codec->spec;
2205
Takashi Iwai888afa12008-03-18 09:57:50 +01002206 snd_hda_codec_cleanup_stream(codec,
2207 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 return 0;
2209}
2210
Takashi Iwai840b64c2010-07-13 22:49:01 +02002211/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002212static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002213 struct hda_codec *codec,
2214 unsigned int stream_tag,
2215 unsigned int format,
2216 struct snd_pcm_substream *substream)
2217{
2218 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002219 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002220 spec->cur_adc_stream_tag = stream_tag;
2221 spec->cur_adc_format = format;
2222 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2223 return 0;
2224}
2225
Takashi Iwai21268962011-07-07 15:01:13 +02002226static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002227 struct hda_codec *codec,
2228 struct snd_pcm_substream *substream)
2229{
2230 struct alc_spec *spec = codec->spec;
2231 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2232 spec->cur_adc = 0;
2233 return 0;
2234}
2235
Takashi Iwai21268962011-07-07 15:01:13 +02002236static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002237 .substreams = 1,
2238 .channels_min = 2,
2239 .channels_max = 2,
2240 .nid = 0, /* fill later */
2241 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002242 .prepare = dyn_adc_capture_pcm_prepare,
2243 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002244 },
2245};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
2247/*
2248 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002249static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 .substreams = 1,
2251 .channels_min = 2,
2252 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002253 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002255 .open = alc_playback_pcm_open,
2256 .prepare = alc_playback_pcm_prepare,
2257 .cleanup = alc_playback_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_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002262 .substreams = 1,
2263 .channels_min = 2,
2264 .channels_max = 2,
2265 /* NID is set in alc_build_pcms */
2266};
2267
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002268static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002269 .substreams = 1,
2270 .channels_min = 2,
2271 .channels_max = 2,
2272 /* NID is set in alc_build_pcms */
2273};
2274
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002275static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002276 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 .channels_min = 2,
2278 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002279 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002281 .prepare = alc_alt_capture_pcm_prepare,
2282 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 },
2284};
2285
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002286static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 .substreams = 1,
2288 .channels_min = 2,
2289 .channels_max = 2,
2290 /* NID is set in alc_build_pcms */
2291 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002292 .open = alc_dig_playback_pcm_open,
2293 .close = alc_dig_playback_pcm_close,
2294 .prepare = alc_dig_playback_pcm_prepare,
2295 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 },
2297};
2298
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002299static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 .substreams = 1,
2301 .channels_min = 2,
2302 .channels_max = 2,
2303 /* NID is set in alc_build_pcms */
2304};
2305
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002306/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002307static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002308 .substreams = 0,
2309 .channels_min = 0,
2310 .channels_max = 0,
2311};
2312
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313static int alc_build_pcms(struct hda_codec *codec)
2314{
2315 struct alc_spec *spec = codec->spec;
2316 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002317 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002318 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 int i;
2320
2321 codec->num_pcms = 1;
2322 codec->pcm_info = info;
2323
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002324 if (spec->no_analog)
2325 goto skip_analog;
2326
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002327 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2328 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002330
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002331 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002332 p = spec->stream_analog_playback;
2333 if (!p)
2334 p = &alc_pcm_analog_playback;
2335 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002336 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2337 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002338 if (spec->adc_nids) {
2339 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002340 if (!p) {
2341 if (spec->dyn_adc_switch)
2342 p = &dyn_adc_pcm_analog_capture;
2343 else
2344 p = &alc_pcm_analog_capture;
2345 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002346 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002347 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
Takashi Iwai4a471b72005-12-07 13:56:29 +01002350 if (spec->channel_mode) {
2351 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2352 for (i = 0; i < spec->num_channel_mode; i++) {
2353 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2354 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 }
2357 }
2358
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002359 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002360 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002362 snprintf(spec->stream_name_digital,
2363 sizeof(spec->stream_name_digital),
2364 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002365 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002366 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002367 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002369 if (spec->dig_out_type)
2370 info->pcm_type = spec->dig_out_type;
2371 else
2372 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002373 if (spec->multiout.dig_out_nid) {
2374 p = spec->stream_digital_playback;
2375 if (!p)
2376 p = &alc_pcm_digital_playback;
2377 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2379 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002380 if (spec->dig_in_nid) {
2381 p = spec->stream_digital_capture;
2382 if (!p)
2383 p = &alc_pcm_digital_capture;
2384 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2386 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002387 /* FIXME: do we need this for all Realtek codec models? */
2388 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 }
2390
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002391 if (spec->no_analog)
2392 return 0;
2393
Takashi Iwaie08a0072006-09-07 17:52:14 +02002394 /* If the use of more than one ADC is requested for the current
2395 * model, configure a second analog capture-only PCM.
2396 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002397 have_multi_adcs = (spec->num_adc_nids > 1) &&
2398 !spec->dyn_adc_switch && !spec->auto_mic &&
2399 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002400 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002401 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002402 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002403 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002404 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002405 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002406 p = spec->stream_analog_alt_playback;
2407 if (!p)
2408 p = &alc_pcm_analog_alt_playback;
2409 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002410 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2411 spec->alt_dac_nid;
2412 } else {
2413 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2414 alc_pcm_null_stream;
2415 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2416 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002417 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002418 p = spec->stream_analog_alt_capture;
2419 if (!p)
2420 p = &alc_pcm_analog_alt_capture;
2421 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002422 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2423 spec->adc_nids[1];
2424 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2425 spec->num_adc_nids - 1;
2426 } else {
2427 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2428 alc_pcm_null_stream;
2429 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002430 }
2431 }
2432
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 return 0;
2434}
2435
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002436static inline void alc_shutup(struct hda_codec *codec)
2437{
Takashi Iwai1c716152011-04-07 10:37:16 +02002438 struct alc_spec *spec = codec->spec;
2439
2440 if (spec && spec->shutup)
2441 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002442 snd_hda_shutup_pins(codec);
2443}
2444
Takashi Iwai603c4012008-07-30 15:01:44 +02002445static void alc_free_kctls(struct hda_codec *codec)
2446{
2447 struct alc_spec *spec = codec->spec;
2448
2449 if (spec->kctls.list) {
2450 struct snd_kcontrol_new *kctl = spec->kctls.list;
2451 int i;
2452 for (i = 0; i < spec->kctls.used; i++)
2453 kfree(kctl[i].name);
2454 }
2455 snd_array_free(&spec->kctls);
2456}
2457
Takashi Iwai23c09b02011-08-19 09:05:35 +02002458static void alc_free_bind_ctls(struct hda_codec *codec)
2459{
2460 struct alc_spec *spec = codec->spec;
2461 if (spec->bind_ctls.list) {
2462 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2463 int i;
2464 for (i = 0; i < spec->bind_ctls.used; i++)
2465 kfree(ctl[i]);
2466 }
2467 snd_array_free(&spec->bind_ctls);
2468}
2469
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470static void alc_free(struct hda_codec *codec)
2471{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002472 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002473
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002474 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002475 return;
2476
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002477 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002478 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002479 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002480 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002481 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482}
2483
Hector Martinf5de24b2009-12-20 22:51:31 +01002484#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002485static void alc_power_eapd(struct hda_codec *codec)
2486{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002487 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002488}
2489
Hector Martinf5de24b2009-12-20 22:51:31 +01002490static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2491{
2492 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002493 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002494 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002495 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002496 return 0;
2497}
2498#endif
2499
Takashi Iwai2a439522011-07-26 09:52:50 +02002500#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002501static int alc_resume(struct hda_codec *codec)
2502{
Takashi Iwai1c716152011-04-07 10:37:16 +02002503 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002504 codec->patch_ops.init(codec);
2505 snd_hda_codec_resume_amp(codec);
2506 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002507 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002508 return 0;
2509}
Takashi Iwaie044c392008-10-27 16:56:24 +01002510#endif
2511
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512/*
2513 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002514static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 .build_controls = alc_build_controls,
2516 .build_pcms = alc_build_pcms,
2517 .init = alc_init,
2518 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002519 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002520#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002521 .resume = alc_resume,
2522#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002523#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002524 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002525 .check_power_status = alc_check_power_status,
2526#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002527 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528};
2529
Kailang Yangc027ddc2010-03-19 11:33:06 +01002530/* replace the codec chip_name with the given string */
2531static int alc_codec_rename(struct hda_codec *codec, const char *name)
2532{
2533 kfree(codec->chip_name);
2534 codec->chip_name = kstrdup(name, GFP_KERNEL);
2535 if (!codec->chip_name) {
2536 alc_free(codec);
2537 return -ENOMEM;
2538 }
2539 return 0;
2540}
2541
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002542/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002543 * Rename codecs appropriately from COEF value
2544 */
2545struct alc_codec_rename_table {
2546 unsigned int vendor_id;
2547 unsigned short coef_mask;
2548 unsigned short coef_bits;
2549 const char *name;
2550};
2551
2552static struct alc_codec_rename_table rename_tbl[] = {
2553 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2554 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2555 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2556 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2557 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2558 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2559 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2560 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2561 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2562 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2563 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2564 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2565 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2566 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2567 { } /* terminator */
2568};
2569
2570static int alc_codec_rename_from_preset(struct hda_codec *codec)
2571{
2572 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002573
2574 for (p = rename_tbl; p->vendor_id; p++) {
2575 if (p->vendor_id != codec->vendor_id)
2576 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002577 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002578 return alc_codec_rename(codec, p->name);
2579 }
2580 return 0;
2581}
2582
2583/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002584 * Automatic parse of I/O pins from the BIOS configuration
2585 */
2586
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002587enum {
2588 ALC_CTL_WIDGET_VOL,
2589 ALC_CTL_WIDGET_MUTE,
2590 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002591 ALC_CTL_BIND_VOL,
2592 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002593};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002594static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002595 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2596 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002597 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002598 HDA_BIND_VOL(NULL, 0),
2599 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002600};
2601
2602/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002603static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002604 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002605{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002606 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002607
Takashi Iwaice764ab2011-04-27 16:35:23 +02002608 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002609 if (!knew)
2610 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002611 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002612 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002613 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002614 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002615 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002616 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002617 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002618 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002619 return 0;
2620}
2621
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002622static int add_control_with_pfx(struct alc_spec *spec, int type,
2623 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002624 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002625{
2626 char name[32];
2627 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002628 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002629}
2630
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002631#define add_pb_vol_ctrl(spec, type, pfx, val) \
2632 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2633#define add_pb_sw_ctrl(spec, type, pfx, val) \
2634 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2635#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2636 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2637#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2638 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002639
Takashi Iwai23c09b02011-08-19 09:05:35 +02002640static const char * const channel_name[4] = {
2641 "Front", "Surround", "CLFE", "Side"
2642};
2643
Takashi Iwai6843ca12011-06-24 11:03:58 +02002644static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2645 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002646{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002647 struct auto_pin_cfg *cfg = &spec->autocfg;
2648
Takashi Iwai6843ca12011-06-24 11:03:58 +02002649 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002650 if (cfg->line_outs == 1 && !spec->multi_ios &&
2651 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002652 return "Master";
2653
2654 switch (cfg->line_out_type) {
2655 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002656 if (cfg->line_outs == 1)
2657 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002658 if (cfg->line_outs == 2)
2659 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002660 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002661 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002662 /* for multi-io case, only the primary out */
2663 if (ch && spec->multi_ios)
2664 break;
2665 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002666 return "Headphone";
2667 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002668 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002669 return "PCM";
2670 break;
2671 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002672 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2673 return "PCM";
2674
2675 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002676}
2677
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002678/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002679static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002680 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002681 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002682{
Kailang Yangdf694da2005-12-05 19:42:22 +01002683 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002684
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002685 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002686 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2687 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002688 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002689 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002690 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2691 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002692 return err;
2693 return 0;
2694}
2695
Takashi Iwai05f5f472009-08-25 13:10:18 +02002696static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002697{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002698 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2699 return (pincap & AC_PINCAP_IN) != 0;
2700}
2701
Takashi Iwai1d045db2011-07-07 18:23:21 +02002702/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002703static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002704{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002705 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002706 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002707 hda_nid_t *adc_nids = spec->private_adc_nids;
2708 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2709 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002710 int i, nums = 0;
2711
Takashi Iwai24de1832011-11-07 17:13:39 +01002712 if (spec->shared_mic_hp)
2713 max_nums = 1; /* no multi streams with the shared HP/mic */
2714
Takashi Iwaib7821702011-07-06 15:12:46 +02002715 nid = codec->start_nid;
2716 for (i = 0; i < codec->num_nodes; i++, nid++) {
2717 hda_nid_t src;
2718 const hda_nid_t *list;
2719 unsigned int caps = get_wcaps(codec, nid);
2720 int type = get_wcaps_type(caps);
2721
2722 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2723 continue;
2724 adc_nids[nums] = nid;
2725 cap_nids[nums] = nid;
2726 src = nid;
2727 for (;;) {
2728 int n;
2729 type = get_wcaps_type(get_wcaps(codec, src));
2730 if (type == AC_WID_PIN)
2731 break;
2732 if (type == AC_WID_AUD_SEL) {
2733 cap_nids[nums] = src;
2734 break;
2735 }
2736 n = snd_hda_get_conn_list(codec, src, &list);
2737 if (n > 1) {
2738 cap_nids[nums] = src;
2739 break;
2740 } else if (n != 1)
2741 break;
2742 src = *list;
2743 }
2744 if (++nums >= max_nums)
2745 break;
2746 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002747 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002748 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002749 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002750 return nums;
2751}
2752
Takashi Iwai05f5f472009-08-25 13:10:18 +02002753/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002754static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002755{
2756 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002757 const struct auto_pin_cfg *cfg = &spec->autocfg;
2758 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002759 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002760 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002761 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002762 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002763
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002764 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002765 if (num_adcs < 0)
2766 return 0;
2767
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002768 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002769 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002770 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002771
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002772 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002773 if (!alc_is_input_pin(codec, pin))
2774 continue;
2775
David Henningsson5322bf22011-01-05 11:03:56 +01002776 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002777 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2778 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002779 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002780 type_idx++;
2781 else
2782 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002783 prev_label = label;
2784
Takashi Iwai05f5f472009-08-25 13:10:18 +02002785 if (mixer) {
2786 idx = get_connection_index(codec, mixer, pin);
2787 if (idx >= 0) {
2788 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002789 label, type_idx,
2790 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002791 if (err < 0)
2792 return err;
2793 }
2794 }
2795
Takashi Iwaib7821702011-07-06 15:12:46 +02002796 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002797 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002798 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002799 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002800 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002801 snd_hda_add_imux_item(imux, label, idx, NULL);
2802 break;
2803 }
2804 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002805 }
Takashi Iwai21268962011-07-07 15:01:13 +02002806
2807 spec->num_mux_defs = 1;
2808 spec->input_mux = imux;
2809
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002810 return 0;
2811}
2812
Takashi Iwai24de1832011-11-07 17:13:39 +01002813/* create a shared input with the headphone out */
2814static int alc_auto_create_shared_input(struct hda_codec *codec)
2815{
2816 struct alc_spec *spec = codec->spec;
2817 struct auto_pin_cfg *cfg = &spec->autocfg;
2818 unsigned int defcfg;
2819 hda_nid_t nid;
2820
2821 /* only one internal input pin? */
2822 if (cfg->num_inputs != 1)
2823 return 0;
2824 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2825 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2826 return 0;
2827
2828 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2829 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2830 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2831 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2832 else
2833 return 0; /* both not available */
2834
2835 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2836 return 0; /* no input */
2837
2838 cfg->inputs[1].pin = nid;
2839 cfg->inputs[1].type = AUTO_PIN_MIC;
2840 cfg->num_inputs = 2;
2841 spec->shared_mic_hp = 1;
2842 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2843 return 0;
2844}
2845
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002846static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2847 unsigned int pin_type)
2848{
2849 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2850 pin_type);
2851 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002852 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2853 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002854 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002855}
2856
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002857static int get_pin_type(int line_out_type)
2858{
2859 if (line_out_type == AUTO_PIN_HP_OUT)
2860 return PIN_HP;
2861 else
2862 return PIN_OUT;
2863}
2864
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002865static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002866{
2867 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002868 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002869 int i;
2870
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002871 for (i = 0; i < cfg->num_inputs; i++) {
2872 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002873 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002874 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002875 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002876 snd_hda_codec_write(codec, nid, 0,
2877 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002878 AMP_OUT_MUTE);
2879 }
2880 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002881
2882 /* mute all loopback inputs */
2883 if (spec->mixer_nid) {
2884 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2885 for (i = 0; i < nums; i++)
2886 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2887 AC_VERB_SET_AMP_GAIN_MUTE,
2888 AMP_IN_MUTE(i));
2889 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002890}
2891
Takashi Iwai7085ec12009-10-02 09:03:58 +02002892/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002893static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002894{
Takashi Iwai604401a2011-04-27 15:14:23 +02002895 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002896 int i, num;
2897
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002898 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2899 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002900 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2901 for (i = 0; i < num; i++) {
2902 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2903 return list[i];
2904 }
2905 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002906}
2907
Takashi Iwai604401a2011-04-27 15:14:23 +02002908/* go down to the selector widget before the mixer */
2909static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2910{
2911 hda_nid_t srcs[5];
2912 int num = snd_hda_get_connections(codec, pin, srcs,
2913 ARRAY_SIZE(srcs));
2914 if (num != 1 ||
2915 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2916 return pin;
2917 return srcs[0];
2918}
2919
Takashi Iwai7085ec12009-10-02 09:03:58 +02002920/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002921static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002922 hda_nid_t dac)
2923{
David Henningssoncc1c4522010-11-24 14:17:47 +01002924 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002925 int i, num;
2926
Takashi Iwai604401a2011-04-27 15:14:23 +02002927 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002928 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2929 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002930 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002931 return mix[i];
2932 }
2933 return 0;
2934}
2935
Takashi Iwaice764ab2011-04-27 16:35:23 +02002936/* select the connection from pin to DAC if needed */
2937static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2938 hda_nid_t dac)
2939{
2940 hda_nid_t mix[5];
2941 int i, num;
2942
2943 pin = alc_go_down_to_selector(codec, pin);
2944 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2945 if (num < 2)
2946 return 0;
2947 for (i = 0; i < num; i++) {
2948 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2949 snd_hda_codec_update_cache(codec, pin, 0,
2950 AC_VERB_SET_CONNECT_SEL, i);
2951 return 0;
2952 }
2953 }
2954 return 0;
2955}
2956
Takashi Iwai7085ec12009-10-02 09:03:58 +02002957/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002958static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002959{
2960 struct alc_spec *spec = codec->spec;
2961 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002962 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002963
Takashi Iwai604401a2011-04-27 15:14:23 +02002964 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002965 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002966 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002967 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002968 if (!nid)
2969 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002970 if (found_in_nid_list(nid, spec->multiout.dac_nids,
Takashi Iwai0a34b422011-12-07 17:20:30 +01002971 ARRAY_SIZE(spec->private_dac_nids)))
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002972 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002973 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2974 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2975 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002976 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2977 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2978 continue;
2979 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002980 }
2981 return 0;
2982}
2983
Takashi Iwai07b18f692011-11-10 15:42:54 +01002984/* check whether the DAC is reachable from the pin */
2985static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2986 hda_nid_t pin, hda_nid_t dac)
2987{
2988 hda_nid_t srcs[5];
2989 int i, num;
2990
2991 pin = alc_go_down_to_selector(codec, pin);
2992 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2993 for (i = 0; i < num; i++) {
2994 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2995 if (nid == dac)
2996 return true;
2997 }
2998 return false;
2999}
3000
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003001static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3002{
3003 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
3004 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
3005 return alc_auto_look_for_dac(codec, pin);
3006 return 0;
3007}
3008
Takashi Iwai0a34b422011-12-07 17:20:30 +01003009/* return 0 if no possible DAC is found, 1 if one or more found */
Takashi Iwaic2674682011-08-24 17:57:44 +02003010static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3011 const hda_nid_t *pins, hda_nid_t *dacs)
3012{
3013 int i;
3014
3015 if (num_outs && !dacs[0]) {
3016 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3017 if (!dacs[0])
3018 return 0;
3019 }
3020
3021 for (i = 1; i < num_outs; i++)
3022 dacs[i] = get_dac_if_single(codec, pins[i]);
3023 for (i = 1; i < num_outs; i++) {
3024 if (!dacs[i])
3025 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3026 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003027 return 1;
Takashi Iwaic2674682011-08-24 17:57:44 +02003028}
3029
3030static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f692011-11-10 15:42:54 +01003031 unsigned int location, int offset);
David Henningssonfde48a12011-12-09 18:27:42 +08003032static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3033 hda_nid_t pin, hda_nid_t dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003034
Takashi Iwai7085ec12009-10-02 09:03:58 +02003035/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003036static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003037{
3038 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003039 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f692011-11-10 15:42:54 +01003040 unsigned int location, defcfg;
3041 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003042 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003043 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003044
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003045 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003046 /* set num_dacs once to full for alc_auto_look_for_dac() */
3047 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003048 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003049 spec->multiout.extra_out_nid[0] = 0;
3050 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3051 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003052 spec->multi_ios = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003053
3054 /* fill hard-wired DACs first */
3055 if (!redone) {
3056 for (i = 0; i < cfg->line_outs; i++)
3057 spec->private_dac_nids[i] =
3058 get_dac_if_single(codec, cfg->line_out_pins[i]);
3059 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003060 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003061 get_dac_if_single(codec, cfg->hp_pins[0]);
3062 if (cfg->speaker_outs)
3063 spec->multiout.extra_out_nid[0] =
3064 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003065 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003066
3067 for (i = 0; i < cfg->line_outs; i++) {
3068 hda_nid_t pin = cfg->line_out_pins[i];
3069 if (spec->private_dac_nids[i])
3070 continue;
3071 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3072 if (!spec->private_dac_nids[i] && !redone) {
3073 /* if we can't find primary DACs, re-probe without
3074 * checking the hard-wired DACs
3075 */
3076 redone = true;
3077 goto again;
3078 }
3079 }
3080
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003081 /* re-count num_dacs and squash invalid entries */
3082 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003083 for (i = 0; i < cfg->line_outs; i++) {
3084 if (spec->private_dac_nids[i])
3085 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003086 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003087 memmove(spec->private_dac_nids + i,
3088 spec->private_dac_nids + i + 1,
3089 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003090 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3091 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003092 }
3093
Takashi Iwaic2674682011-08-24 17:57:44 +02003094 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3095 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003096 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3097 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003098
Takashi Iwai07b18f692011-11-10 15:42:54 +01003099 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003100 if (num_pins > 0) {
3101 spec->multi_ios = num_pins;
3102 spec->ext_channel_count = 2;
3103 spec->multiout.num_dacs = num_pins + 1;
3104 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003105 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003106
Takashi Iwai716eef02011-10-21 15:07:42 +02003107 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3108 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003109 spec->multiout.hp_out_nid);
Takashi Iwai0a34b422011-12-07 17:20:30 +01003110 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3111 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3112 cfg->speaker_pins,
3113 spec->multiout.extra_out_nid);
3114 /* if no speaker volume is assigned, try again as the primary
3115 * output
3116 */
3117 if (!err && cfg->speaker_outs > 0 &&
3118 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3119 cfg->hp_outs = cfg->line_outs;
3120 memcpy(cfg->hp_pins, cfg->line_out_pins,
3121 sizeof(cfg->hp_pins));
3122 cfg->line_outs = cfg->speaker_outs;
3123 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3124 sizeof(cfg->speaker_pins));
3125 cfg->speaker_outs = 0;
3126 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3127 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3128 redone = false;
3129 goto again;
3130 }
3131 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003132
Takashi Iwai07b18f692011-11-10 15:42:54 +01003133 if (!spec->multi_ios &&
3134 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3135 cfg->hp_outs) {
3136 /* try multi-ios with HP + inputs */
3137 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3138 location = get_defcfg_location(defcfg);
3139
3140 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3141 if (num_pins > 0) {
3142 spec->multi_ios = num_pins;
3143 spec->ext_channel_count = 2;
3144 spec->multiout.num_dacs = num_pins + 1;
3145 }
3146 }
3147
David Henningssonfde48a12011-12-09 18:27:42 +08003148 if (cfg->line_out_pins[0])
3149 spec->vmaster_nid =
3150 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3151 spec->multiout.dac_nids[0]);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003152 return 0;
3153}
3154
Takashi Iwai527e4d72011-10-27 16:33:27 +02003155static inline unsigned int get_ctl_pos(unsigned int data)
3156{
3157 hda_nid_t nid = get_amp_nid_(data);
Takashi Iwaic14c95f2012-02-16 16:38:07 +01003158 unsigned int dir;
3159 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3160 return 0;
3161 dir = get_amp_direction_(data);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003162 return (nid << 1) | dir;
3163}
3164
3165#define is_ctl_used(bits, data) \
3166 test_bit(get_ctl_pos(data), bits)
3167#define mark_ctl_usage(bits, data) \
3168 set_bit(get_ctl_pos(data), bits)
3169
Takashi Iwai343a04b2011-07-06 14:28:39 +02003170static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003171 const char *pfx, int cidx,
3172 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003173{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003174 struct alc_spec *spec = codec->spec;
3175 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003176 if (!nid)
3177 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003178 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3179 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3180 return 0;
3181 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003182 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003183 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003184}
3185
Takashi Iwaie29d3772011-11-14 17:13:23 +01003186static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3187 const char *pfx, int cidx,
3188 hda_nid_t nid)
3189{
3190 int chs = 1;
3191 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3192 chs = 3;
3193 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3194}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003195
3196/* create a mute-switch for the given mixer widget;
3197 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3198 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003199static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003200 const char *pfx, int cidx,
3201 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003202{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003203 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003204 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003205 int type;
3206 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003207 if (!nid)
3208 return 0;
3209 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3210 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3211 type = ALC_CTL_WIDGET_MUTE;
3212 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3213 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003214 type = ALC_CTL_WIDGET_MUTE;
3215 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3216 } else {
3217 type = ALC_CTL_BIND_MUTE;
3218 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3219 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003220 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3221 return 0;
3222 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003223 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003224}
3225
Takashi Iwaie29d3772011-11-14 17:13:23 +01003226static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3227 int cidx, hda_nid_t nid)
3228{
3229 int chs = 1;
3230 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3231 chs = 3;
3232 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3233}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003234
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003235static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3236 hda_nid_t pin, hda_nid_t dac)
3237{
3238 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3239 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3240 return pin;
3241 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3242 return mix;
3243 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3244 return dac;
3245 return 0;
3246}
3247
3248static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3249 hda_nid_t pin, hda_nid_t dac)
3250{
3251 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3252 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3253 return dac;
3254 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3255 return mix;
3256 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3257 return pin;
3258 return 0;
3259}
3260
Takashi Iwai7085ec12009-10-02 09:03:58 +02003261/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003262static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003263 const struct auto_pin_cfg *cfg)
3264{
3265 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003266 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003267
Takashi Iwaice764ab2011-04-27 16:35:23 +02003268 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003269 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003270 noutputs += spec->multi_ios;
3271
3272 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003273 const char *name;
3274 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003275 hda_nid_t dac, pin;
3276 hda_nid_t sw, vol;
3277
3278 dac = spec->multiout.dac_nids[i];
3279 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003280 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003281 if (i >= cfg->line_outs)
3282 pin = spec->multi_io[i - 1].pin;
3283 else
3284 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003285
3286 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3287 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003288 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003289 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003290 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003291 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003292 if (err < 0)
3293 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003294 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003295 if (err < 0)
3296 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003297 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003298 if (err < 0)
3299 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003300 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003301 if (err < 0)
3302 return err;
3303 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003304 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003305 if (err < 0)
3306 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003307 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003308 if (err < 0)
3309 return err;
3310 }
3311 }
3312 return 0;
3313}
3314
Takashi Iwai343a04b2011-07-06 14:28:39 +02003315static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003316 hda_nid_t dac, const char *pfx,
3317 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003318{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003319 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003320 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003321 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003322
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003323 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003324 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003325 /* the corresponding DAC is already occupied */
3326 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3327 return 0; /* no way */
3328 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003329 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3330 if (is_ctl_used(spec->sw_ctls, val))
3331 return 0; /* already created */
3332 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003333 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003334 }
3335
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003336 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3337 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003338 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003339 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003340 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003341 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003342 if (err < 0)
3343 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003344 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003345}
3346
Takashi Iwai23c09b02011-08-19 09:05:35 +02003347static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3348 unsigned int nums,
3349 struct hda_ctl_ops *ops)
3350{
3351 struct alc_spec *spec = codec->spec;
3352 struct hda_bind_ctls **ctlp, *ctl;
3353 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3354 ctlp = snd_array_new(&spec->bind_ctls);
3355 if (!ctlp)
3356 return NULL;
3357 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3358 *ctlp = ctl;
3359 if (ctl)
3360 ctl->ops = ops;
3361 return ctl;
3362}
3363
3364/* add playback controls for speaker and HP outputs */
3365static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3366 const hda_nid_t *pins,
3367 const hda_nid_t *dacs,
3368 const char *pfx)
3369{
3370 struct alc_spec *spec = codec->spec;
3371 struct hda_bind_ctls *ctl;
3372 char name[32];
3373 int i, n, err;
3374
3375 if (!num_pins || !pins[0])
3376 return 0;
3377
Takashi Iwai527e4d72011-10-27 16:33:27 +02003378 if (num_pins == 1) {
3379 hda_nid_t dac = *dacs;
3380 if (!dac)
3381 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003382 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003383 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003384
3385 if (dacs[num_pins - 1]) {
3386 /* OK, we have a multi-output system with individual volumes */
3387 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003388 if (num_pins >= 3) {
3389 snprintf(name, sizeof(name), "%s %s",
3390 pfx, channel_name[i]);
3391 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3392 name, 0);
3393 } else {
3394 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3395 pfx, i);
3396 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003397 if (err < 0)
3398 return err;
3399 }
3400 return 0;
3401 }
3402
3403 /* Let's create a bind-controls */
3404 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3405 if (!ctl)
3406 return -ENOMEM;
3407 n = 0;
3408 for (i = 0; i < num_pins; i++) {
3409 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3410 ctl->values[n++] =
3411 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3412 }
3413 if (n) {
3414 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3415 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3416 if (err < 0)
3417 return err;
3418 }
3419
3420 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3421 if (!ctl)
3422 return -ENOMEM;
3423 n = 0;
3424 for (i = 0; i < num_pins; i++) {
3425 hda_nid_t vol;
3426 if (!pins[i] || !dacs[i])
3427 continue;
3428 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3429 if (vol)
3430 ctl->values[n++] =
3431 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3432 }
3433 if (n) {
3434 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3435 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3436 if (err < 0)
3437 return err;
3438 }
3439 return 0;
3440}
3441
Takashi Iwai343a04b2011-07-06 14:28:39 +02003442static int alc_auto_create_hp_out(struct hda_codec *codec)
3443{
3444 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003445 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3446 spec->autocfg.hp_pins,
3447 spec->multiout.hp_out_nid,
3448 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003449}
3450
3451static int alc_auto_create_speaker_out(struct hda_codec *codec)
3452{
3453 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003454 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3455 spec->autocfg.speaker_pins,
3456 spec->multiout.extra_out_nid,
3457 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003458}
3459
Takashi Iwai343a04b2011-07-06 14:28:39 +02003460static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003461 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003462 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003463{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003464 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003465 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003466 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003467
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003468 alc_set_pin_output(codec, pin, pin_type);
3469 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003470 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003471 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003472 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003473 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003474 mix = srcs[i];
3475 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003476 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003477 if (!mix)
3478 return;
3479
3480 /* need the manual connection? */
3481 if (num > 1)
3482 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3483 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003484 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3485 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003486 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003487 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003488 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003489 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003490 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003491 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3492 if (nid)
3493 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3494 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003495
3496 /* unmute DAC if it's not assigned to a mixer */
3497 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3498 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3499 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3500 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003501}
3502
Takashi Iwai343a04b2011-07-06 14:28:39 +02003503static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003504{
3505 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003506 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003507 int i;
3508
3509 for (i = 0; i <= HDA_SIDE; i++) {
3510 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3511 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003512 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003513 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003514 }
3515}
3516
Takashi Iwai343a04b2011-07-06 14:28:39 +02003517static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003518{
3519 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003520 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003521 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003522
David Henningsson636030e2011-10-12 19:26:03 +02003523 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003524 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3525 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003526 pin = spec->autocfg.hp_pins[i];
3527 if (!pin)
3528 break;
3529 dac = spec->multiout.hp_out_nid[i];
3530 if (!dac) {
3531 if (i > 0 && spec->multiout.hp_out_nid[0])
3532 dac = spec->multiout.hp_out_nid[0];
3533 else
3534 dac = spec->multiout.dac_nids[0];
3535 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003536 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3537 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003538 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003539 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3540 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003541 pin = spec->autocfg.speaker_pins[i];
3542 if (!pin)
3543 break;
3544 dac = spec->multiout.extra_out_nid[i];
3545 if (!dac) {
3546 if (i > 0 && spec->multiout.extra_out_nid[0])
3547 dac = spec->multiout.extra_out_nid[0];
3548 else
3549 dac = spec->multiout.dac_nids[0];
3550 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003551 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3552 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003553}
3554
Takashi Iwaice764ab2011-04-27 16:35:23 +02003555/*
3556 * multi-io helper
3557 */
3558static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f692011-11-10 15:42:54 +01003559 unsigned int location,
3560 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003561{
3562 struct alc_spec *spec = codec->spec;
3563 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003564 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f692011-11-10 15:42:54 +01003565 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003566
Takashi Iwai07b18f692011-11-10 15:42:54 +01003567 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003568 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3569 for (i = 0; i < cfg->num_inputs; i++) {
3570 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f692011-11-10 15:42:54 +01003571 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003572 unsigned int defcfg, caps;
3573 if (cfg->inputs[i].type != type)
3574 continue;
3575 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3576 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3577 continue;
3578 if (location && get_defcfg_location(defcfg) != location)
3579 continue;
3580 caps = snd_hda_query_pin_caps(codec, nid);
3581 if (!(caps & AC_PINCAP_OUT))
3582 continue;
Takashi Iwai07b18f692011-11-10 15:42:54 +01003583 if (offset && offset + num_pins < dacs) {
3584 dac = spec->private_dac_nids[offset + num_pins];
3585 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3586 dac = 0;
3587 }
3588 if (!dac)
3589 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003590 if (!dac)
3591 continue;
3592 spec->multi_io[num_pins].pin = nid;
3593 spec->multi_io[num_pins].dac = dac;
3594 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003595 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003596 }
3597 }
Takashi Iwai07b18f692011-11-10 15:42:54 +01003598 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003599 if (num_pins < 2) {
3600 /* clear up again */
Takashi Iwai07b18f692011-11-10 15:42:54 +01003601 memset(spec->private_dac_nids + dacs, 0,
3602 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003603 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003604 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003605 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003606 return num_pins;
3607}
3608
3609static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3610 struct snd_ctl_elem_info *uinfo)
3611{
3612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3613 struct alc_spec *spec = codec->spec;
3614
3615 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3616 uinfo->count = 1;
3617 uinfo->value.enumerated.items = spec->multi_ios + 1;
3618 if (uinfo->value.enumerated.item > spec->multi_ios)
3619 uinfo->value.enumerated.item = spec->multi_ios;
3620 sprintf(uinfo->value.enumerated.name, "%dch",
3621 (uinfo->value.enumerated.item + 1) * 2);
3622 return 0;
3623}
3624
3625static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3626 struct snd_ctl_elem_value *ucontrol)
3627{
3628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3629 struct alc_spec *spec = codec->spec;
3630 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3631 return 0;
3632}
3633
3634static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3635{
3636 struct alc_spec *spec = codec->spec;
3637 hda_nid_t nid = spec->multi_io[idx].pin;
3638
3639 if (!spec->multi_io[idx].ctl_in)
3640 spec->multi_io[idx].ctl_in =
3641 snd_hda_codec_read(codec, nid, 0,
3642 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3643 if (output) {
3644 snd_hda_codec_update_cache(codec, nid, 0,
3645 AC_VERB_SET_PIN_WIDGET_CONTROL,
3646 PIN_OUT);
3647 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3648 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3649 HDA_AMP_MUTE, 0);
3650 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3651 } else {
3652 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3653 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3654 HDA_AMP_MUTE, HDA_AMP_MUTE);
3655 snd_hda_codec_update_cache(codec, nid, 0,
3656 AC_VERB_SET_PIN_WIDGET_CONTROL,
3657 spec->multi_io[idx].ctl_in);
3658 }
3659 return 0;
3660}
3661
3662static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3663 struct snd_ctl_elem_value *ucontrol)
3664{
3665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3666 struct alc_spec *spec = codec->spec;
3667 int i, ch;
3668
3669 ch = ucontrol->value.enumerated.item[0];
3670 if (ch < 0 || ch > spec->multi_ios)
3671 return -EINVAL;
3672 if (ch == (spec->ext_channel_count - 1) / 2)
3673 return 0;
3674 spec->ext_channel_count = (ch + 1) * 2;
3675 for (i = 0; i < spec->multi_ios; i++)
3676 alc_set_multi_io(codec, i, i < ch);
3677 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003678 if (spec->need_dac_fix && !spec->const_channel_count)
3679 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003680 return 1;
3681}
3682
Takashi Iwaia9111322011-05-02 11:30:18 +02003683static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003684 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3685 .name = "Channel Mode",
3686 .info = alc_auto_ch_mode_info,
3687 .get = alc_auto_ch_mode_get,
3688 .put = alc_auto_ch_mode_put,
3689};
3690
Takashi Iwai23c09b02011-08-19 09:05:35 +02003691static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003692{
3693 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003694
Takashi Iwaic2674682011-08-24 17:57:44 +02003695 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003696 struct snd_kcontrol_new *knew;
3697
3698 knew = alc_kcontrol_new(spec);
3699 if (!knew)
3700 return -ENOMEM;
3701 *knew = alc_auto_channel_mode_enum;
3702 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3703 if (!knew->name)
3704 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003705 }
3706 return 0;
3707}
3708
Takashi Iwai1d045db2011-07-07 18:23:21 +02003709/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3710 * active input pins
3711 */
3712static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3713{
3714 struct alc_spec *spec = codec->spec;
3715 const struct hda_input_mux *imux;
3716 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3717 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3718 int i, n, nums;
3719
3720 imux = spec->input_mux;
3721 if (!imux)
3722 return;
3723 if (spec->dyn_adc_switch)
3724 return;
3725
3726 nums = 0;
3727 for (n = 0; n < spec->num_adc_nids; n++) {
3728 hda_nid_t cap = spec->private_capsrc_nids[n];
3729 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3730 for (i = 0; i < imux->num_items; i++) {
3731 hda_nid_t pin = spec->imux_pins[i];
3732 if (pin) {
3733 if (get_connection_index(codec, cap, pin) < 0)
3734 break;
3735 } else if (num_conns <= imux->items[i].index)
3736 break;
3737 }
3738 if (i >= imux->num_items) {
3739 adc_nids[nums] = spec->private_adc_nids[n];
3740 capsrc_nids[nums++] = cap;
3741 }
3742 }
3743 if (!nums) {
3744 /* check whether ADC-switch is possible */
3745 if (!alc_check_dyn_adc_switch(codec)) {
3746 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3747 " using fallback 0x%x\n",
3748 codec->chip_name, spec->private_adc_nids[0]);
3749 spec->num_adc_nids = 1;
3750 spec->auto_mic = 0;
3751 return;
3752 }
3753 } else if (nums != spec->num_adc_nids) {
3754 memcpy(spec->private_adc_nids, adc_nids,
3755 nums * sizeof(hda_nid_t));
3756 memcpy(spec->private_capsrc_nids, capsrc_nids,
3757 nums * sizeof(hda_nid_t));
3758 spec->num_adc_nids = nums;
3759 }
3760
3761 if (spec->auto_mic)
3762 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3763 else if (spec->input_mux->num_items == 1)
3764 spec->num_adc_nids = 1; /* reduce to a single ADC */
3765}
3766
3767/*
3768 * initialize ADC paths
3769 */
3770static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3771{
3772 struct alc_spec *spec = codec->spec;
3773 hda_nid_t nid;
3774
3775 nid = spec->adc_nids[adc_idx];
3776 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003777 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003778 snd_hda_codec_write(codec, nid, 0,
3779 AC_VERB_SET_AMP_GAIN_MUTE,
3780 AMP_IN_MUTE(0));
3781 return;
3782 }
3783 if (!spec->capsrc_nids)
3784 return;
3785 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003786 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003787 snd_hda_codec_write(codec, nid, 0,
3788 AC_VERB_SET_AMP_GAIN_MUTE,
3789 AMP_OUT_MUTE);
3790}
3791
3792static void alc_auto_init_input_src(struct hda_codec *codec)
3793{
3794 struct alc_spec *spec = codec->spec;
3795 int c, nums;
3796
3797 for (c = 0; c < spec->num_adc_nids; c++)
3798 alc_auto_init_adc(codec, c);
3799 if (spec->dyn_adc_switch)
3800 nums = 1;
3801 else
3802 nums = spec->num_adc_nids;
3803 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01003804 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003805}
3806
3807/* add mic boosts if needed */
3808static int alc_auto_add_mic_boost(struct hda_codec *codec)
3809{
3810 struct alc_spec *spec = codec->spec;
3811 struct auto_pin_cfg *cfg = &spec->autocfg;
3812 int i, err;
3813 int type_idx = 0;
3814 hda_nid_t nid;
3815 const char *prev_label = NULL;
3816
3817 for (i = 0; i < cfg->num_inputs; i++) {
3818 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3819 break;
3820 nid = cfg->inputs[i].pin;
3821 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3822 const char *label;
3823 char boost_label[32];
3824
3825 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003826 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3827 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003828 if (prev_label && !strcmp(label, prev_label))
3829 type_idx++;
3830 else
3831 type_idx = 0;
3832 prev_label = label;
3833
3834 snprintf(boost_label, sizeof(boost_label),
3835 "%s Boost Volume", label);
3836 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3837 boost_label, type_idx,
3838 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3839 if (err < 0)
3840 return err;
3841 }
3842 }
3843 return 0;
3844}
3845
3846/* select or unmute the given capsrc route */
3847static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3848 int idx)
3849{
3850 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3851 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3852 HDA_AMP_MUTE, 0);
3853 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3854 snd_hda_codec_write_cache(codec, cap, 0,
3855 AC_VERB_SET_CONNECT_SEL, idx);
3856 }
3857}
3858
3859/* set the default connection to that pin */
3860static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3861{
3862 struct alc_spec *spec = codec->spec;
3863 int i;
3864
3865 if (!pin)
3866 return 0;
3867 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01003868 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003869 int idx;
3870
3871 idx = get_connection_index(codec, cap, pin);
3872 if (idx < 0)
3873 continue;
3874 select_or_unmute_capsrc(codec, cap, idx);
3875 return i; /* return the found index */
3876 }
3877 return -1; /* not found */
3878}
3879
3880/* initialize some special cases for input sources */
3881static void alc_init_special_input_src(struct hda_codec *codec)
3882{
3883 struct alc_spec *spec = codec->spec;
3884 int i;
3885
3886 for (i = 0; i < spec->autocfg.num_inputs; i++)
3887 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3888}
3889
3890/* assign appropriate capture mixers */
3891static void set_capture_mixer(struct hda_codec *codec)
3892{
3893 struct alc_spec *spec = codec->spec;
3894 static const struct snd_kcontrol_new *caps[2][3] = {
3895 { alc_capture_mixer_nosrc1,
3896 alc_capture_mixer_nosrc2,
3897 alc_capture_mixer_nosrc3 },
3898 { alc_capture_mixer1,
3899 alc_capture_mixer2,
3900 alc_capture_mixer3 },
3901 };
3902
3903 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003904 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003905 if (!spec->capsrc_nids)
3906 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003907 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003908 return; /* no volume in capsrc, too */
3909 spec->vol_in_capsrc = 1;
3910 }
3911
3912 if (spec->num_adc_nids > 0) {
3913 int mux = 0;
3914 int num_adcs = 0;
3915
3916 if (spec->input_mux && spec->input_mux->num_items > 1)
3917 mux = 1;
3918 if (spec->auto_mic) {
3919 num_adcs = 1;
3920 mux = 0;
3921 } else if (spec->dyn_adc_switch)
3922 num_adcs = 1;
3923 if (!num_adcs) {
3924 if (spec->num_adc_nids > 3)
3925 spec->num_adc_nids = 3;
3926 else if (!spec->num_adc_nids)
3927 return;
3928 num_adcs = spec->num_adc_nids;
3929 }
3930 spec->cap_mixer = caps[mux][num_adcs - 1];
3931 }
3932}
3933
3934/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003935 * standard auto-parser initializations
3936 */
3937static void alc_auto_init_std(struct hda_codec *codec)
3938{
3939 struct alc_spec *spec = codec->spec;
3940 alc_auto_init_multi_out(codec);
3941 alc_auto_init_extra_out(codec);
3942 alc_auto_init_analog_input(codec);
3943 alc_auto_init_input_src(codec);
3944 alc_auto_init_digital(codec);
3945 if (spec->unsol_event)
3946 alc_inithook(codec);
3947}
3948
3949/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003950 * Digital-beep handlers
3951 */
3952#ifdef CONFIG_SND_HDA_INPUT_BEEP
3953#define set_beep_amp(spec, nid, idx, dir) \
3954 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3955
3956static const struct snd_pci_quirk beep_white_list[] = {
3957 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3958 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3959 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3960 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3961 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3962 {}
3963};
3964
3965static inline int has_cdefine_beep(struct hda_codec *codec)
3966{
3967 struct alc_spec *spec = codec->spec;
3968 const struct snd_pci_quirk *q;
3969 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3970 if (q)
3971 return q->value;
3972 return spec->cdefine.enable_pcbeep;
3973}
3974#else
3975#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3976#define has_cdefine_beep(codec) 0
3977#endif
3978
3979/* parse the BIOS configuration and set up the alc_spec */
3980/* return 1 if successful, 0 if the proper config is not found,
3981 * or a negative error code
3982 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003983static int alc_parse_auto_config(struct hda_codec *codec,
3984 const hda_nid_t *ignore_nids,
3985 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003986{
3987 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003988 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003989 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003990
Takashi Iwai53c334a2011-08-23 18:27:14 +02003991 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3992 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003993 if (err < 0)
3994 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003995 if (!cfg->line_outs) {
3996 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003997 spec->multiout.max_channels = 2;
3998 spec->no_analog = 1;
3999 goto dig_only;
4000 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004001 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004002 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004003
Takashi Iwai06503672011-10-06 08:27:19 +02004004 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4005 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004006 /* use HP as primary out */
4007 cfg->speaker_outs = cfg->line_outs;
4008 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4009 sizeof(cfg->speaker_pins));
4010 cfg->line_outs = cfg->hp_outs;
4011 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4012 cfg->hp_outs = 0;
4013 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4014 cfg->line_out_type = AUTO_PIN_HP_OUT;
4015 }
4016
Takashi Iwai1d045db2011-07-07 18:23:21 +02004017 err = alc_auto_fill_dac_nids(codec);
4018 if (err < 0)
4019 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004020 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004021 if (err < 0)
4022 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004023 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004024 if (err < 0)
4025 return err;
4026 err = alc_auto_create_hp_out(codec);
4027 if (err < 0)
4028 return err;
4029 err = alc_auto_create_speaker_out(codec);
4030 if (err < 0)
4031 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004032 err = alc_auto_create_shared_input(codec);
4033 if (err < 0)
4034 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004035 err = alc_auto_create_input_ctls(codec);
4036 if (err < 0)
4037 return err;
4038
4039 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4040
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004041 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004042 alc_auto_parse_digital(codec);
4043
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004044 if (!spec->no_analog)
4045 alc_remove_invalid_adc_nids(codec);
4046
4047 if (ssid_nids)
4048 alc_ssid_check(codec, ssid_nids);
4049
4050 if (!spec->no_analog) {
4051 alc_auto_check_switches(codec);
4052 err = alc_auto_add_mic_boost(codec);
4053 if (err < 0)
4054 return err;
4055 }
4056
Takashi Iwai1d045db2011-07-07 18:23:21 +02004057 if (spec->kctls.list)
4058 add_mixer(spec, spec->kctls.list);
4059
Takashi Iwai1d045db2011-07-07 18:23:21 +02004060 return 1;
4061}
4062
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004063static int alc880_parse_auto_config(struct hda_codec *codec)
4064{
4065 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4066 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4067 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4068}
4069
Takashi Iwai1d045db2011-07-07 18:23:21 +02004070#ifdef CONFIG_SND_HDA_POWER_SAVE
4071static const struct hda_amp_list alc880_loopbacks[] = {
4072 { 0x0b, HDA_INPUT, 0 },
4073 { 0x0b, HDA_INPUT, 1 },
4074 { 0x0b, HDA_INPUT, 2 },
4075 { 0x0b, HDA_INPUT, 3 },
4076 { 0x0b, HDA_INPUT, 4 },
4077 { } /* end */
4078};
4079#endif
4080
4081/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004082 * ALC880 fix-ups
4083 */
4084enum {
4085 ALC880_FIXUP_GPIO2,
4086 ALC880_FIXUP_MEDION_RIM,
4087};
4088
4089static const struct alc_fixup alc880_fixups[] = {
4090 [ALC880_FIXUP_GPIO2] = {
4091 .type = ALC_FIXUP_VERBS,
4092 .v.verbs = alc_gpio2_init_verbs,
4093 },
4094 [ALC880_FIXUP_MEDION_RIM] = {
4095 .type = ALC_FIXUP_VERBS,
4096 .v.verbs = (const struct hda_verb[]) {
4097 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4098 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4099 { }
4100 },
4101 .chained = true,
4102 .chain_id = ALC880_FIXUP_GPIO2,
4103 },
4104};
4105
4106static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4107 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4108 {}
4109};
4110
4111
4112/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004113 * board setups
4114 */
4115#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4116#define alc_board_config \
4117 snd_hda_check_board_config
4118#define alc_board_codec_sid_config \
4119 snd_hda_check_board_codec_sid_config
4120#include "alc_quirks.c"
4121#else
4122#define alc_board_config(codec, nums, models, tbl) -1
4123#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4124#define setup_preset(codec, x) /* NOP */
4125#endif
4126
4127/*
4128 * OK, here we have finally the patch for ALC880
4129 */
4130#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4131#include "alc880_quirks.c"
4132#endif
4133
4134static int patch_alc880(struct hda_codec *codec)
4135{
4136 struct alc_spec *spec;
4137 int board_config;
4138 int err;
4139
4140 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4141 if (spec == NULL)
4142 return -ENOMEM;
4143
4144 codec->spec = spec;
4145
4146 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004147 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004148
4149 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4150 alc880_models, alc880_cfg_tbl);
4151 if (board_config < 0) {
4152 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4153 codec->chip_name);
4154 board_config = ALC_MODEL_AUTO;
4155 }
4156
4157 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004158 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4159 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4160 }
4161
4162 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004163 /* automatic parse from the BIOS config */
4164 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004165 if (err < 0)
4166 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004167#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4168 else if (!err) {
4169 printk(KERN_INFO
4170 "hda_codec: Cannot set up configuration "
4171 "from BIOS. Using 3-stack mode...\n");
4172 board_config = ALC880_3ST;
4173 }
4174#endif
4175 }
4176
David Henningssonfde48a12011-12-09 18:27:42 +08004177 if (board_config != ALC_MODEL_AUTO) {
4178 spec->vmaster_nid = 0x0c;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004179 setup_preset(codec, &alc880_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004180 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004181
Takashi Iwai60a6a842011-07-27 14:01:24 +02004182 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004183 alc_auto_fill_adc_caps(codec);
4184 alc_rebuild_imux_for_auto_mic(codec);
4185 alc_remove_invalid_adc_nids(codec);
4186 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004187
4188 if (!spec->no_analog && !spec->cap_mixer)
4189 set_capture_mixer(codec);
4190
4191 if (!spec->no_analog) {
4192 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004193 if (err < 0)
4194 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004195 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4196 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004197
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004198 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4199
Takashi Iwai1d045db2011-07-07 18:23:21 +02004200 codec->patch_ops = alc_patch_ops;
4201 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004202 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004203 else
4204 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004205#ifdef CONFIG_SND_HDA_POWER_SAVE
4206 if (!spec->loopback.amplist)
4207 spec->loopback.amplist = alc880_loopbacks;
4208#endif
4209
4210 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004211
4212 error:
4213 alc_free(codec);
4214 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004215}
4216
4217
4218/*
4219 * ALC260 support
4220 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004221static int alc260_parse_auto_config(struct hda_codec *codec)
4222{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004223 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004224 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4225 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004226}
4227
Takashi Iwai1d045db2011-07-07 18:23:21 +02004228#ifdef CONFIG_SND_HDA_POWER_SAVE
4229static const struct hda_amp_list alc260_loopbacks[] = {
4230 { 0x07, HDA_INPUT, 0 },
4231 { 0x07, HDA_INPUT, 1 },
4232 { 0x07, HDA_INPUT, 2 },
4233 { 0x07, HDA_INPUT, 3 },
4234 { 0x07, HDA_INPUT, 4 },
4235 { } /* end */
4236};
4237#endif
4238
4239/*
4240 * Pin config fixes
4241 */
4242enum {
4243 PINFIX_HP_DC5750,
4244};
4245
4246static const struct alc_fixup alc260_fixups[] = {
4247 [PINFIX_HP_DC5750] = {
4248 .type = ALC_FIXUP_PINS,
4249 .v.pins = (const struct alc_pincfg[]) {
4250 { 0x11, 0x90130110 }, /* speaker */
4251 { }
4252 }
4253 },
4254};
4255
4256static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4257 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4258 {}
4259};
4260
4261/*
4262 */
4263#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4264#include "alc260_quirks.c"
4265#endif
4266
4267static int patch_alc260(struct hda_codec *codec)
4268{
4269 struct alc_spec *spec;
4270 int err, board_config;
4271
4272 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4273 if (spec == NULL)
4274 return -ENOMEM;
4275
4276 codec->spec = spec;
4277
4278 spec->mixer_nid = 0x07;
4279
4280 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4281 alc260_models, alc260_cfg_tbl);
4282 if (board_config < 0) {
4283 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4284 codec->chip_name);
4285 board_config = ALC_MODEL_AUTO;
4286 }
4287
4288 if (board_config == ALC_MODEL_AUTO) {
4289 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4290 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4291 }
4292
4293 if (board_config == ALC_MODEL_AUTO) {
4294 /* automatic parse from the BIOS config */
4295 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004296 if (err < 0)
4297 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004298#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4299 else if (!err) {
4300 printk(KERN_INFO
4301 "hda_codec: Cannot set up configuration "
4302 "from BIOS. Using base mode...\n");
4303 board_config = ALC260_BASIC;
4304 }
4305#endif
4306 }
4307
David Henningssonfde48a12011-12-09 18:27:42 +08004308 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004309 setup_preset(codec, &alc260_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004310 spec->vmaster_nid = 0x08;
4311 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004312
Takashi Iwai60a6a842011-07-27 14:01:24 +02004313 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004314 alc_auto_fill_adc_caps(codec);
4315 alc_rebuild_imux_for_auto_mic(codec);
4316 alc_remove_invalid_adc_nids(codec);
4317 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004318
4319 if (!spec->no_analog && !spec->cap_mixer)
4320 set_capture_mixer(codec);
4321
4322 if (!spec->no_analog) {
4323 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004324 if (err < 0)
4325 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004326 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4327 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004328
4329 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4330
Takashi Iwai1d045db2011-07-07 18:23:21 +02004331 codec->patch_ops = alc_patch_ops;
4332 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004333 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004334 else
4335 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004336 spec->shutup = alc_eapd_shutup;
4337#ifdef CONFIG_SND_HDA_POWER_SAVE
4338 if (!spec->loopback.amplist)
4339 spec->loopback.amplist = alc260_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 * ALC882/883/885/888/889 support
4352 *
4353 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4354 * configuration. Each pin widget can choose any input DACs and a mixer.
4355 * Each ADC is connected from a mixer of all inputs. This makes possible
4356 * 6-channel independent captures.
4357 *
4358 * In addition, an independent DAC for the multi-playback (not used in this
4359 * driver yet).
4360 */
4361#ifdef CONFIG_SND_HDA_POWER_SAVE
4362#define alc882_loopbacks alc880_loopbacks
4363#endif
4364
4365/*
4366 * Pin config fixes
4367 */
4368enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004369 ALC882_FIXUP_ABIT_AW9D_MAX,
4370 ALC882_FIXUP_LENOVO_Y530,
4371 ALC882_FIXUP_PB_M5210,
4372 ALC882_FIXUP_ACER_ASPIRE_7736,
4373 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01004374 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004375 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004376 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004377 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004378 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004379 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004380 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004381 ALC889_FIXUP_COEF,
4382 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004383 ALC882_FIXUP_ACER_ASPIRE_4930G,
4384 ALC882_FIXUP_ACER_ASPIRE_8930G,
4385 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004386 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01004387 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004388};
4389
Takashi Iwai68ef0562011-11-09 18:24:44 +01004390static void alc889_fixup_coef(struct hda_codec *codec,
4391 const struct alc_fixup *fix, int action)
4392{
4393 if (action != ALC_FIXUP_ACT_INIT)
4394 return;
4395 alc889_coef_init(codec);
4396}
4397
Takashi Iwai56710872011-11-14 17:42:11 +01004398/* toggle speaker-output according to the hp-jack state */
4399static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4400{
4401 unsigned int gpiostate, gpiomask, gpiodir;
4402
4403 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4404 AC_VERB_GET_GPIO_DATA, 0);
4405
4406 if (!muted)
4407 gpiostate |= (1 << pin);
4408 else
4409 gpiostate &= ~(1 << pin);
4410
4411 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4412 AC_VERB_GET_GPIO_MASK, 0);
4413 gpiomask |= (1 << pin);
4414
4415 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4416 AC_VERB_GET_GPIO_DIRECTION, 0);
4417 gpiodir |= (1 << pin);
4418
4419
4420 snd_hda_codec_write(codec, codec->afg, 0,
4421 AC_VERB_SET_GPIO_MASK, gpiomask);
4422 snd_hda_codec_write(codec, codec->afg, 0,
4423 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4424
4425 msleep(1);
4426
4427 snd_hda_codec_write(codec, codec->afg, 0,
4428 AC_VERB_SET_GPIO_DATA, gpiostate);
4429}
4430
4431/* set up GPIO at initialization */
4432static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4433 const struct alc_fixup *fix, int action)
4434{
4435 if (action != ALC_FIXUP_ACT_INIT)
4436 return;
4437 alc882_gpio_mute(codec, 0, 0);
4438 alc882_gpio_mute(codec, 1, 0);
4439}
4440
Takashi Iwai02a237b2012-02-13 15:25:07 +01004441/* Fix the connection of some pins for ALC889:
4442 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4443 * work correctly (bko#42740)
4444 */
4445static void alc889_fixup_dac_route(struct hda_codec *codec,
4446 const struct alc_fixup *fix, int action)
4447{
4448 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01004449 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01004450 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4451 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4452 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4453 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4454 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4455 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01004456 } else if (action == ALC_FIXUP_ACT_PROBE) {
4457 /* restore the connections */
4458 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
4459 snd_hda_override_conn_list(codec, 0x14, 5, conn);
4460 snd_hda_override_conn_list(codec, 0x15, 5, conn);
4461 snd_hda_override_conn_list(codec, 0x18, 5, conn);
4462 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01004463 }
4464}
4465
Takashi Iwai1d045db2011-07-07 18:23:21 +02004466static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004467 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004468 .type = ALC_FIXUP_PINS,
4469 .v.pins = (const struct alc_pincfg[]) {
4470 { 0x15, 0x01080104 }, /* side */
4471 { 0x16, 0x01011012 }, /* rear */
4472 { 0x17, 0x01016011 }, /* clfe */
4473 { }
4474 }
4475 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004476 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004477 .type = ALC_FIXUP_PINS,
4478 .v.pins = (const struct alc_pincfg[]) {
4479 { 0x15, 0x99130112 }, /* rear int speakers */
4480 { 0x16, 0x99130111 }, /* subwoofer */
4481 { }
4482 }
4483 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004484 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004485 .type = ALC_FIXUP_VERBS,
4486 .v.verbs = (const struct hda_verb[]) {
4487 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4488 {}
4489 }
4490 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004491 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004492 .type = ALC_FIXUP_SKU,
4493 .v.sku = ALC_FIXUP_SKU_IGNORE,
4494 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004495 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004496 .type = ALC_FIXUP_PINS,
4497 .v.pins = (const struct alc_pincfg[]) {
4498 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4499 { }
4500 }
4501 },
Marton Balint8f239212012-03-05 21:33:23 +01004502 [ALC889_FIXUP_CD] = {
4503 .type = ALC_FIXUP_PINS,
4504 .v.pins = (const struct alc_pincfg[]) {
4505 { 0x1c, 0x993301f0 }, /* CD */
4506 { }
4507 }
4508 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004509 [ALC889_FIXUP_VAIO_TT] = {
4510 .type = ALC_FIXUP_PINS,
4511 .v.pins = (const struct alc_pincfg[]) {
4512 { 0x17, 0x90170111 }, /* hidden surround speaker */
4513 { }
4514 }
4515 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004516 [ALC888_FIXUP_EEE1601] = {
4517 .type = ALC_FIXUP_VERBS,
4518 .v.verbs = (const struct hda_verb[]) {
4519 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4520 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4521 { }
4522 }
Takashi Iwai177943a2011-11-09 12:55:18 +01004523 },
4524 [ALC882_FIXUP_EAPD] = {
4525 .type = ALC_FIXUP_VERBS,
4526 .v.verbs = (const struct hda_verb[]) {
4527 /* change to EAPD mode */
4528 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4529 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4530 { }
4531 }
4532 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004533 [ALC883_FIXUP_EAPD] = {
4534 .type = ALC_FIXUP_VERBS,
4535 .v.verbs = (const struct hda_verb[]) {
4536 /* change to EAPD mode */
4537 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4538 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4539 { }
4540 }
4541 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004542 [ALC883_FIXUP_ACER_EAPD] = {
4543 .type = ALC_FIXUP_VERBS,
4544 .v.verbs = (const struct hda_verb[]) {
4545 /* eanable EAPD on Acer laptops */
4546 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4547 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4548 { }
4549 }
4550 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004551 [ALC882_FIXUP_GPIO3] = {
4552 .type = ALC_FIXUP_VERBS,
4553 .v.verbs = alc_gpio3_init_verbs,
4554 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004555 [ALC882_FIXUP_ASUS_W2JC] = {
4556 .type = ALC_FIXUP_VERBS,
4557 .v.verbs = alc_gpio1_init_verbs,
4558 .chained = true,
4559 .chain_id = ALC882_FIXUP_EAPD,
4560 },
4561 [ALC889_FIXUP_COEF] = {
4562 .type = ALC_FIXUP_FUNC,
4563 .v.func = alc889_fixup_coef,
4564 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004565 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4566 .type = ALC_FIXUP_PINS,
4567 .v.pins = (const struct alc_pincfg[]) {
4568 { 0x16, 0x99130111 }, /* CLFE speaker */
4569 { 0x17, 0x99130112 }, /* surround speaker */
4570 { }
4571 }
4572 },
4573 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4574 .type = ALC_FIXUP_PINS,
4575 .v.pins = (const struct alc_pincfg[]) {
4576 { 0x16, 0x99130111 }, /* CLFE speaker */
4577 { 0x1b, 0x99130112 }, /* surround speaker */
4578 { }
4579 },
4580 .chained = true,
4581 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4582 },
4583 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4584 /* additional init verbs for Acer Aspire 8930G */
4585 .type = ALC_FIXUP_VERBS,
4586 .v.verbs = (const struct hda_verb[]) {
4587 /* Enable all DACs */
4588 /* DAC DISABLE/MUTE 1? */
4589 /* setting bits 1-5 disables DAC nids 0x02-0x06
4590 * apparently. Init=0x38 */
4591 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4592 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4593 /* DAC DISABLE/MUTE 2? */
4594 /* some bit here disables the other DACs.
4595 * Init=0x4900 */
4596 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4597 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4598 /* DMIC fix
4599 * This laptop has a stereo digital microphone.
4600 * The mics are only 1cm apart which makes the stereo
4601 * useless. However, either the mic or the ALC889
4602 * makes the signal become a difference/sum signal
4603 * instead of standard stereo, which is annoying.
4604 * So instead we flip this bit which makes the
4605 * codec replicate the sum signal to both channels,
4606 * turning it into a normal mono mic.
4607 */
4608 /* DMIC_CONTROL? Init value = 0x0001 */
4609 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4610 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4611 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4612 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4613 { }
4614 }
4615 },
Takashi Iwai56710872011-11-14 17:42:11 +01004616 [ALC885_FIXUP_MACPRO_GPIO] = {
4617 .type = ALC_FIXUP_FUNC,
4618 .v.func = alc885_fixup_macpro_gpio,
4619 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01004620 [ALC889_FIXUP_DAC_ROUTE] = {
4621 .type = ALC_FIXUP_FUNC,
4622 .v.func = alc889_fixup_dac_route,
4623 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004624};
4625
4626static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004627 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4628 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4629 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4630 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4631 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4632 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004633 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4634 ALC882_FIXUP_ACER_ASPIRE_4930G),
4635 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4636 ALC882_FIXUP_ACER_ASPIRE_4930G),
4637 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4638 ALC882_FIXUP_ACER_ASPIRE_8930G),
4639 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4640 ALC882_FIXUP_ACER_ASPIRE_8930G),
4641 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4642 ALC882_FIXUP_ACER_ASPIRE_4930G),
4643 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4644 ALC882_FIXUP_ACER_ASPIRE_4930G),
4645 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4646 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004647 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwai02a237b2012-02-13 15:25:07 +01004648 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004649 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01004650 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004651 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004652 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004653 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004654 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01004655
4656 /* All Apple entries are in codec SSIDs */
4657 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4658 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4659 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4660 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4661 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4662
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004663 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004664 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01004665 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004666 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004667 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4668 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004669 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004670 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004671 {}
4672};
4673
4674/*
4675 * BIOS auto configuration
4676 */
4677/* almost identical with ALC880 parser... */
4678static int alc882_parse_auto_config(struct hda_codec *codec)
4679{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004680 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004681 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4682 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004683}
4684
Takashi Iwai1d045db2011-07-07 18:23:21 +02004685/*
4686 */
4687#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4688#include "alc882_quirks.c"
4689#endif
4690
4691static int patch_alc882(struct hda_codec *codec)
4692{
4693 struct alc_spec *spec;
4694 int err, board_config;
4695
4696 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4697 if (spec == NULL)
4698 return -ENOMEM;
4699
4700 codec->spec = spec;
4701
4702 spec->mixer_nid = 0x0b;
4703
4704 switch (codec->vendor_id) {
4705 case 0x10ec0882:
4706 case 0x10ec0885:
4707 break;
4708 default:
4709 /* ALC883 and variants */
4710 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4711 break;
4712 }
4713
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004714 err = alc_codec_rename_from_preset(codec);
4715 if (err < 0)
4716 goto error;
4717
Takashi Iwaib2539692011-11-14 17:32:17 +01004718 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4719 alc882_models, NULL);
4720 if (board_config < 0)
4721 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004722 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4723
4724 if (board_config < 0) {
4725 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4726 codec->chip_name);
4727 board_config = ALC_MODEL_AUTO;
4728 }
4729
4730 if (board_config == ALC_MODEL_AUTO) {
4731 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4732 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4733 }
4734
4735 alc_auto_parse_customize_define(codec);
4736
4737 if (board_config == ALC_MODEL_AUTO) {
4738 /* automatic parse from the BIOS config */
4739 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004740 if (err < 0)
4741 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004742 }
4743
David Henningssonfde48a12011-12-09 18:27:42 +08004744 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004745 setup_preset(codec, &alc882_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004746 spec->vmaster_nid = 0x0c;
4747 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004748
Takashi Iwai60a6a842011-07-27 14:01:24 +02004749 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004750 alc_auto_fill_adc_caps(codec);
4751 alc_rebuild_imux_for_auto_mic(codec);
4752 alc_remove_invalid_adc_nids(codec);
4753 }
4754
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004755 if (!spec->no_analog && !spec->cap_mixer)
4756 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004757
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004758 if (!spec->no_analog && has_cdefine_beep(codec)) {
4759 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004760 if (err < 0)
4761 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004762 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004763 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004764
4765 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4766
Takashi Iwai1d045db2011-07-07 18:23:21 +02004767 codec->patch_ops = alc_patch_ops;
4768 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004769 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004770 else
4771 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004772
Takashi Iwai1d045db2011-07-07 18:23:21 +02004773#ifdef CONFIG_SND_HDA_POWER_SAVE
4774 if (!spec->loopback.amplist)
4775 spec->loopback.amplist = alc882_loopbacks;
4776#endif
4777
4778 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004779
4780 error:
4781 alc_free(codec);
4782 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004783}
4784
4785
4786/*
4787 * ALC262 support
4788 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004789static int alc262_parse_auto_config(struct hda_codec *codec)
4790{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004791 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004792 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4793 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004794}
4795
4796/*
4797 * Pin config fixes
4798 */
4799enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004800 ALC262_FIXUP_FSC_H270,
4801 ALC262_FIXUP_HP_Z200,
4802 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01004803 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004804 ALC262_FIXUP_BENQ,
4805 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004806};
4807
4808static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004809 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004810 .type = ALC_FIXUP_PINS,
4811 .v.pins = (const struct alc_pincfg[]) {
4812 { 0x14, 0x99130110 }, /* speaker */
4813 { 0x15, 0x0221142f }, /* front HP */
4814 { 0x1b, 0x0121141f }, /* rear HP */
4815 { }
4816 }
4817 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004818 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004819 .type = ALC_FIXUP_PINS,
4820 .v.pins = (const struct alc_pincfg[]) {
4821 { 0x16, 0x99130120 }, /* internal speaker */
4822 { }
4823 }
4824 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004825 [ALC262_FIXUP_TYAN] = {
4826 .type = ALC_FIXUP_PINS,
4827 .v.pins = (const struct alc_pincfg[]) {
4828 { 0x14, 0x1993e1f0 }, /* int AUX */
4829 { }
4830 }
4831 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004832 [ALC262_FIXUP_LENOVO_3000] = {
4833 .type = ALC_FIXUP_VERBS,
4834 .v.verbs = (const struct hda_verb[]) {
4835 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004836 {}
4837 },
4838 .chained = true,
4839 .chain_id = ALC262_FIXUP_BENQ,
4840 },
4841 [ALC262_FIXUP_BENQ] = {
4842 .type = ALC_FIXUP_VERBS,
4843 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004844 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4845 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4846 {}
4847 }
4848 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004849 [ALC262_FIXUP_BENQ_T31] = {
4850 .type = ALC_FIXUP_VERBS,
4851 .v.verbs = (const struct hda_verb[]) {
4852 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4853 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4854 {}
4855 }
4856 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004857};
4858
4859static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004860 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004861 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4862 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004863 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
4864 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004865 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004866 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4867 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004868 {}
4869};
4870
4871
4872#ifdef CONFIG_SND_HDA_POWER_SAVE
4873#define alc262_loopbacks alc880_loopbacks
4874#endif
4875
Takashi Iwai1d045db2011-07-07 18:23:21 +02004876/*
4877 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004878static int patch_alc262(struct hda_codec *codec)
4879{
4880 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881 int err;
4882
4883 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4884 if (spec == NULL)
4885 return -ENOMEM;
4886
4887 codec->spec = spec;
4888
4889 spec->mixer_nid = 0x0b;
4890
4891#if 0
4892 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4893 * under-run
4894 */
4895 {
4896 int tmp;
4897 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4898 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4899 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4900 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4901 }
4902#endif
4903 alc_auto_parse_customize_define(codec);
4904
4905 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4906
Takashi Iwai42399f72011-11-07 17:18:44 +01004907 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4908 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004909
Takashi Iwai42399f72011-11-07 17:18:44 +01004910 /* automatic parse from the BIOS config */
4911 err = alc262_parse_auto_config(codec);
4912 if (err < 0)
4913 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004914
Takashi Iwai60a6a842011-07-27 14:01:24 +02004915 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004916 alc_auto_fill_adc_caps(codec);
4917 alc_rebuild_imux_for_auto_mic(codec);
4918 alc_remove_invalid_adc_nids(codec);
4919 }
4920
4921 if (!spec->no_analog && !spec->cap_mixer)
4922 set_capture_mixer(codec);
4923
Takashi Iwai1d045db2011-07-07 18:23:21 +02004924 if (!spec->no_analog && has_cdefine_beep(codec)) {
4925 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004926 if (err < 0)
4927 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004928 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004929 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004930
4931 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4932
Takashi Iwai1d045db2011-07-07 18:23:21 +02004933 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004934 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004935 spec->shutup = alc_eapd_shutup;
4936
Takashi Iwai1d045db2011-07-07 18:23:21 +02004937#ifdef CONFIG_SND_HDA_POWER_SAVE
4938 if (!spec->loopback.amplist)
4939 spec->loopback.amplist = alc262_loopbacks;
4940#endif
4941
4942 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004943
4944 error:
4945 alc_free(codec);
4946 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004947}
4948
4949/*
4950 * ALC268
4951 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004952/* bind Beep switches of both NID 0x0f and 0x10 */
4953static const struct hda_bind_ctls alc268_bind_beep_sw = {
4954 .ops = &snd_hda_bind_sw,
4955 .values = {
4956 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4957 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4958 0
4959 },
4960};
4961
4962static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4963 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4964 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4965 { }
4966};
4967
4968/* set PCBEEP vol = 0, mute connections */
4969static const struct hda_verb alc268_beep_init_verbs[] = {
4970 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4971 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4972 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4973 { }
4974};
4975
4976/*
4977 * BIOS auto configuration
4978 */
4979static int alc268_parse_auto_config(struct hda_codec *codec)
4980{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004981 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004982 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004983 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4984 if (err > 0) {
4985 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4986 add_mixer(spec, alc268_beep_mixer);
4987 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004988 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004990 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004991}
4992
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993/*
4994 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995static int patch_alc268(struct hda_codec *codec)
4996{
4997 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004998 int i, has_beep, err;
4999
5000 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5001 if (spec == NULL)
5002 return -ENOMEM;
5003
5004 codec->spec = spec;
5005
5006 /* ALC268 has no aa-loopback mixer */
5007
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005008 /* automatic parse from the BIOS config */
5009 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005010 if (err < 0)
5011 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005012
Takashi Iwai1d045db2011-07-07 18:23:21 +02005013 has_beep = 0;
5014 for (i = 0; i < spec->num_mixers; i++) {
5015 if (spec->mixers[i] == alc268_beep_mixer) {
5016 has_beep = 1;
5017 break;
5018 }
5019 }
5020
5021 if (has_beep) {
5022 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005023 if (err < 0)
5024 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005025 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5026 /* override the amp caps for beep generator */
5027 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5028 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5029 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5030 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5031 (0 << AC_AMPCAP_MUTE_SHIFT));
5032 }
5033
Takashi Iwai60a6a842011-07-27 14:01:24 +02005034 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005035 alc_auto_fill_adc_caps(codec);
5036 alc_rebuild_imux_for_auto_mic(codec);
5037 alc_remove_invalid_adc_nids(codec);
5038 }
5039
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005040 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005041 set_capture_mixer(codec);
5042
Takashi Iwai1d045db2011-07-07 18:23:21 +02005043 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005044 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005045 spec->shutup = alc_eapd_shutup;
5046
Takashi Iwai1d045db2011-07-07 18:23:21 +02005047 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005048
5049 error:
5050 alc_free(codec);
5051 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005052}
5053
5054/*
5055 * ALC269
5056 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005057#ifdef CONFIG_SND_HDA_POWER_SAVE
5058#define alc269_loopbacks alc880_loopbacks
5059#endif
5060
5061static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5062 .substreams = 1,
5063 .channels_min = 2,
5064 .channels_max = 8,
5065 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5066 /* NID is set in alc_build_pcms */
5067 .ops = {
5068 .open = alc_playback_pcm_open,
5069 .prepare = alc_playback_pcm_prepare,
5070 .cleanup = alc_playback_pcm_cleanup
5071 },
5072};
5073
5074static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5075 .substreams = 1,
5076 .channels_min = 2,
5077 .channels_max = 2,
5078 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5079 /* NID is set in alc_build_pcms */
5080};
5081
5082#ifdef CONFIG_SND_HDA_POWER_SAVE
5083static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5084{
5085 switch (codec->subsystem_id) {
5086 case 0x103c1586:
5087 return 1;
5088 }
5089 return 0;
5090}
5091
5092static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5093{
5094 /* update mute-LED according to the speaker mute state */
5095 if (nid == 0x01 || nid == 0x14) {
5096 int pinval;
5097 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5098 HDA_AMP_MUTE)
5099 pinval = 0x24;
5100 else
5101 pinval = 0x20;
5102 /* mic2 vref pin is used for mute LED control */
5103 snd_hda_codec_update_cache(codec, 0x19, 0,
5104 AC_VERB_SET_PIN_WIDGET_CONTROL,
5105 pinval);
5106 }
5107 return alc_check_power_status(codec, nid);
5108}
5109#endif /* CONFIG_SND_HDA_POWER_SAVE */
5110
5111/* different alc269-variants */
5112enum {
5113 ALC269_TYPE_ALC269VA,
5114 ALC269_TYPE_ALC269VB,
5115 ALC269_TYPE_ALC269VC,
5116};
5117
5118/*
5119 * BIOS auto configuration
5120 */
5121static int alc269_parse_auto_config(struct hda_codec *codec)
5122{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005123 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005124 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5125 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5126 struct alc_spec *spec = codec->spec;
5127 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5128 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005129
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005130 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005131}
5132
Takashi Iwai1d045db2011-07-07 18:23:21 +02005133static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5134{
5135 int val = alc_read_coef_idx(codec, 0x04);
5136 if (power_up)
5137 val |= 1 << 11;
5138 else
5139 val &= ~(1 << 11);
5140 alc_write_coef_idx(codec, 0x04, val);
5141}
5142
5143static void alc269_shutup(struct hda_codec *codec)
5144{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005145 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005146 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005147 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005148 alc269_toggle_power_output(codec, 0);
5149 msleep(150);
5150 }
5151}
5152
Takashi Iwai2a439522011-07-26 09:52:50 +02005153#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005154static int alc269_resume(struct hda_codec *codec)
5155{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005156 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005157 alc269_toggle_power_output(codec, 0);
5158 msleep(150);
5159 }
5160
5161 codec->patch_ops.init(codec);
5162
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005163 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005164 alc269_toggle_power_output(codec, 1);
5165 msleep(200);
5166 }
5167
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005168 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005169 alc269_toggle_power_output(codec, 1);
5170
5171 snd_hda_codec_resume_amp(codec);
5172 snd_hda_codec_resume_cache(codec);
5173 hda_call_check_power_status(codec, 0x01);
5174 return 0;
5175}
Takashi Iwai2a439522011-07-26 09:52:50 +02005176#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005177
5178static void alc269_fixup_hweq(struct hda_codec *codec,
5179 const struct alc_fixup *fix, int action)
5180{
5181 int coef;
5182
5183 if (action != ALC_FIXUP_ACT_INIT)
5184 return;
5185 coef = alc_read_coef_idx(codec, 0x1e);
5186 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5187}
5188
5189static void alc271_fixup_dmic(struct hda_codec *codec,
5190 const struct alc_fixup *fix, int action)
5191{
5192 static const struct hda_verb verbs[] = {
5193 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5194 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5195 {}
5196 };
5197 unsigned int cfg;
5198
5199 if (strcmp(codec->chip_name, "ALC271X"))
5200 return;
5201 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5202 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5203 snd_hda_sequence_write(codec, verbs);
5204}
5205
Takashi Iwai017f2a12011-07-09 14:42:25 +02005206static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5207 const struct alc_fixup *fix, int action)
5208{
5209 struct alc_spec *spec = codec->spec;
5210
5211 if (action != ALC_FIXUP_ACT_PROBE)
5212 return;
5213
5214 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5215 * fix the sample rate of analog I/O to 44.1kHz
5216 */
5217 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5218 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5219}
5220
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005221static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5222 const struct alc_fixup *fix, int action)
5223{
5224 int coef;
5225
5226 if (action != ALC_FIXUP_ACT_INIT)
5227 return;
5228 /* The digital-mic unit sends PDM (differential signal) instead of
5229 * the standard PCM, thus you can't record a valid mono stream as is.
5230 * Below is a workaround specific to ALC269 to control the dmic
5231 * signal source as mono.
5232 */
5233 coef = alc_read_coef_idx(codec, 0x07);
5234 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5235}
5236
Takashi Iwai24519912011-08-16 15:08:49 +02005237static void alc269_quanta_automute(struct hda_codec *codec)
5238{
David Henningsson42cf0d02011-09-20 12:04:56 +02005239 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005240
5241 snd_hda_codec_write(codec, 0x20, 0,
5242 AC_VERB_SET_COEF_INDEX, 0x0c);
5243 snd_hda_codec_write(codec, 0x20, 0,
5244 AC_VERB_SET_PROC_COEF, 0x680);
5245
5246 snd_hda_codec_write(codec, 0x20, 0,
5247 AC_VERB_SET_COEF_INDEX, 0x0c);
5248 snd_hda_codec_write(codec, 0x20, 0,
5249 AC_VERB_SET_PROC_COEF, 0x480);
5250}
5251
5252static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5253 const struct alc_fixup *fix, int action)
5254{
5255 struct alc_spec *spec = codec->spec;
5256 if (action != ALC_FIXUP_ACT_PROBE)
5257 return;
5258 spec->automute_hook = alc269_quanta_automute;
5259}
5260
Takashi Iwai1d045db2011-07-07 18:23:21 +02005261enum {
5262 ALC269_FIXUP_SONY_VAIO,
5263 ALC275_FIXUP_SONY_VAIO_GPIO2,
5264 ALC269_FIXUP_DELL_M101Z,
5265 ALC269_FIXUP_SKU_IGNORE,
5266 ALC269_FIXUP_ASUS_G73JW,
5267 ALC269_FIXUP_LENOVO_EAPD,
5268 ALC275_FIXUP_SONY_HWEQ,
5269 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005270 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005271 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005272 ALC269_FIXUP_QUANTA_MUTE,
5273 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005274 ALC269_FIXUP_AMIC,
5275 ALC269_FIXUP_DMIC,
5276 ALC269VB_FIXUP_AMIC,
5277 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005278};
5279
5280static const struct alc_fixup alc269_fixups[] = {
5281 [ALC269_FIXUP_SONY_VAIO] = {
5282 .type = ALC_FIXUP_VERBS,
5283 .v.verbs = (const struct hda_verb[]) {
5284 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5285 {}
5286 }
5287 },
5288 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5289 .type = ALC_FIXUP_VERBS,
5290 .v.verbs = (const struct hda_verb[]) {
5291 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5292 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5293 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5294 { }
5295 },
5296 .chained = true,
5297 .chain_id = ALC269_FIXUP_SONY_VAIO
5298 },
5299 [ALC269_FIXUP_DELL_M101Z] = {
5300 .type = ALC_FIXUP_VERBS,
5301 .v.verbs = (const struct hda_verb[]) {
5302 /* Enables internal speaker */
5303 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5304 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5305 {}
5306 }
5307 },
5308 [ALC269_FIXUP_SKU_IGNORE] = {
5309 .type = ALC_FIXUP_SKU,
5310 .v.sku = ALC_FIXUP_SKU_IGNORE,
5311 },
5312 [ALC269_FIXUP_ASUS_G73JW] = {
5313 .type = ALC_FIXUP_PINS,
5314 .v.pins = (const struct alc_pincfg[]) {
5315 { 0x17, 0x99130111 }, /* subwoofer */
5316 { }
5317 }
5318 },
5319 [ALC269_FIXUP_LENOVO_EAPD] = {
5320 .type = ALC_FIXUP_VERBS,
5321 .v.verbs = (const struct hda_verb[]) {
5322 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5323 {}
5324 }
5325 },
5326 [ALC275_FIXUP_SONY_HWEQ] = {
5327 .type = ALC_FIXUP_FUNC,
5328 .v.func = alc269_fixup_hweq,
5329 .chained = true,
5330 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5331 },
5332 [ALC271_FIXUP_DMIC] = {
5333 .type = ALC_FIXUP_FUNC,
5334 .v.func = alc271_fixup_dmic,
5335 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005336 [ALC269_FIXUP_PCM_44K] = {
5337 .type = ALC_FIXUP_FUNC,
5338 .v.func = alc269_fixup_pcm_44k,
5339 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005340 [ALC269_FIXUP_STEREO_DMIC] = {
5341 .type = ALC_FIXUP_FUNC,
5342 .v.func = alc269_fixup_stereo_dmic,
5343 },
Takashi Iwai24519912011-08-16 15:08:49 +02005344 [ALC269_FIXUP_QUANTA_MUTE] = {
5345 .type = ALC_FIXUP_FUNC,
5346 .v.func = alc269_fixup_quanta_mute,
5347 },
5348 [ALC269_FIXUP_LIFEBOOK] = {
5349 .type = ALC_FIXUP_PINS,
5350 .v.pins = (const struct alc_pincfg[]) {
5351 { 0x1a, 0x2101103f }, /* dock line-out */
5352 { 0x1b, 0x23a11040 }, /* dock mic-in */
5353 { }
5354 },
5355 .chained = true,
5356 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5357 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005358 [ALC269_FIXUP_AMIC] = {
5359 .type = ALC_FIXUP_PINS,
5360 .v.pins = (const struct alc_pincfg[]) {
5361 { 0x14, 0x99130110 }, /* speaker */
5362 { 0x15, 0x0121401f }, /* HP out */
5363 { 0x18, 0x01a19c20 }, /* mic */
5364 { 0x19, 0x99a3092f }, /* int-mic */
5365 { }
5366 },
5367 },
5368 [ALC269_FIXUP_DMIC] = {
5369 .type = ALC_FIXUP_PINS,
5370 .v.pins = (const struct alc_pincfg[]) {
5371 { 0x12, 0x99a3092f }, /* int-mic */
5372 { 0x14, 0x99130110 }, /* speaker */
5373 { 0x15, 0x0121401f }, /* HP out */
5374 { 0x18, 0x01a19c20 }, /* mic */
5375 { }
5376 },
5377 },
5378 [ALC269VB_FIXUP_AMIC] = {
5379 .type = ALC_FIXUP_PINS,
5380 .v.pins = (const struct alc_pincfg[]) {
5381 { 0x14, 0x99130110 }, /* speaker */
5382 { 0x18, 0x01a19c20 }, /* mic */
5383 { 0x19, 0x99a3092f }, /* int-mic */
5384 { 0x21, 0x0121401f }, /* HP out */
5385 { }
5386 },
5387 },
David Henningsson2267ea92012-01-03 08:45:56 +01005388 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02005389 .type = ALC_FIXUP_PINS,
5390 .v.pins = (const struct alc_pincfg[]) {
5391 { 0x12, 0x99a3092f }, /* int-mic */
5392 { 0x14, 0x99130110 }, /* speaker */
5393 { 0x18, 0x01a19c20 }, /* mic */
5394 { 0x21, 0x0121401f }, /* HP out */
5395 { }
5396 },
5397 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005398};
5399
5400static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005401 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005402 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5403 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5404 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5405 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5406 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005407 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5408 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5409 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5410 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5411 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5412 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005413 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005414 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5415 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5416 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5417 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5418 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005419 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005420 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005421 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005422
5423#if 1
5424 /* Below is a quirk table taken from the old code.
5425 * Basically the device should work as is without the fixup table.
5426 * If BIOS doesn't give a proper info, enable the corresponding
5427 * fixup entry.
5428 */
5429 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5430 ALC269_FIXUP_AMIC),
5431 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005432 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5433 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5434 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5435 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5436 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5437 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5438 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5439 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5440 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5441 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5442 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5443 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5444 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5445 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5446 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5447 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5448 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5449 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5450 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5451 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5452 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5453 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5454 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5455 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5456 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5457 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5458 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5459 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5460 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5461 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5462 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5463 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5464 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5465 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5466 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5467 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5468 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5469 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5470#endif
5471 {}
5472};
5473
5474static const struct alc_model_fixup alc269_fixup_models[] = {
5475 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5476 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005477 {}
5478};
5479
5480
5481static int alc269_fill_coef(struct hda_codec *codec)
5482{
Kailang Yang526af6e2012-03-07 08:25:20 +01005483 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005484 int val;
5485
Kailang Yang526af6e2012-03-07 08:25:20 +01005486 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5487 return 0;
5488
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005489 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005490 alc_write_coef_idx(codec, 0xf, 0x960b);
5491 alc_write_coef_idx(codec, 0xe, 0x8817);
5492 }
5493
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005494 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005495 alc_write_coef_idx(codec, 0xf, 0x960b);
5496 alc_write_coef_idx(codec, 0xe, 0x8814);
5497 }
5498
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005499 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005500 val = alc_read_coef_idx(codec, 0x04);
5501 /* Power up output pin */
5502 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5503 }
5504
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005505 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005506 val = alc_read_coef_idx(codec, 0xd);
5507 if ((val & 0x0c00) >> 10 != 0x1) {
5508 /* Capless ramp up clock control */
5509 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5510 }
5511 val = alc_read_coef_idx(codec, 0x17);
5512 if ((val & 0x01c0) >> 6 != 0x4) {
5513 /* Class D power on reset */
5514 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5515 }
5516 }
5517
5518 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5519 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5520
5521 val = alc_read_coef_idx(codec, 0x4); /* HP */
5522 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5523
5524 return 0;
5525}
5526
5527/*
5528 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005529static int patch_alc269(struct hda_codec *codec)
5530{
5531 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005532 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005533
5534 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5535 if (spec == NULL)
5536 return -ENOMEM;
5537
5538 codec->spec = spec;
5539
5540 spec->mixer_nid = 0x0b;
5541
5542 alc_auto_parse_customize_define(codec);
5543
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005544 err = alc_codec_rename_from_preset(codec);
5545 if (err < 0)
5546 goto error;
5547
Takashi Iwai1d045db2011-07-07 18:23:21 +02005548 if (codec->vendor_id == 0x10ec0269) {
5549 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005550 switch (alc_get_coef0(codec) & 0x00f0) {
5551 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005552 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005553 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005554 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005555 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005556 break;
5557 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005558 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5559 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005560 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005561 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005562 break;
5563 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005564 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005565 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005566 if (err < 0)
5567 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005568 alc269_fill_coef(codec);
5569 }
5570
Takashi Iwaia4297b52011-08-23 18:40:12 +02005571 alc_pick_fixup(codec, alc269_fixup_models,
5572 alc269_fixup_tbl, alc269_fixups);
5573 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005574
Takashi Iwaia4297b52011-08-23 18:40:12 +02005575 /* automatic parse from the BIOS config */
5576 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005577 if (err < 0)
5578 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005579
Takashi Iwai60a6a842011-07-27 14:01:24 +02005580 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005581 alc_auto_fill_adc_caps(codec);
5582 alc_rebuild_imux_for_auto_mic(codec);
5583 alc_remove_invalid_adc_nids(codec);
5584 }
5585
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005586 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005587 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005588
5589 if (!spec->no_analog && has_cdefine_beep(codec)) {
5590 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005591 if (err < 0)
5592 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005593 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005594 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005595
5596 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5597
Takashi Iwai1d045db2011-07-07 18:23:21 +02005598 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005599#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005600 codec->patch_ops.resume = alc269_resume;
5601#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005602 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005603 spec->shutup = alc269_shutup;
5604
Takashi Iwai1d045db2011-07-07 18:23:21 +02005605#ifdef CONFIG_SND_HDA_POWER_SAVE
5606 if (!spec->loopback.amplist)
5607 spec->loopback.amplist = alc269_loopbacks;
5608 if (alc269_mic2_for_mute_led(codec))
5609 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5610#endif
5611
5612 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005613
5614 error:
5615 alc_free(codec);
5616 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005617}
5618
5619/*
5620 * ALC861
5621 */
5622
Takashi Iwai1d045db2011-07-07 18:23:21 +02005623static int alc861_parse_auto_config(struct hda_codec *codec)
5624{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005625 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005626 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5627 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005628}
5629
Takashi Iwai1d045db2011-07-07 18:23:21 +02005630#ifdef CONFIG_SND_HDA_POWER_SAVE
5631static const struct hda_amp_list alc861_loopbacks[] = {
5632 { 0x15, HDA_INPUT, 0 },
5633 { 0x15, HDA_INPUT, 1 },
5634 { 0x15, HDA_INPUT, 2 },
5635 { 0x15, HDA_INPUT, 3 },
5636 { } /* end */
5637};
5638#endif
5639
5640
5641/* Pin config fixes */
5642enum {
5643 PINFIX_FSC_AMILO_PI1505,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005644 PINFIX_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645};
5646
Takashi Iwai31150f22012-01-30 10:54:08 +01005647/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5648static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5649 const struct alc_fixup *fix, int action)
5650{
5651 struct alc_spec *spec = codec->spec;
5652 unsigned int val;
5653
5654 if (action != ALC_FIXUP_ACT_INIT)
5655 return;
5656 val = snd_hda_codec_read(codec, 0x0f, 0,
5657 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5658 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5659 val |= AC_PINCTL_IN_EN;
5660 val |= AC_PINCTL_VREF_50;
5661 snd_hda_codec_write(codec, 0x0f, 0,
5662 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5663 spec->keep_vref_in_automute = 1;
5664}
5665
Takashi Iwai1d045db2011-07-07 18:23:21 +02005666static const struct alc_fixup alc861_fixups[] = {
5667 [PINFIX_FSC_AMILO_PI1505] = {
5668 .type = ALC_FIXUP_PINS,
5669 .v.pins = (const struct alc_pincfg[]) {
5670 { 0x0b, 0x0221101f }, /* HP */
5671 { 0x0f, 0x90170310 }, /* speaker */
5672 { }
5673 }
5674 },
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005675 [PINFIX_ASUS_A6RP] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01005676 .type = ALC_FIXUP_FUNC,
5677 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005678 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005679};
5680
5681static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01005682 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", PINFIX_ASUS_A6RP),
Jaroslav Kysela416846d2012-02-07 14:18:14 +01005683 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", PINFIX_ASUS_A6RP),
Takashi Iwaib3a81522012-01-26 15:56:16 +01005684 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", PINFIX_ASUS_A6RP),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005685 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5686 {}
5687};
5688
5689/*
5690 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691static int patch_alc861(struct hda_codec *codec)
5692{
5693 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005694 int err;
5695
5696 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5697 if (spec == NULL)
5698 return -ENOMEM;
5699
5700 codec->spec = spec;
5701
5702 spec->mixer_nid = 0x15;
5703
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005704 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5705 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005706
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005707 /* automatic parse from the BIOS config */
5708 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005709 if (err < 0)
5710 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005711
Takashi Iwai60a6a842011-07-27 14:01:24 +02005712 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005713 alc_auto_fill_adc_caps(codec);
5714 alc_rebuild_imux_for_auto_mic(codec);
5715 alc_remove_invalid_adc_nids(codec);
5716 }
5717
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005718 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005719 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005720
5721 if (!spec->no_analog) {
5722 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005723 if (err < 0)
5724 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005725 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5726 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727
Takashi Iwai1d045db2011-07-07 18:23:21 +02005728 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5729
5730 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005731 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005732#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005733 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005734 if (!spec->loopback.amplist)
5735 spec->loopback.amplist = alc861_loopbacks;
5736#endif
5737
5738 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005739
5740 error:
5741 alc_free(codec);
5742 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743}
5744
5745/*
5746 * ALC861-VD support
5747 *
5748 * Based on ALC882
5749 *
5750 * In addition, an independent DAC
5751 */
5752#ifdef CONFIG_SND_HDA_POWER_SAVE
5753#define alc861vd_loopbacks alc880_loopbacks
5754#endif
5755
Takashi Iwai1d045db2011-07-07 18:23:21 +02005756static int alc861vd_parse_auto_config(struct hda_codec *codec)
5757{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005758 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005759 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5760 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005761}
5762
Takashi Iwai1d045db2011-07-07 18:23:21 +02005763enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005764 ALC660VD_FIX_ASUS_GPIO1,
5765 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005766};
5767
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005768/* exclude VREF80 */
5769static void alc861vd_fixup_dallas(struct hda_codec *codec,
5770 const struct alc_fixup *fix, int action)
5771{
5772 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5773 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5774 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5775 }
5776}
5777
Takashi Iwai1d045db2011-07-07 18:23:21 +02005778static const struct alc_fixup alc861vd_fixups[] = {
5779 [ALC660VD_FIX_ASUS_GPIO1] = {
5780 .type = ALC_FIXUP_VERBS,
5781 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005782 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005783 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5784 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5785 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5786 { }
5787 }
5788 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005789 [ALC861VD_FIX_DALLAS] = {
5790 .type = ALC_FIXUP_FUNC,
5791 .v.func = alc861vd_fixup_dallas,
5792 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005793};
5794
5795static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005796 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005797 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005798 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005799 {}
5800};
5801
5802static const struct hda_verb alc660vd_eapd_verbs[] = {
5803 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5804 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5805 { }
5806};
5807
5808/*
5809 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005810static int patch_alc861vd(struct hda_codec *codec)
5811{
5812 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005813 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005814
5815 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5816 if (spec == NULL)
5817 return -ENOMEM;
5818
5819 codec->spec = spec;
5820
5821 spec->mixer_nid = 0x0b;
5822
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005823 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5824 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005825
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005826 /* automatic parse from the BIOS config */
5827 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005828 if (err < 0)
5829 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005830
Takashi Iwai1d045db2011-07-07 18:23:21 +02005831 if (codec->vendor_id == 0x10ec0660) {
5832 /* always turn on EAPD */
5833 add_verb(spec, alc660vd_eapd_verbs);
5834 }
5835
Takashi Iwai60a6a842011-07-27 14:01:24 +02005836 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005837 alc_auto_fill_adc_caps(codec);
5838 alc_rebuild_imux_for_auto_mic(codec);
5839 alc_remove_invalid_adc_nids(codec);
5840 }
5841
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005842 if (!spec->no_analog && !spec->cap_mixer)
5843 set_capture_mixer(codec);
5844
5845 if (!spec->no_analog) {
5846 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005847 if (err < 0)
5848 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005849 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5850 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005851
Takashi Iwai1d045db2011-07-07 18:23:21 +02005852 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5853
5854 codec->patch_ops = alc_patch_ops;
5855
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005856 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005857 spec->shutup = alc_eapd_shutup;
5858#ifdef CONFIG_SND_HDA_POWER_SAVE
5859 if (!spec->loopback.amplist)
5860 spec->loopback.amplist = alc861vd_loopbacks;
5861#endif
5862
5863 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005864
5865 error:
5866 alc_free(codec);
5867 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005868}
5869
5870/*
5871 * ALC662 support
5872 *
5873 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5874 * configuration. Each pin widget can choose any input DACs and a mixer.
5875 * Each ADC is connected from a mixer of all inputs. This makes possible
5876 * 6-channel independent captures.
5877 *
5878 * In addition, an independent DAC for the multi-playback (not used in this
5879 * driver yet).
5880 */
5881#ifdef CONFIG_SND_HDA_POWER_SAVE
5882#define alc662_loopbacks alc880_loopbacks
5883#endif
5884
5885/*
5886 * BIOS auto configuration
5887 */
5888
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005889static int alc662_parse_auto_config(struct hda_codec *codec)
5890{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005891 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005892 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5893 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5894 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005895
Kailang Yang6227cdc2010-02-25 08:36:52 +01005896 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5897 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005898 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005899 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005900 ssids = alc662_ssids;
5901 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005902}
5903
Todd Broch6be79482010-12-07 16:51:05 -08005904static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005905 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005906{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005907 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005908 return;
Todd Broch6be79482010-12-07 16:51:05 -08005909 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5910 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5911 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5912 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5913 (0 << AC_AMPCAP_MUTE_SHIFT)))
5914 printk(KERN_WARNING
5915 "hda_codec: failed to override amp caps for NID 0x2\n");
5916}
5917
David Henningsson6cb3b702010-09-09 08:51:44 +02005918enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005919 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005920 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005921 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005922 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005923 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005924 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005925 ALC662_FIXUP_ASUS_MODE1,
5926 ALC662_FIXUP_ASUS_MODE2,
5927 ALC662_FIXUP_ASUS_MODE3,
5928 ALC662_FIXUP_ASUS_MODE4,
5929 ALC662_FIXUP_ASUS_MODE5,
5930 ALC662_FIXUP_ASUS_MODE6,
5931 ALC662_FIXUP_ASUS_MODE7,
5932 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005933};
5934
5935static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005936 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005937 .type = ALC_FIXUP_PINS,
5938 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005939 { 0x15, 0x99130112 }, /* subwoofer */
5940 { }
5941 }
5942 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005943 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005944 .type = ALC_FIXUP_PINS,
5945 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005946 { 0x17, 0x99130112 }, /* subwoofer */
5947 { }
5948 }
5949 },
Todd Broch6be79482010-12-07 16:51:05 -08005950 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005951 .type = ALC_FIXUP_FUNC,
5952 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005953 },
5954 [ALC662_FIXUP_CZC_P10T] = {
5955 .type = ALC_FIXUP_VERBS,
5956 .v.verbs = (const struct hda_verb[]) {
5957 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5958 {}
5959 }
5960 },
David Henningsson94024cd2011-04-29 14:10:55 +02005961 [ALC662_FIXUP_SKU_IGNORE] = {
5962 .type = ALC_FIXUP_SKU,
5963 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005964 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005965 [ALC662_FIXUP_HP_RP5800] = {
5966 .type = ALC_FIXUP_PINS,
5967 .v.pins = (const struct alc_pincfg[]) {
5968 { 0x14, 0x0221201f }, /* HP out */
5969 { }
5970 },
5971 .chained = true,
5972 .chain_id = ALC662_FIXUP_SKU_IGNORE
5973 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005974 [ALC662_FIXUP_ASUS_MODE1] = {
5975 .type = ALC_FIXUP_PINS,
5976 .v.pins = (const struct alc_pincfg[]) {
5977 { 0x14, 0x99130110 }, /* speaker */
5978 { 0x18, 0x01a19c20 }, /* mic */
5979 { 0x19, 0x99a3092f }, /* int-mic */
5980 { 0x21, 0x0121401f }, /* HP out */
5981 { }
5982 },
5983 .chained = true,
5984 .chain_id = ALC662_FIXUP_SKU_IGNORE
5985 },
5986 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005987 .type = ALC_FIXUP_PINS,
5988 .v.pins = (const struct alc_pincfg[]) {
5989 { 0x14, 0x99130110 }, /* speaker */
5990 { 0x18, 0x01a19820 }, /* mic */
5991 { 0x19, 0x99a3092f }, /* int-mic */
5992 { 0x1b, 0x0121401f }, /* HP out */
5993 { }
5994 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005995 .chained = true,
5996 .chain_id = ALC662_FIXUP_SKU_IGNORE
5997 },
5998 [ALC662_FIXUP_ASUS_MODE3] = {
5999 .type = ALC_FIXUP_PINS,
6000 .v.pins = (const struct alc_pincfg[]) {
6001 { 0x14, 0x99130110 }, /* speaker */
6002 { 0x15, 0x0121441f }, /* HP */
6003 { 0x18, 0x01a19840 }, /* mic */
6004 { 0x19, 0x99a3094f }, /* int-mic */
6005 { 0x21, 0x01211420 }, /* HP2 */
6006 { }
6007 },
6008 .chained = true,
6009 .chain_id = ALC662_FIXUP_SKU_IGNORE
6010 },
6011 [ALC662_FIXUP_ASUS_MODE4] = {
6012 .type = ALC_FIXUP_PINS,
6013 .v.pins = (const struct alc_pincfg[]) {
6014 { 0x14, 0x99130110 }, /* speaker */
6015 { 0x16, 0x99130111 }, /* speaker */
6016 { 0x18, 0x01a19840 }, /* mic */
6017 { 0x19, 0x99a3094f }, /* int-mic */
6018 { 0x21, 0x0121441f }, /* HP */
6019 { }
6020 },
6021 .chained = true,
6022 .chain_id = ALC662_FIXUP_SKU_IGNORE
6023 },
6024 [ALC662_FIXUP_ASUS_MODE5] = {
6025 .type = ALC_FIXUP_PINS,
6026 .v.pins = (const struct alc_pincfg[]) {
6027 { 0x14, 0x99130110 }, /* speaker */
6028 { 0x15, 0x0121441f }, /* HP */
6029 { 0x16, 0x99130111 }, /* speaker */
6030 { 0x18, 0x01a19840 }, /* mic */
6031 { 0x19, 0x99a3094f }, /* int-mic */
6032 { }
6033 },
6034 .chained = true,
6035 .chain_id = ALC662_FIXUP_SKU_IGNORE
6036 },
6037 [ALC662_FIXUP_ASUS_MODE6] = {
6038 .type = ALC_FIXUP_PINS,
6039 .v.pins = (const struct alc_pincfg[]) {
6040 { 0x14, 0x99130110 }, /* speaker */
6041 { 0x15, 0x01211420 }, /* HP2 */
6042 { 0x18, 0x01a19840 }, /* mic */
6043 { 0x19, 0x99a3094f }, /* int-mic */
6044 { 0x1b, 0x0121441f }, /* HP */
6045 { }
6046 },
6047 .chained = true,
6048 .chain_id = ALC662_FIXUP_SKU_IGNORE
6049 },
6050 [ALC662_FIXUP_ASUS_MODE7] = {
6051 .type = ALC_FIXUP_PINS,
6052 .v.pins = (const struct alc_pincfg[]) {
6053 { 0x14, 0x99130110 }, /* speaker */
6054 { 0x17, 0x99130111 }, /* speaker */
6055 { 0x18, 0x01a19840 }, /* mic */
6056 { 0x19, 0x99a3094f }, /* int-mic */
6057 { 0x1b, 0x01214020 }, /* HP */
6058 { 0x21, 0x0121401f }, /* HP */
6059 { }
6060 },
6061 .chained = true,
6062 .chain_id = ALC662_FIXUP_SKU_IGNORE
6063 },
6064 [ALC662_FIXUP_ASUS_MODE8] = {
6065 .type = ALC_FIXUP_PINS,
6066 .v.pins = (const struct alc_pincfg[]) {
6067 { 0x14, 0x99130110 }, /* speaker */
6068 { 0x12, 0x99a30970 }, /* int-mic */
6069 { 0x15, 0x01214020 }, /* HP */
6070 { 0x17, 0x99130111 }, /* speaker */
6071 { 0x18, 0x01a19840 }, /* mic */
6072 { 0x21, 0x0121401f }, /* HP */
6073 { }
6074 },
6075 .chained = true,
6076 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006077 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006078};
6079
Takashi Iwaia9111322011-05-02 11:30:18 +02006080static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006081 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006082 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006083 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006084 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006085 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006086 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006087 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006088 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006089 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006090 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006091
6092#if 0
6093 /* Below is a quirk table taken from the old code.
6094 * Basically the device should work as is without the fixup table.
6095 * If BIOS doesn't give a proper info, enable the corresponding
6096 * fixup entry.
6097 */
6098 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6099 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6100 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6101 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6102 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6103 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6104 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6105 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6106 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6107 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6108 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6109 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6110 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6111 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6112 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6113 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6114 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6115 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6116 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6117 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6118 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6119 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6120 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6121 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6122 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6123 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6124 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6125 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6126 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6127 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6128 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6129 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6130 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6131 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6132 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6133 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6134 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6135 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6136 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6137 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6138 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6139 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6140 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6141 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6142 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6143 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6144 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6145 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6146 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6147 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6148#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006149 {}
6150};
6151
Todd Broch6be79482010-12-07 16:51:05 -08006152static const struct alc_model_fixup alc662_fixup_models[] = {
6153 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006154 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6155 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6156 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6157 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6158 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6159 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6160 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6161 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006162 {}
6163};
David Henningsson6cb3b702010-09-09 08:51:44 +02006164
6165
Takashi Iwai1d045db2011-07-07 18:23:21 +02006166/*
6167 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006168static int patch_alc662(struct hda_codec *codec)
6169{
6170 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006171 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006172
6173 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6174 if (!spec)
6175 return -ENOMEM;
6176
6177 codec->spec = spec;
6178
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006179 spec->mixer_nid = 0x0b;
6180
Takashi Iwai53c334a2011-08-23 18:27:14 +02006181 /* handle multiple HPs as is */
6182 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6183
Kailang Yangda00c242010-03-19 11:23:45 +01006184 alc_auto_parse_customize_define(codec);
6185
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006186 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6187
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006188 err = alc_codec_rename_from_preset(codec);
6189 if (err < 0)
6190 goto error;
6191
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006192 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006193 codec->bus->pci->subsystem_vendor == 0x1025 &&
6194 spec->cdefine.platform_type == 1) {
6195 if (alc_codec_rename(codec, "ALC272X") < 0)
6196 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006197 }
Kailang Yang274693f2009-12-03 10:07:50 +01006198
Takashi Iwaib9c51062011-08-24 18:08:07 +02006199 alc_pick_fixup(codec, alc662_fixup_models,
6200 alc662_fixup_tbl, alc662_fixups);
6201 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6202 /* automatic parse from the BIOS config */
6203 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006204 if (err < 0)
6205 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006206
Takashi Iwai60a6a842011-07-27 14:01:24 +02006207 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006208 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006209 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006210 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006211 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006212
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006213 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006214 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006215
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006216 if (!spec->no_analog && has_cdefine_beep(codec)) {
6217 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006218 if (err < 0)
6219 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006220 switch (codec->vendor_id) {
6221 case 0x10ec0662:
6222 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6223 break;
6224 case 0x10ec0272:
6225 case 0x10ec0663:
6226 case 0x10ec0665:
6227 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6228 break;
6229 case 0x10ec0273:
6230 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6231 break;
6232 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006233 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006234
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006235 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6236
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006237 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006238 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006239 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006240
Takashi Iwaicb53c622007-08-10 17:21:45 +02006241#ifdef CONFIG_SND_HDA_POWER_SAVE
6242 if (!spec->loopback.amplist)
6243 spec->loopback.amplist = alc662_loopbacks;
6244#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006245
6246 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006247
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006248 error:
6249 alc_free(codec);
6250 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006251}
6252
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006253/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006254 * ALC680 support
6255 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006256
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006257static int alc680_parse_auto_config(struct hda_codec *codec)
6258{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006259 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006260}
6261
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006262/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006263 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006264static int patch_alc680(struct hda_codec *codec)
6265{
6266 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006267 int err;
6268
6269 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6270 if (spec == NULL)
6271 return -ENOMEM;
6272
6273 codec->spec = spec;
6274
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006275 /* ALC680 has no aa-loopback mixer */
6276
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006277 /* automatic parse from the BIOS config */
6278 err = alc680_parse_auto_config(codec);
6279 if (err < 0) {
6280 alc_free(codec);
6281 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006282 }
6283
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006284 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006285 set_capture_mixer(codec);
6286
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006287 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006288 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006289
6290 return 0;
6291}
6292
6293/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294 * patch entries
6295 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006296static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006297 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006299 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006300 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006301 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006302 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006303 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006304 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006305 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006306 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006307 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006308 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006309 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6310 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6311 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006312 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02006313 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006314 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6315 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006316 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6317 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006318 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006319 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006320 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006321 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006322 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006324 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006325 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006326 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006327 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006328 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006329 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006330 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006331 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02006332 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006333 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006334 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006335 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006336 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 {} /* terminator */
6338};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006339
6340MODULE_ALIAS("snd-hda-codec-id:10ec*");
6341
6342MODULE_LICENSE("GPL");
6343MODULE_DESCRIPTION("Realtek HD-audio codec");
6344
6345static struct hda_codec_preset_list realtek_list = {
6346 .preset = snd_hda_preset_realtek,
6347 .owner = THIS_MODULE,
6348};
6349
6350static int __init patch_realtek_init(void)
6351{
6352 return snd_hda_add_codec_preset(&realtek_list);
6353}
6354
6355static void __exit patch_realtek_exit(void)
6356{
6357 snd_hda_delete_codec_preset(&realtek_list);
6358}
6359
6360module_init(patch_realtek_init)
6361module_exit(patch_realtek_exit)