blob: 3c6f5b5161f0b530a6d42c83a0a3ff24e5c9de44 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e482006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
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 Iwai4953550a2009-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 Iwai1c7161532011-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 Iwaicf5a2272012-02-20 16:31:07 +0100654/* update the master volume per volume-knob's unsol event */
655static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
656{
657 unsigned int val;
658 struct snd_kcontrol *kctl;
659 struct snd_ctl_elem_value *uctl;
660
661 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
662 if (!kctl)
663 return;
664 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
665 if (!uctl)
666 return;
667 val = snd_hda_codec_read(codec, nid, 0,
668 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
669 val &= HDA_AMP_VOLMASK;
670 uctl->value.integer.value[0] = val;
671 uctl->value.integer.value[1] = val;
672 kctl->put(kctl, uctl);
673 kfree(uctl);
674}
675
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100676/* unsolicited event for HP jack sensing */
677static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
678{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100679 int action;
680
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100681 if (codec->vendor_id == 0x10ec0880)
682 res >>= 28;
683 else
684 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100685 action = snd_hda_jack_get_action(codec, res);
686 if (res == ALC_DCVOL_EVENT) {
687 /* Execute the dc-vol event here as it requires the NID
688 * but we don't pass NID to alc_exec_unsol_event().
689 * Once when we convert all static quirks to the auto-parser,
690 * this can be integerated into there.
691 */
692 struct hda_jack_tbl *jack;
693 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
694 if (jack)
695 alc_update_knob_master(codec, jack->nid);
696 return;
697 }
698 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100699}
700
Takashi Iwai1d045db2011-07-07 18:23:21 +0200701/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200702static void alc_inithook(struct hda_codec *codec)
703{
Takashi Iwaid922b512011-04-28 12:18:53 +0200704 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200705 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200706 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200707}
708
Kailang Yangf9423e72008-05-27 12:32:25 +0200709/* additional initialization for ALC888 variants */
710static void alc888_coef_init(struct hda_codec *codec)
711{
712 unsigned int tmp;
713
714 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
715 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
716 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100717 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200718 /* alc888S-VC */
719 snd_hda_codec_read(codec, 0x20, 0,
720 AC_VERB_SET_PROC_COEF, 0x830);
721 else
722 /* alc888-VB */
723 snd_hda_codec_read(codec, 0x20, 0,
724 AC_VERB_SET_PROC_COEF, 0x3030);
725}
726
Takashi Iwai1d045db2011-07-07 18:23:21 +0200727/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200728static void alc889_coef_init(struct hda_codec *codec)
729{
730 unsigned int tmp;
731
732 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
733 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
734 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
735 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
736}
737
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100738/* turn on/off EAPD control (only if available) */
739static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
740{
741 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
742 return;
743 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
744 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
745 on ? 2 : 0);
746}
747
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200748/* turn on/off EAPD controls of the codec */
749static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
750{
751 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200752 static hda_nid_t pins[] = {
753 0x0f, 0x10, 0x14, 0x15, 0
754 };
755 hda_nid_t *p;
756 for (p = pins; *p; p++)
757 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200758}
759
Takashi Iwai1c7161532011-04-07 10:37:16 +0200760/* generic shutup callback;
761 * just turning off EPAD and a little pause for avoiding pop-noise
762 */
763static void alc_eapd_shutup(struct hda_codec *codec)
764{
765 alc_auto_setup_eapd(codec, false);
766 msleep(200);
767}
768
Takashi Iwai1d045db2011-07-07 18:23:21 +0200769/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200771{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200772 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200773
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200774 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200775 switch (type) {
776 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200777 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
778 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200779 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200780 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
781 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200782 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200783 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
784 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200785 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200786 switch (codec->vendor_id) {
787 case 0x10ec0260:
788 snd_hda_codec_write(codec, 0x1a, 0,
789 AC_VERB_SET_COEF_INDEX, 7);
790 tmp = snd_hda_codec_read(codec, 0x1a, 0,
791 AC_VERB_GET_PROC_COEF, 0);
792 snd_hda_codec_write(codec, 0x1a, 0,
793 AC_VERB_SET_COEF_INDEX, 7);
794 snd_hda_codec_write(codec, 0x1a, 0,
795 AC_VERB_SET_PROC_COEF,
796 tmp | 0x2010);
797 break;
798 case 0x10ec0262:
799 case 0x10ec0880:
800 case 0x10ec0882:
801 case 0x10ec0883:
802 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100803 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100804 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200805 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200806 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200807 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200808 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200809 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100810#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200811 case 0x10ec0267:
812 case 0x10ec0268:
813 snd_hda_codec_write(codec, 0x20, 0,
814 AC_VERB_SET_COEF_INDEX, 7);
815 tmp = snd_hda_codec_read(codec, 0x20, 0,
816 AC_VERB_GET_PROC_COEF, 0);
817 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200818 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200819 snd_hda_codec_write(codec, 0x20, 0,
820 AC_VERB_SET_PROC_COEF,
821 tmp | 0x3000);
822 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100823#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200824 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200825 break;
826 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200827}
Kailang Yangea1fb292008-08-26 12:58:38 +0200828
Takashi Iwai1d045db2011-07-07 18:23:21 +0200829/*
830 * Auto-Mute mode mixer enum support
831 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200832static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
833 struct snd_ctl_elem_info *uinfo)
834{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200835 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
836 struct alc_spec *spec = codec->spec;
837 static const char * const texts2[] = {
838 "Disabled", "Enabled"
839 };
840 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200841 "Disabled", "Speaker Only", "Line-Out+Speaker"
842 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200843 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200844
845 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
846 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200847 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200848 uinfo->value.enumerated.items = 3;
849 texts = texts3;
850 } else {
851 uinfo->value.enumerated.items = 2;
852 texts = texts2;
853 }
854 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
855 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200856 strcpy(uinfo->value.enumerated.name,
857 texts[uinfo->value.enumerated.item]);
858 return 0;
859}
860
861static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
862 struct snd_ctl_elem_value *ucontrol)
863{
864 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
865 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200866 unsigned int val = 0;
867 if (spec->automute_speaker)
868 val++;
869 if (spec->automute_lo)
870 val++;
871
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200872 ucontrol->value.enumerated.item[0] = val;
873 return 0;
874}
875
876static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
877 struct snd_ctl_elem_value *ucontrol)
878{
879 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
880 struct alc_spec *spec = codec->spec;
881
882 switch (ucontrol->value.enumerated.item[0]) {
883 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200886 spec->automute_speaker = 0;
887 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200888 break;
889 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200890 if (spec->automute_speaker_possible) {
891 if (!spec->automute_lo && spec->automute_speaker)
892 return 0;
893 spec->automute_speaker = 1;
894 spec->automute_lo = 0;
895 } else if (spec->automute_lo_possible) {
896 if (spec->automute_lo)
897 return 0;
898 spec->automute_lo = 1;
899 } else
900 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200901 break;
902 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200903 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200904 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200905 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200906 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200907 spec->automute_speaker = 1;
908 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909 break;
910 default:
911 return -EINVAL;
912 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200913 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200914 return 1;
915}
916
Takashi Iwaia9111322011-05-02 11:30:18 +0200917static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
919 .name = "Auto-Mute Mode",
920 .info = alc_automute_mode_info,
921 .get = alc_automute_mode_get,
922 .put = alc_automute_mode_put,
923};
924
Takashi Iwai1d045db2011-07-07 18:23:21 +0200925static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
926{
927 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
928 return snd_array_new(&spec->kctls);
929}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200930
931static int alc_add_automute_mode_enum(struct hda_codec *codec)
932{
933 struct alc_spec *spec = codec->spec;
934 struct snd_kcontrol_new *knew;
935
936 knew = alc_kcontrol_new(spec);
937 if (!knew)
938 return -ENOMEM;
939 *knew = alc_automute_mode_enum;
940 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
941 if (!knew->name)
942 return -ENOMEM;
943 return 0;
944}
945
Takashi Iwai1d045db2011-07-07 18:23:21 +0200946/*
947 * Check the availability of HP/line-out auto-mute;
948 * Set up appropriately if really supported
949 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200950static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200951{
952 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200953 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200954 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200955 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200956
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200957 if (cfg->hp_pins[0])
958 present++;
959 if (cfg->line_out_pins[0])
960 present++;
961 if (cfg->speaker_pins[0])
962 present++;
963 if (present < 2) /* need two different output types */
964 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200965
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200966 if (!cfg->speaker_pins[0] &&
967 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200968 memcpy(cfg->speaker_pins, cfg->line_out_pins,
969 sizeof(cfg->speaker_pins));
970 cfg->speaker_outs = cfg->line_outs;
971 }
972
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200973 if (!cfg->hp_pins[0] &&
974 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200975 memcpy(cfg->hp_pins, cfg->line_out_pins,
976 sizeof(cfg->hp_pins));
977 cfg->hp_outs = cfg->line_outs;
978 }
979
David Henningsson42cf0d02011-09-20 12:04:56 +0200980 spec->automute_mode = ALC_AUTOMUTE_PIN;
981
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200982 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200983 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200984 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200985 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200986 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200987 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200988 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200989 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200990 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200991
David Henningsson42cf0d02011-09-20 12:04:56 +0200992 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
993 if (cfg->speaker_outs)
994 for (i = 0; i < cfg->line_outs; i++) {
995 hda_nid_t nid = cfg->line_out_pins[i];
996 if (!is_jack_detectable(codec, nid))
997 continue;
998 snd_printdd("realtek: Enable Line-Out "
999 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001000 snd_hda_jack_detect_enable(codec, nid,
1001 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001002 spec->detect_lo = 1;
1003 }
1004 spec->automute_lo_possible = spec->detect_hp;
1005 }
1006
1007 spec->automute_speaker_possible = cfg->speaker_outs &&
1008 (spec->detect_hp || spec->detect_lo);
1009
1010 spec->automute_lo = spec->automute_lo_possible;
1011 spec->automute_speaker = spec->automute_speaker_possible;
1012
1013 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001014 /* create a control for automute mode */
1015 alc_add_automute_mode_enum(codec);
1016 spec->unsol_event = alc_sku_unsol_event;
1017 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001018}
1019
Takashi Iwai1d045db2011-07-07 18:23:21 +02001020/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001021static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1022{
1023 int i;
1024 for (i = 0; i < nums; i++)
1025 if (list[i] == nid)
1026 return i;
1027 return -1;
1028}
1029
Takashi Iwai1d045db2011-07-07 18:23:21 +02001030/* check whether dynamic ADC-switching is available */
1031static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1032{
1033 struct alc_spec *spec = codec->spec;
1034 struct hda_input_mux *imux = &spec->private_imux[0];
1035 int i, n, idx;
1036 hda_nid_t cap, pin;
1037
1038 if (imux != spec->input_mux) /* no dynamic imux? */
1039 return false;
1040
1041 for (n = 0; n < spec->num_adc_nids; n++) {
1042 cap = spec->private_capsrc_nids[n];
1043 for (i = 0; i < imux->num_items; i++) {
1044 pin = spec->imux_pins[i];
1045 if (!pin)
1046 return false;
1047 if (get_connection_index(codec, cap, pin) < 0)
1048 break;
1049 }
1050 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001051 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001052 }
1053
1054 for (i = 0; i < imux->num_items; i++) {
1055 pin = spec->imux_pins[i];
1056 for (n = 0; n < spec->num_adc_nids; n++) {
1057 cap = spec->private_capsrc_nids[n];
1058 idx = get_connection_index(codec, cap, pin);
1059 if (idx >= 0) {
1060 imux->items[i].index = idx;
1061 spec->dyn_adc_idx[i] = n;
1062 break;
1063 }
1064 }
1065 }
1066
1067 snd_printdd("realtek: enabling ADC switching\n");
1068 spec->dyn_adc_switch = 1;
1069 return true;
1070}
Takashi Iwai21268962011-07-07 15:01:13 +02001071
1072/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1073static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1074{
1075 struct alc_spec *spec = codec->spec;
1076 struct hda_input_mux *imux;
1077 static char * const texts[3] = {
1078 "Mic", "Internal Mic", "Dock Mic"
1079 };
1080 int i;
1081
1082 if (!spec->auto_mic)
1083 return false;
1084 imux = &spec->private_imux[0];
1085 if (spec->input_mux == imux)
1086 return true;
1087 spec->imux_pins[0] = spec->ext_mic_pin;
1088 spec->imux_pins[1] = spec->int_mic_pin;
1089 spec->imux_pins[2] = spec->dock_mic_pin;
1090 for (i = 0; i < 3; i++) {
1091 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001092 if (spec->imux_pins[i]) {
1093 hda_nid_t pin = spec->imux_pins[i];
1094 int c;
1095 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001096 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001097 int idx = get_connection_index(codec, cap, pin);
1098 if (idx >= 0) {
1099 imux->items[i].index = idx;
1100 break;
1101 }
1102 }
Takashi Iwai21268962011-07-07 15:01:13 +02001103 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001104 }
Takashi Iwai21268962011-07-07 15:01:13 +02001105 }
1106 spec->num_mux_defs = 1;
1107 spec->input_mux = imux;
1108 return true;
1109}
1110
1111/* check whether all auto-mic pins are valid; setup indices if OK */
1112static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1113{
1114 struct alc_spec *spec = codec->spec;
1115 const struct hda_input_mux *imux;
1116
1117 if (!spec->auto_mic)
1118 return false;
1119 if (spec->auto_mic_valid_imux)
1120 return true; /* already checked */
1121
1122 /* fill up imux indices */
1123 if (!alc_check_dyn_adc_switch(codec)) {
1124 spec->auto_mic = 0;
1125 return false;
1126 }
1127
1128 imux = spec->input_mux;
1129 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1130 spec->imux_pins, imux->num_items);
1131 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1132 spec->imux_pins, imux->num_items);
1133 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1134 spec->imux_pins, imux->num_items);
1135 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1136 spec->auto_mic = 0;
1137 return false; /* no corresponding imux */
1138 }
1139
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001140 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001141 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001142 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1143 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001144
1145 spec->auto_mic_valid_imux = 1;
1146 spec->auto_mic = 1;
1147 return true;
1148}
1149
Takashi Iwai1d045db2011-07-07 18:23:21 +02001150/*
1151 * Check the availability of auto-mic switch;
1152 * Set up if really supported
1153 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001154static void alc_init_auto_mic(struct hda_codec *codec)
1155{
1156 struct alc_spec *spec = codec->spec;
1157 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001158 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001159 int i;
1160
Takashi Iwai24de1832011-11-07 17:13:39 +01001161 if (spec->shared_mic_hp)
1162 return; /* no auto-mic for the shared I/O */
1163
Takashi Iwai21268962011-07-07 15:01:13 +02001164 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1165
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001166 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001167 for (i = 0; i < cfg->num_inputs; i++) {
1168 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001169 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001170 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001171 switch (snd_hda_get_input_pin_attr(defcfg)) {
1172 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001173 if (fixed)
1174 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001175 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1176 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001177 fixed = nid;
1178 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001179 case INPUT_PIN_ATTR_UNUSED:
1180 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001181 case INPUT_PIN_ATTR_DOCK:
1182 if (dock)
1183 return; /* already occupied */
1184 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1185 return; /* invalid type */
1186 dock = nid;
1187 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001188 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001189 if (ext)
1190 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001191 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1192 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001193 ext = nid;
1194 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001195 }
1196 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001197 if (!ext && dock) {
1198 ext = dock;
1199 dock = 0;
1200 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001201 if (!ext || !fixed)
1202 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001203 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001204 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001205 if (dock && !is_jack_detectable(codec, dock))
1206 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001207
1208 /* check imux indices */
1209 spec->ext_mic_pin = ext;
1210 spec->int_mic_pin = fixed;
1211 spec->dock_mic_pin = dock;
1212
1213 spec->auto_mic = 1;
1214 if (!alc_auto_mic_check_imux(codec))
1215 return;
1216
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001217 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1218 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001219 spec->unsol_event = alc_sku_unsol_event;
1220}
1221
Takashi Iwai1d045db2011-07-07 18:23:21 +02001222/* check the availabilities of auto-mute and auto-mic switches */
1223static void alc_auto_check_switches(struct hda_codec *codec)
1224{
David Henningsson42cf0d02011-09-20 12:04:56 +02001225 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001226 alc_init_auto_mic(codec);
1227}
1228
1229/*
1230 * Realtek SSID verification
1231 */
1232
David Henningsson90622912010-10-14 14:50:18 +02001233/* Could be any non-zero and even value. When used as fixup, tells
1234 * the driver to ignore any present sku defines.
1235 */
1236#define ALC_FIXUP_SKU_IGNORE (2)
1237
Kailang Yangda00c242010-03-19 11:23:45 +01001238static int alc_auto_parse_customize_define(struct hda_codec *codec)
1239{
1240 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001241 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001242 struct alc_spec *spec = codec->spec;
1243
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001244 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1245
David Henningsson90622912010-10-14 14:50:18 +02001246 if (spec->cdefine.fixup) {
1247 ass = spec->cdefine.sku_cfg;
1248 if (ass == ALC_FIXUP_SKU_IGNORE)
1249 return -1;
1250 goto do_sku;
1251 }
1252
Kailang Yangda00c242010-03-19 11:23:45 +01001253 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001254 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001255 goto do_sku;
1256
1257 nid = 0x1d;
1258 if (codec->vendor_id == 0x10ec0260)
1259 nid = 0x17;
1260 ass = snd_hda_codec_get_pincfg(codec, nid);
1261
1262 if (!(ass & 1)) {
1263 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1264 codec->chip_name, ass);
1265 return -1;
1266 }
1267
1268 /* check sum */
1269 tmp = 0;
1270 for (i = 1; i < 16; i++) {
1271 if ((ass >> i) & 1)
1272 tmp++;
1273 }
1274 if (((ass >> 16) & 0xf) != tmp)
1275 return -1;
1276
1277 spec->cdefine.port_connectivity = ass >> 30;
1278 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1279 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1280 spec->cdefine.customization = ass >> 8;
1281do_sku:
1282 spec->cdefine.sku_cfg = ass;
1283 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1284 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1285 spec->cdefine.swap = (ass & 0x2) >> 1;
1286 spec->cdefine.override = ass & 0x1;
1287
1288 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1289 nid, spec->cdefine.sku_cfg);
1290 snd_printd("SKU: port_connectivity=0x%x\n",
1291 spec->cdefine.port_connectivity);
1292 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1293 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1294 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1295 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1296 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1297 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1298 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1299
1300 return 0;
1301}
1302
Takashi Iwai1d045db2011-07-07 18:23:21 +02001303/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001304static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1305{
Takashi Iwai21268962011-07-07 15:01:13 +02001306 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001307}
1308
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001309/* check subsystem ID and set up device-specific initialization;
1310 * return 1 if initialized, 0 if invalid SSID
1311 */
1312/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1313 * 31 ~ 16 : Manufacture ID
1314 * 15 ~ 8 : SKU ID
1315 * 7 ~ 0 : Assembly ID
1316 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1317 */
1318static int alc_subsystem_id(struct hda_codec *codec,
1319 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001320 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001321{
1322 unsigned int ass, tmp, i;
1323 unsigned nid;
1324 struct alc_spec *spec = codec->spec;
1325
David Henningsson90622912010-10-14 14:50:18 +02001326 if (spec->cdefine.fixup) {
1327 ass = spec->cdefine.sku_cfg;
1328 if (ass == ALC_FIXUP_SKU_IGNORE)
1329 return 0;
1330 goto do_sku;
1331 }
1332
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001333 ass = codec->subsystem_id & 0xffff;
1334 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1335 goto do_sku;
1336
1337 /* invalid SSID, check the special NID pin defcfg instead */
1338 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001339 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001340 * 29~21 : reserve
1341 * 20 : PCBEEP input
1342 * 19~16 : Check sum (15:1)
1343 * 15~1 : Custom
1344 * 0 : override
1345 */
1346 nid = 0x1d;
1347 if (codec->vendor_id == 0x10ec0260)
1348 nid = 0x17;
1349 ass = snd_hda_codec_get_pincfg(codec, nid);
1350 snd_printd("realtek: No valid SSID, "
1351 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001352 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001353 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001354 return 0;
1355 if ((ass >> 30) != 1) /* no physical connection */
1356 return 0;
1357
1358 /* check sum */
1359 tmp = 0;
1360 for (i = 1; i < 16; i++) {
1361 if ((ass >> i) & 1)
1362 tmp++;
1363 }
1364 if (((ass >> 16) & 0xf) != tmp)
1365 return 0;
1366do_sku:
1367 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1368 ass & 0xffff, codec->vendor_id);
1369 /*
1370 * 0 : override
1371 * 1 : Swap Jack
1372 * 2 : 0 --> Desktop, 1 --> Laptop
1373 * 3~5 : External Amplifier control
1374 * 7~6 : Reserved
1375 */
1376 tmp = (ass & 0x38) >> 3; /* external Amp control */
1377 switch (tmp) {
1378 case 1:
1379 spec->init_amp = ALC_INIT_GPIO1;
1380 break;
1381 case 3:
1382 spec->init_amp = ALC_INIT_GPIO2;
1383 break;
1384 case 7:
1385 spec->init_amp = ALC_INIT_GPIO3;
1386 break;
1387 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001388 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001389 spec->init_amp = ALC_INIT_DEFAULT;
1390 break;
1391 }
1392
1393 /* is laptop or Desktop and enable the function "Mute internal speaker
1394 * when the external headphone out jack is plugged"
1395 */
1396 if (!(ass & 0x8000))
1397 return 1;
1398 /*
1399 * 10~8 : Jack location
1400 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1401 * 14~13: Resvered
1402 * 15 : 1 --> enable the function "Mute internal speaker
1403 * when the external headphone out jack is plugged"
1404 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001405 if (!spec->autocfg.hp_pins[0] &&
1406 !(spec->autocfg.line_out_pins[0] &&
1407 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001408 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001409 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1410 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001411 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001412 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001413 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001414 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001415 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001416 else if (tmp == 3)
1417 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001418 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001419 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001420 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1421 spec->autocfg.line_outs))
1422 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001423 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001424 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001425 return 1;
1426}
Kailang Yangea1fb292008-08-26 12:58:38 +02001427
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001428/* Check the validity of ALC subsystem-id
1429 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1430static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001431{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001432 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001433 struct alc_spec *spec = codec->spec;
1434 snd_printd("realtek: "
1435 "Enable default setup for auto mode as fallback\n");
1436 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001437 }
Takashi Iwai21268962011-07-07 15:01:13 +02001438}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001439
Takashi Iwai41e41f12005-06-08 14:48:49 +02001440/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001441 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001442 */
1443
1444struct alc_pincfg {
1445 hda_nid_t nid;
1446 u32 val;
1447};
1448
Todd Broche1eb5f12010-12-06 11:19:51 -08001449struct alc_model_fixup {
1450 const int id;
1451 const char *name;
1452};
1453
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001454struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001455 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001456 bool chained;
1457 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001458 union {
1459 unsigned int sku;
1460 const struct alc_pincfg *pins;
1461 const struct hda_verb *verbs;
1462 void (*func)(struct hda_codec *codec,
1463 const struct alc_fixup *fix,
1464 int action);
1465 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001466};
1467
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001468enum {
1469 ALC_FIXUP_INVALID,
1470 ALC_FIXUP_SKU,
1471 ALC_FIXUP_PINS,
1472 ALC_FIXUP_VERBS,
1473 ALC_FIXUP_FUNC,
1474};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001475
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001476enum {
1477 ALC_FIXUP_ACT_PRE_PROBE,
1478 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001479 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001480};
1481
1482static void alc_apply_fixup(struct hda_codec *codec, int action)
1483{
1484 struct alc_spec *spec = codec->spec;
1485 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001486#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001487 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001488#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001489 int depth = 0;
1490
1491 if (!spec->fixup_list)
1492 return;
1493
1494 while (id >= 0) {
1495 const struct alc_fixup *fix = spec->fixup_list + id;
1496 const struct alc_pincfg *cfg;
1497
1498 switch (fix->type) {
1499 case ALC_FIXUP_SKU:
1500 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001501 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001502 snd_printdd(KERN_INFO "hda_codec: %s: "
1503 "Apply sku override for %s\n",
1504 codec->chip_name, modelname);
1505 spec->cdefine.sku_cfg = fix->v.sku;
1506 spec->cdefine.fixup = 1;
1507 break;
1508 case ALC_FIXUP_PINS:
1509 cfg = fix->v.pins;
1510 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1511 break;
1512 snd_printdd(KERN_INFO "hda_codec: %s: "
1513 "Apply pincfg for %s\n",
1514 codec->chip_name, modelname);
1515 for (; cfg->nid; cfg++)
1516 snd_hda_codec_set_pincfg(codec, cfg->nid,
1517 cfg->val);
1518 break;
1519 case ALC_FIXUP_VERBS:
1520 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1521 break;
1522 snd_printdd(KERN_INFO "hda_codec: %s: "
1523 "Apply fix-verbs for %s\n",
1524 codec->chip_name, modelname);
1525 add_verb(codec->spec, fix->v.verbs);
1526 break;
1527 case ALC_FIXUP_FUNC:
1528 if (!fix->v.func)
1529 break;
1530 snd_printdd(KERN_INFO "hda_codec: %s: "
1531 "Apply fix-func for %s\n",
1532 codec->chip_name, modelname);
1533 fix->v.func(codec, fix, action);
1534 break;
1535 default:
1536 snd_printk(KERN_ERR "hda_codec: %s: "
1537 "Invalid fixup type %d\n",
1538 codec->chip_name, fix->type);
1539 break;
1540 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001541 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001542 break;
1543 if (++depth > 10)
1544 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001545 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001546 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001547}
1548
Todd Broche1eb5f12010-12-06 11:19:51 -08001549static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001550 const struct alc_model_fixup *models,
1551 const struct snd_pci_quirk *quirk,
1552 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001553{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001554 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001555 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001556 int id = -1;
1557 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001558
Takashi Iwai9155f822012-02-20 18:41:02 +01001559 /* when model=nofixup is given, don't pick up any fixups */
1560 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
1561 spec->fixup_list = NULL;
1562 spec->fixup_id = -1;
1563 return;
1564 }
1565
Todd Broche1eb5f12010-12-06 11:19:51 -08001566 if (codec->modelname && models) {
1567 while (models->name) {
1568 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001569 id = models->id;
1570 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001571 break;
1572 }
1573 models++;
1574 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001575 }
1576 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001577 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1578 if (q) {
1579 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001580#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001581 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001582#endif
1583 }
1584 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001585 if (id < 0) {
1586 for (q = quirk; q->subvendor; q++) {
1587 unsigned int vendorid =
1588 q->subdevice | (q->subvendor << 16);
1589 if (vendorid == codec->subsystem_id) {
1590 id = q->value;
1591#ifdef CONFIG_SND_DEBUG_VERBOSE
1592 name = q->name;
1593#endif
1594 break;
1595 }
1596 }
1597 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001598
1599 spec->fixup_id = id;
1600 if (id >= 0) {
1601 spec->fixup_list = fixlist;
1602 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001603 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001604}
1605
Takashi Iwai1d045db2011-07-07 18:23:21 +02001606/*
1607 * COEF access helper functions
1608 */
Kailang Yang274693f2009-12-03 10:07:50 +01001609static int alc_read_coef_idx(struct hda_codec *codec,
1610 unsigned int coef_idx)
1611{
1612 unsigned int val;
1613 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1614 coef_idx);
1615 val = snd_hda_codec_read(codec, 0x20, 0,
1616 AC_VERB_GET_PROC_COEF, 0);
1617 return val;
1618}
1619
Kailang Yang977ddd62010-09-15 10:02:29 +02001620static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1621 unsigned int coef_val)
1622{
1623 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1624 coef_idx);
1625 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1626 coef_val);
1627}
1628
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001629/* a special bypass for COEF 0; read the cached value at the second time */
1630static unsigned int alc_get_coef0(struct hda_codec *codec)
1631{
1632 struct alc_spec *spec = codec->spec;
1633 if (!spec->coef0)
1634 spec->coef0 = alc_read_coef_idx(codec, 0);
1635 return spec->coef0;
1636}
1637
Takashi Iwai1d045db2011-07-07 18:23:21 +02001638/*
1639 * Digital I/O handling
1640 */
1641
Takashi Iwai757899a2010-07-30 10:48:14 +02001642/* set right pin controls for digital I/O */
1643static void alc_auto_init_digital(struct hda_codec *codec)
1644{
1645 struct alc_spec *spec = codec->spec;
1646 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001647 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001648
1649 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1650 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001651 if (!pin)
1652 continue;
1653 snd_hda_codec_write(codec, pin, 0,
1654 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1655 if (!i)
1656 dac = spec->multiout.dig_out_nid;
1657 else
1658 dac = spec->slave_dig_outs[i - 1];
1659 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1660 continue;
1661 snd_hda_codec_write(codec, dac, 0,
1662 AC_VERB_SET_AMP_GAIN_MUTE,
1663 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001664 }
1665 pin = spec->autocfg.dig_in_pin;
1666 if (pin)
1667 snd_hda_codec_write(codec, pin, 0,
1668 AC_VERB_SET_PIN_WIDGET_CONTROL,
1669 PIN_IN);
1670}
1671
1672/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1673static void alc_auto_parse_digital(struct hda_codec *codec)
1674{
1675 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001676 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001677 hda_nid_t dig_nid;
1678
1679 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001680 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001681 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001682 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001683 err = snd_hda_get_connections(codec,
1684 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001685 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001686 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001687 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001688 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001689 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001690 spec->multiout.dig_out_nid = dig_nid;
1691 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1692 } else {
1693 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001694 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001695 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001696 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001697 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001698 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001699 }
1700
1701 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001702 dig_nid = codec->start_nid;
1703 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1704 unsigned int wcaps = get_wcaps(codec, dig_nid);
1705 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1706 continue;
1707 if (!(wcaps & AC_WCAP_DIGITAL))
1708 continue;
1709 if (!(wcaps & AC_WCAP_CONN_LIST))
1710 continue;
1711 err = get_connection_index(codec, dig_nid,
1712 spec->autocfg.dig_in_pin);
1713 if (err >= 0) {
1714 spec->dig_in_nid = dig_nid;
1715 break;
1716 }
1717 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001718 }
1719}
1720
Takashi Iwaif95474e2007-07-10 00:47:43 +02001721/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001722 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001723 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001724static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1725 struct snd_ctl_elem_info *uinfo)
1726{
1727 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1728 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001729 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001730 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001731
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001732 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001733 if (spec->vol_in_capsrc)
1734 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1735 else
1736 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1737 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001738 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001739 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001740 return err;
1741}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001743static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1744 unsigned int size, unsigned int __user *tlv)
1745{
1746 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1747 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001748 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001749 int err;
1750
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001751 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001752 if (spec->vol_in_capsrc)
1753 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1754 else
1755 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1756 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001757 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001758 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001759 return err;
1760}
1761
1762typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol);
1764
1765static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1766 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001767 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001768{
1769 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1770 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001771 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001772
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001773 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001774 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001775 for (i = 0; i < spec->num_adc_nids; i++) {
1776 kcontrol->private_value =
1777 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1778 3, 0, HDA_INPUT);
1779 err = func(kcontrol, ucontrol);
1780 if (err < 0)
1781 goto error;
1782 }
1783 } else {
1784 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001785 if (spec->vol_in_capsrc)
1786 kcontrol->private_value =
1787 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1788 3, 0, HDA_OUTPUT);
1789 else
1790 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001791 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1792 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001793 err = func(kcontrol, ucontrol);
1794 }
1795 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001796 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001797 return err;
1798}
1799
1800static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1801 struct snd_ctl_elem_value *ucontrol)
1802{
1803 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001804 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001805}
1806
1807static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1808 struct snd_ctl_elem_value *ucontrol)
1809{
1810 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001811 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001812}
1813
1814/* capture mixer elements */
1815#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1816
1817static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1818 struct snd_ctl_elem_value *ucontrol)
1819{
1820 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001821 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001822}
1823
1824static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1825 struct snd_ctl_elem_value *ucontrol)
1826{
1827 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001828 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001829}
1830
Takashi Iwaia23b6882009-03-23 15:21:36 +01001831#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001832 { \
1833 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1834 .name = "Capture Switch", \
1835 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1836 .count = num, \
1837 .info = alc_cap_sw_info, \
1838 .get = alc_cap_sw_get, \
1839 .put = alc_cap_sw_put, \
1840 }, \
1841 { \
1842 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1843 .name = "Capture Volume", \
1844 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1845 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1846 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1847 .count = num, \
1848 .info = alc_cap_vol_info, \
1849 .get = alc_cap_vol_get, \
1850 .put = alc_cap_vol_put, \
1851 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001852 }
1853
1854#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001855 { \
1856 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1857 /* .name = "Capture Source", */ \
1858 .name = "Input Source", \
1859 .count = num, \
1860 .info = alc_mux_enum_info, \
1861 .get = alc_mux_enum_get, \
1862 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001863 }
1864
1865#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001866static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001867 _DEFINE_CAPMIX(num), \
1868 _DEFINE_CAPSRC(num), \
1869 { } /* end */ \
1870}
1871
1872#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001873static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001874 _DEFINE_CAPMIX(num), \
1875 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001876}
1877
1878/* up to three ADCs */
1879DEFINE_CAPMIX(1);
1880DEFINE_CAPMIX(2);
1881DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001882DEFINE_CAPMIX_NOSRC(1);
1883DEFINE_CAPMIX_NOSRC(2);
1884DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001885
1886/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001887 * virtual master controls
1888 */
1889
1890/*
1891 * slave controls for virtual master
1892 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001893static const char * const alc_slave_pfxs[] = {
1894 "Front", "Surround", "Center", "LFE", "Side",
1895 "Headphone", "Speaker", "Mono", "Line-Out",
1896 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001897 NULL,
1898};
1899
1900/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001901 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001903
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001904#define NID_MAPPING (-1)
1905
1906#define SUBDEV_SPEAKER_ (0 << 6)
1907#define SUBDEV_HP_ (1 << 6)
1908#define SUBDEV_LINE_ (2 << 6)
1909#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1910#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1911#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1912
Takashi Iwai603c4012008-07-30 15:01:44 +02001913static void alc_free_kctls(struct hda_codec *codec);
1914
Takashi Iwai67d634c2009-11-16 15:35:59 +01001915#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001916/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001917static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001918 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001919 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001920 { } /* end */
1921};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001922#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001923
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001924static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925{
1926 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001927 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001928 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001929 int i, j, err;
1930 unsigned int u;
1931 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
1933 for (i = 0; i < spec->num_mixers; i++) {
1934 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1935 if (err < 0)
1936 return err;
1937 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001938 if (spec->cap_mixer) {
1939 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1940 if (err < 0)
1941 return err;
1942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001944 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001945 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001946 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 if (err < 0)
1948 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001949 if (!spec->no_analog) {
1950 err = snd_hda_create_spdif_share_sw(codec,
1951 &spec->multiout);
1952 if (err < 0)
1953 return err;
1954 spec->multiout.share_spdif = 1;
1955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 }
1957 if (spec->dig_in_nid) {
1958 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1959 if (err < 0)
1960 return err;
1961 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001962
Takashi Iwai67d634c2009-11-16 15:35:59 +01001963#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001964 /* create beep controls if needed */
1965 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001966 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001967 for (knew = alc_beep_mixer; knew->name; knew++) {
1968 struct snd_kcontrol *kctl;
1969 kctl = snd_ctl_new1(knew, codec);
1970 if (!kctl)
1971 return -ENOMEM;
1972 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001973 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001974 if (err < 0)
1975 return err;
1976 }
1977 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001978#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001979
Takashi Iwai2134ea42008-01-10 16:53:55 +01001980 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001981 if (!spec->no_analog &&
1982 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001983 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001984 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001985 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001986 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001987 vmaster_tlv, alc_slave_pfxs,
1988 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001989 if (err < 0)
1990 return err;
1991 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001992 if (!spec->no_analog &&
1993 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001994 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001995 NULL, alc_slave_pfxs,
1996 "Playback Switch");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001997 if (err < 0)
1998 return err;
1999 }
2000
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002001 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02002002 if (spec->capsrc_nids || spec->adc_nids) {
2003 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
2004 if (!kctl)
2005 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
2006 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002007 err = snd_hda_add_nid(codec, kctl, i,
2008 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02002009 if (err < 0)
2010 return err;
2011 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002012 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02002013 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002014 const char *kname = kctl ? kctl->id.name : NULL;
2015 for (knew = spec->cap_mixer; knew->name; knew++) {
2016 if (kname && strcmp(knew->name, kname) == 0)
2017 continue;
2018 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2019 for (i = 0; kctl && i < kctl->count; i++) {
2020 err = snd_hda_add_nid(codec, kctl, i,
2021 spec->adc_nids[i]);
2022 if (err < 0)
2023 return err;
2024 }
2025 }
2026 }
2027
2028 /* other nid->control mapping */
2029 for (i = 0; i < spec->num_mixers; i++) {
2030 for (knew = spec->mixers[i]; knew->name; knew++) {
2031 if (knew->iface != NID_MAPPING)
2032 continue;
2033 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2034 if (kctl == NULL)
2035 continue;
2036 u = knew->subdevice;
2037 for (j = 0; j < 4; j++, u >>= 8) {
2038 nid = u & 0x3f;
2039 if (nid == 0)
2040 continue;
2041 switch (u & 0xc0) {
2042 case SUBDEV_SPEAKER_:
2043 nid = spec->autocfg.speaker_pins[nid];
2044 break;
2045 case SUBDEV_LINE_:
2046 nid = spec->autocfg.line_out_pins[nid];
2047 break;
2048 case SUBDEV_HP_:
2049 nid = spec->autocfg.hp_pins[nid];
2050 break;
2051 default:
2052 continue;
2053 }
2054 err = snd_hda_add_nid(codec, kctl, 0, nid);
2055 if (err < 0)
2056 return err;
2057 }
2058 u = knew->private_value;
2059 for (j = 0; j < 4; j++, u >>= 8) {
2060 nid = u & 0xff;
2061 if (nid == 0)
2062 continue;
2063 err = snd_hda_add_nid(codec, kctl, 0, nid);
2064 if (err < 0)
2065 return err;
2066 }
2067 }
2068 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002069
2070 alc_free_kctls(codec); /* no longer needed */
2071
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002072 return 0;
2073}
2074
2075static int alc_build_controls(struct hda_codec *codec)
2076{
2077 struct alc_spec *spec = codec->spec;
2078 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002079 if (err < 0)
2080 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002081 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082}
2083
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002084
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002086 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002087 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002088
Takashi Iwai584c0c42011-03-10 12:51:11 +01002089static void alc_init_special_input_src(struct hda_codec *codec);
2090
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091static int alc_init(struct hda_codec *codec)
2092{
2093 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002094 unsigned int i;
2095
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002096 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002097 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002098
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002099 for (i = 0; i < spec->num_init_verbs; i++)
2100 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002101 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002102
2103 if (spec->init_hook)
2104 spec->init_hook(codec);
2105
Takashi Iwai58701122011-01-13 15:41:45 +01002106 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2107
Takashi Iwai01a61e12011-10-28 00:03:22 +02002108 snd_hda_jack_report_sync(codec);
2109
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002110 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 return 0;
2112}
2113
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002114static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2115{
2116 struct alc_spec *spec = codec->spec;
2117
2118 if (spec->unsol_event)
2119 spec->unsol_event(codec, res);
2120}
2121
Takashi Iwaicb53c622007-08-10 17:21:45 +02002122#ifdef CONFIG_SND_HDA_POWER_SAVE
2123static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2124{
2125 struct alc_spec *spec = codec->spec;
2126 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2127}
2128#endif
2129
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130/*
2131 * Analog playback callbacks
2132 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002133static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002135 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
2137 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002138 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2139 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140}
2141
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002142static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct hda_codec *codec,
2144 unsigned int stream_tag,
2145 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002146 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147{
2148 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002149 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2150 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151}
2152
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002153static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002155 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
2157 struct alc_spec *spec = codec->spec;
2158 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2159}
2160
2161/*
2162 * Digital out
2163 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002164static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002166 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167{
2168 struct alc_spec *spec = codec->spec;
2169 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2170}
2171
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002172static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002173 struct hda_codec *codec,
2174 unsigned int stream_tag,
2175 unsigned int format,
2176 struct snd_pcm_substream *substream)
2177{
2178 struct alc_spec *spec = codec->spec;
2179 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2180 stream_tag, format, substream);
2181}
2182
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002183static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002184 struct hda_codec *codec,
2185 struct snd_pcm_substream *substream)
2186{
2187 struct alc_spec *spec = codec->spec;
2188 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2189}
2190
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002191static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002193 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194{
2195 struct alc_spec *spec = codec->spec;
2196 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2197}
2198
2199/*
2200 * Analog capture
2201 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002202static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 struct hda_codec *codec,
2204 unsigned int stream_tag,
2205 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002206 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
2208 struct alc_spec *spec = codec->spec;
2209
Takashi Iwai63300792008-01-24 15:31:36 +01002210 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 stream_tag, 0, format);
2212 return 0;
2213}
2214
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002215static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002217 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218{
2219 struct alc_spec *spec = codec->spec;
2220
Takashi Iwai888afa12008-03-18 09:57:50 +01002221 snd_hda_codec_cleanup_stream(codec,
2222 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 return 0;
2224}
2225
Takashi Iwai840b64c2010-07-13 22:49:01 +02002226/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002227static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002228 struct hda_codec *codec,
2229 unsigned int stream_tag,
2230 unsigned int format,
2231 struct snd_pcm_substream *substream)
2232{
2233 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002234 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002235 spec->cur_adc_stream_tag = stream_tag;
2236 spec->cur_adc_format = format;
2237 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2238 return 0;
2239}
2240
Takashi Iwai21268962011-07-07 15:01:13 +02002241static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002242 struct hda_codec *codec,
2243 struct snd_pcm_substream *substream)
2244{
2245 struct alc_spec *spec = codec->spec;
2246 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2247 spec->cur_adc = 0;
2248 return 0;
2249}
2250
Takashi Iwai21268962011-07-07 15:01:13 +02002251static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002252 .substreams = 1,
2253 .channels_min = 2,
2254 .channels_max = 2,
2255 .nid = 0, /* fill later */
2256 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002257 .prepare = dyn_adc_capture_pcm_prepare,
2258 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002259 },
2260};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
2262/*
2263 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002264static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 .substreams = 1,
2266 .channels_min = 2,
2267 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002268 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002270 .open = alc_playback_pcm_open,
2271 .prepare = alc_playback_pcm_prepare,
2272 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 },
2274};
2275
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002276static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002277 .substreams = 1,
2278 .channels_min = 2,
2279 .channels_max = 2,
2280 /* NID is set in alc_build_pcms */
2281};
2282
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002283static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002284 .substreams = 1,
2285 .channels_min = 2,
2286 .channels_max = 2,
2287 /* NID is set in alc_build_pcms */
2288};
2289
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002290static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002291 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 .channels_min = 2,
2293 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002294 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002296 .prepare = alc_alt_capture_pcm_prepare,
2297 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 },
2299};
2300
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002301static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 .substreams = 1,
2303 .channels_min = 2,
2304 .channels_max = 2,
2305 /* NID is set in alc_build_pcms */
2306 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002307 .open = alc_dig_playback_pcm_open,
2308 .close = alc_dig_playback_pcm_close,
2309 .prepare = alc_dig_playback_pcm_prepare,
2310 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 },
2312};
2313
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002314static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 .substreams = 1,
2316 .channels_min = 2,
2317 .channels_max = 2,
2318 /* NID is set in alc_build_pcms */
2319};
2320
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002321/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002322static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002323 .substreams = 0,
2324 .channels_min = 0,
2325 .channels_max = 0,
2326};
2327
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328static int alc_build_pcms(struct hda_codec *codec)
2329{
2330 struct alc_spec *spec = codec->spec;
2331 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002332 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002333 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 int i;
2335
2336 codec->num_pcms = 1;
2337 codec->pcm_info = info;
2338
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002339 if (spec->no_analog)
2340 goto skip_analog;
2341
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002342 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2343 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002345
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002346 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002347 p = spec->stream_analog_playback;
2348 if (!p)
2349 p = &alc_pcm_analog_playback;
2350 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002351 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2352 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002353 if (spec->adc_nids) {
2354 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002355 if (!p) {
2356 if (spec->dyn_adc_switch)
2357 p = &dyn_adc_pcm_analog_capture;
2358 else
2359 p = &alc_pcm_analog_capture;
2360 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002361 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002362 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Takashi Iwai4a471b72005-12-07 13:56:29 +01002365 if (spec->channel_mode) {
2366 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2367 for (i = 0; i < spec->num_channel_mode; i++) {
2368 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2369 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 }
2372 }
2373
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002374 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002375 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002377 snprintf(spec->stream_name_digital,
2378 sizeof(spec->stream_name_digital),
2379 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002380 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002381 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002382 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002384 if (spec->dig_out_type)
2385 info->pcm_type = spec->dig_out_type;
2386 else
2387 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002388 if (spec->multiout.dig_out_nid) {
2389 p = spec->stream_digital_playback;
2390 if (!p)
2391 p = &alc_pcm_digital_playback;
2392 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2394 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002395 if (spec->dig_in_nid) {
2396 p = spec->stream_digital_capture;
2397 if (!p)
2398 p = &alc_pcm_digital_capture;
2399 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2401 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002402 /* FIXME: do we need this for all Realtek codec models? */
2403 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 }
2405
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002406 if (spec->no_analog)
2407 return 0;
2408
Takashi Iwaie08a0072006-09-07 17:52:14 +02002409 /* If the use of more than one ADC is requested for the current
2410 * model, configure a second analog capture-only PCM.
2411 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002412 have_multi_adcs = (spec->num_adc_nids > 1) &&
2413 !spec->dyn_adc_switch && !spec->auto_mic &&
2414 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002415 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002416 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002417 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002418 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002419 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002420 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002421 p = spec->stream_analog_alt_playback;
2422 if (!p)
2423 p = &alc_pcm_analog_alt_playback;
2424 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002425 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2426 spec->alt_dac_nid;
2427 } else {
2428 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2429 alc_pcm_null_stream;
2430 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2431 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002432 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002433 p = spec->stream_analog_alt_capture;
2434 if (!p)
2435 p = &alc_pcm_analog_alt_capture;
2436 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002437 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2438 spec->adc_nids[1];
2439 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2440 spec->num_adc_nids - 1;
2441 } else {
2442 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2443 alc_pcm_null_stream;
2444 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002445 }
2446 }
2447
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 return 0;
2449}
2450
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002451static inline void alc_shutup(struct hda_codec *codec)
2452{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002453 struct alc_spec *spec = codec->spec;
2454
2455 if (spec && spec->shutup)
2456 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002457 snd_hda_shutup_pins(codec);
2458}
2459
Takashi Iwai603c4012008-07-30 15:01:44 +02002460static void alc_free_kctls(struct hda_codec *codec)
2461{
2462 struct alc_spec *spec = codec->spec;
2463
2464 if (spec->kctls.list) {
2465 struct snd_kcontrol_new *kctl = spec->kctls.list;
2466 int i;
2467 for (i = 0; i < spec->kctls.used; i++)
2468 kfree(kctl[i].name);
2469 }
2470 snd_array_free(&spec->kctls);
2471}
2472
Takashi Iwai23c09b02011-08-19 09:05:35 +02002473static void alc_free_bind_ctls(struct hda_codec *codec)
2474{
2475 struct alc_spec *spec = codec->spec;
2476 if (spec->bind_ctls.list) {
2477 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2478 int i;
2479 for (i = 0; i < spec->bind_ctls.used; i++)
2480 kfree(ctl[i]);
2481 }
2482 snd_array_free(&spec->bind_ctls);
2483}
2484
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485static void alc_free(struct hda_codec *codec)
2486{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002487 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002488
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002489 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002490 return;
2491
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002492 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002493 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002494 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002495 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002496 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497}
2498
Hector Martinf5de24b2009-12-20 22:51:31 +01002499#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002500static void alc_power_eapd(struct hda_codec *codec)
2501{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002502 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002503}
2504
Hector Martinf5de24b2009-12-20 22:51:31 +01002505static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2506{
2507 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002508 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002509 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002510 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002511 return 0;
2512}
2513#endif
2514
Takashi Iwai2a439522011-07-26 09:52:50 +02002515#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002516static int alc_resume(struct hda_codec *codec)
2517{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002518 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002519 codec->patch_ops.init(codec);
2520 snd_hda_codec_resume_amp(codec);
2521 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002522 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002523 return 0;
2524}
Takashi Iwaie044c392008-10-27 16:56:24 +01002525#endif
2526
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527/*
2528 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002529static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 .build_controls = alc_build_controls,
2531 .build_pcms = alc_build_pcms,
2532 .init = alc_init,
2533 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002534 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002535#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002536 .resume = alc_resume,
2537#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002538#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002539 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002540 .check_power_status = alc_check_power_status,
2541#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002542 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543};
2544
Kailang Yangc027ddc2010-03-19 11:33:06 +01002545/* replace the codec chip_name with the given string */
2546static int alc_codec_rename(struct hda_codec *codec, const char *name)
2547{
2548 kfree(codec->chip_name);
2549 codec->chip_name = kstrdup(name, GFP_KERNEL);
2550 if (!codec->chip_name) {
2551 alc_free(codec);
2552 return -ENOMEM;
2553 }
2554 return 0;
2555}
2556
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002557/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002558 * Rename codecs appropriately from COEF value
2559 */
2560struct alc_codec_rename_table {
2561 unsigned int vendor_id;
2562 unsigned short coef_mask;
2563 unsigned short coef_bits;
2564 const char *name;
2565};
2566
2567static struct alc_codec_rename_table rename_tbl[] = {
2568 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2569 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2570 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2571 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2572 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2573 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2574 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2575 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2576 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2577 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2578 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2579 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2580 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2581 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2582 { } /* terminator */
2583};
2584
2585static int alc_codec_rename_from_preset(struct hda_codec *codec)
2586{
2587 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002588
2589 for (p = rename_tbl; p->vendor_id; p++) {
2590 if (p->vendor_id != codec->vendor_id)
2591 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002592 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002593 return alc_codec_rename(codec, p->name);
2594 }
2595 return 0;
2596}
2597
2598/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002599 * Automatic parse of I/O pins from the BIOS configuration
2600 */
2601
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002602enum {
2603 ALC_CTL_WIDGET_VOL,
2604 ALC_CTL_WIDGET_MUTE,
2605 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002606 ALC_CTL_BIND_VOL,
2607 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002608};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002609static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002610 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2611 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002612 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002613 HDA_BIND_VOL(NULL, 0),
2614 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002615};
2616
2617/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002618static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002619 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002620{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002621 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002622
Takashi Iwaice764ab2011-04-27 16:35:23 +02002623 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002624 if (!knew)
2625 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002626 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002627 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002628 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002629 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002630 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002631 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002632 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002633 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002634 return 0;
2635}
2636
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002637static int add_control_with_pfx(struct alc_spec *spec, int type,
2638 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002639 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002640{
2641 char name[32];
2642 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002643 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002644}
2645
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002646#define add_pb_vol_ctrl(spec, type, pfx, val) \
2647 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2648#define add_pb_sw_ctrl(spec, type, pfx, val) \
2649 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2650#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2651 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2652#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2653 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002654
Takashi Iwai23c09b02011-08-19 09:05:35 +02002655static const char * const channel_name[4] = {
2656 "Front", "Surround", "CLFE", "Side"
2657};
2658
Takashi Iwai6843ca12011-06-24 11:03:58 +02002659static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2660 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002661{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002662 struct auto_pin_cfg *cfg = &spec->autocfg;
2663
Takashi Iwai6843ca12011-06-24 11:03:58 +02002664 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002665 if (cfg->line_outs == 1 && !spec->multi_ios &&
2666 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002667 return "Master";
2668
2669 switch (cfg->line_out_type) {
2670 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002671 if (cfg->line_outs == 1)
2672 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002673 if (cfg->line_outs == 2)
2674 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002675 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002676 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002677 /* for multi-io case, only the primary out */
2678 if (ch && spec->multi_ios)
2679 break;
2680 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002681 return "Headphone";
2682 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002683 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002684 return "PCM";
2685 break;
2686 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002687 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2688 return "PCM";
2689
2690 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002691}
2692
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002693/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002694static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002695 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002696 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002697{
Kailang Yangdf694da2005-12-05 19:42:22 +01002698 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002699
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002700 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002701 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2702 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002703 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002704 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002705 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2706 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002707 return err;
2708 return 0;
2709}
2710
Takashi Iwai05f5f472009-08-25 13:10:18 +02002711static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002712{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002713 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2714 return (pincap & AC_PINCAP_IN) != 0;
2715}
2716
Takashi Iwai1d045db2011-07-07 18:23:21 +02002717/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002718static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002719{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002720 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002721 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002722 hda_nid_t *adc_nids = spec->private_adc_nids;
2723 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2724 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002725 int i, nums = 0;
2726
Takashi Iwai24de1832011-11-07 17:13:39 +01002727 if (spec->shared_mic_hp)
2728 max_nums = 1; /* no multi streams with the shared HP/mic */
2729
Takashi Iwaib7821702011-07-06 15:12:46 +02002730 nid = codec->start_nid;
2731 for (i = 0; i < codec->num_nodes; i++, nid++) {
2732 hda_nid_t src;
2733 const hda_nid_t *list;
2734 unsigned int caps = get_wcaps(codec, nid);
2735 int type = get_wcaps_type(caps);
2736
2737 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2738 continue;
2739 adc_nids[nums] = nid;
2740 cap_nids[nums] = nid;
2741 src = nid;
2742 for (;;) {
2743 int n;
2744 type = get_wcaps_type(get_wcaps(codec, src));
2745 if (type == AC_WID_PIN)
2746 break;
2747 if (type == AC_WID_AUD_SEL) {
2748 cap_nids[nums] = src;
2749 break;
2750 }
2751 n = snd_hda_get_conn_list(codec, src, &list);
2752 if (n > 1) {
2753 cap_nids[nums] = src;
2754 break;
2755 } else if (n != 1)
2756 break;
2757 src = *list;
2758 }
2759 if (++nums >= max_nums)
2760 break;
2761 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002762 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002763 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002764 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002765 return nums;
2766}
2767
Takashi Iwai05f5f472009-08-25 13:10:18 +02002768/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002769static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002770{
2771 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002772 const struct auto_pin_cfg *cfg = &spec->autocfg;
2773 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002774 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002775 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002776 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002777 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002778
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002779 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002780 if (num_adcs < 0)
2781 return 0;
2782
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002783 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002784 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002785 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002786
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002787 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002788 if (!alc_is_input_pin(codec, pin))
2789 continue;
2790
David Henningsson5322bf22011-01-05 11:03:56 +01002791 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002792 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2793 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002794 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002795 type_idx++;
2796 else
2797 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002798 prev_label = label;
2799
Takashi Iwai05f5f472009-08-25 13:10:18 +02002800 if (mixer) {
2801 idx = get_connection_index(codec, mixer, pin);
2802 if (idx >= 0) {
2803 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002804 label, type_idx,
2805 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002806 if (err < 0)
2807 return err;
2808 }
2809 }
2810
Takashi Iwaib7821702011-07-06 15:12:46 +02002811 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002812 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002813 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002814 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002815 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002816 snd_hda_add_imux_item(imux, label, idx, NULL);
2817 break;
2818 }
2819 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002820 }
Takashi Iwai21268962011-07-07 15:01:13 +02002821
2822 spec->num_mux_defs = 1;
2823 spec->input_mux = imux;
2824
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002825 return 0;
2826}
2827
Takashi Iwai24de1832011-11-07 17:13:39 +01002828/* create a shared input with the headphone out */
2829static int alc_auto_create_shared_input(struct hda_codec *codec)
2830{
2831 struct alc_spec *spec = codec->spec;
2832 struct auto_pin_cfg *cfg = &spec->autocfg;
2833 unsigned int defcfg;
2834 hda_nid_t nid;
2835
2836 /* only one internal input pin? */
2837 if (cfg->num_inputs != 1)
2838 return 0;
2839 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2840 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2841 return 0;
2842
2843 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2844 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2845 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2846 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2847 else
2848 return 0; /* both not available */
2849
2850 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2851 return 0; /* no input */
2852
2853 cfg->inputs[1].pin = nid;
2854 cfg->inputs[1].type = AUTO_PIN_MIC;
2855 cfg->num_inputs = 2;
2856 spec->shared_mic_hp = 1;
2857 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2858 return 0;
2859}
2860
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002861static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2862 unsigned int pin_type)
2863{
2864 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2865 pin_type);
2866 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002867 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2868 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002869 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002870}
2871
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002872static int get_pin_type(int line_out_type)
2873{
2874 if (line_out_type == AUTO_PIN_HP_OUT)
2875 return PIN_HP;
2876 else
2877 return PIN_OUT;
2878}
2879
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002880static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002881{
2882 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002883 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002884 int i;
2885
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002886 for (i = 0; i < cfg->num_inputs; i++) {
2887 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002888 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002889 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002890 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002891 snd_hda_codec_write(codec, nid, 0,
2892 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002893 AMP_OUT_MUTE);
2894 }
2895 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002896
2897 /* mute all loopback inputs */
2898 if (spec->mixer_nid) {
2899 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2900 for (i = 0; i < nums; i++)
2901 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2902 AC_VERB_SET_AMP_GAIN_MUTE,
2903 AMP_IN_MUTE(i));
2904 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002905}
2906
Takashi Iwai7085ec12009-10-02 09:03:58 +02002907/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002908static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002909{
Takashi Iwai604401a2011-04-27 15:14:23 +02002910 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002911 int i, num;
2912
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002913 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2914 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002915 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2916 for (i = 0; i < num; i++) {
2917 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2918 return list[i];
2919 }
2920 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002921}
2922
Takashi Iwai604401a2011-04-27 15:14:23 +02002923/* go down to the selector widget before the mixer */
2924static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2925{
2926 hda_nid_t srcs[5];
2927 int num = snd_hda_get_connections(codec, pin, srcs,
2928 ARRAY_SIZE(srcs));
2929 if (num != 1 ||
2930 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2931 return pin;
2932 return srcs[0];
2933}
2934
Takashi Iwai7085ec12009-10-02 09:03:58 +02002935/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002936static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002937 hda_nid_t dac)
2938{
David Henningssoncc1c4522010-11-24 14:17:47 +01002939 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002940 int i, num;
2941
Takashi Iwai604401a2011-04-27 15:14:23 +02002942 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002943 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2944 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002945 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002946 return mix[i];
2947 }
2948 return 0;
2949}
2950
Takashi Iwaice764ab2011-04-27 16:35:23 +02002951/* select the connection from pin to DAC if needed */
2952static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2953 hda_nid_t dac)
2954{
2955 hda_nid_t mix[5];
2956 int i, num;
2957
2958 pin = alc_go_down_to_selector(codec, pin);
2959 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2960 if (num < 2)
2961 return 0;
2962 for (i = 0; i < num; i++) {
2963 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2964 snd_hda_codec_update_cache(codec, pin, 0,
2965 AC_VERB_SET_CONNECT_SEL, i);
2966 return 0;
2967 }
2968 }
2969 return 0;
2970}
2971
Takashi Iwai185d99f2012-02-16 18:39:45 +01002972static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2973{
2974 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002975 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002976 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2977 ARRAY_SIZE(spec->private_dac_nids)) ||
2978 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2979 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2980 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2981 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2982 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002983 for (i = 0; i < spec->multi_ios; i++) {
2984 if (spec->multi_io[i].dac == nid)
2985 return true;
2986 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002987 return false;
2988}
2989
Takashi Iwai7085ec12009-10-02 09:03:58 +02002990/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002991static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002992{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002993 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002994 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002995
Takashi Iwai604401a2011-04-27 15:14:23 +02002996 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002997 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002998 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002999 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003000 if (!nid)
3001 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003002 if (!alc_is_dac_already_used(codec, nid))
3003 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003004 }
3005 return 0;
3006}
3007
Takashi Iwai07b18f62011-11-10 15:42:54 +01003008/* check whether the DAC is reachable from the pin */
3009static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
3010 hda_nid_t pin, hda_nid_t dac)
3011{
3012 hda_nid_t srcs[5];
3013 int i, num;
3014
Takashi Iwaidc31b582012-02-17 17:27:53 +01003015 if (!pin || !dac)
3016 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003017 pin = alc_go_down_to_selector(codec, pin);
3018 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
3019 for (i = 0; i < num; i++) {
3020 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3021 if (nid == dac)
3022 return true;
3023 }
3024 return false;
3025}
3026
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003027static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3028{
Takashi Iwai140547e2012-02-16 17:23:46 +01003029 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003030 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003031 hda_nid_t nid, nid_found, srcs[5];
3032 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01003033 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01003034 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003035 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003036 nid_found = 0;
3037 for (i = 0; i < num; i++) {
3038 if (srcs[i] == spec->mixer_nid)
3039 continue;
3040 nid = alc_auto_mix_to_dac(codec, srcs[i]);
3041 if (nid && !alc_is_dac_already_used(codec, nid)) {
3042 if (nid_found)
3043 return 0;
3044 nid_found = nid;
3045 }
3046 }
3047 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003048}
3049
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003050/* mark up volume and mute control NIDs: used during badness parsing and
3051 * at creating actual controls
3052 */
3053static inline unsigned int get_ctl_pos(unsigned int data)
3054{
3055 hda_nid_t nid = get_amp_nid_(data);
3056 unsigned int dir;
3057 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3058 return 0;
3059 dir = get_amp_direction_(data);
3060 return (nid << 1) | dir;
3061}
3062
3063#define is_ctl_used(bits, data) \
3064 test_bit(get_ctl_pos(data), bits)
3065#define mark_ctl_usage(bits, data) \
3066 set_bit(get_ctl_pos(data), bits)
3067
3068static void clear_vol_marks(struct hda_codec *codec)
3069{
3070 struct alc_spec *spec = codec->spec;
3071 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3072 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3073}
3074
3075/* badness definition */
3076enum {
3077 /* No primary DAC is found for the main output */
3078 BAD_NO_PRIMARY_DAC = 0x10000,
3079 /* No DAC is found for the extra output */
3080 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003081 /* No possible multi-ios */
3082 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003083 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003084 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003085 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003086 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003087 /* Primary DAC shared with main surrounds */
3088 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003089 /* Primary DAC shared with main CLFE */
3090 BAD_SHARED_CLFE = 0x10,
3091 /* Primary DAC shared with extra surrounds */
3092 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003093 /* Volume widget is shared */
3094 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003095};
3096
3097static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3098 hda_nid_t pin, hda_nid_t dac);
3099static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3100 hda_nid_t pin, hda_nid_t dac);
3101
3102static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3103 hda_nid_t dac)
3104{
3105 struct alc_spec *spec = codec->spec;
3106 hda_nid_t nid;
3107 unsigned int val;
3108 int badness = 0;
3109
3110 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3111 if (nid) {
3112 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3113 if (is_ctl_used(spec->vol_ctls, nid))
3114 badness += BAD_SHARED_VOL;
3115 else
3116 mark_ctl_usage(spec->vol_ctls, val);
3117 } else
3118 badness += BAD_SHARED_VOL;
3119 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3120 if (nid) {
3121 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3122 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3123 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3124 else
3125 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3126 if (is_ctl_used(spec->sw_ctls, val))
3127 badness += BAD_SHARED_VOL;
3128 else
3129 mark_ctl_usage(spec->sw_ctls, val);
3130 } else
3131 badness += BAD_SHARED_VOL;
3132 return badness;
3133}
3134
Takashi Iwaidc31b582012-02-17 17:27:53 +01003135struct badness_table {
3136 int no_primary_dac; /* no primary DAC */
3137 int no_dac; /* no secondary DACs */
3138 int shared_primary; /* primary DAC is shared with main output */
3139 int shared_surr; /* secondary DAC shared with main or primary */
3140 int shared_clfe; /* third DAC shared with main or primary */
3141 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3142};
3143
3144static struct badness_table main_out_badness = {
3145 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3146 .no_dac = BAD_NO_DAC,
3147 .shared_primary = BAD_NO_PRIMARY_DAC,
3148 .shared_surr = BAD_SHARED_SURROUND,
3149 .shared_clfe = BAD_SHARED_CLFE,
3150 .shared_surr_main = BAD_SHARED_SURROUND,
3151};
3152
3153static struct badness_table extra_out_badness = {
3154 .no_primary_dac = BAD_NO_DAC,
3155 .no_dac = BAD_NO_DAC,
3156 .shared_primary = BAD_NO_EXTRA_DAC,
3157 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3158 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3159 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3160};
3161
3162/* try to assign DACs to pins and return the resultant badness */
3163static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3164 const hda_nid_t *pins, hda_nid_t *dacs,
3165 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003166{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003167 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003168 struct auto_pin_cfg *cfg = &spec->autocfg;
3169 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003170 int badness = 0;
3171 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003172
Takashi Iwai185d99f2012-02-16 18:39:45 +01003173 if (!num_outs)
3174 return 0;
3175
Takashi Iwaidc31b582012-02-17 17:27:53 +01003176 for (i = 0; i < num_outs; i++) {
3177 hda_nid_t pin = pins[i];
3178 if (!dacs[i])
3179 dacs[i] = alc_auto_look_for_dac(codec, pin);
3180 if (!dacs[i] && !i) {
3181 for (j = 1; j < num_outs; j++) {
3182 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3183 dacs[0] = dacs[j];
3184 dacs[j] = 0;
3185 break;
3186 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003187 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003188 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003189 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003190 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003191 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003192 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003193 else if (cfg->line_outs > i &&
3194 alc_auto_is_dac_reachable(codec, pin,
3195 spec->private_dac_nids[i]))
3196 dac = spec->private_dac_nids[i];
3197 if (dac) {
3198 if (!i)
3199 badness += bad->shared_primary;
3200 else if (i == 1)
3201 badness += bad->shared_surr;
3202 else
3203 badness += bad->shared_clfe;
3204 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003205 spec->private_dac_nids[0])) {
3206 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003207 badness += bad->shared_surr_main;
3208 } else if (!i)
3209 badness += bad->no_primary_dac;
3210 else
3211 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003212 }
3213 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003214 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003215 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003216
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003217 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003218}
3219
3220static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003221 hda_nid_t reference_pin,
3222 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003223
Takashi Iwai185d99f2012-02-16 18:39:45 +01003224static bool alc_map_singles(struct hda_codec *codec, int outs,
3225 const hda_nid_t *pins, hda_nid_t *dacs)
3226{
3227 int i;
3228 bool found = false;
3229 for (i = 0; i < outs; i++) {
3230 if (dacs[i])
3231 continue;
3232 dacs[i] = get_dac_if_single(codec, pins[i]);
3233 if (dacs[i])
3234 found = true;
3235 }
3236 return found;
3237}
3238
Takashi Iwai7085ec12009-10-02 09:03:58 +02003239/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003240static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003241 bool fill_hardwired,
3242 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003243{
3244 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003245 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003246 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003247
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003248 /* set num_dacs once to full for alc_auto_look_for_dac() */
3249 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003250 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003251 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3252 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3253 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003254 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003255 clear_vol_marks(codec);
3256 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003257
3258 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003259 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003260 bool mapped;
3261 do {
3262 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003263 cfg->line_out_pins,
3264 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003265 mapped |= alc_map_singles(codec, cfg->hp_outs,
3266 cfg->hp_pins,
3267 spec->multiout.hp_out_nid);
3268 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3269 cfg->speaker_pins,
3270 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003271 if (fill_mio_first && cfg->line_outs == 1 &&
3272 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3273 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3274 if (!err)
3275 mapped = true;
3276 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003277 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003278 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003279
Takashi Iwaidc31b582012-02-17 17:27:53 +01003280 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3281 spec->private_dac_nids,
3282 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003283
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003284 /* re-count num_dacs and squash invalid entries */
3285 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003286 for (i = 0; i < cfg->line_outs; i++) {
3287 if (spec->private_dac_nids[i])
3288 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003289 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003290 memmove(spec->private_dac_nids + i,
3291 spec->private_dac_nids + i + 1,
3292 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003293 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3294 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003295 }
3296
Takashi Iwai276dd702012-02-17 16:17:03 +01003297 if (fill_mio_first &&
3298 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003299 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003300 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003301 if (err < 0)
3302 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003303 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003304 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003305
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003306 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003307 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3308 spec->multiout.hp_out_nid,
3309 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003310 if (err < 0)
3311 return err;
3312 badness += err;
3313 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003314 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003315 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3316 cfg->speaker_pins,
3317 spec->multiout.extra_out_nid,
3318 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003319 if (err < 0)
3320 return err;
3321 badness += err;
3322 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003323 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3324 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003325 if (err < 0)
3326 return err;
3327 badness += err;
3328 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003329 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3330 /* try multi-ios with HP + inputs */
3331 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, 1);
3332 if (err < 0)
3333 return err;
3334 badness += err;
3335 }
3336
3337 if (spec->multi_ios == 2) {
3338 for (i = 0; i < 2; i++)
3339 spec->private_dac_nids[spec->multiout.num_dacs++] =
3340 spec->multi_io[i].dac;
3341 spec->ext_channel_count = 2;
3342 } else if (spec->multi_ios) {
3343 spec->multi_ios = 0;
3344 badness += BAD_MULTI_IO;
3345 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003346
3347 return badness;
3348}
3349
3350#define DEBUG_BADNESS
3351
3352#ifdef DEBUG_BADNESS
3353#define debug_badness snd_printdd
3354#else
3355#define debug_badness(...)
3356#endif
3357
3358static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3359{
3360 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3361 cfg->line_out_pins[0], cfg->line_out_pins[1],
3362 cfg->line_out_pins[2], cfg->line_out_pins[2],
3363 spec->multiout.dac_nids[0],
3364 spec->multiout.dac_nids[1],
3365 spec->multiout.dac_nids[2],
3366 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003367 if (spec->multi_ios > 0)
3368 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3369 spec->multi_ios,
3370 spec->multi_io[0].pin, spec->multi_io[1].pin,
3371 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003372 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3373 cfg->hp_pins[0], cfg->hp_pins[1],
3374 cfg->hp_pins[2], cfg->hp_pins[2],
3375 spec->multiout.hp_out_nid[0],
3376 spec->multiout.hp_out_nid[1],
3377 spec->multiout.hp_out_nid[2],
3378 spec->multiout.hp_out_nid[3]);
3379 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3380 cfg->speaker_pins[0], cfg->speaker_pins[1],
3381 cfg->speaker_pins[2], cfg->speaker_pins[3],
3382 spec->multiout.extra_out_nid[0],
3383 spec->multiout.extra_out_nid[1],
3384 spec->multiout.extra_out_nid[2],
3385 spec->multiout.extra_out_nid[3]);
3386}
3387
3388static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3389{
3390 struct alc_spec *spec = codec->spec;
3391 struct auto_pin_cfg *cfg = &spec->autocfg;
3392 struct auto_pin_cfg *best_cfg;
3393 int best_badness = INT_MAX;
3394 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003395 bool fill_hardwired = true, fill_mio_first = true;
3396 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003397 bool hp_spk_swapped = false;
3398
3399 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3400 if (!best_cfg)
3401 return -ENOMEM;
3402 *best_cfg = *cfg;
3403
3404 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003405 badness = fill_and_eval_dacs(codec, fill_hardwired,
3406 fill_mio_first);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003407 if (badness < 0)
3408 return badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003409 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3410 cfg->line_out_type, fill_hardwired, fill_mio_first,
3411 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003412 debug_show_configs(spec, cfg);
3413 if (badness < best_badness) {
3414 best_badness = badness;
3415 *best_cfg = *cfg;
3416 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003417 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003418 }
3419 if (!badness)
3420 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003421 fill_mio_first = !fill_mio_first;
3422 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003423 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003424 fill_hardwired = !fill_hardwired;
3425 if (!fill_hardwired)
3426 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003427 if (hp_spk_swapped)
3428 break;
3429 hp_spk_swapped = true;
3430 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003431 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3432 cfg->hp_outs = cfg->line_outs;
3433 memcpy(cfg->hp_pins, cfg->line_out_pins,
3434 sizeof(cfg->hp_pins));
3435 cfg->line_outs = cfg->speaker_outs;
3436 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3437 sizeof(cfg->speaker_pins));
3438 cfg->speaker_outs = 0;
3439 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3440 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003441 fill_hardwired = true;
3442 continue;
3443 }
3444 if (cfg->hp_outs > 0 &&
3445 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3446 cfg->speaker_outs = cfg->line_outs;
3447 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3448 sizeof(cfg->speaker_pins));
3449 cfg->line_outs = cfg->hp_outs;
3450 memcpy(cfg->line_out_pins, cfg->hp_pins,
3451 sizeof(cfg->hp_pins));
3452 cfg->hp_outs = 0;
3453 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3454 cfg->line_out_type = AUTO_PIN_HP_OUT;
3455 fill_hardwired = true;
3456 continue;
3457 }
3458 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003459 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003460
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003461 if (badness) {
3462 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003463 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003464 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003465 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3466 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003467 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003468
David Henningssonfde48a12011-12-09 18:27:42 +08003469 if (cfg->line_out_pins[0])
3470 spec->vmaster_nid =
3471 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3472 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003473
3474 /* clear the bitmap flags for creating controls */
3475 clear_vol_marks(codec);
3476 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003477 return 0;
3478}
3479
Takashi Iwai343a04b2011-07-06 14:28:39 +02003480static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003481 const char *pfx, int cidx,
3482 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003483{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003484 struct alc_spec *spec = codec->spec;
3485 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003486 if (!nid)
3487 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003488 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3489 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3490 return 0;
3491 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003492 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003493 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003494}
3495
Takashi Iwaie29d3772011-11-14 17:13:23 +01003496static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3497 const char *pfx, int cidx,
3498 hda_nid_t nid)
3499{
3500 int chs = 1;
3501 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3502 chs = 3;
3503 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3504}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003505
3506/* create a mute-switch for the given mixer widget;
3507 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3508 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003509static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003510 const char *pfx, int cidx,
3511 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003512{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003513 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003514 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003515 int type;
3516 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003517 if (!nid)
3518 return 0;
3519 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3520 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3521 type = ALC_CTL_WIDGET_MUTE;
3522 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3523 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003524 type = ALC_CTL_WIDGET_MUTE;
3525 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3526 } else {
3527 type = ALC_CTL_BIND_MUTE;
3528 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3529 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003530 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3531 return 0;
3532 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003533 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003534}
3535
Takashi Iwaie29d3772011-11-14 17:13:23 +01003536static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3537 int cidx, hda_nid_t nid)
3538{
3539 int chs = 1;
3540 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3541 chs = 3;
3542 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3543}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003544
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003545static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3546 hda_nid_t pin, hda_nid_t dac)
3547{
3548 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3549 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3550 return pin;
3551 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3552 return mix;
3553 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3554 return dac;
3555 return 0;
3556}
3557
3558static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3559 hda_nid_t pin, hda_nid_t dac)
3560{
3561 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3562 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3563 return dac;
3564 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3565 return mix;
3566 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3567 return pin;
3568 return 0;
3569}
3570
Takashi Iwai7085ec12009-10-02 09:03:58 +02003571/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003572static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003573 const struct auto_pin_cfg *cfg)
3574{
3575 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003576 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003577
Takashi Iwaice764ab2011-04-27 16:35:23 +02003578 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003579 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003580 noutputs += spec->multi_ios;
3581
3582 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003583 const char *name;
3584 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003585 hda_nid_t dac, pin;
3586 hda_nid_t sw, vol;
3587
3588 dac = spec->multiout.dac_nids[i];
3589 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003590 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003591 if (i >= cfg->line_outs)
3592 pin = spec->multi_io[i - 1].pin;
3593 else
3594 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003595
3596 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3597 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003598 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003599 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003600 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003601 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003602 if (err < 0)
3603 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003604 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003605 if (err < 0)
3606 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003607 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003608 if (err < 0)
3609 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003610 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003611 if (err < 0)
3612 return err;
3613 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003614 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003615 if (err < 0)
3616 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003617 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003618 if (err < 0)
3619 return err;
3620 }
3621 }
3622 return 0;
3623}
3624
Takashi Iwai343a04b2011-07-06 14:28:39 +02003625static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003626 hda_nid_t dac, const char *pfx,
3627 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003628{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003629 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003630 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003631 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003632
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003633 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003634 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003635 /* the corresponding DAC is already occupied */
3636 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3637 return 0; /* no way */
3638 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003639 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3640 if (is_ctl_used(spec->sw_ctls, val))
3641 return 0; /* already created */
3642 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003643 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003644 }
3645
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003646 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3647 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003648 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003649 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003650 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003651 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003652 if (err < 0)
3653 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003654 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003655}
3656
Takashi Iwai23c09b02011-08-19 09:05:35 +02003657static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3658 unsigned int nums,
3659 struct hda_ctl_ops *ops)
3660{
3661 struct alc_spec *spec = codec->spec;
3662 struct hda_bind_ctls **ctlp, *ctl;
3663 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3664 ctlp = snd_array_new(&spec->bind_ctls);
3665 if (!ctlp)
3666 return NULL;
3667 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3668 *ctlp = ctl;
3669 if (ctl)
3670 ctl->ops = ops;
3671 return ctl;
3672}
3673
3674/* add playback controls for speaker and HP outputs */
3675static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3676 const hda_nid_t *pins,
3677 const hda_nid_t *dacs,
3678 const char *pfx)
3679{
3680 struct alc_spec *spec = codec->spec;
3681 struct hda_bind_ctls *ctl;
3682 char name[32];
3683 int i, n, err;
3684
3685 if (!num_pins || !pins[0])
3686 return 0;
3687
Takashi Iwai527e4d72011-10-27 16:33:27 +02003688 if (num_pins == 1) {
3689 hda_nid_t dac = *dacs;
3690 if (!dac)
3691 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003692 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003693 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003694
3695 if (dacs[num_pins - 1]) {
3696 /* OK, we have a multi-output system with individual volumes */
3697 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003698 if (num_pins >= 3) {
3699 snprintf(name, sizeof(name), "%s %s",
3700 pfx, channel_name[i]);
3701 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3702 name, 0);
3703 } else {
3704 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3705 pfx, i);
3706 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003707 if (err < 0)
3708 return err;
3709 }
3710 return 0;
3711 }
3712
3713 /* Let's create a bind-controls */
3714 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3715 if (!ctl)
3716 return -ENOMEM;
3717 n = 0;
3718 for (i = 0; i < num_pins; i++) {
3719 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3720 ctl->values[n++] =
3721 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3722 }
3723 if (n) {
3724 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3725 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3726 if (err < 0)
3727 return err;
3728 }
3729
3730 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3731 if (!ctl)
3732 return -ENOMEM;
3733 n = 0;
3734 for (i = 0; i < num_pins; i++) {
3735 hda_nid_t vol;
3736 if (!pins[i] || !dacs[i])
3737 continue;
3738 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3739 if (vol)
3740 ctl->values[n++] =
3741 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3742 }
3743 if (n) {
3744 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3745 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3746 if (err < 0)
3747 return err;
3748 }
3749 return 0;
3750}
3751
Takashi Iwai343a04b2011-07-06 14:28:39 +02003752static int alc_auto_create_hp_out(struct hda_codec *codec)
3753{
3754 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003755 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3756 spec->autocfg.hp_pins,
3757 spec->multiout.hp_out_nid,
3758 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003759}
3760
3761static int alc_auto_create_speaker_out(struct hda_codec *codec)
3762{
3763 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003764 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3765 spec->autocfg.speaker_pins,
3766 spec->multiout.extra_out_nid,
3767 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003768}
3769
Takashi Iwai343a04b2011-07-06 14:28:39 +02003770static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003771 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003772 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003773{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003774 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003775 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003776 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003777
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003778 alc_set_pin_output(codec, pin, pin_type);
3779 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003780 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003781 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003782 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003783 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003784 mix = srcs[i];
3785 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003786 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003787 if (!mix)
3788 return;
3789
3790 /* need the manual connection? */
3791 if (num > 1)
3792 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3793 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003794 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3795 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003796 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003797 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003798 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003799 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003800 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003801 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3802 if (nid)
3803 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3804 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003805
3806 /* unmute DAC if it's not assigned to a mixer */
3807 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3808 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3809 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3810 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003811}
3812
Takashi Iwai343a04b2011-07-06 14:28:39 +02003813static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003814{
3815 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003816 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003817 int i;
3818
3819 for (i = 0; i <= HDA_SIDE; i++) {
3820 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3821 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003822 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003823 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003824 }
3825}
3826
Takashi Iwai343a04b2011-07-06 14:28:39 +02003827static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003828{
3829 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003830 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003831 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003832
David Henningsson636030e2011-10-12 19:26:03 +02003833 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003834 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3835 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003836 pin = spec->autocfg.hp_pins[i];
3837 if (!pin)
3838 break;
3839 dac = spec->multiout.hp_out_nid[i];
3840 if (!dac) {
3841 if (i > 0 && spec->multiout.hp_out_nid[0])
3842 dac = spec->multiout.hp_out_nid[0];
3843 else
3844 dac = spec->multiout.dac_nids[0];
3845 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003846 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3847 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003848 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003849 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3850 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003851 pin = spec->autocfg.speaker_pins[i];
3852 if (!pin)
3853 break;
3854 dac = spec->multiout.extra_out_nid[i];
3855 if (!dac) {
3856 if (i > 0 && spec->multiout.extra_out_nid[0])
3857 dac = spec->multiout.extra_out_nid[0];
3858 else
3859 dac = spec->multiout.dac_nids[0];
3860 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003861 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3862 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003863}
3864
Takashi Iwai276dd702012-02-17 16:17:03 +01003865/* check whether the given pin can be a multi-io pin */
3866static bool can_be_multiio_pin(struct hda_codec *codec,
3867 unsigned int location, hda_nid_t nid)
3868{
3869 unsigned int defcfg, caps;
3870
3871 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3872 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3873 return false;
3874 if (location && get_defcfg_location(defcfg) != location)
3875 return false;
3876 caps = snd_hda_query_pin_caps(codec, nid);
3877 if (!(caps & AC_PINCAP_OUT))
3878 return false;
3879 return true;
3880}
3881
Takashi Iwaice764ab2011-04-27 16:35:23 +02003882/*
3883 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003884 *
3885 * When hardwired is set, try to fill ony hardwired pins, and returns
3886 * zero if any pins are filled, non-zero if nothing found.
3887 * When hardwired is off, try to fill possible input pins, and returns
3888 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003889 */
3890static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003891 hda_nid_t reference_pin,
3892 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003893{
3894 struct alc_spec *spec = codec->spec;
3895 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003896 int type, i, j, dacs, num_pins, old_pins;
3897 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3898 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003899 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003900
Takashi Iwai276dd702012-02-17 16:17:03 +01003901 old_pins = spec->multi_ios;
3902 if (old_pins >= 2)
3903 goto end_fill;
3904
3905 num_pins = 0;
3906 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3907 for (i = 0; i < cfg->num_inputs; i++) {
3908 if (cfg->inputs[i].type != type)
3909 continue;
3910 if (can_be_multiio_pin(codec, location,
3911 cfg->inputs[i].pin))
3912 num_pins++;
3913 }
3914 }
3915 if (num_pins < 2)
3916 goto end_fill;
3917
Takashi Iwai07b18f62011-11-10 15:42:54 +01003918 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003919 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3920 for (i = 0; i < cfg->num_inputs; i++) {
3921 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003922 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003923
Takashi Iwaice764ab2011-04-27 16:35:23 +02003924 if (cfg->inputs[i].type != type)
3925 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003926 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003927 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003928 for (j = 0; j < spec->multi_ios; j++) {
3929 if (nid == spec->multi_io[j].pin)
3930 break;
3931 }
3932 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003933 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003934
3935 if (offset && offset + spec->multi_ios < dacs) {
3936 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003937 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3938 dac = 0;
3939 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003940 if (hardwired)
3941 dac = get_dac_if_single(codec, nid);
3942 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003943 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003944 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003945 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003946 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003947 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003948 spec->multi_io[spec->multi_ios].pin = nid;
3949 spec->multi_io[spec->multi_ios].dac = dac;
3950 spec->multi_ios++;
3951 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003952 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003953 }
3954 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003955 end_fill:
3956 if (badness)
3957 badness = BAD_MULTI_IO;
3958 if (old_pins == spec->multi_ios) {
3959 if (hardwired)
3960 return 1; /* nothing found */
3961 else
3962 return badness; /* no badness if nothing found */
3963 }
3964 if (!hardwired && spec->multi_ios < 2) {
3965 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003966 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003967 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003968
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003969 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003970}
3971
3972static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3973 struct snd_ctl_elem_info *uinfo)
3974{
3975 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3976 struct alc_spec *spec = codec->spec;
3977
3978 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3979 uinfo->count = 1;
3980 uinfo->value.enumerated.items = spec->multi_ios + 1;
3981 if (uinfo->value.enumerated.item > spec->multi_ios)
3982 uinfo->value.enumerated.item = spec->multi_ios;
3983 sprintf(uinfo->value.enumerated.name, "%dch",
3984 (uinfo->value.enumerated.item + 1) * 2);
3985 return 0;
3986}
3987
3988static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3989 struct snd_ctl_elem_value *ucontrol)
3990{
3991 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3992 struct alc_spec *spec = codec->spec;
3993 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3994 return 0;
3995}
3996
3997static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3998{
3999 struct alc_spec *spec = codec->spec;
4000 hda_nid_t nid = spec->multi_io[idx].pin;
4001
4002 if (!spec->multi_io[idx].ctl_in)
4003 spec->multi_io[idx].ctl_in =
4004 snd_hda_codec_read(codec, nid, 0,
4005 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4006 if (output) {
4007 snd_hda_codec_update_cache(codec, nid, 0,
4008 AC_VERB_SET_PIN_WIDGET_CONTROL,
4009 PIN_OUT);
4010 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4011 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4012 HDA_AMP_MUTE, 0);
4013 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
4014 } else {
4015 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4016 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4017 HDA_AMP_MUTE, HDA_AMP_MUTE);
4018 snd_hda_codec_update_cache(codec, nid, 0,
4019 AC_VERB_SET_PIN_WIDGET_CONTROL,
4020 spec->multi_io[idx].ctl_in);
4021 }
4022 return 0;
4023}
4024
4025static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4026 struct snd_ctl_elem_value *ucontrol)
4027{
4028 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4029 struct alc_spec *spec = codec->spec;
4030 int i, ch;
4031
4032 ch = ucontrol->value.enumerated.item[0];
4033 if (ch < 0 || ch > spec->multi_ios)
4034 return -EINVAL;
4035 if (ch == (spec->ext_channel_count - 1) / 2)
4036 return 0;
4037 spec->ext_channel_count = (ch + 1) * 2;
4038 for (i = 0; i < spec->multi_ios; i++)
4039 alc_set_multi_io(codec, i, i < ch);
4040 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004041 if (spec->need_dac_fix && !spec->const_channel_count)
4042 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004043 return 1;
4044}
4045
Takashi Iwaia9111322011-05-02 11:30:18 +02004046static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004047 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4048 .name = "Channel Mode",
4049 .info = alc_auto_ch_mode_info,
4050 .get = alc_auto_ch_mode_get,
4051 .put = alc_auto_ch_mode_put,
4052};
4053
Takashi Iwai23c09b02011-08-19 09:05:35 +02004054static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004055{
4056 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004057
Takashi Iwaic2674682011-08-24 17:57:44 +02004058 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004059 struct snd_kcontrol_new *knew;
4060
4061 knew = alc_kcontrol_new(spec);
4062 if (!knew)
4063 return -ENOMEM;
4064 *knew = alc_auto_channel_mode_enum;
4065 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4066 if (!knew->name)
4067 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004068 }
4069 return 0;
4070}
4071
Takashi Iwai1d045db2011-07-07 18:23:21 +02004072/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4073 * active input pins
4074 */
4075static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4076{
4077 struct alc_spec *spec = codec->spec;
4078 const struct hda_input_mux *imux;
4079 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4080 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4081 int i, n, nums;
4082
4083 imux = spec->input_mux;
4084 if (!imux)
4085 return;
4086 if (spec->dyn_adc_switch)
4087 return;
4088
4089 nums = 0;
4090 for (n = 0; n < spec->num_adc_nids; n++) {
4091 hda_nid_t cap = spec->private_capsrc_nids[n];
4092 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4093 for (i = 0; i < imux->num_items; i++) {
4094 hda_nid_t pin = spec->imux_pins[i];
4095 if (pin) {
4096 if (get_connection_index(codec, cap, pin) < 0)
4097 break;
4098 } else if (num_conns <= imux->items[i].index)
4099 break;
4100 }
4101 if (i >= imux->num_items) {
4102 adc_nids[nums] = spec->private_adc_nids[n];
4103 capsrc_nids[nums++] = cap;
4104 }
4105 }
4106 if (!nums) {
4107 /* check whether ADC-switch is possible */
4108 if (!alc_check_dyn_adc_switch(codec)) {
4109 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4110 " using fallback 0x%x\n",
4111 codec->chip_name, spec->private_adc_nids[0]);
4112 spec->num_adc_nids = 1;
4113 spec->auto_mic = 0;
4114 return;
4115 }
4116 } else if (nums != spec->num_adc_nids) {
4117 memcpy(spec->private_adc_nids, adc_nids,
4118 nums * sizeof(hda_nid_t));
4119 memcpy(spec->private_capsrc_nids, capsrc_nids,
4120 nums * sizeof(hda_nid_t));
4121 spec->num_adc_nids = nums;
4122 }
4123
4124 if (spec->auto_mic)
4125 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4126 else if (spec->input_mux->num_items == 1)
4127 spec->num_adc_nids = 1; /* reduce to a single ADC */
4128}
4129
4130/*
4131 * initialize ADC paths
4132 */
4133static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4134{
4135 struct alc_spec *spec = codec->spec;
4136 hda_nid_t nid;
4137
4138 nid = spec->adc_nids[adc_idx];
4139 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004140 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004141 snd_hda_codec_write(codec, nid, 0,
4142 AC_VERB_SET_AMP_GAIN_MUTE,
4143 AMP_IN_MUTE(0));
4144 return;
4145 }
4146 if (!spec->capsrc_nids)
4147 return;
4148 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004149 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004150 snd_hda_codec_write(codec, nid, 0,
4151 AC_VERB_SET_AMP_GAIN_MUTE,
4152 AMP_OUT_MUTE);
4153}
4154
4155static void alc_auto_init_input_src(struct hda_codec *codec)
4156{
4157 struct alc_spec *spec = codec->spec;
4158 int c, nums;
4159
4160 for (c = 0; c < spec->num_adc_nids; c++)
4161 alc_auto_init_adc(codec, c);
4162 if (spec->dyn_adc_switch)
4163 nums = 1;
4164 else
4165 nums = spec->num_adc_nids;
4166 for (c = 0; c < nums; c++)
4167 alc_mux_select(codec, 0, spec->cur_mux[c], true);
4168}
4169
4170/* add mic boosts if needed */
4171static int alc_auto_add_mic_boost(struct hda_codec *codec)
4172{
4173 struct alc_spec *spec = codec->spec;
4174 struct auto_pin_cfg *cfg = &spec->autocfg;
4175 int i, err;
4176 int type_idx = 0;
4177 hda_nid_t nid;
4178 const char *prev_label = NULL;
4179
4180 for (i = 0; i < cfg->num_inputs; i++) {
4181 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4182 break;
4183 nid = cfg->inputs[i].pin;
4184 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4185 const char *label;
4186 char boost_label[32];
4187
4188 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004189 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4190 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004191 if (prev_label && !strcmp(label, prev_label))
4192 type_idx++;
4193 else
4194 type_idx = 0;
4195 prev_label = label;
4196
4197 snprintf(boost_label, sizeof(boost_label),
4198 "%s Boost Volume", label);
4199 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4200 boost_label, type_idx,
4201 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4202 if (err < 0)
4203 return err;
4204 }
4205 }
4206 return 0;
4207}
4208
4209/* select or unmute the given capsrc route */
4210static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4211 int idx)
4212{
4213 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4214 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4215 HDA_AMP_MUTE, 0);
4216 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4217 snd_hda_codec_write_cache(codec, cap, 0,
4218 AC_VERB_SET_CONNECT_SEL, idx);
4219 }
4220}
4221
4222/* set the default connection to that pin */
4223static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4224{
4225 struct alc_spec *spec = codec->spec;
4226 int i;
4227
4228 if (!pin)
4229 return 0;
4230 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004231 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004232 int idx;
4233
4234 idx = get_connection_index(codec, cap, pin);
4235 if (idx < 0)
4236 continue;
4237 select_or_unmute_capsrc(codec, cap, idx);
4238 return i; /* return the found index */
4239 }
4240 return -1; /* not found */
4241}
4242
4243/* initialize some special cases for input sources */
4244static void alc_init_special_input_src(struct hda_codec *codec)
4245{
4246 struct alc_spec *spec = codec->spec;
4247 int i;
4248
4249 for (i = 0; i < spec->autocfg.num_inputs; i++)
4250 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4251}
4252
4253/* assign appropriate capture mixers */
4254static void set_capture_mixer(struct hda_codec *codec)
4255{
4256 struct alc_spec *spec = codec->spec;
4257 static const struct snd_kcontrol_new *caps[2][3] = {
4258 { alc_capture_mixer_nosrc1,
4259 alc_capture_mixer_nosrc2,
4260 alc_capture_mixer_nosrc3 },
4261 { alc_capture_mixer1,
4262 alc_capture_mixer2,
4263 alc_capture_mixer3 },
4264 };
4265
4266 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004267 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004268 if (!spec->capsrc_nids)
4269 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004270 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004271 return; /* no volume in capsrc, too */
4272 spec->vol_in_capsrc = 1;
4273 }
4274
4275 if (spec->num_adc_nids > 0) {
4276 int mux = 0;
4277 int num_adcs = 0;
4278
4279 if (spec->input_mux && spec->input_mux->num_items > 1)
4280 mux = 1;
4281 if (spec->auto_mic) {
4282 num_adcs = 1;
4283 mux = 0;
4284 } else if (spec->dyn_adc_switch)
4285 num_adcs = 1;
4286 if (!num_adcs) {
4287 if (spec->num_adc_nids > 3)
4288 spec->num_adc_nids = 3;
4289 else if (!spec->num_adc_nids)
4290 return;
4291 num_adcs = spec->num_adc_nids;
4292 }
4293 spec->cap_mixer = caps[mux][num_adcs - 1];
4294 }
4295}
4296
4297/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004298 * standard auto-parser initializations
4299 */
4300static void alc_auto_init_std(struct hda_codec *codec)
4301{
4302 struct alc_spec *spec = codec->spec;
4303 alc_auto_init_multi_out(codec);
4304 alc_auto_init_extra_out(codec);
4305 alc_auto_init_analog_input(codec);
4306 alc_auto_init_input_src(codec);
4307 alc_auto_init_digital(codec);
4308 if (spec->unsol_event)
4309 alc_inithook(codec);
4310}
4311
4312/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004313 * Digital-beep handlers
4314 */
4315#ifdef CONFIG_SND_HDA_INPUT_BEEP
4316#define set_beep_amp(spec, nid, idx, dir) \
4317 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4318
4319static const struct snd_pci_quirk beep_white_list[] = {
4320 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4321 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4322 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4323 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4324 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4325 {}
4326};
4327
4328static inline int has_cdefine_beep(struct hda_codec *codec)
4329{
4330 struct alc_spec *spec = codec->spec;
4331 const struct snd_pci_quirk *q;
4332 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4333 if (q)
4334 return q->value;
4335 return spec->cdefine.enable_pcbeep;
4336}
4337#else
4338#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4339#define has_cdefine_beep(codec) 0
4340#endif
4341
4342/* parse the BIOS configuration and set up the alc_spec */
4343/* return 1 if successful, 0 if the proper config is not found,
4344 * or a negative error code
4345 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004346static int alc_parse_auto_config(struct hda_codec *codec,
4347 const hda_nid_t *ignore_nids,
4348 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004349{
4350 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004351 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004352 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004353
Takashi Iwai53c334a2011-08-23 18:27:14 +02004354 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4355 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004356 if (err < 0)
4357 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004358 if (!cfg->line_outs) {
4359 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004360 spec->multiout.max_channels = 2;
4361 spec->no_analog = 1;
4362 goto dig_only;
4363 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004364 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004365 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004366
Takashi Iwai06503672011-10-06 08:27:19 +02004367 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4368 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004369 /* use HP as primary out */
4370 cfg->speaker_outs = cfg->line_outs;
4371 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4372 sizeof(cfg->speaker_pins));
4373 cfg->line_outs = cfg->hp_outs;
4374 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4375 cfg->hp_outs = 0;
4376 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4377 cfg->line_out_type = AUTO_PIN_HP_OUT;
4378 }
4379
Takashi Iwai1d045db2011-07-07 18:23:21 +02004380 err = alc_auto_fill_dac_nids(codec);
4381 if (err < 0)
4382 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004383 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004384 if (err < 0)
4385 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004386 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004387 if (err < 0)
4388 return err;
4389 err = alc_auto_create_hp_out(codec);
4390 if (err < 0)
4391 return err;
4392 err = alc_auto_create_speaker_out(codec);
4393 if (err < 0)
4394 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004395 err = alc_auto_create_shared_input(codec);
4396 if (err < 0)
4397 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004398 err = alc_auto_create_input_ctls(codec);
4399 if (err < 0)
4400 return err;
4401
4402 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4403
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004404 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004405 alc_auto_parse_digital(codec);
4406
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004407 if (!spec->no_analog)
4408 alc_remove_invalid_adc_nids(codec);
4409
4410 if (ssid_nids)
4411 alc_ssid_check(codec, ssid_nids);
4412
4413 if (!spec->no_analog) {
4414 alc_auto_check_switches(codec);
4415 err = alc_auto_add_mic_boost(codec);
4416 if (err < 0)
4417 return err;
4418 }
4419
Takashi Iwai1d045db2011-07-07 18:23:21 +02004420 if (spec->kctls.list)
4421 add_mixer(spec, spec->kctls.list);
4422
Takashi Iwai1d045db2011-07-07 18:23:21 +02004423 return 1;
4424}
4425
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004426static int alc880_parse_auto_config(struct hda_codec *codec)
4427{
4428 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4429 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4430 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4431}
4432
Takashi Iwai1d045db2011-07-07 18:23:21 +02004433#ifdef CONFIG_SND_HDA_POWER_SAVE
4434static const struct hda_amp_list alc880_loopbacks[] = {
4435 { 0x0b, HDA_INPUT, 0 },
4436 { 0x0b, HDA_INPUT, 1 },
4437 { 0x0b, HDA_INPUT, 2 },
4438 { 0x0b, HDA_INPUT, 3 },
4439 { 0x0b, HDA_INPUT, 4 },
4440 { } /* end */
4441};
4442#endif
4443
4444/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004445 * ALC880 fix-ups
4446 */
4447enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004448 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004449 ALC880_FIXUP_GPIO2,
4450 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004451 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004452 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004453 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004454 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004455 ALC880_FIXUP_VOL_KNOB,
4456 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004457 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004458 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004459 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004460 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004461 ALC880_FIXUP_3ST_BASE,
4462 ALC880_FIXUP_3ST,
4463 ALC880_FIXUP_3ST_DIG,
4464 ALC880_FIXUP_5ST_BASE,
4465 ALC880_FIXUP_5ST,
4466 ALC880_FIXUP_5ST_DIG,
4467 ALC880_FIXUP_6ST_BASE,
4468 ALC880_FIXUP_6ST,
4469 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004470};
4471
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004472/* enable the volume-knob widget support on NID 0x21 */
4473static void alc880_fixup_vol_knob(struct hda_codec *codec,
4474 const struct alc_fixup *fix, int action)
4475{
4476 if (action == ALC_FIXUP_ACT_PROBE)
4477 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4478}
4479
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004480static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004481 [ALC880_FIXUP_GPIO1] = {
4482 .type = ALC_FIXUP_VERBS,
4483 .v.verbs = alc_gpio1_init_verbs,
4484 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004485 [ALC880_FIXUP_GPIO2] = {
4486 .type = ALC_FIXUP_VERBS,
4487 .v.verbs = alc_gpio2_init_verbs,
4488 },
4489 [ALC880_FIXUP_MEDION_RIM] = {
4490 .type = ALC_FIXUP_VERBS,
4491 .v.verbs = (const struct hda_verb[]) {
4492 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4493 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4494 { }
4495 },
4496 .chained = true,
4497 .chain_id = ALC880_FIXUP_GPIO2,
4498 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004499 [ALC880_FIXUP_LG] = {
4500 .type = ALC_FIXUP_PINS,
4501 .v.pins = (const struct alc_pincfg[]) {
4502 /* disable bogus unused pins */
4503 { 0x16, 0x411111f0 },
4504 { 0x18, 0x411111f0 },
4505 { 0x1a, 0x411111f0 },
4506 { }
4507 }
4508 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004509 [ALC880_FIXUP_W810] = {
4510 .type = ALC_FIXUP_PINS,
4511 .v.pins = (const struct alc_pincfg[]) {
4512 /* disable bogus unused pins */
4513 { 0x17, 0x411111f0 },
4514 { }
4515 },
4516 .chained = true,
4517 .chain_id = ALC880_FIXUP_GPIO2,
4518 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004519 [ALC880_FIXUP_EAPD_COEF] = {
4520 .type = ALC_FIXUP_VERBS,
4521 .v.verbs = (const struct hda_verb[]) {
4522 /* change to EAPD mode */
4523 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4524 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4525 {}
4526 },
4527 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004528 [ALC880_FIXUP_TCL_S700] = {
4529 .type = ALC_FIXUP_VERBS,
4530 .v.verbs = (const struct hda_verb[]) {
4531 /* change to EAPD mode */
4532 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4533 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4534 {}
4535 },
4536 .chained = true,
4537 .chain_id = ALC880_FIXUP_GPIO2,
4538 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004539 [ALC880_FIXUP_VOL_KNOB] = {
4540 .type = ALC_FIXUP_FUNC,
4541 .v.func = alc880_fixup_vol_knob,
4542 },
4543 [ALC880_FIXUP_FUJITSU] = {
4544 /* override all pins as BIOS on old Amilo is broken */
4545 .type = ALC_FIXUP_PINS,
4546 .v.pins = (const struct alc_pincfg[]) {
4547 { 0x14, 0x0121411f }, /* HP */
4548 { 0x15, 0x99030120 }, /* speaker */
4549 { 0x16, 0x99030130 }, /* bass speaker */
4550 { 0x17, 0x411111f0 }, /* N/A */
4551 { 0x18, 0x411111f0 }, /* N/A */
4552 { 0x19, 0x01a19950 }, /* mic-in */
4553 { 0x1a, 0x411111f0 }, /* N/A */
4554 { 0x1b, 0x411111f0 }, /* N/A */
4555 { 0x1c, 0x411111f0 }, /* N/A */
4556 { 0x1d, 0x411111f0 }, /* N/A */
4557 { 0x1e, 0x01454140 }, /* SPDIF out */
4558 { }
4559 },
4560 .chained = true,
4561 .chain_id = ALC880_FIXUP_VOL_KNOB,
4562 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004563 [ALC880_FIXUP_F1734] = {
4564 /* almost compatible with FUJITSU, but no bass and SPDIF */
4565 .type = ALC_FIXUP_PINS,
4566 .v.pins = (const struct alc_pincfg[]) {
4567 { 0x14, 0x0121411f }, /* HP */
4568 { 0x15, 0x99030120 }, /* speaker */
4569 { 0x16, 0x411111f0 }, /* N/A */
4570 { 0x17, 0x411111f0 }, /* N/A */
4571 { 0x18, 0x411111f0 }, /* N/A */
4572 { 0x19, 0x01a19950 }, /* mic-in */
4573 { 0x1a, 0x411111f0 }, /* N/A */
4574 { 0x1b, 0x411111f0 }, /* N/A */
4575 { 0x1c, 0x411111f0 }, /* N/A */
4576 { 0x1d, 0x411111f0 }, /* N/A */
4577 { 0x1e, 0x411111f0 }, /* N/A */
4578 { }
4579 },
4580 .chained = true,
4581 .chain_id = ALC880_FIXUP_VOL_KNOB,
4582 },
Takashi Iwai817de922012-02-20 17:20:48 +01004583 [ALC880_FIXUP_UNIWILL] = {
4584 /* need to fix HP and speaker pins to be parsed correctly */
4585 .type = ALC_FIXUP_PINS,
4586 .v.pins = (const struct alc_pincfg[]) {
4587 { 0x14, 0x0121411f }, /* HP */
4588 { 0x15, 0x99030120 }, /* speaker */
4589 { 0x16, 0x99030130 }, /* bass speaker */
4590 { }
4591 },
4592 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004593 [ALC880_FIXUP_UNIWILL_DIG] = {
4594 .type = ALC_FIXUP_PINS,
4595 .v.pins = (const struct alc_pincfg[]) {
4596 /* disable bogus unused pins */
4597 { 0x17, 0x411111f0 },
4598 { 0x19, 0x411111f0 },
4599 { 0x1b, 0x411111f0 },
4600 { 0x1f, 0x411111f0 },
4601 { }
4602 }
4603 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004604 [ALC880_FIXUP_Z71V] = {
4605 .type = ALC_FIXUP_PINS,
4606 .v.pins = (const struct alc_pincfg[]) {
4607 /* set up the whole pins as BIOS is utterly broken */
4608 { 0x14, 0x99030120 }, /* speaker */
4609 { 0x15, 0x0121411f }, /* HP */
4610 { 0x16, 0x411111f0 }, /* N/A */
4611 { 0x17, 0x411111f0 }, /* N/A */
4612 { 0x18, 0x01a19950 }, /* mic-in */
4613 { 0x19, 0x411111f0 }, /* N/A */
4614 { 0x1a, 0x01813031 }, /* line-in */
4615 { 0x1b, 0x411111f0 }, /* N/A */
4616 { 0x1c, 0x411111f0 }, /* N/A */
4617 { 0x1d, 0x411111f0 }, /* N/A */
4618 { 0x1e, 0x0144111e }, /* SPDIF */
4619 { }
4620 }
4621 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004622 [ALC880_FIXUP_3ST_BASE] = {
4623 .type = ALC_FIXUP_PINS,
4624 .v.pins = (const struct alc_pincfg[]) {
4625 { 0x14, 0x01014010 }, /* line-out */
4626 { 0x15, 0x411111f0 }, /* N/A */
4627 { 0x16, 0x411111f0 }, /* N/A */
4628 { 0x17, 0x411111f0 }, /* N/A */
4629 { 0x18, 0x01a19c30 }, /* mic-in */
4630 { 0x19, 0x0121411f }, /* HP */
4631 { 0x1a, 0x01813031 }, /* line-in */
4632 { 0x1b, 0x02a19c40 }, /* front-mic */
4633 { 0x1c, 0x411111f0 }, /* N/A */
4634 { 0x1d, 0x411111f0 }, /* N/A */
4635 /* 0x1e is filled in below */
4636 { 0x1f, 0x411111f0 }, /* N/A */
4637 { }
4638 }
4639 },
4640 [ALC880_FIXUP_3ST] = {
4641 .type = ALC_FIXUP_PINS,
4642 .v.pins = (const struct alc_pincfg[]) {
4643 { 0x1e, 0x411111f0 }, /* N/A */
4644 { }
4645 },
4646 .chained = true,
4647 .chain_id = ALC880_FIXUP_3ST_BASE,
4648 },
4649 [ALC880_FIXUP_3ST_DIG] = {
4650 .type = ALC_FIXUP_PINS,
4651 .v.pins = (const struct alc_pincfg[]) {
4652 { 0x1e, 0x0144111e }, /* SPDIF */
4653 { }
4654 },
4655 .chained = true,
4656 .chain_id = ALC880_FIXUP_3ST_BASE,
4657 },
4658 [ALC880_FIXUP_5ST_BASE] = {
4659 .type = ALC_FIXUP_PINS,
4660 .v.pins = (const struct alc_pincfg[]) {
4661 { 0x14, 0x01014010 }, /* front */
4662 { 0x15, 0x411111f0 }, /* N/A */
4663 { 0x16, 0x01011411 }, /* CLFE */
4664 { 0x17, 0x01016412 }, /* surr */
4665 { 0x18, 0x01a19c30 }, /* mic-in */
4666 { 0x19, 0x0121411f }, /* HP */
4667 { 0x1a, 0x01813031 }, /* line-in */
4668 { 0x1b, 0x02a19c40 }, /* front-mic */
4669 { 0x1c, 0x411111f0 }, /* N/A */
4670 { 0x1d, 0x411111f0 }, /* N/A */
4671 /* 0x1e is filled in below */
4672 { 0x1f, 0x411111f0 }, /* N/A */
4673 { }
4674 }
4675 },
4676 [ALC880_FIXUP_5ST] = {
4677 .type = ALC_FIXUP_PINS,
4678 .v.pins = (const struct alc_pincfg[]) {
4679 { 0x1e, 0x411111f0 }, /* N/A */
4680 { }
4681 },
4682 .chained = true,
4683 .chain_id = ALC880_FIXUP_5ST_BASE,
4684 },
4685 [ALC880_FIXUP_5ST_DIG] = {
4686 .type = ALC_FIXUP_PINS,
4687 .v.pins = (const struct alc_pincfg[]) {
4688 { 0x1e, 0x0144111e }, /* SPDIF */
4689 { }
4690 },
4691 .chained = true,
4692 .chain_id = ALC880_FIXUP_5ST_BASE,
4693 },
4694 [ALC880_FIXUP_6ST_BASE] = {
4695 .type = ALC_FIXUP_PINS,
4696 .v.pins = (const struct alc_pincfg[]) {
4697 { 0x14, 0x01014010 }, /* front */
4698 { 0x15, 0x01016412 }, /* surr */
4699 { 0x16, 0x01011411 }, /* CLFE */
4700 { 0x17, 0x01012414 }, /* side */
4701 { 0x18, 0x01a19c30 }, /* mic-in */
4702 { 0x19, 0x02a19c40 }, /* front-mic */
4703 { 0x1a, 0x01813031 }, /* line-in */
4704 { 0x1b, 0x0121411f }, /* HP */
4705 { 0x1c, 0x411111f0 }, /* N/A */
4706 { 0x1d, 0x411111f0 }, /* N/A */
4707 /* 0x1e is filled in below */
4708 { 0x1f, 0x411111f0 }, /* N/A */
4709 { }
4710 }
4711 },
4712 [ALC880_FIXUP_6ST] = {
4713 .type = ALC_FIXUP_PINS,
4714 .v.pins = (const struct alc_pincfg[]) {
4715 { 0x1e, 0x411111f0 }, /* N/A */
4716 { }
4717 },
4718 .chained = true,
4719 .chain_id = ALC880_FIXUP_6ST_BASE,
4720 },
4721 [ALC880_FIXUP_6ST_DIG] = {
4722 .type = ALC_FIXUP_PINS,
4723 .v.pins = (const struct alc_pincfg[]) {
4724 { 0x1e, 0x0144111e }, /* SPDIF */
4725 { }
4726 },
4727 .chained = true,
4728 .chain_id = ALC880_FIXUP_6ST_BASE,
4729 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004730};
4731
4732static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004733 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004734 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004735 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4736 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004737 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004738 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004739 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004740 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004741 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004742 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004743 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004744 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004745 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004746 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004747 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004748 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4749 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4750 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004751 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004752
4753 /* Below is the copied entries from alc880_quirks.c.
4754 * It's not quite sure whether BIOS sets the correct pin-config table
4755 * on these machines, thus they are kept to be compatible with
4756 * the old static quirks. Once when it's confirmed to work without
4757 * these overrides, it'd be better to remove.
4758 */
4759 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4760 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4761 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4762 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4763 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4764 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4765 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4766 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4767 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4768 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4769 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4770 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4771 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4772 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4773 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4774 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4775 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4776 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4777 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4778 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4779 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4780 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4781 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4782 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4783 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4784 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4785 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4786 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4787 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4788 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4789 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4790 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4791 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4792 /* default Intel */
4793 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4794 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4795 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4796 {}
4797};
4798
4799static const struct alc_model_fixup alc880_fixup_models[] = {
4800 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4801 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4802 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4803 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4804 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4805 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004806 {}
4807};
4808
4809
4810/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004811 * board setups
4812 */
4813#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4814#define alc_board_config \
4815 snd_hda_check_board_config
4816#define alc_board_codec_sid_config \
4817 snd_hda_check_board_codec_sid_config
4818#include "alc_quirks.c"
4819#else
4820#define alc_board_config(codec, nums, models, tbl) -1
4821#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4822#define setup_preset(codec, x) /* NOP */
4823#endif
4824
4825/*
4826 * OK, here we have finally the patch for ALC880
4827 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004828static int patch_alc880(struct hda_codec *codec)
4829{
4830 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004831 int err;
4832
4833 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4834 if (spec == NULL)
4835 return -ENOMEM;
4836
4837 codec->spec = spec;
4838
4839 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004840 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004841
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004842 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4843 alc880_fixups);
4844 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004845
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004846 /* automatic parse from the BIOS config */
4847 err = alc880_parse_auto_config(codec);
4848 if (err < 0)
4849 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004850
Takashi Iwai60a6a842011-07-27 14:01:24 +02004851 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004852 alc_auto_fill_adc_caps(codec);
4853 alc_rebuild_imux_for_auto_mic(codec);
4854 alc_remove_invalid_adc_nids(codec);
4855 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004856
4857 if (!spec->no_analog && !spec->cap_mixer)
4858 set_capture_mixer(codec);
4859
4860 if (!spec->no_analog) {
4861 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004862 if (err < 0)
4863 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004864 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4865 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004866
Takashi Iwai1d045db2011-07-07 18:23:21 +02004867 codec->patch_ops = alc_patch_ops;
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004868 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004869#ifdef CONFIG_SND_HDA_POWER_SAVE
4870 if (!spec->loopback.amplist)
4871 spec->loopback.amplist = alc880_loopbacks;
4872#endif
4873
Takashi Iwai589876e2012-02-20 15:47:55 +01004874 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4875
Takashi Iwai1d045db2011-07-07 18:23:21 +02004876 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004877
4878 error:
4879 alc_free(codec);
4880 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881}
4882
4883
4884/*
4885 * ALC260 support
4886 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004887static int alc260_parse_auto_config(struct hda_codec *codec)
4888{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004889 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004890 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4891 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004892}
4893
Takashi Iwai1d045db2011-07-07 18:23:21 +02004894#ifdef CONFIG_SND_HDA_POWER_SAVE
4895static const struct hda_amp_list alc260_loopbacks[] = {
4896 { 0x07, HDA_INPUT, 0 },
4897 { 0x07, HDA_INPUT, 1 },
4898 { 0x07, HDA_INPUT, 2 },
4899 { 0x07, HDA_INPUT, 3 },
4900 { 0x07, HDA_INPUT, 4 },
4901 { } /* end */
4902};
4903#endif
4904
4905/*
4906 * Pin config fixes
4907 */
4908enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004909 ALC260_FIXUP_HP_DC5750,
4910 ALC260_FIXUP_HP_PIN_0F,
4911 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004912 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004913 ALC260_FIXUP_GPIO1_TOGGLE,
4914 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004915 ALC260_FIXUP_HP_B1900,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004916};
4917
Takashi Iwai20f7d922012-02-16 12:35:16 +01004918static void alc260_gpio1_automute(struct hda_codec *codec)
4919{
4920 struct alc_spec *spec = codec->spec;
4921 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4922 spec->hp_jack_present);
4923}
4924
4925static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4926 const struct alc_fixup *fix, int action)
4927{
4928 struct alc_spec *spec = codec->spec;
4929 if (action == ALC_FIXUP_ACT_PROBE) {
4930 /* although the machine has only one output pin, we need to
4931 * toggle GPIO1 according to the jack state
4932 */
4933 spec->automute_hook = alc260_gpio1_automute;
4934 spec->detect_hp = 1;
4935 spec->automute_speaker = 1;
4936 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4937 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4938 spec->unsol_event = alc_sku_unsol_event;
4939 add_verb(codec->spec, alc_gpio1_init_verbs);
4940 }
4941}
4942
Takashi Iwai1d045db2011-07-07 18:23:21 +02004943static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004944 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004945 .type = ALC_FIXUP_PINS,
4946 .v.pins = (const struct alc_pincfg[]) {
4947 { 0x11, 0x90130110 }, /* speaker */
4948 { }
4949 }
4950 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004951 [ALC260_FIXUP_HP_PIN_0F] = {
4952 .type = ALC_FIXUP_PINS,
4953 .v.pins = (const struct alc_pincfg[]) {
4954 { 0x0f, 0x01214000 }, /* HP */
4955 { }
4956 }
4957 },
4958 [ALC260_FIXUP_COEF] = {
4959 .type = ALC_FIXUP_VERBS,
4960 .v.verbs = (const struct hda_verb[]) {
4961 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4962 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4963 { }
4964 },
4965 .chained = true,
4966 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4967 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004968 [ALC260_FIXUP_GPIO1] = {
4969 .type = ALC_FIXUP_VERBS,
4970 .v.verbs = alc_gpio1_init_verbs,
4971 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004972 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4973 .type = ALC_FIXUP_FUNC,
4974 .v.func = alc260_fixup_gpio1_toggle,
4975 .chained = true,
4976 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4977 },
4978 [ALC260_FIXUP_REPLACER] = {
4979 .type = ALC_FIXUP_VERBS,
4980 .v.verbs = (const struct hda_verb[]) {
4981 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4982 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4983 { }
4984 },
4985 .chained = true,
4986 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4987 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004988 [ALC260_FIXUP_HP_B1900] = {
4989 .type = ALC_FIXUP_FUNC,
4990 .v.func = alc260_fixup_gpio1_toggle,
4991 .chained = true,
4992 .chain_id = ALC260_FIXUP_COEF,
4993 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004994};
4995
4996static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004997 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004998 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004999 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005000 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005001 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005002 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005003 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005004 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005 {}
5006};
5007
5008/*
5009 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005010static int patch_alc260(struct hda_codec *codec)
5011{
5012 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005013 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005014
5015 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5016 if (spec == NULL)
5017 return -ENOMEM;
5018
5019 codec->spec = spec;
5020
5021 spec->mixer_nid = 0x07;
5022
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005023 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5024 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005025
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005026 /* automatic parse from the BIOS config */
5027 err = alc260_parse_auto_config(codec);
5028 if (err < 0)
5029 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005030
Takashi Iwai60a6a842011-07-27 14:01:24 +02005031 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005032 alc_auto_fill_adc_caps(codec);
5033 alc_rebuild_imux_for_auto_mic(codec);
5034 alc_remove_invalid_adc_nids(codec);
5035 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005036
5037 if (!spec->no_analog && !spec->cap_mixer)
5038 set_capture_mixer(codec);
5039
5040 if (!spec->no_analog) {
5041 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005042 if (err < 0)
5043 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005044 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5045 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005046
Takashi Iwai1d045db2011-07-07 18:23:21 +02005047 codec->patch_ops = alc_patch_ops;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005048 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005049 spec->shutup = alc_eapd_shutup;
5050#ifdef CONFIG_SND_HDA_POWER_SAVE
5051 if (!spec->loopback.amplist)
5052 spec->loopback.amplist = alc260_loopbacks;
5053#endif
5054
Takashi Iwai589876e2012-02-20 15:47:55 +01005055 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5056
Takashi Iwai1d045db2011-07-07 18:23:21 +02005057 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005058
5059 error:
5060 alc_free(codec);
5061 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005062}
5063
5064
5065/*
5066 * ALC882/883/885/888/889 support
5067 *
5068 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5069 * configuration. Each pin widget can choose any input DACs and a mixer.
5070 * Each ADC is connected from a mixer of all inputs. This makes possible
5071 * 6-channel independent captures.
5072 *
5073 * In addition, an independent DAC for the multi-playback (not used in this
5074 * driver yet).
5075 */
5076#ifdef CONFIG_SND_HDA_POWER_SAVE
5077#define alc882_loopbacks alc880_loopbacks
5078#endif
5079
5080/*
5081 * Pin config fixes
5082 */
5083enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005084 ALC882_FIXUP_ABIT_AW9D_MAX,
5085 ALC882_FIXUP_LENOVO_Y530,
5086 ALC882_FIXUP_PB_M5210,
5087 ALC882_FIXUP_ACER_ASPIRE_7736,
5088 ALC882_FIXUP_ASUS_W90V,
5089 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005090 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005091 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005092 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005093 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005094 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005095 ALC889_FIXUP_COEF,
5096 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005097 ALC882_FIXUP_ACER_ASPIRE_4930G,
5098 ALC882_FIXUP_ACER_ASPIRE_8930G,
5099 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005100 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005101 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005102};
5103
Takashi Iwai68ef0562011-11-09 18:24:44 +01005104static void alc889_fixup_coef(struct hda_codec *codec,
5105 const struct alc_fixup *fix, int action)
5106{
5107 if (action != ALC_FIXUP_ACT_INIT)
5108 return;
5109 alc889_coef_init(codec);
5110}
5111
Takashi Iwai56710872011-11-14 17:42:11 +01005112/* toggle speaker-output according to the hp-jack state */
5113static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5114{
5115 unsigned int gpiostate, gpiomask, gpiodir;
5116
5117 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5118 AC_VERB_GET_GPIO_DATA, 0);
5119
5120 if (!muted)
5121 gpiostate |= (1 << pin);
5122 else
5123 gpiostate &= ~(1 << pin);
5124
5125 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5126 AC_VERB_GET_GPIO_MASK, 0);
5127 gpiomask |= (1 << pin);
5128
5129 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5130 AC_VERB_GET_GPIO_DIRECTION, 0);
5131 gpiodir |= (1 << pin);
5132
5133
5134 snd_hda_codec_write(codec, codec->afg, 0,
5135 AC_VERB_SET_GPIO_MASK, gpiomask);
5136 snd_hda_codec_write(codec, codec->afg, 0,
5137 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5138
5139 msleep(1);
5140
5141 snd_hda_codec_write(codec, codec->afg, 0,
5142 AC_VERB_SET_GPIO_DATA, gpiostate);
5143}
5144
5145/* set up GPIO at initialization */
5146static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5147 const struct alc_fixup *fix, int action)
5148{
5149 if (action != ALC_FIXUP_ACT_INIT)
5150 return;
5151 alc882_gpio_mute(codec, 0, 0);
5152 alc882_gpio_mute(codec, 1, 0);
5153}
5154
Takashi Iwai02a237b2012-02-13 15:25:07 +01005155/* Fix the connection of some pins for ALC889:
5156 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5157 * work correctly (bko#42740)
5158 */
5159static void alc889_fixup_dac_route(struct hda_codec *codec,
5160 const struct alc_fixup *fix, int action)
5161{
5162 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5163 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5164 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5165 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5166 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5167 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5168 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5169 }
5170}
5171
Takashi Iwai1d045db2011-07-07 18:23:21 +02005172static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005173 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005174 .type = ALC_FIXUP_PINS,
5175 .v.pins = (const struct alc_pincfg[]) {
5176 { 0x15, 0x01080104 }, /* side */
5177 { 0x16, 0x01011012 }, /* rear */
5178 { 0x17, 0x01016011 }, /* clfe */
5179 { }
5180 }
5181 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005182 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005183 .type = ALC_FIXUP_PINS,
5184 .v.pins = (const struct alc_pincfg[]) {
5185 { 0x15, 0x99130112 }, /* rear int speakers */
5186 { 0x16, 0x99130111 }, /* subwoofer */
5187 { }
5188 }
5189 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005190 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005191 .type = ALC_FIXUP_VERBS,
5192 .v.verbs = (const struct hda_verb[]) {
5193 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5194 {}
5195 }
5196 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005197 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005198 .type = ALC_FIXUP_SKU,
5199 .v.sku = ALC_FIXUP_SKU_IGNORE,
5200 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005201 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005202 .type = ALC_FIXUP_PINS,
5203 .v.pins = (const struct alc_pincfg[]) {
5204 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5205 { }
5206 }
5207 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005208 [ALC889_FIXUP_VAIO_TT] = {
5209 .type = ALC_FIXUP_PINS,
5210 .v.pins = (const struct alc_pincfg[]) {
5211 { 0x17, 0x90170111 }, /* hidden surround speaker */
5212 { }
5213 }
5214 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005215 [ALC888_FIXUP_EEE1601] = {
5216 .type = ALC_FIXUP_VERBS,
5217 .v.verbs = (const struct hda_verb[]) {
5218 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5219 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5220 { }
5221 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005222 },
5223 [ALC882_FIXUP_EAPD] = {
5224 .type = ALC_FIXUP_VERBS,
5225 .v.verbs = (const struct hda_verb[]) {
5226 /* change to EAPD mode */
5227 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5228 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5229 { }
5230 }
5231 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005232 [ALC883_FIXUP_EAPD] = {
5233 .type = ALC_FIXUP_VERBS,
5234 .v.verbs = (const struct hda_verb[]) {
5235 /* change to EAPD mode */
5236 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5237 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5238 { }
5239 }
5240 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005241 [ALC883_FIXUP_ACER_EAPD] = {
5242 .type = ALC_FIXUP_VERBS,
5243 .v.verbs = (const struct hda_verb[]) {
5244 /* eanable EAPD on Acer laptops */
5245 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5246 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5247 { }
5248 }
5249 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005250 [ALC882_FIXUP_GPIO3] = {
5251 .type = ALC_FIXUP_VERBS,
5252 .v.verbs = alc_gpio3_init_verbs,
5253 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005254 [ALC882_FIXUP_ASUS_W2JC] = {
5255 .type = ALC_FIXUP_VERBS,
5256 .v.verbs = alc_gpio1_init_verbs,
5257 .chained = true,
5258 .chain_id = ALC882_FIXUP_EAPD,
5259 },
5260 [ALC889_FIXUP_COEF] = {
5261 .type = ALC_FIXUP_FUNC,
5262 .v.func = alc889_fixup_coef,
5263 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005264 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5265 .type = ALC_FIXUP_PINS,
5266 .v.pins = (const struct alc_pincfg[]) {
5267 { 0x16, 0x99130111 }, /* CLFE speaker */
5268 { 0x17, 0x99130112 }, /* surround speaker */
5269 { }
5270 }
5271 },
5272 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5273 .type = ALC_FIXUP_PINS,
5274 .v.pins = (const struct alc_pincfg[]) {
5275 { 0x16, 0x99130111 }, /* CLFE speaker */
5276 { 0x1b, 0x99130112 }, /* surround speaker */
5277 { }
5278 },
5279 .chained = true,
5280 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5281 },
5282 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5283 /* additional init verbs for Acer Aspire 8930G */
5284 .type = ALC_FIXUP_VERBS,
5285 .v.verbs = (const struct hda_verb[]) {
5286 /* Enable all DACs */
5287 /* DAC DISABLE/MUTE 1? */
5288 /* setting bits 1-5 disables DAC nids 0x02-0x06
5289 * apparently. Init=0x38 */
5290 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5291 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5292 /* DAC DISABLE/MUTE 2? */
5293 /* some bit here disables the other DACs.
5294 * Init=0x4900 */
5295 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5296 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5297 /* DMIC fix
5298 * This laptop has a stereo digital microphone.
5299 * The mics are only 1cm apart which makes the stereo
5300 * useless. However, either the mic or the ALC889
5301 * makes the signal become a difference/sum signal
5302 * instead of standard stereo, which is annoying.
5303 * So instead we flip this bit which makes the
5304 * codec replicate the sum signal to both channels,
5305 * turning it into a normal mono mic.
5306 */
5307 /* DMIC_CONTROL? Init value = 0x0001 */
5308 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5309 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5310 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5311 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5312 { }
5313 }
5314 },
Takashi Iwai56710872011-11-14 17:42:11 +01005315 [ALC885_FIXUP_MACPRO_GPIO] = {
5316 .type = ALC_FIXUP_FUNC,
5317 .v.func = alc885_fixup_macpro_gpio,
5318 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005319 [ALC889_FIXUP_DAC_ROUTE] = {
5320 .type = ALC_FIXUP_FUNC,
5321 .v.func = alc889_fixup_dac_route,
5322 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005323};
5324
5325static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005326 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5327 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5328 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5329 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5330 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5331 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005332 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5333 ALC882_FIXUP_ACER_ASPIRE_4930G),
5334 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5335 ALC882_FIXUP_ACER_ASPIRE_4930G),
5336 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5337 ALC882_FIXUP_ACER_ASPIRE_8930G),
5338 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5339 ALC882_FIXUP_ACER_ASPIRE_8930G),
5340 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5341 ALC882_FIXUP_ACER_ASPIRE_4930G),
5342 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5343 ALC882_FIXUP_ACER_ASPIRE_4930G),
5344 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5345 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005346 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005347 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005348 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005349 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005350 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005351 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005352 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005353 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005354
5355 /* All Apple entries are in codec SSIDs */
5356 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5357 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5358 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
5359 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5360 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
5361
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005362 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005363 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005364 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005365 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5366 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005367 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005368 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005369 {}
5370};
5371
5372/*
5373 * BIOS auto configuration
5374 */
5375/* almost identical with ALC880 parser... */
5376static int alc882_parse_auto_config(struct hda_codec *codec)
5377{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005378 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005379 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5380 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005381}
5382
Takashi Iwai1d045db2011-07-07 18:23:21 +02005383/*
5384 */
5385#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5386#include "alc882_quirks.c"
5387#endif
5388
5389static int patch_alc882(struct hda_codec *codec)
5390{
5391 struct alc_spec *spec;
5392 int err, board_config;
5393
5394 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5395 if (spec == NULL)
5396 return -ENOMEM;
5397
5398 codec->spec = spec;
5399
5400 spec->mixer_nid = 0x0b;
5401
5402 switch (codec->vendor_id) {
5403 case 0x10ec0882:
5404 case 0x10ec0885:
5405 break;
5406 default:
5407 /* ALC883 and variants */
5408 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5409 break;
5410 }
5411
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005412 err = alc_codec_rename_from_preset(codec);
5413 if (err < 0)
5414 goto error;
5415
Takashi Iwaib2539692011-11-14 17:32:17 +01005416 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
5417 alc882_models, NULL);
5418 if (board_config < 0)
5419 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005420 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
5421
5422 if (board_config < 0) {
5423 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5424 codec->chip_name);
5425 board_config = ALC_MODEL_AUTO;
5426 }
5427
5428 if (board_config == ALC_MODEL_AUTO) {
5429 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
5430 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5431 }
5432
5433 alc_auto_parse_customize_define(codec);
5434
5435 if (board_config == ALC_MODEL_AUTO) {
5436 /* automatic parse from the BIOS config */
5437 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005438 if (err < 0)
5439 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005440 }
5441
David Henningssonfde48a12011-12-09 18:27:42 +08005442 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005443 setup_preset(codec, &alc882_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08005444 spec->vmaster_nid = 0x0c;
5445 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005446
Takashi Iwai60a6a842011-07-27 14:01:24 +02005447 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005448 alc_auto_fill_adc_caps(codec);
5449 alc_rebuild_imux_for_auto_mic(codec);
5450 alc_remove_invalid_adc_nids(codec);
5451 }
5452
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005453 if (!spec->no_analog && !spec->cap_mixer)
5454 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005455
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005456 if (!spec->no_analog && has_cdefine_beep(codec)) {
5457 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005458 if (err < 0)
5459 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005460 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005461 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005462
Takashi Iwai1d045db2011-07-07 18:23:21 +02005463 codec->patch_ops = alc_patch_ops;
5464 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02005465 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01005466 else
5467 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005468
Takashi Iwai1d045db2011-07-07 18:23:21 +02005469#ifdef CONFIG_SND_HDA_POWER_SAVE
5470 if (!spec->loopback.amplist)
5471 spec->loopback.amplist = alc882_loopbacks;
5472#endif
5473
Takashi Iwai589876e2012-02-20 15:47:55 +01005474 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5475
Takashi Iwai1d045db2011-07-07 18:23:21 +02005476 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005477
5478 error:
5479 alc_free(codec);
5480 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481}
5482
5483
5484/*
5485 * ALC262 support
5486 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005487static int alc262_parse_auto_config(struct hda_codec *codec)
5488{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005490 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5491 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005492}
5493
5494/*
5495 * Pin config fixes
5496 */
5497enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005498 ALC262_FIXUP_FSC_H270,
5499 ALC262_FIXUP_HP_Z200,
5500 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005501 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005502 ALC262_FIXUP_BENQ,
5503 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005504};
5505
5506static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005507 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508 .type = ALC_FIXUP_PINS,
5509 .v.pins = (const struct alc_pincfg[]) {
5510 { 0x14, 0x99130110 }, /* speaker */
5511 { 0x15, 0x0221142f }, /* front HP */
5512 { 0x1b, 0x0121141f }, /* rear HP */
5513 { }
5514 }
5515 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005516 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005517 .type = ALC_FIXUP_PINS,
5518 .v.pins = (const struct alc_pincfg[]) {
5519 { 0x16, 0x99130120 }, /* internal speaker */
5520 { }
5521 }
5522 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005523 [ALC262_FIXUP_TYAN] = {
5524 .type = ALC_FIXUP_PINS,
5525 .v.pins = (const struct alc_pincfg[]) {
5526 { 0x14, 0x1993e1f0 }, /* int AUX */
5527 { }
5528 }
5529 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005530 [ALC262_FIXUP_LENOVO_3000] = {
5531 .type = ALC_FIXUP_VERBS,
5532 .v.verbs = (const struct hda_verb[]) {
5533 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005534 {}
5535 },
5536 .chained = true,
5537 .chain_id = ALC262_FIXUP_BENQ,
5538 },
5539 [ALC262_FIXUP_BENQ] = {
5540 .type = ALC_FIXUP_VERBS,
5541 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005542 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5543 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5544 {}
5545 }
5546 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005547 [ALC262_FIXUP_BENQ_T31] = {
5548 .type = ALC_FIXUP_VERBS,
5549 .v.verbs = (const struct hda_verb[]) {
5550 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5551 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5552 {}
5553 }
5554 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005555};
5556
5557static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005558 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005559 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5560 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005561 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5562 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005563 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005564 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5565 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005566 {}
5567};
5568
5569
5570#ifdef CONFIG_SND_HDA_POWER_SAVE
5571#define alc262_loopbacks alc880_loopbacks
5572#endif
5573
Takashi Iwai1d045db2011-07-07 18:23:21 +02005574/*
5575 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005576static int patch_alc262(struct hda_codec *codec)
5577{
5578 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005579 int err;
5580
5581 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5582 if (spec == NULL)
5583 return -ENOMEM;
5584
5585 codec->spec = spec;
5586
5587 spec->mixer_nid = 0x0b;
5588
5589#if 0
5590 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5591 * under-run
5592 */
5593 {
5594 int tmp;
5595 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5596 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5597 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5598 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5599 }
5600#endif
5601 alc_auto_parse_customize_define(codec);
5602
5603 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5604
Takashi Iwai42399f72011-11-07 17:18:44 +01005605 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5606 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005607
Takashi Iwai42399f72011-11-07 17:18:44 +01005608 /* automatic parse from the BIOS config */
5609 err = alc262_parse_auto_config(codec);
5610 if (err < 0)
5611 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005612
Takashi Iwai60a6a842011-07-27 14:01:24 +02005613 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005614 alc_auto_fill_adc_caps(codec);
5615 alc_rebuild_imux_for_auto_mic(codec);
5616 alc_remove_invalid_adc_nids(codec);
5617 }
5618
5619 if (!spec->no_analog && !spec->cap_mixer)
5620 set_capture_mixer(codec);
5621
Takashi Iwai1d045db2011-07-07 18:23:21 +02005622 if (!spec->no_analog && has_cdefine_beep(codec)) {
5623 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005624 if (err < 0)
5625 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005626 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005627 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005628
Takashi Iwai1d045db2011-07-07 18:23:21 +02005629 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01005630 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005631 spec->shutup = alc_eapd_shutup;
5632
Takashi Iwai1d045db2011-07-07 18:23:21 +02005633#ifdef CONFIG_SND_HDA_POWER_SAVE
5634 if (!spec->loopback.amplist)
5635 spec->loopback.amplist = alc262_loopbacks;
5636#endif
5637
Takashi Iwai589876e2012-02-20 15:47:55 +01005638 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5639
Takashi Iwai1d045db2011-07-07 18:23:21 +02005640 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005641
5642 error:
5643 alc_free(codec);
5644 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645}
5646
5647/*
5648 * ALC268
5649 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005650/* bind Beep switches of both NID 0x0f and 0x10 */
5651static const struct hda_bind_ctls alc268_bind_beep_sw = {
5652 .ops = &snd_hda_bind_sw,
5653 .values = {
5654 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5655 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5656 0
5657 },
5658};
5659
5660static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5661 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5662 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5663 { }
5664};
5665
5666/* set PCBEEP vol = 0, mute connections */
5667static const struct hda_verb alc268_beep_init_verbs[] = {
5668 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5669 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5670 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5671 { }
5672};
5673
5674/*
5675 * BIOS auto configuration
5676 */
5677static int alc268_parse_auto_config(struct hda_codec *codec)
5678{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005679 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005680 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005681 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5682 if (err > 0) {
5683 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5684 add_mixer(spec, alc268_beep_mixer);
5685 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005686 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005687 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005688 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005689}
5690
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691/*
5692 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005693static int patch_alc268(struct hda_codec *codec)
5694{
5695 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005696 int i, has_beep, err;
5697
5698 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5699 if (spec == NULL)
5700 return -ENOMEM;
5701
5702 codec->spec = spec;
5703
5704 /* ALC268 has no aa-loopback mixer */
5705
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005706 /* automatic parse from the BIOS config */
5707 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005708 if (err < 0)
5709 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005710
Takashi Iwai1d045db2011-07-07 18:23:21 +02005711 has_beep = 0;
5712 for (i = 0; i < spec->num_mixers; i++) {
5713 if (spec->mixers[i] == alc268_beep_mixer) {
5714 has_beep = 1;
5715 break;
5716 }
5717 }
5718
5719 if (has_beep) {
5720 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005721 if (err < 0)
5722 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005723 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5724 /* override the amp caps for beep generator */
5725 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5726 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5727 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5728 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5729 (0 << AC_AMPCAP_MUTE_SHIFT));
5730 }
5731
Takashi Iwai60a6a842011-07-27 14:01:24 +02005732 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005733 alc_auto_fill_adc_caps(codec);
5734 alc_rebuild_imux_for_auto_mic(codec);
5735 alc_remove_invalid_adc_nids(codec);
5736 }
5737
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005738 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005739 set_capture_mixer(codec);
5740
Takashi Iwai1d045db2011-07-07 18:23:21 +02005741 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005742 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743 spec->shutup = alc_eapd_shutup;
5744
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005746
5747 error:
5748 alc_free(codec);
5749 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750}
5751
5752/*
5753 * ALC269
5754 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005755#ifdef CONFIG_SND_HDA_POWER_SAVE
5756#define alc269_loopbacks alc880_loopbacks
5757#endif
5758
5759static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5760 .substreams = 1,
5761 .channels_min = 2,
5762 .channels_max = 8,
5763 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5764 /* NID is set in alc_build_pcms */
5765 .ops = {
5766 .open = alc_playback_pcm_open,
5767 .prepare = alc_playback_pcm_prepare,
5768 .cleanup = alc_playback_pcm_cleanup
5769 },
5770};
5771
5772static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5773 .substreams = 1,
5774 .channels_min = 2,
5775 .channels_max = 2,
5776 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5777 /* NID is set in alc_build_pcms */
5778};
5779
5780#ifdef CONFIG_SND_HDA_POWER_SAVE
5781static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5782{
5783 switch (codec->subsystem_id) {
5784 case 0x103c1586:
5785 return 1;
5786 }
5787 return 0;
5788}
5789
5790static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5791{
5792 /* update mute-LED according to the speaker mute state */
5793 if (nid == 0x01 || nid == 0x14) {
5794 int pinval;
5795 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5796 HDA_AMP_MUTE)
5797 pinval = 0x24;
5798 else
5799 pinval = 0x20;
5800 /* mic2 vref pin is used for mute LED control */
5801 snd_hda_codec_update_cache(codec, 0x19, 0,
5802 AC_VERB_SET_PIN_WIDGET_CONTROL,
5803 pinval);
5804 }
5805 return alc_check_power_status(codec, nid);
5806}
5807#endif /* CONFIG_SND_HDA_POWER_SAVE */
5808
5809/* different alc269-variants */
5810enum {
5811 ALC269_TYPE_ALC269VA,
5812 ALC269_TYPE_ALC269VB,
5813 ALC269_TYPE_ALC269VC,
5814};
5815
5816/*
5817 * BIOS auto configuration
5818 */
5819static int alc269_parse_auto_config(struct hda_codec *codec)
5820{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005821 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005822 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5823 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5824 struct alc_spec *spec = codec->spec;
5825 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5826 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005827
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005828 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005829}
5830
Takashi Iwai1d045db2011-07-07 18:23:21 +02005831static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5832{
5833 int val = alc_read_coef_idx(codec, 0x04);
5834 if (power_up)
5835 val |= 1 << 11;
5836 else
5837 val &= ~(1 << 11);
5838 alc_write_coef_idx(codec, 0x04, val);
5839}
5840
5841static void alc269_shutup(struct hda_codec *codec)
5842{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005843 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005844 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005845 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005846 alc269_toggle_power_output(codec, 0);
5847 msleep(150);
5848 }
5849}
5850
Takashi Iwai2a439522011-07-26 09:52:50 +02005851#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005852static int alc269_resume(struct hda_codec *codec)
5853{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005854 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005855 alc269_toggle_power_output(codec, 0);
5856 msleep(150);
5857 }
5858
5859 codec->patch_ops.init(codec);
5860
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005861 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005862 alc269_toggle_power_output(codec, 1);
5863 msleep(200);
5864 }
5865
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005866 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005867 alc269_toggle_power_output(codec, 1);
5868
5869 snd_hda_codec_resume_amp(codec);
5870 snd_hda_codec_resume_cache(codec);
5871 hda_call_check_power_status(codec, 0x01);
5872 return 0;
5873}
Takashi Iwai2a439522011-07-26 09:52:50 +02005874#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005875
5876static void alc269_fixup_hweq(struct hda_codec *codec,
5877 const struct alc_fixup *fix, int action)
5878{
5879 int coef;
5880
5881 if (action != ALC_FIXUP_ACT_INIT)
5882 return;
5883 coef = alc_read_coef_idx(codec, 0x1e);
5884 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5885}
5886
5887static void alc271_fixup_dmic(struct hda_codec *codec,
5888 const struct alc_fixup *fix, int action)
5889{
5890 static const struct hda_verb verbs[] = {
5891 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5892 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5893 {}
5894 };
5895 unsigned int cfg;
5896
5897 if (strcmp(codec->chip_name, "ALC271X"))
5898 return;
5899 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5900 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5901 snd_hda_sequence_write(codec, verbs);
5902}
5903
Takashi Iwai017f2a12011-07-09 14:42:25 +02005904static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5905 const struct alc_fixup *fix, int action)
5906{
5907 struct alc_spec *spec = codec->spec;
5908
5909 if (action != ALC_FIXUP_ACT_PROBE)
5910 return;
5911
5912 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5913 * fix the sample rate of analog I/O to 44.1kHz
5914 */
5915 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5916 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5917}
5918
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005919static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5920 const struct alc_fixup *fix, int action)
5921{
5922 int coef;
5923
5924 if (action != ALC_FIXUP_ACT_INIT)
5925 return;
5926 /* The digital-mic unit sends PDM (differential signal) instead of
5927 * the standard PCM, thus you can't record a valid mono stream as is.
5928 * Below is a workaround specific to ALC269 to control the dmic
5929 * signal source as mono.
5930 */
5931 coef = alc_read_coef_idx(codec, 0x07);
5932 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5933}
5934
Takashi Iwai24519912011-08-16 15:08:49 +02005935static void alc269_quanta_automute(struct hda_codec *codec)
5936{
David Henningsson42cf0d02011-09-20 12:04:56 +02005937 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005938
5939 snd_hda_codec_write(codec, 0x20, 0,
5940 AC_VERB_SET_COEF_INDEX, 0x0c);
5941 snd_hda_codec_write(codec, 0x20, 0,
5942 AC_VERB_SET_PROC_COEF, 0x680);
5943
5944 snd_hda_codec_write(codec, 0x20, 0,
5945 AC_VERB_SET_COEF_INDEX, 0x0c);
5946 snd_hda_codec_write(codec, 0x20, 0,
5947 AC_VERB_SET_PROC_COEF, 0x480);
5948}
5949
5950static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5951 const struct alc_fixup *fix, int action)
5952{
5953 struct alc_spec *spec = codec->spec;
5954 if (action != ALC_FIXUP_ACT_PROBE)
5955 return;
5956 spec->automute_hook = alc269_quanta_automute;
5957}
5958
Takashi Iwai1d045db2011-07-07 18:23:21 +02005959enum {
5960 ALC269_FIXUP_SONY_VAIO,
5961 ALC275_FIXUP_SONY_VAIO_GPIO2,
5962 ALC269_FIXUP_DELL_M101Z,
5963 ALC269_FIXUP_SKU_IGNORE,
5964 ALC269_FIXUP_ASUS_G73JW,
5965 ALC269_FIXUP_LENOVO_EAPD,
5966 ALC275_FIXUP_SONY_HWEQ,
5967 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005968 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005969 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005970 ALC269_FIXUP_QUANTA_MUTE,
5971 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005972 ALC269_FIXUP_AMIC,
5973 ALC269_FIXUP_DMIC,
5974 ALC269VB_FIXUP_AMIC,
5975 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005976};
5977
5978static const struct alc_fixup alc269_fixups[] = {
5979 [ALC269_FIXUP_SONY_VAIO] = {
5980 .type = ALC_FIXUP_VERBS,
5981 .v.verbs = (const struct hda_verb[]) {
5982 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5983 {}
5984 }
5985 },
5986 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5987 .type = ALC_FIXUP_VERBS,
5988 .v.verbs = (const struct hda_verb[]) {
5989 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5990 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5991 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5992 { }
5993 },
5994 .chained = true,
5995 .chain_id = ALC269_FIXUP_SONY_VAIO
5996 },
5997 [ALC269_FIXUP_DELL_M101Z] = {
5998 .type = ALC_FIXUP_VERBS,
5999 .v.verbs = (const struct hda_verb[]) {
6000 /* Enables internal speaker */
6001 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6002 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6003 {}
6004 }
6005 },
6006 [ALC269_FIXUP_SKU_IGNORE] = {
6007 .type = ALC_FIXUP_SKU,
6008 .v.sku = ALC_FIXUP_SKU_IGNORE,
6009 },
6010 [ALC269_FIXUP_ASUS_G73JW] = {
6011 .type = ALC_FIXUP_PINS,
6012 .v.pins = (const struct alc_pincfg[]) {
6013 { 0x17, 0x99130111 }, /* subwoofer */
6014 { }
6015 }
6016 },
6017 [ALC269_FIXUP_LENOVO_EAPD] = {
6018 .type = ALC_FIXUP_VERBS,
6019 .v.verbs = (const struct hda_verb[]) {
6020 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6021 {}
6022 }
6023 },
6024 [ALC275_FIXUP_SONY_HWEQ] = {
6025 .type = ALC_FIXUP_FUNC,
6026 .v.func = alc269_fixup_hweq,
6027 .chained = true,
6028 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6029 },
6030 [ALC271_FIXUP_DMIC] = {
6031 .type = ALC_FIXUP_FUNC,
6032 .v.func = alc271_fixup_dmic,
6033 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006034 [ALC269_FIXUP_PCM_44K] = {
6035 .type = ALC_FIXUP_FUNC,
6036 .v.func = alc269_fixup_pcm_44k,
6037 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006038 [ALC269_FIXUP_STEREO_DMIC] = {
6039 .type = ALC_FIXUP_FUNC,
6040 .v.func = alc269_fixup_stereo_dmic,
6041 },
Takashi Iwai24519912011-08-16 15:08:49 +02006042 [ALC269_FIXUP_QUANTA_MUTE] = {
6043 .type = ALC_FIXUP_FUNC,
6044 .v.func = alc269_fixup_quanta_mute,
6045 },
6046 [ALC269_FIXUP_LIFEBOOK] = {
6047 .type = ALC_FIXUP_PINS,
6048 .v.pins = (const struct alc_pincfg[]) {
6049 { 0x1a, 0x2101103f }, /* dock line-out */
6050 { 0x1b, 0x23a11040 }, /* dock mic-in */
6051 { }
6052 },
6053 .chained = true,
6054 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6055 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006056 [ALC269_FIXUP_AMIC] = {
6057 .type = ALC_FIXUP_PINS,
6058 .v.pins = (const struct alc_pincfg[]) {
6059 { 0x14, 0x99130110 }, /* speaker */
6060 { 0x15, 0x0121401f }, /* HP out */
6061 { 0x18, 0x01a19c20 }, /* mic */
6062 { 0x19, 0x99a3092f }, /* int-mic */
6063 { }
6064 },
6065 },
6066 [ALC269_FIXUP_DMIC] = {
6067 .type = ALC_FIXUP_PINS,
6068 .v.pins = (const struct alc_pincfg[]) {
6069 { 0x12, 0x99a3092f }, /* int-mic */
6070 { 0x14, 0x99130110 }, /* speaker */
6071 { 0x15, 0x0121401f }, /* HP out */
6072 { 0x18, 0x01a19c20 }, /* mic */
6073 { }
6074 },
6075 },
6076 [ALC269VB_FIXUP_AMIC] = {
6077 .type = ALC_FIXUP_PINS,
6078 .v.pins = (const struct alc_pincfg[]) {
6079 { 0x14, 0x99130110 }, /* speaker */
6080 { 0x18, 0x01a19c20 }, /* mic */
6081 { 0x19, 0x99a3092f }, /* int-mic */
6082 { 0x21, 0x0121401f }, /* HP out */
6083 { }
6084 },
6085 },
David Henningsson2267ea92012-01-03 08:45:56 +01006086 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006087 .type = ALC_FIXUP_PINS,
6088 .v.pins = (const struct alc_pincfg[]) {
6089 { 0x12, 0x99a3092f }, /* int-mic */
6090 { 0x14, 0x99130110 }, /* speaker */
6091 { 0x18, 0x01a19c20 }, /* mic */
6092 { 0x21, 0x0121401f }, /* HP out */
6093 { }
6094 },
6095 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006096};
6097
6098static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02006099 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006100 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6101 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6102 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6103 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6104 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006105 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6106 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6107 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6108 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6109 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6110 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006111 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006112 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6113 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6114 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6115 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6116 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006117 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006118 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006119 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006120
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006121#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006122 /* Below is a quirk table taken from the old code.
6123 * Basically the device should work as is without the fixup table.
6124 * If BIOS doesn't give a proper info, enable the corresponding
6125 * fixup entry.
6126 */
6127 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6128 ALC269_FIXUP_AMIC),
6129 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006130 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6131 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6132 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6133 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6134 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6135 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6136 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6137 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6138 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6139 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6140 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6141 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6142 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6143 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6144 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6145 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6146 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6147 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6148 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6149 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6150 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6151 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6152 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6153 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6154 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6155 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6156 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6157 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6158 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6159 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6160 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6161 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6162 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6163 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6164 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6165 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6166 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6167 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6168#endif
6169 {}
6170};
6171
6172static const struct alc_model_fixup alc269_fixup_models[] = {
6173 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6174 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006175 {}
6176};
6177
6178
6179static int alc269_fill_coef(struct hda_codec *codec)
6180{
6181 int val;
6182
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006183 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006184 alc_write_coef_idx(codec, 0xf, 0x960b);
6185 alc_write_coef_idx(codec, 0xe, 0x8817);
6186 }
6187
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006188 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006189 alc_write_coef_idx(codec, 0xf, 0x960b);
6190 alc_write_coef_idx(codec, 0xe, 0x8814);
6191 }
6192
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006193 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006194 val = alc_read_coef_idx(codec, 0x04);
6195 /* Power up output pin */
6196 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6197 }
6198
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006199 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006200 val = alc_read_coef_idx(codec, 0xd);
6201 if ((val & 0x0c00) >> 10 != 0x1) {
6202 /* Capless ramp up clock control */
6203 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6204 }
6205 val = alc_read_coef_idx(codec, 0x17);
6206 if ((val & 0x01c0) >> 6 != 0x4) {
6207 /* Class D power on reset */
6208 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6209 }
6210 }
6211
6212 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6213 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6214
6215 val = alc_read_coef_idx(codec, 0x4); /* HP */
6216 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6217
6218 return 0;
6219}
6220
6221/*
6222 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006223static int patch_alc269(struct hda_codec *codec)
6224{
6225 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006226 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006227
6228 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6229 if (spec == NULL)
6230 return -ENOMEM;
6231
6232 codec->spec = spec;
6233
6234 spec->mixer_nid = 0x0b;
6235
6236 alc_auto_parse_customize_define(codec);
6237
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006238 err = alc_codec_rename_from_preset(codec);
6239 if (err < 0)
6240 goto error;
6241
Takashi Iwai1d045db2011-07-07 18:23:21 +02006242 if (codec->vendor_id == 0x10ec0269) {
6243 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006244 switch (alc_get_coef0(codec) & 0x00f0) {
6245 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006246 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006247 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006248 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006249 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006250 break;
6251 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006252 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6253 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006254 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006255 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006256 break;
6257 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006258 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006259 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006260 if (err < 0)
6261 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006262 alc269_fill_coef(codec);
6263 }
6264
Takashi Iwaia4297b52011-08-23 18:40:12 +02006265 alc_pick_fixup(codec, alc269_fixup_models,
6266 alc269_fixup_tbl, alc269_fixups);
6267 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006268
Takashi Iwaia4297b52011-08-23 18:40:12 +02006269 /* automatic parse from the BIOS config */
6270 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006271 if (err < 0)
6272 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006273
Takashi Iwai60a6a842011-07-27 14:01:24 +02006274 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006275 alc_auto_fill_adc_caps(codec);
6276 alc_rebuild_imux_for_auto_mic(codec);
6277 alc_remove_invalid_adc_nids(codec);
6278 }
6279
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006280 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006281 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006282
6283 if (!spec->no_analog && has_cdefine_beep(codec)) {
6284 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006285 if (err < 0)
6286 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006287 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006288 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006289
Takashi Iwai1d045db2011-07-07 18:23:21 +02006290 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006291#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006292 codec->patch_ops.resume = alc269_resume;
6293#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02006294 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006295 spec->shutup = alc269_shutup;
6296
Takashi Iwai1d045db2011-07-07 18:23:21 +02006297#ifdef CONFIG_SND_HDA_POWER_SAVE
6298 if (!spec->loopback.amplist)
6299 spec->loopback.amplist = alc269_loopbacks;
6300 if (alc269_mic2_for_mute_led(codec))
6301 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
6302#endif
6303
Takashi Iwai589876e2012-02-20 15:47:55 +01006304 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6305
Takashi Iwai1d045db2011-07-07 18:23:21 +02006306 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006307
6308 error:
6309 alc_free(codec);
6310 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006311}
6312
6313/*
6314 * ALC861
6315 */
6316
Takashi Iwai1d045db2011-07-07 18:23:21 +02006317static int alc861_parse_auto_config(struct hda_codec *codec)
6318{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006319 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006320 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6321 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006322}
6323
Takashi Iwai1d045db2011-07-07 18:23:21 +02006324#ifdef CONFIG_SND_HDA_POWER_SAVE
6325static const struct hda_amp_list alc861_loopbacks[] = {
6326 { 0x15, HDA_INPUT, 0 },
6327 { 0x15, HDA_INPUT, 1 },
6328 { 0x15, HDA_INPUT, 2 },
6329 { 0x15, HDA_INPUT, 3 },
6330 { } /* end */
6331};
6332#endif
6333
6334
6335/* Pin config fixes */
6336enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006337 ALC861_FIXUP_FSC_AMILO_PI1505,
6338 ALC861_FIXUP_AMP_VREF_0F,
6339 ALC861_FIXUP_NO_JACK_DETECT,
6340 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006341};
6342
Takashi Iwai31150f22012-01-30 10:54:08 +01006343/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6344static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6345 const struct alc_fixup *fix, int action)
6346{
6347 struct alc_spec *spec = codec->spec;
6348 unsigned int val;
6349
6350 if (action != ALC_FIXUP_ACT_INIT)
6351 return;
6352 val = snd_hda_codec_read(codec, 0x0f, 0,
6353 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6354 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6355 val |= AC_PINCTL_IN_EN;
6356 val |= AC_PINCTL_VREF_50;
6357 snd_hda_codec_write(codec, 0x0f, 0,
6358 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6359 spec->keep_vref_in_automute = 1;
6360}
6361
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006362/* suppress the jack-detection */
6363static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6364 const struct alc_fixup *fix, int action)
6365{
6366 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6367 codec->no_jack_detect = 1;
6368}
6369
Takashi Iwai1d045db2011-07-07 18:23:21 +02006370static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006371 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006372 .type = ALC_FIXUP_PINS,
6373 .v.pins = (const struct alc_pincfg[]) {
6374 { 0x0b, 0x0221101f }, /* HP */
6375 { 0x0f, 0x90170310 }, /* speaker */
6376 { }
6377 }
6378 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006379 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006380 .type = ALC_FIXUP_FUNC,
6381 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006382 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006383 [ALC861_FIXUP_NO_JACK_DETECT] = {
6384 .type = ALC_FIXUP_FUNC,
6385 .v.func = alc_fixup_no_jack_detect,
6386 },
6387 [ALC861_FIXUP_ASUS_A6RP] = {
6388 .type = ALC_FIXUP_FUNC,
6389 .v.func = alc861_fixup_asus_amp_vref_0f,
6390 .chained = true,
6391 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6392 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006393};
6394
6395static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006396 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6397 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6398 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6399 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6400 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6401 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006402 {}
6403};
6404
6405/*
6406 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006407static int patch_alc861(struct hda_codec *codec)
6408{
6409 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006410 int err;
6411
6412 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6413 if (spec == NULL)
6414 return -ENOMEM;
6415
6416 codec->spec = spec;
6417
6418 spec->mixer_nid = 0x15;
6419
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006420 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6421 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006422
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006423 /* automatic parse from the BIOS config */
6424 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006425 if (err < 0)
6426 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006427
Takashi Iwai60a6a842011-07-27 14:01:24 +02006428 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006429 alc_auto_fill_adc_caps(codec);
6430 alc_rebuild_imux_for_auto_mic(codec);
6431 alc_remove_invalid_adc_nids(codec);
6432 }
6433
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006434 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006435 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006436
6437 if (!spec->no_analog) {
6438 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006439 if (err < 0)
6440 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006441 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6442 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006443
Takashi Iwai1d045db2011-07-07 18:23:21 +02006444 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006445 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006446#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006447 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006448 if (!spec->loopback.amplist)
6449 spec->loopback.amplist = alc861_loopbacks;
6450#endif
6451
Takashi Iwai589876e2012-02-20 15:47:55 +01006452 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6453
Takashi Iwai1d045db2011-07-07 18:23:21 +02006454 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006455
6456 error:
6457 alc_free(codec);
6458 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006459}
6460
6461/*
6462 * ALC861-VD support
6463 *
6464 * Based on ALC882
6465 *
6466 * In addition, an independent DAC
6467 */
6468#ifdef CONFIG_SND_HDA_POWER_SAVE
6469#define alc861vd_loopbacks alc880_loopbacks
6470#endif
6471
Takashi Iwai1d045db2011-07-07 18:23:21 +02006472static int alc861vd_parse_auto_config(struct hda_codec *codec)
6473{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006474 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006475 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6476 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006477}
6478
Takashi Iwai1d045db2011-07-07 18:23:21 +02006479enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006480 ALC660VD_FIX_ASUS_GPIO1,
6481 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006482};
6483
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006484/* exclude VREF80 */
6485static void alc861vd_fixup_dallas(struct hda_codec *codec,
6486 const struct alc_fixup *fix, int action)
6487{
6488 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6489 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6490 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6491 }
6492}
6493
Takashi Iwai1d045db2011-07-07 18:23:21 +02006494static const struct alc_fixup alc861vd_fixups[] = {
6495 [ALC660VD_FIX_ASUS_GPIO1] = {
6496 .type = ALC_FIXUP_VERBS,
6497 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006498 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006499 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6500 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6501 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6502 { }
6503 }
6504 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006505 [ALC861VD_FIX_DALLAS] = {
6506 .type = ALC_FIXUP_FUNC,
6507 .v.func = alc861vd_fixup_dallas,
6508 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006509};
6510
6511static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006512 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006513 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006514 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006515 {}
6516};
6517
6518static const struct hda_verb alc660vd_eapd_verbs[] = {
6519 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6520 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6521 { }
6522};
6523
6524/*
6525 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006526static int patch_alc861vd(struct hda_codec *codec)
6527{
6528 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006529 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006530
6531 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6532 if (spec == NULL)
6533 return -ENOMEM;
6534
6535 codec->spec = spec;
6536
6537 spec->mixer_nid = 0x0b;
6538
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006539 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6540 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006541
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006542 /* automatic parse from the BIOS config */
6543 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006544 if (err < 0)
6545 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006546
Takashi Iwai1d045db2011-07-07 18:23:21 +02006547 if (codec->vendor_id == 0x10ec0660) {
6548 /* always turn on EAPD */
6549 add_verb(spec, alc660vd_eapd_verbs);
6550 }
6551
Takashi Iwai60a6a842011-07-27 14:01:24 +02006552 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006553 alc_auto_fill_adc_caps(codec);
6554 alc_rebuild_imux_for_auto_mic(codec);
6555 alc_remove_invalid_adc_nids(codec);
6556 }
6557
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006558 if (!spec->no_analog && !spec->cap_mixer)
6559 set_capture_mixer(codec);
6560
6561 if (!spec->no_analog) {
6562 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006563 if (err < 0)
6564 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006565 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6566 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006567
Takashi Iwai1d045db2011-07-07 18:23:21 +02006568 codec->patch_ops = alc_patch_ops;
6569
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006570 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006571 spec->shutup = alc_eapd_shutup;
6572#ifdef CONFIG_SND_HDA_POWER_SAVE
6573 if (!spec->loopback.amplist)
6574 spec->loopback.amplist = alc861vd_loopbacks;
6575#endif
6576
Takashi Iwai589876e2012-02-20 15:47:55 +01006577 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6578
Takashi Iwai1d045db2011-07-07 18:23:21 +02006579 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006580
6581 error:
6582 alc_free(codec);
6583 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006584}
6585
6586/*
6587 * ALC662 support
6588 *
6589 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6590 * configuration. Each pin widget can choose any input DACs and a mixer.
6591 * Each ADC is connected from a mixer of all inputs. This makes possible
6592 * 6-channel independent captures.
6593 *
6594 * In addition, an independent DAC for the multi-playback (not used in this
6595 * driver yet).
6596 */
6597#ifdef CONFIG_SND_HDA_POWER_SAVE
6598#define alc662_loopbacks alc880_loopbacks
6599#endif
6600
6601/*
6602 * BIOS auto configuration
6603 */
6604
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006605static int alc662_parse_auto_config(struct hda_codec *codec)
6606{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006607 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006608 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6609 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6610 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006611
Kailang Yang6227cdc2010-02-25 08:36:52 +01006612 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6613 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006614 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006615 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006616 ssids = alc662_ssids;
6617 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006618}
6619
Todd Broch6be79482010-12-07 16:51:05 -08006620static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006621 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006622{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006623 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006624 return;
Todd Broch6be79482010-12-07 16:51:05 -08006625 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6626 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6627 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6628 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6629 (0 << AC_AMPCAP_MUTE_SHIFT)))
6630 printk(KERN_WARNING
6631 "hda_codec: failed to override amp caps for NID 0x2\n");
6632}
6633
David Henningsson6cb3b702010-09-09 08:51:44 +02006634enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006635 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006636 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006637 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006638 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006639 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006640 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006641 ALC662_FIXUP_ASUS_MODE1,
6642 ALC662_FIXUP_ASUS_MODE2,
6643 ALC662_FIXUP_ASUS_MODE3,
6644 ALC662_FIXUP_ASUS_MODE4,
6645 ALC662_FIXUP_ASUS_MODE5,
6646 ALC662_FIXUP_ASUS_MODE6,
6647 ALC662_FIXUP_ASUS_MODE7,
6648 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006649 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006650};
6651
6652static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006653 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006654 .type = ALC_FIXUP_PINS,
6655 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006656 { 0x15, 0x99130112 }, /* subwoofer */
6657 { }
6658 }
6659 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006660 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006661 .type = ALC_FIXUP_PINS,
6662 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006663 { 0x17, 0x99130112 }, /* subwoofer */
6664 { }
6665 }
6666 },
Todd Broch6be79482010-12-07 16:51:05 -08006667 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006668 .type = ALC_FIXUP_FUNC,
6669 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006670 },
6671 [ALC662_FIXUP_CZC_P10T] = {
6672 .type = ALC_FIXUP_VERBS,
6673 .v.verbs = (const struct hda_verb[]) {
6674 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6675 {}
6676 }
6677 },
David Henningsson94024cd2011-04-29 14:10:55 +02006678 [ALC662_FIXUP_SKU_IGNORE] = {
6679 .type = ALC_FIXUP_SKU,
6680 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006681 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006682 [ALC662_FIXUP_HP_RP5800] = {
6683 .type = ALC_FIXUP_PINS,
6684 .v.pins = (const struct alc_pincfg[]) {
6685 { 0x14, 0x0221201f }, /* HP out */
6686 { }
6687 },
6688 .chained = true,
6689 .chain_id = ALC662_FIXUP_SKU_IGNORE
6690 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006691 [ALC662_FIXUP_ASUS_MODE1] = {
6692 .type = ALC_FIXUP_PINS,
6693 .v.pins = (const struct alc_pincfg[]) {
6694 { 0x14, 0x99130110 }, /* speaker */
6695 { 0x18, 0x01a19c20 }, /* mic */
6696 { 0x19, 0x99a3092f }, /* int-mic */
6697 { 0x21, 0x0121401f }, /* HP out */
6698 { }
6699 },
6700 .chained = true,
6701 .chain_id = ALC662_FIXUP_SKU_IGNORE
6702 },
6703 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006704 .type = ALC_FIXUP_PINS,
6705 .v.pins = (const struct alc_pincfg[]) {
6706 { 0x14, 0x99130110 }, /* speaker */
6707 { 0x18, 0x01a19820 }, /* mic */
6708 { 0x19, 0x99a3092f }, /* int-mic */
6709 { 0x1b, 0x0121401f }, /* HP out */
6710 { }
6711 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006712 .chained = true,
6713 .chain_id = ALC662_FIXUP_SKU_IGNORE
6714 },
6715 [ALC662_FIXUP_ASUS_MODE3] = {
6716 .type = ALC_FIXUP_PINS,
6717 .v.pins = (const struct alc_pincfg[]) {
6718 { 0x14, 0x99130110 }, /* speaker */
6719 { 0x15, 0x0121441f }, /* HP */
6720 { 0x18, 0x01a19840 }, /* mic */
6721 { 0x19, 0x99a3094f }, /* int-mic */
6722 { 0x21, 0x01211420 }, /* HP2 */
6723 { }
6724 },
6725 .chained = true,
6726 .chain_id = ALC662_FIXUP_SKU_IGNORE
6727 },
6728 [ALC662_FIXUP_ASUS_MODE4] = {
6729 .type = ALC_FIXUP_PINS,
6730 .v.pins = (const struct alc_pincfg[]) {
6731 { 0x14, 0x99130110 }, /* speaker */
6732 { 0x16, 0x99130111 }, /* speaker */
6733 { 0x18, 0x01a19840 }, /* mic */
6734 { 0x19, 0x99a3094f }, /* int-mic */
6735 { 0x21, 0x0121441f }, /* HP */
6736 { }
6737 },
6738 .chained = true,
6739 .chain_id = ALC662_FIXUP_SKU_IGNORE
6740 },
6741 [ALC662_FIXUP_ASUS_MODE5] = {
6742 .type = ALC_FIXUP_PINS,
6743 .v.pins = (const struct alc_pincfg[]) {
6744 { 0x14, 0x99130110 }, /* speaker */
6745 { 0x15, 0x0121441f }, /* HP */
6746 { 0x16, 0x99130111 }, /* speaker */
6747 { 0x18, 0x01a19840 }, /* mic */
6748 { 0x19, 0x99a3094f }, /* int-mic */
6749 { }
6750 },
6751 .chained = true,
6752 .chain_id = ALC662_FIXUP_SKU_IGNORE
6753 },
6754 [ALC662_FIXUP_ASUS_MODE6] = {
6755 .type = ALC_FIXUP_PINS,
6756 .v.pins = (const struct alc_pincfg[]) {
6757 { 0x14, 0x99130110 }, /* speaker */
6758 { 0x15, 0x01211420 }, /* HP2 */
6759 { 0x18, 0x01a19840 }, /* mic */
6760 { 0x19, 0x99a3094f }, /* int-mic */
6761 { 0x1b, 0x0121441f }, /* HP */
6762 { }
6763 },
6764 .chained = true,
6765 .chain_id = ALC662_FIXUP_SKU_IGNORE
6766 },
6767 [ALC662_FIXUP_ASUS_MODE7] = {
6768 .type = ALC_FIXUP_PINS,
6769 .v.pins = (const struct alc_pincfg[]) {
6770 { 0x14, 0x99130110 }, /* speaker */
6771 { 0x17, 0x99130111 }, /* speaker */
6772 { 0x18, 0x01a19840 }, /* mic */
6773 { 0x19, 0x99a3094f }, /* int-mic */
6774 { 0x1b, 0x01214020 }, /* HP */
6775 { 0x21, 0x0121401f }, /* HP */
6776 { }
6777 },
6778 .chained = true,
6779 .chain_id = ALC662_FIXUP_SKU_IGNORE
6780 },
6781 [ALC662_FIXUP_ASUS_MODE8] = {
6782 .type = ALC_FIXUP_PINS,
6783 .v.pins = (const struct alc_pincfg[]) {
6784 { 0x14, 0x99130110 }, /* speaker */
6785 { 0x12, 0x99a30970 }, /* int-mic */
6786 { 0x15, 0x01214020 }, /* HP */
6787 { 0x17, 0x99130111 }, /* speaker */
6788 { 0x18, 0x01a19840 }, /* mic */
6789 { 0x21, 0x0121401f }, /* HP */
6790 { }
6791 },
6792 .chained = true,
6793 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006794 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006795 [ALC662_FIXUP_NO_JACK_DETECT] = {
6796 .type = ALC_FIXUP_FUNC,
6797 .v.func = alc_fixup_no_jack_detect,
6798 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006799};
6800
Takashi Iwaia9111322011-05-02 11:30:18 +02006801static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006802 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006803 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006804 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006805 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006806 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006807 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006808 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006809 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006810 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006811 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006812 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006813
6814#if 0
6815 /* Below is a quirk table taken from the old code.
6816 * Basically the device should work as is without the fixup table.
6817 * If BIOS doesn't give a proper info, enable the corresponding
6818 * fixup entry.
6819 */
6820 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6821 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6822 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6823 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6824 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6825 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6826 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6827 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6828 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6829 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6830 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6831 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6832 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6833 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6834 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6835 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6836 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6837 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6838 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6839 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6840 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6841 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6842 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6843 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6844 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6845 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6846 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6847 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6848 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6849 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6850 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6851 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6852 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6853 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6854 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6855 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6856 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6857 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6858 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6859 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6860 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6861 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6862 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6863 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6864 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6865 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6866 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6867 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6868 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6869 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6870#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006871 {}
6872};
6873
Todd Broch6be79482010-12-07 16:51:05 -08006874static const struct alc_model_fixup alc662_fixup_models[] = {
6875 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006876 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6877 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6878 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6879 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6880 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6881 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6882 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6883 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006884 {}
6885};
David Henningsson6cb3b702010-09-09 08:51:44 +02006886
6887
Takashi Iwai1d045db2011-07-07 18:23:21 +02006888/*
6889 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006890static int patch_alc662(struct hda_codec *codec)
6891{
6892 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006893 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006894
6895 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6896 if (!spec)
6897 return -ENOMEM;
6898
6899 codec->spec = spec;
6900
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006901 spec->mixer_nid = 0x0b;
6902
Takashi Iwai53c334a2011-08-23 18:27:14 +02006903 /* handle multiple HPs as is */
6904 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6905
Kailang Yangda00c242010-03-19 11:23:45 +01006906 alc_auto_parse_customize_define(codec);
6907
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006908 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6909
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006910 err = alc_codec_rename_from_preset(codec);
6911 if (err < 0)
6912 goto error;
6913
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006914 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006915 codec->bus->pci->subsystem_vendor == 0x1025 &&
6916 spec->cdefine.platform_type == 1) {
6917 if (alc_codec_rename(codec, "ALC272X") < 0)
6918 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006919 }
Kailang Yang274693f2009-12-03 10:07:50 +01006920
Takashi Iwaib9c51062011-08-24 18:08:07 +02006921 alc_pick_fixup(codec, alc662_fixup_models,
6922 alc662_fixup_tbl, alc662_fixups);
6923 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6924 /* automatic parse from the BIOS config */
6925 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006926 if (err < 0)
6927 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006928
Takashi Iwai60a6a842011-07-27 14:01:24 +02006929 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006930 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006931 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006932 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006933 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006934
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006935 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006936 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006937
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006938 if (!spec->no_analog && has_cdefine_beep(codec)) {
6939 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006940 if (err < 0)
6941 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006942 switch (codec->vendor_id) {
6943 case 0x10ec0662:
6944 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6945 break;
6946 case 0x10ec0272:
6947 case 0x10ec0663:
6948 case 0x10ec0665:
6949 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6950 break;
6951 case 0x10ec0273:
6952 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6953 break;
6954 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006955 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006956
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006957 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006958 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c7161532011-04-07 10:37:16 +02006959 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006960
Takashi Iwaicb53c622007-08-10 17:21:45 +02006961#ifdef CONFIG_SND_HDA_POWER_SAVE
6962 if (!spec->loopback.amplist)
6963 spec->loopback.amplist = alc662_loopbacks;
6964#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006965
Takashi Iwai589876e2012-02-20 15:47:55 +01006966 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6967
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006968 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006969
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006970 error:
6971 alc_free(codec);
6972 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006973}
6974
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006975/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006976 * ALC680 support
6977 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006978
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006979static int alc680_parse_auto_config(struct hda_codec *codec)
6980{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006981 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006982}
6983
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006984/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006985 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006986static int patch_alc680(struct hda_codec *codec)
6987{
6988 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006989 int err;
6990
6991 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6992 if (spec == NULL)
6993 return -ENOMEM;
6994
6995 codec->spec = spec;
6996
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006997 /* ALC680 has no aa-loopback mixer */
6998
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006999 /* automatic parse from the BIOS config */
7000 err = alc680_parse_auto_config(codec);
7001 if (err < 0) {
7002 alc_free(codec);
7003 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007004 }
7005
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007006 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007007 set_capture_mixer(codec);
7008
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007009 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007010 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007011
7012 return 0;
7013}
7014
7015/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007016 * patch entries
7017 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007018static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007019 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007020 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007021 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007022 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007023 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007024 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007025 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007026 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007027 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007028 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007029 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007030 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007031 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7032 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7033 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007034 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007035 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007036 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7037 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007038 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7039 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007040 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007041 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007042 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007043 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007044 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007045 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007046 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007047 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007048 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007049 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007050 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007051 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007052 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007053 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007054 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007055 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007056 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007057 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007058 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 {} /* terminator */
7060};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007061
7062MODULE_ALIAS("snd-hda-codec-id:10ec*");
7063
7064MODULE_LICENSE("GPL");
7065MODULE_DESCRIPTION("Realtek HD-audio codec");
7066
7067static struct hda_codec_preset_list realtek_list = {
7068 .preset = snd_hda_preset_realtek,
7069 .owner = THIS_MODULE,
7070};
7071
7072static int __init patch_realtek_init(void)
7073{
7074 return snd_hda_add_codec_preset(&realtek_list);
7075}
7076
7077static void __exit patch_realtek_exit(void)
7078{
7079 snd_hda_delete_codec_preset(&realtek_list);
7080}
7081
7082module_init(patch_realtek_init)
7083module_exit(patch_realtek_exit)