blob: d0c71d5be83f722067602999dda304c7fe1dbd33 [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 Iwai1a1455d2011-04-28 17:36:18 +0200805 "Disabled", "Speaker Only", "Line-Out+Speaker"
806 };
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 Iwai51e41522011-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 Iwai51e41522011-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 Iwai51e41522011-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 Iwai51e41522011-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 Iwai51e41522011-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 Iwai51e41522011-11-03 16:54:06 +01001653 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001654 }
Takashi Iwai51e41522011-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 Iwai9322ca52012-02-03 14:28:01 +01001850static const char * const alc_slave_pfxs[] = {
1851 "Front", "Surround", "Center", "LFE", "Side",
1852 "Headphone", "Speaker", "Mono", "Line-Out",
1853 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001854 NULL,
1855};
1856
1857/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001858 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001860
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001861#define NID_MAPPING (-1)
1862
1863#define SUBDEV_SPEAKER_ (0 << 6)
1864#define SUBDEV_HP_ (1 << 6)
1865#define SUBDEV_LINE_ (2 << 6)
1866#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1867#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1868#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1869
Takashi Iwai603c4012008-07-30 15:01:44 +02001870static void alc_free_kctls(struct hda_codec *codec);
1871
Takashi Iwai67d634c2009-11-16 15:35:59 +01001872#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001873/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001874static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001875 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001876 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001877 { } /* end */
1878};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001879#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001880
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001881static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882{
1883 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001884 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001885 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001886 int i, j, err;
1887 unsigned int u;
1888 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
1890 for (i = 0; i < spec->num_mixers; i++) {
1891 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1892 if (err < 0)
1893 return err;
1894 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001895 if (spec->cap_mixer) {
1896 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1897 if (err < 0)
1898 return err;
1899 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001901 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001902 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001903 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 if (err < 0)
1905 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001906 if (!spec->no_analog) {
1907 err = snd_hda_create_spdif_share_sw(codec,
1908 &spec->multiout);
1909 if (err < 0)
1910 return err;
1911 spec->multiout.share_spdif = 1;
1912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 }
1914 if (spec->dig_in_nid) {
1915 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1916 if (err < 0)
1917 return err;
1918 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001919
Takashi Iwai67d634c2009-11-16 15:35:59 +01001920#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001921 /* create beep controls if needed */
1922 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001923 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001924 for (knew = alc_beep_mixer; knew->name; knew++) {
1925 struct snd_kcontrol *kctl;
1926 kctl = snd_ctl_new1(knew, codec);
1927 if (!kctl)
1928 return -ENOMEM;
1929 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001930 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001931 if (err < 0)
1932 return err;
1933 }
1934 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001935#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001936
Takashi Iwai2134ea42008-01-10 16:53:55 +01001937 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001938 if (!spec->no_analog &&
1939 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001940 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001941 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001942 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001943 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001944 vmaster_tlv, alc_slave_pfxs,
1945 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001946 if (err < 0)
1947 return err;
1948 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001949 if (!spec->no_analog &&
1950 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001951 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001952 NULL, alc_slave_pfxs,
1953 "Playback Switch");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001954 if (err < 0)
1955 return err;
1956 }
1957
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001958 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001959 if (spec->capsrc_nids || spec->adc_nids) {
1960 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1961 if (!kctl)
1962 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1963 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001964 err = snd_hda_add_nid(codec, kctl, i,
1965 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001966 if (err < 0)
1967 return err;
1968 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001969 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001970 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001971 const char *kname = kctl ? kctl->id.name : NULL;
1972 for (knew = spec->cap_mixer; knew->name; knew++) {
1973 if (kname && strcmp(knew->name, kname) == 0)
1974 continue;
1975 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1976 for (i = 0; kctl && i < kctl->count; i++) {
1977 err = snd_hda_add_nid(codec, kctl, i,
1978 spec->adc_nids[i]);
1979 if (err < 0)
1980 return err;
1981 }
1982 }
1983 }
1984
1985 /* other nid->control mapping */
1986 for (i = 0; i < spec->num_mixers; i++) {
1987 for (knew = spec->mixers[i]; knew->name; knew++) {
1988 if (knew->iface != NID_MAPPING)
1989 continue;
1990 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1991 if (kctl == NULL)
1992 continue;
1993 u = knew->subdevice;
1994 for (j = 0; j < 4; j++, u >>= 8) {
1995 nid = u & 0x3f;
1996 if (nid == 0)
1997 continue;
1998 switch (u & 0xc0) {
1999 case SUBDEV_SPEAKER_:
2000 nid = spec->autocfg.speaker_pins[nid];
2001 break;
2002 case SUBDEV_LINE_:
2003 nid = spec->autocfg.line_out_pins[nid];
2004 break;
2005 case SUBDEV_HP_:
2006 nid = spec->autocfg.hp_pins[nid];
2007 break;
2008 default:
2009 continue;
2010 }
2011 err = snd_hda_add_nid(codec, kctl, 0, nid);
2012 if (err < 0)
2013 return err;
2014 }
2015 u = knew->private_value;
2016 for (j = 0; j < 4; j++, u >>= 8) {
2017 nid = u & 0xff;
2018 if (nid == 0)
2019 continue;
2020 err = snd_hda_add_nid(codec, kctl, 0, nid);
2021 if (err < 0)
2022 return err;
2023 }
2024 }
2025 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002026
2027 alc_free_kctls(codec); /* no longer needed */
2028
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002029 return 0;
2030}
2031
2032static int alc_build_controls(struct hda_codec *codec)
2033{
2034 struct alc_spec *spec = codec->spec;
2035 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002036 if (err < 0)
2037 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002038 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039}
2040
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002043 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002044 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002045
Takashi Iwai584c0c42011-03-10 12:51:11 +01002046static void alc_init_special_input_src(struct hda_codec *codec);
2047
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048static int alc_init(struct hda_codec *codec)
2049{
2050 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002051 unsigned int i;
2052
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002053 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002054 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002055
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002056 for (i = 0; i < spec->num_init_verbs; i++)
2057 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002058 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002059
2060 if (spec->init_hook)
2061 spec->init_hook(codec);
2062
Takashi Iwai58701122011-01-13 15:41:45 +01002063 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2064
Takashi Iwai01a61e12011-10-28 00:03:22 +02002065 snd_hda_jack_report_sync(codec);
2066
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002067 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 return 0;
2069}
2070
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002071static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2072{
2073 struct alc_spec *spec = codec->spec;
2074
2075 if (spec->unsol_event)
2076 spec->unsol_event(codec, res);
2077}
2078
Takashi Iwaicb53c622007-08-10 17:21:45 +02002079#ifdef CONFIG_SND_HDA_POWER_SAVE
2080static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2081{
2082 struct alc_spec *spec = codec->spec;
2083 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2084}
2085#endif
2086
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087/*
2088 * Analog playback callbacks
2089 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002090static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002092 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093{
2094 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002095 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2096 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097}
2098
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002099static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 struct hda_codec *codec,
2101 unsigned int stream_tag,
2102 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002103 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
2105 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002106 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2107 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108}
2109
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002110static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002112 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
2114 struct alc_spec *spec = codec->spec;
2115 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2116}
2117
2118/*
2119 * Digital out
2120 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002121static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002123 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
2125 struct alc_spec *spec = codec->spec;
2126 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2127}
2128
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002129static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002130 struct hda_codec *codec,
2131 unsigned int stream_tag,
2132 unsigned int format,
2133 struct snd_pcm_substream *substream)
2134{
2135 struct alc_spec *spec = codec->spec;
2136 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2137 stream_tag, format, substream);
2138}
2139
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002140static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002141 struct hda_codec *codec,
2142 struct snd_pcm_substream *substream)
2143{
2144 struct alc_spec *spec = codec->spec;
2145 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2146}
2147
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002148static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002150 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151{
2152 struct alc_spec *spec = codec->spec;
2153 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2154}
2155
2156/*
2157 * Analog capture
2158 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002159static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 struct hda_codec *codec,
2161 unsigned int stream_tag,
2162 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002163 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
2165 struct alc_spec *spec = codec->spec;
2166
Takashi Iwai63300792008-01-24 15:31:36 +01002167 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 stream_tag, 0, format);
2169 return 0;
2170}
2171
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002172static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002174 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175{
2176 struct alc_spec *spec = codec->spec;
2177
Takashi Iwai888afa12008-03-18 09:57:50 +01002178 snd_hda_codec_cleanup_stream(codec,
2179 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 return 0;
2181}
2182
Takashi Iwai840b64c2010-07-13 22:49:01 +02002183/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002184static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002185 struct hda_codec *codec,
2186 unsigned int stream_tag,
2187 unsigned int format,
2188 struct snd_pcm_substream *substream)
2189{
2190 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002191 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002192 spec->cur_adc_stream_tag = stream_tag;
2193 spec->cur_adc_format = format;
2194 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2195 return 0;
2196}
2197
Takashi Iwai21268962011-07-07 15:01:13 +02002198static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002199 struct hda_codec *codec,
2200 struct snd_pcm_substream *substream)
2201{
2202 struct alc_spec *spec = codec->spec;
2203 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2204 spec->cur_adc = 0;
2205 return 0;
2206}
2207
Takashi Iwai21268962011-07-07 15:01:13 +02002208static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002209 .substreams = 1,
2210 .channels_min = 2,
2211 .channels_max = 2,
2212 .nid = 0, /* fill later */
2213 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002214 .prepare = dyn_adc_capture_pcm_prepare,
2215 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002216 },
2217};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
2219/*
2220 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002221static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 .substreams = 1,
2223 .channels_min = 2,
2224 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002225 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002227 .open = alc_playback_pcm_open,
2228 .prepare = alc_playback_pcm_prepare,
2229 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 },
2231};
2232
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002233static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002234 .substreams = 1,
2235 .channels_min = 2,
2236 .channels_max = 2,
2237 /* NID is set in alc_build_pcms */
2238};
2239
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002240static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002241 .substreams = 1,
2242 .channels_min = 2,
2243 .channels_max = 2,
2244 /* NID is set in alc_build_pcms */
2245};
2246
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002247static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002248 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 .channels_min = 2,
2250 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002251 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002253 .prepare = alc_alt_capture_pcm_prepare,
2254 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 },
2256};
2257
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002258static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 .substreams = 1,
2260 .channels_min = 2,
2261 .channels_max = 2,
2262 /* NID is set in alc_build_pcms */
2263 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002264 .open = alc_dig_playback_pcm_open,
2265 .close = alc_dig_playback_pcm_close,
2266 .prepare = alc_dig_playback_pcm_prepare,
2267 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 },
2269};
2270
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002271static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 .substreams = 1,
2273 .channels_min = 2,
2274 .channels_max = 2,
2275 /* NID is set in alc_build_pcms */
2276};
2277
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002278/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002279static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002280 .substreams = 0,
2281 .channels_min = 0,
2282 .channels_max = 0,
2283};
2284
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285static int alc_build_pcms(struct hda_codec *codec)
2286{
2287 struct alc_spec *spec = codec->spec;
2288 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002289 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002290 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 int i;
2292
2293 codec->num_pcms = 1;
2294 codec->pcm_info = info;
2295
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002296 if (spec->no_analog)
2297 goto skip_analog;
2298
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002299 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2300 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002302
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002303 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002304 p = spec->stream_analog_playback;
2305 if (!p)
2306 p = &alc_pcm_analog_playback;
2307 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002308 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2309 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002310 if (spec->adc_nids) {
2311 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002312 if (!p) {
2313 if (spec->dyn_adc_switch)
2314 p = &dyn_adc_pcm_analog_capture;
2315 else
2316 p = &alc_pcm_analog_capture;
2317 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002318 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002319 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
Takashi Iwai4a471b72005-12-07 13:56:29 +01002322 if (spec->channel_mode) {
2323 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2324 for (i = 0; i < spec->num_channel_mode; i++) {
2325 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2326 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 }
2329 }
2330
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002331 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002332 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002334 snprintf(spec->stream_name_digital,
2335 sizeof(spec->stream_name_digital),
2336 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002337 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002338 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002339 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002341 if (spec->dig_out_type)
2342 info->pcm_type = spec->dig_out_type;
2343 else
2344 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002345 if (spec->multiout.dig_out_nid) {
2346 p = spec->stream_digital_playback;
2347 if (!p)
2348 p = &alc_pcm_digital_playback;
2349 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2351 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002352 if (spec->dig_in_nid) {
2353 p = spec->stream_digital_capture;
2354 if (!p)
2355 p = &alc_pcm_digital_capture;
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2358 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002359 /* FIXME: do we need this for all Realtek codec models? */
2360 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 }
2362
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002363 if (spec->no_analog)
2364 return 0;
2365
Takashi Iwaie08a0072006-09-07 17:52:14 +02002366 /* If the use of more than one ADC is requested for the current
2367 * model, configure a second analog capture-only PCM.
2368 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002369 have_multi_adcs = (spec->num_adc_nids > 1) &&
2370 !spec->dyn_adc_switch && !spec->auto_mic &&
2371 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002372 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002373 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002374 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002375 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002376 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002377 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002378 p = spec->stream_analog_alt_playback;
2379 if (!p)
2380 p = &alc_pcm_analog_alt_playback;
2381 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002382 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2383 spec->alt_dac_nid;
2384 } else {
2385 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2386 alc_pcm_null_stream;
2387 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2388 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002389 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002390 p = spec->stream_analog_alt_capture;
2391 if (!p)
2392 p = &alc_pcm_analog_alt_capture;
2393 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002394 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2395 spec->adc_nids[1];
2396 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2397 spec->num_adc_nids - 1;
2398 } else {
2399 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2400 alc_pcm_null_stream;
2401 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002402 }
2403 }
2404
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 return 0;
2406}
2407
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002408static inline void alc_shutup(struct hda_codec *codec)
2409{
Takashi Iwai1c716152011-04-07 10:37:16 +02002410 struct alc_spec *spec = codec->spec;
2411
2412 if (spec && spec->shutup)
2413 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002414 snd_hda_shutup_pins(codec);
2415}
2416
Takashi Iwai603c4012008-07-30 15:01:44 +02002417static void alc_free_kctls(struct hda_codec *codec)
2418{
2419 struct alc_spec *spec = codec->spec;
2420
2421 if (spec->kctls.list) {
2422 struct snd_kcontrol_new *kctl = spec->kctls.list;
2423 int i;
2424 for (i = 0; i < spec->kctls.used; i++)
2425 kfree(kctl[i].name);
2426 }
2427 snd_array_free(&spec->kctls);
2428}
2429
Takashi Iwai23c09b02011-08-19 09:05:35 +02002430static void alc_free_bind_ctls(struct hda_codec *codec)
2431{
2432 struct alc_spec *spec = codec->spec;
2433 if (spec->bind_ctls.list) {
2434 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2435 int i;
2436 for (i = 0; i < spec->bind_ctls.used; i++)
2437 kfree(ctl[i]);
2438 }
2439 snd_array_free(&spec->bind_ctls);
2440}
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442static void alc_free(struct hda_codec *codec)
2443{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002444 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002445
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002446 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002447 return;
2448
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002449 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002450 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002451 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002452 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002453 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454}
2455
Hector Martinf5de24b2009-12-20 22:51:31 +01002456#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002457static void alc_power_eapd(struct hda_codec *codec)
2458{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002459 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002460}
2461
Hector Martinf5de24b2009-12-20 22:51:31 +01002462static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2463{
2464 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002465 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002466 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002467 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002468 return 0;
2469}
2470#endif
2471
Takashi Iwai2a439522011-07-26 09:52:50 +02002472#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002473static int alc_resume(struct hda_codec *codec)
2474{
Takashi Iwai1c716152011-04-07 10:37:16 +02002475 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002476 codec->patch_ops.init(codec);
2477 snd_hda_codec_resume_amp(codec);
2478 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002479 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002480 return 0;
2481}
Takashi Iwaie044c392008-10-27 16:56:24 +01002482#endif
2483
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484/*
2485 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002486static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 .build_controls = alc_build_controls,
2488 .build_pcms = alc_build_pcms,
2489 .init = alc_init,
2490 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002491 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002492#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002493 .resume = alc_resume,
2494#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002495#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002496 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002497 .check_power_status = alc_check_power_status,
2498#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002499 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500};
2501
Kailang Yangc027ddc2010-03-19 11:33:06 +01002502/* replace the codec chip_name with the given string */
2503static int alc_codec_rename(struct hda_codec *codec, const char *name)
2504{
2505 kfree(codec->chip_name);
2506 codec->chip_name = kstrdup(name, GFP_KERNEL);
2507 if (!codec->chip_name) {
2508 alc_free(codec);
2509 return -ENOMEM;
2510 }
2511 return 0;
2512}
2513
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002514/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002515 * Rename codecs appropriately from COEF value
2516 */
2517struct alc_codec_rename_table {
2518 unsigned int vendor_id;
2519 unsigned short coef_mask;
2520 unsigned short coef_bits;
2521 const char *name;
2522};
2523
2524static struct alc_codec_rename_table rename_tbl[] = {
2525 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2526 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2527 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2528 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2529 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2530 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2531 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2532 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2533 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2534 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2535 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2536 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2537 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2538 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2539 { } /* terminator */
2540};
2541
2542static int alc_codec_rename_from_preset(struct hda_codec *codec)
2543{
2544 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002545
2546 for (p = rename_tbl; p->vendor_id; p++) {
2547 if (p->vendor_id != codec->vendor_id)
2548 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002549 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002550 return alc_codec_rename(codec, p->name);
2551 }
2552 return 0;
2553}
2554
2555/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002556 * Automatic parse of I/O pins from the BIOS configuration
2557 */
2558
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002559enum {
2560 ALC_CTL_WIDGET_VOL,
2561 ALC_CTL_WIDGET_MUTE,
2562 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002563 ALC_CTL_BIND_VOL,
2564 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002565};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002566static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002567 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2568 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002569 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002570 HDA_BIND_VOL(NULL, 0),
2571 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002572};
2573
2574/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002575static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002576 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002577{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002578 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002579
Takashi Iwaice764ab2011-04-27 16:35:23 +02002580 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002581 if (!knew)
2582 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002583 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002584 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002585 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002586 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002587 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002588 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002589 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002590 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002591 return 0;
2592}
2593
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002594static int add_control_with_pfx(struct alc_spec *spec, int type,
2595 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002596 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002597{
2598 char name[32];
2599 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002600 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002601}
2602
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002603#define add_pb_vol_ctrl(spec, type, pfx, val) \
2604 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2605#define add_pb_sw_ctrl(spec, type, pfx, val) \
2606 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2607#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2608 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2609#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2610 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002611
Takashi Iwai23c09b02011-08-19 09:05:35 +02002612static const char * const channel_name[4] = {
2613 "Front", "Surround", "CLFE", "Side"
2614};
2615
Takashi Iwai6843ca12011-06-24 11:03:58 +02002616static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2617 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002618{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002619 struct auto_pin_cfg *cfg = &spec->autocfg;
2620
Takashi Iwai6843ca12011-06-24 11:03:58 +02002621 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002622 if (cfg->line_outs == 1 && !spec->multi_ios &&
2623 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002624 return "Master";
2625
2626 switch (cfg->line_out_type) {
2627 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002628 if (cfg->line_outs == 1)
2629 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002630 if (cfg->line_outs == 2)
2631 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002632 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002633 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002634 /* for multi-io case, only the primary out */
2635 if (ch && spec->multi_ios)
2636 break;
2637 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002638 return "Headphone";
2639 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002640 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002641 return "PCM";
2642 break;
2643 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002644 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2645 return "PCM";
2646
2647 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002648}
2649
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002650/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002651static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002652 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002653 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002654{
Kailang Yangdf694da2005-12-05 19:42:22 +01002655 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002656
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002657 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002658 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2659 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002660 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002661 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002662 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2663 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002664 return err;
2665 return 0;
2666}
2667
Takashi Iwai05f5f472009-08-25 13:10:18 +02002668static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002669{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002670 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2671 return (pincap & AC_PINCAP_IN) != 0;
2672}
2673
Takashi Iwai1d045db2011-07-07 18:23:21 +02002674/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002675static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002676{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002677 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002678 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002679 hda_nid_t *adc_nids = spec->private_adc_nids;
2680 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2681 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002682 int i, nums = 0;
2683
Takashi Iwai24de1832011-11-07 17:13:39 +01002684 if (spec->shared_mic_hp)
2685 max_nums = 1; /* no multi streams with the shared HP/mic */
2686
Takashi Iwaib7821702011-07-06 15:12:46 +02002687 nid = codec->start_nid;
2688 for (i = 0; i < codec->num_nodes; i++, nid++) {
2689 hda_nid_t src;
2690 const hda_nid_t *list;
2691 unsigned int caps = get_wcaps(codec, nid);
2692 int type = get_wcaps_type(caps);
2693
2694 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2695 continue;
2696 adc_nids[nums] = nid;
2697 cap_nids[nums] = nid;
2698 src = nid;
2699 for (;;) {
2700 int n;
2701 type = get_wcaps_type(get_wcaps(codec, src));
2702 if (type == AC_WID_PIN)
2703 break;
2704 if (type == AC_WID_AUD_SEL) {
2705 cap_nids[nums] = src;
2706 break;
2707 }
2708 n = snd_hda_get_conn_list(codec, src, &list);
2709 if (n > 1) {
2710 cap_nids[nums] = src;
2711 break;
2712 } else if (n != 1)
2713 break;
2714 src = *list;
2715 }
2716 if (++nums >= max_nums)
2717 break;
2718 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002719 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002720 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002721 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002722 return nums;
2723}
2724
Takashi Iwai05f5f472009-08-25 13:10:18 +02002725/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002726static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002727{
2728 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002729 const struct auto_pin_cfg *cfg = &spec->autocfg;
2730 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002731 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002732 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002733 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002734 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002735
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002736 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002737 if (num_adcs < 0)
2738 return 0;
2739
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002740 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002741 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002742 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002743
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002744 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002745 if (!alc_is_input_pin(codec, pin))
2746 continue;
2747
David Henningsson5322bf22011-01-05 11:03:56 +01002748 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002749 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2750 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002751 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002752 type_idx++;
2753 else
2754 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002755 prev_label = label;
2756
Takashi Iwai05f5f472009-08-25 13:10:18 +02002757 if (mixer) {
2758 idx = get_connection_index(codec, mixer, pin);
2759 if (idx >= 0) {
2760 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002761 label, type_idx,
2762 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002763 if (err < 0)
2764 return err;
2765 }
2766 }
2767
Takashi Iwaib7821702011-07-06 15:12:46 +02002768 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002769 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002770 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002771 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002772 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002773 snd_hda_add_imux_item(imux, label, idx, NULL);
2774 break;
2775 }
2776 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002777 }
Takashi Iwai21268962011-07-07 15:01:13 +02002778
2779 spec->num_mux_defs = 1;
2780 spec->input_mux = imux;
2781
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002782 return 0;
2783}
2784
Takashi Iwai24de1832011-11-07 17:13:39 +01002785/* create a shared input with the headphone out */
2786static int alc_auto_create_shared_input(struct hda_codec *codec)
2787{
2788 struct alc_spec *spec = codec->spec;
2789 struct auto_pin_cfg *cfg = &spec->autocfg;
2790 unsigned int defcfg;
2791 hda_nid_t nid;
2792
2793 /* only one internal input pin? */
2794 if (cfg->num_inputs != 1)
2795 return 0;
2796 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2797 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2798 return 0;
2799
2800 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2801 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2802 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2803 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2804 else
2805 return 0; /* both not available */
2806
2807 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2808 return 0; /* no input */
2809
2810 cfg->inputs[1].pin = nid;
2811 cfg->inputs[1].type = AUTO_PIN_MIC;
2812 cfg->num_inputs = 2;
2813 spec->shared_mic_hp = 1;
2814 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2815 return 0;
2816}
2817
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002818static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2819 unsigned int pin_type)
2820{
2821 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2822 pin_type);
2823 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002824 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2825 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002826 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002827}
2828
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002829static int get_pin_type(int line_out_type)
2830{
2831 if (line_out_type == AUTO_PIN_HP_OUT)
2832 return PIN_HP;
2833 else
2834 return PIN_OUT;
2835}
2836
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002837static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002838{
2839 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002840 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002841 int i;
2842
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002843 for (i = 0; i < cfg->num_inputs; i++) {
2844 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002845 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002846 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002847 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002848 snd_hda_codec_write(codec, nid, 0,
2849 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002850 AMP_OUT_MUTE);
2851 }
2852 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002853
2854 /* mute all loopback inputs */
2855 if (spec->mixer_nid) {
2856 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2857 for (i = 0; i < nums; i++)
2858 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2859 AC_VERB_SET_AMP_GAIN_MUTE,
2860 AMP_IN_MUTE(i));
2861 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002862}
2863
Takashi Iwai7085ec12009-10-02 09:03:58 +02002864/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002865static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002866{
Takashi Iwai604401a2011-04-27 15:14:23 +02002867 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002868 int i, num;
2869
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002870 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2871 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002872 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2873 for (i = 0; i < num; i++) {
2874 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2875 return list[i];
2876 }
2877 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002878}
2879
Takashi Iwai604401a2011-04-27 15:14:23 +02002880/* go down to the selector widget before the mixer */
2881static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2882{
2883 hda_nid_t srcs[5];
2884 int num = snd_hda_get_connections(codec, pin, srcs,
2885 ARRAY_SIZE(srcs));
2886 if (num != 1 ||
2887 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2888 return pin;
2889 return srcs[0];
2890}
2891
Takashi Iwai7085ec12009-10-02 09:03:58 +02002892/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002893static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002894 hda_nid_t dac)
2895{
David Henningssoncc1c4522010-11-24 14:17:47 +01002896 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002897 int i, num;
2898
Takashi Iwai604401a2011-04-27 15:14:23 +02002899 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002900 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2901 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002902 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002903 return mix[i];
2904 }
2905 return 0;
2906}
2907
Takashi Iwaice764ab2011-04-27 16:35:23 +02002908/* select the connection from pin to DAC if needed */
2909static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2910 hda_nid_t dac)
2911{
2912 hda_nid_t mix[5];
2913 int i, num;
2914
2915 pin = alc_go_down_to_selector(codec, pin);
2916 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2917 if (num < 2)
2918 return 0;
2919 for (i = 0; i < num; i++) {
2920 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2921 snd_hda_codec_update_cache(codec, pin, 0,
2922 AC_VERB_SET_CONNECT_SEL, i);
2923 return 0;
2924 }
2925 }
2926 return 0;
2927}
2928
Takashi Iwai185d99f2012-02-16 18:39:45 +01002929static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2930{
2931 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002932 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002933 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2934 ARRAY_SIZE(spec->private_dac_nids)) ||
2935 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2936 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2937 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2938 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2939 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002940 for (i = 0; i < spec->multi_ios; i++) {
2941 if (spec->multi_io[i].dac == nid)
2942 return true;
2943 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002944 return false;
2945}
2946
Takashi Iwai7085ec12009-10-02 09:03:58 +02002947/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002948static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002949{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002950 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002951 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002952
Takashi Iwai604401a2011-04-27 15:14:23 +02002953 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002954 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002955 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002956 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002957 if (!nid)
2958 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002959 if (!alc_is_dac_already_used(codec, nid))
2960 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002961 }
2962 return 0;
2963}
2964
Takashi Iwai07b18f62011-11-10 15:42:54 +01002965/* check whether the DAC is reachable from the pin */
2966static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2967 hda_nid_t pin, hda_nid_t dac)
2968{
2969 hda_nid_t srcs[5];
2970 int i, num;
2971
2972 pin = alc_go_down_to_selector(codec, pin);
2973 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2974 for (i = 0; i < num; i++) {
2975 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2976 if (nid == dac)
2977 return true;
2978 }
2979 return false;
2980}
2981
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002982static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2983{
Takashi Iwai140547e2012-02-16 17:23:46 +01002984 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002985 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002986 hda_nid_t nid, nid_found, srcs[5];
2987 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01002988 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01002989 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002990 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002991 nid_found = 0;
2992 for (i = 0; i < num; i++) {
2993 if (srcs[i] == spec->mixer_nid)
2994 continue;
2995 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2996 if (nid && !alc_is_dac_already_used(codec, nid)) {
2997 if (nid_found)
2998 return 0;
2999 nid_found = nid;
3000 }
3001 }
3002 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003003}
3004
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003005/* mark up volume and mute control NIDs: used during badness parsing and
3006 * at creating actual controls
3007 */
3008static inline unsigned int get_ctl_pos(unsigned int data)
3009{
3010 hda_nid_t nid = get_amp_nid_(data);
3011 unsigned int dir;
3012 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3013 return 0;
3014 dir = get_amp_direction_(data);
3015 return (nid << 1) | dir;
3016}
3017
3018#define is_ctl_used(bits, data) \
3019 test_bit(get_ctl_pos(data), bits)
3020#define mark_ctl_usage(bits, data) \
3021 set_bit(get_ctl_pos(data), bits)
3022
3023static void clear_vol_marks(struct hda_codec *codec)
3024{
3025 struct alc_spec *spec = codec->spec;
3026 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3027 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3028}
3029
3030/* badness definition */
3031enum {
3032 /* No primary DAC is found for the main output */
3033 BAD_NO_PRIMARY_DAC = 0x10000,
3034 /* No DAC is found for the extra output */
3035 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003036 /* No possible multi-ios */
3037 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003038 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003039 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003040 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003041 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003042 /* Primary DAC shared with main surrounds */
3043 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003044 /* Primary DAC shared with main CLFE */
3045 BAD_SHARED_CLFE = 0x10,
3046 /* Primary DAC shared with extra surrounds */
3047 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003048 /* Volume widget is shared */
3049 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003050};
3051
3052static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3053 hda_nid_t pin, hda_nid_t dac);
3054static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3055 hda_nid_t pin, hda_nid_t dac);
3056
3057static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3058 hda_nid_t dac)
3059{
3060 struct alc_spec *spec = codec->spec;
3061 hda_nid_t nid;
3062 unsigned int val;
3063 int badness = 0;
3064
3065 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3066 if (nid) {
3067 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3068 if (is_ctl_used(spec->vol_ctls, nid))
3069 badness += BAD_SHARED_VOL;
3070 else
3071 mark_ctl_usage(spec->vol_ctls, val);
3072 } else
3073 badness += BAD_SHARED_VOL;
3074 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3075 if (nid) {
3076 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3077 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3078 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3079 else
3080 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3081 if (is_ctl_used(spec->sw_ctls, val))
3082 badness += BAD_SHARED_VOL;
3083 else
3084 mark_ctl_usage(spec->sw_ctls, val);
3085 } else
3086 badness += BAD_SHARED_VOL;
3087 return badness;
3088}
3089
3090/* try to assign DACs to extra pins and return the resultant badness */
Takashi Iwaic2674682011-08-24 17:57:44 +02003091static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3092 const hda_nid_t *pins, hda_nid_t *dacs)
3093{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003094 struct alc_spec *spec = codec->spec;
Takashi Iwaic2674682011-08-24 17:57:44 +02003095 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003096 int badness = 0;
3097 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003098
Takashi Iwai185d99f2012-02-16 18:39:45 +01003099 if (!num_outs)
3100 return 0;
3101
3102 if (!dacs[0])
3103 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3104 if (!dacs[0]) {
3105 for (i = 1; i < num_outs; i++) {
3106 dac = dacs[i];
3107 if (dac && alc_auto_is_dac_reachable(codec, pins[0], dac)) {
3108 dacs[0] = dac;
3109 dacs[i] = 0;
3110 break;
3111 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003112 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003113 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003114 dac = dacs[0];
3115 if (!dac) {
3116 dac = spec->private_dac_nids[0];
3117 if (!alc_auto_is_dac_reachable(codec, pins[0], dac))
3118 return BAD_NO_DAC;
3119 badness += BAD_NO_EXTRA_DAC;
3120 }
3121 if (dac)
3122 badness += eval_shared_vol_badness(codec, pins[0], dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003123
3124 for (i = 1; i < num_outs; i++)
3125 dacs[i] = get_dac_if_single(codec, pins[i]);
3126 for (i = 1; i < num_outs; i++) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003127 dac = dacs[i];
3128 if (!dac)
3129 dac = dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3130 if (!dac) {
3131 if (alc_auto_is_dac_reachable(codec, pins[i], dacs[0])) {
3132 dac = dacs[0];
3133 badness += BAD_SHARED_EXTRA_SURROUND;
3134 } else if (alc_auto_is_dac_reachable(codec, pins[i],
3135 spec->private_dac_nids[0])) {
3136 dac = spec->private_dac_nids[0];
3137 badness += BAD_NO_EXTRA_SURR_DAC;
3138 } else
3139 badness += BAD_NO_DAC;
3140 }
3141 if (dac)
3142 badness += eval_shared_vol_badness(codec, pins[i], dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003143 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003144 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003145}
3146
3147static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003148 hda_nid_t reference_pin,
3149 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003150
Takashi Iwai185d99f2012-02-16 18:39:45 +01003151static bool alc_map_singles(struct hda_codec *codec, int outs,
3152 const hda_nid_t *pins, hda_nid_t *dacs)
3153{
3154 int i;
3155 bool found = false;
3156 for (i = 0; i < outs; i++) {
3157 if (dacs[i])
3158 continue;
3159 dacs[i] = get_dac_if_single(codec, pins[i]);
3160 if (dacs[i])
3161 found = true;
3162 }
3163 return found;
3164}
3165
Takashi Iwai7085ec12009-10-02 09:03:58 +02003166/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003167static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003168 bool fill_hardwired,
3169 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003170{
3171 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003172 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003173 int i, j, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003174
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003175 /* set num_dacs once to full for alc_auto_look_for_dac() */
3176 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003177 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003178 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3179 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3180 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003181 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003182 clear_vol_marks(codec);
3183 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003184
3185 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003186 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003187 bool mapped;
3188 do {
3189 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003190 cfg->line_out_pins,
3191 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003192 mapped |= alc_map_singles(codec, cfg->hp_outs,
3193 cfg->hp_pins,
3194 spec->multiout.hp_out_nid);
3195 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3196 cfg->speaker_pins,
3197 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003198 if (fill_mio_first && cfg->line_outs == 1 &&
3199 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3200 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3201 if (!err)
3202 mapped = true;
3203 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003204 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003205 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003206
3207 for (i = 0; i < cfg->line_outs; i++) {
3208 hda_nid_t pin = cfg->line_out_pins[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003209 hda_nid_t dac;
3210 if (!spec->private_dac_nids[i])
3211 spec->private_dac_nids[i] =
3212 alc_auto_look_for_dac(codec, pin);
3213 dac = spec->private_dac_nids[i];
Takashi Iwai185d99f2012-02-16 18:39:45 +01003214 if (!dac && !i) {
3215 for (j = 1; j < cfg->line_outs; j++) {
3216 hda_nid_t dac2 = spec->private_dac_nids[j];
3217 if (dac2 &&
3218 alc_auto_is_dac_reachable(codec, pin, dac2)) {
3219 dac = spec->private_dac_nids[0] = dac2;
3220 spec->private_dac_nids[j] = 0;
3221 break;
3222 }
3223 }
3224 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003225 if (!dac) {
3226 if (!i)
3227 badness += BAD_NO_PRIMARY_DAC;
3228 else if (alc_auto_is_dac_reachable(codec, pin,
3229 spec->private_dac_nids[0])) {
3230 if (i == 1)
3231 badness += BAD_SHARED_SURROUND;
3232 else
3233 badness += BAD_SHARED_CLFE;
3234 dac = spec->private_dac_nids[0];
3235 } else
3236 badness += BAD_NO_DAC;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003237 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003238 if (dac)
3239 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003240 }
3241
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003242 /* re-count num_dacs and squash invalid entries */
3243 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003244 for (i = 0; i < cfg->line_outs; i++) {
3245 if (spec->private_dac_nids[i])
3246 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003247 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003248 memmove(spec->private_dac_nids + i,
3249 spec->private_dac_nids + i + 1,
3250 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003251 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3252 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003253 }
3254
Takashi Iwai276dd702012-02-17 16:17:03 +01003255 if (fill_mio_first &&
3256 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003257 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003258 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003259 if (err < 0)
3260 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003261 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003262 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003263
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003264 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3265 err = alc_auto_fill_extra_dacs(codec, cfg->hp_outs,
3266 cfg->hp_pins,
3267 spec->multiout.hp_out_nid);
3268 if (err < 0)
3269 return err;
3270 badness += err;
3271 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003272 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003273 err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3274 cfg->speaker_pins,
3275 spec->multiout.extra_out_nid);
3276 if (err < 0)
3277 return err;
3278 badness += err;
3279 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003280 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3281 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003282 if (err < 0)
3283 return err;
3284 badness += err;
3285 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003286 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3287 /* try multi-ios with HP + inputs */
3288 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, 1);
3289 if (err < 0)
3290 return err;
3291 badness += err;
3292 }
3293
3294 if (spec->multi_ios == 2) {
3295 for (i = 0; i < 2; i++)
3296 spec->private_dac_nids[spec->multiout.num_dacs++] =
3297 spec->multi_io[i].dac;
3298 spec->ext_channel_count = 2;
3299 } else if (spec->multi_ios) {
3300 spec->multi_ios = 0;
3301 badness += BAD_MULTI_IO;
3302 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003303
3304 return badness;
3305}
3306
3307#define DEBUG_BADNESS
3308
3309#ifdef DEBUG_BADNESS
3310#define debug_badness snd_printdd
3311#else
3312#define debug_badness(...)
3313#endif
3314
3315static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3316{
3317 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3318 cfg->line_out_pins[0], cfg->line_out_pins[1],
3319 cfg->line_out_pins[2], cfg->line_out_pins[2],
3320 spec->multiout.dac_nids[0],
3321 spec->multiout.dac_nids[1],
3322 spec->multiout.dac_nids[2],
3323 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003324 if (spec->multi_ios > 0)
3325 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3326 spec->multi_ios,
3327 spec->multi_io[0].pin, spec->multi_io[1].pin,
3328 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003329 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3330 cfg->hp_pins[0], cfg->hp_pins[1],
3331 cfg->hp_pins[2], cfg->hp_pins[2],
3332 spec->multiout.hp_out_nid[0],
3333 spec->multiout.hp_out_nid[1],
3334 spec->multiout.hp_out_nid[2],
3335 spec->multiout.hp_out_nid[3]);
3336 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3337 cfg->speaker_pins[0], cfg->speaker_pins[1],
3338 cfg->speaker_pins[2], cfg->speaker_pins[3],
3339 spec->multiout.extra_out_nid[0],
3340 spec->multiout.extra_out_nid[1],
3341 spec->multiout.extra_out_nid[2],
3342 spec->multiout.extra_out_nid[3]);
3343}
3344
3345static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3346{
3347 struct alc_spec *spec = codec->spec;
3348 struct auto_pin_cfg *cfg = &spec->autocfg;
3349 struct auto_pin_cfg *best_cfg;
3350 int best_badness = INT_MAX;
3351 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003352 bool fill_hardwired = true, fill_mio_first = true;
3353 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003354 bool hp_spk_swapped = false;
3355
3356 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3357 if (!best_cfg)
3358 return -ENOMEM;
3359 *best_cfg = *cfg;
3360
3361 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003362 badness = fill_and_eval_dacs(codec, fill_hardwired,
3363 fill_mio_first);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003364 if (badness < 0)
3365 return badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003366 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3367 cfg->line_out_type, fill_hardwired, fill_mio_first,
3368 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003369 debug_show_configs(spec, cfg);
3370 if (badness < best_badness) {
3371 best_badness = badness;
3372 *best_cfg = *cfg;
3373 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003374 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003375 }
3376 if (!badness)
3377 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003378 fill_mio_first = !fill_mio_first;
3379 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003380 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003381 fill_hardwired = !fill_hardwired;
3382 if (!fill_hardwired)
3383 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003384 if (hp_spk_swapped)
3385 break;
3386 hp_spk_swapped = true;
3387 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003388 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3389 cfg->hp_outs = cfg->line_outs;
3390 memcpy(cfg->hp_pins, cfg->line_out_pins,
3391 sizeof(cfg->hp_pins));
3392 cfg->line_outs = cfg->speaker_outs;
3393 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3394 sizeof(cfg->speaker_pins));
3395 cfg->speaker_outs = 0;
3396 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3397 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003398 fill_hardwired = true;
3399 continue;
3400 }
3401 if (cfg->hp_outs > 0 &&
3402 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3403 cfg->speaker_outs = cfg->line_outs;
3404 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3405 sizeof(cfg->speaker_pins));
3406 cfg->line_outs = cfg->hp_outs;
3407 memcpy(cfg->line_out_pins, cfg->hp_pins,
3408 sizeof(cfg->hp_pins));
3409 cfg->hp_outs = 0;
3410 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3411 cfg->line_out_type = AUTO_PIN_HP_OUT;
3412 fill_hardwired = true;
3413 continue;
3414 }
3415 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003416 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003417
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003418 if (badness) {
3419 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003420 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003421 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003422 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3423 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003424 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003425
David Henningssonfde48a12011-12-09 18:27:42 +08003426 if (cfg->line_out_pins[0])
3427 spec->vmaster_nid =
3428 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3429 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003430
3431 /* clear the bitmap flags for creating controls */
3432 clear_vol_marks(codec);
3433 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003434 return 0;
3435}
3436
Takashi Iwai343a04b2011-07-06 14:28:39 +02003437static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003438 const char *pfx, int cidx,
3439 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003440{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003441 struct alc_spec *spec = codec->spec;
3442 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003443 if (!nid)
3444 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003445 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3446 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3447 return 0;
3448 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003449 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003450 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003451}
3452
Takashi Iwaie29d3772011-11-14 17:13:23 +01003453static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3454 const char *pfx, int cidx,
3455 hda_nid_t nid)
3456{
3457 int chs = 1;
3458 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3459 chs = 3;
3460 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3461}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003462
3463/* create a mute-switch for the given mixer widget;
3464 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3465 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003466static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003467 const char *pfx, int cidx,
3468 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003469{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003470 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003471 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003472 int type;
3473 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003474 if (!nid)
3475 return 0;
3476 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3477 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3478 type = ALC_CTL_WIDGET_MUTE;
3479 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3480 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003481 type = ALC_CTL_WIDGET_MUTE;
3482 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3483 } else {
3484 type = ALC_CTL_BIND_MUTE;
3485 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3486 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003487 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3488 return 0;
3489 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003490 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003491}
3492
Takashi Iwaie29d3772011-11-14 17:13:23 +01003493static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3494 int cidx, hda_nid_t nid)
3495{
3496 int chs = 1;
3497 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3498 chs = 3;
3499 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3500}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003501
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003502static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3503 hda_nid_t pin, hda_nid_t dac)
3504{
3505 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3506 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3507 return pin;
3508 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3509 return mix;
3510 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3511 return dac;
3512 return 0;
3513}
3514
3515static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3516 hda_nid_t pin, hda_nid_t dac)
3517{
3518 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3519 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3520 return dac;
3521 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3522 return mix;
3523 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3524 return pin;
3525 return 0;
3526}
3527
Takashi Iwai7085ec12009-10-02 09:03:58 +02003528/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003529static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003530 const struct auto_pin_cfg *cfg)
3531{
3532 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003533 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003534
Takashi Iwaice764ab2011-04-27 16:35:23 +02003535 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003536 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003537 noutputs += spec->multi_ios;
3538
3539 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003540 const char *name;
3541 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003542 hda_nid_t dac, pin;
3543 hda_nid_t sw, vol;
3544
3545 dac = spec->multiout.dac_nids[i];
3546 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003547 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003548 if (i >= cfg->line_outs)
3549 pin = spec->multi_io[i - 1].pin;
3550 else
3551 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003552
3553 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3554 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003555 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003556 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003557 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003558 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003559 if (err < 0)
3560 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003561 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003562 if (err < 0)
3563 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003564 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003565 if (err < 0)
3566 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003567 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003568 if (err < 0)
3569 return err;
3570 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003571 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003572 if (err < 0)
3573 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003574 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003575 if (err < 0)
3576 return err;
3577 }
3578 }
3579 return 0;
3580}
3581
Takashi Iwai343a04b2011-07-06 14:28:39 +02003582static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003583 hda_nid_t dac, const char *pfx,
3584 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003585{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003586 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003587 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003588 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003589
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003590 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003591 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003592 /* the corresponding DAC is already occupied */
3593 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3594 return 0; /* no way */
3595 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003596 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3597 if (is_ctl_used(spec->sw_ctls, val))
3598 return 0; /* already created */
3599 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003600 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003601 }
3602
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003603 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3604 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003605 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003606 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003607 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003608 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003609 if (err < 0)
3610 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003611 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003612}
3613
Takashi Iwai23c09b02011-08-19 09:05:35 +02003614static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3615 unsigned int nums,
3616 struct hda_ctl_ops *ops)
3617{
3618 struct alc_spec *spec = codec->spec;
3619 struct hda_bind_ctls **ctlp, *ctl;
3620 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3621 ctlp = snd_array_new(&spec->bind_ctls);
3622 if (!ctlp)
3623 return NULL;
3624 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3625 *ctlp = ctl;
3626 if (ctl)
3627 ctl->ops = ops;
3628 return ctl;
3629}
3630
3631/* add playback controls for speaker and HP outputs */
3632static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3633 const hda_nid_t *pins,
3634 const hda_nid_t *dacs,
3635 const char *pfx)
3636{
3637 struct alc_spec *spec = codec->spec;
3638 struct hda_bind_ctls *ctl;
3639 char name[32];
3640 int i, n, err;
3641
3642 if (!num_pins || !pins[0])
3643 return 0;
3644
Takashi Iwai527e4d72011-10-27 16:33:27 +02003645 if (num_pins == 1) {
3646 hda_nid_t dac = *dacs;
3647 if (!dac)
3648 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003649 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003650 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003651
3652 if (dacs[num_pins - 1]) {
3653 /* OK, we have a multi-output system with individual volumes */
3654 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003655 if (num_pins >= 3) {
3656 snprintf(name, sizeof(name), "%s %s",
3657 pfx, channel_name[i]);
3658 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3659 name, 0);
3660 } else {
3661 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3662 pfx, i);
3663 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003664 if (err < 0)
3665 return err;
3666 }
3667 return 0;
3668 }
3669
3670 /* Let's create a bind-controls */
3671 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3672 if (!ctl)
3673 return -ENOMEM;
3674 n = 0;
3675 for (i = 0; i < num_pins; i++) {
3676 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3677 ctl->values[n++] =
3678 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3679 }
3680 if (n) {
3681 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3682 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3683 if (err < 0)
3684 return err;
3685 }
3686
3687 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3688 if (!ctl)
3689 return -ENOMEM;
3690 n = 0;
3691 for (i = 0; i < num_pins; i++) {
3692 hda_nid_t vol;
3693 if (!pins[i] || !dacs[i])
3694 continue;
3695 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3696 if (vol)
3697 ctl->values[n++] =
3698 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3699 }
3700 if (n) {
3701 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3702 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3703 if (err < 0)
3704 return err;
3705 }
3706 return 0;
3707}
3708
Takashi Iwai343a04b2011-07-06 14:28:39 +02003709static int alc_auto_create_hp_out(struct hda_codec *codec)
3710{
3711 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003712 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3713 spec->autocfg.hp_pins,
3714 spec->multiout.hp_out_nid,
3715 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003716}
3717
3718static int alc_auto_create_speaker_out(struct hda_codec *codec)
3719{
3720 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003721 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3722 spec->autocfg.speaker_pins,
3723 spec->multiout.extra_out_nid,
3724 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003725}
3726
Takashi Iwai343a04b2011-07-06 14:28:39 +02003727static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003728 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003729 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003730{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003731 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003732 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003733 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003734
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003735 alc_set_pin_output(codec, pin, pin_type);
3736 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003737 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003738 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003739 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003740 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003741 mix = srcs[i];
3742 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003743 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003744 if (!mix)
3745 return;
3746
3747 /* need the manual connection? */
3748 if (num > 1)
3749 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3750 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003751 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3752 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003753 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003754 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003755 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003756 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003757 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003758 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3759 if (nid)
3760 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3761 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003762
3763 /* unmute DAC if it's not assigned to a mixer */
3764 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3765 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3766 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3767 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003768}
3769
Takashi Iwai343a04b2011-07-06 14:28:39 +02003770static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003771{
3772 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003773 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003774 int i;
3775
3776 for (i = 0; i <= HDA_SIDE; i++) {
3777 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3778 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003779 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003780 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003781 }
3782}
3783
Takashi Iwai343a04b2011-07-06 14:28:39 +02003784static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003785{
3786 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003787 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003788 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003789
David Henningsson636030e2011-10-12 19:26:03 +02003790 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003791 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3792 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003793 pin = spec->autocfg.hp_pins[i];
3794 if (!pin)
3795 break;
3796 dac = spec->multiout.hp_out_nid[i];
3797 if (!dac) {
3798 if (i > 0 && spec->multiout.hp_out_nid[0])
3799 dac = spec->multiout.hp_out_nid[0];
3800 else
3801 dac = spec->multiout.dac_nids[0];
3802 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003803 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3804 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003805 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003806 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3807 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003808 pin = spec->autocfg.speaker_pins[i];
3809 if (!pin)
3810 break;
3811 dac = spec->multiout.extra_out_nid[i];
3812 if (!dac) {
3813 if (i > 0 && spec->multiout.extra_out_nid[0])
3814 dac = spec->multiout.extra_out_nid[0];
3815 else
3816 dac = spec->multiout.dac_nids[0];
3817 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003818 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3819 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003820}
3821
Takashi Iwai276dd702012-02-17 16:17:03 +01003822/* check whether the given pin can be a multi-io pin */
3823static bool can_be_multiio_pin(struct hda_codec *codec,
3824 unsigned int location, hda_nid_t nid)
3825{
3826 unsigned int defcfg, caps;
3827
3828 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3829 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3830 return false;
3831 if (location && get_defcfg_location(defcfg) != location)
3832 return false;
3833 caps = snd_hda_query_pin_caps(codec, nid);
3834 if (!(caps & AC_PINCAP_OUT))
3835 return false;
3836 return true;
3837}
3838
Takashi Iwaice764ab2011-04-27 16:35:23 +02003839/*
3840 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003841 *
3842 * When hardwired is set, try to fill ony hardwired pins, and returns
3843 * zero if any pins are filled, non-zero if nothing found.
3844 * When hardwired is off, try to fill possible input pins, and returns
3845 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003846 */
3847static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003848 hda_nid_t reference_pin,
3849 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003850{
3851 struct alc_spec *spec = codec->spec;
3852 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003853 int type, i, j, dacs, num_pins, old_pins;
3854 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3855 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003856 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003857
Takashi Iwai276dd702012-02-17 16:17:03 +01003858 old_pins = spec->multi_ios;
3859 if (old_pins >= 2)
3860 goto end_fill;
3861
3862 num_pins = 0;
3863 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3864 for (i = 0; i < cfg->num_inputs; i++) {
3865 if (cfg->inputs[i].type != type)
3866 continue;
3867 if (can_be_multiio_pin(codec, location,
3868 cfg->inputs[i].pin))
3869 num_pins++;
3870 }
3871 }
3872 if (num_pins < 2)
3873 goto end_fill;
3874
Takashi Iwai07b18f62011-11-10 15:42:54 +01003875 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003876 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3877 for (i = 0; i < cfg->num_inputs; i++) {
3878 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003879 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003880
Takashi Iwaice764ab2011-04-27 16:35:23 +02003881 if (cfg->inputs[i].type != type)
3882 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003883 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003884 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003885 for (j = 0; j < spec->multi_ios; j++) {
3886 if (nid == spec->multi_io[j].pin)
3887 break;
3888 }
3889 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003890 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003891
3892 if (offset && offset + spec->multi_ios < dacs) {
3893 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003894 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3895 dac = 0;
3896 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003897 if (hardwired)
3898 dac = get_dac_if_single(codec, nid);
3899 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003900 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003901 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003902 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003903 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003904 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003905 spec->multi_io[spec->multi_ios].pin = nid;
3906 spec->multi_io[spec->multi_ios].dac = dac;
3907 spec->multi_ios++;
3908 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003909 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003910 }
3911 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003912 end_fill:
3913 if (badness)
3914 badness = BAD_MULTI_IO;
3915 if (old_pins == spec->multi_ios) {
3916 if (hardwired)
3917 return 1; /* nothing found */
3918 else
3919 return badness; /* no badness if nothing found */
3920 }
3921 if (!hardwired && spec->multi_ios < 2) {
3922 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003923 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003924 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003925
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003926 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003927}
3928
3929static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3930 struct snd_ctl_elem_info *uinfo)
3931{
3932 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3933 struct alc_spec *spec = codec->spec;
3934
3935 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3936 uinfo->count = 1;
3937 uinfo->value.enumerated.items = spec->multi_ios + 1;
3938 if (uinfo->value.enumerated.item > spec->multi_ios)
3939 uinfo->value.enumerated.item = spec->multi_ios;
3940 sprintf(uinfo->value.enumerated.name, "%dch",
3941 (uinfo->value.enumerated.item + 1) * 2);
3942 return 0;
3943}
3944
3945static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3946 struct snd_ctl_elem_value *ucontrol)
3947{
3948 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3949 struct alc_spec *spec = codec->spec;
3950 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3951 return 0;
3952}
3953
3954static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3955{
3956 struct alc_spec *spec = codec->spec;
3957 hda_nid_t nid = spec->multi_io[idx].pin;
3958
3959 if (!spec->multi_io[idx].ctl_in)
3960 spec->multi_io[idx].ctl_in =
3961 snd_hda_codec_read(codec, nid, 0,
3962 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3963 if (output) {
3964 snd_hda_codec_update_cache(codec, nid, 0,
3965 AC_VERB_SET_PIN_WIDGET_CONTROL,
3966 PIN_OUT);
3967 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3968 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3969 HDA_AMP_MUTE, 0);
3970 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3971 } else {
3972 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3973 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3974 HDA_AMP_MUTE, HDA_AMP_MUTE);
3975 snd_hda_codec_update_cache(codec, nid, 0,
3976 AC_VERB_SET_PIN_WIDGET_CONTROL,
3977 spec->multi_io[idx].ctl_in);
3978 }
3979 return 0;
3980}
3981
3982static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3983 struct snd_ctl_elem_value *ucontrol)
3984{
3985 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3986 struct alc_spec *spec = codec->spec;
3987 int i, ch;
3988
3989 ch = ucontrol->value.enumerated.item[0];
3990 if (ch < 0 || ch > spec->multi_ios)
3991 return -EINVAL;
3992 if (ch == (spec->ext_channel_count - 1) / 2)
3993 return 0;
3994 spec->ext_channel_count = (ch + 1) * 2;
3995 for (i = 0; i < spec->multi_ios; i++)
3996 alc_set_multi_io(codec, i, i < ch);
3997 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003998 if (spec->need_dac_fix && !spec->const_channel_count)
3999 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004000 return 1;
4001}
4002
Takashi Iwaia9111322011-05-02 11:30:18 +02004003static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004004 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4005 .name = "Channel Mode",
4006 .info = alc_auto_ch_mode_info,
4007 .get = alc_auto_ch_mode_get,
4008 .put = alc_auto_ch_mode_put,
4009};
4010
Takashi Iwai23c09b02011-08-19 09:05:35 +02004011static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004012{
4013 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004014
Takashi Iwaic2674682011-08-24 17:57:44 +02004015 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004016 struct snd_kcontrol_new *knew;
4017
4018 knew = alc_kcontrol_new(spec);
4019 if (!knew)
4020 return -ENOMEM;
4021 *knew = alc_auto_channel_mode_enum;
4022 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4023 if (!knew->name)
4024 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004025 }
4026 return 0;
4027}
4028
Takashi Iwai1d045db2011-07-07 18:23:21 +02004029/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4030 * active input pins
4031 */
4032static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4033{
4034 struct alc_spec *spec = codec->spec;
4035 const struct hda_input_mux *imux;
4036 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4037 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4038 int i, n, nums;
4039
4040 imux = spec->input_mux;
4041 if (!imux)
4042 return;
4043 if (spec->dyn_adc_switch)
4044 return;
4045
4046 nums = 0;
4047 for (n = 0; n < spec->num_adc_nids; n++) {
4048 hda_nid_t cap = spec->private_capsrc_nids[n];
4049 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4050 for (i = 0; i < imux->num_items; i++) {
4051 hda_nid_t pin = spec->imux_pins[i];
4052 if (pin) {
4053 if (get_connection_index(codec, cap, pin) < 0)
4054 break;
4055 } else if (num_conns <= imux->items[i].index)
4056 break;
4057 }
4058 if (i >= imux->num_items) {
4059 adc_nids[nums] = spec->private_adc_nids[n];
4060 capsrc_nids[nums++] = cap;
4061 }
4062 }
4063 if (!nums) {
4064 /* check whether ADC-switch is possible */
4065 if (!alc_check_dyn_adc_switch(codec)) {
4066 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4067 " using fallback 0x%x\n",
4068 codec->chip_name, spec->private_adc_nids[0]);
4069 spec->num_adc_nids = 1;
4070 spec->auto_mic = 0;
4071 return;
4072 }
4073 } else if (nums != spec->num_adc_nids) {
4074 memcpy(spec->private_adc_nids, adc_nids,
4075 nums * sizeof(hda_nid_t));
4076 memcpy(spec->private_capsrc_nids, capsrc_nids,
4077 nums * sizeof(hda_nid_t));
4078 spec->num_adc_nids = nums;
4079 }
4080
4081 if (spec->auto_mic)
4082 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4083 else if (spec->input_mux->num_items == 1)
4084 spec->num_adc_nids = 1; /* reduce to a single ADC */
4085}
4086
4087/*
4088 * initialize ADC paths
4089 */
4090static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4091{
4092 struct alc_spec *spec = codec->spec;
4093 hda_nid_t nid;
4094
4095 nid = spec->adc_nids[adc_idx];
4096 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004097 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004098 snd_hda_codec_write(codec, nid, 0,
4099 AC_VERB_SET_AMP_GAIN_MUTE,
4100 AMP_IN_MUTE(0));
4101 return;
4102 }
4103 if (!spec->capsrc_nids)
4104 return;
4105 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004106 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004107 snd_hda_codec_write(codec, nid, 0,
4108 AC_VERB_SET_AMP_GAIN_MUTE,
4109 AMP_OUT_MUTE);
4110}
4111
4112static void alc_auto_init_input_src(struct hda_codec *codec)
4113{
4114 struct alc_spec *spec = codec->spec;
4115 int c, nums;
4116
4117 for (c = 0; c < spec->num_adc_nids; c++)
4118 alc_auto_init_adc(codec, c);
4119 if (spec->dyn_adc_switch)
4120 nums = 1;
4121 else
4122 nums = spec->num_adc_nids;
4123 for (c = 0; c < nums; c++)
4124 alc_mux_select(codec, 0, spec->cur_mux[c], true);
4125}
4126
4127/* add mic boosts if needed */
4128static int alc_auto_add_mic_boost(struct hda_codec *codec)
4129{
4130 struct alc_spec *spec = codec->spec;
4131 struct auto_pin_cfg *cfg = &spec->autocfg;
4132 int i, err;
4133 int type_idx = 0;
4134 hda_nid_t nid;
4135 const char *prev_label = NULL;
4136
4137 for (i = 0; i < cfg->num_inputs; i++) {
4138 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4139 break;
4140 nid = cfg->inputs[i].pin;
4141 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4142 const char *label;
4143 char boost_label[32];
4144
4145 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004146 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4147 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004148 if (prev_label && !strcmp(label, prev_label))
4149 type_idx++;
4150 else
4151 type_idx = 0;
4152 prev_label = label;
4153
4154 snprintf(boost_label, sizeof(boost_label),
4155 "%s Boost Volume", label);
4156 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4157 boost_label, type_idx,
4158 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4159 if (err < 0)
4160 return err;
4161 }
4162 }
4163 return 0;
4164}
4165
4166/* select or unmute the given capsrc route */
4167static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4168 int idx)
4169{
4170 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4171 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4172 HDA_AMP_MUTE, 0);
4173 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4174 snd_hda_codec_write_cache(codec, cap, 0,
4175 AC_VERB_SET_CONNECT_SEL, idx);
4176 }
4177}
4178
4179/* set the default connection to that pin */
4180static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4181{
4182 struct alc_spec *spec = codec->spec;
4183 int i;
4184
4185 if (!pin)
4186 return 0;
4187 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004188 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004189 int idx;
4190
4191 idx = get_connection_index(codec, cap, pin);
4192 if (idx < 0)
4193 continue;
4194 select_or_unmute_capsrc(codec, cap, idx);
4195 return i; /* return the found index */
4196 }
4197 return -1; /* not found */
4198}
4199
4200/* initialize some special cases for input sources */
4201static void alc_init_special_input_src(struct hda_codec *codec)
4202{
4203 struct alc_spec *spec = codec->spec;
4204 int i;
4205
4206 for (i = 0; i < spec->autocfg.num_inputs; i++)
4207 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4208}
4209
4210/* assign appropriate capture mixers */
4211static void set_capture_mixer(struct hda_codec *codec)
4212{
4213 struct alc_spec *spec = codec->spec;
4214 static const struct snd_kcontrol_new *caps[2][3] = {
4215 { alc_capture_mixer_nosrc1,
4216 alc_capture_mixer_nosrc2,
4217 alc_capture_mixer_nosrc3 },
4218 { alc_capture_mixer1,
4219 alc_capture_mixer2,
4220 alc_capture_mixer3 },
4221 };
4222
4223 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004224 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004225 if (!spec->capsrc_nids)
4226 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004227 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004228 return; /* no volume in capsrc, too */
4229 spec->vol_in_capsrc = 1;
4230 }
4231
4232 if (spec->num_adc_nids > 0) {
4233 int mux = 0;
4234 int num_adcs = 0;
4235
4236 if (spec->input_mux && spec->input_mux->num_items > 1)
4237 mux = 1;
4238 if (spec->auto_mic) {
4239 num_adcs = 1;
4240 mux = 0;
4241 } else if (spec->dyn_adc_switch)
4242 num_adcs = 1;
4243 if (!num_adcs) {
4244 if (spec->num_adc_nids > 3)
4245 spec->num_adc_nids = 3;
4246 else if (!spec->num_adc_nids)
4247 return;
4248 num_adcs = spec->num_adc_nids;
4249 }
4250 spec->cap_mixer = caps[mux][num_adcs - 1];
4251 }
4252}
4253
4254/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004255 * standard auto-parser initializations
4256 */
4257static void alc_auto_init_std(struct hda_codec *codec)
4258{
4259 struct alc_spec *spec = codec->spec;
4260 alc_auto_init_multi_out(codec);
4261 alc_auto_init_extra_out(codec);
4262 alc_auto_init_analog_input(codec);
4263 alc_auto_init_input_src(codec);
4264 alc_auto_init_digital(codec);
4265 if (spec->unsol_event)
4266 alc_inithook(codec);
4267}
4268
4269/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004270 * Digital-beep handlers
4271 */
4272#ifdef CONFIG_SND_HDA_INPUT_BEEP
4273#define set_beep_amp(spec, nid, idx, dir) \
4274 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4275
4276static const struct snd_pci_quirk beep_white_list[] = {
4277 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4278 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4279 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4280 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4281 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4282 {}
4283};
4284
4285static inline int has_cdefine_beep(struct hda_codec *codec)
4286{
4287 struct alc_spec *spec = codec->spec;
4288 const struct snd_pci_quirk *q;
4289 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4290 if (q)
4291 return q->value;
4292 return spec->cdefine.enable_pcbeep;
4293}
4294#else
4295#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4296#define has_cdefine_beep(codec) 0
4297#endif
4298
4299/* parse the BIOS configuration and set up the alc_spec */
4300/* return 1 if successful, 0 if the proper config is not found,
4301 * or a negative error code
4302 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004303static int alc_parse_auto_config(struct hda_codec *codec,
4304 const hda_nid_t *ignore_nids,
4305 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004306{
4307 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004308 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004309 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004310
Takashi Iwai53c334a2011-08-23 18:27:14 +02004311 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4312 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004313 if (err < 0)
4314 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004315 if (!cfg->line_outs) {
4316 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004317 spec->multiout.max_channels = 2;
4318 spec->no_analog = 1;
4319 goto dig_only;
4320 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004321 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004322 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004323
Takashi Iwai06503672011-10-06 08:27:19 +02004324 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4325 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004326 /* use HP as primary out */
4327 cfg->speaker_outs = cfg->line_outs;
4328 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4329 sizeof(cfg->speaker_pins));
4330 cfg->line_outs = cfg->hp_outs;
4331 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4332 cfg->hp_outs = 0;
4333 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4334 cfg->line_out_type = AUTO_PIN_HP_OUT;
4335 }
4336
Takashi Iwai1d045db2011-07-07 18:23:21 +02004337 err = alc_auto_fill_dac_nids(codec);
4338 if (err < 0)
4339 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004340 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004341 if (err < 0)
4342 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004343 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004344 if (err < 0)
4345 return err;
4346 err = alc_auto_create_hp_out(codec);
4347 if (err < 0)
4348 return err;
4349 err = alc_auto_create_speaker_out(codec);
4350 if (err < 0)
4351 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004352 err = alc_auto_create_shared_input(codec);
4353 if (err < 0)
4354 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004355 err = alc_auto_create_input_ctls(codec);
4356 if (err < 0)
4357 return err;
4358
4359 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4360
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004361 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004362 alc_auto_parse_digital(codec);
4363
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004364 if (!spec->no_analog)
4365 alc_remove_invalid_adc_nids(codec);
4366
4367 if (ssid_nids)
4368 alc_ssid_check(codec, ssid_nids);
4369
4370 if (!spec->no_analog) {
4371 alc_auto_check_switches(codec);
4372 err = alc_auto_add_mic_boost(codec);
4373 if (err < 0)
4374 return err;
4375 }
4376
Takashi Iwai1d045db2011-07-07 18:23:21 +02004377 if (spec->kctls.list)
4378 add_mixer(spec, spec->kctls.list);
4379
Takashi Iwai1d045db2011-07-07 18:23:21 +02004380 return 1;
4381}
4382
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004383static int alc880_parse_auto_config(struct hda_codec *codec)
4384{
4385 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4386 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4387 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4388}
4389
Takashi Iwai1d045db2011-07-07 18:23:21 +02004390#ifdef CONFIG_SND_HDA_POWER_SAVE
4391static const struct hda_amp_list alc880_loopbacks[] = {
4392 { 0x0b, HDA_INPUT, 0 },
4393 { 0x0b, HDA_INPUT, 1 },
4394 { 0x0b, HDA_INPUT, 2 },
4395 { 0x0b, HDA_INPUT, 3 },
4396 { 0x0b, HDA_INPUT, 4 },
4397 { } /* end */
4398};
4399#endif
4400
4401/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004402 * ALC880 fix-ups
4403 */
4404enum {
4405 ALC880_FIXUP_GPIO2,
4406 ALC880_FIXUP_MEDION_RIM,
4407};
4408
4409static const struct alc_fixup alc880_fixups[] = {
4410 [ALC880_FIXUP_GPIO2] = {
4411 .type = ALC_FIXUP_VERBS,
4412 .v.verbs = alc_gpio2_init_verbs,
4413 },
4414 [ALC880_FIXUP_MEDION_RIM] = {
4415 .type = ALC_FIXUP_VERBS,
4416 .v.verbs = (const struct hda_verb[]) {
4417 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4418 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4419 { }
4420 },
4421 .chained = true,
4422 .chain_id = ALC880_FIXUP_GPIO2,
4423 },
4424};
4425
4426static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4427 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4428 {}
4429};
4430
4431
4432/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004433 * board setups
4434 */
4435#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4436#define alc_board_config \
4437 snd_hda_check_board_config
4438#define alc_board_codec_sid_config \
4439 snd_hda_check_board_codec_sid_config
4440#include "alc_quirks.c"
4441#else
4442#define alc_board_config(codec, nums, models, tbl) -1
4443#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4444#define setup_preset(codec, x) /* NOP */
4445#endif
4446
4447/*
4448 * OK, here we have finally the patch for ALC880
4449 */
4450#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4451#include "alc880_quirks.c"
4452#endif
4453
4454static int patch_alc880(struct hda_codec *codec)
4455{
4456 struct alc_spec *spec;
4457 int board_config;
4458 int err;
4459
4460 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4461 if (spec == NULL)
4462 return -ENOMEM;
4463
4464 codec->spec = spec;
4465
4466 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004467 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004468
4469 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4470 alc880_models, alc880_cfg_tbl);
4471 if (board_config < 0) {
4472 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4473 codec->chip_name);
4474 board_config = ALC_MODEL_AUTO;
4475 }
4476
4477 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004478 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4479 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4480 }
4481
4482 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004483 /* automatic parse from the BIOS config */
4484 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004485 if (err < 0)
4486 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004487#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4488 else if (!err) {
4489 printk(KERN_INFO
4490 "hda_codec: Cannot set up configuration "
4491 "from BIOS. Using 3-stack mode...\n");
4492 board_config = ALC880_3ST;
4493 }
4494#endif
4495 }
4496
David Henningssonfde48a12011-12-09 18:27:42 +08004497 if (board_config != ALC_MODEL_AUTO) {
4498 spec->vmaster_nid = 0x0c;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004499 setup_preset(codec, &alc880_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004500 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004501
Takashi Iwai60a6a842011-07-27 14:01:24 +02004502 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004503 alc_auto_fill_adc_caps(codec);
4504 alc_rebuild_imux_for_auto_mic(codec);
4505 alc_remove_invalid_adc_nids(codec);
4506 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004507
4508 if (!spec->no_analog && !spec->cap_mixer)
4509 set_capture_mixer(codec);
4510
4511 if (!spec->no_analog) {
4512 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004513 if (err < 0)
4514 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004515 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4516 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004517
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004518 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4519
Takashi Iwai1d045db2011-07-07 18:23:21 +02004520 codec->patch_ops = alc_patch_ops;
4521 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004522 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004523 else
4524 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004525#ifdef CONFIG_SND_HDA_POWER_SAVE
4526 if (!spec->loopback.amplist)
4527 spec->loopback.amplist = alc880_loopbacks;
4528#endif
4529
4530 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004531
4532 error:
4533 alc_free(codec);
4534 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004535}
4536
4537
4538/*
4539 * ALC260 support
4540 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004541static int alc260_parse_auto_config(struct hda_codec *codec)
4542{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004543 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004544 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4545 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004546}
4547
Takashi Iwai1d045db2011-07-07 18:23:21 +02004548#ifdef CONFIG_SND_HDA_POWER_SAVE
4549static const struct hda_amp_list alc260_loopbacks[] = {
4550 { 0x07, HDA_INPUT, 0 },
4551 { 0x07, HDA_INPUT, 1 },
4552 { 0x07, HDA_INPUT, 2 },
4553 { 0x07, HDA_INPUT, 3 },
4554 { 0x07, HDA_INPUT, 4 },
4555 { } /* end */
4556};
4557#endif
4558
4559/*
4560 * Pin config fixes
4561 */
4562enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004563 ALC260_FIXUP_HP_DC5750,
4564 ALC260_FIXUP_HP_PIN_0F,
4565 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004566 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004567 ALC260_FIXUP_GPIO1_TOGGLE,
4568 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004569 ALC260_FIXUP_HP_B1900,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004570};
4571
Takashi Iwai20f7d922012-02-16 12:35:16 +01004572static void alc260_gpio1_automute(struct hda_codec *codec)
4573{
4574 struct alc_spec *spec = codec->spec;
4575 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4576 spec->hp_jack_present);
4577}
4578
4579static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4580 const struct alc_fixup *fix, int action)
4581{
4582 struct alc_spec *spec = codec->spec;
4583 if (action == ALC_FIXUP_ACT_PROBE) {
4584 /* although the machine has only one output pin, we need to
4585 * toggle GPIO1 according to the jack state
4586 */
4587 spec->automute_hook = alc260_gpio1_automute;
4588 spec->detect_hp = 1;
4589 spec->automute_speaker = 1;
4590 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4591 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4592 spec->unsol_event = alc_sku_unsol_event;
4593 add_verb(codec->spec, alc_gpio1_init_verbs);
4594 }
4595}
4596
Takashi Iwai1d045db2011-07-07 18:23:21 +02004597static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004598 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004599 .type = ALC_FIXUP_PINS,
4600 .v.pins = (const struct alc_pincfg[]) {
4601 { 0x11, 0x90130110 }, /* speaker */
4602 { }
4603 }
4604 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004605 [ALC260_FIXUP_HP_PIN_0F] = {
4606 .type = ALC_FIXUP_PINS,
4607 .v.pins = (const struct alc_pincfg[]) {
4608 { 0x0f, 0x01214000 }, /* HP */
4609 { }
4610 }
4611 },
4612 [ALC260_FIXUP_COEF] = {
4613 .type = ALC_FIXUP_VERBS,
4614 .v.verbs = (const struct hda_verb[]) {
4615 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4616 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4617 { }
4618 },
4619 .chained = true,
4620 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4621 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004622 [ALC260_FIXUP_GPIO1] = {
4623 .type = ALC_FIXUP_VERBS,
4624 .v.verbs = alc_gpio1_init_verbs,
4625 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004626 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4627 .type = ALC_FIXUP_FUNC,
4628 .v.func = alc260_fixup_gpio1_toggle,
4629 .chained = true,
4630 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4631 },
4632 [ALC260_FIXUP_REPLACER] = {
4633 .type = ALC_FIXUP_VERBS,
4634 .v.verbs = (const struct hda_verb[]) {
4635 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4636 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4637 { }
4638 },
4639 .chained = true,
4640 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4641 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004642 [ALC260_FIXUP_HP_B1900] = {
4643 .type = ALC_FIXUP_FUNC,
4644 .v.func = alc260_fixup_gpio1_toggle,
4645 .chained = true,
4646 .chain_id = ALC260_FIXUP_COEF,
4647 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004648};
4649
4650static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004651 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004652 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004653 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004654 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004655 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004656 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004657 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004658 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004659 {}
4660};
4661
4662/*
4663 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004664static int patch_alc260(struct hda_codec *codec)
4665{
4666 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004667 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004668
4669 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4670 if (spec == NULL)
4671 return -ENOMEM;
4672
4673 codec->spec = spec;
4674
4675 spec->mixer_nid = 0x07;
4676
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004677 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4678 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004679
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004680 /* automatic parse from the BIOS config */
4681 err = alc260_parse_auto_config(codec);
4682 if (err < 0)
4683 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004684
Takashi Iwai60a6a842011-07-27 14:01:24 +02004685 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004686 alc_auto_fill_adc_caps(codec);
4687 alc_rebuild_imux_for_auto_mic(codec);
4688 alc_remove_invalid_adc_nids(codec);
4689 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004690
4691 if (!spec->no_analog && !spec->cap_mixer)
4692 set_capture_mixer(codec);
4693
4694 if (!spec->no_analog) {
4695 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004696 if (err < 0)
4697 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004698 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4699 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004700
4701 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4702
Takashi Iwai1d045db2011-07-07 18:23:21 +02004703 codec->patch_ops = alc_patch_ops;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004704 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004705 spec->shutup = alc_eapd_shutup;
4706#ifdef CONFIG_SND_HDA_POWER_SAVE
4707 if (!spec->loopback.amplist)
4708 spec->loopback.amplist = alc260_loopbacks;
4709#endif
4710
4711 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004712
4713 error:
4714 alc_free(codec);
4715 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004716}
4717
4718
4719/*
4720 * ALC882/883/885/888/889 support
4721 *
4722 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4723 * configuration. Each pin widget can choose any input DACs and a mixer.
4724 * Each ADC is connected from a mixer of all inputs. This makes possible
4725 * 6-channel independent captures.
4726 *
4727 * In addition, an independent DAC for the multi-playback (not used in this
4728 * driver yet).
4729 */
4730#ifdef CONFIG_SND_HDA_POWER_SAVE
4731#define alc882_loopbacks alc880_loopbacks
4732#endif
4733
4734/*
4735 * Pin config fixes
4736 */
4737enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004738 ALC882_FIXUP_ABIT_AW9D_MAX,
4739 ALC882_FIXUP_LENOVO_Y530,
4740 ALC882_FIXUP_PB_M5210,
4741 ALC882_FIXUP_ACER_ASPIRE_7736,
4742 ALC882_FIXUP_ASUS_W90V,
4743 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004744 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004745 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004746 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004747 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004748 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004749 ALC889_FIXUP_COEF,
4750 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004751 ALC882_FIXUP_ACER_ASPIRE_4930G,
4752 ALC882_FIXUP_ACER_ASPIRE_8930G,
4753 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004754 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01004755 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004756};
4757
Takashi Iwai68ef0562011-11-09 18:24:44 +01004758static void alc889_fixup_coef(struct hda_codec *codec,
4759 const struct alc_fixup *fix, int action)
4760{
4761 if (action != ALC_FIXUP_ACT_INIT)
4762 return;
4763 alc889_coef_init(codec);
4764}
4765
Takashi Iwai56710872011-11-14 17:42:11 +01004766/* toggle speaker-output according to the hp-jack state */
4767static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4768{
4769 unsigned int gpiostate, gpiomask, gpiodir;
4770
4771 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4772 AC_VERB_GET_GPIO_DATA, 0);
4773
4774 if (!muted)
4775 gpiostate |= (1 << pin);
4776 else
4777 gpiostate &= ~(1 << pin);
4778
4779 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4780 AC_VERB_GET_GPIO_MASK, 0);
4781 gpiomask |= (1 << pin);
4782
4783 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4784 AC_VERB_GET_GPIO_DIRECTION, 0);
4785 gpiodir |= (1 << pin);
4786
4787
4788 snd_hda_codec_write(codec, codec->afg, 0,
4789 AC_VERB_SET_GPIO_MASK, gpiomask);
4790 snd_hda_codec_write(codec, codec->afg, 0,
4791 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4792
4793 msleep(1);
4794
4795 snd_hda_codec_write(codec, codec->afg, 0,
4796 AC_VERB_SET_GPIO_DATA, gpiostate);
4797}
4798
4799/* set up GPIO at initialization */
4800static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4801 const struct alc_fixup *fix, int action)
4802{
4803 if (action != ALC_FIXUP_ACT_INIT)
4804 return;
4805 alc882_gpio_mute(codec, 0, 0);
4806 alc882_gpio_mute(codec, 1, 0);
4807}
4808
Takashi Iwai02a237b2012-02-13 15:25:07 +01004809/* Fix the connection of some pins for ALC889:
4810 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4811 * work correctly (bko#42740)
4812 */
4813static void alc889_fixup_dac_route(struct hda_codec *codec,
4814 const struct alc_fixup *fix, int action)
4815{
4816 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
4817 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4818 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4819 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4820 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4821 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4822 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
4823 }
4824}
4825
Takashi Iwai1d045db2011-07-07 18:23:21 +02004826static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004827 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004828 .type = ALC_FIXUP_PINS,
4829 .v.pins = (const struct alc_pincfg[]) {
4830 { 0x15, 0x01080104 }, /* side */
4831 { 0x16, 0x01011012 }, /* rear */
4832 { 0x17, 0x01016011 }, /* clfe */
4833 { }
4834 }
4835 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004836 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004837 .type = ALC_FIXUP_PINS,
4838 .v.pins = (const struct alc_pincfg[]) {
4839 { 0x15, 0x99130112 }, /* rear int speakers */
4840 { 0x16, 0x99130111 }, /* subwoofer */
4841 { }
4842 }
4843 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004844 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004845 .type = ALC_FIXUP_VERBS,
4846 .v.verbs = (const struct hda_verb[]) {
4847 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4848 {}
4849 }
4850 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004851 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004852 .type = ALC_FIXUP_SKU,
4853 .v.sku = ALC_FIXUP_SKU_IGNORE,
4854 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004855 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004856 .type = ALC_FIXUP_PINS,
4857 .v.pins = (const struct alc_pincfg[]) {
4858 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4859 { }
4860 }
4861 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004862 [ALC889_FIXUP_VAIO_TT] = {
4863 .type = ALC_FIXUP_PINS,
4864 .v.pins = (const struct alc_pincfg[]) {
4865 { 0x17, 0x90170111 }, /* hidden surround speaker */
4866 { }
4867 }
4868 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004869 [ALC888_FIXUP_EEE1601] = {
4870 .type = ALC_FIXUP_VERBS,
4871 .v.verbs = (const struct hda_verb[]) {
4872 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4873 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4874 { }
4875 }
Takashi Iwai177943a2011-11-09 12:55:18 +01004876 },
4877 [ALC882_FIXUP_EAPD] = {
4878 .type = ALC_FIXUP_VERBS,
4879 .v.verbs = (const struct hda_verb[]) {
4880 /* change to EAPD mode */
4881 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4882 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4883 { }
4884 }
4885 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004886 [ALC883_FIXUP_EAPD] = {
4887 .type = ALC_FIXUP_VERBS,
4888 .v.verbs = (const struct hda_verb[]) {
4889 /* change to EAPD mode */
4890 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4891 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4892 { }
4893 }
4894 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004895 [ALC883_FIXUP_ACER_EAPD] = {
4896 .type = ALC_FIXUP_VERBS,
4897 .v.verbs = (const struct hda_verb[]) {
4898 /* eanable EAPD on Acer laptops */
4899 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4900 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4901 { }
4902 }
4903 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004904 [ALC882_FIXUP_GPIO3] = {
4905 .type = ALC_FIXUP_VERBS,
4906 .v.verbs = alc_gpio3_init_verbs,
4907 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004908 [ALC882_FIXUP_ASUS_W2JC] = {
4909 .type = ALC_FIXUP_VERBS,
4910 .v.verbs = alc_gpio1_init_verbs,
4911 .chained = true,
4912 .chain_id = ALC882_FIXUP_EAPD,
4913 },
4914 [ALC889_FIXUP_COEF] = {
4915 .type = ALC_FIXUP_FUNC,
4916 .v.func = alc889_fixup_coef,
4917 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004918 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4919 .type = ALC_FIXUP_PINS,
4920 .v.pins = (const struct alc_pincfg[]) {
4921 { 0x16, 0x99130111 }, /* CLFE speaker */
4922 { 0x17, 0x99130112 }, /* surround speaker */
4923 { }
4924 }
4925 },
4926 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4927 .type = ALC_FIXUP_PINS,
4928 .v.pins = (const struct alc_pincfg[]) {
4929 { 0x16, 0x99130111 }, /* CLFE speaker */
4930 { 0x1b, 0x99130112 }, /* surround speaker */
4931 { }
4932 },
4933 .chained = true,
4934 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4935 },
4936 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4937 /* additional init verbs for Acer Aspire 8930G */
4938 .type = ALC_FIXUP_VERBS,
4939 .v.verbs = (const struct hda_verb[]) {
4940 /* Enable all DACs */
4941 /* DAC DISABLE/MUTE 1? */
4942 /* setting bits 1-5 disables DAC nids 0x02-0x06
4943 * apparently. Init=0x38 */
4944 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4945 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4946 /* DAC DISABLE/MUTE 2? */
4947 /* some bit here disables the other DACs.
4948 * Init=0x4900 */
4949 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4950 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4951 /* DMIC fix
4952 * This laptop has a stereo digital microphone.
4953 * The mics are only 1cm apart which makes the stereo
4954 * useless. However, either the mic or the ALC889
4955 * makes the signal become a difference/sum signal
4956 * instead of standard stereo, which is annoying.
4957 * So instead we flip this bit which makes the
4958 * codec replicate the sum signal to both channels,
4959 * turning it into a normal mono mic.
4960 */
4961 /* DMIC_CONTROL? Init value = 0x0001 */
4962 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4963 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4964 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4965 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4966 { }
4967 }
4968 },
Takashi Iwai56710872011-11-14 17:42:11 +01004969 [ALC885_FIXUP_MACPRO_GPIO] = {
4970 .type = ALC_FIXUP_FUNC,
4971 .v.func = alc885_fixup_macpro_gpio,
4972 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01004973 [ALC889_FIXUP_DAC_ROUTE] = {
4974 .type = ALC_FIXUP_FUNC,
4975 .v.func = alc889_fixup_dac_route,
4976 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004977};
4978
4979static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004980 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4981 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4982 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4983 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4984 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4985 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004986 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4987 ALC882_FIXUP_ACER_ASPIRE_4930G),
4988 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4989 ALC882_FIXUP_ACER_ASPIRE_4930G),
4990 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4991 ALC882_FIXUP_ACER_ASPIRE_8930G),
4992 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4993 ALC882_FIXUP_ACER_ASPIRE_8930G),
4994 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4995 ALC882_FIXUP_ACER_ASPIRE_4930G),
4996 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4997 ALC882_FIXUP_ACER_ASPIRE_4930G),
4998 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4999 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005000 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005001 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005002 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005003 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005004 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005005 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005006 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005007 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005008
5009 /* All Apple entries are in codec SSIDs */
5010 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5011 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5012 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
5013 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5014 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
5015
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005016 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005017 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005018 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005019 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5020 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005021 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005022 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005023 {}
5024};
5025
5026/*
5027 * BIOS auto configuration
5028 */
5029/* almost identical with ALC880 parser... */
5030static int alc882_parse_auto_config(struct hda_codec *codec)
5031{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005032 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005033 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5034 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005035}
5036
Takashi Iwai1d045db2011-07-07 18:23:21 +02005037/*
5038 */
5039#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5040#include "alc882_quirks.c"
5041#endif
5042
5043static int patch_alc882(struct hda_codec *codec)
5044{
5045 struct alc_spec *spec;
5046 int err, board_config;
5047
5048 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5049 if (spec == NULL)
5050 return -ENOMEM;
5051
5052 codec->spec = spec;
5053
5054 spec->mixer_nid = 0x0b;
5055
5056 switch (codec->vendor_id) {
5057 case 0x10ec0882:
5058 case 0x10ec0885:
5059 break;
5060 default:
5061 /* ALC883 and variants */
5062 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5063 break;
5064 }
5065
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005066 err = alc_codec_rename_from_preset(codec);
5067 if (err < 0)
5068 goto error;
5069
Takashi Iwaib2539692011-11-14 17:32:17 +01005070 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
5071 alc882_models, NULL);
5072 if (board_config < 0)
5073 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005074 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
5075
5076 if (board_config < 0) {
5077 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5078 codec->chip_name);
5079 board_config = ALC_MODEL_AUTO;
5080 }
5081
5082 if (board_config == ALC_MODEL_AUTO) {
5083 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
5084 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5085 }
5086
5087 alc_auto_parse_customize_define(codec);
5088
5089 if (board_config == ALC_MODEL_AUTO) {
5090 /* automatic parse from the BIOS config */
5091 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005092 if (err < 0)
5093 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005094 }
5095
David Henningssonfde48a12011-12-09 18:27:42 +08005096 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005097 setup_preset(codec, &alc882_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08005098 spec->vmaster_nid = 0x0c;
5099 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005100
Takashi Iwai60a6a842011-07-27 14:01:24 +02005101 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005102 alc_auto_fill_adc_caps(codec);
5103 alc_rebuild_imux_for_auto_mic(codec);
5104 alc_remove_invalid_adc_nids(codec);
5105 }
5106
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005107 if (!spec->no_analog && !spec->cap_mixer)
5108 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005109
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005110 if (!spec->no_analog && has_cdefine_beep(codec)) {
5111 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005112 if (err < 0)
5113 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005114 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005115 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005116
5117 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5118
Takashi Iwai1d045db2011-07-07 18:23:21 +02005119 codec->patch_ops = alc_patch_ops;
5120 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02005121 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01005122 else
5123 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005124
Takashi Iwai1d045db2011-07-07 18:23:21 +02005125#ifdef CONFIG_SND_HDA_POWER_SAVE
5126 if (!spec->loopback.amplist)
5127 spec->loopback.amplist = alc882_loopbacks;
5128#endif
5129
5130 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005131
5132 error:
5133 alc_free(codec);
5134 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005135}
5136
5137
5138/*
5139 * ALC262 support
5140 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005141static int alc262_parse_auto_config(struct hda_codec *codec)
5142{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005143 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005144 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5145 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005146}
5147
5148/*
5149 * Pin config fixes
5150 */
5151enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005152 ALC262_FIXUP_FSC_H270,
5153 ALC262_FIXUP_HP_Z200,
5154 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005155 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005156 ALC262_FIXUP_BENQ,
5157 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005158};
5159
5160static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005161 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005162 .type = ALC_FIXUP_PINS,
5163 .v.pins = (const struct alc_pincfg[]) {
5164 { 0x14, 0x99130110 }, /* speaker */
5165 { 0x15, 0x0221142f }, /* front HP */
5166 { 0x1b, 0x0121141f }, /* rear HP */
5167 { }
5168 }
5169 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005170 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005171 .type = ALC_FIXUP_PINS,
5172 .v.pins = (const struct alc_pincfg[]) {
5173 { 0x16, 0x99130120 }, /* internal speaker */
5174 { }
5175 }
5176 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005177 [ALC262_FIXUP_TYAN] = {
5178 .type = ALC_FIXUP_PINS,
5179 .v.pins = (const struct alc_pincfg[]) {
5180 { 0x14, 0x1993e1f0 }, /* int AUX */
5181 { }
5182 }
5183 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005184 [ALC262_FIXUP_LENOVO_3000] = {
5185 .type = ALC_FIXUP_VERBS,
5186 .v.verbs = (const struct hda_verb[]) {
5187 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005188 {}
5189 },
5190 .chained = true,
5191 .chain_id = ALC262_FIXUP_BENQ,
5192 },
5193 [ALC262_FIXUP_BENQ] = {
5194 .type = ALC_FIXUP_VERBS,
5195 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005196 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5197 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5198 {}
5199 }
5200 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005201 [ALC262_FIXUP_BENQ_T31] = {
5202 .type = ALC_FIXUP_VERBS,
5203 .v.verbs = (const struct hda_verb[]) {
5204 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5205 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5206 {}
5207 }
5208 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005209};
5210
5211static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005212 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005213 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5214 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005215 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5216 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005217 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005218 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5219 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005220 {}
5221};
5222
5223
5224#ifdef CONFIG_SND_HDA_POWER_SAVE
5225#define alc262_loopbacks alc880_loopbacks
5226#endif
5227
Takashi Iwai1d045db2011-07-07 18:23:21 +02005228/*
5229 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005230static int patch_alc262(struct hda_codec *codec)
5231{
5232 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005233 int err;
5234
5235 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5236 if (spec == NULL)
5237 return -ENOMEM;
5238
5239 codec->spec = spec;
5240
5241 spec->mixer_nid = 0x0b;
5242
5243#if 0
5244 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5245 * under-run
5246 */
5247 {
5248 int tmp;
5249 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5250 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5251 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5252 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5253 }
5254#endif
5255 alc_auto_parse_customize_define(codec);
5256
5257 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5258
Takashi Iwai42399f72011-11-07 17:18:44 +01005259 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5260 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005261
Takashi Iwai42399f72011-11-07 17:18:44 +01005262 /* automatic parse from the BIOS config */
5263 err = alc262_parse_auto_config(codec);
5264 if (err < 0)
5265 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005266
Takashi Iwai60a6a842011-07-27 14:01:24 +02005267 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005268 alc_auto_fill_adc_caps(codec);
5269 alc_rebuild_imux_for_auto_mic(codec);
5270 alc_remove_invalid_adc_nids(codec);
5271 }
5272
5273 if (!spec->no_analog && !spec->cap_mixer)
5274 set_capture_mixer(codec);
5275
Takashi Iwai1d045db2011-07-07 18:23:21 +02005276 if (!spec->no_analog && has_cdefine_beep(codec)) {
5277 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005278 if (err < 0)
5279 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005280 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005281 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005282
5283 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5284
Takashi Iwai1d045db2011-07-07 18:23:21 +02005285 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01005286 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005287 spec->shutup = alc_eapd_shutup;
5288
Takashi Iwai1d045db2011-07-07 18:23:21 +02005289#ifdef CONFIG_SND_HDA_POWER_SAVE
5290 if (!spec->loopback.amplist)
5291 spec->loopback.amplist = alc262_loopbacks;
5292#endif
5293
5294 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005295
5296 error:
5297 alc_free(codec);
5298 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005299}
5300
5301/*
5302 * ALC268
5303 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005304/* bind Beep switches of both NID 0x0f and 0x10 */
5305static const struct hda_bind_ctls alc268_bind_beep_sw = {
5306 .ops = &snd_hda_bind_sw,
5307 .values = {
5308 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5309 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5310 0
5311 },
5312};
5313
5314static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5315 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5316 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5317 { }
5318};
5319
5320/* set PCBEEP vol = 0, mute connections */
5321static const struct hda_verb alc268_beep_init_verbs[] = {
5322 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5323 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5324 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5325 { }
5326};
5327
5328/*
5329 * BIOS auto configuration
5330 */
5331static int alc268_parse_auto_config(struct hda_codec *codec)
5332{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005333 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005334 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005335 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5336 if (err > 0) {
5337 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5338 add_mixer(spec, alc268_beep_mixer);
5339 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005340 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005341 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005342 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005343}
5344
Takashi Iwai1d045db2011-07-07 18:23:21 +02005345/*
5346 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005347static int patch_alc268(struct hda_codec *codec)
5348{
5349 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005350 int i, has_beep, err;
5351
5352 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5353 if (spec == NULL)
5354 return -ENOMEM;
5355
5356 codec->spec = spec;
5357
5358 /* ALC268 has no aa-loopback mixer */
5359
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005360 /* automatic parse from the BIOS config */
5361 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005362 if (err < 0)
5363 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005364
Takashi Iwai1d045db2011-07-07 18:23:21 +02005365 has_beep = 0;
5366 for (i = 0; i < spec->num_mixers; i++) {
5367 if (spec->mixers[i] == alc268_beep_mixer) {
5368 has_beep = 1;
5369 break;
5370 }
5371 }
5372
5373 if (has_beep) {
5374 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005375 if (err < 0)
5376 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005377 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5378 /* override the amp caps for beep generator */
5379 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5380 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5381 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5382 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5383 (0 << AC_AMPCAP_MUTE_SHIFT));
5384 }
5385
Takashi Iwai60a6a842011-07-27 14:01:24 +02005386 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005387 alc_auto_fill_adc_caps(codec);
5388 alc_rebuild_imux_for_auto_mic(codec);
5389 alc_remove_invalid_adc_nids(codec);
5390 }
5391
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005392 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005393 set_capture_mixer(codec);
5394
Takashi Iwai1d045db2011-07-07 18:23:21 +02005395 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005396 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005397 spec->shutup = alc_eapd_shutup;
5398
Takashi Iwai1d045db2011-07-07 18:23:21 +02005399 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005400
5401 error:
5402 alc_free(codec);
5403 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005404}
5405
5406/*
5407 * ALC269
5408 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005409#ifdef CONFIG_SND_HDA_POWER_SAVE
5410#define alc269_loopbacks alc880_loopbacks
5411#endif
5412
5413static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5414 .substreams = 1,
5415 .channels_min = 2,
5416 .channels_max = 8,
5417 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5418 /* NID is set in alc_build_pcms */
5419 .ops = {
5420 .open = alc_playback_pcm_open,
5421 .prepare = alc_playback_pcm_prepare,
5422 .cleanup = alc_playback_pcm_cleanup
5423 },
5424};
5425
5426static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5427 .substreams = 1,
5428 .channels_min = 2,
5429 .channels_max = 2,
5430 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5431 /* NID is set in alc_build_pcms */
5432};
5433
5434#ifdef CONFIG_SND_HDA_POWER_SAVE
5435static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5436{
5437 switch (codec->subsystem_id) {
5438 case 0x103c1586:
5439 return 1;
5440 }
5441 return 0;
5442}
5443
5444static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5445{
5446 /* update mute-LED according to the speaker mute state */
5447 if (nid == 0x01 || nid == 0x14) {
5448 int pinval;
5449 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5450 HDA_AMP_MUTE)
5451 pinval = 0x24;
5452 else
5453 pinval = 0x20;
5454 /* mic2 vref pin is used for mute LED control */
5455 snd_hda_codec_update_cache(codec, 0x19, 0,
5456 AC_VERB_SET_PIN_WIDGET_CONTROL,
5457 pinval);
5458 }
5459 return alc_check_power_status(codec, nid);
5460}
5461#endif /* CONFIG_SND_HDA_POWER_SAVE */
5462
5463/* different alc269-variants */
5464enum {
5465 ALC269_TYPE_ALC269VA,
5466 ALC269_TYPE_ALC269VB,
5467 ALC269_TYPE_ALC269VC,
5468};
5469
5470/*
5471 * BIOS auto configuration
5472 */
5473static int alc269_parse_auto_config(struct hda_codec *codec)
5474{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005475 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005476 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5477 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5478 struct alc_spec *spec = codec->spec;
5479 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5480 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005482 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005483}
5484
Takashi Iwai1d045db2011-07-07 18:23:21 +02005485static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5486{
5487 int val = alc_read_coef_idx(codec, 0x04);
5488 if (power_up)
5489 val |= 1 << 11;
5490 else
5491 val &= ~(1 << 11);
5492 alc_write_coef_idx(codec, 0x04, val);
5493}
5494
5495static void alc269_shutup(struct hda_codec *codec)
5496{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005497 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005498 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005499 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005500 alc269_toggle_power_output(codec, 0);
5501 msleep(150);
5502 }
5503}
5504
Takashi Iwai2a439522011-07-26 09:52:50 +02005505#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005506static int alc269_resume(struct hda_codec *codec)
5507{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005508 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005509 alc269_toggle_power_output(codec, 0);
5510 msleep(150);
5511 }
5512
5513 codec->patch_ops.init(codec);
5514
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005515 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005516 alc269_toggle_power_output(codec, 1);
5517 msleep(200);
5518 }
5519
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005520 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005521 alc269_toggle_power_output(codec, 1);
5522
5523 snd_hda_codec_resume_amp(codec);
5524 snd_hda_codec_resume_cache(codec);
5525 hda_call_check_power_status(codec, 0x01);
5526 return 0;
5527}
Takashi Iwai2a439522011-07-26 09:52:50 +02005528#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005529
5530static void alc269_fixup_hweq(struct hda_codec *codec,
5531 const struct alc_fixup *fix, int action)
5532{
5533 int coef;
5534
5535 if (action != ALC_FIXUP_ACT_INIT)
5536 return;
5537 coef = alc_read_coef_idx(codec, 0x1e);
5538 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5539}
5540
5541static void alc271_fixup_dmic(struct hda_codec *codec,
5542 const struct alc_fixup *fix, int action)
5543{
5544 static const struct hda_verb verbs[] = {
5545 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5546 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5547 {}
5548 };
5549 unsigned int cfg;
5550
5551 if (strcmp(codec->chip_name, "ALC271X"))
5552 return;
5553 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5554 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5555 snd_hda_sequence_write(codec, verbs);
5556}
5557
Takashi Iwai017f2a12011-07-09 14:42:25 +02005558static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5559 const struct alc_fixup *fix, int action)
5560{
5561 struct alc_spec *spec = codec->spec;
5562
5563 if (action != ALC_FIXUP_ACT_PROBE)
5564 return;
5565
5566 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5567 * fix the sample rate of analog I/O to 44.1kHz
5568 */
5569 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5570 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5571}
5572
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005573static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5574 const struct alc_fixup *fix, int action)
5575{
5576 int coef;
5577
5578 if (action != ALC_FIXUP_ACT_INIT)
5579 return;
5580 /* The digital-mic unit sends PDM (differential signal) instead of
5581 * the standard PCM, thus you can't record a valid mono stream as is.
5582 * Below is a workaround specific to ALC269 to control the dmic
5583 * signal source as mono.
5584 */
5585 coef = alc_read_coef_idx(codec, 0x07);
5586 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5587}
5588
Takashi Iwai24519912011-08-16 15:08:49 +02005589static void alc269_quanta_automute(struct hda_codec *codec)
5590{
David Henningsson42cf0d02011-09-20 12:04:56 +02005591 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005592
5593 snd_hda_codec_write(codec, 0x20, 0,
5594 AC_VERB_SET_COEF_INDEX, 0x0c);
5595 snd_hda_codec_write(codec, 0x20, 0,
5596 AC_VERB_SET_PROC_COEF, 0x680);
5597
5598 snd_hda_codec_write(codec, 0x20, 0,
5599 AC_VERB_SET_COEF_INDEX, 0x0c);
5600 snd_hda_codec_write(codec, 0x20, 0,
5601 AC_VERB_SET_PROC_COEF, 0x480);
5602}
5603
5604static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5605 const struct alc_fixup *fix, int action)
5606{
5607 struct alc_spec *spec = codec->spec;
5608 if (action != ALC_FIXUP_ACT_PROBE)
5609 return;
5610 spec->automute_hook = alc269_quanta_automute;
5611}
5612
Takashi Iwai1d045db2011-07-07 18:23:21 +02005613enum {
5614 ALC269_FIXUP_SONY_VAIO,
5615 ALC275_FIXUP_SONY_VAIO_GPIO2,
5616 ALC269_FIXUP_DELL_M101Z,
5617 ALC269_FIXUP_SKU_IGNORE,
5618 ALC269_FIXUP_ASUS_G73JW,
5619 ALC269_FIXUP_LENOVO_EAPD,
5620 ALC275_FIXUP_SONY_HWEQ,
5621 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005622 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005623 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005624 ALC269_FIXUP_QUANTA_MUTE,
5625 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005626 ALC269_FIXUP_AMIC,
5627 ALC269_FIXUP_DMIC,
5628 ALC269VB_FIXUP_AMIC,
5629 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005630};
5631
5632static const struct alc_fixup alc269_fixups[] = {
5633 [ALC269_FIXUP_SONY_VAIO] = {
5634 .type = ALC_FIXUP_VERBS,
5635 .v.verbs = (const struct hda_verb[]) {
5636 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5637 {}
5638 }
5639 },
5640 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5641 .type = ALC_FIXUP_VERBS,
5642 .v.verbs = (const struct hda_verb[]) {
5643 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5644 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5645 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5646 { }
5647 },
5648 .chained = true,
5649 .chain_id = ALC269_FIXUP_SONY_VAIO
5650 },
5651 [ALC269_FIXUP_DELL_M101Z] = {
5652 .type = ALC_FIXUP_VERBS,
5653 .v.verbs = (const struct hda_verb[]) {
5654 /* Enables internal speaker */
5655 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5656 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5657 {}
5658 }
5659 },
5660 [ALC269_FIXUP_SKU_IGNORE] = {
5661 .type = ALC_FIXUP_SKU,
5662 .v.sku = ALC_FIXUP_SKU_IGNORE,
5663 },
5664 [ALC269_FIXUP_ASUS_G73JW] = {
5665 .type = ALC_FIXUP_PINS,
5666 .v.pins = (const struct alc_pincfg[]) {
5667 { 0x17, 0x99130111 }, /* subwoofer */
5668 { }
5669 }
5670 },
5671 [ALC269_FIXUP_LENOVO_EAPD] = {
5672 .type = ALC_FIXUP_VERBS,
5673 .v.verbs = (const struct hda_verb[]) {
5674 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5675 {}
5676 }
5677 },
5678 [ALC275_FIXUP_SONY_HWEQ] = {
5679 .type = ALC_FIXUP_FUNC,
5680 .v.func = alc269_fixup_hweq,
5681 .chained = true,
5682 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5683 },
5684 [ALC271_FIXUP_DMIC] = {
5685 .type = ALC_FIXUP_FUNC,
5686 .v.func = alc271_fixup_dmic,
5687 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005688 [ALC269_FIXUP_PCM_44K] = {
5689 .type = ALC_FIXUP_FUNC,
5690 .v.func = alc269_fixup_pcm_44k,
5691 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005692 [ALC269_FIXUP_STEREO_DMIC] = {
5693 .type = ALC_FIXUP_FUNC,
5694 .v.func = alc269_fixup_stereo_dmic,
5695 },
Takashi Iwai24519912011-08-16 15:08:49 +02005696 [ALC269_FIXUP_QUANTA_MUTE] = {
5697 .type = ALC_FIXUP_FUNC,
5698 .v.func = alc269_fixup_quanta_mute,
5699 },
5700 [ALC269_FIXUP_LIFEBOOK] = {
5701 .type = ALC_FIXUP_PINS,
5702 .v.pins = (const struct alc_pincfg[]) {
5703 { 0x1a, 0x2101103f }, /* dock line-out */
5704 { 0x1b, 0x23a11040 }, /* dock mic-in */
5705 { }
5706 },
5707 .chained = true,
5708 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5709 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005710 [ALC269_FIXUP_AMIC] = {
5711 .type = ALC_FIXUP_PINS,
5712 .v.pins = (const struct alc_pincfg[]) {
5713 { 0x14, 0x99130110 }, /* speaker */
5714 { 0x15, 0x0121401f }, /* HP out */
5715 { 0x18, 0x01a19c20 }, /* mic */
5716 { 0x19, 0x99a3092f }, /* int-mic */
5717 { }
5718 },
5719 },
5720 [ALC269_FIXUP_DMIC] = {
5721 .type = ALC_FIXUP_PINS,
5722 .v.pins = (const struct alc_pincfg[]) {
5723 { 0x12, 0x99a3092f }, /* int-mic */
5724 { 0x14, 0x99130110 }, /* speaker */
5725 { 0x15, 0x0121401f }, /* HP out */
5726 { 0x18, 0x01a19c20 }, /* mic */
5727 { }
5728 },
5729 },
5730 [ALC269VB_FIXUP_AMIC] = {
5731 .type = ALC_FIXUP_PINS,
5732 .v.pins = (const struct alc_pincfg[]) {
5733 { 0x14, 0x99130110 }, /* speaker */
5734 { 0x18, 0x01a19c20 }, /* mic */
5735 { 0x19, 0x99a3092f }, /* int-mic */
5736 { 0x21, 0x0121401f }, /* HP out */
5737 { }
5738 },
5739 },
David Henningsson2267ea92012-01-03 08:45:56 +01005740 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02005741 .type = ALC_FIXUP_PINS,
5742 .v.pins = (const struct alc_pincfg[]) {
5743 { 0x12, 0x99a3092f }, /* int-mic */
5744 { 0x14, 0x99130110 }, /* speaker */
5745 { 0x18, 0x01a19c20 }, /* mic */
5746 { 0x21, 0x0121401f }, /* HP out */
5747 { }
5748 },
5749 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750};
5751
5752static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005753 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005754 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5755 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5756 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5757 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5758 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005759 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5760 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5761 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5762 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5763 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5764 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005765 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005766 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5767 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5768 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5769 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5770 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005771 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005772 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005773 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005774
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01005775#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02005776 /* Below is a quirk table taken from the old code.
5777 * Basically the device should work as is without the fixup table.
5778 * If BIOS doesn't give a proper info, enable the corresponding
5779 * fixup entry.
5780 */
5781 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5782 ALC269_FIXUP_AMIC),
5783 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005784 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5785 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5786 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5787 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5788 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5789 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5790 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5791 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5792 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5793 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5794 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5795 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5796 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5797 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5798 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5799 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5800 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5801 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5802 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5803 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5804 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5805 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5806 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5807 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5808 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5809 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5810 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5811 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5812 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5813 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5814 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5815 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5816 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5817 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5818 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5819 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5820 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5821 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5822#endif
5823 {}
5824};
5825
5826static const struct alc_model_fixup alc269_fixup_models[] = {
5827 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5828 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005829 {}
5830};
5831
5832
5833static int alc269_fill_coef(struct hda_codec *codec)
5834{
5835 int val;
5836
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005837 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005838 alc_write_coef_idx(codec, 0xf, 0x960b);
5839 alc_write_coef_idx(codec, 0xe, 0x8817);
5840 }
5841
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005842 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005843 alc_write_coef_idx(codec, 0xf, 0x960b);
5844 alc_write_coef_idx(codec, 0xe, 0x8814);
5845 }
5846
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005847 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005848 val = alc_read_coef_idx(codec, 0x04);
5849 /* Power up output pin */
5850 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5851 }
5852
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005853 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005854 val = alc_read_coef_idx(codec, 0xd);
5855 if ((val & 0x0c00) >> 10 != 0x1) {
5856 /* Capless ramp up clock control */
5857 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5858 }
5859 val = alc_read_coef_idx(codec, 0x17);
5860 if ((val & 0x01c0) >> 6 != 0x4) {
5861 /* Class D power on reset */
5862 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5863 }
5864 }
5865
5866 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5867 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5868
5869 val = alc_read_coef_idx(codec, 0x4); /* HP */
5870 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5871
5872 return 0;
5873}
5874
5875/*
5876 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005877static int patch_alc269(struct hda_codec *codec)
5878{
5879 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005880 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005881
5882 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5883 if (spec == NULL)
5884 return -ENOMEM;
5885
5886 codec->spec = spec;
5887
5888 spec->mixer_nid = 0x0b;
5889
5890 alc_auto_parse_customize_define(codec);
5891
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005892 err = alc_codec_rename_from_preset(codec);
5893 if (err < 0)
5894 goto error;
5895
Takashi Iwai1d045db2011-07-07 18:23:21 +02005896 if (codec->vendor_id == 0x10ec0269) {
5897 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005898 switch (alc_get_coef0(codec) & 0x00f0) {
5899 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005900 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005901 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005902 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005903 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005904 break;
5905 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005906 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5907 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005908 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005909 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005910 break;
5911 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005912 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005913 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005914 if (err < 0)
5915 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005916 alc269_fill_coef(codec);
5917 }
5918
Takashi Iwaia4297b52011-08-23 18:40:12 +02005919 alc_pick_fixup(codec, alc269_fixup_models,
5920 alc269_fixup_tbl, alc269_fixups);
5921 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005922
Takashi Iwaia4297b52011-08-23 18:40:12 +02005923 /* automatic parse from the BIOS config */
5924 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005925 if (err < 0)
5926 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005927
Takashi Iwai60a6a842011-07-27 14:01:24 +02005928 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005929 alc_auto_fill_adc_caps(codec);
5930 alc_rebuild_imux_for_auto_mic(codec);
5931 alc_remove_invalid_adc_nids(codec);
5932 }
5933
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005934 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005935 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005936
5937 if (!spec->no_analog && has_cdefine_beep(codec)) {
5938 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005939 if (err < 0)
5940 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005941 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005942 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005943
5944 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5945
Takashi Iwai1d045db2011-07-07 18:23:21 +02005946 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005947#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005948 codec->patch_ops.resume = alc269_resume;
5949#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005950 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005951 spec->shutup = alc269_shutup;
5952
Takashi Iwai1d045db2011-07-07 18:23:21 +02005953#ifdef CONFIG_SND_HDA_POWER_SAVE
5954 if (!spec->loopback.amplist)
5955 spec->loopback.amplist = alc269_loopbacks;
5956 if (alc269_mic2_for_mute_led(codec))
5957 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5958#endif
5959
5960 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005961
5962 error:
5963 alc_free(codec);
5964 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005965}
5966
5967/*
5968 * ALC861
5969 */
5970
Takashi Iwai1d045db2011-07-07 18:23:21 +02005971static int alc861_parse_auto_config(struct hda_codec *codec)
5972{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005973 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005974 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5975 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005976}
5977
Takashi Iwai1d045db2011-07-07 18:23:21 +02005978#ifdef CONFIG_SND_HDA_POWER_SAVE
5979static const struct hda_amp_list alc861_loopbacks[] = {
5980 { 0x15, HDA_INPUT, 0 },
5981 { 0x15, HDA_INPUT, 1 },
5982 { 0x15, HDA_INPUT, 2 },
5983 { 0x15, HDA_INPUT, 3 },
5984 { } /* end */
5985};
5986#endif
5987
5988
5989/* Pin config fixes */
5990enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01005991 ALC861_FIXUP_FSC_AMILO_PI1505,
5992 ALC861_FIXUP_AMP_VREF_0F,
5993 ALC861_FIXUP_NO_JACK_DETECT,
5994 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005995};
5996
Takashi Iwai31150f22012-01-30 10:54:08 +01005997/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5998static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5999 const struct alc_fixup *fix, int action)
6000{
6001 struct alc_spec *spec = codec->spec;
6002 unsigned int val;
6003
6004 if (action != ALC_FIXUP_ACT_INIT)
6005 return;
6006 val = snd_hda_codec_read(codec, 0x0f, 0,
6007 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6008 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6009 val |= AC_PINCTL_IN_EN;
6010 val |= AC_PINCTL_VREF_50;
6011 snd_hda_codec_write(codec, 0x0f, 0,
6012 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6013 spec->keep_vref_in_automute = 1;
6014}
6015
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006016/* suppress the jack-detection */
6017static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6018 const struct alc_fixup *fix, int action)
6019{
6020 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6021 codec->no_jack_detect = 1;
6022}
6023
Takashi Iwai1d045db2011-07-07 18:23:21 +02006024static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006025 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006026 .type = ALC_FIXUP_PINS,
6027 .v.pins = (const struct alc_pincfg[]) {
6028 { 0x0b, 0x0221101f }, /* HP */
6029 { 0x0f, 0x90170310 }, /* speaker */
6030 { }
6031 }
6032 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006033 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006034 .type = ALC_FIXUP_FUNC,
6035 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006036 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006037 [ALC861_FIXUP_NO_JACK_DETECT] = {
6038 .type = ALC_FIXUP_FUNC,
6039 .v.func = alc_fixup_no_jack_detect,
6040 },
6041 [ALC861_FIXUP_ASUS_A6RP] = {
6042 .type = ALC_FIXUP_FUNC,
6043 .v.func = alc861_fixup_asus_amp_vref_0f,
6044 .chained = true,
6045 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6046 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006047};
6048
6049static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006050 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6051 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6052 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6053 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6054 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6055 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006056 {}
6057};
6058
6059/*
6060 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006061static int patch_alc861(struct hda_codec *codec)
6062{
6063 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006064 int err;
6065
6066 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6067 if (spec == NULL)
6068 return -ENOMEM;
6069
6070 codec->spec = spec;
6071
6072 spec->mixer_nid = 0x15;
6073
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006074 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6075 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006076
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006077 /* automatic parse from the BIOS config */
6078 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006079 if (err < 0)
6080 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006081
Takashi Iwai60a6a842011-07-27 14:01:24 +02006082 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006083 alc_auto_fill_adc_caps(codec);
6084 alc_rebuild_imux_for_auto_mic(codec);
6085 alc_remove_invalid_adc_nids(codec);
6086 }
6087
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006088 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006089 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006090
6091 if (!spec->no_analog) {
6092 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006093 if (err < 0)
6094 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006095 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6096 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006097
Takashi Iwai1d045db2011-07-07 18:23:21 +02006098 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6099
6100 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006101 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006102#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006103 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006104 if (!spec->loopback.amplist)
6105 spec->loopback.amplist = alc861_loopbacks;
6106#endif
6107
6108 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006109
6110 error:
6111 alc_free(codec);
6112 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006113}
6114
6115/*
6116 * ALC861-VD support
6117 *
6118 * Based on ALC882
6119 *
6120 * In addition, an independent DAC
6121 */
6122#ifdef CONFIG_SND_HDA_POWER_SAVE
6123#define alc861vd_loopbacks alc880_loopbacks
6124#endif
6125
Takashi Iwai1d045db2011-07-07 18:23:21 +02006126static int alc861vd_parse_auto_config(struct hda_codec *codec)
6127{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006128 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006129 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6130 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006131}
6132
Takashi Iwai1d045db2011-07-07 18:23:21 +02006133enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006134 ALC660VD_FIX_ASUS_GPIO1,
6135 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006136};
6137
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006138/* exclude VREF80 */
6139static void alc861vd_fixup_dallas(struct hda_codec *codec,
6140 const struct alc_fixup *fix, int action)
6141{
6142 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6143 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6144 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6145 }
6146}
6147
Takashi Iwai1d045db2011-07-07 18:23:21 +02006148static const struct alc_fixup alc861vd_fixups[] = {
6149 [ALC660VD_FIX_ASUS_GPIO1] = {
6150 .type = ALC_FIXUP_VERBS,
6151 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006152 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006153 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6154 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6155 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6156 { }
6157 }
6158 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006159 [ALC861VD_FIX_DALLAS] = {
6160 .type = ALC_FIXUP_FUNC,
6161 .v.func = alc861vd_fixup_dallas,
6162 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006163};
6164
6165static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006166 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006167 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006168 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006169 {}
6170};
6171
6172static const struct hda_verb alc660vd_eapd_verbs[] = {
6173 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6174 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6175 { }
6176};
6177
6178/*
6179 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006180static int patch_alc861vd(struct hda_codec *codec)
6181{
6182 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006183 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006184
6185 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6186 if (spec == NULL)
6187 return -ENOMEM;
6188
6189 codec->spec = spec;
6190
6191 spec->mixer_nid = 0x0b;
6192
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006193 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6194 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006195
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006196 /* automatic parse from the BIOS config */
6197 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006198 if (err < 0)
6199 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006200
Takashi Iwai1d045db2011-07-07 18:23:21 +02006201 if (codec->vendor_id == 0x10ec0660) {
6202 /* always turn on EAPD */
6203 add_verb(spec, alc660vd_eapd_verbs);
6204 }
6205
Takashi Iwai60a6a842011-07-27 14:01:24 +02006206 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006207 alc_auto_fill_adc_caps(codec);
6208 alc_rebuild_imux_for_auto_mic(codec);
6209 alc_remove_invalid_adc_nids(codec);
6210 }
6211
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006212 if (!spec->no_analog && !spec->cap_mixer)
6213 set_capture_mixer(codec);
6214
6215 if (!spec->no_analog) {
6216 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006217 if (err < 0)
6218 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006219 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6220 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006221
Takashi Iwai1d045db2011-07-07 18:23:21 +02006222 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6223
6224 codec->patch_ops = alc_patch_ops;
6225
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006226 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006227 spec->shutup = alc_eapd_shutup;
6228#ifdef CONFIG_SND_HDA_POWER_SAVE
6229 if (!spec->loopback.amplist)
6230 spec->loopback.amplist = alc861vd_loopbacks;
6231#endif
6232
6233 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006234
6235 error:
6236 alc_free(codec);
6237 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006238}
6239
6240/*
6241 * ALC662 support
6242 *
6243 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6244 * configuration. Each pin widget can choose any input DACs and a mixer.
6245 * Each ADC is connected from a mixer of all inputs. This makes possible
6246 * 6-channel independent captures.
6247 *
6248 * In addition, an independent DAC for the multi-playback (not used in this
6249 * driver yet).
6250 */
6251#ifdef CONFIG_SND_HDA_POWER_SAVE
6252#define alc662_loopbacks alc880_loopbacks
6253#endif
6254
6255/*
6256 * BIOS auto configuration
6257 */
6258
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006259static int alc662_parse_auto_config(struct hda_codec *codec)
6260{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006261 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006262 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6263 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6264 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006265
Kailang Yang6227cdc2010-02-25 08:36:52 +01006266 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6267 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006268 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006269 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006270 ssids = alc662_ssids;
6271 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006272}
6273
Todd Broch6be79482010-12-07 16:51:05 -08006274static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006275 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006276{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006277 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006278 return;
Todd Broch6be79482010-12-07 16:51:05 -08006279 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6280 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6281 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6282 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6283 (0 << AC_AMPCAP_MUTE_SHIFT)))
6284 printk(KERN_WARNING
6285 "hda_codec: failed to override amp caps for NID 0x2\n");
6286}
6287
David Henningsson6cb3b702010-09-09 08:51:44 +02006288enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006289 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006290 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006291 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006292 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006293 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006294 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006295 ALC662_FIXUP_ASUS_MODE1,
6296 ALC662_FIXUP_ASUS_MODE2,
6297 ALC662_FIXUP_ASUS_MODE3,
6298 ALC662_FIXUP_ASUS_MODE4,
6299 ALC662_FIXUP_ASUS_MODE5,
6300 ALC662_FIXUP_ASUS_MODE6,
6301 ALC662_FIXUP_ASUS_MODE7,
6302 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006303 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006304};
6305
6306static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006307 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006308 .type = ALC_FIXUP_PINS,
6309 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006310 { 0x15, 0x99130112 }, /* subwoofer */
6311 { }
6312 }
6313 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006314 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006315 .type = ALC_FIXUP_PINS,
6316 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006317 { 0x17, 0x99130112 }, /* subwoofer */
6318 { }
6319 }
6320 },
Todd Broch6be79482010-12-07 16:51:05 -08006321 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006322 .type = ALC_FIXUP_FUNC,
6323 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006324 },
6325 [ALC662_FIXUP_CZC_P10T] = {
6326 .type = ALC_FIXUP_VERBS,
6327 .v.verbs = (const struct hda_verb[]) {
6328 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6329 {}
6330 }
6331 },
David Henningsson94024cd2011-04-29 14:10:55 +02006332 [ALC662_FIXUP_SKU_IGNORE] = {
6333 .type = ALC_FIXUP_SKU,
6334 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006335 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006336 [ALC662_FIXUP_HP_RP5800] = {
6337 .type = ALC_FIXUP_PINS,
6338 .v.pins = (const struct alc_pincfg[]) {
6339 { 0x14, 0x0221201f }, /* HP out */
6340 { }
6341 },
6342 .chained = true,
6343 .chain_id = ALC662_FIXUP_SKU_IGNORE
6344 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006345 [ALC662_FIXUP_ASUS_MODE1] = {
6346 .type = ALC_FIXUP_PINS,
6347 .v.pins = (const struct alc_pincfg[]) {
6348 { 0x14, 0x99130110 }, /* speaker */
6349 { 0x18, 0x01a19c20 }, /* mic */
6350 { 0x19, 0x99a3092f }, /* int-mic */
6351 { 0x21, 0x0121401f }, /* HP out */
6352 { }
6353 },
6354 .chained = true,
6355 .chain_id = ALC662_FIXUP_SKU_IGNORE
6356 },
6357 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006358 .type = ALC_FIXUP_PINS,
6359 .v.pins = (const struct alc_pincfg[]) {
6360 { 0x14, 0x99130110 }, /* speaker */
6361 { 0x18, 0x01a19820 }, /* mic */
6362 { 0x19, 0x99a3092f }, /* int-mic */
6363 { 0x1b, 0x0121401f }, /* HP out */
6364 { }
6365 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006366 .chained = true,
6367 .chain_id = ALC662_FIXUP_SKU_IGNORE
6368 },
6369 [ALC662_FIXUP_ASUS_MODE3] = {
6370 .type = ALC_FIXUP_PINS,
6371 .v.pins = (const struct alc_pincfg[]) {
6372 { 0x14, 0x99130110 }, /* speaker */
6373 { 0x15, 0x0121441f }, /* HP */
6374 { 0x18, 0x01a19840 }, /* mic */
6375 { 0x19, 0x99a3094f }, /* int-mic */
6376 { 0x21, 0x01211420 }, /* HP2 */
6377 { }
6378 },
6379 .chained = true,
6380 .chain_id = ALC662_FIXUP_SKU_IGNORE
6381 },
6382 [ALC662_FIXUP_ASUS_MODE4] = {
6383 .type = ALC_FIXUP_PINS,
6384 .v.pins = (const struct alc_pincfg[]) {
6385 { 0x14, 0x99130110 }, /* speaker */
6386 { 0x16, 0x99130111 }, /* speaker */
6387 { 0x18, 0x01a19840 }, /* mic */
6388 { 0x19, 0x99a3094f }, /* int-mic */
6389 { 0x21, 0x0121441f }, /* HP */
6390 { }
6391 },
6392 .chained = true,
6393 .chain_id = ALC662_FIXUP_SKU_IGNORE
6394 },
6395 [ALC662_FIXUP_ASUS_MODE5] = {
6396 .type = ALC_FIXUP_PINS,
6397 .v.pins = (const struct alc_pincfg[]) {
6398 { 0x14, 0x99130110 }, /* speaker */
6399 { 0x15, 0x0121441f }, /* HP */
6400 { 0x16, 0x99130111 }, /* speaker */
6401 { 0x18, 0x01a19840 }, /* mic */
6402 { 0x19, 0x99a3094f }, /* int-mic */
6403 { }
6404 },
6405 .chained = true,
6406 .chain_id = ALC662_FIXUP_SKU_IGNORE
6407 },
6408 [ALC662_FIXUP_ASUS_MODE6] = {
6409 .type = ALC_FIXUP_PINS,
6410 .v.pins = (const struct alc_pincfg[]) {
6411 { 0x14, 0x99130110 }, /* speaker */
6412 { 0x15, 0x01211420 }, /* HP2 */
6413 { 0x18, 0x01a19840 }, /* mic */
6414 { 0x19, 0x99a3094f }, /* int-mic */
6415 { 0x1b, 0x0121441f }, /* HP */
6416 { }
6417 },
6418 .chained = true,
6419 .chain_id = ALC662_FIXUP_SKU_IGNORE
6420 },
6421 [ALC662_FIXUP_ASUS_MODE7] = {
6422 .type = ALC_FIXUP_PINS,
6423 .v.pins = (const struct alc_pincfg[]) {
6424 { 0x14, 0x99130110 }, /* speaker */
6425 { 0x17, 0x99130111 }, /* speaker */
6426 { 0x18, 0x01a19840 }, /* mic */
6427 { 0x19, 0x99a3094f }, /* int-mic */
6428 { 0x1b, 0x01214020 }, /* HP */
6429 { 0x21, 0x0121401f }, /* HP */
6430 { }
6431 },
6432 .chained = true,
6433 .chain_id = ALC662_FIXUP_SKU_IGNORE
6434 },
6435 [ALC662_FIXUP_ASUS_MODE8] = {
6436 .type = ALC_FIXUP_PINS,
6437 .v.pins = (const struct alc_pincfg[]) {
6438 { 0x14, 0x99130110 }, /* speaker */
6439 { 0x12, 0x99a30970 }, /* int-mic */
6440 { 0x15, 0x01214020 }, /* HP */
6441 { 0x17, 0x99130111 }, /* speaker */
6442 { 0x18, 0x01a19840 }, /* mic */
6443 { 0x21, 0x0121401f }, /* HP */
6444 { }
6445 },
6446 .chained = true,
6447 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006448 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006449 [ALC662_FIXUP_NO_JACK_DETECT] = {
6450 .type = ALC_FIXUP_FUNC,
6451 .v.func = alc_fixup_no_jack_detect,
6452 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006453};
6454
Takashi Iwaia9111322011-05-02 11:30:18 +02006455static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006456 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006457 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006458 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006459 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006460 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006461 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006462 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006463 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006464 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006465 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006466 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006467
6468#if 0
6469 /* Below is a quirk table taken from the old code.
6470 * Basically the device should work as is without the fixup table.
6471 * If BIOS doesn't give a proper info, enable the corresponding
6472 * fixup entry.
6473 */
6474 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6475 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6476 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6477 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6478 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6479 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6480 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6481 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6482 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6483 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6484 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6485 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6486 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6487 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6488 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6489 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6490 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6491 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6492 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6493 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6494 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6495 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6496 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6497 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6498 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6499 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6500 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6501 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6502 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6503 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6504 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6505 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6506 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6507 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6508 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6509 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6510 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6511 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6512 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6513 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6514 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6515 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6516 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6517 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6518 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6519 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6520 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6521 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6522 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6523 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6524#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006525 {}
6526};
6527
Todd Broch6be79482010-12-07 16:51:05 -08006528static const struct alc_model_fixup alc662_fixup_models[] = {
6529 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006530 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6531 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6532 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6533 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6534 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6535 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6536 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6537 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006538 {}
6539};
David Henningsson6cb3b702010-09-09 08:51:44 +02006540
6541
Takashi Iwai1d045db2011-07-07 18:23:21 +02006542/*
6543 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006544static int patch_alc662(struct hda_codec *codec)
6545{
6546 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006547 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006548
6549 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6550 if (!spec)
6551 return -ENOMEM;
6552
6553 codec->spec = spec;
6554
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006555 spec->mixer_nid = 0x0b;
6556
Takashi Iwai53c334a2011-08-23 18:27:14 +02006557 /* handle multiple HPs as is */
6558 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6559
Kailang Yangda00c242010-03-19 11:23:45 +01006560 alc_auto_parse_customize_define(codec);
6561
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006562 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6563
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006564 err = alc_codec_rename_from_preset(codec);
6565 if (err < 0)
6566 goto error;
6567
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006568 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006569 codec->bus->pci->subsystem_vendor == 0x1025 &&
6570 spec->cdefine.platform_type == 1) {
6571 if (alc_codec_rename(codec, "ALC272X") < 0)
6572 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006573 }
Kailang Yang274693f2009-12-03 10:07:50 +01006574
Takashi Iwaib9c51062011-08-24 18:08:07 +02006575 alc_pick_fixup(codec, alc662_fixup_models,
6576 alc662_fixup_tbl, alc662_fixups);
6577 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6578 /* automatic parse from the BIOS config */
6579 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006580 if (err < 0)
6581 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006582
Takashi Iwai60a6a842011-07-27 14:01:24 +02006583 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006584 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006585 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006586 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006587 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006588
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006589 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006590 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006591
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006592 if (!spec->no_analog && has_cdefine_beep(codec)) {
6593 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006594 if (err < 0)
6595 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006596 switch (codec->vendor_id) {
6597 case 0x10ec0662:
6598 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6599 break;
6600 case 0x10ec0272:
6601 case 0x10ec0663:
6602 case 0x10ec0665:
6603 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6604 break;
6605 case 0x10ec0273:
6606 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6607 break;
6608 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006609 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006610
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006611 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6612
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006613 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006614 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006615 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006616
Takashi Iwaicb53c622007-08-10 17:21:45 +02006617#ifdef CONFIG_SND_HDA_POWER_SAVE
6618 if (!spec->loopback.amplist)
6619 spec->loopback.amplist = alc662_loopbacks;
6620#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006621
6622 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006623
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006624 error:
6625 alc_free(codec);
6626 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006627}
6628
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006629/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006630 * ALC680 support
6631 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006632
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006633static int alc680_parse_auto_config(struct hda_codec *codec)
6634{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006635 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006636}
6637
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006638/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006639 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006640static int patch_alc680(struct hda_codec *codec)
6641{
6642 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006643 int err;
6644
6645 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6646 if (spec == NULL)
6647 return -ENOMEM;
6648
6649 codec->spec = spec;
6650
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006651 /* ALC680 has no aa-loopback mixer */
6652
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006653 /* automatic parse from the BIOS config */
6654 err = alc680_parse_auto_config(codec);
6655 if (err < 0) {
6656 alc_free(codec);
6657 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006658 }
6659
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006660 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006661 set_capture_mixer(codec);
6662
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006663 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006664 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006665
6666 return 0;
6667}
6668
6669/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006670 * patch entries
6671 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006672static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006673 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006675 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006676 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006677 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006678 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006679 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006680 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006681 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006682 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006683 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006684 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006685 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6686 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6687 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006688 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02006689 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006690 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6691 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006692 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6693 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006694 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006695 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006696 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006697 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006698 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006700 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006701 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006702 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006703 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006704 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006705 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006706 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006707 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02006708 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006709 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006710 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006711 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006712 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713 {} /* terminator */
6714};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006715
6716MODULE_ALIAS("snd-hda-codec-id:10ec*");
6717
6718MODULE_LICENSE("GPL");
6719MODULE_DESCRIPTION("Realtek HD-audio codec");
6720
6721static struct hda_codec_preset_list realtek_list = {
6722 .preset = snd_hda_preset_realtek,
6723 .owner = THIS_MODULE,
6724};
6725
6726static int __init patch_realtek_init(void)
6727{
6728 return snd_hda_add_codec_preset(&realtek_list);
6729}
6730
6731static void __exit patch_realtek_exit(void)
6732{
6733 snd_hda_delete_codec_preset(&realtek_list);
6734}
6735
6736module_init(patch_realtek_init)
6737module_exit(patch_realtek_exit)